Bug 1244901 - When recording transform duration for potential checkerboarding time, do so on the compositor thread. r?botond draft
authorKartikaya Gupta <kgupta@mozilla.com>
Mon, 01 Feb 2016 19:41:10 -0500
changeset 327797 0f5066a9eb30a78c949926ebccfc15785371cdd5
parent 327605 d07dbd40dcd209124149f331f60dd55c8da33fbe
child 513763 33842ac1a26bddcaa2ce968e555cc5dc354087d2
push id10306
push userkgupta@mozilla.com
push dateTue, 02 Feb 2016 00:41:22 +0000
reviewersbotond
bugs1244901
milestone47.0a1
Bug 1244901 - When recording transform duration for potential checkerboarding time, do so on the compositor thread. r?botond
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/src/PotentialCheckerboardDurationTracker.cpp
gfx/layers/apz/src/PotentialCheckerboardDurationTracker.h
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -3144,16 +3144,17 @@ AsyncPanZoomController::ReportCheckerboa
   bool recordTrace = gfxPrefs::APZRecordCheckerboarding();
   bool forTelemetry = Telemetry::CanRecordExtended();
   uint32_t magnitude = GetCheckerboardMagnitude();
 
   MutexAutoLock lock(mCheckerboardEventLock);
   if (!mCheckerboardEvent && (recordTrace || forTelemetry)) {
     mCheckerboardEvent = MakeUnique<CheckerboardEvent>(recordTrace);
   }
+  mPotentialCheckerboardTracker.InTransform(IsTransformingState(mState));
   if (magnitude) {
     mPotentialCheckerboardTracker.CheckerboardSeen();
   }
   if (mCheckerboardEvent && mCheckerboardEvent->RecordFrameInfo(magnitude)) {
     // This checkerboard event is done. Report some metrics to telemetry.
     mozilla::Telemetry::Accumulate(mozilla::Telemetry::CHECKERBOARD_SEVERITY,
       mCheckerboardEvent->GetSeverity());
     mozilla::Telemetry::Accumulate(mozilla::Telemetry::CHECKERBOARD_PEAK,
@@ -3629,28 +3630,26 @@ void AsyncPanZoomController::DispatchSta
     ReentrantMonitorAutoEnter lock(mMonitor);
     if (mNotificationBlockers > 0) {
       return;
     }
   }
 
   if (RefPtr<GeckoContentController> controller = GetGeckoContentController()) {
     if (!IsTransformingState(aOldState) && IsTransformingState(aNewState)) {
-      mPotentialCheckerboardTracker.TransformStarted();
       controller->NotifyAPZStateChange(
           GetGuid(), APZStateChange::TransformBegin);
 #if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
       // Let the compositor know about scroll state changes so it can manage
       // windowed plugins.
       if (mCompositorParent) {
         mCompositorParent->ScheduleHideAllPluginWindows();
       }
 #endif
     } else if (IsTransformingState(aOldState) && !IsTransformingState(aNewState)) {
-      mPotentialCheckerboardTracker.TransformStopped();
       controller->NotifyAPZStateChange(
           GetGuid(), APZStateChange::TransformEnd);
 #if defined(XP_WIN) || defined(MOZ_WIDGET_GTK)
       if (mCompositorParent) {
         mCompositorParent->ScheduleShowAllPluginWindows();
       }
 #endif
     }
--- a/gfx/layers/apz/src/PotentialCheckerboardDurationTracker.cpp
+++ b/gfx/layers/apz/src/PotentialCheckerboardDurationTracker.cpp
@@ -35,31 +35,39 @@ PotentialCheckerboardDurationTracker::Ch
   if (!Tracking()) {
     mozilla::Telemetry::AccumulateTimeDelta(
         mozilla::Telemetry::CHECKERBOARD_POTENTIAL_DURATION,
         mCurrentPeriodStart);
   }
 }
 
 void
-PotentialCheckerboardDurationTracker::TransformStarted()
+PotentialCheckerboardDurationTracker::InTransform(bool aInTransform)
 {
-  MOZ_ASSERT(!mInTransform);
-  if (!Tracking()) {
-    mCurrentPeriodStart = TimeStamp::Now();
+  if (aInTransform == mInTransform) {
+    // no-op
+    return;
   }
-  mInTransform = true;
-}
 
-void
-PotentialCheckerboardDurationTracker::TransformStopped()
-{
-  MOZ_ASSERT(mInTransform);
-  mInTransform = false;
   if (!Tracking()) {
+    // Because !Tracking(), mInTransform must be false, and so aInTransform
+    // must be true (or we would have early-exited this function already).
+    // Therefore, we are starting a potential checkerboard period.
+    mInTransform = aInTransform;
+    mCurrentPeriodStart = TimeStamp::Now();
+    return;
+  }
+
+  mInTransform = aInTransform;
+
+  if (!Tracking()) {
+    // Tracking() must have been true at the start of this function, or we
+    // would have taken the other !Tracking branch above. If it's false now,
+    // it means we just stopped tracking, so we are ending a potential
+    // checkerboard period.
     mozilla::Telemetry::AccumulateTimeDelta(
         mozilla::Telemetry::CHECKERBOARD_POTENTIAL_DURATION,
         mCurrentPeriodStart);
   }
 }
 
 bool
 PotentialCheckerboardDurationTracker::Tracking() const
--- a/gfx/layers/apz/src/PotentialCheckerboardDurationTracker.h
+++ b/gfx/layers/apz/src/PotentialCheckerboardDurationTracker.h
@@ -34,25 +34,20 @@ public:
   void CheckerboardSeen();
   /**
    * This should be called when checkerboarding is done. It must have been
    * preceded by one or more calls to CheckerboardSeen().
    */
   void CheckerboardDone();
 
   /**
-   * This should be called when a transform is started. Calls to this must be
-   * interleaved with calls to TransformStopped().
+   * This should be called at composition time, to indicate if the APZC is in
+   * a transforming state or not.
    */
-  void TransformStarted();
-  /**
-   * This should be called when a transform is stopped. Calls to this must be
-   * interleaved with calls to TransformStarted().
-   */
-  void TransformStopped();
+  void InTransform(bool aInTransform);
 
 private:
   bool Tracking() const;
 
 private:
   bool mInCheckerboard;
   bool mInTransform;