diff options
Diffstat (limited to 'android')
-rw-r--r-- | android/cpp/JNI.cpp | 18 | ||||
-rw-r--r-- | android/cpp/NativeMapView.cpp | 87 | ||||
-rw-r--r-- | android/cpp/NativeMapView.hpp | 3 | ||||
-rw-r--r-- | android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java | 13 | ||||
-rw-r--r-- | android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java | 12 |
5 files changed, 92 insertions, 41 deletions
diff --git a/android/cpp/JNI.cpp b/android/cpp/JNI.cpp index e1731aa99d..3b1801c4c6 100644 --- a/android/cpp/JNI.cpp +++ b/android/cpp/JNI.cpp @@ -221,6 +221,20 @@ void JNICALL nativeStop(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { native_map_view->stop(); } +void JNICALL nativePause(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { + LOG_VERBOSE("nativePause"); + LOG_ASSERT(native_map_view_ptr != 0); + NativeMapView* native_map_view = reinterpret_cast<NativeMapView*>(native_map_view_ptr); + native_map_view->pause(); +} + +void JNICALL nativeResume(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { + LOG_VERBOSE("nativeResume"); + LOG_ASSERT(native_map_view_ptr != 0); + NativeMapView* native_map_view = reinterpret_cast<NativeMapView*>(native_map_view_ptr); + native_map_view->resume(); +} + void JNICALL nativeRun(JNIEnv* env, jobject obj, jlong native_map_view_ptr) { LOG_VERBOSE("nativeRun"); LOG_ASSERT(native_map_view_ptr != 0); @@ -739,7 +753,7 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { } // NOTE: if you get java.lang.UnsatisfiedLinkError you likely forgot to set the size of the array correctly (too large) - std::array<JNINativeMethod, 58> methods = {{ // Can remove the extra brace in C++14 + std::array<JNINativeMethod, 60> methods = {{ // Can remove the extra brace in C++14 { "nativeCreate", "(Ljava/lang/String;)J", reinterpret_cast<void*>(&nativeCreate) }, { "nativeDestroy", "(J)V", reinterpret_cast<void*>(&nativeDestroy) }, { "nativeInitializeDisplay", "(J)V", reinterpret_cast<void*>(&nativeInitializeDisplay) }, @@ -750,6 +764,8 @@ extern "C" JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) { { "nativeDestroySurface", "(J)V", reinterpret_cast<void*>(&nativeDestroySurface) }, { "nativeStart", "(J)V", reinterpret_cast<void*>(&nativeStart) }, { "nativeStop", "(J)V", reinterpret_cast<void*>(&nativeStop) }, + { "nativePause", "(J)V", reinterpret_cast<void*>(&nativePause) }, + { "nativeResume", "(J)V", reinterpret_cast<void*>(&nativeResume) }, { "nativeRun", "(J)V", reinterpret_cast<void*>(&nativeRun) }, { "nativeRerender", "(J)V", reinterpret_cast<void*>(&nativeRerender) }, { "nativeUpdate", "(J)V", reinterpret_cast<void*>(&nativeUpdate) }, diff --git a/android/cpp/NativeMapView.cpp b/android/cpp/NativeMapView.cpp index 394e01bdb1..6761f3ede9 100644 --- a/android/cpp/NativeMapView.cpp +++ b/android/cpp/NativeMapView.cpp @@ -149,12 +149,6 @@ bool NativeMapView::initializeDisplay() { // Now try 8888 use565 = false; - // TODO removed these due to different indices - //config_attribs[9] = 32; // EGL_BUFFER_SIZE // Ensure we get 32bit color buffer on Tegra, 24 bit will be sorted first without it (slow software mode) - //config_attribs[11] = 8; // EGL_RED_SIZE - //config_attribs[13] = 8; // EGL_GREEN_SIZE - //config_attribs[15] = 8; // EGL_BLUE_SIZE - config_attribs[5] = 32; // EGL_BUFFER_SIZE // Ensure we get 32bit color buffer on Tegra, 24 bit will be sorted first without it (slow software mode) config_attribs[7] = 8; // EGL_RED_SIZE config_attribs[9] = 8; // EGL_GREEN_SIZE @@ -296,7 +290,25 @@ bool NativeMapView::createSurface(ANativeWindow* window_) { return false; } - start(); + if (!eglMakeCurrent(display, surface, surface, context)) { + LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError()); + } + + log_gl_string(GL_VENDOR, "Vendor"); + log_gl_string(GL_RENDERER, "Renderer"); + log_gl_string(GL_VERSION, "Version"); + log_gl_string(GL_SHADING_LANGUAGE_VERSION, "SL Version"); // In the emulator this returns NULL with error code 0? https://code.google.com/p/android/issues/detail?id=78977 + log_gl_string(GL_EXTENSIONS, "Extensions"); + + loadExtensions(); + + if (!eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, + EGL_NO_CONTEXT)) { + LOG_ERROR("eglMakeCurrent(EGL_NO_CONTEXT) returned error %d", + eglGetError()); + } + + resume(); return true; } @@ -304,7 +316,7 @@ bool NativeMapView::createSurface(ANativeWindow* window_) { void NativeMapView::destroySurface() { LOG_VERBOSE("NativeMapView::destroySurface"); - map->terminate(); + pause(); if (surface != EGL_NO_SURFACE) { if (!eglDestroySurface(display, surface)) { @@ -464,31 +476,10 @@ void NativeMapView::start() { initializeContext(); } - if ((display != EGL_NO_DISPLAY) && (surface != EGL_NO_SURFACE) - && (context != EGL_NO_CONTEXT)) { - - if (!eglMakeCurrent(display, surface, surface, context)) { - LOG_ERROR("eglMakeCurrent() returned error %d", eglGetError()); - } - - log_gl_string(GL_VENDOR, "Vendor"); - log_gl_string(GL_RENDERER, "Renderer"); - log_gl_string(GL_VERSION, "Version"); - log_gl_string(GL_SHADING_LANGUAGE_VERSION, "SL Version"); // In the emulator this returns NULL with error code 0? https://code.google.com/p/android/issues/detail?id=78977 - log_gl_string(GL_EXTENSIONS, "Extensions"); - - loadExtensions(); - - if (!eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, - EGL_NO_CONTEXT)) { - LOG_ERROR("eglMakeCurrent(EGL_NO_CONTEXT) returned error %d", - eglGetError()); - } - - map->start(); - } else { - LOG_DEBUG("Not starting because we are not ready"); - } + LOG_ASSERT(display != EGL_NO_DISPLAY); + LOG_ASSERT(context != EGL_NO_CONTEXT); + + map->start(); } void NativeMapView::loadExtensions() { @@ -519,9 +510,33 @@ void NativeMapView::loadExtensions() { void NativeMapView::stop() { LOG_VERBOSE("NativeMapView::stop"); - if ((display != EGL_NO_DISPLAY) && (surface != EGL_NO_SURFACE) - && (context != EGL_NO_CONTEXT)) { - map->stop(); + + LOG_ASSERT(display != EGL_NO_DISPLAY); + LOG_ASSERT(context != EGL_NO_CONTEXT); + + map->stop(); +} + + +void NativeMapView::pause() { + LOG_VERBOSE("NativeMapView::pause"); + + LOG_ASSERT(display != EGL_NO_DISPLAY); + LOG_ASSERT(context != EGL_NO_CONTEXT); + + map->pause(); +} + +void NativeMapView::resume() { + LOG_VERBOSE("NativeMapView::resume"); + + LOG_ASSERT(display != EGL_NO_DISPLAY); + LOG_ASSERT(context != EGL_NO_CONTEXT); + + if (surface != EGL_NO_SURFACE) { + map->resume(); + } else { + LOG_DEBUG("Not resuming because we are not ready"); } } diff --git a/android/cpp/NativeMapView.hpp b/android/cpp/NativeMapView.hpp index aafd761894..05aa11b88c 100644 --- a/android/cpp/NativeMapView.hpp +++ b/android/cpp/NativeMapView.hpp @@ -62,6 +62,9 @@ public: void start(); void stop(); + void resume(); + void pause(); + void notifyMapChange(); private: diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java index e9e815dedf..2b150e8ba4 100644 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java +++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/MapView.java @@ -373,6 +373,7 @@ public class MapView extends SurfaceView { } mNativeMapView.initializeDisplay(); + mNativeMapView.initializeContext(); } // Called when we need to save instance state @@ -392,6 +393,7 @@ public class MapView extends SurfaceView { // Must be called from Activity onDestroy public void onDestroy() { Log.v(TAG, "onDestroy"); + mNativeMapView.terminateContext(); mNativeMapView.terminateDisplay(); } @@ -399,21 +401,22 @@ public class MapView extends SurfaceView { // Must be called from Activity onStart public void onStart() { Log.v(TAG, "onStart"); - mNativeMapView.initializeContext(); + mNativeMapView.pause(); + mNativeMapView.start(); } // Called when we need to terminate the GL context // Must be called from Activity onPause public void onStop() { Log.v(TAG, "onStop"); - mNativeMapView.terminateContext(); + mNativeMapView.stop(); } // Called when we need to stop the render thread // Must be called from Activity onPause public void onPause() { Log.v(TAG, "onPause"); - mNativeMapView.stop(); + mNativeMapView.pause(); } // Called when we need to start the render thread @@ -421,7 +424,7 @@ public class MapView extends SurfaceView { public void onResume() { Log.v(TAG, "onResume"); - mNativeMapView.start(); + mNativeMapView.resume(); } // This class handles SurfaceHolder callbacks @@ -464,6 +467,8 @@ public class MapView extends SurfaceView { } } + // TODO examine how GLSurvaceView hadles attach/detach from window + // Called when view is no longer connected @Override protected void onDetachedFromWindow() { diff --git a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java index 01ee430df1..974c408b6c 100644 --- a/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java +++ b/android/java/lib/src/main/java/com/mapbox/mapboxgl/lib/NativeMapView.java @@ -80,6 +80,14 @@ class NativeMapView { nativeStop(mNativeMapViewPtr); } + public void pause() { + nativePause(mNativeMapViewPtr); + } + + public void resume() { + nativeResume(mNativeMapViewPtr); + } + public void run() { nativeRun(mNativeMapViewPtr); } @@ -420,6 +428,10 @@ class NativeMapView { private native void nativeStop(long nativeMapViewPtr); + private native void nativePause(long nativeMapViewPtr); + + private native void nativeResume(long nativeMapViewPtr); + private native void nativeRun(long nativeMapViewPtr); private native void nativeRerender(long nativeMapViewPtr); |