Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4beb695a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Updated EdgeEffect parameters for overscroll stretch" into sc-dev

parents 7c614b2e a225d21f
Loading
Loading
Loading
Loading
+20 −30
Original line number Diff line number Diff line
@@ -130,7 +130,11 @@ public class EdgeEffect {
    public @interface EdgeEffectType {
    }

    private static final float DEFAULT_MAX_STRETCH_INTENSITY = 0.08f;
    private static final float LINEAR_STRETCH_INTENSITY = 0.03f;

    private static final float EXP_STRETCH_INTENSITY = 0.02f;

    private static final float SCROLL_DIST_AFFECTED_BY_EXP_STRETCH = 0.4f;

    @SuppressWarnings("UnusedDeclaration")
    private static final String TAG = "EdgeEffect";
@@ -176,9 +180,6 @@ public class EdgeEffect {

    private long mStartTime;
    private float mDuration;
    private float mStretchIntensity = DEFAULT_MAX_STRETCH_INTENSITY;
    private float mStretchDistanceFraction = 1f;
    private float mStretchDistance = -1f;

    private final Interpolator mInterpolator = new DecelerateInterpolator();

@@ -268,16 +269,6 @@ public class EdgeEffect {
        mHeight = height;
    }

    /**
     * Configure the distance in pixels to stretch the content. This is only consumed as part
     * if {@link #setType(int)} is set to {@link #TYPE_STRETCH}
     * @param stretchDistance Stretch distance in pixels when the target View is overscrolled
     * @hide
     */
    public void setStretchDistance(float stretchDistance) {
        mStretchDistance = stretchDistance;
    }

    /**
     * Reports if this EdgeEffect's animation is finished. If this method returns false
     * after a call to {@link #draw(Canvas)} the host widget should schedule another
@@ -519,13 +510,6 @@ public class EdgeEffect {
        mEdgeEffectType = type;
    }

    /**
     * @hide
     */
    public void setMaxStretchIntensity(float stretchIntensity) {
        mStretchIntensity = stretchIntensity;
    }

    /**
     * Set or clear the blend mode. A blend mode defines how source pixels
     * (generated by a drawing command) are composited with the destination pixels
@@ -642,22 +626,19 @@ public class EdgeEffect {
            // assume rotations of increments of 90 degrees
            float x = mTmpPoints[10] - mTmpPoints[8];
            float width = right - left;
            float vecX = Math.max(-1f, Math.min(1f, x / width));
            float vecX = dampStretchVector(Math.max(-1f, Math.min(1f, x / width)));
            float y = mTmpPoints[11] - mTmpPoints[9];
            float height = bottom - top;
            float vecY = Math.max(-1f, Math.min(1f, y / height));
            float vecY = dampStretchVector(Math.max(-1f, Math.min(1f, y / height)));
            renderNode.stretch(
                    left,
                    top,
                    right,
                    bottom,
                    vecX * mStretchIntensity,
                    vecY * mStretchIntensity,
                    // TODO (njawad/mount) figure out proper stretch distance from UX
                    //  for now leverage placeholder logic if no stretch distance is provided to
                    //  consume the displacement ratio times the minimum of the width or height
                    mStretchDistance > 0 ? mStretchDistance :
                            (mStretchDistanceFraction * Math.max(mWidth, mHeight))
                    vecX,
                    vecY,
                    mWidth,
                    mHeight
            );
        }

@@ -794,4 +775,13 @@ public class EdgeEffect {
        return Math.abs(mVelocity) < VELOCITY_THRESHOLD
                && Math.abs(displacement) < VALUE_THRESHOLD;
    }

    private float dampStretchVector(float normalizedVec) {
        float sign = normalizedVec > 0 ? 1f : -1f;
        float overscroll = Math.abs(normalizedVec);
        float linearIntensity = LINEAR_STRETCH_INTENSITY * overscroll;
        double scalar = Math.E / SCROLL_DIST_AFFECTED_BY_EXP_STRETCH;
        double expIntensity = EXP_STRETCH_INTENSITY * (1 - Math.exp(-overscroll * scalar));
        return sign * (float) (linearIntensity + expIntensity);
    }
}
+0 −20
Original line number Diff line number Diff line
@@ -248,26 +248,6 @@ public class HorizontalScrollView extends FrameLayout {
        setRightEdgeEffectColor(color);
    }

    /**
     * API used for prototyping stretch effect parameters in framework sample apps
     * @hide
     */
    public void setEdgeEffectIntensity(float intensity) {
        mEdgeGlowLeft.setMaxStretchIntensity(intensity);
        mEdgeGlowRight.setMaxStretchIntensity(intensity);
        invalidate();
    }

    /**
     * API used for prototyping stretch effect parameters in the framework sample apps
     * @hide
     */
    public void setStretchDistance(float distance) {
        mEdgeGlowLeft.setStretchDistance(distance);
        mEdgeGlowRight.setStretchDistance(distance);
        invalidate();
    }

    /**
     * Sets the right edge effect color.
     *
+0 −20
Original line number Diff line number Diff line
@@ -280,26 +280,6 @@ public class ScrollView extends FrameLayout {
        setBottomEdgeEffectColor(color);
    }

    /**
     * API used for prototyping stretch effect parameters in framework sample apps
     * @hide
     */
    public void setEdgeEffectIntensity(float intensity) {
        mEdgeGlowTop.setMaxStretchIntensity(intensity);
        mEdgeGlowBottom.setMaxStretchIntensity(intensity);
        invalidate();
    }

    /**
     * API used for prototyping stretch effect parameters in the framework sample apps
     * @hide
     */
    public void setStretchDistance(float distance) {
        mEdgeGlowTop.setStretchDistance(distance);
        mEdgeGlowBottom.setStretchDistance(distance);
        invalidate();
    }

    /**
     * Sets the bottom edge effect color.
     *
+12 −5
Original line number Diff line number Diff line
@@ -275,6 +275,8 @@ public final class RenderNode {
         * Call to apply a stretch effect to any child SurfaceControl layers
         *
         * TODO: Fold this into positionChanged & have HWUI do the ASurfaceControl calls?
         *   (njawad) update to consume different stretch parameters for horizontal/vertical stretch
         *   to ensure SkiaGLRenderEngine can also apply the same stretch to a surface
         *
         * @hide
         */
@@ -718,7 +720,7 @@ public final class RenderNode {

    /** @hide */
    public boolean stretch(float left, float top, float right, float bottom,
            float vecX, float vecY, float maxStretchAmount) {
            float vecX, float vecY, float maxStretchAmountX, float maxStretchAmountY) {
        if (Float.isInfinite(vecX) || Float.isNaN(vecX)) {
            throw new IllegalArgumentException("vecX must be a finite, non-NaN value " + vecX);
        }
@@ -730,9 +732,13 @@ public final class RenderNode {
                    "Stretch region must not be empty, got "
                            + new RectF(left, top, right, bottom).toString());
        }
        if (maxStretchAmount <= 0.0f) {
        if (maxStretchAmountX <= 0.0f) {
            throw new IllegalArgumentException(
                    "The max stretch amount must be >0, got " + maxStretchAmount);
                    "The max horizontal stretch amount must be >0, got " + maxStretchAmountX);
        }
        if (maxStretchAmountY <= 0.0f) {
            throw new IllegalArgumentException(
                    "The max vertical stretch amount must be >0, got " + maxStretchAmountY);
        }
        return nStretch(
                mNativeRenderNode,
@@ -742,7 +748,8 @@ public final class RenderNode {
                bottom,
                vecX,
                vecY,
                maxStretchAmount
                maxStretchAmountX,
                maxStretchAmountY
        );
    }

@@ -1695,7 +1702,7 @@ public final class RenderNode {

    @CriticalNative
    private static native boolean nStretch(long renderNode, float left, float top, float right,
            float bottom, float vecX, float vecY, float maxStretch);
            float bottom, float vecX, float vecY, float maxStretchX, float maxStretchY);

    @CriticalNative
    private static native boolean nHasShadow(long renderNode);
+12 −12
Original line number Diff line number Diff line
@@ -33,7 +33,8 @@ static const SkString stretchShader = SkString(R"(
    uniform float uMaxStretchIntensity;

    // Maximum percentage to stretch beyond bounds  of target
    uniform float uStretchAffectedDist;
    uniform float uStretchAffectedDistX;
    uniform float uStretchAffectedDistY;

    // Distance stretched as a function of the normalized overscroll times
    // scale intensity
@@ -138,7 +139,7 @@ static const SkString stretchShader = SkString(R"(
            outU,
            inU,
            uOverscrollX,
            uStretchAffectedDist,
            uStretchAffectedDistX,
            uDistanceStretchedX,
            uDistDiffX
        );
@@ -146,7 +147,7 @@ static const SkString stretchShader = SkString(R"(
            outV,
            inV,
            uOverscrollY,
            uStretchAffectedDist,
            uStretchAffectedDistY,
            uDistanceStretchedY,
            uDistDiffY
        );
@@ -166,16 +167,14 @@ sk_sp<SkImageFilter> StretchEffect::getImageFilter(const sk_sp<SkImage>& snapsho
        return mStretchFilter;
    }

    float distanceNotStretchedX = maxStretchAmount / stretchArea.width();
    float distanceNotStretchedY = maxStretchAmount / stretchArea.height();
    float normOverScrollDistX = mStretchDirection.x();
    float normOverScrollDistY = mStretchDirection.y();
    float distanceStretchedX = maxStretchAmount / (1 + abs(normOverScrollDistX));
    float distanceStretchedY = maxStretchAmount / (1 + abs(normOverScrollDistY));
    float diffX = distanceStretchedX - distanceNotStretchedX;
    float diffY = distanceStretchedY - distanceNotStretchedY;
    float viewportWidth = stretchArea.width();
    float viewportHeight = stretchArea.height();
    float normOverScrollDistX = mStretchDirection.x();
    float normOverScrollDistY = mStretchDirection.y();
    float distanceStretchedX = maxStretchAmountX / (1 + abs(normOverScrollDistX));
    float distanceStretchedY = maxStretchAmountY / (1 + abs(normOverScrollDistY));
    float diffX = distanceStretchedX;
    float diffY = distanceStretchedY;

    if (mBuilder == nullptr) {
        mBuilder = std::make_unique<SkRuntimeShaderBuilder>(getStretchEffect());
@@ -183,7 +182,8 @@ sk_sp<SkImageFilter> StretchEffect::getImageFilter(const sk_sp<SkImage>& snapsho

    mBuilder->child("uContentTexture") = snapshotImage->makeShader(
            SkTileMode::kClamp, SkTileMode::kClamp, SkSamplingOptions(SkFilterMode::kLinear));
    mBuilder->uniform("uStretchAffectedDist").set(&maxStretchAmount, 1);
    mBuilder->uniform("uStretchAffectedDistX").set(&maxStretchAmountX, 1);
    mBuilder->uniform("uStretchAffectedDistY").set(&maxStretchAmountY, 1);
    mBuilder->uniform("uDistanceStretchedX").set(&distanceStretchedX, 1);
    mBuilder->uniform("uDistanceStretchedY").set(&distanceStretchedY, 1);
    mBuilder->uniform("uDistDiffX").set(&diffX, 1);
Loading