Mesa (master): xlib: add X error handler around XGetImage() call

Brian Paul brianp at kemper.freedesktop.org
Thu Jul 26 20:01:37 UTC 2012


Module: Mesa
Branch: master
Commit: a73e9207da188a65af50da279f1436566c4a8418
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=a73e9207da188a65af50da279f1436566c4a8418

Author: Brian Paul <brianp at vmware.com>
Date:   Wed Jul 25 16:23:42 2012 -0600

xlib: add X error handler around XGetImage() call

XGetImage() will generate a BadMatch error if the source window isn't
visible.  When that happens, create a new XImage.  Fixes piglit 'select'
test failures with swrast/xlib driver.

NOTE: This is a candidate for the 8.0 branch.

Reviewed-by: Ian Romanick <ian.d.romanick at intel.com>

---

 src/mesa/drivers/x11/xm_buffer.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)

diff --git a/src/mesa/drivers/x11/xm_buffer.c b/src/mesa/drivers/x11/xm_buffer.c
index a7395a3..eb68f94 100644
--- a/src/mesa/drivers/x11/xm_buffer.c
+++ b/src/mesa/drivers/x11/xm_buffer.c
@@ -446,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 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 = (char *) 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;




More information about the mesa-commit mailing list