Bug 587316 - Part 4: Support CAIRO_EXTEND_NONE for D2D source surfaces. r=jrmuizel
authorBas Schouten <bschouten@mozilla.com>
Mon, 16 Aug 2010 09:15:02 +0200
changeset 50651 055a407bb683d9e5d567d9972446dd1d5d61cd83
parent 50650 1d7c15818f663035ce835a7c336d6d0496a7fe54
child 50652 6aa55fbbabc0100ee46aed3d63b6ae0fe0577ae1
push idunknown
push userunknown
push dateunknown
reviewersjrmuizel
bugs587316
milestone2.0b4pre
Bug 587316 - Part 4: Support CAIRO_EXTEND_NONE for D2D source surfaces. r=jrmuizel
gfx/cairo/cairo/src/cairo-d2d-surface.cpp
--- a/gfx/cairo/cairo/src/cairo-d2d-surface.cpp
+++ b/gfx/cairo/cairo/src/cairo-d2d-surface.cpp
@@ -1655,23 +1655,20 @@ RefPtr<ID2D1Brush>
 	D2D1_EXTEND_MODE extendMode;
 
 	cairo_user_data_key_t *key = &bitmap_key_extend;
 
 	if (pattern->extend == CAIRO_EXTEND_NONE) {
 	    extendMode = D2D1_EXTEND_MODE_CLAMP;
 	    key = &bitmap_key_nonextend;
 	    /** 
-	     * For image surfaces we create a slightly larger bitmap with
-	     * a transparent border around it for this case. Need to translate
-	     * for that.
+	     * We create a slightly larger bitmap with a transparent border
+	     * around it for this case. Need to translate for that.
 	     */
-	    if (surfacePattern->surface->type == CAIRO_SURFACE_TYPE_IMAGE) {
-		cairo_matrix_translate(&mat, -1.0, -1.0);
-	    }
+	    cairo_matrix_translate(&mat, -1.0, -1.0);
 	} else if (pattern->extend == CAIRO_EXTEND_REPEAT) {
 	    extendMode = D2D1_EXTEND_MODE_WRAP;
 	} else if (pattern->extend == CAIRO_EXTEND_REFLECT) {
 	    extendMode = D2D1_EXTEND_MODE_MIRROR;
 	} else {
 	    extendMode = D2D1_EXTEND_MODE_CLAMP;
 	}
 
@@ -1696,19 +1693,31 @@ RefPtr<ID2D1Brush>
 		/* D2D cannot deal with self-copy. We should add an optimized
 		 * codepath for self-copy in the easy cases that does ping-pong like
 		 * scroll does. See bug 579215. For now fallback.
 		 */
 		return NULL;
 	    }
 
 	    _cairo_d2d_update_surface_bitmap(srcSurf);
-	    sourceBitmap = srcSurf->surfaceBitmap;
-
 	    _cairo_d2d_flush(srcSurf);
+
+	    if (pattern->extend == CAIRO_EXTEND_NONE) {
+		ID2D1Bitmap *srcSurfBitmap = srcSurf->surfaceBitmap;
+		d2dsurf->rt->CreateBitmap(
+		    D2D1::SizeU(srcSurfBitmap->GetPixelSize().width + 2,
+				srcSurfBitmap->GetPixelSize().height + 2),
+		    D2D1::BitmapProperties(srcSurfBitmap->GetPixelFormat()),
+		    &sourceBitmap);
+		D2D1_POINT_2U point = D2D1::Point2U(1, 1);
+		sourceBitmap->CopyFromBitmap(&point, srcSurfBitmap, NULL);
+	    } else {
+		sourceBitmap = srcSurf->surfaceBitmap;
+	    }
+
 	} else if (surfacePattern->surface->type == CAIRO_SURFACE_TYPE_IMAGE) {
 	    cairo_image_surface_t *srcSurf = 
 		reinterpret_cast<cairo_image_surface_t*>(surfacePattern->surface);
 	    D2D1_ALPHA_MODE alpha;
 	    if (srcSurf->format == CAIRO_FORMAT_ARGB32 ||
 		srcSurf->format == CAIRO_FORMAT_A8) {
 		alpha = D2D1_ALPHA_MODE_PREMULTIPLIED;
 	    } else {