Bug 1457586 - Allow PlatformSpecificState to choose the VelocityTracker implementation. r=kats draft
authorBotond Ballo <botond@mozilla.com>
Fri, 03 Aug 2018 17:28:27 -0400
changeset 827068 216128959f08af228b96b2a76edb4d2203c5bb75
parent 827067 8d21aa3841f9f8ddf4f4f309022a81971476ec35
child 827069 7f451e77b95996dfa24db114bf0bc78f5e59bf8b
child 827677 0e699715f02b16c075c73983a70f562d1a36be7f
push id118454
push userbballo@mozilla.com
push dateMon, 06 Aug 2018 22:41:31 +0000
reviewerskats
bugs1457586
milestone63.0a1
Bug 1457586 - Allow PlatformSpecificState to choose the VelocityTracker implementation. r=kats MozReview-Commit-ID: LyW9N2H7fv7
gfx/layers/apz/src/AsyncPanZoomController.cpp
gfx/layers/apz/src/AsyncPanZoomController.h
gfx/layers/apz/src/Axis.cpp
--- a/gfx/layers/apz/src/AsyncPanZoomController.cpp
+++ b/gfx/layers/apz/src/AsyncPanZoomController.cpp
@@ -23,16 +23,17 @@
 #include "GenericFlingAnimation.h"      // for GenericFlingAnimation
 #include "GestureEventListener.h"       // for GestureEventListener
 #include "HitTestingTreeNode.h"         // for HitTestingTreeNode
 #include "InputData.h"                  // for MultiTouchInput, etc
 #include "InputBlockState.h"            // for InputBlockState, TouchBlockState
 #include "InputQueue.h"                 // for InputQueue
 #include "Overscroll.h"                 // for OverscrollAnimation
 #include "OverscrollHandoffState.h"     // for OverscrollHandoffState
+#include "SimpleVelocityTracker.h"      // for SimpleVelocityTracker
 #include "Units.h"                      // for CSSRect, CSSPoint, etc
 #include "UnitTransforms.h"             // for TransformTo
 #include "base/message_loop.h"          // for MessageLoop
 #include "base/task.h"                  // for NewRunnableMethod, etc
 #include "gfxPrefs.h"                   // for gfxPrefs
 #include "gfxTypes.h"                   // for gfxFloat
 #include "LayersLogging.h"              // for print_stderr
 #include "mozilla/Assertions.h"         // for MOZ_ASSERT, etc
@@ -544,16 +545,22 @@ PlatformSpecificStateBase::CreateFlingAn
 {
   return new GenericFlingAnimation<DesktopFlingPhysics>(aApzc,
       aHandoffState.mChain,
       aHandoffState.mIsHandoff,
       aHandoffState.mScrolledApzc,
       aPLPPI);
 }
 
+UniquePtr<VelocityTracker>
+PlatformSpecificStateBase::CreateVelocityTracker(Axis* aAxis)
+{
+  return MakeUnique<SimpleVelocityTracker>(aAxis);
+}
+
 TimeStamp
 AsyncPanZoomController::GetFrameTime() const
 {
   APZCTreeManager* treeManagerLocal = GetApzcTreeManager();
   return treeManagerLocal ? treeManagerLocal->GetFrameTime() : TimeStamp::Now();
 }
 
 class MOZ_STACK_CLASS StateChangeNotificationBlocker {
--- a/gfx/layers/apz/src/AsyncPanZoomController.h
+++ b/gfx/layers/apz/src/AsyncPanZoomController.h
@@ -70,16 +70,17 @@ struct KeyboardScrollAction;
 class PlatformSpecificStateBase {
 public:
   virtual ~PlatformSpecificStateBase() = default;
   virtual AndroidSpecificState* AsAndroidSpecificState() { return nullptr; }
   // PLPPI = "ParentLayer pixels per (Screen) inch"
   virtual AsyncPanZoomAnimation* CreateFlingAnimation(AsyncPanZoomController& aApzc,
                                                       const FlingHandoffState& aHandoffState,
                                                       float aPLPPI);
+  virtual UniquePtr<VelocityTracker> CreateVelocityTracker(Axis* aAxis);
 
   static void InitializeGlobalState() {}
 };
 
 /*
  * Represents a transform from the ParentLayer coordinate space of an APZC
  * to the ParentLayer coordinate space of its parent APZC.
  * Each layer along the way contributes to the transform. We track
--- a/gfx/layers/apz/src/Axis.cpp
+++ b/gfx/layers/apz/src/Axis.cpp
@@ -39,17 +39,17 @@ bool FuzzyEqualsCoordinate(float aValue1
 
 Axis::Axis(AsyncPanZoomController* aAsyncPanZoomController)
   : mPos(0),
     mVelocity(0.0f),
     mAxisLocked(false),
     mAsyncPanZoomController(aAsyncPanZoomController),
     mOverscroll(0),
     mMSDModel(0.0, 0.0, 0.0, 400.0, 1.2),
-    mVelocityTracker(MakeUnique<SimpleVelocityTracker>(this))
+    mVelocityTracker(mAsyncPanZoomController->GetPlatformSpecificState()->CreateVelocityTracker(this))
 {
 }
 
 float Axis::ToLocalVelocity(float aVelocityInchesPerMs) const {
   ScreenPoint velocity = MakePoint(aVelocityInchesPerMs * mAsyncPanZoomController->GetDPI());
   // Use ToScreenCoordinates() to convert a point rather than a vector by
   // treating the point as a vector, and using (0, 0) as the anchor.
   ScreenPoint panStart = mAsyncPanZoomController->ToScreenCoordinates(