diff options
author | Tobrun <tobrun@mapbox.com> | 2018-04-10 11:10:14 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-10 11:10:14 +0200 |
commit | c2a78d0d72ec369342b202e861a04a47b4f0c69f (patch) | |
tree | e9164aa1dbc64f169e98fec391607c4d617d14fd | |
parent | 44ce5ab08792df5f38560016ed3d41712e8025d0 (diff) | |
download | qtlocation-mapboxgl-c2a78d0d72ec369342b202e861a04a47b4f0c69f.tar.gz |
[android] - add paused state to map renderer, don't render snapshot when paused (#11358)
5 files changed, 34 insertions, 5 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java index fcee5bd179..f1c70325a0 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/renderer/MapRenderer.java @@ -37,11 +37,11 @@ public abstract class MapRenderer implements MapRendererScheduler { } public void onPause() { - // Implement if needed + nativeOnPause(); } public void onResume() { - // Implement if needed + nativeOnResume(); } public void onStop() { @@ -124,6 +124,10 @@ public abstract class MapRenderer implements MapRendererScheduler { private native void nativeRender(); + private native void nativeOnResume(); + + private native void nativeOnPause(); + private long frames; private long timeElapsed; diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.java b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.java index 62d3ad34df..1ec9d48a51 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/java/com/mapbox/mapboxsdk/testapp/activity/imagegenerator/SnapshotActivity.java @@ -1,5 +1,6 @@ package com.mapbox.mapboxsdk.testapp.activity.imagegenerator; +import android.graphics.Bitmap; import android.os.Bundle; import android.support.design.widget.FloatingActionButton; import android.support.v4.content.ContextCompat; @@ -16,6 +17,8 @@ import com.mapbox.mapboxsdk.testapp.R; import java.util.Locale; +import timber.log.Timber; + /** * Test activity showcasing the Snapshot API to create and display a bitmap of the current shown Map. */ @@ -75,6 +78,12 @@ public class SnapshotActivity extends AppCompatActivity implements OnMapReadyCal @Override protected void onPause() { super.onPause(); + mapboxMap.snapshot(new MapboxMap.SnapshotReadyCallback() { + @Override + public void onSnapshotReady(Bitmap snapshot) { + Timber.e("Regression test for https://github.com/mapbox/mapbox-gl-native/pull/11358"); + } + }); mapView.onPause(); } diff --git a/platform/android/src/map_renderer.cpp b/platform/android/src/map_renderer.cpp index 2440ac93ef..f7e16b7091 100644 --- a/platform/android/src/map_renderer.cpp +++ b/platform/android/src/map_renderer.cpp @@ -136,7 +136,7 @@ void MapRenderer::render(JNIEnv&) { renderer->render(*params); // Deliver the snapshot if requested - if (snapshotCallback) { + if (snapshotCallback && !paused) { snapshotCallback->operator()(backend->readFramebuffer()); snapshotCallback.reset(); } @@ -174,6 +174,14 @@ void MapRenderer::onSurfaceChanged(JNIEnv&, jint width, jint height) { requestRender(); } +void MapRenderer::onResume(JNIEnv&) { + paused = false; +} + +void MapRenderer::onPause(JNIEnv&) { + paused = true; +} + // Static methods // jni::Class<MapRenderer> MapRenderer::javaClass; @@ -192,7 +200,11 @@ void MapRenderer::registerNative(jni::JNIEnv& env) { METHOD(&MapRenderer::onSurfaceCreated, "nativeOnSurfaceCreated"), METHOD(&MapRenderer::onSurfaceChanged, - "nativeOnSurfaceChanged")); + "nativeOnSurfaceChanged"), + METHOD(&MapRenderer::onResume, + "nativeOnResume"), + METHOD(&MapRenderer::onPause, + "nativeOnPause")); } MapRenderer& MapRenderer::getNativePeer(JNIEnv& env, jni::Object<MapRenderer> jObject) { diff --git a/platform/android/src/map_renderer.hpp b/platform/android/src/map_renderer.hpp index c36357af7a..5fb5ef1a61 100644 --- a/platform/android/src/map_renderer.hpp +++ b/platform/android/src/map_renderer.hpp @@ -98,6 +98,10 @@ private: void onSurfaceChanged(JNIEnv&, jint width, jint height); + void onResume(JNIEnv&); + + void onPause(JNIEnv&); + private: GenericUniqueWeakObject<MapRenderer> javaPeer; @@ -120,6 +124,7 @@ private: std::mutex updateMutex; bool framebufferSizeChanged = false; + std::atomic<bool> paused {false}; std::unique_ptr<SnapshotCallback> snapshotCallback; }; diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp index 1f9911c801..aff3b51c42 100755 --- a/platform/android/src/native_map_view.hpp +++ b/platform/android/src/native_map_view.hpp @@ -257,7 +257,6 @@ private: MapRenderer& mapRenderer; std::string styleUrl; - std::string apiKey; float pixelRatio; |