]> git.cworth.org Git - apitrace/commitdiff
Recreate egl surface when glViewport for watching framebuffer in qapitrace's surface...
authorHuang Dongsung <luxtella@company100.net>
Sat, 23 Jun 2012 07:03:26 +0000 (16:03 +0900)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 5 Aug 2012 09:21:52 +0000 (10:21 +0100)
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 <jose.r.fonseca@gmail.com>
retrace/glws_egl_xlib.cpp

index 0b8f34c17bc595d192d297cf5517901632abbb05..58824c29b2b897765e0af4c8fe36753e907ef79e 100644 (file)
@@ -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<const EglVisual *>(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) {