Bug 1280666 - Expose velocity (speed) from StackScroller and use in APZC r=rbarker a=gchang
authorJames Willcox <snorp@snorp.net>
Wed, 29 Jun 2016 13:42:17 -0700
changeset 340408 ffaec482162fe3f63debf3fcd22c14d57d036f11
parent 340407 976364bdedb9b830d3a8421d5ef09705c5348677
child 340409 cdf6a5d6956615824ae14d5b48218a784a80dbd0
push id6326
push userjwillcox@mozilla.com
push dateMon, 22 Aug 2016 16:38:05 +0000
treeherdermozilla-beta@ffaec482162f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersrbarker, gchang
bugs1280666
milestone49.0
Bug 1280666 - Expose velocity (speed) from StackScroller and use in APZC r=rbarker a=gchang
gfx/layers/apz/src/AndroidAPZ.cpp
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);
   ParentLayerPoint preCheckedOffset(offset);
 
   bool hitBoundX = CheckBounds(mApzc.mX, offset.x, mFlingDirection.x, &(offset.x));
@@ -153,17 +151,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 ((fabsf(offset.x - preCheckedOffset.x) > BOUNDS_EPSILON) || (fabsf(offset.y - preCheckedOffset.y) > BOUNDS_EPSILON)) {
     // The page is no longer scrolling but the fling animation is still animating beyond the page bounds. If it goes
     // beyond the BOUNDS_EPSILON then it has overflowed and will never stop. In that case, stop the fling animation.
     shouldContinueFling = false;
   } else if (hitBoundX && hitBoundY) {
     // We can't scroll any farther along either axis.
--- a/widget/android/GeneratedJNIWrappers.cpp
+++ b/widget/android/GeneratedJNIWrappers.cpp
@@ -1605,17 +1605,17 @@ auto ProgressiveUpdateData::Y() const ->
     return mozilla::jni::Field<Y_t>::Get(ProgressiveUpdateData::mCtx, nullptr);
 }
 
 auto ProgressiveUpdateData::Y(float a0) const -> void
 {
     return mozilla::jni::Field<Y_t>::Set(ProgressiveUpdateData::mCtx, nullptr, a0);
 }
 
-const char StackScroller::name[] =
+template<> const char mozilla::jni::Context<StackScroller, jobject>::name[] =
         "org/mozilla/gecko/gfx/StackScroller";
 
 constexpr char StackScroller::New_t::name[];
 constexpr char StackScroller::New_t::signature[];
 
 auto StackScroller::New(mozilla::jni::Object::Param a0, StackScroller::LocalRef* a1) -> nsresult
 {
     MOZ_ASSERT(a1);
@@ -1660,16 +1660,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);
@@ -1855,17 +1877,17 @@ auto StackScroller::SViscousFluidScale(f
 auto StackScroller::SViscousFluidScale(float a0) -> nsresult
 {
     nsresult rv = NS_OK;
     mozilla::jni::Field<SViscousFluidScale_t>::Set(StackScroller::Context(), &rv, a0);
     return rv;
 }
 
 template<> const char mozilla::jni::Context<ViewTransform, jobject>::name[] =
-    "org/mozilla/gecko/gfx/ViewTransform";
+        "org/mozilla/gecko/gfx/ViewTransform";
 
 constexpr char ViewTransform::New_t::name[];
 constexpr char ViewTransform::New_t::signature[];
 
 auto ViewTransform::New(float a0, float a1, float a2) -> ViewTransform::LocalRef
 {
     return mozilla::jni::Constructor<New_t>::Call(ViewTransform::Context(), nullptr, a0, a1, a2);
 }
--- a/widget/android/GeneratedJNIWrappers.h
+++ b/widget/android/GeneratedJNIWrappers.h
@@ -3860,18 +3860,16 @@ public:
 
     static const bool isMultithreaded = true;
 
 };
 
 class StackScroller : public mozilla::jni::ObjectBase<StackScroller, jobject>
 {
 public:
-    static const char name[];
-
     explicit StackScroller(const Context& ctx) : ObjectBase<StackScroller, jobject>(ctx) {}
 
     struct New_t {
         typedef StackScroller Owner;
         typedef StackScroller::LocalRef ReturnType;
         typedef StackScroller::Param SetterType;
         typedef mozilla::jni::Args<
                 mozilla::jni::Object::Param> Args;
@@ -3953,16 +3951,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";