Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 85ff47e3 authored by Nader Jawad's avatar Nader Jawad
Browse files

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
parent 02adb97e
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -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
+0 −41
Original line number Diff line number Diff line
@@ -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);
+7 −8
Original line number Diff line number Diff line
@@ -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;
    }

+4 −1
Original line number Diff line number Diff line
@@ -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);
+14 −4
Original line number Diff line number Diff line
@@ -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);
Loading