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

Commit 3fa3403e authored by Romain Guy's avatar Romain Guy Committed by Android (Google) Code Review
Browse files

Merge "Support non-PorterDuff xfermodes with Xfermode."

parents 4d0e7cd7 8918190a
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -20,7 +20,12 @@ package android.graphics;
    an {@link android.graphics.Xfermode} subclass.
*/
public class ComposeShader extends Shader {
    /**
     * Hold onto the shaders to avoid GC.
     */
    @SuppressWarnings({"UnusedDeclaration"})
    private final Shader mShaderA;
    @SuppressWarnings({"UnusedDeclaration"})
    private final Shader mShaderB;

    /** Create a new compose shader, given shaders A, B, and a combining mode.
@@ -36,8 +41,14 @@ public class ComposeShader extends Shader {
        mShaderB = shaderB;
        native_instance = nativeCreate1(shaderA.native_instance, shaderB.native_instance,
                (mode != null) ? mode.native_instance : 0);
        if (mode instanceof PorterDuffXfermode) {
            PorterDuff.Mode pdMode = ((PorterDuffXfermode) mode).mode;
            native_shader = nativePostCreate1(native_instance, shaderA.native_shader,
                    shaderB.native_shader, pdMode != null ? pdMode.nativeInt : 0);
        } else {
            native_shader = nativePostCreate1(native_instance, shaderA.native_shader,
                shaderB.native_shader, (mode != null) ? mode.native_instance : 0);
                    shaderB.native_shader, mode != null ? mode.native_instance : 0);
        }
    }

    /** Create a new compose shader, given shaders A, B, and a combining PorterDuff mode.
+6 −0
Original line number Diff line number Diff line
@@ -17,12 +17,18 @@
package android.graphics;

public class PorterDuffXfermode extends Xfermode {
    /**
     * @hide
     */
    public final PorterDuff.Mode mode;

    /**
     * Create an xfermode that uses the specified porter-duff mode.
     *
     * @param mode           The porter-duff mode that is applied
     */
    public PorterDuffXfermode(PorterDuff.Mode mode) {
        this.mode = mode;
        native_instance = nativeCreateXfermode(mode.nativeInt);
    }
    
+5 −1
Original line number Diff line number Diff line
@@ -31,7 +31,11 @@ package android.graphics;
public class Xfermode {

    protected void finalize() throws Throwable {
        try {
            finalizer(native_instance);
        } finally {
            super.finalize();
        }
    }

    private static native void finalizer(int native_instance);