st/xorg: Work around cursor reference counting bugs in older X servers.
[mesa.git] / src / gallium / winsys / xlib / xlib_softpipe.c
index 49dbf443ca30dd583618ea3ba77b74035fa5d357..716338aef47f76b943a946b603cd6649f6fa26ad 100644 (file)
 #undef ASSERT
 #undef Elements
 
-#include "pipe/internal/p_winsys_screen.h"
+#include "util/u_simple_screen.h"
 #include "pipe/p_format.h"
 #include "pipe/p_context.h"
-#include "pipe/p_inlines.h"
+#include "util/u_inlines.h"
 #include "util/u_format.h"
 #include "util/u_math.h"
 #include "util/u_memory.h"
@@ -63,7 +63,7 @@ struct xm_buffer
 
    XImage *tempImage;
 #ifdef USE_XSHM
-   int shm;
+   boolean shm;         /** Is this a shared memory buffer? */
    XShmSegmentInfo shminfo;
 #endif
 };
@@ -152,7 +152,7 @@ alloc_shm_ximage(struct xm_buffer *b, struct xmesa_buffer *xmb,
                                   &b->shminfo,
                                   width, height);
    if (b->tempImage == NULL) {
-      b->shm = 0;
+      b->shm = FALSE;
       return;
    }
 
@@ -169,12 +169,12 @@ alloc_shm_ximage(struct xm_buffer *b, struct xmesa_buffer *xmb,
       mesaXErrorFlag = 0;
       XDestroyImage(b->tempImage);
       b->tempImage = NULL;
-      b->shm = 0;
+      b->shm = FALSE;
       (void) XSetErrorHandler(old_handler);
       return;
    }
 
-   b->shm = 1;
+   b->shm = TRUE;
 }
 
 #endif /* USE_XSHM */
@@ -222,12 +222,13 @@ xm_buffer_destroy(struct pipe_buffer *buf)
          oldBuf->shminfo.shmaddr = (char *) -1;
       }
 
+      if (oldBuf->shm) {
+         oldBuf->data = NULL;
+      }
+
       if (oldBuf->tempImage) {
-         if (oldBuf->data == oldBuf->tempImage->data) {
-            /* oldBuf->data points at the xshm memory which we'll now free */
-            oldBuf->data = NULL;
-         }
          XDestroyImage(oldBuf->tempImage);
+         oldBuf->tempImage = NULL;
       }
 #endif
 
@@ -342,10 +343,8 @@ xm_buffer_create(struct pipe_winsys *pws,
    buffer->base.usage = usage;
    buffer->base.size = size;
 
-   if (buffer->data == NULL) {
-      /* align to 16-byte multiple for Cell */
-      buffer->data = align_malloc(size, max(alignment, 16));
-   }
+   /* align to 16-byte multiple for Cell */
+   buffer->data = align_malloc(size, max(alignment, 16));
 
    return &buffer->base;
 }
@@ -499,28 +498,9 @@ fail:
 }
 
 
-static struct pipe_context *
-xlib_create_softpipe_context( struct pipe_screen *screen,
-                              void *context_private )
-{
-   struct pipe_context *pipe;
-   
-   pipe = softpipe_create(screen);
-   if (pipe == NULL)
-      goto fail;
-
-   pipe->priv = context_private;
-   return pipe;
-
-fail:
-   /* Free stuff here */
-   return NULL;
-}
-
 struct xm_driver xlib_softpipe_driver = 
 {
    .create_pipe_screen = xlib_create_softpipe_screen,
-   .create_pipe_context = xlib_create_softpipe_context,
    .display_surface = xlib_softpipe_display_surface
 };