From: Huang Dongsung Date: Sat, 23 Jun 2012 07:03:26 +0000 (+0900) Subject: Recreate egl surface when glViewport for watching framebuffer in qapitrace's surface... X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=67e00fdd5bdf596c9468d29ad99e7eba646cd02a;p=apitrace Recreate egl surface when glViewport for watching framebuffer in qapitrace's surface tab. It is quirk of mesa egl 1.4 with Nvidia-dri. It is ok with intel-dri. After resizing XWindow, mesa egl does not know new size of the surface. If you call eglQuerySurface(currentDisplay, currentSurface, EGL_WIDTH, width), width is the width at the time to create the egl surface, not current width. However, glx can know what the size of window well. Signed-off-by: José Fonseca --- diff --git a/retrace/glws_egl_xlib.cpp b/retrace/glws_egl_xlib.cpp index 0b8f34c..58824c2 100644 --- a/retrace/glws_egl_xlib.cpp +++ b/retrace/glws_egl_xlib.cpp @@ -155,6 +155,28 @@ public: eglWaitNative(EGL_CORE_NATIVE_ENGINE); } + void + recreate(void) { + EGLContext currentContext = eglGetCurrentContext(); + EGLSurface currentDrawSurface = eglGetCurrentSurface(EGL_DRAW); + EGLSurface currentReadSurface = eglGetCurrentSurface(EGL_DRAW); + bool rebindDrawSurface = currentDrawSurface == surface; + bool rebindReadSurface = currentReadSurface == surface; + + if (rebindDrawSurface || rebindReadSurface) { + eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT); + } + + eglDestroySurface(eglDisplay, surface); + + EGLConfig config = static_cast(visual)->config; + surface = eglCreateWindowSurface(eglDisplay, config, (EGLNativeWindowType)window, NULL); + + if (rebindDrawSurface || rebindReadSurface) { + eglMakeCurrent(eglDisplay, surface, surface, currentContext); + } + } + void resize(int w, int h) { if (w == width && h == height) { @@ -182,6 +204,27 @@ public: waitForEvent(ConfigureNotify); eglWaitNative(EGL_CORE_NATIVE_ENGINE); + + /* + * Some implementations won't update the backbuffer unless we recreate + * the EGL surface. + */ + + int eglWidth; + int eglHeight; + + eglQuerySurface(eglDisplay, surface, EGL_WIDTH, &eglWidth); + eglQuerySurface(eglDisplay, surface, EGL_HEIGHT, &eglHeight); + + if (eglWidth != width || eglHeight != height) { + recreate(); + + eglQuerySurface(eglDisplay, surface, EGL_WIDTH, &eglWidth); + eglQuerySurface(eglDisplay, surface, EGL_HEIGHT, &eglHeight); + } + + assert(eglWidth == width); + assert(eglHeight == height); } void show(void) {