Merge "Support non-PorterDuff xfermodes with Xfermode."

This commit is contained in:
Romain Guy
2010-08-10 21:56:12 -07:00
committed by Android (Google) Code Review
3 changed files with 24 additions and 3 deletions

View File

@@ -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);
native_shader = nativePostCreate1(native_instance, shaderA.native_shader,
shaderB.native_shader, (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);
}
}
/** Create a new compose shader, given shaders A, B, and a combining PorterDuff mode.

View File

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

View File

@@ -31,7 +31,11 @@ package android.graphics;
public class Xfermode {
protected void finalize() throws Throwable {
finalizer(native_instance);
try {
finalizer(native_instance);
} finally {
super.finalize();
}
}
private static native void finalizer(int native_instance);