Clean up some methods on ContentClient (bug 1409871 part 17, r=nical) draft
authorRyan Hunt <rhunt@eqrion.net>
Wed, 18 Oct 2017 14:54:26 -0400
changeset 684139 e39739b9b1bff36966e38e8dfb95fdac4ae73552
parent 684138 b6dafe25315d42b6b556c0dd75f46120b65978ad
child 684140 8c58ba66dc913dfaf8f870c8330fe993f4ab7d85
push id85567
push userbmo:rhunt@eqrion.net
push dateFri, 20 Oct 2017 22:13:22 +0000
reviewersnical
bugs1409871
milestone58.0a1
Clean up some methods on ContentClient (bug 1409871 part 17, r=nical) This commit does some more cleanup on the content client class hierarchy. Some methods were virtual or instance methods when they didn't need to be. MozReview-Commit-ID: 2y2D3zYtYvM
gfx/layers/basic/BasicPaintedLayer.cpp
gfx/layers/client/ClientPaintedLayer.cpp
gfx/layers/client/ContentClient.cpp
gfx/layers/client/ContentClient.h
--- a/gfx/layers/basic/BasicPaintedLayer.cpp
+++ b/gfx/layers/basic/BasicPaintedLayer.cpp
@@ -182,23 +182,23 @@ BasicPaintedLayer::Validate(LayerManager
 
     PaintBuffer(ctx,
                 state.mRegionToDraw, state.mRegionToDraw, state.mRegionToInvalidate,
                 state.mClip,
                 aCallback, aCallbackData);
     MOZ_LAYERS_LOG_IF_SHADOWABLE(this, ("Layer::Mutated(%p) PaintThebes", this));
     Mutated();
     ctx = nullptr;
-    mContentClient->ReturnDrawTargetToBuffer(target);
+    mContentClient->ReturnDrawTarget(target);
     target = nullptr;
 
     RenderTraceInvalidateEnd(this, "FFFF00");
   } else {
     if (target) {
-      mContentClient->ReturnDrawTargetToBuffer(target);
+      mContentClient->ReturnDrawTarget(target);
       target = nullptr;
     }
 
     // It's possible that state.mRegionToInvalidate is nonempty here,
     // if we are shrinking the valid region to nothing. So use mRegionToDraw
     // instead.
     NS_WARNING_ASSERTION(
       state.mRegionToDraw.IsEmpty(),
--- a/gfx/layers/client/ClientPaintedLayer.cpp
+++ b/gfx/layers/client/ClientPaintedLayer.cpp
@@ -147,17 +147,17 @@ ClientPaintedLayer::PaintThebes(nsTArray
     return;
   }
 
   bool didUpdate = false;
   RotatedBuffer::DrawIterator iter;
   while (DrawTarget* target = mContentClient->BorrowDrawTargetForPainting(state, &iter)) {
     if (!target || !target->IsValid()) {
       if (target) {
-        mContentClient->ReturnDrawTargetToBuffer(target);
+        mContentClient->ReturnDrawTarget(target);
       }
       continue;
     }
 
     SetAntialiasingFlags(this, target);
 
     RefPtr<gfxContext> ctx = gfxContext::CreatePreservingTransformOrNull(target);
     MOZ_ASSERT(ctx); // already checked the target above
@@ -166,17 +166,17 @@ ClientPaintedLayer::PaintThebes(nsTArray
                                               ctx,
                                               iter.mDrawRegion,
                                               iter.mDrawRegion,
                                               state.mClip,
                                               state.mRegionToInvalidate,
                                               ClientManager()->GetPaintedLayerCallbackData());
 
     ctx = nullptr;
-    mContentClient->ReturnDrawTargetToBuffer(target);
+    mContentClient->ReturnDrawTarget(target);
     didUpdate = true;
   }
 
   mContentClient->EndPaint(aReadbackUpdates);
 
   if (didUpdate) {
     UpdateContentClient(state);
   }
@@ -222,17 +222,17 @@ ClientPaintedLayer::PaintOffMainThread()
 
   // Debug Protip: Change to BorrowDrawTargetForPainting if using sync OMTP.
   while (RefPtr<CapturedPaintState> captureState =
           mContentClient->BorrowDrawTargetForRecording(state, &iter))
   {
     DrawTarget* target = captureState->mTargetDual;
     if (!target || !target->IsValid()) {
       if (target) {
-        mContentClient->ReturnDrawTargetToBuffer(target);
+        mContentClient->ReturnDrawTarget(target);
       }
       continue;
     }
 
     RefPtr<DrawTargetCapture> captureDT =
       Factory::CreateCaptureDrawTarget(target->GetBackendType(),
                                        target->GetSize(),
                                        target->GetFormat());
@@ -252,17 +252,17 @@ ClientPaintedLayer::PaintOffMainThread()
                                               ClientManager()->GetPaintedLayerCallbackData());
 
     ctx = nullptr;
 
     captureState->mCapture = captureDT.forget();
     PaintThread::Get()->PaintContents(captureState,
                                       ContentClient::PrepareDrawTargetForPainting);
 
-    mContentClient->ReturnDrawTargetToBuffer(target);
+    mContentClient->ReturnDrawTarget(target);
 
     didUpdate = true;
   }
 
   PaintThread::Get()->EndLayer();
   mContentClient->EndPaint(nullptr);
 
   if (didUpdate) {
--- a/gfx/layers/client/ContentClient.cpp
+++ b/gfx/layers/client/ContentClient.cpp
@@ -251,16 +251,37 @@ ContentClient::BorrowDrawTargetForPainti
 
   if (!ContentClient::PrepareDrawTargetForPainting(capturedState)) {
     return nullptr;
   }
 
   return capturedState->mTargetDual;
 }
 
+nsIntRegion
+ExpandDrawRegion(ContentClient::PaintState& aPaintState,
+                 RotatedBuffer::DrawIterator* aIter,
+                 BackendType aBackendType)
+{
+  nsIntRegion* drawPtr = &aPaintState.mRegionToDraw;
+  if (aIter) {
+    // The iterators draw region currently only contains the bounds of the region,
+    // this makes it the precise region.
+    aIter->mDrawRegion.And(aIter->mDrawRegion, aPaintState.mRegionToDraw);
+    drawPtr = &aIter->mDrawRegion;
+  }
+  if (aBackendType == BackendType::DIRECT2D ||
+      aBackendType == BackendType::DIRECT2D1_1) {
+    // Simplify the draw region to avoid hitting expensive drawing paths
+    // for complex regions.
+    drawPtr->SimplifyOutwardByArea(100 * 100);
+  }
+  return *drawPtr;
+}
+
 RefPtr<CapturedPaintState>
 ContentClient::BorrowDrawTargetForRecording(ContentClient::PaintState& aPaintState,
                                             RotatedBuffer::DrawIterator* aIter,
                                             bool aSetTransform)
 {
   if (aPaintState.mMode == SurfaceMode::SURFACE_NONE ||
       !mBuffer || !mBuffer->IsLocked()) {
     return nullptr;
@@ -286,42 +307,21 @@ ContentClient::BorrowDrawTargetForRecord
                            mBuffer->GetDTBufferOnWhite(),
                            transform,
                            aPaintState.mMode,
                            aPaintState.mContentType);
   return state;
 }
 
 void
-ContentClient::ReturnDrawTargetToBuffer(gfx::DrawTarget*& aReturned)
+ContentClient::ReturnDrawTarget(gfx::DrawTarget*& aReturned)
 {
   mBuffer->ReturnDrawTarget(aReturned);
 }
 
-nsIntRegion
-ContentClient::ExpandDrawRegion(ContentClient::PaintState& aPaintState,
-                                RotatedBuffer::DrawIterator* aIter,
-                                BackendType aBackendType)
-{
-  nsIntRegion* drawPtr = &aPaintState.mRegionToDraw;
-  if (aIter) {
-    // The iterators draw region currently only contains the bounds of the region,
-    // this makes it the precise region.
-    aIter->mDrawRegion.And(aIter->mDrawRegion, aPaintState.mRegionToDraw);
-    drawPtr = &aIter->mDrawRegion;
-  }
-  if (aBackendType == BackendType::DIRECT2D ||
-      aBackendType == BackendType::DIRECT2D1_1) {
-    // Simplify the draw region to avoid hitting expensive drawing paths
-    // for complex regions.
-    drawPtr->SimplifyOutwardByArea(100 * 100);
-  }
-  return *drawPtr;
-}
-
 /*static */ bool
 ContentClient::PrepareDrawTargetForPainting(CapturedPaintState* aState)
 {
   MOZ_ASSERT(aState);
   RefPtr<DrawTarget> target = aState->mTarget;
   RefPtr<DrawTarget> whiteTarget = aState->mTargetOnWhite;
 
   if (aState->mSurfaceMode == SurfaceMode::SURFACE_COMPONENT_ALPHA) {
@@ -627,29 +627,16 @@ private:
   // This array is used to keep the layers alive until the callback.
   vector<RefPtr<Layer>> mLayerRefs;
 
   IntRect mBufferRect;
   nsIntPoint mBufferRotation;
 };
 
 void
-ContentClientRemoteBuffer::BeginPaint()
-{
-  EnsureBackBufferIfFrontBuffer();
-}
-
-void
-ContentClientRemoteBuffer::BeginAsyncPaint()
-{
-  BeginPaint();
-  mInAsyncPaint = true;
-}
-
-void
 ContentClientRemoteBuffer::EndPaint(nsTArray<ReadbackProcessor::Update>* aReadbackUpdates)
 {
   MOZ_ASSERT(!mBuffer || !mBuffer->HaveBufferOnWhite() ||
              !aReadbackUpdates || aReadbackUpdates->Length() == 0);
 
   RemoteRotatedBuffer* remoteBuffer = GetRemoteBuffer();
 
   if (remoteBuffer && remoteBuffer->IsLocked()) {
@@ -831,16 +818,23 @@ ContentClientDoubleBuffered::Dump(std::s
     aStream << "\n" << aPrefix << "Surface: ";
   }
   CompositableClient::DumpTextureClient(aStream,
                                         mFrontBuffer ? mFrontBuffer->GetClient() : nullptr,
                                         aCompress);
 }
 
 void
+ContentClientDoubleBuffered::Clear()
+{
+  ContentClient::Clear();
+  mFrontBuffer = nullptr;
+}
+
+void
 ContentClientDoubleBuffered::SwapBuffers(const nsIntRegion& aFrontUpdatedRegion)
 {
   mFrontUpdatedRegion = aFrontUpdatedRegion;
 
   RefPtr<RemoteRotatedBuffer> frontBuffer = mFrontBuffer;
   RefPtr<RemoteRotatedBuffer> backBuffer = GetRemoteBuffer();
 
   std::swap(frontBuffer, backBuffer);
@@ -849,17 +843,17 @@ ContentClientDoubleBuffered::SwapBuffers
   mBuffer = backBuffer;
 
   mFrontAndBackBufferDiffer = true;
 }
 
 void
 ContentClientDoubleBuffered::BeginPaint()
 {
-  ContentClientRemoteBuffer::BeginPaint();
+  EnsureBackBufferIfFrontBuffer();
 
   mIsNewBuffer = false;
 
   if (!mFrontAndBackBufferDiffer) {
     return;
   }
 
   if (!mFrontBuffer || !mBuffer) {
--- a/gfx/layers/client/ContentClient.h
+++ b/gfx/layers/client/ContentClient.h
@@ -168,32 +168,23 @@ public:
    * is not applied to the returned DrawTarget by default, BUT it is
    * required to be whenever drawing does happen.
    */
   virtual RefPtr<CapturedPaintState> BorrowDrawTargetForRecording(
     PaintState& aPaintState,
     RotatedBuffer::DrawIterator* aIter,
     bool aSetTransform = false);
 
-  virtual void ReturnDrawTargetToBuffer(gfx::DrawTarget*& aReturned);
-
-  // Called as part of the layers transation reply. Conveys data about our
-  // buffer(s) from the compositor. If appropriate we should swap references
-  // to our buffers.
-  virtual void SwapBuffers(const nsIntRegion& aFrontUpdatedRegion) {}
+  void ReturnDrawTarget(gfx::DrawTarget*& aReturned);
 
   // Call before and after painting into this content client
   virtual void BeginPaint() {}
   virtual void BeginAsyncPaint();
   virtual void EndPaint(nsTArray<ReadbackProcessor::Update>* aReadbackUpdates = nullptr);
 
-  nsIntRegion ExpandDrawRegion(PaintState& aPaintState,
-                               RotatedBuffer::DrawIterator* aIter,
-                               gfx::BackendType aBackendType);
-
   static bool PrepareDrawTargetForPainting(CapturedPaintState*);
 
   enum {
     BUFFER_COMPONENT_ALPHA = 0x02 // Dual buffers should be created for drawing with
                                   // component alpha.
   };
 
 protected:
@@ -311,38 +302,36 @@ public:
                     const char* aPrefix="",
                     bool aDumpHtml=false,
                     TextureDumpMode aCompress=TextureDumpMode::Compress) override;
 
   virtual RefPtr<CapturedPaintState> BorrowDrawTargetForRecording(PaintState& aPaintState,
                                                                   RotatedBuffer::DrawIterator* aIter,
                                                                   bool aSetTransform) override;
 
-  virtual void BeginPaint() override;
-  virtual void BeginAsyncPaint() override;
   virtual void EndPaint(nsTArray<ReadbackProcessor::Update>* aReadbackUpdates = nullptr) override;
 
   virtual void Updated(const nsIntRegion& aRegionToDraw,
                        const nsIntRegion& aVisibleRegion);
 
   virtual TextureFlags ExtraTextureFlags() const
   {
     return TextureFlags::IMMEDIATE_UPLOAD;
   }
 
 protected:
+  /**
+   * Called when we have been updated and should swap references to our
+   * buffers.
+   */
+  virtual void SwapBuffers(const nsIntRegion& aFrontUpdatedRegion) {}
+
   virtual nsIntRegion GetUpdatedRegion(const nsIntRegion& aRegionToDraw,
                                        const nsIntRegion& aVisibleRegion);
 
-  /**
-   * Ensure we have a valid back buffer if we have a valid front buffer (i.e.
-   * if a backbuffer has been created.)
-   */
-  virtual void EnsureBackBufferIfFrontBuffer() {}
-
   virtual RefPtr<RotatedBuffer> CreateBuffer(gfxContentType aType,
                                              const gfx::IntRect& aRect,
                                              uint32_t aFlags) override;
 
   RefPtr<RotatedBuffer> CreateBufferInternal(const gfx::IntRect& aRect,
                                              gfx::SurfaceFormat aFormat,
                                              TextureFlags aFlags);
 
@@ -373,37 +362,33 @@ public:
 
   virtual ~ContentClientDoubleBuffered() {}
 
   virtual void Dump(std::stringstream& aStream,
                     const char* aPrefix="",
                     bool aDumpHtml=false,
                     TextureDumpMode aCompress=TextureDumpMode::Compress) override;
 
-  virtual void Clear() override
-  {
-    ContentClient::Clear();
-    mFrontBuffer = nullptr;
-  }
+  virtual void Clear() override;
 
   virtual void SwapBuffers(const nsIntRegion& aFrontUpdatedRegion) override;
 
   virtual void BeginPaint() override;
   virtual void BeginAsyncPaint() override;
 
   virtual void FinalizeFrame(const nsIntRegion& aRegionToDraw) override;
 
-  virtual void EnsureBackBufferIfFrontBuffer() override;
-
   virtual TextureInfo GetTextureInfo() const override
   {
     return TextureInfo(CompositableType::CONTENT_DOUBLE, mTextureFlags);
   }
 
 private:
+  void EnsureBackBufferIfFrontBuffer();
+
   RefPtr<RemoteRotatedBuffer> mFrontBuffer;
   nsIntRegion mFrontUpdatedRegion;
   bool mFrontAndBackBufferDiffer;
 };
 
 /**
  * A single buffered ContentClientRemoteBuffer. We have a single
  * TextureClient/Host which we update and then send a message to the