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

Commit 238aeca5 authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Reduce overdraw after clearing ripples in RippleDrawable" into lmp-dev

parents 84f20ec4 2ae56403
Loading
Loading
Loading
Loading
+4 −0
Original line number Original line Diff line number Diff line
@@ -139,6 +139,10 @@ class Ripple {
        clampStartingPosition();
        clampStartingPosition();
    }
    }


    public boolean isHardwareAnimating() {
        return mHardwareAnimating;
    }

    private void clampStartingPosition() {
    private void clampStartingPosition() {
        final float cX = mBounds.exactCenterX();
        final float cX = mBounds.exactCenterX();
        final float cY = mBounds.exactCenterY();
        final float cY = mBounds.exactCenterY();
+4 −0
Original line number Original line Diff line number Diff line
@@ -122,6 +122,10 @@ class RippleBackground {
        mDensity = density;
        mDensity = density;
    }
    }


    public boolean isHardwareAnimating() {
        return mHardwareAnimating;
    }

    public void onHotspotBoundsChanged() {
    public void onHotspotBoundsChanged() {
        if (!mHasMaxRadius) {
        if (!mHasMaxRadius) {
            final float halfWidth = mBounds.width() / 2.0f;
            final float halfWidth = mBounds.width() / 2.0f;
+22 −5
Original line number Original line Diff line number Diff line
@@ -202,24 +202,31 @@ public class RippleDrawable extends LayerDrawable {
    public void jumpToCurrentState() {
    public void jumpToCurrentState() {
        super.jumpToCurrentState();
        super.jumpToCurrentState();


        boolean needsDraw = false;

        if (mRipple != null) {
        if (mRipple != null) {
            needsDraw |= mRipple.isHardwareAnimating();
            mRipple.jump();
            mRipple.jump();
        }
        }


        if (mBackground != null) {
        if (mBackground != null) {
            needsDraw |= mBackground.isHardwareAnimating();
            mBackground.jump();
            mBackground.jump();
        }
        }


        cancelExitingRipples();
        needsDraw |= cancelExitingRipples();


        mNeedsDraw = true;
        mNeedsDraw = needsDraw;
        invalidateSelf();
        invalidateSelf();
    }
    }


    private void cancelExitingRipples() {
    private boolean cancelExitingRipples() {
        boolean needsDraw = false;

        final int count = mExitingRipplesCount;
        final int count = mExitingRipplesCount;
        final Ripple[] ripples = mExitingRipples;
        final Ripple[] ripples = mExitingRipples;
        for (int i = 0; i < count; i++) {
        for (int i = 0; i < count; i++) {
            needsDraw |= ripples[i].isHardwareAnimating();
            ripples[i].cancel();
            ripples[i].cancel();
        }
        }


@@ -227,6 +234,8 @@ public class RippleDrawable extends LayerDrawable {
            Arrays.fill(ripples, 0, count, null);
            Arrays.fill(ripples, 0, count, null);
        }
        }
        mExitingRipplesCount = 0;
        mExitingRipplesCount = 0;

        return needsDraw;
    }
    }


    @Override
    @Override
@@ -546,19 +555,23 @@ public class RippleDrawable extends LayerDrawable {
     * background. Nothing will be drawn after this method is called.
     * background. Nothing will be drawn after this method is called.
     */
     */
    private void clearHotspots() {
    private void clearHotspots() {
        boolean needsDraw = false;

        if (mRipple != null) {
        if (mRipple != null) {
            needsDraw |= mRipple.isHardwareAnimating();
            mRipple.cancel();
            mRipple.cancel();
            mRipple = null;
            mRipple = null;
        }
        }


        if (mBackground != null) {
        if (mBackground != null) {
            needsDraw |= mBackground.isHardwareAnimating();
            mBackground.cancel();
            mBackground.cancel();
            mBackground = null;
            mBackground = null;
        }
        }


        cancelExitingRipples();
        needsDraw |= cancelExitingRipples();


        mNeedsDraw = true;
        mNeedsDraw = needsDraw;
        invalidateSelf();
        invalidateSelf();
    }
    }


@@ -657,6 +670,10 @@ public class RippleDrawable extends LayerDrawable {
        // least draw a color so that hardware invalidation works correctly.
        // least draw a color so that hardware invalidation works correctly.
        if (contentLayer < 0 && backgroundLayer < 0 && rippleLayer < 0 && mNeedsDraw) {
        if (contentLayer < 0 && backgroundLayer < 0 && rippleLayer < 0 && mNeedsDraw) {
            canvas.drawColor(Color.TRANSPARENT);
            canvas.drawColor(Color.TRANSPARENT);

            // Request another draw so we can avoid adding a transparent layer
            // during the next display list refresh.
            invalidateSelf();
        }
        }
        mNeedsDraw = false;
        mNeedsDraw = false;