Bug 1457586 - Refactor APZCTreeManager::ProcessTouchVelocity() and related functions to take the time and position deltas separately. r=kats
authorBotond Ballo <botond@mozilla.com>
Fri, 05 Oct 2018 16:51:12 +0000
changeset 495570 cd68d246a34dd8bec4d26a6d27fbf3a7138facda
parent 495569 664a7c0f81838749901456166cbff2f9a5317db6
child 495571 5d40107ce896cd188a295e5f0a77d8095cc0c96b
push id9984
push userffxbld-merge
push dateMon, 15 Oct 2018 21:07:35 +0000
treeherdermozilla-beta@183d27ea8570 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1457586
milestone64.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 1457586 - Refactor APZCTreeManager::ProcessTouchVelocity() and related functions to take the time and position deltas separately. r=kats The motivation is to support velocity tracking implementations (added in a later patch) that need the position delta rather than resulting velocity. Also rename the functions to make it clearer that they have to do with dynamic toolbar movement. MozReview-Commit-ID: G0IVJHYTurB Depends on D7654 Differential Revision: https://phabricator.services.mozilla.com/D7655
gfx/layers/apz/src/APZCTreeManager.cpp
gfx/layers/apz/src/APZCTreeManager.h
gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/src/AsyncPanZoomController.h
gfx/layers/apz/src/Axis.cpp
gfx/layers/apz/src/Axis.h
--- a/gfx/layers/apz/src/APZCTreeManager.cpp
+++ b/gfx/layers/apz/src/APZCTreeManager.cpp
@@ -2003,20 +2003,25 @@ APZCTreeManager::ProcessUnhandledEvent(L
   }
 
   // Update the focus sequence number and attach it to the event
   mFocusState.ReceiveFocusChangingEvent();
   *aOutFocusSequenceNumber = mFocusState.LastAPZProcessedEvent();
 }
 
 void
-APZCTreeManager::ProcessTouchVelocity(uint32_t aTimestampMs, float aSpeedY)
+APZCTreeManager::ProcessDynamicToolbarMovement(uint32_t aStartTimestampMs,
+                                                    uint32_t aEndTimestampMs,
+                                                    ScreenCoord aDeltaY)
 {
   if (mApzcForInputBlock) {
-    mApzcForInputBlock->HandleTouchVelocity(aTimestampMs, aSpeedY);
+    mApzcForInputBlock->HandleDynamicToolbarMovement(
+        aStartTimestampMs,
+        aEndTimestampMs,
+        ViewAs<ParentLayerPixel>(aDeltaY, PixelCastJustification::ScreenIsParentLayerForRoot));
   }
 }
 
 void
 APZCTreeManager::SetKeyboardMap(const KeyboardMap& aKeyboardMap)
 {
   APZThreadUtils::AssertOnControllerThread();
 
--- a/gfx/layers/apz/src/APZCTreeManager.h
+++ b/gfx/layers/apz/src/APZCTreeManager.h
@@ -583,22 +583,25 @@ public:
                                                          HitTestingTreeNodeAutoLock* aOutScrollbarNode = nullptr);
   already_AddRefed<AsyncPanZoomController> GetTargetAPZC(const LayersId& aLayersId,
                                                          const FrameMetrics::ViewID& aScrollId);
   ScreenToParentLayerMatrix4x4 GetScreenToApzcTransform(const AsyncPanZoomController *aApzc) const;
   ParentLayerToScreenMatrix4x4 GetApzcToGeckoTransform(const AsyncPanZoomController *aApzc) const;
   ScreenPoint GetCurrentMousePosition() const;
 
   /**
-   * Process touch velocity.
-   * Sometimes the touch move event will have a velocity even though no scrolling
-   * is occurring such as when the toolbar is being hidden/shown in Fennec.
-   * This function can be called to have the y axis' velocity queue updated.
+   * Process a movement of the dynamic toolbar by |aDeltaY| over the time
+   * period from |aStartTimestampMs| to |aEndTimestampMs|.
+   * This is used to track velocities accurately in the presence of movement
+   * of the dynamic toolbar, since in such cases the finger can be moving
+   * relative to the screen even though no scrolling is occurring.
    */
-  void ProcessTouchVelocity(uint32_t aTimestampMs, float aSpeedY);
+  void ProcessDynamicToolbarMovement(uint32_t aStartTimestampMs,
+                                     uint32_t aEndTimestampMs,
+                                     ScreenCoord aDeltaY);
 private:
   typedef bool (*GuidComparator)(const ScrollableLayerGuid&, const ScrollableLayerGuid&);
 
   /* Helpers */
   template<class ScrollNode>
   void UpdateHitTestingTreeImpl(LayersId aRootLayerTreeId,
                                 const ScrollNode& aRoot,
                                 bool aIsFirstPaint,
--- a/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp
+++ b/gfx/layers/apz/src/AndroidDynamicToolbarAnimator.cpp
@@ -637,21 +637,22 @@ AndroidDynamicToolbarAnimator::ProcessTo
     RequestComposite();
     // If there was no delta left over, the event was completely consumed.
     if (deltaRemainder == 0) {
       status = nsEventStatus_eConsumeNoDefault;
     }
 
     uint32_t timeDelta = aTimeStamp - mControllerLastEventTimeStamp;
     if (mControllerLastEventTimeStamp && timeDelta && aDelta) {
-      float speed = -(float)aDelta / (float)timeDelta;
       // we can't use mApz because we're on the controller thread, so we have
       // the caller provide a RefPtr to the same underlying object, which should
       // be safe to use.
-      aApz->ProcessTouchVelocity(aTimeStamp, speed);
+      aApz->ProcessDynamicToolbarMovement(mControllerLastEventTimeStamp,
+                                          aTimeStamp,
+                                          -(float)aDelta);
     }
   }
 
   return status;
 }
 
 void
 AndroidDynamicToolbarAnimator::HandleTouchEnd(StaticToolbarState aCurrentToolbarState, ScreenIntCoord aCurrentTouch)
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -1209,19 +1209,23 @@ nsEventStatus AsyncPanZoomController::Ha
     break;
   }
   default: MOZ_ASSERT_UNREACHABLE("Unhandled input event"); break;
   }
 
   return rv;
 }
 
-void AsyncPanZoomController::HandleTouchVelocity(uint32_t aTimesampMs, float aSpeedY)
+void AsyncPanZoomController::HandleDynamicToolbarMovement(uint32_t aStartTimestampMs,
+                                                          uint32_t aEndTimestampMs,
+                                                          ParentLayerCoord aDeltaY)
 {
-  mY.HandleTouchVelocity(aTimesampMs, aSpeedY);
+  mY.HandleDynamicToolbarMovement(aStartTimestampMs,
+                                  aEndTimestampMs,
+                                  aDeltaY);
 }
 
 void AsyncPanZoomController::StartAutoscroll(const ScreenPoint& aPoint)
 {
   // Cancel any existing animation.
   CancelAnimation();
 
   SetState(AUTOSCROLL);
--- a/gfx/layers/apz/src/AsyncPanZoomController.h
+++ b/gfx/layers/apz/src/AsyncPanZoomController.h
@@ -351,22 +351,25 @@ public:
    * Currently some gestures are detected in GestureEventListener that calls
    * APZC back through this handler in order to avoid recursive calls to
    * APZC::HandleInputEvent() which is supposed to do the work for
    * ReceiveInputEvent().
    */
   nsEventStatus HandleGestureEvent(const InputData& aEvent);
 
   /**
-   * Handler for touch velocity.
-   * Sometimes the touch move event will have a velocity even though no scrolling
-   * is occurring such as when the toolbar is being hidden/shown in Fennec.
-   * This function can be called to have the y axis' velocity queue updated.
+   * Handle movement of the dynamic toolbar by |aDeltaY| over the time
+   * period from |aStartTimestampMs| to |aEndTimestampMs|.
+   * This is used to track velocities accurately in the presence of movement
+   * of the dynamic toolbar, since in such cases the finger can be moving
+   * relative to the screen even though no scrolling is occurring.
    */
-  void HandleTouchVelocity(uint32_t aTimesampMs, float aSpeedY);
+  void HandleDynamicToolbarMovement(uint32_t aStartTimestampMs,
+                                    uint32_t aEndTimestampMs,
+                                    ParentLayerCoord aDeltaY);
 
   /**
    * Start autoscrolling this APZC, anchored at the provided location.
    */
   void StartAutoscroll(const ScreenPoint& aAnchorLocation);
 
   /**
    * Stop autoscrolling this APZC.
--- a/gfx/layers/apz/src/Axis.cpp
+++ b/gfx/layers/apz/src/Axis.cpp
@@ -137,24 +137,30 @@ float Axis::ApplyFlingCurveToVelocity(fl
 
 void Axis::AddVelocityToQueue(uint32_t aTimestampMs, float aVelocity) {
   mVelocityQueue.AppendElement(std::make_pair(aTimestampMs, aVelocity));
   if (mVelocityQueue.Length() > gfxPrefs::APZMaxVelocityQueueSize()) {
     mVelocityQueue.RemoveElementAt(0);
   }
 }
 
-void Axis::HandleTouchVelocity(uint32_t aTimestampMs, float aSpeed) {
+void Axis::HandleDynamicToolbarMovement(uint32_t aStartTimestampMs,
+                                        uint32_t aEndTimestampMs,
+                                        ParentLayerCoord aDelta)
+{
   // mVelocityQueue is controller-thread only
   APZThreadUtils::AssertOnControllerThread();
 
-  mVelocity = ApplyFlingCurveToVelocity(aSpeed);
-  mVelocitySampleTimeMs = aTimestampMs;
+  float timeDelta = aEndTimestampMs - aStartTimestampMs;
+  MOZ_ASSERT(timeDelta != 0);
+  float speed = aDelta / timeDelta;
+  mVelocity = ApplyFlingCurveToVelocity(speed);
+  mVelocitySampleTimeMs = aEndTimestampMs;
 
-  AddVelocityToQueue(aTimestampMs, mVelocity);
+  AddVelocityToQueue(aEndTimestampMs, mVelocity);
 }
 
 void Axis::StartTouch(ParentLayerCoord aPos, uint32_t aTimestampMs) {
   mStartPos = aPos;
   mPos = aPos;
   mVelocitySampleTimeMs = aTimestampMs;
   mVelocitySamplePos = aPos;
   mAxisLocked = false;
--- a/gfx/layers/apz/src/Axis.h
+++ b/gfx/layers/apz/src/Axis.h
@@ -52,17 +52,19 @@ public:
    */
   void UpdateWithTouchAtDevicePoint(ParentLayerCoord aPos, uint32_t aTimestampMs);
 
 protected:
   float ApplyFlingCurveToVelocity(float aVelocity) const;
   void AddVelocityToQueue(uint32_t aTimestampMs, float aVelocity);
 
 public:
-  void HandleTouchVelocity(uint32_t aTimestampMs, float aSpeed);
+  void HandleDynamicToolbarMovement(uint32_t aStartTimestampMs,
+                                    uint32_t aEndTimestampMs,
+                                    ParentLayerCoord aDelta);
 
   /**
    * Notify this Axis that a touch has begun, i.e. the user has put their finger
    * on the screen but has not yet tried to pan.
    */
   void StartTouch(ParentLayerCoord aPos, uint32_t aTimestampMs);
 
   /**