Adjusted interpolation and stretch intensity

Updated stretch intensity to 0.016 and added a new uniform to control
the intensity of the interpoloation

Bug: 183768138
Test: ran EdgeEffectTest and visual
Change-Id: Iac10bee5980802fffe838ed83e02b7c41dee6f71
diff --git a/core/java/android/widget/EdgeEffect.java b/core/java/android/widget/EdgeEffect.java
index 50fca04..cd91d02 100644
--- a/core/java/android/widget/EdgeEffect.java
+++ b/core/java/android/widget/EdgeEffect.java
@@ -130,9 +130,9 @@
     public @interface EdgeEffectType {
     }
 
-    private static final float LINEAR_STRETCH_INTENSITY = 0.06f;
+    private static final float LINEAR_STRETCH_INTENSITY = 0.016f;
 
-    private static final float EXP_STRETCH_INTENSITY = 0.06f;
+    private static final float EXP_STRETCH_INTENSITY = 0.016f;
 
     private static final float SCROLL_DIST_AFFECTED_BY_EXP_STRETCH = 0.33f;
 
diff --git a/libs/hwui/effects/StretchEffect.cpp b/libs/hwui/effects/StretchEffect.cpp
index de14beb..c2642d3 100644
--- a/libs/hwui/effects/StretchEffect.cpp
+++ b/libs/hwui/effects/StretchEffect.cpp
@@ -60,6 +60,14 @@
     uniform float viewportWidth; // target height in pixels
     uniform float viewportHeight; // target width in pixels
 
+    // uInterpolationStrength is the intensity of the interpolation.
+    // if uInterpolationStrength is 0, then the stretch is constant for all the
+    // uStretchAffectedDist. if uInterpolationStrength is 1, then stretch intensity
+    // is interpolated based on the pixel position in the uStretchAffectedDist area;
+    // The closer we are from the scroll anchor point, the more it stretches,
+    // and the other way around.
+    uniform float uInterpolationStrength;
+
     float easeInCubic(float t, float d) {
         float tmp = t * d;
         return tmp * tmp * tmp;
@@ -70,10 +78,12 @@
         float overscroll,
         float uStretchAffectedDist,
         float uInverseStretchAffectedDist,
-        float distanceStretched
+        float distanceStretched,
+        float interpolationStrength
     ) {
         float offsetPos = uStretchAffectedDist - inPos;
-        float posBasedVariation = easeInCubic(offsetPos, uInverseStretchAffectedDist);
+        float posBasedVariation = mix(
+                1. ,easeInCubic(offsetPos, uInverseStretchAffectedDist), interpolationStrength);
         float stretchIntensity = overscroll * posBasedVariation;
         return distanceStretched - (offsetPos / (1. + stretchIntensity));
     }
@@ -84,10 +94,12 @@
         float reverseStretchDist,
         float uStretchAffectedDist,
         float uInverseStretchAffectedDist,
-        float distanceStretched
+        float distanceStretched,
+        float interpolationStrength
     ) {
         float offsetPos = inPos - reverseStretchDist;
-        float posBasedVariation = easeInCubic(offsetPos, uInverseStretchAffectedDist);
+        float posBasedVariation = mix(
+                1. ,easeInCubic(offsetPos, uInverseStretchAffectedDist), interpolationStrength);
         float stretchIntensity = (-overscroll) * posBasedVariation;
         return 1 - (distanceStretched - (offsetPos / (1. + stretchIntensity)));
     }
@@ -101,7 +113,8 @@
         float uStretchAffectedDist,
         float uInverseStretchAffectedDist,
         float distanceStretched,
-        float distanceDiff
+        float distanceDiff,
+        float interpolationStrength
     ) {
       float outPos = inPos;
       if (overscroll > 0) {
@@ -111,7 +124,8 @@
                   overscroll,
                   uStretchAffectedDist,
                   uInverseStretchAffectedDist,
-                  distanceStretched
+                  distanceStretched,
+                  interpolationStrength
                 );
             } else if (inPos >= distanceStretched) {
                 outPos = distanceDiff + inPos;
@@ -126,7 +140,8 @@
                   stretchAffectedDist,
                   uStretchAffectedDist,
                   uInverseStretchAffectedDist,
-                  distanceStretched
+                  distanceStretched,
+                  interpolationStrength
                 );
             } else if (inPos < stretchAffectedDist) {
                 outPos = -distanceDiff + inPos;
@@ -153,7 +168,8 @@
             uStretchAffectedDistX,
             uInverseDistanceStretchedX,
             uDistanceStretchedX,
-            uDistDiffX
+            uDistDiffX,
+            uInterpolationStrength
         );
         outV = computeOverscroll(
             inV,
@@ -161,7 +177,8 @@
             uStretchAffectedDistY,
             uInverseDistanceStretchedY,
             uDistanceStretchedY,
-            uDistDiffY
+            uDistDiffY,
+            uInterpolationStrength
         );
         coord.x = outU * viewportWidth;
         coord.y = outV * viewportHeight;
@@ -170,6 +187,7 @@
 
 static const float ZERO = 0.f;
 static const float CONTENT_DISTANCE_STRETCHED = 1.f;
+static const float INTERPOLATION_STRENGTH_VALUE = 0.7f;
 
 sk_sp<SkShader> StretchEffect::getShader(const sk_sp<SkImage>& snapshotImage) const {
     if (isEmpty()) {
@@ -197,6 +215,7 @@
 
     mBuilder->child("uContentTexture") = snapshotImage->makeShader(
             SkTileMode::kClamp, SkTileMode::kClamp, SkSamplingOptions(SkFilterMode::kLinear));
+    mBuilder->uniform("uInterpolationStrength").set(&INTERPOLATION_STRENGTH_VALUE, 1);
     mBuilder->uniform("uStretchAffectedDistX").set(&CONTENT_DISTANCE_STRETCHED, 1);
     mBuilder->uniform("uStretchAffectedDistY").set(&CONTENT_DISTANCE_STRETCHED, 1);
     mBuilder->uniform("uDistanceStretchedX").set(&distanceStretchedX, 1);