Have RippleDrawable ignore non-attached RenderNodes

Don't try to do a RenderNodeAnimation if the RenderNode
isn't attached. Although this isn't strictly speaking a
valid state to be in, it's also easy for RippleDrawable
to just ignore it.

Bug: 186864959
Test: ripples still show up, are still RT accelerated normally
Change-Id: I8127f1419508157eb83ac9bb1562745ac53d2ced
This commit is contained in:
John Reck
2021-08-04 11:18:32 -04:00
parent d459da6362
commit a355e904a2

View File

@@ -67,7 +67,7 @@ public final class RippleAnimationSession {
@NonNull RippleAnimationSession enter(Canvas canvas) {
mStartTime = AnimationUtils.currentAnimationTimeMillis();
if (isHwAccelerated(canvas)) {
if (useRTAnimations(canvas)) {
enterHardware((RecordingCanvas) canvas);
} else {
enterSoftware();
@@ -82,7 +82,7 @@ public final class RippleAnimationSession {
}
@NonNull RippleAnimationSession exit(Canvas canvas) {
if (isHwAccelerated(canvas)) exitHardware((RecordingCanvas) canvas);
if (useRTAnimations(canvas)) exitHardware((RecordingCanvas) canvas);
else exitSoftware();
return this;
}
@@ -102,8 +102,12 @@ public final class RippleAnimationSession {
return this;
}
private boolean isHwAccelerated(Canvas canvas) {
return canvas.isHardwareAccelerated() && !mForceSoftware;
private boolean useRTAnimations(Canvas canvas) {
if (mForceSoftware) return false;
if (!canvas.isHardwareAccelerated()) return false;
RecordingCanvas hwCanvas = (RecordingCanvas) canvas;
if (hwCanvas.mNode == null || !hwCanvas.mNode.isAttached()) return false;
return true;
}
private void exitSoftware() {