From: José Fonseca Date: Wed, 26 Oct 2011 17:43:21 +0000 (+0100) Subject: Cleanup X11 event handling. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=79ae5703b55b13194e1dc50db7f5813d107e8806;p=apitrace Cleanup X11 event handling. Fixes an infinite loop on GlxDrawable::show() in certain traces. --- diff --git a/glretrace_main.cpp b/glretrace_main.cpp index 89ead9d..9212ff6 100644 --- a/glretrace_main.cpp +++ b/glretrace_main.cpp @@ -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); } diff --git a/glretrace_wgl.cpp b/glretrace_wgl.cpp index 34b48d0..3e978d2 100644 --- a/glretrace_wgl.cpp +++ b/glretrace_wgl.cpp @@ -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; } diff --git a/glws_cocoa.mm b/glws_cocoa.mm index a35dcf5..493cb4a 100644 --- a/glws_cocoa.mm +++ b/glws_cocoa.mm @@ -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) { diff --git a/glws_glx.cpp b/glws_glx.cpp index d26066a..3c49de8 100644 --- a/glws_glx.cpp +++ b/glws_glx.cpp @@ -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); diff --git a/glws_wgl.cpp b/glws_wgl.cpp index adc9957..1958b5f 100644 --- a/glws_wgl.cpp +++ b/glws_wgl.cpp @@ -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) {