]> git.cworth.org Git - apitrace/commitdiff
Cleanup X11 event handling.
authorJosé Fonseca <jfonseca@vmware.com>
Wed, 26 Oct 2011 17:43:21 +0000 (18:43 +0100)
committerJosé Fonseca <jfonseca@vmware.com>
Wed, 26 Oct 2011 17:43:21 +0000 (18:43 +0100)
Fixes an infinite loop on GlxDrawable::show() in certain traces.

glretrace_main.cpp
glretrace_wgl.cpp
glws_cocoa.mm
glws_glx.cpp
glws_wgl.cpp

index 89ead9d5261b37d8a0658031b422f796c0e68d30..9212ff61fb8cb42f3a5e20b435c61f5c1c822a38 100644 (file)
@@ -111,8 +111,8 @@ updateDrawable(int width, int height) {
     }
 
     if (drawable->visible &&
-        width  <= glretrace::drawable->width &&
-        height <= glretrace::drawable->height) {
+        width  <= drawable->width &&
+        height <= drawable->height) {
         return;
     }
 
@@ -123,10 +123,9 @@ updateDrawable(int width, int height) {
         return;
     }
 
-    glretrace::drawable->resize(width, height);
-    if (!drawable->visible) {
-        drawable->show();
-    }
+    drawable->resize(width, height);
+    drawable->show();
+
     glScissor(0, 0, width, height);
 }
 
index 34b48d013ccda904d2938b0dab52306f24880d00..3e978d27907661f2f1befa3cb7efdf7df39719ad 100644 (file)
@@ -184,6 +184,7 @@ static void retrace_wglCreatePbufferARB(Trace::Call &call) {
     glws::Drawable *drawable = glws::createDrawable(glretrace::visual);
 
     drawable->resize(iWidth, iHeight);
+    drawable->show();
 
     pbuffer_map[orig_pbuffer] = drawable;
 }
index a35dcf506370d0d8215305572897b9576f8694ee..493cb4a58dc54b1c3af3e0a9da4243298d2b70a2 100644 (file)
@@ -104,7 +104,9 @@ public:
 
     void
     resize(int w, int h) {
-        Drawable::resize(w, h);
+        if (w == width && h == height) {
+            return;
+        }
 
         [window setContentSize:NSMakeSize(w, h)];
 
@@ -114,13 +116,18 @@ public:
             [currentContext setView:[window contentView]];
             [currentContext makeCurrentContext];
         }
+
+        Drawable::resize(w, h);
     }
 
     void show(void) {
-        if (!visible) {
-            // TODO
-            Drawable::show();
+        if (visible) {
+            return;
         }
+
+        // TODO
+
+        Drawable::show();
     }
 
     void swapBuffers(void) {
index d26066af650b80716895f944eb66613cdf0fd6fa..3c49de81309dd25983da7a3eca51efee5d14f3a1 100644 (file)
@@ -87,17 +87,6 @@ static void describeEvent(const XEvent &event) {
     }
 }
 
-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:
@@ -115,7 +104,7 @@ public:
         attr.background_pixel = 0;
         attr.border_pixel = 0;
         attr.colormap = XCreateColormap(display, root, visinfo->visual, AllocNone);
-        attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask;
+        attr.event_mask = StructureNotifyMask;
 
         unsigned long mask;
         mask = CWBackPixel | CWBorderPixel | CWColormap | CWEventMask;
@@ -148,12 +137,24 @@ public:
         glXWaitX();
     }
 
+    void waitForEvent(int type) {
+        XEvent event;
+        do {
+            XWindowEvent(display, window, StructureNotifyMask, &event);
+            describeEvent(event);
+        } while (event.type != type);
+    }
+
     ~GlxDrawable() {
         XDestroyWindow(display, window);
     }
 
     void
     resize(int w, int h) {
+        if (w == width && h == height) {
+            return;
+        }
+
         glXWaitGL();
 
         // We need to ensure that pending events are processed here, and XSync
@@ -166,27 +167,31 @@ public:
         XResizeWindow(display, window, w, h);
 
         // Tell the window manager to respect the requested size
-        XSizeHints *size_hints;
-        size_hints = XAllocSizeHints();
-        size_hints->max_width  = size_hints->min_width  = w;
-        size_hints->max_height = size_hints->min_height = h;
-        size_hints->flags = PMinSize | PMaxSize;
-        XSetWMNormalHints(display, window, size_hints);
-        XFree(size_hints);
+        XSizeHints size_hints;
+        size_hints.max_width  = size_hints.min_width  = w;
+        size_hints.max_height = size_hints.min_height = h;
+        size_hints.flags = PMinSize | PMaxSize;
+        XSetWMNormalHints(display, window, &size_hints);
 
-        waitForEvent(window, ConfigureNotify);
+        waitForEvent(ConfigureNotify);
 
         glXWaitX();
     }
 
     void show(void) {
-        if (!visible) {
-            XMapWindow(display, window);
+        if (visible) {
+            return;
+        }
 
-            waitForEvent(window, Expose);
+        glXWaitGL();
 
-            Drawable::show();
-        }
+        XMapWindow(display, window);
+
+        waitForEvent(MapNotify);
+
+        glXWaitX();
+
+        Drawable::show();
     }
 
     void swapBuffers(void) {
@@ -332,7 +337,6 @@ makeCurrent(Drawable *drawable, Context *context)
 
 bool
 processEvents(void) {
-    XFlush(display);
     while (XPending(display) > 0) {
         XEvent event;
         XNextEvent(display, &event);
index adc99578e3b7aa9cd885c2de41458301856dec52..1958b5fc22a193aa8f64cc116231631806768be9 100644 (file)
@@ -136,21 +136,28 @@ public:
     
     void
     resize(int w, int h) {
-        Drawable::resize(w, h);
+        if (w == width && h == height) {
+            return;
+        }
+
         RECT rClient, rWindow;
         GetClientRect(hWnd, &rClient);
         GetWindowRect(hWnd, &rWindow);
         w += (rWindow.right  - rWindow.left) - rClient.right;
         h += (rWindow.bottom - rWindow.top)  - rClient.bottom;
         SetWindowPos(hWnd, NULL, rWindow.left, rWindow.top, w, h, SWP_NOMOVE);
+
+        Drawable::resize(w, h);
     }
 
     void show(void) {
-        if (!visible) {
-            ShowWindow(hWnd, SW_SHOW);
-
-            Drawable::show();
+        if (visible) {
+            return;
         }
+
+        ShowWindow(hWnd, SW_SHOW);
+
+        Drawable::show();
     }
 
     void swapBuffers(void) {