]> git.cworth.org Git - apitrace/commitdiff
Start with a smaller default window size; avoid race conditions on resize.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 17 May 2011 08:43:36 +0000 (09:43 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Tue, 17 May 2011 08:43:36 +0000 (09:43 +0100)
Because most mesa demos use a 250x250 window, and the window only grows
to accomodate the viewport (never shrinks) so we end up retracing with
a larger framebuffer.

But for this to work all the time, especially with DRI drivers which do
not hook into glViewport, it was necessary to do more event processing
to ensure that by the time the resize is done, the new window size is
visible to GL.

glws.hpp
glws_glx.cpp

index bfd34480613e4713ddb24a77e9a7ee85f38a3715..3d3c83d4982bf2ea2a265ce90b1b7c52ec90008d 100644 (file)
--- a/glws.hpp
+++ b/glws.hpp
@@ -94,7 +94,7 @@ public:
     createVisual(bool doubleBuffer = false) = 0;
     
     virtual Drawable *
-    createDrawable(const Visual *visual, int width = 256, int height = 256) = 0;
+    createDrawable(const Visual *visual, int width = 32, int height = 32) = 0;
 
     virtual Context *
     createContext(const Visual *visual, Context *shareContext = NULL) = 0;
index 732f33d150671430b473546e0c5accee898d35a7..efc11c4362fc7c7a72bc4915ddfde5346db30862 100644 (file)
@@ -36,6 +36,7 @@ namespace glws {
 static Display *display = NULL;
 static int screen = 0;
 
+
 class GlxVisual : public Visual
 {
 public:
@@ -51,6 +52,42 @@ public:
 };
 
 
+static void describeEvent(const XEvent &event) {
+    if (0) {
+        switch (event.type) {
+        case ConfigureNotify:
+            std::cerr << "ConfigureNotify";
+            break;
+        case Expose:
+            std::cerr << "Expose";
+            break;
+        case KeyPress:
+            std::cerr << "KeyPress";
+            break;
+        case MapNotify:
+            std::cerr << "MapNotify";
+            break;
+        case ReparentNotify:
+            std::cerr << "ReparentNotify";
+            break;
+        default:
+            std::cerr << "Event " << event.type;
+        }
+        std::cerr << " " << event.xany.window << "\n";
+    }
+}
+
+static void waitForEvent(Window window, int type) {
+    XFlush(display);
+    XEvent event;
+    do {
+        XNextEvent(display, &event);
+        describeEvent(event);
+    } while (event.type != type ||
+             event.xany.window != window);
+}
+
+
 class GlxDrawable : public Drawable
 {
 public:
@@ -99,6 +136,9 @@ public:
             None, (char **)NULL, 0, &sizehints);
 
         XMapWindow(display, window);
+
+        waitForEvent(window, Expose);
+        glXWaitX();
     }
 
     ~GlxDrawable() {
@@ -108,8 +148,18 @@ public:
     void
     resize(int w, int h) {
         glXWaitGL();
+
+        // We need to ensure that pending events are processed here, and XSync
+        // with discard = True guarantees that, but it appears the limited
+        // event processing we do so far is sufficient
+        //XSync(display, True);
+
         Drawable::resize(w, h);
+
         XResizeWindow(display, window, w, h);
+
+        waitForEvent(window, ConfigureNotify);
+
         glXWaitX();
     }
 
@@ -220,10 +270,11 @@ public:
 
     bool
     processEvents(void) {
+        XFlush(display);
         while (XPending(display) > 0) {
             XEvent event;
             XNextEvent(display, &event);
-            // TODO
+            describeEvent(event);
         }
         return true;
     }