Bug 968807 - Add assertions in TextureClient. r=bjacob
authorNicolas Silva <nical@mozilla.com>
Fri, 21 Mar 2014 18:03:20 +0100
changeset 174796 54c9f249fb7a241a0c27df147666863579fcac48
parent 174795 fe6c589943402ab46cf1c2a83090e626508dee93
child 174797 73bed2a97a20fb0e794cd9872917f7b995729938
push id1
push userroot
push dateMon, 20 Oct 2014 17:29:22 +0000
reviewersbjacob
bugs968807
milestone31.0a1
Bug 968807 - Add assertions in TextureClient. r=bjacob
gfx/layers/client/TextureClient.cpp
gfx/layers/d3d11/TextureD3D11.cpp
gfx/layers/ipc/ImageBridgeChild.cpp
gfx/layers/ipc/ShadowLayers.cpp
--- a/gfx/layers/client/TextureClient.cpp
+++ b/gfx/layers/client/TextureClient.cpp
@@ -483,16 +483,17 @@ bool TextureClient::CopyToTextureClient(
   sourceTarget = nullptr;
 
   return true;
 }
 
 void
 TextureClient::Finalize()
 {
+  MOZ_ASSERT(!IsLocked());
   // Always make a temporary strong reference to the actor before we use it,
   // in case TextureChild::ActorDestroy might null mActor concurrently.
   RefPtr<TextureChild> actor = mActor;
 
   if (actor) {
     // this will call ForceRemove in the right thread, using a sync proxy if needed
     if (actor->GetForwarder()) {
       actor->GetForwarder()->RemoveTexture(this);
@@ -643,16 +644,17 @@ ISurfaceAllocator*
 BufferTextureClient::GetAllocator() const
 {
   return mAllocator;
 }
 
 bool
 BufferTextureClient::UpdateSurface(gfxASurface* aSurface)
 {
+  MOZ_ASSERT(mLocked);
   MOZ_ASSERT(aSurface);
   MOZ_ASSERT(!IsImmutable());
   MOZ_ASSERT(IsValid());
 
   ImageDataSerializer serializer(GetBuffer(), GetBufferSize());
   if (!serializer.IsValid()) {
     return false;
   }
@@ -671,16 +673,17 @@ BufferTextureClient::UpdateSurface(gfxAS
     MarkImmutable();
   }
   return true;
 }
 
 already_AddRefed<gfxASurface>
 BufferTextureClient::GetAsSurface()
 {
+  MOZ_ASSERT(mLocked);
   MOZ_ASSERT(IsValid());
 
   ImageDataSerializer serializer(GetBuffer(), GetBufferSize());
   if (!serializer.IsValid()) {
     return nullptr;
   }
 
   RefPtr<gfxImageSurface> surf = serializer.GetAsThebesSurface();
@@ -710,18 +713,17 @@ BufferTextureClient::AllocateForSurface(
   mSize = aSize;
   return true;
 }
 
 TemporaryRef<gfx::DrawTarget>
 BufferTextureClient::GetAsDrawTarget()
 {
   MOZ_ASSERT(IsValid());
-  // XXX - Turn this into a fatal assertion as soon as Bug 952507 is fixed
-  NS_WARN_IF_FALSE(mLocked, "GetAsDrawTarget should be called on locked textures only");
+  MOZ_ASSERT(mLocked, "GetAsDrawTarget should be called on locked textures only");
 
   if (mDrawTarget) {
     return mDrawTarget;
   }
 
   ImageDataSerializer serializer(GetBuffer(), GetBufferSize());
   if (!serializer.IsValid()) {
     return nullptr;
@@ -748,34 +750,38 @@ BufferTextureClient::GetAsDrawTarget()
     mDrawTarget->CopySurface(surface, rect, IntPoint(0,0));
   }
   return mDrawTarget;
 }
 
 bool
 BufferTextureClient::Lock(OpenMode aMode)
 {
-  // XXX - Turn this into a fatal assertion as soon as Bug 952507 is fixed
-  NS_WARN_IF_FALSE(!mLocked, "The TextureClient is already Locked!");
+  MOZ_ASSERT(!mLocked, "The TextureClient is already Locked!");
   mOpenMode = aMode;
   mLocked = IsValid() && IsAllocated();;
   return mLocked;
 }
 
 void
 BufferTextureClient::Unlock()
 {
-  // XXX - Turn this into a fatal assertion as soon as Bug 952507 is fixed
-  NS_WARN_IF_FALSE(mLocked, "The TextureClient is already Unlocked!");
+  MOZ_ASSERT(mLocked, "The TextureClient is already Unlocked!");
   mLocked = false;
   if (!mDrawTarget) {
     mUsingFallbackDrawTarget = false;
     return;
   }
 
+  // see the comment on TextureClientDrawTarget::GetAsDrawTarget.
+  // This DrawTarget is internal to the TextureClient and is only exposed to the
+  // outside world between Lock() and Unlock(). This assertion checks that no outside
+  // reference remains by the time Unlock() is called.
+  MOZ_ASSERT(mDrawTarget->refCount() == 1);
+
   mDrawTarget->Flush();
   if (mUsingFallbackDrawTarget && (mOpenMode & OPEN_WRITE)) {
     // When we are using a fallback DrawTarget, it means we could not create
     // a DrawTarget wrapping the TextureClient's shared memory. In this scenario
     // we need to put the content of the fallback draw target back into our shared
     // memory.
     RefPtr<SourceSurface> snapshot = mDrawTarget->Snapshot();
     RefPtr<DataSourceSurface> surface = snapshot->GetDataSurface();
@@ -797,16 +803,17 @@ BufferTextureClient::Unlock()
   }
   mDrawTarget = nullptr;
   mUsingFallbackDrawTarget = false;
 }
 
 bool
 BufferTextureClient::UpdateYCbCr(const PlanarYCbCrData& aData)
 {
+  MOZ_ASSERT(mLocked);
   MOZ_ASSERT(mFormat == gfx::SurfaceFormat::YUV, "This textureClient can only use YCbCr data");
   MOZ_ASSERT(!IsImmutable());
   MOZ_ASSERT(IsValid());
   MOZ_ASSERT(aData.mCbSkip == aData.mCrSkip);
 
   YCbCrImageDataSerializer serializer(GetBuffer(), GetBufferSize());
   MOZ_ASSERT(serializer.IsValid());
   if (!serializer.CopyData(aData.mYChannel, aData.mCbChannel, aData.mCrChannel,
--- a/gfx/layers/d3d11/TextureD3D11.cpp
+++ b/gfx/layers/d3d11/TextureD3D11.cpp
@@ -183,16 +183,20 @@ TextureClientD3D11::Lock(OpenMode aMode)
   return true;
 }
 
 void
 TextureClientD3D11::Unlock()
 {
   MOZ_ASSERT(mIsLocked, "Unlocked called while the texture is not locked!");
   if (mDrawTarget) {
+    // see the comment on TextureClientDrawTarget::GetAsDrawTarget.
+    // This DrawTarget is internal to the TextureClient and is only exposed to the
+    // outside world between Lock() and Unlock(). This assertion checks that no outside
+    // reference remains by the time Unlock() is called.
     MOZ_ASSERT(mDrawTarget->refCount() == 1);
     mDrawTarget->Flush();
   }
 
   // The DrawTarget is created only once, and is only usable between calls
   // to Lock and Unlock.
   UnlockD3DTexture(mTexture.get());
   mIsLocked = false;
--- a/gfx/layers/ipc/ImageBridgeChild.cpp
+++ b/gfx/layers/ipc/ImageBridgeChild.cpp
@@ -114,16 +114,17 @@ ImageBridgeChild::UseTexture(Compositabl
                                    nullptr, aTexture->GetIPDLActor()));
 }
 
 void
 ImageBridgeChild::UseComponentAlphaTextures(CompositableClient* aCompositable,
                                             TextureClient* aTextureOnBlack,
                                             TextureClient* aTextureOnWhite)
 {
+  MOZ_ASSERT(aTextureOnBlack->GetSize() == aTextureOnWhite->GetSize());
   mTxn->AddNoSwapEdit(OpUseComponentAlphaTextures(nullptr, aCompositable->GetIPDLActor(),
                                                   nullptr, aTextureOnBlack->GetIPDLActor(),
                                                   nullptr, aTextureOnWhite->GetIPDLActor()));
 }
 
 void
 ImageBridgeChild::UpdatedTexture(CompositableClient* aCompositable,
                                  TextureClient* aTexture,
--- a/gfx/layers/ipc/ShadowLayers.cpp
+++ b/gfx/layers/ipc/ShadowLayers.cpp
@@ -434,16 +434,17 @@ ShadowLayerForwarder::UseTexture(Composi
                              nullptr, aTexture->GetIPDLActor()));
 }
 
 void
 ShadowLayerForwarder::UseComponentAlphaTextures(CompositableClient* aCompositable,
                                                 TextureClient* aTextureOnBlack,
                                                 TextureClient* aTextureOnWhite)
 {
+  MOZ_ASSERT(aTextureOnBlack->GetSize() == aTextureOnWhite->GetSize());
   mTxn->AddEdit(OpUseComponentAlphaTextures(nullptr, aCompositable->GetIPDLActor(),
                                             nullptr, aTextureOnBlack->GetIPDLActor(),
                                             nullptr, aTextureOnWhite->GetIPDLActor()));
 }
 
 void
 ShadowLayerForwarder::RemoveTextureFromCompositable(CompositableClient* aCompositable,
                                                     TextureClient* aTexture)