From 2ae56403542582bd39c0e522bf29844d59300f37 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Mon, 15 Sep 2014 12:27:13 -0700 Subject: 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 --- .../java/android/graphics/drawable/Ripple.java | 4 ++++ .../graphics/drawable/RippleBackground.java | 4 ++++ .../android/graphics/drawable/RippleDrawable.java | 27 ++++++++++++++++++---- 3 files changed, 30 insertions(+), 5 deletions(-) (limited to 'graphics') diff --git a/graphics/java/android/graphics/drawable/Ripple.java b/graphics/java/android/graphics/drawable/Ripple.java index 6f95f91..864e119 100644 --- a/graphics/java/android/graphics/drawable/Ripple.java +++ b/graphics/java/android/graphics/drawable/Ripple.java @@ -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(); diff --git a/graphics/java/android/graphics/drawable/RippleBackground.java b/graphics/java/android/graphics/drawable/RippleBackground.java index bc6f5fb..4e709b5 100644 --- a/graphics/java/android/graphics/drawable/RippleBackground.java +++ b/graphics/java/android/graphics/drawable/RippleBackground.java @@ -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; diff --git a/graphics/java/android/graphics/drawable/RippleDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java index b13669b..4fd98b7 100644 --- a/graphics/java/android/graphics/drawable/RippleDrawable.java +++ b/graphics/java/android/graphics/drawable/RippleDrawable.java @@ -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; -- cgit v1.1