summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config/hiddenapi-light-greylist.txt2
-rw-r--r--graphics/java/android/graphics/PorterDuffColorFilter.java41
-rw-r--r--graphics/java/android/graphics/drawable/Drawable.java15
-rw-r--r--graphics/java/android/graphics/drawable/RippleDrawable.java5
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/drawable/UserIconDrawable.java18
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/ScrimView.java15
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationIconDozeHelper.java12
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java15
-rw-r--r--tests/HwAccelerationTest/src/com/android/test/hwui/ColorFiltersMutateActivity.java2
9 files changed, 52 insertions, 73 deletions
diff --git a/config/hiddenapi-light-greylist.txt b/config/hiddenapi-light-greylist.txt
index a1e71f46b61b..973968469e48 100644
--- a/config/hiddenapi-light-greylist.txt
+++ b/config/hiddenapi-light-greylist.txt
@@ -793,8 +793,6 @@ Landroid/graphics/NinePatch$InsetStruct;-><init>(IIIIIIIIFIF)V
Landroid/graphics/NinePatch;->mBitmap:Landroid/graphics/Bitmap;
Landroid/graphics/Picture;->mNativePicture:J
Landroid/graphics/PixelXorXfermode;-><init>(I)V
-Landroid/graphics/PorterDuffColorFilter;->setColor(I)V
-Landroid/graphics/PorterDuffColorFilter;->setMode(Landroid/graphics/PorterDuff$Mode;)V
Landroid/graphics/Rect;->scale(F)V
Landroid/graphics/Region;-><init>(JI)V
Landroid/graphics/Region;->mNativeRegion:J
diff --git a/graphics/java/android/graphics/PorterDuffColorFilter.java b/graphics/java/android/graphics/PorterDuffColorFilter.java
index 01d5825dd1e0..88a63223ea40 100644
--- a/graphics/java/android/graphics/PorterDuffColorFilter.java
+++ b/graphics/java/android/graphics/PorterDuffColorFilter.java
@@ -35,8 +35,6 @@ public class PorterDuffColorFilter extends ColorFilter {
* @param mode The porter-duff mode that is applied
*
* @see Color
- * @see #setColor(int)
- * @see #setMode(android.graphics.PorterDuff.Mode)
*/
public PorterDuffColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode) {
mColor = color;
@@ -48,7 +46,6 @@ public class PorterDuffColorFilter extends ColorFilter {
* is applied.
*
* @see Color
- * @see #setColor(int)
*
* @hide
*/
@@ -58,30 +55,10 @@ public class PorterDuffColorFilter extends ColorFilter {
}
/**
- * Specifies the color to tint the source pixels with when this color
- * filter is applied.
- *
- * @param color An ARGB {@link Color color}
- *
- * @see Color
- * @see #getColor()
- * @see #getMode()
- *
- * @hide
- */
- public void setColor(@ColorInt int color) {
- if (mColor != color) {
- mColor = color;
- discardNativeInstance();
- }
- }
-
- /**
* Returns the Porter-Duff mode used to composite this color filter's
* color with the source pixel when this filter is applied.
*
* @see PorterDuff
- * @see #setMode(android.graphics.PorterDuff.Mode)
*
* @hide
*/
@@ -89,24 +66,6 @@ public class PorterDuffColorFilter extends ColorFilter {
return mMode;
}
- /**
- * Specifies the Porter-Duff mode to use when compositing this color
- * filter's color with the source pixel at draw time.
- *
- * @see PorterDuff
- * @see #getMode()
- * @see #getColor()
- *
- * @hide
- */
- public void setMode(@NonNull PorterDuff.Mode mode) {
- if (mode == null) {
- throw new IllegalArgumentException("mode must be non-null");
- }
- mMode = mode;
- discardNativeInstance();
- }
-
@Override
long createNativeInstance() {
return native_CreatePorterDuffFilter(mColor, mMode.nativeInt);
diff --git a/graphics/java/android/graphics/drawable/Drawable.java b/graphics/java/android/graphics/drawable/Drawable.java
index 8af2fd8bbb5e..b77d74a7c675 100644
--- a/graphics/java/android/graphics/drawable/Drawable.java
+++ b/graphics/java/android/graphics/drawable/Drawable.java
@@ -16,11 +16,6 @@
package android.graphics.drawable;
-import com.android.internal.R;
-
-import org.xmlpull.v1.XmlPullParser;
-import org.xmlpull.v1.XmlPullParserException;
-
import android.annotation.AttrRes;
import android.annotation.ColorInt;
import android.annotation.IntRange;
@@ -57,6 +52,11 @@ import android.util.TypedValue;
import android.util.Xml;
import android.view.View;
+import com.android.internal.R;
+
+import org.xmlpull.v1.XmlPullParser;
+import org.xmlpull.v1.XmlPullParserException;
+
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
@@ -1516,12 +1516,11 @@ public abstract class Drawable {
}
final int color = tint.getColorForState(getState(), Color.TRANSPARENT);
- if (tintFilter == null) {
+ if (tintFilter == null || tintFilter.getColor() != color
+ || tintFilter.getMode() != tintMode) {
return new PorterDuffColorFilter(color, tintMode);
}
- tintFilter.setColor(color);
- tintFilter.setMode(tintMode);
return tintFilter;
}
diff --git a/graphics/java/android/graphics/drawable/RippleDrawable.java b/graphics/java/android/graphics/drawable/RippleDrawable.java
index 0da61c29bd8d..266a6ac87d53 100644
--- a/graphics/java/android/graphics/drawable/RippleDrawable.java
+++ b/graphics/java/android/graphics/drawable/RippleDrawable.java
@@ -888,7 +888,10 @@ public class RippleDrawable extends LayerDrawable {
// The ripple timing depends on the paint's alpha value, so we need
// to push just the alpha channel into the paint and let the filter
// handle the full-alpha color.
- mMaskColorFilter.setColor(color | 0xFF000000);
+ int maskColor = color | 0xFF000000;
+ if (mMaskColorFilter.getColor() != maskColor) {
+ mMaskColorFilter = new PorterDuffColorFilter(maskColor, mMaskColorFilter.getMode());
+ }
p.setColor(color & 0xFF000000);
p.setColorFilter(mMaskColorFilter);
p.setShader(mMaskShader);
diff --git a/packages/SettingsLib/src/com/android/settingslib/drawable/UserIconDrawable.java b/packages/SettingsLib/src/com/android/settingslib/drawable/UserIconDrawable.java
index 54d1aba09ae3..148b7a72b705 100644
--- a/packages/SettingsLib/src/com/android/settingslib/drawable/UserIconDrawable.java
+++ b/packages/SettingsLib/src/com/android/settingslib/drawable/UserIconDrawable.java
@@ -16,6 +16,7 @@
package com.android.settingslib.drawable;
+import android.annotation.ColorInt;
import android.annotation.DrawableRes;
import android.annotation.NonNull;
import android.app.admin.DevicePolicyManager;
@@ -251,11 +252,8 @@ public class UserIconDrawable extends Drawable implements Drawable.Callback {
mPaint.setColorFilter(null);
} else {
int color = mTintColor.getColorForState(getState(), mTintColor.getDefaultColor());
- if (mPaint.getColorFilter() == null) {
+ if (shouldUpdateColorFilter(color, mTintMode)) {
mPaint.setColorFilter(new PorterDuffColorFilter(color, mTintMode));
- } else {
- ((PorterDuffColorFilter) mPaint.getColorFilter()).setMode(mTintMode);
- ((PorterDuffColorFilter) mPaint.getColorFilter()).setColor(color);
}
}
@@ -263,6 +261,18 @@ public class UserIconDrawable extends Drawable implements Drawable.Callback {
}
}
+ private boolean shouldUpdateColorFilter(@ColorInt int color, PorterDuff.Mode mode) {
+ ColorFilter colorFilter = mPaint.getColorFilter();
+ if (colorFilter instanceof PorterDuffColorFilter) {
+ PorterDuffColorFilter porterDuffColorFilter = (PorterDuffColorFilter) colorFilter;
+ int currentColor = porterDuffColorFilter.getColor();
+ PorterDuff.Mode currentMode = porterDuffColorFilter.getMode();
+ return currentColor != color || currentMode != mode;
+ } else {
+ return false;
+ }
+ }
+
@Override
public void setAlpha(int alpha) {
mPaint.setAlpha(alpha);
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ScrimView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ScrimView.java
index 1807465004c6..c99bdef36492 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/ScrimView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/ScrimView.java
@@ -26,6 +26,7 @@ import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.PorterDuff;
+import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
@@ -272,12 +273,18 @@ public class ScrimView extends View implements ConfigurationController.Configura
tintAmount);
drawable.setColors(mainTinted, secondaryTinted, animated);
} else {
- if (mColorFilter == null) {
- mColorFilter = new PorterDuffColorFilter(mTintColor, PorterDuff.Mode.SRC_OVER);
+ boolean hasAlpha = Color.alpha(mTintColor) != 0;
+ if (hasAlpha) {
+ PorterDuff.Mode targetMode = mColorFilter == null ? Mode.SRC_OVER :
+ mColorFilter.getMode();
+ if (mColorFilter == null || mColorFilter.getColor() != mTintColor) {
+ mColorFilter = new PorterDuffColorFilter(mTintColor, targetMode);
+ }
} else {
- mColorFilter.setColor(mTintColor);
+ mColorFilter = null;
}
- mDrawable.setColorFilter(Color.alpha(mTintColor) == 0 ? null : mColorFilter);
+
+ mDrawable.setColorFilter(mColorFilter);
mDrawable.invalidateSelf();
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationIconDozeHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationIconDozeHelper.java
index 9f79ef2491d9..43e45b14cfbe 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationIconDozeHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationIconDozeHelper.java
@@ -16,9 +16,10 @@
package com.android.systemui.statusbar.notification;
+import android.annotation.Nullable;
import android.content.Context;
import android.graphics.Color;
-import android.graphics.PorterDuff;
+import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
@@ -29,8 +30,9 @@ public class NotificationIconDozeHelper extends NotificationDozeHelper {
private final int mImageDarkAlpha;
private final int mImageDarkColor = 0xffffffff;
- private final PorterDuffColorFilter mImageColorFilter = new PorterDuffColorFilter(
- 0, PorterDuff.Mode.SRC_ATOP);
+
+ @Nullable
+ private PorterDuffColorFilter mImageColorFilter = null;
private int mColor = Color.BLACK;
@@ -80,7 +82,9 @@ public class NotificationIconDozeHelper extends NotificationDozeHelper {
private void updateImageColorFilter(ImageView target, float intensity) {
int color = NotificationUtils.interpolateColors(mColor, mImageDarkColor, intensity);
- mImageColorFilter.setColor(color);
+ if (mImageColorFilter == null || mImageColorFilter.getColor() != color) {
+ mImageColorFilter = new PorterDuffColorFilter(color, Mode.SRC_ATOP);
+ }
Drawable imageDrawable = target.getDrawable();
// Also, the notification might have been modified during the animation, so background
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java
index 4bca79715422..5ec822dcbe08 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/BarTransitions.java
@@ -183,20 +183,19 @@ public class BarTransitions {
@Override
public void setTint(int color) {
- if (mTintFilter == null) {
- mTintFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
- } else {
- mTintFilter.setColor(color);
+ PorterDuff.Mode targetMode = mTintFilter == null ? Mode.SRC_IN :
+ mTintFilter.getMode();
+ if (mTintFilter == null || mTintFilter.getColor() != color) {
+ mTintFilter = new PorterDuffColorFilter(color, targetMode);
}
invalidateSelf();
}
@Override
public void setTintMode(Mode tintMode) {
- if (mTintFilter == null) {
- mTintFilter = new PorterDuffColorFilter(0, tintMode);
- } else {
- mTintFilter.setMode(tintMode);
+ int targetColor = mTintFilter == null ? 0 : mTintFilter.getColor();
+ if (mTintFilter == null || mTintFilter.getMode() != tintMode) {
+ mTintFilter = new PorterDuffColorFilter(targetColor, tintMode);
}
invalidateSelf();
}
diff --git a/tests/HwAccelerationTest/src/com/android/test/hwui/ColorFiltersMutateActivity.java b/tests/HwAccelerationTest/src/com/android/test/hwui/ColorFiltersMutateActivity.java
index a7bdabd64684..0787d823756c 100644
--- a/tests/HwAccelerationTest/src/com/android/test/hwui/ColorFiltersMutateActivity.java
+++ b/tests/HwAccelerationTest/src/com/android/test/hwui/ColorFiltersMutateActivity.java
@@ -106,7 +106,7 @@ public class ColorFiltersMutateActivity extends Activity {
mPorterDuffColor = porterDuffColor;
final PorterDuffColorFilter filter =
(PorterDuffColorFilter) mBlendPaint.getColorFilter();
- filter.setColor(mPorterDuffColor);
+ mBlendPaint.setColorFilter(new PorterDuffColorFilter(porterDuffColor, filter.getMode()));
invalidate();
}