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

[android] Restore prior GLContext if exists #4716

Merged
merged 1 commit into from
Apr 18, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion platform/android/src/native_map_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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());
Expand Down
6 changes: 6 additions & 0 deletions platform/android/src/native_map_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ class NativeMapView : public mbgl::View, private mbgl::util::noncopyable {
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;
Expand Down