Bug 1435282 - Add a helper FlushPendingComposite function. r?sotaro draft
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 02 Feb 2018 10:48:25 -0500
changeset 750554 dd5fce9853d01a8b422d0bfe187f336c431f323c
parent 750553 2d85fa4f8f9699cc1dc0ac5cc6c5f1ca5adf5a95
child 750555 8d26ff0fe47c3f1bb36632e56092dcc8583fead1
push id97707
push userkgupta@mozilla.com
push dateFri, 02 Feb 2018 17:00:40 +0000
reviewerssotaro
bugs1435282
milestone60.0a1
Bug 1435282 - Add a helper FlushPendingComposite function. r?sotaro This extracts a code pattern that appears a couple of times in the code. It occurs in CompositorBridgeParent as well but there's some extra stuff involved there with the mOverrideComposeReadiness flag that I don't understand so I'm leaving that as-is for now. MozReview-Commit-ID: 2xqgaQZT4e1
gfx/layers/ipc/CompositorVsyncScheduler.cpp
gfx/layers/ipc/CompositorVsyncScheduler.h
gfx/layers/wr/WebRenderBridgeParent.cpp
--- a/gfx/layers/ipc/CompositorVsyncScheduler.cpp
+++ b/gfx/layers/ipc/CompositorVsyncScheduler.cpp
@@ -281,16 +281,28 @@ CompositorVsyncScheduler::ForceComposeTo
 
 bool
 CompositorVsyncScheduler::NeedsComposite()
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   return mNeedsComposite;
 }
 
+bool
+CompositorVsyncScheduler::FlushPendingComposite()
+{
+  MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
+  if (mNeedsComposite) {
+    CancelCurrentCompositeTask();
+    ForceComposeToTarget(nullptr, nullptr);
+    return true;
+  }
+  return false;
+}
+
 void
 CompositorVsyncScheduler::ObserveVsync()
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
   mWidget->ObserveVsync(mVsyncObserver);
   mIsObservingVsync = true;
 }
 
--- a/gfx/layers/ipc/CompositorVsyncScheduler.h
+++ b/gfx/layers/ipc/CompositorVsyncScheduler.h
@@ -76,16 +76,23 @@ public:
 
   /**
    * Force a composite to happen right away, without waiting for the next vsync.
    * This must be called on the compositor thread.
    */
   void ForceComposeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect);
 
   /**
+   * If a composite is pending, force it to trigger right away. This must be
+   * called on the compositor thread. Returns true if there was a composite
+   * flushed.
+   */
+  bool FlushPendingComposite();
+
+  /**
    * Return the vsync timestamp of the last or ongoing composite. Must be called
    * on the compositor thread.
    */
   const TimeStamp& GetLastComposeTime() const;
 
 private:
   virtual ~CompositorVsyncScheduler();
 
--- a/gfx/layers/wr/WebRenderBridgeParent.cpp
+++ b/gfx/layers/wr/WebRenderBridgeParent.cpp
@@ -800,21 +800,17 @@ WebRenderBridgeParent::RecvGetSnapshot(P
   MOZ_ASSERT(bufferTexture->GetFormat() == SurfaceFormat::B8G8R8A8);
   uint32_t buffer_size = size.width * size.height * 4;
 
   // Assert the stride of the buffer is what webrender expects
   MOZ_ASSERT((uint32_t)(size.width * 4) == stride);
 
   mForceRendering = true;
 
-  if (mCompositorScheduler->NeedsComposite()) {
-    mCompositorScheduler->CancelCurrentCompositeTask();
-    mCompositorScheduler->ForceComposeToTarget(nullptr, nullptr);
-  }
-
+  mCompositorScheduler->FlushPendingComposite();
   mApi->Readback(size, buffer, buffer_size);
 
   mForceRendering = false;
 
   return IPC_OK();
 }
 
 mozilla::ipc::IPCResult
@@ -1343,25 +1339,21 @@ WebRenderBridgeParent::ScheduleGenerateF
 
 void
 WebRenderBridgeParent::FlushRendering(bool aIsSync)
 {
   if (mDestroyed) {
     return;
   }
 
-  if (!mCompositorScheduler->NeedsComposite()) {
-    return;
-  }
-
   mForceRendering = true;
-  mCompositorScheduler->CancelCurrentCompositeTask();
-  mCompositorScheduler->ForceComposeToTarget(nullptr, nullptr);
-  if (aIsSync) {
-    mApi->WaitFlushed();
+  if (mCompositorScheduler->FlushPendingComposite()) {
+    if (aIsSync) {
+      mApi->WaitFlushed();
+    }
   }
   mForceRendering = false;
 }
 
 void
 WebRenderBridgeParent::Pause()
 {
   MOZ_ASSERT(mWidget);