Bug 1435022 - Make the Composite function private and document/clean it. r?sotaro draft
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 01 Feb 2018 16:28:53 -0500
changeset 750299 9130b90c157d27882fc1278c3a3918ce187621dc
parent 750298 1f4e754143ecfd714ec5c424a860faaf4b0cd136
child 750300 f4d29c4dd7c5e2e59d012c7eebcedac479ce74eb
push id97612
push userkgupta@mozilla.com
push dateThu, 01 Feb 2018 21:30:35 +0000
reviewerssotaro
bugs1435022
milestone60.0a1
Bug 1435022 - Make the Composite function private and document/clean it. r?sotaro MozReview-Commit-ID: 3UQKwwC3Fav
gfx/layers/ipc/CompositorVsyncScheduler.cpp
gfx/layers/ipc/CompositorVsyncScheduler.h
--- a/gfx/layers/ipc/CompositorVsyncScheduler.cpp
+++ b/gfx/layers/ipc/CompositorVsyncScheduler.cpp
@@ -206,42 +206,49 @@ CompositorVsyncScheduler::CancelCurrentC
     mCurrentCompositeTask = nullptr;
   }
 }
 
 void
 CompositorVsyncScheduler::Composite(TimeStamp aVsyncTimestamp)
 {
   MOZ_ASSERT(CompositorThreadHolder::IsInCompositorThread());
-  {
+  MOZ_ASSERT(mVsyncSchedulerOwner);
+
+  { // scope lock
     MonitorAutoLock lock(mCurrentCompositeTaskMonitor);
     mCurrentCompositeTask = nullptr;
   }
 
-  if ((aVsyncTimestamp < mLastCompose) && !mAsapScheduling) {
-    // We can sometimes get vsync timestamps that are in the past
-    // compared to the last compose with force composites.
-    // In those cases, wait until the next vsync;
-    return;
-  }
+  if (!mAsapScheduling) {
+    // Some early exit conditions if we're not in ASAP mode
+    if (aVsyncTimestamp < mLastCompose) {
+      // We can sometimes get vsync timestamps that are in the past
+      // compared to the last compose with force composites.
+      // In those cases, wait until the next vsync;
+      return;
+    }
 
-  MOZ_ASSERT(mVsyncSchedulerOwner);
-  if (!mAsapScheduling && mVsyncSchedulerOwner->IsPendingComposite()) {
-    // If previous composite is still on going, finish it and does a next
-    // composite in a next vsync.
-    mVsyncSchedulerOwner->FinishPendingComposite();
-    return;
+    if (mVsyncSchedulerOwner->IsPendingComposite()) {
+      // If previous composite is still on going, finish it and wait for the
+      // next vsync.
+      mVsyncSchedulerOwner->FinishPendingComposite();
+      return;
+    }
   }
 
   DispatchTouchEvents(aVsyncTimestamp);
 
   if (mNeedsComposite || mAsapScheduling) {
     mNeedsComposite = 0;
     mLastCompose = aVsyncTimestamp;
+
+    // Tell the owner to do a composite
     mVsyncSchedulerOwner->CompositeToTarget(nullptr, nullptr);
+
     mVsyncNotificationsSkipped = 0;
 
     TimeDuration compositeFrameTotal = TimeStamp::Now() - aVsyncTimestamp;
     mozilla::Telemetry::Accumulate(mozilla::Telemetry::COMPOSITE_FRAME_ROUNDTRIP_TIME,
                                    compositeFrameTotal.ToMilliseconds());
   } else if (mVsyncNotificationsSkipped++ > gfxPrefs::CompositorUnobserveCount()) {
     UnobserveVsync();
   }
--- a/gfx/layers/ipc/CompositorVsyncScheduler.h
+++ b/gfx/layers/ipc/CompositorVsyncScheduler.h
@@ -53,17 +53,16 @@ public:
   /**
    * Do cleanup. This must be called on the compositor thread.
    */
   void Destroy();
 
   void ScheduleComposition();
   void CancelCurrentCompositeTask();
   bool NeedsComposite();
-  void Composite(TimeStamp aVsyncTimestamp);
   void ForceComposeToTarget(gfx::DrawTarget* aTarget, const gfx::IntRect* aRect);
 
   const TimeStamp& GetLastComposeTime()
   {
     return mLastCompose;
   }
 
 #ifdef COMPOSITOR_PERFORMANCE_WARNING
@@ -82,16 +81,20 @@ private:
   // Post a task to run Composite() on the compositor thread, if there isn't
   // such a task already queued. Can be called from any thread.
   void PostCompositeTask(TimeStamp aCompositeTimestamp);
 
   // Post a task to run DispatchVREvents() on the VR thread, if there isn't
   // such a task already queued. Can be called from any thread.
   void PostVRTask(TimeStamp aTimestamp);
 
+  // This gets run at vsync time and "does" a composite (which really means
+  // update internal state and call the owner to do the composite).
+  void Composite(TimeStamp aVsyncTimestamp);
+
   void NotifyCompositeTaskExecuted();
   void ObserveVsync();
   void UnobserveVsync();
   void DispatchTouchEvents(TimeStamp aVsyncTimestamp);
   void DispatchVREvents(TimeStamp aVsyncTimestamp);
 
   class Observer final : public VsyncObserver
   {