glamor: Rely on nested mappings to handle src==dst and !prepare bugs.
authorEric Anholt <eric@anholt.net>
Fri, 10 Jan 2014 16:00:00 +0000 (00:00 +0800)
committerEric Anholt <eric@anholt.net>
Mon, 17 Mar 2014 21:30:56 +0000 (14:30 -0700)
Now that the core deals with that for us, we can avoid all this extra
carefulness.

Signed-off-by: Eric Anholt <eric@anholt.net>
Reviewed-by: Markus Wick <markus@selfnet.de>
16 files changed:
glamor/glamor_addtraps.c
glamor/glamor_copyarea.c
glamor/glamor_copyplane.c
glamor/glamor_core.c
glamor/glamor_fill.c
glamor/glamor_fillspans.c
glamor/glamor_getspans.c
glamor/glamor_picture.c
glamor/glamor_polyfillrect.c
glamor/glamor_polylines.c
glamor/glamor_priv.h
glamor/glamor_putimage.c
glamor/glamor_render.c
glamor/glamor_setspans.c
glamor/glamor_triangles.c
glamor/glamor_utils.h

index 655d87e..fdc0f42 100644 (file)
@@ -40,8 +40,8 @@ _glamor_add_traps(PicturePtr pPicture,
 
     if (glamor_prepare_access_picture(pPicture, GLAMOR_ACCESS_RW)) {
         fbAddTraps(pPicture, x_off, y_off, ntrap, traps);
-        glamor_finish_access_picture(pPicture, GLAMOR_ACCESS_RW);
     }
+    glamor_finish_access_picture(pPicture);
 
     return TRUE;
 }
index d03f708..ae3264d 100644 (file)
@@ -570,15 +570,13 @@ _glamor_copy_n_to_n(DrawablePtr src,
                     glamor_get_drawable_location(src),
                     glamor_get_drawable_location(dst));
 
-    if (glamor_prepare_access(dst, GLAMOR_ACCESS_RW)) {
-        if (dst == src || glamor_prepare_access(src, GLAMOR_ACCESS_RO)) {
-            fbCopyNtoN(src, dst, gc, box, nbox,
-                       dx, dy, reverse, upsidedown, bitplane, closure);
-            if (dst != src)
-                glamor_finish_access(src, GLAMOR_ACCESS_RO);
-        }
-        glamor_finish_access(dst, GLAMOR_ACCESS_RW);
+    if (glamor_prepare_access(dst, GLAMOR_ACCESS_RW) &&
+        glamor_prepare_access(src, GLAMOR_ACCESS_RO)) {
+        fbCopyNtoN(src, dst, gc, box, nbox,
+                   dx, dy, reverse, upsidedown, bitplane, closure);
     }
+    glamor_finish_access(src);
+    glamor_finish_access(dst);
     ok = TRUE;
 
  done:
index c42d33e..50e9cf3 100644 (file)
@@ -38,12 +38,13 @@ _glamor_copy_plane(DrawablePtr pSrc, DrawablePtr pDst, GCPtr pGC,
         && glamor_ddx_fallback_check_pixmap(pDst))
         goto fail;
 
-    glamor_prepare_access(pDst, GLAMOR_ACCESS_RW);
-    glamor_prepare_access(pSrc, GLAMOR_ACCESS_RO);
-    *pRegion = fbCopyPlane(pSrc, pDst, pGC, srcx, srcy, w, h,
-                           dstx, dsty, bitPlane);
-    glamor_finish_access(pSrc, GLAMOR_ACCESS_RO);
-    glamor_finish_access(pDst, GLAMOR_ACCESS_RW);
+    if (glamor_prepare_access(pDst, GLAMOR_ACCESS_RW) &&
+        glamor_prepare_access(pSrc, GLAMOR_ACCESS_RO)) {
+        *pRegion = fbCopyPlane(pSrc, pDst, pGC, srcx, srcy, w, h,
+                               dstx, dsty, bitPlane);
+    }
+    glamor_finish_access(pSrc);
+    glamor_finish_access(pDst);
     return TRUE;
 
  fail:
index a6a6039..61025c3 100644 (file)
@@ -304,7 +304,7 @@ glamor_fini_finish_access_shaders(ScreenPtr screen)
 }
 
 void
-glamor_finish_access(DrawablePtr drawable, glamor_access_t access_mode)
+glamor_finish_access(DrawablePtr drawable)
 {
     PixmapPtr pixmap = glamor_get_drawable_pixmap(drawable);
     glamor_pixmap_private *pixmap_priv = glamor_get_pixmap_private(pixmap);
@@ -370,7 +370,7 @@ glamor_prepare_access_gc(GCPtr gc)
         if (!glamor_prepare_access(&gc->tile.pixmap->drawable,
                                    GLAMOR_ACCESS_RO)) {
             if (gc->stipple)
-                glamor_finish_access(&gc->stipple->drawable, GLAMOR_ACCESS_RO);
+                glamor_finish_access(&gc->stipple->drawable);
             return FALSE;
         }
     }
@@ -384,9 +384,9 @@ void
 glamor_finish_access_gc(GCPtr gc)
 {
     if (gc->fillStyle == FillTiled)
-        glamor_finish_access(&gc->tile.pixmap->drawable, GLAMOR_ACCESS_RO);
+        glamor_finish_access(&gc->tile.pixmap->drawable);
     if (gc->stipple)
-        glamor_finish_access(&gc->stipple->drawable, GLAMOR_ACCESS_RO);
+        glamor_finish_access(&gc->stipple->drawable);
 }
 
 Bool
@@ -460,7 +460,7 @@ glamor_validate_gc(GCPtr gc, unsigned long changes, DrawablePtr drawable)
                     (&old_tile->drawable, GLAMOR_ACCESS_RO)) {
                     new_tile =
                         fb24_32ReformatTile(old_tile, drawable->bitsPerPixel);
-                    glamor_finish_access(&old_tile->drawable, GLAMOR_ACCESS_RO);
+                    glamor_finish_access(&old_tile->drawable);
                 }
             }
             if (new_tile) {
@@ -483,8 +483,7 @@ glamor_validate_gc(GCPtr gc, unsigned long changes, DrawablePtr drawable)
                 if (glamor_prepare_access
                     (&gc->tile.pixmap->drawable, GLAMOR_ACCESS_RW)) {
                     fbPadPixmap(gc->tile.pixmap);
-                    glamor_finish_access
-                        (&gc->tile.pixmap->drawable, GLAMOR_ACCESS_RW);
+                    glamor_finish_access(&gc->tile.pixmap->drawable);
                 }
             }
         }
@@ -500,7 +499,7 @@ glamor_validate_gc(GCPtr gc, unsigned long changes, DrawablePtr drawable)
          */
         if (glamor_prepare_access(&gc->stipple->drawable, GLAMOR_ACCESS_RW)) {
             fbValidateGC(gc, changes, drawable);
-            glamor_finish_access(&gc->stipple->drawable, GLAMOR_ACCESS_RW);
+            glamor_finish_access(&gc->stipple->drawable);
         }
     }
     else {
@@ -544,7 +543,7 @@ glamor_bitmap_to_region(PixmapPtr pixmap)
     if (!glamor_prepare_access(&pixmap->drawable, GLAMOR_ACCESS_RO))
         return NULL;
     ret = fbPixmapToRegion(pixmap);
-    glamor_finish_access(&pixmap->drawable, GLAMOR_ACCESS_RO);
+    glamor_finish_access(&pixmap->drawable);
     return ret;
 }
 
index a3f0f29..d91dafb 100644 (file)
@@ -112,13 +112,12 @@ glamor_fill(DrawablePtr drawable,
         x = 0;
         y = 0;
     }
-    if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
-        if (glamor_prepare_access_gc(gc)) {
-            fbFill(drawable, gc, x, y, width, height);
-            glamor_finish_access_gc(gc);
-        }
-        glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
+    if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW) &&
+        glamor_prepare_access_gc(gc)) {
+        fbFill(drawable, gc, x, y, width, height);
     }
+    glamor_finish_access_gc(gc);
+    glamor_finish_access(drawable);
 
     if (sub_pixmap != NULL) {
         if (gc->fillStyle != FillSolid) {
index 7261d28..8cbd79f 100644 (file)
@@ -79,13 +79,12 @@ _glamor_fill_spans(DrawablePtr drawable,
     }
     glamor_fallback("to %p (%c)\n", drawable,
                     glamor_get_drawable_location(drawable));
-    if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
-        if (glamor_prepare_access_gc(gc)) {
-            fbFillSpans(drawable, gc, n, points, widths, sorted);
-            glamor_finish_access_gc(gc);
-        }
-        glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
+    if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW) &&
+        glamor_prepare_access_gc(gc)) {
+        fbFillSpans(drawable, gc, n, points, widths, sorted);
     }
+    glamor_finish_access_gc(gc);
+    glamor_finish_access(drawable);
     ret = TRUE;
 
  done:
index ff58725..42df87f 100644 (file)
@@ -69,8 +69,8 @@ _glamor_get_spans(DrawablePtr drawable,
     ret = TRUE;
     if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RO)) {
         fbGetSpans(drawable, wmax, points, widths, count, dst);
-        glamor_finish_access(drawable, GLAMOR_ACCESS_RO);
     }
+    glamor_finish_access(drawable);
  done:
     return ret;
 }
index 8bbe2e9..5fdc5f9 100644 (file)
@@ -55,12 +55,12 @@ glamor_prepare_access_picture(PicturePtr picture, glamor_access_t access)
 }
 
 void
-glamor_finish_access_picture(PicturePtr picture, glamor_access_t access)
+glamor_finish_access_picture(PicturePtr picture)
 {
     if (!picture || !picture->pDrawable)
         return;
 
-    glamor_finish_access(picture->pDrawable, access);
+    glamor_finish_access(picture->pDrawable);
 }
 
 /* 
index a25fc4e..1e361a4 100644 (file)
@@ -96,13 +96,12 @@ _glamor_poly_fill_rect(DrawablePtr drawable,
 
     glamor_fallback(" to %p (%c)\n",
                     drawable, glamor_get_drawable_location(drawable));
-    if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
-        if (glamor_prepare_access_gc(gc)) {
-            fbPolyFillRect(drawable, gc, nrect, prect);
-            glamor_finish_access_gc(gc);
-        }
-        glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
+    if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW) &&
+        glamor_prepare_access_gc(gc)) {
+        fbPolyFillRect(drawable, gc, nrect, prect);
     }
+    glamor_finish_access_gc(gc);
+    glamor_finish_access(drawable);
     ret = TRUE;
 
  done:
index b941617..697fc9e 100644 (file)
@@ -105,13 +105,12 @@ _glamor_poly_lines(DrawablePtr drawable, GCPtr gc, int mode, int n,
         return FALSE;
 
     if (gc->lineWidth == 0) {
-        if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
-            if (glamor_prepare_access_gc(gc)) {
-                fbPolyLine(drawable, gc, mode, n, points);
-                glamor_finish_access_gc(gc);
-            }
-            glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
+        if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW) &&
+            glamor_prepare_access_gc(gc)) {
+            fbPolyLine(drawable, gc, mode, n, points);
         }
+        glamor_finish_access_gc(gc);
+        glamor_finish_access(drawable);
     }
     else {
  wide_line:
index 776de06..fed1597 100644 (file)
@@ -578,7 +578,7 @@ void glamor_copy_window(WindowPtr win, DDXPointRec old_origin,
 
 /* glamor_core.c */
 Bool glamor_prepare_access(DrawablePtr drawable, glamor_access_t access);
-void glamor_finish_access(DrawablePtr drawable, glamor_access_t access);
+void glamor_finish_access(DrawablePtr drawable);
 Bool glamor_prepare_access_window(WindowPtr window);
 void glamor_finish_access_window(WindowPtr window);
 Bool glamor_prepare_access_gc(GCPtr gc);
@@ -904,7 +904,7 @@ void glamor_set_window_pixmap(WindowPtr pWindow, PixmapPtr pPixmap);
 
 Bool glamor_prepare_access_picture(PicturePtr picture, glamor_access_t access);
 
-void glamor_finish_access_picture(PicturePtr picture, glamor_access_t access);
+void glamor_finish_access_picture(PicturePtr picture);
 
 void glamor_destroy_picture(PicturePtr picture);
 
index 702e89f..a4f97cd 100644 (file)
@@ -229,8 +229,8 @@ glamor_put_image_xybitmap(DrawablePtr drawable, GCPtr gc,
  fail:
     if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
         fbPutImage(drawable, gc, 1, x, y, w, h, left_pad, XYBitmap, bits);
-        glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
     }
+    glamor_finish_access(drawable);
 }
 #endif
 
index f93aac1..65f3778 100644 (file)
@@ -1784,22 +1784,17 @@ _glamor_composite(CARD8 op,
     if (mask && mask->pDrawable && !mask->transform)
         GET_SUB_PICTURE(mask, GLAMOR_ACCESS_RO);
 
-    if (glamor_prepare_access_picture(dest, GLAMOR_ACCESS_RW)) {
-        if (source_pixmap == dest_pixmap || glamor_prepare_access_picture
-            (source, GLAMOR_ACCESS_RO)) {
-            if (!mask || glamor_prepare_access_picture(mask, GLAMOR_ACCESS_RO)) {
-                fbComposite(op,
-                            source, mask, dest,
-                            x_source, y_source,
-                            x_mask, y_mask, x_dest, y_dest, width, height);
-                if (mask)
-                    glamor_finish_access_picture(mask, GLAMOR_ACCESS_RO);
-            }
-            if (source_pixmap != dest_pixmap)
-                glamor_finish_access_picture(source, GLAMOR_ACCESS_RO);
-        }
-        glamor_finish_access_picture(dest, GLAMOR_ACCESS_RW);
-    }
+    if (glamor_prepare_access_picture(dest, GLAMOR_ACCESS_RW) &&
+        glamor_prepare_access_picture(source, GLAMOR_ACCESS_RO) &&
+        glamor_prepare_access_picture(mask, GLAMOR_ACCESS_RO)) {
+        fbComposite(op,
+                    source, mask, dest,
+                    x_source, y_source,
+                    x_mask, y_mask, x_dest, y_dest, width, height);
+    }
+    glamor_finish_access_picture(mask);
+    glamor_finish_access_picture(source);
+    glamor_finish_access_picture(dest);
 
 #define PUT_SUB_PICTURE(p, access)             do {                            \
        if (sub_ ##p ##_pixmap != NULL) {                                       \
index 22fe88c..664f8ac 100644 (file)
@@ -88,8 +88,8 @@ _glamor_set_spans(DrawablePtr drawable, GCPtr gc, char *src,
                     drawable, glamor_get_drawable_location(drawable));
     if (glamor_prepare_access(drawable, GLAMOR_ACCESS_RW)) {
         fbSetSpans(drawable, gc, src, points, widths, numPoints, sorted);
-        glamor_finish_access(drawable, GLAMOR_ACCESS_RW);
     }
+    glamor_finish_access(drawable);
     ret = TRUE;
 
  done:
index 693eef1..b89cb2d 100644 (file)
@@ -41,16 +41,13 @@ _glamor_triangles(CARD8 op,
             || glamor_ddx_fallback_check_pixmap(pSrc->pDrawable)))
         return FALSE;
 
-    if (glamor_prepare_access_picture(pDst, GLAMOR_ACCESS_RW)) {
-        if (glamor_prepare_access_picture(pSrc, GLAMOR_ACCESS_RO)) {
-
-            fbTriangles(op, pSrc, pDst, maskFormat, xSrc, ySrc, ntris, tris);
-
-            glamor_finish_access_picture(pSrc, GLAMOR_ACCESS_RO);
-        }
-
-        glamor_finish_access_picture(pDst, GLAMOR_ACCESS_RW);
+    if (glamor_prepare_access_picture(pDst, GLAMOR_ACCESS_RW) &&
+        glamor_prepare_access_picture(pSrc, GLAMOR_ACCESS_RO)) {
+        fbTriangles(op, pSrc, pDst, maskFormat, xSrc, ySrc, ntris, tris);
     }
+    glamor_finish_access_picture(pSrc);
+    glamor_finish_access_picture(pDst);
+
     return TRUE;
 }
 
index f9550b7..53b7d9b 100644 (file)
@@ -1177,7 +1177,7 @@ glamor_dump_pixmap(PixmapPtr pixmap, int x, int y, int w, int h)
     default:
         ErrorF("dump depth %d, not implemented.\n", pixmap->drawable.depth);
     }
-    glamor_finish_access(&pixmap->drawable, GLAMOR_ACCESS_RO);
+    glamor_finish_access(&pixmap->drawable);
 }
 
 static inline void
@@ -1318,13 +1318,12 @@ glamor_compare_pixmaps(PixmapPtr pixmap1, PixmapPtr pixmap2,
 {
     assert(pixmap1->drawable.depth == pixmap2->drawable.depth);
 
-    glamor_prepare_access(&pixmap1->drawable, GLAMOR_ACCESS_RO);
-    glamor_prepare_access(&pixmap2->drawable, GLAMOR_ACCESS_RO);
-
-    _glamor_compare_pixmaps(pixmap1, pixmap2, x, y, w, h, -1, all, diffs);
-
-    glamor_finish_access(&pixmap1->drawable, GLAMOR_ACCESS_RO);
-    glamor_finish_access(&pixmap2->drawable, GLAMOR_ACCESS_RO);
+    if (glamor_prepare_access(&pixmap1->drawable, GLAMOR_ACCESS_RO) &&
+        glamor_prepare_access(&pixmap2->drawable, GLAMOR_ACCESS_RO)) {
+        _glamor_compare_pixmaps(pixmap1, pixmap2, x, y, w, h, -1, all, diffs);
+    }
+    glamor_finish_access(&pixmap1->drawable);
+    glamor_finish_access(&pixmap2->drawable);
 }
 
 /* This function is used to compare two pictures.
@@ -1432,9 +1431,6 @@ glamor_compare_pictures(ScreenPtr screen,
         return;
     }
 
-    glamor_prepare_access(&fst_pixmap->drawable, GLAMOR_ACCESS_RO);
-    glamor_prepare_access(&snd_pixmap->drawable, GLAMOR_ACCESS_RO);
-
     if ((fst_type == SourcePictTypeLinear) ||
         (fst_type == SourcePictTypeRadial) ||
         (fst_type == SourcePictTypeConical) ||
@@ -1444,12 +1440,15 @@ glamor_compare_pictures(ScreenPtr screen,
         x_source = y_source = 0;
     }
 
-    _glamor_compare_pixmaps(fst_pixmap, snd_pixmap,
-                            x_source, y_source,
-                            width, height, fst_picture->format, all, diffs);
-
-    glamor_finish_access(&fst_pixmap->drawable, GLAMOR_ACCESS_RO);
-    glamor_finish_access(&snd_pixmap->drawable, GLAMOR_ACCESS_RO);
+    if (glamor_prepare_access(&fst_pixmap->drawable, GLAMOR_ACCESS_RO) &&
+        glamor_prepare_access(&snd_pixmap->drawable, GLAMOR_ACCESS_RO)) {
+        _glamor_compare_pixmaps(fst_pixmap, snd_pixmap,
+                                x_source, y_source,
+                                width, height, fst_picture->format,
+                                all, diffs);
+    }
+    glamor_finish_access(&fst_pixmap->drawable);
+    glamor_finish_access(&snd_pixmap->drawable);
 
     if (fst_generated)
         glamor_destroy_picture(fst_picture);