sna: Remove the replace indirection prior to performing write_boxes
authorChris Wilson <chris@chris-wilson.co.uk>
Mon, 4 Nov 2013 11:30:39 +0000 (11:30 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Mon, 4 Nov 2013 11:30:39 +0000 (11:30 +0000)
As write_boxes itself decides whether or not to stage the upload into
the destination bo, we can destroy the temporary allocation along the
write_boxes fallback path (i.e. after failing to map the destination
bo).

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
src/sna/sna_io.c

index 75d9fe1..0aac61e 100644 (file)
@@ -1841,6 +1841,11 @@ bool sna_replace(struct sna *sna, PixmapPtr pixmap,
        } else {
                BoxRec box;
 
+               if (bo != priv->gpu_bo) {
+                       kgem_bo_destroy(&sna->kgem, bo);
+                       bo = priv->gpu_bo;
+               }
+
                box.x1 = box.y1 = 0;
                box.x2 = pixmap->drawable.width;
                box.y2 = pixmap->drawable.height;
@@ -1849,7 +1854,7 @@ bool sna_replace(struct sna *sna, PixmapPtr pixmap,
                                     bo, 0, 0,
                                     src, stride, 0, 0,
                                     &box, 1))
-                       goto err;
+                       return false;
        }
 
 done:
@@ -1860,11 +1865,6 @@ done:
        }
 
        return true;
-
-err:
-       if (bo != priv->gpu_bo)
-               kgem_bo_destroy(&sna->kgem, bo);
-       return false;
 }
 
 bool
@@ -1887,7 +1887,8 @@ sna_replace__xor(struct sna *sna, PixmapPtr pixmap,
 
        kgem_bo_undo(&sna->kgem, bo);
 
-       if (kgem_bo_is_busy(bo)) {
+       if (!kgem_bo_can_map(&sna->kgem, bo) ||
+           __kgem_bo_is_busy(&sna->kgem, bo)) {
                struct kgem_bo *new_bo;
 
                new_bo = kgem_create_2d(&sna->kgem,
@@ -1914,6 +1915,11 @@ sna_replace__xor(struct sna *sna, PixmapPtr pixmap,
        } else {
                BoxRec box;
 
+               if (bo != priv->gpu_bo) {
+                       kgem_bo_destroy(&sna->kgem, bo);
+                       bo = priv->gpu_bo;
+               }
+
                box.x1 = box.y1 = 0;
                box.x2 = pixmap->drawable.width;
                box.y2 = pixmap->drawable.height;
@@ -1923,7 +1929,7 @@ sna_replace__xor(struct sna *sna, PixmapPtr pixmap,
                                          src, stride, 0, 0,
                                          &box, 1,
                                          and, or))
-                       goto err;
+                       return false;
        }
 
        if (bo != priv->gpu_bo) {
@@ -1933,9 +1939,4 @@ sna_replace__xor(struct sna *sna, PixmapPtr pixmap,
        }
 
        return true;
-
-err:
-       if (bo != priv->gpu_bo)
-               kgem_bo_destroy(&sna->kgem, bo);
-       return false;
 }