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

Commit

Permalink
WIP [android] Main loop integration
Browse files Browse the repository at this point in the history
  • Loading branch information
tmpsantos committed Dec 8, 2015
1 parent 89c2736 commit 4383fdd
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,6 @@ public void onPause() {
mConnectivityReceiver = null;

mUserLocationView.pause();
mNativeMapView.pause();
}

/**
Expand All @@ -987,7 +986,6 @@ public void onResume() {
getContext().registerReceiver(mConnectivityReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

mUserLocationView.resume();
mNativeMapView.resume();
mNativeMapView.update();
}

Expand Down Expand Up @@ -2117,12 +2115,6 @@ private List<Marker> getMarkersInBounds(@NonNull BoundingBox bbox) {
}

private int getTopOffsetPixelsForSprite(Sprite sprite) {
// This method will dead lock if map paused. Causes a freeze if you add a marker in an
// activity's onCreate()
if (mNativeMapView.isPaused()) {
return 0;
}

return (int) (mNativeMapView.getTopOffsetPixelsForAnnotationSymbol(sprite.getId())
* mScreenDensity);
}
Expand Down Expand Up @@ -2345,9 +2337,7 @@ public void onDraw(Canvas canvas) {
return;
}

if (!mNativeMapView.isPaused()) {
mNativeMapView.renderSync();
}
mNativeMapView.render();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,24 +100,12 @@ public void destroySurface() {
nativeDestroySurface(mNativeMapViewPtr);
}

public void pause() {
nativePause(mNativeMapViewPtr);
}

public boolean isPaused() {
return nativeIsPaused(mNativeMapViewPtr);
}

public void resume() {
nativeResume(mNativeMapViewPtr);
}

public void update() {
nativeUpdate(mNativeMapViewPtr);
}

public void renderSync() {
nativeRenderSync(mNativeMapViewPtr);
public void render() {
nativeRender(mNativeMapViewPtr);
}

public void resizeView(int width, int height) {
Expand Down Expand Up @@ -494,7 +482,7 @@ private native void nativeCreateSurface(long nativeMapViewPtr,

private native void nativeUpdate(long nativeMapViewPtr);

private native void nativeRenderSync(long nativeMapViewPtr);
private native void nativeRender(long nativeMapViewPtr);

private native void nativeViewResize(long nativeMapViewPtr, int width, int height);

Expand Down
32 changes: 4 additions & 28 deletions platform/android/jni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,39 +453,18 @@ void JNICALL nativeDestroySurface(JNIEnv *env, jobject obj, jlong nativeMapViewP
nativeMapView->destroySurface();
}

void JNICALL nativePause(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativePause");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->pause();
}

jboolean JNICALL nativeIsPaused(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeIsPaused");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
return nativeMapView->getMap().isPaused();
}

void JNICALL nativeResume(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeResume");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->resume();
}

void JNICALL nativeUpdate(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeUpdate");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->getMap().update(mbgl::Update::Repaint);
}

void JNICALL nativeRenderSync(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeRenderSync");
void JNICALL nativeRender(JNIEnv *env, jobject obj, jlong nativeMapViewPtr) {
mbgl::Log::Debug(mbgl::Event::JNI, "nativeRender");
assert(nativeMapViewPtr != 0);
NativeMapView *nativeMapView = reinterpret_cast<NativeMapView *>(nativeMapViewPtr);
nativeMapView->getMap().renderSync();
nativeMapView->getMap().render();
}

void JNICALL nativeViewResize(JNIEnv *env, jobject obj, jlong nativeMapViewPtr, jint width, jint height) {
Expand Down Expand Up @@ -1859,11 +1838,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
{"nativeCreateSurface", "(JLandroid/view/Surface;)V",
reinterpret_cast<void *>(&nativeCreateSurface)},
{"nativeDestroySurface", "(J)V", reinterpret_cast<void *>(&nativeDestroySurface)},
{"nativePause", "(J)V", reinterpret_cast<void *>(&nativePause)},
{"nativeIsPaused", "(J)Z", reinterpret_cast<void *>(&nativeIsPaused)},
{"nativeResume", "(J)V", reinterpret_cast<void *>(&nativeResume)},
{"nativeUpdate", "(J)V", reinterpret_cast<void *>(&nativeUpdate)},
{"nativeRenderSync", "(J)V", reinterpret_cast<void *>(&nativeRenderSync)},
{"nativeRender", "(J)V", reinterpret_cast<void *>(&nativeRender)},
{"nativeViewResize", "(JII)V",
reinterpret_cast<void *>(static_cast<void JNICALL (
*)(JNIEnv *, jobject, jlong, jint, jint)>(&nativeViewResize))},
Expand Down
25 changes: 0 additions & 25 deletions platform/android/native_map_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ NativeMapView::NativeMapView(JNIEnv *env, jobject obj_, float pixelRatio_, int a
size_t cacheSize = zoomFactor * cpuFactor * memoryFactor * sizeFactor * 0.5f;

map->setSourceTileCacheSize(cacheSize);

map->pause();
}

NativeMapView::~NativeMapView() {
Expand Down Expand Up @@ -440,8 +438,6 @@ void NativeMapView::createSurface(ANativeWindow *window_) {
void NativeMapView::destroySurface() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::destroySurface");

pause();

if (surface != EGL_NO_SURFACE) {
if (!eglDestroySurface(display, surface)) {
mbgl::Log::Error(mbgl::Event::OpenGL, "eglDestroySurface() returned error %d",
Expand Down Expand Up @@ -658,27 +654,6 @@ EGLConfig NativeMapView::chooseConfig(const EGLConfig configs[], EGLint numConfi
return configId;
}

void NativeMapView::pause() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::pause");

if ((display != EGL_NO_DISPLAY) && (context != EGL_NO_CONTEXT)) {
map->pause();
}
}

void NativeMapView::resume() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::resume");

assert(display != EGL_NO_DISPLAY);
assert(context != EGL_NO_CONTEXT);

if (surface != EGL_NO_SURFACE) {
map->resume();
} else {
mbgl::Log::Debug(mbgl::Event::Android, "Not resuming because we are not ready");
}
}

void NativeMapView::notifyMapChange(mbgl::MapChange change) {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::notifyMapChange()");

Expand Down

0 comments on commit 4383fdd

Please sign in to comment.