Bug 1262390: In some cases, we fail with the small allocation because of the device reset situation. r?bas.schouten draft
authorMilan Sreckovic <milan@mozilla.com>
Mon, 20 Feb 2017 17:14:49 -0500
changeset 487135 319644a29cb988cfcfc631d665c165fbfa48ab95
parent 484626 ec3ef9f77a52693e9732ca480df16017af0d9504
child 546390 0c821156aad8771594ae9a8631d5b123a3dfd0df
push id46142
push userbmo:milan@mozilla.com
push dateMon, 20 Feb 2017 22:31:00 +0000
reviewersbas.schouten
bugs1262390
milestone54.0a1
Bug 1262390: In some cases, we fail with the small allocation because of the device reset situation. r?bas.schouten MozReview-Commit-ID: BKMOZbgJ7px
gfx/2d/DrawTargetD2D1.cpp
--- a/gfx/2d/DrawTargetD2D1.cpp
+++ b/gfx/2d/DrawTargetD2D1.cpp
@@ -1353,16 +1353,19 @@ DrawTargetD2D1::FinalizeDrawing(Composit
     if (FAILED(hr) || !blendEffect) {
       gfxWarning() << "Failed to create blend effect!";
       return;
     }
 
     // We don't need to preserve the current content of this layer as the output
     // of the blend effect should completely replace it.
     RefPtr<ID2D1Image> tmpImage = GetImageForLayerContent(false);
+    if (!tmpImage) {
+      return;
+    }
 
     blendEffect->SetInput(0, tmpImage);
     blendEffect->SetInput(1, source);
     blendEffect->SetValue(D2D1_BLEND_PROP_MODE, D2DBlendMode(aOp));
 
     mDC->DrawImage(blendEffect, D2D1_INTERPOLATION_MODE_NEAREST_NEIGHBOR, D2D1_COMPOSITE_MODE_BOUNDED_SOURCE_COPY);
 
     // This may seem a little counter intuitive. If this is false, we go through the regular
@@ -1456,19 +1459,23 @@ DrawTargetD2D1::GetImageForLayerContent(
 {
   PopAllClips();
 
   if (!CurrentLayer().mCurrentList) {
     RefPtr<ID2D1Bitmap> tmpBitmap;
     HRESULT hr = mDC->CreateBitmap(D2DIntSize(mSize), D2D1::BitmapProperties(D2DPixelFormat(mFormat)), getter_AddRefs(tmpBitmap));
     if (FAILED(hr)) {
       gfxCriticalError(CriticalLog::DefaultOptions(Factory::ReasonableSurfaceSize(mSize))) << "[D2D1.1] 6CreateBitmap failure " << mSize << " Code: " << hexa(hr) << " format " << (int)mFormat;
-      // For now, crash in this scenario; this should happen because tmpBitmap is
+      // If it's a recreate target error, return and handle it elsewhere.
+      if (hr == D2DERR_RECREATE_TARGET) {
+        mDC->Flush();
+        return nullptr;
+      }
+      // For now, crash in other scenarios; this should happen because tmpBitmap is
       // null and CopyFromBitmap call below dereferences it.
-      // return;
     }
     mDC->Flush();
 
     tmpBitmap->CopyFromBitmap(nullptr, mBitmap, nullptr);
     return tmpBitmap.forget();
   } else {
     RefPtr<ID2D1CommandList> list = CurrentLayer().mCurrentList;
     mDC->CreateCommandList(getter_AddRefs(CurrentLayer().mCurrentList));