Refactor Skia shaders handling.

With this change, Skia shaders can easily be applied to any mesh. This change also
supports ComposeShader. For instance, this can be used to blend a gradient and a
bitmap togehter and paint a string of text with the result.

Change-Id: I701c2f9cf7f89b2ff58005e8a1d0d80ccf4a4aea
This commit is contained in:
Romain Guy
2010-07-30 19:18:16 -07:00
parent 42272759e4
commit 06f96e2652
15 changed files with 618 additions and 439 deletions

View File

@ -17,28 +17,6 @@
package android.graphics;
public class LinearGradient extends Shader {
/**
* These fields are manipulated by the JNI layer, don't touch!
* @hide
*/
public int bounds;
/**
* @hide
*/
public int colors;
/**
* @hide
*/
public int positions;
/**
* @hide
*/
public int count;
/**
* @hide
*/
public int tileMode;
/** Create a shader that draws a linear gradient along a line.
@param x0 The x-coordinate for the start of the gradient line
@param y0 The y-coordinate for the start of the gradient line
@ -59,8 +37,8 @@ public class LinearGradient extends Shader {
throw new IllegalArgumentException("color and position arrays must be of equal length");
}
native_instance = nativeCreate1(x0, y0, x1, y1, colors, positions, tile.nativeInt);
count = colors.length;
tileMode = tile.nativeInt;
native_shader = nativePostCreate1(native_instance, x0, y0, x1, y1, colors, positions,
tile.nativeInt);
}
/** Create a shader that draws a linear gradient along a line.
@ -75,21 +53,16 @@ public class LinearGradient extends Shader {
public LinearGradient(float x0, float y0, float x1, float y1,
int color0, int color1, TileMode tile) {
native_instance = nativeCreate2(x0, y0, x1, y1, color0, color1, tile.nativeInt);
count = 2;
tileMode = tile.nativeInt;
}
protected void finalize() throws Throwable {
try {
super.finalize();
} finally {
nativeDestructor(native_instance);
}
native_shader = nativePostCreate2(native_instance, x0, y0, x1, y1, color0, color1,
tile.nativeInt);
}
private native void nativeDestructor(int native_shader);
private native int nativeCreate1(float x0, float y0, float x1, float y1,
int colors[], float positions[], int tileMode);
private native int nativeCreate2(float x0, float y0, float x1, float y1,
int color0, int color1, int tileMode);
private native int nativePostCreate1(int native_shader, float x0, float y0, float x1, float y1,
int colors[], float positions[], int tileMode);
private native int nativePostCreate2(int native_shader, float x0, float y0, float x1, float y1,
int color0, int color1, int tileMode);
}