diff options
Diffstat (limited to 'opengl/libs/EGL/egl_display.cpp')
-rw-r--r-- | opengl/libs/EGL/egl_display.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/opengl/libs/EGL/egl_display.cpp b/opengl/libs/EGL/egl_display.cpp index 53eaf9a..6b2ae51 100644 --- a/opengl/libs/EGL/egl_display.cpp +++ b/opengl/libs/EGL/egl_display.cpp @@ -342,6 +342,78 @@ EGLBoolean egl_display_t::terminate() { return res; } +void egl_display_t::loseCurrent(egl_context_t * cur_c) +{ + if (cur_c) { + egl_display_t* display = cur_c->getDisplay(); + if (display) { + display->loseCurrentImpl(cur_c); + } + } +} + +void egl_display_t::loseCurrentImpl(egl_context_t * cur_c) +{ + // by construction, these are either 0 or valid (possibly terminated) + // it should be impossible for these to be invalid + ContextRef _cur_c(cur_c); + SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : NULL); + SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : NULL); + + { // scope for the lock + Mutex::Autolock _l(lock); + cur_c->onLooseCurrent(); + + } + + // This cannot be called with the lock held because it might end-up + // calling back into EGL (in particular when a surface is destroyed + // it calls ANativeWindow::disconnect + _cur_c.release(); + _cur_r.release(); + _cur_d.release(); +} + +EGLBoolean egl_display_t::makeCurrent(egl_context_t* c, egl_context_t* cur_c, + EGLSurface draw, EGLSurface read, EGLContext ctx, + EGLSurface impl_draw, EGLSurface impl_read, EGLContext impl_ctx) +{ + EGLBoolean result; + + // by construction, these are either 0 or valid (possibly terminated) + // it should be impossible for these to be invalid + ContextRef _cur_c(cur_c); + SurfaceRef _cur_r(cur_c ? get_surface(cur_c->read) : NULL); + SurfaceRef _cur_d(cur_c ? get_surface(cur_c->draw) : NULL); + + { // scope for the lock + Mutex::Autolock _l(lock); + if (c) { + result = c->cnx->egl.eglMakeCurrent( + disp[c->impl].dpy, impl_draw, impl_read, impl_ctx); + if (result == EGL_TRUE) { + c->onMakeCurrent(draw, read); + } + } else { + result = cur_c->cnx->egl.eglMakeCurrent( + disp[cur_c->impl].dpy, impl_draw, impl_read, impl_ctx); + if (result == EGL_TRUE) { + cur_c->onLooseCurrent(); + } + } + } + + if (result == EGL_TRUE) { + // This cannot be called with the lock held because it might end-up + // calling back into EGL (in particular when a surface is destroyed + // it calls ANativeWindow::disconnect + _cur_c.release(); + _cur_r.release(); + _cur_d.release(); + } + + return result; +} // ---------------------------------------------------------------------------- }; // namespace android |