Bug 1061699 - Only crash debug builds if BorrowDrawTarget is called on an unlocked TextureClient. r=Bas, a=sledru
authorNicolas Silva <nsilva@mozilla.com>
Tue, 16 Sep 2014 14:32:24 +0200
changeset 216876 4020480a6741
parent 216875 69047a750833
child 216877 737fbc0e3df4
push id3951
push userryanvm@gmail.com
push date2014-09-29 18:48 +0000
treeherdermozilla-beta@19338c25065c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersBas, sledru
bugs1061699
milestone33.0
Bug 1061699 - Only crash debug builds if BorrowDrawTarget is called on an unlocked TextureClient. r=Bas, a=sledru
gfx/layers/client/TextureClient.cpp
gfx/layers/d3d11/TextureD3D11.cpp
gfx/layers/d3d9/TextureD3D9.cpp
gfx/layers/opengl/GrallocTextureClient.cpp
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -658,16 +658,19 @@ BufferTextureClient::AllocateForSurface(
   return true;
 }
 
 gfx::DrawTarget*
 BufferTextureClient::BorrowDrawTarget()
 {
   MOZ_ASSERT(IsValid());
   MOZ_ASSERT(mLocked, "BorrowDrawTarget should be called on locked textures only");
+  if (!mLocked) {
+    return nullptr;
+  }
 
   if (mDrawTarget) {
     return mDrawTarget;
   }
 
   ImageDataSerializer serializer(GetBuffer(), GetBufferSize());
   if (!serializer.IsValid()) {
     return nullptr;
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -242,17 +242,17 @@ TextureClientD3D11::Unlock()
   mIsLocked = false;
 }
 
 DrawTarget*
 TextureClientD3D11::BorrowDrawTarget()
 {
   MOZ_ASSERT(mIsLocked, "Calling TextureClient::BorrowDrawTarget without locking :(");
 
-  if (!mTexture) {
+  if (!mIsLocked || !mTexture) {
     return nullptr;
   }
 
   if (mDrawTarget) {
     return mDrawTarget;
   }
 
   // This may return a null DrawTarget
--- a/gfx/layers/d3d9/TextureD3D9.cpp
+++ b/gfx/layers/d3d9/TextureD3D9.cpp
@@ -647,16 +647,21 @@ CairoTextureClientD3D9::ToSurfaceDescrip
   aOutDescriptor = SurfaceDescriptorD3D9(reinterpret_cast<uintptr_t>(mTexture.get()));
   return true;
 }
 
 gfx::DrawTarget*
 CairoTextureClientD3D9::BorrowDrawTarget()
 {
   MOZ_ASSERT(mIsLocked && mD3D9Surface);
+  if (!mIsLocked || !mD3D9Surface) {
+    NS_WARNING("Calling BorrowDrawTarget on an Unlocked TextureClient");
+    return nullptr;
+  }
+
   if (mDrawTarget) {
     return mDrawTarget;
   }
 
   if (ContentForFormat(mFormat) == gfxContentType::COLOR) {
     mSurface = new gfxWindowsSurface(mD3D9Surface);
     if (!mSurface || mSurface->CairoStatus()) {
       NS_WARNING("Could not create surface for d3d9 surface");
--- a/gfx/layers/opengl/GrallocTextureClient.cpp
+++ b/gfx/layers/opengl/GrallocTextureClient.cpp
@@ -174,17 +174,17 @@ SurfaceFormatForPixelFormat(android::Pix
 }
 
 gfx::DrawTarget*
 GrallocTextureClientOGL::BorrowDrawTarget()
 {
   MOZ_ASSERT(IsValid());
   MOZ_ASSERT(mMappedBuffer, "Calling TextureClient::BorrowDrawTarget without locking :(");
 
-  if (!IsValid() || !IsAllocated()) {
+  if (!IsValid() || !IsAllocated() || !mMappedBuffer) {
     return nullptr;
   }
 
   if (mDrawTarget) {
     return mDrawTarget;
   }
 
   gfx::SurfaceFormat format = SurfaceFormatForPixelFormat(mGraphicBuffer->getPixelFormat());