From b57ad81dae75e979218b1248b367b181a65ff704 Mon Sep 17 00:00:00 2001 From: Guy Zadikario Date: Thu, 2 Jun 2011 15:26:40 +0300 Subject: [PATCH] emulator opengl: Fix bug when re-binding the same context When re-binding the same context the resoult was that the surfaces got unbinded from the context. Fixed that situation and added an optimization to do nothing in case of re-binding the same context to the same binded surfaces. Change-Id: Ic7058723399b0807d902c29b4170c7465c02bb99 --- .../opengl/host/libs/Translator/EGL/EglImp.cpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp b/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp index 1e47f0f27..c17d2746f 100644 --- a/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp +++ b/tools/emulator/opengl/host/libs/Translator/EGL/EglImp.cpp @@ -676,6 +676,7 @@ EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay display, EGLSurface draw EGLSurface read, EGLContext context) { VALIDATE_DISPLAY(display); + bool releaseContext = EglValidate::releaseContext(context,read,draw); if(!releaseContext && EglValidate::badContextMatch(context,read,draw)) { RETURN_ERROR(EGL_FALSE,EGL_BAD_MATCH); @@ -701,6 +702,20 @@ EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay display, EGLSurface draw EglSurface* newReadPtr = newReadSrfc.Ptr(); EglContext* newCtx = ctx.Ptr(); + if (newCtx && prevCtx) { + if (newCtx == prevCtx) { + if (newDrawPtr == prevCtx->draw().Ptr() && + newReadPtr == prevCtx->read().Ptr()) { + // nothing to do + return EGL_TRUE; + } + } + else { + // Make sure previous context is detached from surfaces + releaseContext = true; + } + } + //surfaces compitability check if(!((*ctx->getConfig()).compitableWith((*newDrawPtr->getConfig()))) || !((*ctx->getConfig()).compitableWith((*newReadPtr->getConfig())))) { @@ -743,7 +758,7 @@ EGLAPI EGLBoolean EGLAPIENTRY eglMakeCurrent(EGLDisplay display, EGLSurface draw SurfacePtr prevRead; SurfacePtr prevDraw; //removing terminated surfaces & context - if(prevCtx) { + if(prevCtx && releaseContext) { prevRead = prevCtx->read(); if(prevRead->destroy()){ if(destroySurfaceIfNotCurrent(dpy,prevRead)) { //removes surface from the list if not current