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

Commit

Permalink
[android] Restore prior GLContext if exists
Browse files Browse the repository at this point in the history
Apparently some versions of Android, notable 4.4.4 running
on my Nexus 5, creates a GLContext on the Android UIThread
which is the one we are now using for rendering after #2909.

If the context is not restored, nothing gets rendered (or
sometimes partially, or artifacts) because Android will try
to do GL stuff on the context used by Mapbox GL and mess things up.
  • Loading branch information
tmpsantos committed Apr 15, 2016
1 parent 253a007 commit 9efa5f9
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion platform/android/src/native_map_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ void NativeMapView::invalidate() {
}

void NativeMapView::render() {
EGLDisplay currentDisplay = eglGetCurrentDisplay();
EGLSurface currentReadSurface = eglGetCurrentSurface(EGL_READ);
EGLSurface currentDrawSurface = eglGetCurrentSurface(EGL_DRAW);
EGLContext currentContext = eglGetCurrentContext();

activate();

if(sizeChanged){
Expand All @@ -195,7 +200,19 @@ void NativeMapView::render() {
mbgl::Log::Info(mbgl::Event::Android, "Not swapping as we are not ready");
}

deactivate();
if (currentContext != context && currentContext != EGL_NO_CONTEXT) {
if (currentDisplay == EGL_NO_DISPLAY) {
currentDisplay = display;
}

if (!eglMakeCurrent(currentDisplay, currentDrawSurface, currentReadSurface, currentContext)) {
mbgl::Log::Error(mbgl::Event::OpenGL, "eglMakeCurrent() returned error %d",
eglGetError());
throw std::runtime_error("eglMakeCurrent() failed");
}
} else {
deactivate();
}
}

mbgl::Map &NativeMapView::getMap() { return *map; }
Expand Down

0 comments on commit 9efa5f9

Please sign in to comment.