Bug 1235994 - Extract a helper function to request a snap to the predicted destination. r?botond draft
authorKartikaya Gupta <kgupta@mozilla.com>
Thu, 31 Dec 2015 15:59:03 -0500
changeset 318198 18b17734f5d21b30afac4473835889e81a7c6879
parent 318143 22f51211915bf7daff076180847a7140d35aa353
child 318199 2d05dab6d29b5ce9763a2146e14c3779df180742
push id8853
push userkgupta@mozilla.com
push dateThu, 31 Dec 2015 20:59:46 +0000
reviewersbotond
bugs1235994
milestone46.0a1
Bug 1235994 - Extract a helper function to request a snap to the predicted destination. r?botond
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/src/AsyncPanZoomController.h
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -2424,16 +2424,24 @@ void AsyncPanZoomController::AcceptFling
     mY.SetVelocity(mY.GetVelocity() + aHandoffState.mVelocity.y);
     aHandoffState.mVelocity.y = 0;
   }
   SetState(FLING);
   FlingAnimation *fling = new FlingAnimation(*this,
       aHandoffState.mChain,
       !aHandoffState.mIsHandoff,  // only apply acceleration if this is an initial fling
       aHandoffState.mScrolledApzc);
+  RequestSnapToDestination();
+  StartAnimation(fling);
+}
+
+void
+AsyncPanZoomController::RequestSnapToDestination()
+{
+  ReentrantMonitorAutoEnter lock(mMonitor);
 
   float friction = gfxPrefs::APZFlingFriction();
   ParentLayerPoint velocity(mX.GetVelocity(), mY.GetVelocity());
   ParentLayerPoint predictedDelta;
   // "-velocity / log(1.0 - friction)" is the integral of the deceleration
   // curve modeled for flings in the "Axis" class.
   if (velocity.x != 0.0f) {
     predictedDelta.x = -velocity.x / log(1.0 - friction);
@@ -2457,18 +2465,16 @@ void AsyncPanZoomController::AcceptFling
                this, friction, velocity.x, velocity.y, (float)predictedDelta.x,
                (float)predictedDelta.y, (float)mFrameMetrics.GetScrollOffset().x,
                (float)mFrameMetrics.GetScrollOffset().y,
                (float)predictedDestination.x, (float)predictedDestination.y);
       controller->RequestFlingSnap(mFrameMetrics.GetScrollId(),
                                    predictedDestination);
     }
   }
-
-  StartAnimation(fling);
 }
 
 bool AsyncPanZoomController::AttemptFling(FlingHandoffState& aHandoffState) {
   // If we are pannable, take over the fling ourselves.
   if (IsPannable()) {
     AcceptFling(aHandoffState);
     return true;
   }
--- a/gfx/layers/apz/src/AsyncPanZoomController.h
+++ b/gfx/layers/apz/src/AsyncPanZoomController.h
@@ -635,16 +635,19 @@ protected:
 
   // Common processing at the end of a touch block.
   void OnTouchEndOrCancel();
 
   // This is called to request that the main thread snap the scroll position
   // to a nearby snap position if appropriate. The current scroll position is
   // used as the final destination.
   void RequestSnap();
+  // Same as above, but takes into account the current velocity to find a
+  // predicted destination.
+  void RequestSnapToDestination();
 
   uint64_t mLayersId;
   RefPtr<CompositorParent> mCompositorParent;
 
   /* Access to the following two fields is protected by the mRefPtrMonitor,
      since they are accessed on the UI thread but can be cleared on the
      compositor thread. */
   RefPtr<GeckoContentController> mGeckoContentController;