Bug 1154003 - More protection for failed surface drawable creation. r=bas, a=sledru
authorMilan Sreckovic <milan@mozilla.com>
Wed, 15 Apr 2015 15:04:38 -0400
changeset 260238 474ffd404414
parent 260237 a6fe316e7571
child 260239 9fe28719e4fd
push id724
push userryanvm@gmail.com
push date2015-04-23 01:08 +0000
treeherdermozilla-release@db41e8e267ed [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbas, sledru
bugs1154003
milestone38.0
Bug 1154003 - More protection for failed surface drawable creation. r=bas, a=sledru
gfx/thebes/gfxDrawable.cpp
--- a/gfx/thebes/gfxDrawable.cpp
+++ b/gfx/thebes/gfxDrawable.cpp
@@ -8,27 +8,31 @@
 #include "gfxContext.h"
 #include "gfxPlatform.h"
 #include "gfxColor.h"
 #include "gfx2DGlue.h"
 #ifdef MOZ_X11
 #include "cairo.h"
 #include "gfxXlibSurface.h"
 #endif
+#include "mozilla/gfx/Logging.h"
 
 using namespace mozilla;
 using namespace mozilla::gfx;
 
 gfxSurfaceDrawable::gfxSurfaceDrawable(SourceSurface* aSurface,
                                        const gfxIntSize aSize,
                                        const gfxMatrix aTransform)
  : gfxDrawable(aSize)
  , mSourceSurface(aSurface)
  , mTransform(aTransform)
 {
+  if (!mSourceSurface) {
+    gfxWarning() << "Creating gfxSurfaceDrawable with null SourceSurface";
+  }
 }
 
 bool
 gfxSurfaceDrawable::DrawWithSamplingRect(gfxContext* aContext,
                                          const gfxRect& aFillRect,
                                          const gfxRect& aSamplingRect,
                                          bool aRepeat,
                                          const GraphicsFilter& aFilter,
@@ -56,16 +60,20 @@ gfxSurfaceDrawable::DrawWithSamplingRect
 bool
 gfxSurfaceDrawable::Draw(gfxContext* aContext,
                          const gfxRect& aFillRect,
                          bool aRepeat,
                          const GraphicsFilter& aFilter,
                          gfxFloat aOpacity,
                          const gfxMatrix& aTransform)
 {
+  if (!mSourceSurface) {
+    return true;
+  }
+
   DrawInternal(aContext, aFillRect, IntRect(), aRepeat, aFilter, aOpacity, aTransform);
   return true;
 }
 
 void
 gfxSurfaceDrawable::DrawInternal(gfxContext* aContext,
                                  const gfxRect& aFillRect,
                                  const IntRect& aSamplingRect,
@@ -119,18 +127,21 @@ gfxCallbackDrawable::MakeSurfaceDrawable
                                                                      format);
     if (!dt)
         return nullptr;
 
     nsRefPtr<gfxContext> ctx = new gfxContext(dt);
     Draw(ctx, gfxRect(0, 0, mSize.width, mSize.height), false, aFilter);
 
     RefPtr<SourceSurface> surface = dt->Snapshot();
-    nsRefPtr<gfxSurfaceDrawable> drawable = new gfxSurfaceDrawable(surface, mSize);
-    return drawable.forget();
+    if (surface) {
+        nsRefPtr<gfxSurfaceDrawable> drawable = new gfxSurfaceDrawable(surface, mSize);
+        return drawable.forget();
+    }
+    return nullptr;
 }
 
 bool
 gfxCallbackDrawable::Draw(gfxContext* aContext,
                           const gfxRect& aFillRect,
                           bool aRepeat,
                           const GraphicsFilter& aFilter,
                           gfxFloat aOpacity,