Bug 1105836 - Add more logging to the APZ code. r=botond
authorKartikaya Gupta <kgupta@mozilla.com>
Fri, 28 Nov 2014 12:25:41 -0500
changeset 243897 3910f8c77b51524a2e56bcd7aaf046f3257320ec
parent 243896 cd8ecc2e1a2e35dffc6f0480c9d3849410b0e00d
child 243898 5a68579c6fbf4f0890d2a38e3b28a09ec581302e
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbotond
bugs1105836
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1105836 - Add more logging to the APZ code. r=botond
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/src/Axis.cpp
gfx/layers/apz/src/Axis.h
gfx/layers/apz/src/InputBlockState.cpp
gfx/layers/apz/src/InputQueue.cpp
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -2330,17 +2330,21 @@ bool AsyncPanZoomController::SnapBackIfO
     StartOverscrollAnimation(ParentLayerPoint(0, 0));
     return true;
   }
   return false;
 }
 
 bool AsyncPanZoomController::IsMovingFast() const {
   ReentrantMonitorAutoEnter lock(mMonitor);
-  return (GetVelocityVector().Length() > gfxPrefs::APZFlingStopOnTapThreshold());
+  if (GetVelocityVector().Length() > gfxPrefs::APZFlingStopOnTapThreshold()) {
+    APZC_LOG("%p is moving fast\n", this);
+    return true;
+  }
+  return false;
 }
 
 bool AsyncPanZoomController::IsPannable() const {
   ReentrantMonitorAutoEnter lock(mMonitor);
   return mX.CanScroll() || mY.CanScroll();
 }
 
 int32_t AsyncPanZoomController::GetLastTouchIdentifier() const {
--- a/gfx/layers/apz/src/Axis.cpp
+++ b/gfx/layers/apz/src/Axis.cpp
@@ -78,26 +78,29 @@ void Axis::UpdateWithTouchAtDevicePoint(
     if (gfxPrefs::APZCurveThreshold() > 0.0f && gfxPrefs::APZCurveThreshold() < gfxPrefs::APZMaxVelocity()) {
       float curveThreshold = ToLocalVelocity(gfxPrefs::APZCurveThreshold());
       if (newVelocity > curveThreshold) {
         // here, 0 < curveThreshold < newVelocity <= maxVelocity, so we apply the curve
         float scale = maxVelocity - curveThreshold;
         float funcInput = (newVelocity - curveThreshold) / scale;
         float funcOutput = gVelocityCurveFunction->GetValue(funcInput);
         float curvedVelocity = (funcOutput * scale) + curveThreshold;
-        AXIS_LOG("Curving up velocity from %f to %f\n", newVelocity, curvedVelocity);
+        AXIS_LOG("%p|%s curving up velocity from %f to %f\n",
+          mAsyncPanZoomController, Name(), newVelocity, curvedVelocity);
         newVelocity = curvedVelocity;
       }
     }
 
     if (velocityIsNegative) {
       newVelocity = -newVelocity;
     }
   }
 
+  AXIS_LOG("%p|%s updating velocity to %f with touch\n",
+    mAsyncPanZoomController, Name(), newVelocity);
   mVelocity = newVelocity;
   mPos = aPos;
   mPosTimeMs = aTimestampMs;
 
   // Limit queue size pased on pref
   mVelocityQueue.AppendElement(std::make_pair(aTimestampMs, mVelocity));
   if (mVelocityQueue.Length() > gfxPrefs::APZMaxVelocityQueueSize()) {
     mVelocityQueue.RemoveElementAt(0);
@@ -134,16 +137,18 @@ bool Axis::AdjustDisplacement(ParentLaye
   displacement += consumedOverscroll;
 
   // Split the requested displacement into an allowed displacement that does
   // not overscroll, and an overscroll amount.
   aOverscrollAmountOut = DisplacementWillOverscrollAmount(displacement);
   if (aOverscrollAmountOut != 0.0f) {
     // No need to have a velocity along this axis anymore; it won't take us
     // anywhere, so we're just spinning needlessly.
+    AXIS_LOG("%p|%s has overscrolled, clearing velocity\n",
+      mAsyncPanZoomController, Name());
     mVelocity = 0.0f;
     displacement -= aOverscrollAmountOut;
   }
   aDisplacementOut = displacement;
   return fabsf(consumedOverscroll) > EPSILON;
 }
 
 ParentLayerCoord Axis::ApplyResistance(ParentLayerCoord aRequestedOverscroll) const {
@@ -212,16 +217,18 @@ bool Axis::SampleOverscrollAnimation(con
 
   // Apply spring force.
   float springForce = -1 * kSpringStiffness * mOverscroll;
   // Assume unit mass, so force = acceleration.
   mVelocity += springForce * aDelta.ToMilliseconds();
 
   // Apply dampening.
   mVelocity *= pow(double(1 - kSpringFriction), aDelta.ToMilliseconds());
+  AXIS_LOG("%p|%s sampled overscroll animation, leaving velocity at %f\n",
+    mAsyncPanZoomController, Name(), mVelocity);
 
   // Adjust the amount of overscroll based on the velocity.
   // Note that we allow for oscillations. mInUnderscroll tracks whether
   // we are currently in a state where we have overshot and the spring is
   // displaced in the other direction.
   float oldOverscroll = mOverscroll;
   mOverscroll += (mVelocity * aDelta.ToMilliseconds());
   bool signChange = (oldOverscroll * mOverscroll) < 0;
@@ -233,16 +240,18 @@ bool Axis::SampleOverscrollAnimation(con
 
   // If both the velocity and the displacement fall below a threshold, stop
   // the animation so we don't continue doing tiny oscillations that aren't
   // noticeable.
   if (fabs(mOverscroll) < gfxPrefs::APZOverscrollStopDistanceThreshold() &&
       fabs(mVelocity) < gfxPrefs::APZOverscrollStopVelocityThreshold()) {
     // "Jump" to the at-rest state. The jump shouldn't be noticeable as the
     // velocity and overscroll are already low.
+    AXIS_LOG("%p|%s oscillation dropped below threshold, going to rest\n",
+      mAsyncPanZoomController, Name());
     mOverscroll = 0;
     mVelocity = 0;
     mInUnderscroll = false;
     return false;
   }
 
   // Otherwise, continue the animation.
   return true;
@@ -280,22 +289,26 @@ void Axis::EndTouch(uint32_t aTimestampM
       count++;
       mVelocity += mVelocityQueue[0].second;
     }
     mVelocityQueue.RemoveElementAt(0);
   }
   if (count > 1) {
     mVelocity /= count;
   }
+  AXIS_LOG("%p|%s ending touch, computed velocity %f\n",
+    mAsyncPanZoomController, Name(), mVelocity);
 }
 
 void Axis::CancelTouch() {
   // mVelocityQueue is controller-thread only
   AsyncPanZoomController::AssertOnControllerThread();
 
+  AXIS_LOG("%p|%s cancelling touch, clearing velocity queue\n",
+    mAsyncPanZoomController, Name());
   mVelocity = 0.0f;
   while (!mVelocityQueue.IsEmpty()) {
     mVelocityQueue.RemoveElementAt(0);
   }
 }
 
 bool Axis::CanScroll() const {
   return GetPageLength() - GetCompositionLength() > COORDINATE_EPSILON;
@@ -312,16 +325,18 @@ bool Axis::FlingApplyFrictionOrCancel(co
     // If the velocity is very low, just set it to 0 and stop the fling,
     // otherwise we'll just asymptotically approach 0 and the user won't
     // actually see any changes.
     mVelocity = 0.0f;
     return false;
   } else {
     mVelocity *= pow(1.0f - aFriction, float(aDelta.ToMilliseconds()));
   }
+  AXIS_LOG("%p|%s reduced velocity to %f due to friction\n",
+    mAsyncPanZoomController, Name(), mVelocity);
   return true;
 }
 
 ParentLayerCoord Axis::DisplacementWillOverscrollAmount(ParentLayerCoord aDisplacement) const {
   ParentLayerCoord newOrigin = GetOrigin() + aDisplacement;
   ParentLayerCoord newCompositionEnd = GetCompositionEnd() + aDisplacement;
   // If the current pan plus a displacement takes the window to the left of or
   // above the current page rect.
@@ -368,16 +383,18 @@ CSSCoord Axis::ScaleWillOverscrollAmount
   return 0;
 }
 
 float Axis::GetVelocity() const {
   return mAxisLocked ? 0 : mVelocity;
 }
 
 void Axis::SetVelocity(float aVelocity) {
+  AXIS_LOG("%p|%s direct-setting velocity to %f\n",
+    mAsyncPanZoomController, Name(), aVelocity);
   mVelocity = aVelocity;
 }
 
 ParentLayerCoord Axis::GetCompositionEnd() const {
   return GetOrigin() + GetCompositionLength();
 }
 
 ParentLayerCoord Axis::GetPageEnd() const {
@@ -436,16 +453,21 @@ ParentLayerCoord AxisX::GetRectOffset(co
   return aRect.x;
 }
 
 ScreenPoint AxisX::MakePoint(ScreenCoord aCoord) const
 {
   return ScreenPoint(aCoord, 0);
 }
 
+const char* AxisX::Name() const
+{
+  return "X";
+}
+
 AxisY::AxisY(AsyncPanZoomController* aAsyncPanZoomController)
   : Axis(aAsyncPanZoomController)
 {
 
 }
 
 ParentLayerCoord AxisY::GetPointOffset(const ParentLayerPoint& aPoint) const
 {
@@ -462,10 +484,15 @@ ParentLayerCoord AxisY::GetRectOffset(co
   return aRect.y;
 }
 
 ScreenPoint AxisY::MakePoint(ScreenCoord aCoord) const
 {
   return ScreenPoint(0, aCoord);
 }
 
+const char* AxisY::Name() const
+{
+  return "Y";
+}
+
 }
 }
--- a/gfx/layers/apz/src/Axis.h
+++ b/gfx/layers/apz/src/Axis.h
@@ -233,16 +233,18 @@ public:
   ParentLayerCoord GetPos() const { return mPos; }
 
   virtual ParentLayerCoord GetPointOffset(const ParentLayerPoint& aPoint) const = 0;
   virtual ParentLayerCoord GetRectLength(const ParentLayerRect& aRect) const = 0;
   virtual ParentLayerCoord GetRectOffset(const ParentLayerRect& aRect) const = 0;
 
   virtual ScreenPoint MakePoint(ScreenCoord aCoord) const = 0;
 
+  virtual const char* Name() const = 0;
+
 protected:
   ParentLayerCoord mPos;
   uint32_t mPosTimeMs;
   ParentLayerCoord mStartPos;
   float mVelocity;      // Units: ParentLayerCoords per millisecond
   bool mAxisLocked;     // Whether movement on this axis is locked.
   AsyncPanZoomController* mAsyncPanZoomController;
   ParentLayerCoord mOverscroll;  // See GetOverscroll().
@@ -265,23 +267,25 @@ protected:
 
 class AxisX : public Axis {
 public:
   explicit AxisX(AsyncPanZoomController* mAsyncPanZoomController);
   virtual ParentLayerCoord GetPointOffset(const ParentLayerPoint& aPoint) const MOZ_OVERRIDE;
   virtual ParentLayerCoord GetRectLength(const ParentLayerRect& aRect) const MOZ_OVERRIDE;
   virtual ParentLayerCoord GetRectOffset(const ParentLayerRect& aRect) const MOZ_OVERRIDE;
   virtual ScreenPoint MakePoint(ScreenCoord aCoord) const MOZ_OVERRIDE;
+  virtual const char* Name() const MOZ_OVERRIDE;
 };
 
 class AxisY : public Axis {
 public:
   explicit AxisY(AsyncPanZoomController* mAsyncPanZoomController);
   virtual ParentLayerCoord GetPointOffset(const ParentLayerPoint& aPoint) const MOZ_OVERRIDE;
   virtual ParentLayerCoord GetRectLength(const ParentLayerRect& aRect) const MOZ_OVERRIDE;
   virtual ParentLayerCoord GetRectOffset(const ParentLayerRect& aRect) const MOZ_OVERRIDE;
   virtual ScreenPoint MakePoint(ScreenCoord aCoord) const MOZ_OVERRIDE;
+  virtual const char* Name() const MOZ_OVERRIDE;
 };
 
 }
 }
 
 #endif
--- a/gfx/layers/apz/src/InputBlockState.cpp
+++ b/gfx/layers/apz/src/InputBlockState.cpp
@@ -32,16 +32,17 @@ InputBlockState::InputBlockState(const n
 bool
 InputBlockState::SetConfirmedTargetApzc(const nsRefPtr<AsyncPanZoomController>& aTargetApzc)
 {
   if (mTargetConfirmed) {
     return false;
   }
   mTargetConfirmed = true;
 
+  TBS_LOG("%p got confirmed target APZC %p\n", this, mTargetApzc.get());
   if (mTargetApzc == aTargetApzc) {
     // The confirmed target is the same as the tentative one, so we're done.
     return true;
   }
 
   // Log enabled by default for now, we will put it in a TBS_LOG eventually
   // once this code is more baked
   printf_stderr("%p replacing unconfirmed target %p with real target %p\n",
--- a/gfx/layers/apz/src/InputQueue.cpp
+++ b/gfx/layers/apz/src/InputQueue.cpp
@@ -55,16 +55,17 @@ InputQueue::ReceiveInputEvent(const nsRe
     if (block == CurrentTouchBlock()) {
       // XXX using the chain from |block| here may be wrong in cases where the
       // target isn't confirmed and the real target turns out to be something
       // else. For now assume this is rare enough that it's not an issue.
       if (block->GetOverscrollHandoffChain()->HasFastMovingApzc()) {
         // If we're already in a fast fling, then we want the touch event to stop the fling
         // and to disallow the touch event from being used as part of a fling.
         block->SetDuringFastMotion();
+        INPQ_LOG("block %p tagged as fast-motion\n", block);
       }
       block->GetOverscrollHandoffChain()->CancelAnimations();
     }
 
     bool waitForMainThread = !aTargetConfirmed;
     if (!gfxPrefs::LayoutEventRegionsEnabled()) {
       waitForMainThread |= aTarget->NeedToWaitForContent();
     }