ws/xlib: manage the GC internally
authorKeith Whitwell <keithw@vmware.com>
Tue, 9 Mar 2010 11:39:40 +0000 (11:39 +0000)
committerKeith Whitwell <keithw@vmware.com>
Tue, 9 Mar 2010 11:39:40 +0000 (11:39 +0000)
No need for the user of this winsys to supply/manage the x11 gc for
us.

src/gallium/include/state_tracker/xlib_sw_winsys.h
src/gallium/state_trackers/egl/x11/native_ximage.c
src/gallium/state_trackers/glx/xlib/xm_api.c
src/gallium/winsys/xlib/xlib_sw_winsys.c

index 915a7b37fb5a03504ad036ec625085ed85682700..3cb679426d619dca8da808e9b56431e18e66bd30 100644 (file)
@@ -16,7 +16,6 @@ struct xlib_drawable {
    Visual *visual;
    int depth;
    Drawable drawable;
-   GC gc;                       /* temporary? */
 };
 
 
index 0006b0caca4ca109c11903ff6cef2bc83689e0b2..0aa25ead253f2d493175566cacc6c9616282a477 100644 (file)
@@ -73,8 +73,6 @@ struct ximage_surface {
    XVisualInfo visual;
    struct ximage_display *xdpy;
 
-   GC gc;
-
    unsigned int server_stamp;
    unsigned int client_stamp;
    int width, height;
@@ -155,7 +153,6 @@ ximage_surface_alloc_buffer(struct native_surface *nsurf,
       xbuf->xdraw.visual = xsurf->visual.visual;
       xbuf->xdraw.depth = xsurf->visual.depth;
       xbuf->xdraw.drawable = xsurf->drawable;
-      xbuf->xdraw.gc = xsurf->gc;
    }
 
    /* clean up the buffer if allocation failed */
@@ -373,8 +370,6 @@ ximage_surface_destroy(struct native_surface *nsurf)
    for (i = 0; i < NUM_NATIVE_ATTACHMENTS; i++)
       ximage_surface_free_buffer(&xsurf->base, i);
 
-   if (xsurf->type != XIMAGE_SURFACE_TYPE_PBUFFER)
-      XFreeGC(xsurf->xdpy->dpy, xsurf->gc);
    free(xsurf);
 }
 
@@ -400,13 +395,6 @@ ximage_display_create_surface(struct native_display *ndpy,
    if (xsurf->type != XIMAGE_SURFACE_TYPE_PBUFFER) {
       xsurf->drawable = drawable;
       xsurf->visual = *xconf->visual;
-
-      xsurf->gc = XCreateGC(xdpy->dpy, xsurf->drawable, 0, NULL);
-      if (!xsurf->gc) {
-         free(xsurf);
-         return NULL;
-      }
-
       /* initialize the geometry */
       ximage_surface_update_buffers(&xsurf->base, 0x0);
    }
index d8aa59b3b7cde7672efd31981d8482fb753b3a66..cf9a3992091981f615b95f5c976ff082329c712b 100644 (file)
@@ -446,8 +446,6 @@ xmesa_free_buffer(XMesaBuffer buffer)
          /* Unreference.  If count = zero we'll really delete the buffer */
          _mesa_reference_framebuffer(&fb, NULL);
 
-         XFreeGC(b->xm_visual->display, b->ws.gc);
-
          free(buffer);
 
          return;
@@ -524,16 +522,6 @@ initialize_visual_and_buffer(XMesaVisual v, XMesaBuffer b,
       printf("X/Mesa bits per pixel = %d\n", v->BitsPerPixel);
    }
 
-   if (b && window) {
-      /* these should have been set in create_xmesa_buffer */
-      ASSERT(b->ws.drawable == window);
-
-
-      /* X11 graphics context */
-      b->ws.gc = XCreateGC( v->display, window, 0, NULL );
-      XSetFunction( v->display, b->ws.gc, GXcopy );
-   }
-
    return GL_TRUE;
 }
 
index 9a4ae39aeb99ef6e50376daf305a5754ab7d2a2d..846d79c0eb5c685b431e55ce27239144c973d9fe 100644 (file)
@@ -73,6 +73,12 @@ struct xm_displaytarget
    Display *display;
    Visual *visual;
    XImage *tempImage;
+   GC gc;
+
+   /* This is the last drawable that this display target was presented
+    * against.  May need to recreate gc, tempImage when this changes??
+    */
+   Drawable drawable;
 
    XShmSegmentInfo shminfo;
    int shm;
@@ -260,6 +266,12 @@ xm_displaytarget_destroy(struct sw_winsys *ws,
          FREE(xm_dt->data);
    }
 
+   if (xm_dt->tempImage)
+      XDestroyImage(xm_dt->tempImage);
+
+   if (xm_dt->gc)
+      XFreeGC(xm_dt->display, xm_dt->gc);
+
    FREE(xm_dt);
 }
 
@@ -272,10 +284,11 @@ void
 xlib_sw_display(struct xlib_drawable *xlib_drawable,
                 struct sw_displaytarget *dt)
 {
-   XImage *ximage;
-   struct xm_displaytarget *xm_dt = xm_displaytarget(dt);
    static boolean no_swap = 0;
    static boolean firsttime = 1;
+   struct xm_displaytarget *xm_dt = xm_displaytarget(dt);
+   Display *display = xm_dt->display;
+   XImage *ximage;
 
    if (firsttime) {
       no_swap = getenv("SP_NO_RAST") != NULL;
@@ -285,8 +298,21 @@ xlib_sw_display(struct xlib_drawable *xlib_drawable,
    if (no_swap)
       return;
 
-   if (xm_dt->tempImage == NULL)
-   {
+   if (xm_dt->drawable != xlib_drawable->drawable) {
+      if (xm_dt->gc) {
+         XFreeGC( display, xm_dt->gc );
+         xm_dt->gc = NULL;
+      }
+
+      if (xm_dt->tempImage) {
+         XDestroyImage( xm_dt->tempImage );
+         xm_dt->tempImage = NULL;
+      }
+
+      xm_dt->drawable = xlib_drawable->drawable;
+   }
+
+   if (xm_dt->tempImage == NULL) {
       assert(util_format_get_blockwidth(xm_dt->format) == 1);
       assert(util_format_get_blockheight(xm_dt->format) == 1);
       alloc_ximage(xm_dt, xlib_drawable,
@@ -296,6 +322,11 @@ xlib_sw_display(struct xlib_drawable *xlib_drawable,
          return;
    }
 
+   if (xm_dt->gc == NULL) {
+      xm_dt->gc = XCreateGC( display, xlib_drawable->drawable, 0, NULL );
+      XSetFunction( display, xm_dt->gc, GXcopy );
+   }
+
 #ifdef USE_XSHM
    if (xm_dt->shm)
    {
@@ -303,7 +334,7 @@ xlib_sw_display(struct xlib_drawable *xlib_drawable,
       ximage->data = xm_dt->data;
 
       /* _debug_printf("XSHM\n"); */
-      XShmPutImage(xm_dt->display, xlib_drawable->drawable, xlib_drawable->gc,
+      XShmPutImage(xm_dt->display, xlib_drawable->drawable, xm_dt->gc,
                    ximage, 0, 0, 0, 0, xm_dt->width, xm_dt->height, False);
    }
    else
@@ -323,7 +354,7 @@ xlib_sw_display(struct xlib_drawable *xlib_drawable,
       ximage->bytes_per_line = xm_dt->stride;
 
       /* _debug_printf("XPUT\n"); */
-      XPutImage(xm_dt->display, xlib_drawable->drawable, xlib_drawable->gc,
+      XPutImage(xm_dt->display, xlib_drawable->drawable, xm_dt->gc,
                 ximage, 0, 0, 0, 0, xm_dt->width, xm_dt->height);
    }
 }