Blob Blame History Raw
diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index 6f9c2c8b8cf..c1c15013a58 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -589,7 +589,7 @@ struct __DRIdamageExtensionRec {
  * SWRast Loader extension.
  */
 #define __DRI_SWRAST_LOADER "DRI_SWRastLoader"
-#define __DRI_SWRAST_LOADER_VERSION 4
+#define __DRI_SWRAST_LOADER_VERSION 5
 struct __DRIswrastLoaderExtensionRec {
     __DRIextension base;
 
@@ -649,6 +649,23 @@ struct __DRIswrastLoaderExtensionRec {
     void (*getImageShm)(__DRIdrawable *readable,
                         int x, int y, int width, int height,
                         int shmid, void *loaderPrivate);
+
+   /**
+     * Put shm image to drawable (v2)
+     *
+     * The original version fixes srcx/y to 0, and expected
+     * the offset to be adjusted. This version allows src x,y
+     * to not be included in the offset. This is needed to
+     * avoid certain overflow checks in the X server, that
+     * result in lost rendering.
+     *
+     * \since 5
+     */
+    void (*putImageShm2)(__DRIdrawable *drawable, int op,
+                         int x, int y,
+                         int width, int height, int stride,
+                         int shmid, char *shmaddr, unsigned offset,
+                         void *loaderPrivate);
 };
 
 /**
diff --git a/src/gallium/include/state_tracker/drisw_api.h b/src/gallium/include/state_tracker/drisw_api.h
index e365ab81f18..4b5d36c1797 100644
--- a/src/gallium/include/state_tracker/drisw_api.h
+++ b/src/gallium/include/state_tracker/drisw_api.h
@@ -20,7 +20,7 @@ struct drisw_loader_funcs
    void (*put_image2) (struct dri_drawable *dri_drawable,
                        void *data, int x, int y, unsigned width, unsigned height, unsigned stride);
    void (*put_image_shm) (struct dri_drawable *dri_drawable,
-                          int shmid, char *shmaddr, unsigned offset,
+                          int shmid, char *shmaddr, unsigned offset, unsigned offset_x,
                           int x, int y, unsigned width, unsigned height, unsigned stride);
 };
 
diff --git a/src/gallium/state_trackers/dri/drisw.c b/src/gallium/state_trackers/dri/drisw.c
index 5a0d2e1354d..927ac39ce65 100644
--- a/src/gallium/state_trackers/dri/drisw.c
+++ b/src/gallium/state_trackers/dri/drisw.c
@@ -79,15 +79,21 @@ put_image2(__DRIdrawable *dPriv, void *data, int x, int y,
 
 static inline void
 put_image_shm(__DRIdrawable *dPriv, int shmid, char *shmaddr,
-              unsigned offset, int x, int y,
+              unsigned offset, unsigned offset_x, int x, int y,
               unsigned width, unsigned height, unsigned stride)
 {
    __DRIscreen *sPriv = dPriv->driScreenPriv;
    const __DRIswrastLoaderExtension *loader = sPriv->swrast_loader;
 
-   loader->putImageShm(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP,
-                       x, y, width, height, stride,
-                       shmid, shmaddr, offset, dPriv->loaderPrivate);
+   /* if we have the newer interface, don't have to add the offset_x here. */
+   if (loader->base.version > 4 && loader->putImageShm2)
+     loader->putImageShm2(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP,
+                          x, y, width, height, stride,
+                          shmid, shmaddr, offset, dPriv->loaderPrivate);
+   else
+     loader->putImageShm(dPriv, __DRI_SWRAST_IMAGE_OP_SWAP,
+                         x, y, width, height, stride,
+                         shmid, shmaddr, offset + offset_x, dPriv->loaderPrivate);
 }
 
 static inline void
@@ -179,12 +185,13 @@ drisw_put_image2(struct dri_drawable *drawable,
 static inline void
 drisw_put_image_shm(struct dri_drawable *drawable,
                     int shmid, char *shmaddr, unsigned offset,
+                    unsigned offset_x,
                     int x, int y, unsigned width, unsigned height,
                     unsigned stride)
 {
    __DRIdrawable *dPriv = drawable->dPriv;
 
-   put_image_shm(dPriv, shmid, shmaddr, offset, x, y, width, height, stride);
+   put_image_shm(dPriv, shmid, shmaddr, offset, offset_x, x, y, width, height, stride);
 }
 
 static inline void
diff --git a/src/gallium/winsys/sw/dri/dri_sw_winsys.c b/src/gallium/winsys/sw/dri/dri_sw_winsys.c
index cd44b036c6f..c0200f939b6 100644
--- a/src/gallium/winsys/sw/dri/dri_sw_winsys.c
+++ b/src/gallium/winsys/sw/dri/dri_sw_winsys.c
@@ -244,15 +244,20 @@ dri_sw_displaytarget_display(struct sw_winsys *ws,
    unsigned width, height, x = 0, y = 0;
    unsigned blsize = util_format_get_blocksize(dri_sw_dt->format);
    unsigned offset = 0;
+   unsigned offset_x = 0;
    char *data = dri_sw_dt->data;
-
+   bool is_shm = dri_sw_dt->shmid != -1;
    /* Set the width to 'stride / cpp'.
     *
     * PutImage correctly clips to the width of the dst drawable.
     */
    if (box) {
-      offset = (dri_sw_dt->stride * box->y) + box->x * blsize;
+      offset = dri_sw_dt->stride * box->y;
+      offset_x = box->x * blsize;
       data += offset;
+      /* don't add x offset for shm, the put_image_shm will deal with it */
+      if (!is_shm)
+         data += offset_x;
       x = box->x;
       y = box->y;
       width = box->width;
@@ -262,8 +267,8 @@ dri_sw_displaytarget_display(struct sw_winsys *ws,
       height = dri_sw_dt->height;
    }
 
-   if (dri_sw_dt->shmid != -1) {
-      dri_sw_ws->lf->put_image_shm(dri_drawable, dri_sw_dt->shmid, dri_sw_dt->data, offset,
+   if (is_shm) {
+      dri_sw_ws->lf->put_image_shm(dri_drawable, dri_sw_dt->shmid, dri_sw_dt->data, offset, offset_x,
                                    x, y, width, height, dri_sw_dt->stride);
       return;
    }
diff --git a/src/glx/drisw_glx.c b/src/glx/drisw_glx.c
index a2777100a32..fa0f0d7bf6f 100644
--- a/src/glx/drisw_glx.c
+++ b/src/glx/drisw_glx.c
@@ -201,7 +201,8 @@ bytes_per_line(unsigned pitch_bits, unsigned mul)
 
 static void
 swrastXPutImage(__DRIdrawable * draw, int op,
-                int x, int y, int w, int h, int stride,
+                int srcx, int srcy, int x, int y,
+                int w, int h, int stride,
                 int shmid, char *data, void *loaderPrivate)
 {
    struct drisw_drawable *pdp = loaderPrivate;
@@ -235,12 +236,12 @@ swrastXPutImage(__DRIdrawable * draw, int op,
    if (pdp->shminfo.shmid >= 0) {
       ximage->width = ximage->bytes_per_line / ((ximage->bits_per_pixel + 7)/ 8);
       ximage->height = h;
-      XShmPutImage(dpy, drawable, gc, ximage, 0, 0, x, y, w, h, False);
+      XShmPutImage(dpy, drawable, gc, ximage, srcx, srcy, x, y, w, h, False);
       XSync(dpy, False);
    } else {
       ximage->width = w;
       ximage->height = h;
-      XPutImage(dpy, drawable, gc, ximage, 0, 0, x, y, w, h);
+      XPutImage(dpy, drawable, gc, ximage, srcx, srcy, x, y, w, h);
    }
    ximage->data = NULL;
 }
@@ -254,7 +255,21 @@ swrastPutImageShm(__DRIdrawable * draw, int op,
    struct drisw_drawable *pdp = loaderPrivate;
 
    pdp->shminfo.shmaddr = shmaddr;
-   swrastXPutImage(draw, op, x, y, w, h, stride, shmid,
+   swrastXPutImage(draw, op, 0, 0, x, y, w, h, stride, shmid,
+                   shmaddr + offset, loaderPrivate);
+}
+
+static void
+swrastPutImageShm2(__DRIdrawable * draw, int op,
+                   int x, int y,
+                   int w, int h, int stride,
+		   int shmid, char *shmaddr, unsigned offset,
+		   void *loaderPrivate)
+{
+   struct drisw_drawable *pdp = loaderPrivate;
+
+   pdp->shminfo.shmaddr = shmaddr;
+   swrastXPutImage(draw, op, x, 0, x, y, w, h, stride, shmid,
                    shmaddr + offset, loaderPrivate);
 }
 
@@ -263,7 +278,7 @@ swrastPutImage2(__DRIdrawable * draw, int op,
                 int x, int y, int w, int h, int stride,
                 char *data, void *loaderPrivate)
 {
-   swrastXPutImage(draw, op, x, y, w, h, stride, -1,
+   swrastXPutImage(draw, op, 0, 0, x, y, w, h, stride, -1,
                    data, loaderPrivate);
 }
 
@@ -272,7 +287,7 @@ swrastPutImage(__DRIdrawable * draw, int op,
                int x, int y, int w, int h,
                char *data, void *loaderPrivate)
 {
-   swrastXPutImage(draw, op, x, y, w, h, 0, -1,
+   swrastXPutImage(draw, op, 0, 0, x, y, w, h, 0, -1,
                    data, loaderPrivate);
 }
 
@@ -340,7 +355,7 @@ swrastGetImageShm(__DRIdrawable * read,
 }
 
 static const __DRIswrastLoaderExtension swrastLoaderExtension_shm = {
-   .base = {__DRI_SWRAST_LOADER, 4 },
+   .base = {__DRI_SWRAST_LOADER, 5 },
 
    .getDrawableInfo     = swrastGetDrawableInfo,
    .putImage            = swrastPutImage,
@@ -349,6 +364,7 @@ static const __DRIswrastLoaderExtension swrastLoaderExtension_shm = {
    .getImage2           = swrastGetImage2,
    .putImageShm         = swrastPutImageShm,
    .getImageShm         = swrastGetImageShm,
+   .putImageShm2        = swrastPutImageShm2,
 };
 
 static const __DRIextension *loader_extensions_shm[] = {