diff options
author | Tobrun <tobrun@mapbox.com> | 2017-12-06 11:51:33 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-06 11:51:33 +0100 |
commit | c311e69e0ef61f5203fa6cf632d5ec73b1e181da (patch) | |
tree | 379809fb2d65fbdad0327ac3ed8ab6f4b7d026be /platform/android/src/snapshotter | |
parent | f16ecf59074e6c1f6296eb03f30b744eaa66779f (diff) | |
download | qtlocation-mapboxgl-c311e69e0ef61f5203fa6cf632d5ec73b1e181da.tar.gz |
[android] - add FileSource activation/deactivation to MapSnapshotter, handle multiple deactivate scenario in FileSource (#10556)
Diffstat (limited to 'platform/android/src/snapshotter')
-rw-r--r-- | platform/android/src/snapshotter/map_snapshotter.cpp | 33 | ||||
-rw-r--r-- | platform/android/src/snapshotter/map_snapshotter.hpp | 5 |
2 files changed, 31 insertions, 7 deletions
diff --git a/platform/android/src/snapshotter/map_snapshotter.cpp b/platform/android/src/snapshotter/map_snapshotter.cpp index 637eb5c1fd..71f8b4f4c0 100644 --- a/platform/android/src/snapshotter/map_snapshotter.cpp +++ b/platform/android/src/snapshotter/map_snapshotter.cpp @@ -15,7 +15,7 @@ namespace android { MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env, jni::Object<MapSnapshotter> _obj, - jni::Object<FileSource> jFileSource, + jni::Object<FileSource> _jFileSource, jni::jfloat _pixelRatio, jni::jint width, jni::jint height, @@ -34,16 +34,16 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env, return; } - auto& fileSource = mbgl::android::FileSource::getDefaultFileSource(_env, jFileSource); + jFileSource = FileSource::getNativePeer(_env, _jFileSource); + auto& fileSource = mbgl::android::FileSource::getDefaultFileSource(_env, _jFileSource); auto size = mbgl::Size { static_cast<uint32_t>(width), static_cast<uint32_t>(height) }; auto cameraOptions = position ? CameraPosition::getCameraOptions(_env, position) : CameraOptions(); optional<mbgl::LatLngBounds> bounds; if (region) { bounds = LatLngBounds::getLatLngBounds(_env, region); } - + showLogo = _showLogo; - // Create the core snapshotter snapshotter = std::make_unique<mbgl::MapSnapshotter>(fileSource, *threadPool, @@ -58,8 +58,9 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env, MapSnapshotter::~MapSnapshotter() = default; -void MapSnapshotter::start(JNIEnv&) { +void MapSnapshotter::start(JNIEnv& env) { MBGL_VERIFY_THREAD(tid); + activateFilesource(env); snapshotCallback = std::make_unique<Actor<mbgl::MapSnapshotter::Callback>>( *Scheduler::GetCurrent(), @@ -79,17 +80,19 @@ void MapSnapshotter::start(JNIEnv&) { static auto onSnapshotReady = javaClass.GetMethod<void (jni::Object<MapSnapshot>)>(*_env, "onSnapshotReady"); javaPeer->Call(*_env, onSnapshotReady, mapSnapshot); } + + deactivateFilesource(*_env); }); snapshotter->snapshot(snapshotCallback->self()); } -void MapSnapshotter::cancel(JNIEnv&) { +void MapSnapshotter::cancel(JNIEnv& env) { MBGL_VERIFY_THREAD(tid); snapshotCallback.reset(); + deactivateFilesource(env); } - void MapSnapshotter::setStyleUrl(JNIEnv& env, jni::String styleURL) { snapshotter->setStyleURL(jni::Make<std::string>(env, styleURL)); } @@ -108,6 +111,22 @@ void MapSnapshotter::setRegion(JNIEnv& env, jni::Object<LatLngBounds> region) { snapshotter->setRegion(LatLngBounds::getLatLngBounds(env, region)); } +// Private methods // + +void MapSnapshotter::activateFilesource(JNIEnv& env) { + if (!activatedFilesource) { + activatedFilesource = true; + jFileSource->resume(env); + } +} + +void MapSnapshotter::deactivateFilesource(JNIEnv& env) { + if (activatedFilesource) { + activatedFilesource = false; + jFileSource->pause(env); + } +} + // Static methods // jni::Class<MapSnapshotter> MapSnapshotter::javaClass; diff --git a/platform/android/src/snapshotter/map_snapshotter.hpp b/platform/android/src/snapshotter/map_snapshotter.hpp index 8cd85060bf..4cdf4bcf2b 100644 --- a/platform/android/src/snapshotter/map_snapshotter.hpp +++ b/platform/android/src/snapshotter/map_snapshotter.hpp @@ -65,6 +65,11 @@ private: std::shared_ptr<mbgl::ThreadPool> threadPool; std::unique_ptr<Actor<mbgl::MapSnapshotter::Callback>> snapshotCallback; std::unique_ptr<mbgl::MapSnapshotter> snapshotter; + + FileSource *jFileSource; + void activateFilesource(JNIEnv&); + void deactivateFilesource(JNIEnv&); + bool activatedFilesource = false; }; } // namespace android |