Bug 1280656 - Use Android ViewConfiguration to get max fling velocity. r=kats a=sylvestre
authorRandall Barker <rbarker@mozilla.com>
Fri, 17 Jun 2016 15:27:24 +0100
changeset 339764 6c31d36da0d4a2aa5f7726302a8b40b0200e3b07
parent 339763 ddf1c2c6a9e31c96b3a83862bb4972d5d009e823
child 339765 766442658e59aadab137c413e9f53c7808538638
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats, sylvestre
bugs1280656
milestone49.0a2
Bug 1280656 - Use Android ViewConfiguration to get max fling velocity. r=kats a=sylvestre
gfx/layers/apz/src/AndroidAPZ.cpp
widget/android/bindings/ViewConfiguration-classes.txt
widget/android/bindings/moz.build
--- a/gfx/layers/apz/src/AndroidAPZ.cpp
+++ b/gfx/layers/apz/src/AndroidAPZ.cpp
@@ -6,24 +6,38 @@
 
 #include "AndroidAPZ.h"
 
 #include "AsyncPanZoomController.h"
 #include "GeneratedJNIWrappers.h"
 #include "gfxPrefs.h"
 #include "OverscrollHandoffState.h"
 #include "OverScroller.h"
+#include "ViewConfiguration.h"
 
 #define ANDROID_APZ_LOG(...)
 // #define ANDROID_APZ_LOG(...) printf_stderr("ANDROID_APZ: " __VA_ARGS__)
 
+static float sMaxFlingSpeed = 0.0f;
+
 namespace mozilla {
 namespace layers {
 
 AndroidSpecificState::AndroidSpecificState() {
+  widget::sdk::ViewConfiguration::LocalRef config;
+  if (widget::sdk::ViewConfiguration::Get(widget::GeckoAppShell::GetApplicationContext(), &config) == NS_OK) {
+    int32_t speed = 0;
+    if (config->GetScaledMaximumFlingVelocity(&speed) == NS_OK) {
+      sMaxFlingSpeed = (float)speed * 0.001f;
+    } else {
+      ANDROID_APZ_LOG("%p Failed to query ViewConfiguration for scaled maximum fling velocity\n", this);
+    }
+  } else {
+    ANDROID_APZ_LOG("%p Failed to get ViewConfiguration\n", this);
+  }
   widget::sdk::OverScroller::LocalRef scroller;
   if (widget::sdk::OverScroller::New(widget::GeckoAppShell::GetApplicationContext(), &scroller) != NS_OK) {
     ANDROID_APZ_LOG("%p Failed to create Android OverScroller\n", this);
     return;
   }
   mOverScroller = scroller;
 }
 
@@ -76,29 +90,34 @@ AndroidFlingAnimation::AndroidFlingAnima
     mApzc.mX.SetVelocity(0);
   }
   if (!mOverscrollHandoffChain->CanScrollInDirection(&mApzc, Layer::VERTICAL)) {
     ReentrantMonitorAutoEnter lock(mApzc.mMonitor);
     mApzc.mY.SetVelocity(0);
   }
 
   ParentLayerPoint velocity = mApzc.GetVelocityVector();
-  mPreviousVelocity = velocity;
 
   float scrollRangeStartX = mApzc.mX.GetPageStart().value;
   float scrollRangeEndX = mApzc.mX.GetScrollRangeEnd().value;
   float scrollRangeStartY = mApzc.mY.GetPageStart().value;
   float scrollRangeEndY = mApzc.mY.GetScrollRangeEnd().value;
   mStartOffset.x = mPreviousOffset.x = mApzc.mX.GetOrigin().value;
   mStartOffset.y = mPreviousOffset.y = mApzc.mY.GetOrigin().value;
   float length = velocity.Length();
   if (length > 0.0f) {
     mFlingDirection = velocity / length;
+
+    if ((sMaxFlingSpeed > 0.0f) && (length > sMaxFlingSpeed)) {
+       velocity = mFlingDirection * sMaxFlingSpeed;
+    }
   }
 
+  mPreviousVelocity = velocity;
+
   int32_t originX = ClampStart(mStartOffset.x, scrollRangeStartX, scrollRangeEndX);
   int32_t originY = ClampStart(mStartOffset.y, scrollRangeStartY, scrollRangeEndY);
   mOverScroller->Fling(originX, originY,
                        // Android needs the velocity in pixels per second and it is in pixels per ms.
                        (int32_t)(velocity.x * 1000.0f), (int32_t)(velocity.y * 1000.0f),
                        (int32_t)floor(scrollRangeStartX), (int32_t)ceil(scrollRangeEndX),
                        (int32_t)floor(scrollRangeStartY), (int32_t)ceil(scrollRangeEndY),
                        0, 0);
new file mode 100644
--- /dev/null
+++ b/widget/android/bindings/ViewConfiguration-classes.txt
@@ -0,0 +1,1 @@
+android.view.ViewConfiguration
--- a/widget/android/bindings/moz.build
+++ b/widget/android/bindings/moz.build
@@ -8,17 +8,18 @@
 # this list and ensure that $(stem)-classes.txt exists in this directory.
 generated = [
     'AndroidRect',
     'Bundle',
     'KeyEvent',
     'MediaCodec',
     'MotionEvent',
     'OverScroller',
-    'SurfaceTexture'
+    'SurfaceTexture',
+    'ViewConfiguration'
 ]
 
 SOURCES += ['!%s.cpp' % stem for stem in generated]
 
 EXPORTS += ['!%s.h' % stem for stem in generated]
 
 # We'd like to add these to a future GENERATED_EXPORTS list, but for now we mark
 # them as generated here and manually install them in Makefile.in.