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

Null java peer callback #11358

Merged
merged 1 commit into from
Apr 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -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;
Expand All @@ -16,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 @@ -75,6 +78,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