Removed hidden mutable APIs from PorterDuffColorFilter

Removed PorterDuffColorFilter#setColor and PorterDuffColorFilter#setMode
as the public facing ColorFilter API is immutable. These framework
internal APIs were causing issues with Drawables as updates to state of
the ColorFilter would not be propagated up to the Drawable to cause an
invalidation.

Fixes: 77723600
Test: Ran atest on SystemUITest and CtsGraphicsTest modules

Change-Id: I935c9e35ffa225735b951bb3b1eb753ea5815a84
This commit is contained in:
Nader Jawad
2018-04-09 09:54:48 -07:00
parent 02adb97ec2
commit 85ff47e3fc
9 changed files with 52 additions and 73 deletions

View File

@@ -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
*/
@@ -57,31 +54,11 @@ public class PorterDuffColorFilter extends ColorFilter {
return mColor;
}
/**
* 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);

View File

@@ -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;
}

View File

@@ -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);