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

Commit be71b3ed authored by Jorge Betancourt's avatar Jorge Betancourt
Browse files

add RuntimeXfermode API to the graphics platform

Flag: com.android.graphics.hwui.flags.runtime_color_filters_blenders

Test: atest CtsUiRenderingTestCases:RuntimeXfermodeTests
Bug: b/358126864

Change-Id: Idd15f937707feec51387b513b75cfadfaf0336a3
parent a9774d77
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -17491,6 +17491,25 @@ package android.graphics {
    method public void setIntUniform(@NonNull String, @NonNull int[]);
  }
  @FlaggedApi("com.android.graphics.hwui.flags.runtime_color_filters_blenders") public class RuntimeXfermode extends android.graphics.Xfermode {
    ctor public RuntimeXfermode(@NonNull String);
    method public void setColorUniform(@NonNull String, @ColorInt int);
    method public void setColorUniform(@NonNull String, @ColorLong long);
    method public void setColorUniform(@NonNull String, @NonNull android.graphics.Color);
    method public void setFloatUniform(@NonNull String, float);
    method public void setFloatUniform(@NonNull String, float, float);
    method public void setFloatUniform(@NonNull String, float, float, float);
    method public void setFloatUniform(@NonNull String, float, float, float, float);
    method public void setFloatUniform(@NonNull String, @NonNull float[]);
    method public void setInputColorFilter(@NonNull String, @NonNull android.graphics.ColorFilter);
    method public void setInputShader(@NonNull String, @NonNull android.graphics.Shader);
    method public void setIntUniform(@NonNull String, int);
    method public void setIntUniform(@NonNull String, int, int);
    method public void setIntUniform(@NonNull String, int, int, int);
    method public void setIntUniform(@NonNull String, int, int, int, int);
    method public void setIntUniform(@NonNull String, @NonNull int[]);
  }
  public class Shader {
    ctor @Deprecated public Shader();
    method public boolean getLocalMatrix(@NonNull android.graphics.Matrix);
+3 −3
Original line number Diff line number Diff line
@@ -571,10 +571,10 @@ public enum BlendMode {
    }

    @NonNull
    private final Xfermode mXfermode;
    private final PorterDuffXfermode mXfermode;

    BlendMode(int mode) {
        mXfermode = new Xfermode();
        mXfermode = new PorterDuffXfermode();
        mXfermode.porterDuffMode = mode;
    }

@@ -582,7 +582,7 @@ public enum BlendMode {
     * @hide
     */
    @NonNull
    public Xfermode getXfermode() {
    public PorterDuffXfermode getXfermode() {
        return mXfermode;
    }
}
+4 −1
Original line number Diff line number Diff line
@@ -40,9 +40,12 @@ public class ComposeShader extends Shader {
     * @param mode     The mode that combines the colors from the two shaders. If mode
     *                 is null, then SRC_OVER is assumed.
     */
    //TODO(358126864): allow a ComposeShader to accept a RuntimeXfermode
    @Deprecated
    public ComposeShader(@NonNull Shader shaderA, @NonNull Shader shaderB, @NonNull Xfermode mode) {
        this(shaderA, shaderB, mode.porterDuffMode);
        this(shaderA, shaderB,
                mode instanceof PorterDuffXfermode ? ((PorterDuffXfermode) mode).porterDuffMode
                : BlendMode.SRC_OVER.getXfermode().porterDuffMode);
    }

    /**
+26 −6
Original line number Diff line number Diff line
@@ -71,6 +71,7 @@ public class Paint {
    private long mNativePaint;
    private long mNativeShader;
    private long mNativeColorFilter;
    private long mNativeXfermode;

    // Use a Holder to allow static initialization of Paint in the boot image.
    private static class NoImagePreloadHolder {
@@ -735,6 +736,7 @@ public class Paint {
        mPathEffect = null;
        mShader = null;
        mNativeShader = 0;
        mNativeXfermode = 0;
        mTypeface = null;
        mXfermode = null;

@@ -780,6 +782,7 @@ public class Paint {
        mNativeShader = paint.mNativeShader;
        mTypeface = paint.mTypeface;
        mXfermode = paint.mXfermode;
        mNativeXfermode = paint.mNativeXfermode;

        mHasCompatScaling = paint.mHasCompatScaling;
        mCompatScaling = paint.mCompatScaling;
@@ -815,7 +818,7 @@ public class Paint {
     *
     * Note: Although this method is |synchronized|, this is simply so it
     * is not thread-hostile to multiple threads calling this method. It
     * is still unsafe to attempt to change the Shader/ColorFilter while
     * is still unsafe to attempt to change the Shader/ColorFilter/Xfermode while
     * another thread attempts to access the native object.
     *
     * @hide
@@ -833,6 +836,13 @@ public class Paint {
            mNativeColorFilter = newNativeColorFilter;
            nSetColorFilter(mNativePaint, mNativeColorFilter);
        }
        if (mXfermode instanceof RuntimeXfermode) {
            long newNativeXfermode = ((RuntimeXfermode) mXfermode).createNativeInstance();
            if (newNativeXfermode != mNativeXfermode) {
                mNativeXfermode = newNativeXfermode;
                nSetXfermode(mNativePaint, mNativeXfermode);
            }
        }
        return mNativePaint;
    }

@@ -1427,16 +1437,17 @@ public class Paint {
    }

    /**
     * Get the paint's blend mode object.
     * Get the paint's blend mode object. Will return null if there is a Xfermode applied that
     * cannot be represented by a blend mode (i.e. a custom {@code RuntimeXfermode}
     *
     * @return the paint's blend mode (or null)
     */
    @Nullable
    public BlendMode getBlendMode() {
        if (mXfermode == null) {
        if (mXfermode == null || !(mXfermode instanceof PorterDuffXfermode)) {
            return null;
        } else {
            return BlendMode.fromValue(mXfermode.porterDuffMode);
            return BlendMode.fromValue(((PorterDuffXfermode) mXfermode).porterDuffMode);
        }
    }

@@ -1459,8 +1470,15 @@ public class Paint {

    @Nullable
    private Xfermode installXfermode(Xfermode xfermode) {
        int newMode = xfermode != null ? xfermode.porterDuffMode : Xfermode.DEFAULT;
        int curMode = mXfermode != null ? mXfermode.porterDuffMode : Xfermode.DEFAULT;
        if (xfermode instanceof RuntimeXfermode) {
            mXfermode = xfermode;
            nSetXfermode(mNativePaint, ((RuntimeXfermode) xfermode).createNativeInstance());
            return xfermode;
        }
        int newMode = (xfermode instanceof PorterDuffXfermode)
                ? ((PorterDuffXfermode) xfermode).porterDuffMode : PorterDuffXfermode.DEFAULT;
        int curMode = (mXfermode instanceof PorterDuffXfermode)
                ? ((PorterDuffXfermode) mXfermode).porterDuffMode : PorterDuffXfermode.DEFAULT;
        if (newMode != curMode) {
            nSetXfermode(mNativePaint, newMode);
        }
@@ -3823,6 +3841,8 @@ public class Paint {
    @CriticalNative
    private static native void nSetXfermode(long paintPtr, int xfermode);
    @CriticalNative
    private static native void nSetXfermode(long paintPtr, long xfermodePtr);
    @CriticalNative
    private static native long nSetPathEffect(long paintPtr, long effect);
    @CriticalNative
    private static native long nSetMaskFilter(long paintPtr, long maskfilter);
+3 −0
Original line number Diff line number Diff line
@@ -29,6 +29,9 @@ public class PorterDuffXfermode extends Xfermode {
     *
     * @param mode           The porter-duff mode that is applied
     */
    static final int DEFAULT = PorterDuff.Mode.SRC_OVER.nativeInt;
    int porterDuffMode = DEFAULT;
    PorterDuffXfermode() {}
    public PorterDuffXfermode(PorterDuff.Mode mode) {
        porterDuffMode = mode.nativeInt;
    }
Loading