Bug 1088300 - Null-check TileClient::mAllocator. r=milan
authorNicolas Silva <nsilva@mozilla.com>
Tue, 30 Aug 2016 13:48:29 +0200
changeset 312400 41632799ddc4a50356a837ed37a1918a5bfe59f5
parent 312399 565bac97a123fa4d0e7e623a1df448085b3afec9
child 312401 1d96c286f93e59548bb9462626ebd135b46c6956
push id20447
push userkwierso@gmail.com
push dateFri, 02 Sep 2016 20:36:44 +0000
treeherderfx-team@969397f22187 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmilan
bugs1088300
milestone51.0a1
Bug 1088300 - Null-check TileClient::mAllocator. r=milan
gfx/layers/client/TiledContentClient.cpp
--- a/gfx/layers/client/TiledContentClient.cpp
+++ b/gfx/layers/client/TiledContentClient.cpp
@@ -536,35 +536,40 @@ TileClient::ValidateBackBufferFromFront(
 }
 
 void
 TileClient::DiscardFrontBuffer()
 {
   if (mFrontBuffer) {
     MOZ_ASSERT(mFrontBuffer->GetReadLock());
 
-    mAllocator->ReturnTextureClientDeferred(mFrontBuffer);
-    if (mFrontBufferOnWhite) {
-      mAllocator->ReturnTextureClientDeferred(mFrontBufferOnWhite);
+    MOZ_ASSERT(mAllocator);
+    if (mAllocator) {
+      mAllocator->ReturnTextureClientDeferred(mFrontBuffer);
+      if (mFrontBufferOnWhite) {
+        mAllocator->ReturnTextureClientDeferred(mFrontBufferOnWhite);
+      }
     }
+
     if (mFrontBuffer->IsLocked()) {
       mFrontBuffer->Unlock();
     }
     if (mFrontBufferOnWhite && mFrontBufferOnWhite->IsLocked()) {
       mFrontBufferOnWhite->Unlock();
     }
     mFrontBuffer = nullptr;
     mFrontBufferOnWhite = nullptr;
   }
 }
 
 static void
 DiscardTexture(TextureClient* aTexture, TextureClientAllocator* aAllocator)
 {
-  if (aTexture) {
+  MOZ_ASSERT(aAllocator);
+  if (aTexture && aAllocator) {
     MOZ_ASSERT(aTexture->GetReadLock());
     if (!aTexture->HasSynchronization() && aTexture->IsReadLocked()) {
       // Our current back-buffer is still locked by the compositor. This can occur
       // when the client is producing faster than the compositor can consume. In
       // this case we just want to drop it and not return it to the pool.
      aAllocator->ReportClientLost();
     } else {
       aAllocator->ReturnTextureClientDeferred(aTexture);
@@ -573,20 +578,22 @@ DiscardTexture(TextureClient* aTexture, 
       aTexture->Unlock();
     }
   }
 }
 
 void
 TileClient::DiscardBackBuffer()
 {
-  DiscardTexture(mBackBuffer, mAllocator);
-  mBackBuffer.Set(this, nullptr);
-  DiscardTexture(mBackBufferOnWhite, mAllocator);
-  mBackBufferOnWhite = nullptr;
+  if (mBackBuffer) {
+    DiscardTexture(mBackBuffer, mAllocator);
+    mBackBuffer.Set(this, nullptr);
+    DiscardTexture(mBackBufferOnWhite, mAllocator);
+    mBackBufferOnWhite = nullptr;
+  }
 }
 
 static already_AddRefed<TextureClient>
 CreateBackBufferTexture(TextureClient* aCurrentTexture,
                         CompositableClient& aCompositable,
                         TextureClientAllocator* aAllocator)
 {
   if (aCurrentTexture) {
@@ -616,16 +623,20 @@ CreateBackBufferTexture(TextureClient* a
 TextureClient*
 TileClient::GetBackBuffer(CompositableClient& aCompositable,
                           const nsIntRegion& aDirtyRegion,
                           gfxContentType aContent,
                           SurfaceMode aMode,
                           nsIntRegion& aAddPaintedRegion,
                           RefPtr<TextureClient>* aBackBufferOnWhite)
 {
+  if (!mAllocator) {
+    gfxCriticalError() << "[TileClient] Missing TextureClientAllocator.";
+    return nullptr;
+  }
   if (aMode != SurfaceMode::SURFACE_COMPONENT_ALPHA) {
     // It can happen that a component-alpha layer stops being on component alpha
     // on the next frame, just drop the buffers on white if that happens.
     if (mBackBufferOnWhite) {
       mAllocator->ReportClientLost();
       mBackBufferOnWhite = nullptr;
     }
     if (mFrontBufferOnWhite) {
@@ -1039,21 +1050,22 @@ ClientMultiTiledLayerBuffer::ValidateTil
   if (aDirtyRegion.IsComplex()) {
     printf_stderr("Complex region\n");
   }
 #endif
 
   SurfaceMode mode;
   gfxContentType content = GetContentType(&mode);
 
-  if (aTile.IsPlaceholderTile()) {
+  if (!aTile.mAllocator) {
     aTile.SetTextureAllocator(mManager->GetCompositorBridgeChild()->GetTexturePool(
       mManager->GetCompositorBackendType(),
       gfxPlatform::GetPlatform()->Optimal2DFormatForContent(content),
       TextureFlags::DISALLOW_BIGIMAGE | TextureFlags::IMMEDIATE_UPLOAD));
+    MOZ_ASSERT(aTile.mAllocator);
   }
 
   nsIntRegion offsetScaledDirtyRegion = aDirtyRegion.MovedBy(-aTileOrigin);
   offsetScaledDirtyRegion.ScaleRoundOut(mResolution, mResolution);
 
   nsIntRegion extraPainted;
   RefPtr<TextureClient> backBufferOnWhite;
   RefPtr<TextureClient> backBuffer =