Bug 981621 - Don't crash if we fail to create SkiaGL backing texture r=gwright
authorJames Willcox <snorp@snorp.net>
Wed, 26 Mar 2014 13:21:50 -0500
changeset 175548 cf6adb086a9e5064980436f8e70d7b12c4389d60
parent 175547 6374f5d7525de5b445127eeed3004243fdf1cad5
child 175549 32ce387c548754cd911a184d6d193bb7ca3a1e0a
push id26492
push userryanvm@gmail.com
push dateThu, 27 Mar 2014 00:57:51 +0000
treeherdermozilla-central@441f5fd256e2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgwright
bugs981621
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 981621 - Don't crash if we fail to create SkiaGL backing texture r=gwright
gfx/2d/2D.h
gfx/2d/DrawTargetSkia.cpp
gfx/2d/DrawTargetSkia.h
gfx/2d/Factory.cpp
--- a/gfx/2d/2D.h
+++ b/gfx/2d/2D.h
@@ -974,17 +974,17 @@ public:
     mPermitSubpixelAA = aPermitSubpixelAA;
   }
 
   bool GetPermitSubpixelAA() {
     return mPermitSubpixelAA;
   }
 
 #ifdef USE_SKIA_GPU
-  virtual void InitWithGrContext(GrContext* aGrContext,
+  virtual bool InitWithGrContext(GrContext* aGrContext,
                                  const IntSize &aSize,
                                  SurfaceFormat aFormat)
   {
     MOZ_CRASH();
   }
 #endif
 
 protected:
--- a/gfx/2d/DrawTargetSkia.cpp
+++ b/gfx/2d/DrawTargetSkia.cpp
@@ -654,17 +654,17 @@ DrawTargetSkia::Init(const IntSize &aSiz
   mSize = aSize;
 
   mCanvas = canvas.get();
   mFormat = aFormat;
   return true;
 }
 
 #ifdef USE_SKIA_GPU
-void
+bool
 DrawTargetSkia::InitWithGrContext(GrContext* aGrContext,
                                   const IntSize &aSize,
                                   SurfaceFormat aFormat)
 {
   MOZ_ASSERT(aGrContext, "null GrContext");
 
   mGrContext = aGrContext;
 
@@ -676,22 +676,27 @@ DrawTargetSkia::InitWithGrContext(GrCont
   targetDescriptor.fFlags = kRenderTarget_GrTextureFlagBit;
   targetDescriptor.fWidth = mSize.width;
   targetDescriptor.fHeight = mSize.height;
   targetDescriptor.fConfig = GfxFormatToGrConfig(mFormat);
   targetDescriptor.fOrigin = kBottomLeft_GrSurfaceOrigin;
   targetDescriptor.fSampleCnt = 0;
 
   SkAutoTUnref<GrTexture> skiaTexture(mGrContext->createUncachedTexture(targetDescriptor, NULL, 0));
+  if (!skiaTexture) {
+    return false;
+  }
 
   mTexture = (uint32_t)skiaTexture->getTextureHandle();
 
   SkAutoTUnref<SkBaseDevice> device(new SkGpuDevice(mGrContext.get(), skiaTexture->asRenderTarget()));
   SkAutoTUnref<SkCanvas> canvas(new SkCanvas(device.get()));
   mCanvas = canvas.get();
+
+  return true;
 }
 
 #endif
 
 void
 DrawTargetSkia::Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat)
 {
   SkAlphaType alphaType = kPremul_SkAlphaType;
--- a/gfx/2d/DrawTargetSkia.h
+++ b/gfx/2d/DrawTargetSkia.h
@@ -101,17 +101,17 @@ public:
   virtual TemporaryRef<FilterNode> CreateFilter(FilterType aType);
   virtual void SetTransform(const Matrix &aTransform);
   virtual void *GetNativeSurface(NativeSurfaceType aType);
 
   bool Init(const IntSize &aSize, SurfaceFormat aFormat);
   void Init(unsigned char* aData, const IntSize &aSize, int32_t aStride, SurfaceFormat aFormat);
 
 #ifdef USE_SKIA_GPU
-  void InitWithGrContext(GrContext* aGrContext,
+  bool InitWithGrContext(GrContext* aGrContext,
                          const IntSize &aSize,
                          SurfaceFormat aFormat) MOZ_OVERRIDE;
 #endif
 
   operator std::string() const {
     std::stringstream stream;
     stream << "DrawTargetSkia(" << this << ")";
     return stream.str();
--- a/gfx/2d/Factory.cpp
+++ b/gfx/2d/Factory.cpp
@@ -585,19 +585,20 @@ Factory::D2DCleanup()
 #endif // XP_WIN
 
 #ifdef USE_SKIA_GPU
 TemporaryRef<DrawTarget>
 Factory::CreateDrawTargetSkiaWithGrContext(GrContext* aGrContext,
                                            const IntSize &aSize,
                                            SurfaceFormat aFormat)
 {
-  DrawTargetSkia* newDrawTargetSkia = new DrawTargetSkia();
-  newDrawTargetSkia->InitWithGrContext(aGrContext, aSize, aFormat);
-  RefPtr<DrawTarget> newTarget = newDrawTargetSkia;
+  RefPtr<DrawTarget> newTarget = new DrawTargetSkia();
+  if (!newTarget->InitWithGrContext(aGrContext, aSize, aFormat)) {
+    return nullptr;
+  }
   return newTarget;
 }
 
 #endif // USE_SKIA_GPU
 
 void
 Factory::PurgeAllCaches()
 {