Bug 1232231 - BorrowDrawTarget can return nullptr - be ready for it. r=nical a=sylvestre
authorMilan Sreckovic <milan@mozilla.com>
Mon, 04 Jan 2016 09:50:00 -0500
changeset 298344 7355ad1c4528384ba0ff381809f0ff154d51be3d
parent 298343 d8843dfeb7066fe2df49baeed0fcdc89e9707da5
child 298345 c1809400ce53b9904a2d316c70d14d4cf3aec8c4
push id8918
push userkwierso@gmail.com
push dateThu, 14 Jan 2016 21:04:28 +0000
treeherdermozilla-aurora@bfcf642c55e4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnical, sylvestre
bugs1232231
milestone45.0a2
Bug 1232231 - BorrowDrawTarget can return nullptr - be ready for it. r=nical a=sylvestre
gfx/layers/TextureWrapperImage.cpp
gfx/layers/client/TextureClient.h
--- a/gfx/layers/TextureWrapperImage.cpp
+++ b/gfx/layers/TextureWrapperImage.cpp
@@ -35,17 +35,22 @@ TextureWrapperImage::GetPictureRect()
 already_AddRefed<gfx::SourceSurface>
 TextureWrapperImage::GetAsSourceSurface()
 {
   TextureClientAutoLock autoLock(mTextureClient, OpenMode::OPEN_READ);
   if (!autoLock.Succeeded()) {
     return nullptr;
   }
 
-  return mTextureClient->BorrowDrawTarget()->Snapshot();
+  RefPtr<DrawTarget> dt = mTextureClient->BorrowDrawTarget();
+  if (!dt) {
+    return nullptr;
+  }
+
+  return dt->Snapshot();
 }
 
 TextureClient*
 TextureWrapperImage::GetTextureClient(CompositableClient* aClient)
 {
   return mTextureClient;
 }
 
--- a/gfx/layers/client/TextureClient.h
+++ b/gfx/layers/client/TextureClient.h
@@ -367,18 +367,24 @@ public:
   virtual gfx::SurfaceFormat GetFormat() const;
 
   /**
    * This method is strictly for debugging. It causes locking and
    * needless copies.
    */
   already_AddRefed<gfx::DataSourceSurface> GetAsSurface() {
     Lock(OpenMode::OPEN_READ);
-    RefPtr<gfx::SourceSurface> surf = BorrowDrawTarget()->Snapshot();
-    RefPtr<gfx::DataSourceSurface> data = surf->GetDataSurface();
+    RefPtr<gfx::DataSourceSurface> data;
+    RefPtr<gfx::DrawTarget> dt = BorrowDrawTarget();
+    if (dt) {
+      RefPtr<gfx::SourceSurface> surf = dt->Snapshot();
+      if (surf) {
+        data = surf->GetDataSurface();
+      }
+    }
     Unlock();
     return data.forget();
   }
 
   virtual void PrintInfo(std::stringstream& aStream, const char* aPrefix);
 
   /**
    * Copies a rectangle from this texture client to a position in aTarget.