Revision: 294 http://trac.macosforge.org/projects/xquartz/changeset/294 Author: gstaplin@apple.com Date: 2009-03-07 20:03:12 -0800 (Sat, 07 Mar 2009) Log Message: ----------- Add a new test that fails due to surface destruction events being dispatched when a window is withdrawn. I'm not sure yet why this occurs, but it's obviously wrong. triangle_glx_withdraw_remap starts when you type a key with the window active. This is the type of unexpected side effect I thought might occur when I fixed the surface destruction events. Though I didn't anticipate this particular failure. I found this while running the glut tests suite. Modified Paths: -------------- AppleSGLX/trunk/tests/tests.mk AppleSGLX/trunk/tests/triangle_glx/triangle_glx.mk Added Paths: ----------- AppleSGLX/trunk/tests/triangle_glx/triangle_glx_withdraw_remap.c Modified: AppleSGLX/trunk/tests/tests.mk =================================================================== --- AppleSGLX/trunk/tests/tests.mk 2009-03-07 23:04:22 UTC (rev 293) +++ AppleSGLX/trunk/tests/tests.mk 2009-03-08 04:03:12 UTC (rev 294) @@ -33,6 +33,6 @@ $(TEST_BUILD_DIR)/multisample_glx \ $(TEST_BUILD_DIR)/glthreads \ $(TEST_BUILD_DIR)/triangle_glx_surface \ - $(TEST_BUILD_DIR)/triangle_glx_surface-2 + $(TEST_BUILD_DIR)/triangle_glx_surface-2 \ + $(TEST_BUILD_DIR)/triangle_glx_withdraw_remap - Modified: AppleSGLX/trunk/tests/triangle_glx/triangle_glx.mk =================================================================== --- AppleSGLX/trunk/tests/triangle_glx/triangle_glx.mk 2009-03-07 23:04:22 UTC (rev 293) +++ AppleSGLX/trunk/tests/triangle_glx/triangle_glx.mk 2009-03-08 04:03:12 UTC (rev 294) @@ -6,3 +6,6 @@ $(TEST_BUILD_DIR)/triangle_glx_surface-2: tests/triangle_glx/triangle_glx_surface-2.c $(LIBGL) $(CC) tests/triangle_glx/triangle_glx_surface-2.c -Iinclude -o $(TEST_BUILD_DIR)/triangle_glx_surface-2 $(LINK_TEST) + +$(TEST_BUILD_DIR)/triangle_glx_withdraw_remap: tests/triangle_glx/triangle_glx_withdraw_remap.c $(LIBGL) + $(CC) tests/triangle_glx/triangle_glx_withdraw_remap.c -Iinclude -o $(TEST_BUILD_DIR)/triangle_glx_withdraw_remap $(LINK_TEST) Added: AppleSGLX/trunk/tests/triangle_glx/triangle_glx_withdraw_remap.c =================================================================== --- AppleSGLX/trunk/tests/triangle_glx/triangle_glx_withdraw_remap.c (rev 0) +++ AppleSGLX/trunk/tests/triangle_glx/triangle_glx_withdraw_remap.c 2009-03-08 04:03:12 UTC (rev 294) @@ -0,0 +1,118 @@ +#include <stdio.h> +#include <stdlib.h> +#include <X11/Xlib.h> +#include <GL/glx.h> + +void draw(Display *dpy, Window w) { + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + glLoadIdentity(); + glColor3f(0.5f, 0.5f, 1.0f); + glBegin(GL_TRIANGLES); + glVertex3f( 0.0f, 1.0f, 0.0f); + glVertex3f(-1.0f,-1.0f, 0.0f); + glVertex3f( 1.0f,-1.0f, 0.0f); + glEnd(); + glXSwapBuffers(dpy, w); +} + +void resize(Display *dpy, Window w, int width, int height) { + glViewport(0, 0, width, height); + draw(dpy, w); +} + +void event_loop(Display *dpy) { + XEvent event; + + while(1) { + XNextEvent(dpy, &event); + + switch(event.type) { + case Expose: + draw(dpy, event.xexpose.window); + break; + + case KeyPress: + XWithdrawWindow(dpy, event.xkey.window, DefaultScreen(dpy)); + XFlush(dpy); + sleep(1); + XMapWindow(dpy, event.xkey.window); + draw(dpy, event.xkey.window); + XFlush(dpy); + break; + + case ConfigureNotify: + resize(dpy, event.xconfigure.window, event.xconfigure.width, + event.xconfigure.height); + break; + } + } +} + +int main() { + Display *dpy; + int attrib[] = { GLX_RGBA, + GLX_RED_SIZE, 8, + GLX_GREEN_SIZE, 8, + GLX_BLUE_SIZE, 8, + GLX_DEPTH_SIZE, 24, + GLX_DOUBLEBUFFER, + None }; + int eventbase, errorbase; + int screen; + Window root, win; + XVisualInfo *visinfo; + XSetWindowAttributes attr; + GLXContext ctx; + + dpy = XOpenDisplay(NULL); + + if(NULL == dpy) { + fprintf(stderr, "error: unable to open display!\n"); + return EXIT_FAILURE; + } + + if(!glXQueryExtension(dpy, &eventbase, &errorbase)) { + fprintf(stderr, "GLX is not available!\n"); + return EXIT_FAILURE; + } + + screen = DefaultScreen(dpy); + root = RootWindow(dpy, screen); + + visinfo = glXChooseVisual(dpy, screen, attrib); + + if(!visinfo) { + fprintf(stderr, "error: couldn't get an RGBA, double-buffered visual!\n"); + return EXIT_FAILURE; + } + + attr.background_pixel = 0; + attr.border_pixel = 0; + attr.colormap = XCreateColormap(dpy, root, visinfo->visual, AllocNone); + attr.event_mask = StructureNotifyMask | ExposureMask | KeyPressMask; + + win = XCreateWindow(dpy, root, /*x*/ 0, /*y*/ 0, + /*width*/ 400, /*height*/ 400, + 0, visinfo->depth, InputOutput, + visinfo->visual, + CWBackPixel | CWBorderPixel | CWColormap | CWEventMask, + &attr); + + ctx = glXCreateContext(dpy, visinfo, NULL, True ); + if(!ctx) { + fprintf(stderr, "error: glXCreateContext failed!\n"); + return EXIT_FAILURE; + } + + XMapWindow(dpy, win); + + glXMakeCurrent(dpy, win, ctx); + printf("passed dpy %p current dpy %p\n", (void *)dpy, + (void *)glXGetCurrentDisplay()); + + printf("Press any key to withdraw, sleep, and remap.\n"); + + event_loop(dpy); + + return EXIT_SUCCESS; +}