summaryrefslogtreecommitdiff
path: root/platform/android/src/snapshotter/map_snapshotter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/src/snapshotter/map_snapshotter.cpp')
-rw-r--r--platform/android/src/snapshotter/map_snapshotter.cpp33
1 files changed, 26 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;