[android] synchronize and coalesce requests targeting the same TileID in the CustomGeometrySource

This commit is contained in:
Łukasz Paczos
2018-07-30 15:09:35 +02:00
committed by Łukasz Paczos
parent 51f3842a28
commit f9fd9c0f00
3 changed files with 168 additions and 42 deletions

View File

@@ -102,6 +102,19 @@ namespace android {
peer.Call(*_env, releaseThreads);
};
bool CustomGeometrySource::isCancelled(jni::jint z,
jni::jint x,
jni::jint y) {
android::UniqueEnv _env = android::AttachEnv();
static auto isCancelled = javaClass.GetMethod<jboolean (jni::jint, jni::jint, jni::jint)>(*_env, "isCancelled");
assert(javaPeer);
auto peer = jni::Cast(*_env, *javaPeer, javaClass);
return peer.Call(*_env, isCancelled, z, x, y);
};
void CustomGeometrySource::setTileData(jni::JNIEnv& env,
jni::jint z,
jni::jint x,
@@ -112,8 +125,10 @@ namespace android {
// Convert the jni object
auto geometry = geojson::FeatureCollection::convert(env, jFeatures);
// Update the core source
source.as<mbgl::style::CustomGeometrySource>()->CustomGeometrySource::setTileData(CanonicalTileID(z, x, y), GeoJSON(geometry));
// Update the core source if not cancelled
if (!isCancelled(z, x ,y)) {
source.as<mbgl::style::CustomGeometrySource>()->CustomGeometrySource::setTileData(CanonicalTileID(z, x, y), GeoJSON(geometry));
}
}
void CustomGeometrySource::invalidateTile(jni::JNIEnv&, jni::jint z, jni::jint x, jni::jint y) {