Bug 1028491 - Try to create a reasonable size surface when surface creation fails, otherwise OOM abort. r=jrmuizel, a=sledru
authorBas Schouten <bschouten@mozilla.com>
Thu, 03 Jul 2014 22:20:08 +0200
changeset 208788 753c99efdb0dfd6bdd42604902dbb47532507e43
parent 208787 48c49053a2e679e61e65c9a576bd39b99493cbff
child 208789 c35c034db37892d5d3dbca40875e8848eed49d9b
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjrmuizel, sledru
bugs1028491
milestone32.0a2
Bug 1028491 - Try to create a reasonable size surface when surface creation fails, otherwise OOM abort. r=jrmuizel, a=sledru
gfx/thebes/gfxContext.cpp
--- a/gfx/thebes/gfxContext.cpp
+++ b/gfx/thebes/gfxContext.cpp
@@ -2275,19 +2275,31 @@ void
 gfxContext::PushNewDT(gfxContentType content)
 {
   Rect clipBounds = GetAzureDeviceSpaceClipBounds();
   clipBounds.RoundOut();
 
   clipBounds.width = std::max(1.0f, clipBounds.width);
   clipBounds.height = std::max(1.0f, clipBounds.height);
 
+  SurfaceFormat format = gfxPlatform::GetPlatform()->Optimal2DFormatForContent(content);
+
   RefPtr<DrawTarget> newDT =
     mDT->CreateSimilarDrawTarget(IntSize(int32_t(clipBounds.width), int32_t(clipBounds.height)),
-                                  gfxPlatform::GetPlatform()->Optimal2DFormatForContent(content));
+                                 format);
+
+  if (!newDT) {
+    NS_WARNING("Failed to create DrawTarget of sufficient size.");
+    newDT = mDT->CreateSimilarDrawTarget(IntSize(64, 64), format);
+
+    if (!newDT) {
+      // If even this fails.. we're most likely just out of memory!
+      NS_ABORT_OOM(BytesPerPixel(format) * 64 * 64);
+    }
+  }
 
   Save();
 
   CurrentState().drawTarget = newDT;
   CurrentState().deviceOffset = clipBounds.TopLeft();
 
   mDT = newDT;
 }