From 584c1f5365a140493b5be83df69feea545d336f0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= <krh@bitplanet.net>
Date: Fri, 22 Jan 2010 09:43:42 -0500
Subject: [PATCH] [drm] Reuse fallback surface if present

If we've used a fallback surface earlier it will still be around when we
fallback next time unless we flush in the meantime.  When that happens,
dont assert that fallback is NULL, just reuse it.
---
 src/drm/cairo-drm-intel-surface.c |   55 +++++++++++++++++++------------------
 1 files changed, 28 insertions(+), 27 deletions(-)

diff --git a/src/drm/cairo-drm-intel-surface.c b/src/drm/cairo-drm-intel-surface.c
index 2152c59..cc355a0 100644
--- a/src/drm/cairo-drm-intel-surface.c
+++ b/src/drm/cairo-drm-intel-surface.c
@@ -160,38 +160,39 @@ intel_surface_acquire_dest_image (void *abstract_surface,
     cairo_status_t status;
     void *ptr;
 
-    assert (surface->base.fallback == NULL);
-
-    status = intel_surface_batch_flush (surface);
-    if (unlikely (status))
-	return status;
-
-    /* Force a read barrier, as well as flushing writes above */
-    if (to_intel_bo (surface->base.bo)->in_batch) {
-	status = intel_batch_flush (to_intel_device (surface->base.device));
+    if (surface->base.fallback == NULL) {
+	status = intel_surface_batch_flush (surface);
 	if (unlikely (status))
 	    return status;
-    }
 
-    ptr = intel_bo_map (to_intel_device (surface->base.device),
-			to_intel_bo (surface->base.bo));
-    if (unlikely (ptr == NULL))
-	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+	/* Force a read barrier, as well as flushing writes above */
+	if (to_intel_bo (surface->base.bo)->in_batch) {
+	    status = intel_batch_flush (to_intel_device (surface->base.device));
+	    if (unlikely (status))
+		return status;
+	}
 
-    image = cairo_image_surface_create_for_data (ptr,
-						 surface->base.format,
-						 surface->base.width,
-						 surface->base.height,
-						 surface->base.stride);
-    status = image->status;
-    if (unlikely (status)) {
-	intel_bo_unmap (to_intel_bo (surface->base.bo));
-	return status;
-    }
+	ptr = intel_bo_map (to_intel_device (surface->base.device),
+			    to_intel_bo (surface->base.bo));
+	if (unlikely (ptr == NULL))
+	    return _cairo_error (CAIRO_STATUS_NO_MEMORY);
+
+	image = cairo_image_surface_create_for_data (ptr,
+						     surface->base.format,
+						     surface->base.width,
+						     surface->base.height,
+						     surface->base.stride);
+	status = image->status;
+	if (unlikely (status)) {
+	   intel_bo_unmap (to_intel_bo (surface->base.bo));
+	   return status;
+	}
 
-    surface->base.fallback = cairo_surface_reference (image);
+	surface->base.fallback = image;
+    }
 
-    *image_out = (cairo_image_surface_t *) image;
+    *image_out = (cairo_image_surface_t *) 
+	    cairo_surface_reference (surface->base.fallback);
     *image_extra = NULL;
 
     image_rect_out->x = 0;
-- 
1.6.5.rc2

