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

Commit 2ae56403 authored by Alan Viverette's avatar Alan Viverette
Browse files

Reduce overdraw after clearing ripples in RippleDrawable

We only need to force a transparent draw after canceling a render
thread accelerated animation, and then we can draw again without
the transparency to avoid overdraw in the display list.

BUG: 17451761
Change-Id: I640f9a29d0940a93802f14a15f27d2c2072755ce
parent c6a65dfb
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -139,6 +139,10 @@ class Ripple {
        clampStartingPosition();
    }

    public boolean isHardwareAnimating() {
        return mHardwareAnimating;
    }

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

    public boolean isHardwareAnimating() {
        return mHardwareAnimating;
    }

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

        boolean needsDraw = false;

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

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

        cancelExitingRipples();
        needsDraw |= cancelExitingRipples();

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

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

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

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

        return needsDraw;
    }

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

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

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

        cancelExitingRipples();
        needsDraw |= cancelExitingRipples();

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

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

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