Bug 1280666 - Expose velocity (speed) from StackScroller and use in APZC r=rbarker
authorJames Willcox <snorp@snorp.net>
Wed, 29 Jun 2016 13:42:17 -0700
changeset 303153 a8e0bbf386df5bc77c365c61acb957f5f389ee51
parent 303152 ab9fc4342f54bd6f4be03f7788151fda931266a3
child 303154 335dc3e1cb1fe6a09fd759062a6556a55aae43a3
push id78996
push userrbarker@mozilla.com
push dateThu, 30 Jun 2016 00:10:05 +0000
treeherdermozilla-inbound@a8e0bbf386df [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarker
bugs1280666
milestone50.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 1280666 - Expose velocity (speed) from StackScroller and use in APZC r=rbarker
gfx/layers/apz/src/AndroidAPZ.cpp
mobile/android/base/java/org/mozilla/gecko/gfx/StackScroller.java
widget/android/GeneratedJNIWrappers.cpp
widget/android/GeneratedJNIWrappers.h
--- a/gfx/layers/apz/src/AndroidAPZ.cpp
+++ b/gfx/layers/apz/src/AndroidAPZ.cpp
@@ -132,19 +132,17 @@ AndroidFlingAnimation::AndroidFlingAnima
 bool
 AndroidFlingAnimation::DoSample(FrameMetrics& aFrameMetrics,
                                 const TimeDuration& aDelta)
 {
   bool shouldContinueFling = true;
 
   mFlingDuration += aDelta.ToMilliseconds();
   mOverScroller->ComputeScrollOffset(mFlingDuration, &shouldContinueFling);
-  // OverScroller::GetCurrVelocity will sometimes return NaN. So need to externally
-  // calculate current velocity and not rely on what the OverScroller calculates.
-  // mOverScroller->GetCurrVelocity(&speed);
+
   int32_t currentX = 0;
   int32_t currentY = 0;
   mOverScroller->GetCurrX(&currentX);
   mOverScroller->GetCurrY(&currentY);
   ParentLayerPoint offset((float)currentX, (float)currentY);
 
   bool hitBoundX = CheckBounds(mApzc.mX, offset.x, mFlingDirection.x, &(offset.x));
   bool hitBoundY = CheckBounds(mApzc.mY, offset.y, mFlingDirection.y, &(offset.y));
@@ -152,17 +150,22 @@ AndroidFlingAnimation::DoSample(FrameMet
   ParentLayerPoint velocity = mPreviousVelocity;
 
   // Sometimes the OverScroller fails to update the offset for a frame.
   // If the frame can still scroll we just use the velocity from the previous
   // frame. However, if the frame can no longer scroll in the direction
   // of the fling, then end the animation.
   if (offset != mPreviousOffset) {
     if (aDelta.ToMilliseconds() > 0) {
-      velocity = (offset - mPreviousOffset) / (float)aDelta.ToMilliseconds();
+      mOverScroller->GetCurrSpeedX(&velocity.x);
+      mOverScroller->GetCurrSpeedY(&velocity.y);
+
+      velocity.x /= 1000;
+      velocity.y /= 1000;
+
       mPreviousVelocity = velocity;
     }
   } else if (hitBoundX || hitBoundY) {
     // We have reached the end of the scroll in one of the directions being scrolled and the offset has not
     // changed so end animation.
     shouldContinueFling = false;
   }
 
--- a/mobile/android/base/java/org/mozilla/gecko/gfx/StackScroller.java
+++ b/mobile/android/base/java/org/mozilla/gecko/gfx/StackScroller.java
@@ -93,16 +93,24 @@ public class StackScroller {
      * Returns where the scroll will end. Valid only for "fling" scrolls.
      *
      * @return The final X offset as an absolute distance from the origin.
      */
     public final int getFinalX() {
         return mScrollerX.mFinal;
     }
 
+    public final float getCurrSpeedX() {
+        return mScrollerX.mCurrVelocity;
+    }
+
+    public final float getCurrSpeedY() {
+        return mScrollerY.mCurrVelocity;
+    }
+
     /**
      * Returns where the scroll will end. Valid only for "fling" scrolls.
      *
      * @return The final Y offset as an absolute distance from the origin.
      */
     public final int getFinalY() {
         return mScrollerY.mFinal;
     }
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -1668,16 +1668,38 @@ constexpr char StackScroller::ForceFinis
 
 auto StackScroller::ForceFinished(bool a0) const -> nsresult
 {
     nsresult rv = NS_OK;
     mozilla::jni::Method<ForceFinished_t>::Call(StackScroller::mCtx, &rv, a0);
     return rv;
 }
 
+constexpr char StackScroller::GetCurrSpeedX_t::name[];
+constexpr char StackScroller::GetCurrSpeedX_t::signature[];
+
+auto StackScroller::GetCurrSpeedX(float* a0) const -> nsresult
+{
+    MOZ_ASSERT(a0);
+    nsresult rv = NS_OK;
+    *a0 = mozilla::jni::Method<GetCurrSpeedX_t>::Call(StackScroller::mCtx, &rv);
+    return rv;
+}
+
+constexpr char StackScroller::GetCurrSpeedY_t::name[];
+constexpr char StackScroller::GetCurrSpeedY_t::signature[];
+
+auto StackScroller::GetCurrSpeedY(float* a0) const -> nsresult
+{
+    MOZ_ASSERT(a0);
+    nsresult rv = NS_OK;
+    *a0 = mozilla::jni::Method<GetCurrSpeedY_t>::Call(StackScroller::mCtx, &rv);
+    return rv;
+}
+
 constexpr char StackScroller::GetCurrX_t::name[];
 constexpr char StackScroller::GetCurrX_t::signature[];
 
 auto StackScroller::GetCurrX(int32_t* a0) const -> nsresult
 {
     MOZ_ASSERT(a0);
     nsresult rv = NS_OK;
     *a0 = mozilla::jni::Method<GetCurrX_t>::Call(StackScroller::mCtx, &rv);
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -4025,16 +4025,46 @@ public:
                 "(Z)V";
         static const bool isStatic = false;
         static const mozilla::jni::ExceptionMode exceptionMode =
                 mozilla::jni::ExceptionMode::NSRESULT;
     };
 
     auto ForceFinished(bool) const -> nsresult;
 
+    struct GetCurrSpeedX_t {
+        typedef StackScroller Owner;
+        typedef float ReturnType;
+        typedef float SetterType;
+        typedef mozilla::jni::Args<> Args;
+        static constexpr char name[] = "getCurrSpeedX";
+        static constexpr char signature[] =
+                "()F";
+        static const bool isStatic = false;
+        static const mozilla::jni::ExceptionMode exceptionMode =
+                mozilla::jni::ExceptionMode::NSRESULT;
+    };
+
+    auto GetCurrSpeedX(float*) const -> nsresult;
+
+    struct GetCurrSpeedY_t {
+        typedef StackScroller Owner;
+        typedef float ReturnType;
+        typedef float SetterType;
+        typedef mozilla::jni::Args<> Args;
+        static constexpr char name[] = "getCurrSpeedY";
+        static constexpr char signature[] =
+                "()F";
+        static const bool isStatic = false;
+        static const mozilla::jni::ExceptionMode exceptionMode =
+                mozilla::jni::ExceptionMode::NSRESULT;
+    };
+
+    auto GetCurrSpeedY(float*) const -> nsresult;
+
     struct GetCurrX_t {
         typedef StackScroller Owner;
         typedef int32_t ReturnType;
         typedef int32_t SetterType;
         typedef mozilla::jni::Args<> Args;
         static constexpr char name[] = "getCurrX";
         static constexpr char signature[] =
                 "()I";