Bug 965914 - Don't crash when we can't allocate a new surface in CloneAligned. r=Bas, a=sledru
authorMarkus Stange <mstange@themasta.com>
Tue, 04 Feb 2014 21:03:12 +0100
changeset 176254 0347798cdf3759cb799286e53c86ba0d5124c278
parent 176253 f5bc77716852688512a0806d2c023fb238abee02
child 176255 a1e4675ef6808e6141a18579de5878ad489a826e
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas, sledru
bugs965914
milestone28.0
Bug 965914 - Don't crash when we can't allocate a new surface in CloneAligned. r=Bas, a=sledru
gfx/2d/FilterNodeSoftware.cpp
--- a/gfx/2d/FilterNodeSoftware.cpp
+++ b/gfx/2d/FilterNodeSoftware.cpp
@@ -230,17 +230,19 @@ CopyRect(DataSourceSurface* aSrc, DataSo
   }
 }
 
 TemporaryRef<DataSourceSurface>
 CloneAligned(DataSourceSurface* aSource)
 {
   RefPtr<DataSourceSurface> copy =
     Factory::CreateDataSourceSurface(aSource->GetSize(), aSource->GetFormat());
-  CopyRect(aSource, copy, IntRect(IntPoint(), aSource->GetSize()), IntPoint());
+  if (copy) {
+    CopyRect(aSource, copy, IntRect(IntPoint(), aSource->GetSize()), IntPoint());
+  }
   return copy;
 }
 
 static void
 FillRectWithPixel(DataSourceSurface *aSurface, const IntRect &aFillRect, IntPoint aPixelPos)
 {
   uint8_t* data = aSurface->GetData();
   uint8_t* sourcePixelData = data + DataOffset(aSurface, aPixelPos);
@@ -725,29 +727,30 @@ FilterNodeSoftware::GetInputDataSourceSu
     IntRect srcRect = aTransparencyPaddedSourceRect->Intersect(aRect);
     surface = GetDataSurfaceInRect(surface, surfaceRect, srcRect, EDGE_MODE_NONE);
     surfaceRect = srcRect;
   }
 
   RefPtr<DataSourceSurface> result =
     GetDataSurfaceInRect(surface, surfaceRect, aRect, aEdgeMode);
 
+  if (result &&
+      (result->Stride() != GetAlignedStride<16>(result->Stride()) ||
+      reinterpret_cast<uintptr_t>(result->GetData()) % 16 != 0)) {
+    // Align unaligned surface.
+    result = CloneAligned(result);
+  }
+
   if (!result) {
 #ifdef DEBUG_DUMP_SURFACES
     printf(" -- no input --</section>\n\n");
 #endif
     return nullptr;
   }
 
-  if (result->Stride() != GetAlignedStride<16>(result->Stride()) ||
-      reinterpret_cast<uintptr_t>(result->GetData()) % 16 != 0) {
-    // Align unaligned surface.
-    result = CloneAligned(result);
-  }
-
   SurfaceFormat currentFormat = result->GetFormat();
   if (DesiredFormat(currentFormat, aFormatHint) == FORMAT_B8G8R8A8 &&
       currentFormat != FORMAT_B8G8R8A8) {
     result = FilterProcessing::ConvertToB8G8R8A8(result);
   }
 
 #ifdef DEBUG_DUMP_SURFACES
   printf("<img src='"); DumpAsPNG(result); printf("'></section>");