Bug 595375: Fail brush creation when bitmap creation fails. r=jrmuizel a=akeybl
authorBas Schouten <bschouten@mozilla.com>
Sun, 20 May 2012 22:29:07 +0200
changeset 95876 ef414707a0d6d85bba62656eba37bd6ac3fd9e70
parent 95875 7802a253d406d92a1a5cb9cef5cfec579ac62600
child 95877 8b330f11e7809897c232a39d9747c5113f55fac4
push id886
push userlsblakk@mozilla.com
push dateMon, 04 Jun 2012 19:57:52 +0000
treeherdermozilla-beta@bbd8d5efd6d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel, akeybl
bugs595375
milestone14.0a2
Bug 595375: Fail brush creation when bitmap creation fails. r=jrmuizel a=akeybl
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
@@ -1705,16 +1705,18 @@ static RefPtr<ID2D1Brush>
  * this will make the function return a seperate brush.
  * \return A brush object
  */
 static RefPtr<ID2D1Brush>
 _cairo_d2d_create_brush_for_pattern(cairo_d2d_surface_t *d2dsurf, 
 				    const cairo_pattern_t *pattern,
 				    bool unique = false)
 {
+    HRESULT hr;
+
     if (pattern->type == CAIRO_PATTERN_TYPE_SOLID) {
 	cairo_solid_pattern_t *sourcePattern =
 	    (cairo_solid_pattern_t*)pattern;
 	D2D1_COLOR_F color = _cairo_d2d_color_from_cairo_color(sourcePattern->color);
 	if (unique) {
 	    RefPtr<ID2D1SolidColorBrush> brush;
 	    d2dsurf->rt->CreateSolidColorBrush(color,
 					       &brush);
@@ -1964,22 +1966,26 @@ static RefPtr<ID2D1Brush>
 						cachebitmap,
 						NULL);
 		    cairo_surface_attach_snapshot(surfacePattern->surface,
 						   nullSurf,
 						   _d2d_snapshot_detached);
 		}
 	    } else {
 		if (pattern->extend != CAIRO_EXTEND_NONE) {
-		    d2dsurf->rt->CreateBitmap(D2D1::SizeU(width, height),
-							  data + yoffset * stride + xoffset * Bpp,
-							  stride,
-							  D2D1::BitmapProperties(D2D1::PixelFormat(format,
-												   alpha)),
-					      &sourceBitmap);
+		    hr = d2dsurf->rt->CreateBitmap(D2D1::SizeU(width, height),
+						   data + yoffset * stride + xoffset * Bpp,
+						   stride,
+						   D2D1::BitmapProperties(D2D1::PixelFormat(format,
+											    alpha)),
+						   &sourceBitmap);
+
+		    if (FAILED(hr)) {
+			return NULL;
+		    }
 		} else {
 		    /**
 		     * Trick here, we create a temporary rectangular
 		     * surface with 1 pixel margin on each side. This
 		     * provides a rectangular transparent border, that
 		     * will ensure CLAMP acts as EXTEND_NONE. Perhaps
 		     * this could be further optimized by not memsetting
 		     * the whole array.
@@ -1990,23 +1996,27 @@ static RefPtr<ID2D1Brush>
 		    memset(tmp, 0, tmpWidth * tmpHeight * Bpp);
 		    for (unsigned int y = 0; y < height; y++) {
 			memcpy(
 			    tmp + tmpWidth * Bpp * y + tmpWidth * Bpp + Bpp, 
 			    data + yoffset * stride + y * stride + xoffset * Bpp, 
 			    width * Bpp);
 		    }
 
-		    d2dsurf->rt->CreateBitmap(D2D1::SizeU(tmpWidth, tmpHeight),
-					      tmp,
-					      tmpWidth * Bpp,
-					      D2D1::BitmapProperties(D2D1::PixelFormat(format,
-										       D2D1_ALPHA_MODE_PREMULTIPLIED)),
-					      &sourceBitmap);
+		    hr = d2dsurf->rt->CreateBitmap(D2D1::SizeU(tmpWidth, tmpHeight),
+						   tmp,
+						   tmpWidth * Bpp,
+						   D2D1::BitmapProperties(D2D1::PixelFormat(format,
+					 						    D2D1_ALPHA_MODE_PREMULTIPLIED)),
+						   &sourceBitmap);
+
 		    delete [] tmp;
+		    if (FAILED(hr)) {
+			return NULL;
+		    }
 		}
 
 		if (!partial) {
 		    cached_bitmap *cachebitmap = new cached_bitmap;
 		    /* We can cache it if it isn't a partial bitmap */
 		    cachebitmap->dirty = false;
 		    cachebitmap->bitmap = sourceBitmap;
 		    cachebitmap->device = d2dsurf->device;