Bug 1299738 - warn instead of crash if DrawTargetSkia's GetBitmapForSurface fails. r=mchang
authorLee Salzman <lsalzman@mozilla.com>
Thu, 01 Sep 2016 21:17:03 -0400
changeset 312370 657ba2f2611c714d718fb0268acfd5e60ff44310
parent 312369 0cfb84806c0863af4facbdde2b37ac5fdd40567c
child 312371 6d30a609081db505484615065263515faa225ca1
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmchang
bugs1299738
milestone51.0a1
Bug 1299738 - warn instead of crash if DrawTargetSkia's GetBitmapForSurface fails. r=mchang
gfx/2d/DrawTargetSkia.cpp
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -207,17 +207,17 @@ GetBitmapForSurface(SourceSurface* aSurf
 
   if (aSurface->GetType() == SurfaceType::SKIA) {
     bitmap = static_cast<SourceSurfaceSkia*>(aSurface)->GetBitmap();
     return bitmap;
   }
 
   DataSourceSurface* surf = aSurface->GetDataSurface().take();
   if (!surf) {
-    gfxDevCrash(LogReason::SourceSurfaceIncompatible) << "Non-Skia SourceSurfaces need to be DataSourceSurfaces";
+    gfxWarning() << "Failed getting DataSourceSurface for Skia bitmap";
     return bitmap;
   }
 
   if (!bitmap.installPixels(MakeSkiaImageInfo(surf->GetSize(), surf->GetFormat()),
                             surf->GetData(), surf->Stride(), nullptr,
                             ReleaseTemporarySurface, surf)) {
     gfxDebug() << "Failed installing pixels on Skia bitmap for temporary surface";
   }
@@ -487,36 +487,29 @@ DrawTargetSkia::Flush()
 
 void
 DrawTargetSkia::DrawSurface(SourceSurface *aSurface,
                             const Rect &aDest,
                             const Rect &aSource,
                             const DrawSurfaceOptions &aSurfOptions,
                             const DrawOptions &aOptions)
 {
-  RefPtr<SourceSurface> dataSurface;
-
-  if (!(aSurface->GetType() == SurfaceType::SKIA || aSurface->GetType() == SurfaceType::DATA)) {
-    dataSurface = aSurface->GetDataSurface();
-    if (!dataSurface) {
-      gfxDebug() << *this << ": DrawSurface() can't draw surface";
-      return;
-    }
-    aSurface = dataSurface.get();
+  if (aSource.IsEmpty()) {
+    return;
   }
 
-  if (aSource.IsEmpty()) {
+  SkBitmap bitmap = GetBitmapForSurface(aSurface);
+  if (bitmap.empty()) {
     return;
   }
 
   MarkChanged();
 
   SkRect destRect = RectToSkRect(aDest);
   SkRect sourceRect = RectToSkRect(aSource);
-  SkBitmap bitmap = GetBitmapForSurface(aSurface);
   bool forceGroup = bitmap.colorType() == kAlpha_8_SkColorType &&
                     aOptions.mCompositionOp != CompositionOp::OP_OVER;
 
   AutoPaintSetup paint(mCanvas.get(), aOptions, &aDest, forceGroup);
   if (aSurfOptions.mSamplingFilter == SamplingFilter::POINT) {
     paint.mPaint.setFilterQuality(kNone_SkFilterQuality);
   }
 
@@ -547,28 +540,30 @@ DrawTargetSkia::DrawFilter(FilterNode *a
 void
 DrawTargetSkia::DrawSurfaceWithShadow(SourceSurface *aSurface,
                                       const Point &aDest,
                                       const Color &aColor,
                                       const Point &aOffset,
                                       Float aSigma,
                                       CompositionOp aOperator)
 {
-  if (!(aSurface->GetType() == SurfaceType::SKIA || aSurface->GetType() == SurfaceType::DATA) ||
-      aSurface->GetSize().IsEmpty()) {
+  if (aSurface->GetSize().IsEmpty()) {
+    return;
+  }
+
+  SkBitmap bitmap = GetBitmapForSurface(aSurface);
+  if (bitmap.empty()) {
     return;
   }
 
   MarkChanged();
 
   mCanvas->save();
   mCanvas->resetMatrix();
 
-  SkBitmap bitmap = GetBitmapForSurface(aSurface);
-
   SkPaint paint;
   paint.setXfermodeMode(GfxOpToSkiaOp(aOperator));
 
   // bug 1201272
   // We can't use the SkDropShadowImageFilter here because it applies the xfer
   // mode first to render the bitmap to a temporary layer, and then implicitly
   // uses src-over to composite the resulting shadow.
   // The canvas spec, however, states that the composite op must be used to
@@ -1344,16 +1339,19 @@ DrawTarget::Draw3DTransformedSurface(Sou
   if (xformBounds.IsEmpty()) {
     return true;
   }
   // Offset the matrix by the transformed origin.
   fullMat.PostTranslate(-xformBounds.x, -xformBounds.y, 0);
 
   // Read in the source data.
   SkBitmap srcBitmap = GetBitmapForSurface(aSurface);
+  if (srcBitmap.empty()) {
+    return true;
+  }
 
   // Set up an intermediate destination surface only the size of the transformed bounds.
   // Try to pass through the source's format unmodified in both the BGRA and ARGB cases.
   RefPtr<DataSourceSurface> dstSurf =
     Factory::CreateDataSourceSurface(xformBounds.Size(),
                                      srcBitmap.alphaType() == kPremul_SkAlphaType ?
                                        aSurface->GetFormat() : SurfaceFormat::A8R8G8B8_UINT32,
                                      true);
@@ -1398,19 +1396,22 @@ DrawTarget::Draw3DTransformedSurface(Sou
 
 bool
 DrawTargetSkia::Draw3DTransformedSurface(SourceSurface* aSurface, const Matrix4x4& aMatrix)
 {
   if (aMatrix.IsSingular()) {
     return false;
   }
 
-  MarkChanged();
+  SkBitmap bitmap = GetBitmapForSurface(aSurface);
+  if (bitmap.empty()) {
+    return true;
+  }
 
-  SkBitmap bitmap = GetBitmapForSurface(aSurface);
+  MarkChanged();
 
   mCanvas->save();
 
   SkPaint paint;
   paint.setAntiAlias(true);
   paint.setFilterQuality(kLow_SkFilterQuality);
 
   SkMatrix xform;
@@ -1588,24 +1589,23 @@ DrawTargetSkia::CreateSourceSurfaceFromN
   return nullptr;
 }
 
 void
 DrawTargetSkia::CopySurface(SourceSurface *aSurface,
                             const IntRect& aSourceRect,
                             const IntPoint &aDestination)
 {
-  if (aSurface->GetType() != SurfaceType::SKIA && aSurface->GetType() != SurfaceType::DATA) {
+  SkBitmap bitmap = GetBitmapForSurface(aSurface);
+  if (bitmap.empty()) {
     return;
   }
 
   MarkChanged();
 
-  SkBitmap bitmap = GetBitmapForSurface(aSurface);
-
   mCanvas->save();
   mCanvas->setMatrix(SkMatrix::MakeTrans(SkIntToScalar(aDestination.x), SkIntToScalar(aDestination.y)));
   mCanvas->clipRect(SkRect::MakeIWH(aSourceRect.width, aSourceRect.height), SkRegion::kReplace_Op);
 
   SkPaint paint;
   if (!bitmap.isOpaque()) {
     // Keep the xfermode as SOURCE_OVER for opaque bitmaps
     // http://code.google.com/p/skia/issues/detail?id=628