summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xplatform/android/src/native_map_view.cpp13
-rwxr-xr-xplatform/android/src/native_map_view.hpp6
2 files changed, 18 insertions, 1 deletions
diff --git a/platform/android/src/native_map_view.cpp b/platform/android/src/native_map_view.cpp
index 45d078a390..d6405c53c0 100755
--- a/platform/android/src/native_map_view.cpp
+++ b/platform/android/src/native_map_view.cpp
@@ -127,6 +127,11 @@ std::array<uint16_t, 2> NativeMapView::getFramebufferSize() const {
void NativeMapView::activate() {
mbgl::Log::Debug(mbgl::Event::Android, "NativeMapView::activate");
+ oldDisplay = eglGetCurrentDisplay();
+ oldReadSurface = eglGetCurrentSurface(EGL_READ);
+ oldDrawSurface = eglGetCurrentSurface(EGL_DRAW);
+ oldContext = eglGetCurrentContext();
+
assert(vm != nullptr);
if ((display != EGL_NO_DISPLAY) && (surface != EGL_NO_SURFACE) && (context != EGL_NO_CONTEXT)) {
@@ -150,7 +155,13 @@ void NativeMapView::deactivate() {
assert(vm != nullptr);
- if (display != EGL_NO_DISPLAY) {
+ if (oldContext != context && oldContext != EGL_NO_CONTEXT) {
+ if (!eglMakeCurrent(oldDisplay, oldDrawSurface, oldReadSurface, oldContext)) {
+ mbgl::Log::Error(mbgl::Event::OpenGL, "eglMakeCurrent() returned error %d",
+ eglGetError());
+ throw std::runtime_error("eglMakeCurrent() failed");
+ }
+ } else if (display != EGL_NO_DISPLAY) {
if (!eglMakeCurrent(display, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT)) {
mbgl::Log::Error(mbgl::Event::OpenGL, "eglMakeCurrent(EGL_NO_CONTEXT) returned error %d",
eglGetError());
diff --git a/platform/android/src/native_map_view.hpp b/platform/android/src/native_map_view.hpp
index 0c29c2fe5c..5bae79ad9a 100755
--- a/platform/android/src/native_map_view.hpp
+++ b/platform/android/src/native_map_view.hpp
@@ -61,6 +61,12 @@ private:
jweak obj = nullptr;
ANativeWindow *window = nullptr;
+
+ EGLDisplay oldDisplay = EGL_NO_DISPLAY;
+ EGLSurface oldReadSurface = EGL_NO_SURFACE;
+ EGLSurface oldDrawSurface = EGL_NO_SURFACE;
+ EGLContext oldContext = EGL_NO_CONTEXT;
+
EGLDisplay display = EGL_NO_DISPLAY;
EGLSurface surface = EGL_NO_SURFACE;
EGLContext context = EGL_NO_CONTEXT;