From f10d08a3d4968d3dfb4324959e33ebb691899eda Mon Sep 17 00:00:00 2001 From: Teng-Hui Zhu Date: Tue, 8 Mar 2016 15:25:39 -0800 Subject: [PATCH] Update the VD and AVD's getOpacity() static VectorDrawable should be returning Transparent while root alpha is 0. AnimatedVectorDrawable running on RenderThread now, and the opacity should be conservatively set as Translucent. http://b/27554766 Change-Id: I9a78696cab94f10ba40a733cc9c00f1c2d7ebb7f --- .../android/graphics/drawable/AnimatedVectorDrawable.java | 3 ++- graphics/java/android/graphics/drawable/VectorDrawable.java | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java index 3901af36be832..d325bd0bbb118 100644 --- a/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java +++ b/graphics/java/android/graphics/drawable/AnimatedVectorDrawable.java @@ -35,6 +35,7 @@ import android.graphics.Canvas; import android.graphics.ColorFilter; import android.graphics.Insets; import android.graphics.Outline; +import android.graphics.PixelFormat; import android.graphics.PorterDuff; import android.graphics.Rect; import android.os.Build; @@ -306,7 +307,7 @@ public class AnimatedVectorDrawable extends Drawable implements Animatable2 { @Override public int getOpacity() { - return mAnimatedVectorState.mVectorDrawable.getOpacity(); + return PixelFormat.TRANSLUCENT; } @Override diff --git a/graphics/java/android/graphics/drawable/VectorDrawable.java b/graphics/java/android/graphics/drawable/VectorDrawable.java index 9e0f1b460839a..44a91fefc4a0a 100644 --- a/graphics/java/android/graphics/drawable/VectorDrawable.java +++ b/graphics/java/android/graphics/drawable/VectorDrawable.java @@ -364,7 +364,9 @@ public class VectorDrawable extends Drawable { @Override public int getOpacity() { - return PixelFormat.TRANSLUCENT; + // We can't tell whether the drawable is fully opaque unless we examine all the pixels, + // but we could tell it is transparent if the root alpha is 0. + return getAlpha() == 0 ? PixelFormat.TRANSPARENT : PixelFormat.TRANSLUCENT; } @Override