intel: Allocate prog_data::[pull_]param deeper inside the compiler
[mesa.git] / src / mesa / drivers / x11 / xm_buffer.c
index 84e6fcd795c37bed9ab1dc7d47b915c5207cfda4..4d52169d777044611f65fa7a880985719919524d 100644 (file)
@@ -1,6 +1,5 @@
 /*
  * Mesa 3-D graphics library
- * Version:  6.5.2
  *
  * Copyright (C) 1999-2006  Brian Paul   All Rights Reserved.
  *
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
- * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
- * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
- * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
  */
 
 
@@ -203,7 +203,7 @@ alloc_back_buffer(XMesaBuffer b, GLuint width, GLuint height)
            _mesa_warning(NULL, "alloc_back_buffer: XCreateImage failed.\n");
             return;
         }
-         b->backxrb->ximage->data = (char *) MALLOC(b->backxrb->ximage->height
+         b->backxrb->ximage->data = malloc(b->backxrb->ximage->height
                                         * b->backxrb->ximage->bytes_per_line);
          if (!b->backxrb->ximage->data) {
             _mesa_warning(NULL, "alloc_back_buffer: MALLOC failed.\n");
@@ -235,7 +235,7 @@ alloc_back_buffer(XMesaBuffer b, GLuint width, GLuint height)
 
 
 static void
-xmesa_delete_renderbuffer(struct gl_renderbuffer *rb)
+xmesa_delete_renderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
 {
    /* XXX Note: the ximage or Pixmap attached to this renderbuffer
     * should probably get freed here, but that's currently done in
@@ -326,38 +326,37 @@ xmesa_new_renderbuffer(struct gl_context *ctx, GLuint name,
    struct xmesa_renderbuffer *xrb = CALLOC_STRUCT(xmesa_renderbuffer);
    if (xrb) {
       GLuint name = 0;
-      _mesa_init_renderbuffer(&xrb->Base, name);
+      _mesa_init_renderbuffer(&xrb->Base.Base, name);
 
-      xrb->Base.Delete = xmesa_delete_renderbuffer;
+      xrb->Base.Base.Delete = xmesa_delete_renderbuffer;
       if (backBuffer)
-         xrb->Base.AllocStorage = xmesa_alloc_back_storage;
+         xrb->Base.Base.AllocStorage = xmesa_alloc_back_storage;
       else
-         xrb->Base.AllocStorage = xmesa_alloc_front_storage;
+         xrb->Base.Base.AllocStorage = xmesa_alloc_front_storage;
 
-      xrb->Base.InternalFormat = GL_RGBA;
-      xrb->Base._BaseFormat = GL_RGBA;
-      xrb->Base.DataType = GL_UNSIGNED_BYTE;
-      xrb->Base.ClassID = XMESA_RENDERBUFFER;
+      xrb->Base.Base.InternalFormat = GL_RGBA;
+      xrb->Base.Base._BaseFormat = GL_RGBA;
+      xrb->Base.Base.ClassID = XMESA_RENDERBUFFER;
 
       switch (xmvis->undithered_pf) {
       case PF_8R8G8B:
          /* This will really only happen for pixmaps.  We'll access the
           * pixmap via a temporary XImage which will be 32bpp.
           */
-         xrb->Base.Format = MESA_FORMAT_XRGB8888;
+         xrb->Base.Base.Format = MESA_FORMAT_B8G8R8X8_UNORM;
          break;
       case PF_8A8R8G8B:
-         xrb->Base.Format = MESA_FORMAT_ARGB8888;
+         xrb->Base.Base.Format = MESA_FORMAT_B8G8R8A8_UNORM;
          break;
       case PF_8A8B8G8R:
-         xrb->Base.Format = MESA_FORMAT_RGBA8888_REV;
+         xrb->Base.Base.Format = MESA_FORMAT_R8G8B8A8_UNORM;
          break;
       case PF_5R6G5B:
-         xrb->Base.Format = MESA_FORMAT_RGB565;
+         xrb->Base.Base.Format = MESA_FORMAT_B5G6R5_UNORM;
          break;
       default:
          _mesa_warning(ctx, "Bad pixel format in xmesa_new_renderbuffer");
-         xrb->Base.Format = MESA_FORMAT_ARGB8888;
+         xrb->Base.Base.Format = MESA_FORMAT_B8G8R8A8_UNORM;
          break;
       }
 
@@ -410,12 +409,6 @@ xmesa_delete_framebuffer(struct gl_framebuffer *fb)
       }
    }
 
-   if (b->rowimage) {
-      free( b->rowimage->data );
-      b->rowimage->data = NULL;
-      XMesaDestroyImage( b->rowimage );
-   }
-
    _mesa_free_framebuffer_data(fb);
    free(fb);
 }
@@ -433,7 +426,7 @@ xmesa_MapRenderbuffer(struct gl_context *ctx,
 {
    struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
 
-   if (xrb->Base.ClassID == XMESA_RENDERBUFFER) {
+   if (xrb->Base.Base.ClassID == XMESA_RENDERBUFFER) {
       XImage *ximage = xrb->ximage;
 
       assert(!xrb->map_mode); /* only a single mapping allowed */
@@ -453,14 +446,43 @@ xmesa_MapRenderbuffer(struct gl_context *ctx,
       }
       else {
          /* this must be a pixmap/window renderbuffer */
+         int (*old_handler)(XMesaDisplay *, XErrorEvent *);
          int y2 = rb->Height - y - h;
 
          assert(xrb->pixmap);
 
+         /* Install error handler for XGetImage() in case the window
+          * isn't mapped.  If we fail we'll create a temporary XImage.
+          */
+         mesaXErrorFlag = 0;
+         old_handler = XSetErrorHandler(mesaHandleXError);
+
          /* read pixel data out of the pixmap/window into an XImage */
          ximage = XGetImage(xrb->Parent->display,
                             xrb->pixmap, x, y2, w, h,
                             AllPlanes, ZPixmap);
+
+         XSetErrorHandler(old_handler);
+
+         if (mesaXErrorFlag) {
+            /* create new, temporary XImage */
+            int bytes_per_line =
+               _mesa_format_row_stride(xrb->Base.Base.Format,
+                                       xrb->Base.Base.Width);
+            char *image = malloc(bytes_per_line *
+                                          xrb->Base.Base.Height);
+            ximage = XCreateImage(xrb->Parent->display,
+                                  xrb->Parent->xm_visual->visinfo->visual,
+                                  xrb->Parent->xm_visual->visinfo->depth,
+                                  ZPixmap, /* format */
+                                  0, /* offset */
+                                  image, /* data */
+                                  xrb->Base.Base.Width,
+                                  xrb->Base.Base.Height,
+                                  8, /* pad */
+                                  bytes_per_line);
+         }
+
          if (!ximage) {
             *mapOut = NULL;
             *rowStrideOut = 0;
@@ -495,7 +517,7 @@ xmesa_UnmapRenderbuffer(struct gl_context *ctx, struct gl_renderbuffer *rb)
 {
    struct xmesa_renderbuffer *xrb = xmesa_renderbuffer(rb);
 
-   if (xrb->Base.ClassID == XMESA_RENDERBUFFER) {
+   if (xrb->Base.Base.ClassID == XMESA_RENDERBUFFER) {
       XImage *ximage = xrb->ximage;
 
       if (!ximage) {