Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
[android] - add paused state to map renderer, don't render snapshot w…
Browse files Browse the repository at this point in the history
…hen paused (#11358)
  • Loading branch information
tobrun committed Apr 10, 2018
1 parent 4ba63d5 commit 70db04a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ public void onStart() {
}

public void onPause() {
// Implement if needed
nativeOnPause();
}

public void onResume() {
// Implement if needed
nativeOnResume();
}

public void onStop() {
Expand Down Expand Up @@ -124,6 +124,10 @@ private native void nativeInitialize(MapRenderer self,

private native void nativeRender();

private native void nativeOnResume();

private native void nativeOnPause();

private long frames;
private long timeElapsed;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

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.
*/
Expand Down Expand Up @@ -79,6 +81,12 @@ protected void onResume() {
@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();
}

Expand Down
16 changes: 14 additions & 2 deletions platform/android/src/map_renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions platform/android/src/map_renderer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ class MapRenderer : public Scheduler {

void onSurfaceChanged(JNIEnv&, jint width, jint height);

void onResume(JNIEnv&);

void onPause(JNIEnv&);

private:
GenericUniqueWeakObject<MapRenderer> javaPeer;

Expand All @@ -120,6 +124,7 @@ class MapRenderer : public Scheduler {
std::mutex updateMutex;

bool framebufferSizeChanged = false;
std::atomic<bool> paused {false};

std::unique_ptr<SnapshotCallback> snapshotCallback;
};
Expand Down
1 change: 0 additions & 1 deletion platform/android/src/native_map_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,6 @@ class NativeMapView : public MapObserver {
MapRenderer& mapRenderer;

std::string styleUrl;
std::string apiKey;

float pixelRatio;

Expand Down

0 comments on commit 70db04a

Please sign in to comment.