From: José Fonseca Date: Tue, 17 May 2011 08:43:36 +0000 (+0100) Subject: Start with a smaller default window size; avoid race conditions on resize. X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=53d224eb79529d0c0f45fa4f68251822c9c7bb6a;p=apitrace Start with a smaller default window size; avoid race conditions on resize. 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. --- diff --git a/glws.hpp b/glws.hpp index bfd3448..3d3c83d 100644 --- 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; diff --git a/glws_glx.cpp b/glws_glx.cpp index 732f33d..efc11c4 100644 --- a/glws_glx.cpp +++ b/glws_glx.cpp @@ -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; }