[android] - add paused state to map renderer, don't render snapshot when paused (#11358)
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -17,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.
|
||||
*/
|
||||
@@ -79,6 +81,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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
@@ -257,7 +257,6 @@ private:
|
||||
MapRenderer& mapRenderer;
|
||||
|
||||
std::string styleUrl;
|
||||
std::string apiKey;
|
||||
|
||||
float pixelRatio;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user