Add Map::pause/resume
Fixed bug after switching apps
This commit is contained in:
@@ -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) },
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,9 @@ public:
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
void resume();
|
||||
void pause();
|
||||
|
||||
void notifyMapChange();
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user