diff options
author | Romain Guy <romainguy@google.com> | 2010-07-30 19:18:16 -0700 |
---|---|---|
committer | Romain Guy <romainguy@google.com> | 2010-07-30 19:18:16 -0700 |
commit | 06f96e2652e4855b6520ad9dd70583677605b79a (patch) | |
tree | 7d0e3709c8a400e264f37206eb27a286ee50d64b /graphics | |
parent | 42272759e4c3c406977187fd2b4df8739edccde8 (diff) | |
download | frameworks_base-06f96e2652e4855b6520ad9dd70583677605b79a.zip frameworks_base-06f96e2652e4855b6520ad9dd70583677605b79a.tar.gz frameworks_base-06f96e2652e4855b6520ad9dd70583677605b79a.tar.bz2 |
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
Diffstat (limited to 'graphics')
-rw-r--r-- | graphics/java/android/graphics/BitmapShader.java | 26 | ||||
-rw-r--r-- | graphics/java/android/graphics/ComposeShader.java | 19 | ||||
-rw-r--r-- | graphics/java/android/graphics/LinearGradient.java | 43 | ||||
-rw-r--r-- | graphics/java/android/graphics/Shader.java | 22 |
4 files changed, 37 insertions, 73 deletions
diff --git a/graphics/java/android/graphics/BitmapShader.java b/graphics/java/android/graphics/BitmapShader.java index 37b40e7..4c92942 100644 --- a/graphics/java/android/graphics/BitmapShader.java +++ b/graphics/java/android/graphics/BitmapShader.java @@ -22,21 +22,6 @@ package android.graphics; */ public class BitmapShader extends Shader { /** - * We hold on just for the GC, since our native counterpart is using it. - * - * @hide - */ - public Bitmap mBitmap; - /** - * @hide - */ - public int mTileX; - /** - * @hide - */ - public int mTileY; - - /** * Call this to create a new shader that will draw with a bitmap. * * @param bitmap The bitmap to use inside the shader @@ -44,12 +29,13 @@ public class BitmapShader extends Shader { * @param tileY The tiling mode for y to draw the bitmap in. */ public BitmapShader(Bitmap bitmap, TileMode tileX, TileMode tileY) { - mBitmap = bitmap; - mTileX = tileX.nativeInt; - mTileY = tileY.nativeInt; - native_instance = nativeCreate(bitmap.ni(), mTileX, mTileY); + final int b = bitmap.ni(); + native_instance = nativeCreate(b, tileX.nativeInt, tileY.nativeInt); + native_shader = nativePostCreate(native_instance, b, tileX.nativeInt, tileY.nativeInt); } private static native int nativeCreate(int native_bitmap, int shaderTileModeX, - int shaderTileModeY); + int shaderTileModeY); + private static native int nativePostCreate(int native_shader, int native_bitmap, + int shaderTileModeX, int shaderTileModeY); } diff --git a/graphics/java/android/graphics/ComposeShader.java b/graphics/java/android/graphics/ComposeShader.java index a06d30b..9b57ea4 100644 --- a/graphics/java/android/graphics/ComposeShader.java +++ b/graphics/java/android/graphics/ComposeShader.java @@ -30,7 +30,9 @@ public class ComposeShader extends Shader { */ public ComposeShader(Shader shaderA, Shader shaderB, Xfermode mode) { native_instance = nativeCreate1(shaderA.native_instance, shaderB.native_instance, - (mode != null) ? mode.native_instance : 0); + (mode != null) ? mode.native_instance : 0); + 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. @@ -42,10 +44,17 @@ public class ComposeShader extends Shader { */ public ComposeShader(Shader shaderA, Shader shaderB, PorterDuff.Mode mode) { native_instance = nativeCreate2(shaderA.native_instance, shaderB.native_instance, - mode.nativeInt); + mode.nativeInt); + native_shader = nativePostCreate2(native_instance, shaderA.native_shader, + shaderB.native_shader, mode.nativeInt); } - private static native int nativeCreate1(int native_shaderA, int native_shaderB, int native_mode); - private static native int nativeCreate2(int native_shaderA, int native_shaderB, int porterDuffMode); + private static native int nativeCreate1(int native_shaderA, int native_shaderB, + int native_mode); + private static native int nativeCreate2(int native_shaderA, int native_shaderB, + int porterDuffMode); + private static native int nativePostCreate1(int native_shader, int native_skiaShaderA, + int native_skiaShaderB, int native_mode); + private static native int nativePostCreate2(int native_shader, int native_skiaShaderA, + int native_skiaShaderB, int porterDuffMode); } - diff --git a/graphics/java/android/graphics/LinearGradient.java b/graphics/java/android/graphics/LinearGradient.java index fd57591..82ed199 100644 --- a/graphics/java/android/graphics/LinearGradient.java +++ b/graphics/java/android/graphics/LinearGradient.java @@ -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); } diff --git a/graphics/java/android/graphics/Shader.java b/graphics/java/android/graphics/Shader.java index 86c71e3..b397662 100644 --- a/graphics/java/android/graphics/Shader.java +++ b/graphics/java/android/graphics/Shader.java @@ -24,18 +24,15 @@ package android.graphics; */ public class Shader { /** - * Local matrix native instance. - * - * @hide - */ - public int mLocalMatrix; - - /** * This is set by subclasses, but don't make it public. * * @hide */ public int native_instance; + /** + * @hide + */ + public int native_shader; public enum TileMode { /** @@ -74,21 +71,20 @@ public class Shader { * @param localM The shader's new local matrix, or null to specify identity */ public void setLocalMatrix(Matrix localM) { - mLocalMatrix = localM != null ? localM.native_instance : 0; - nativeSetLocalMatrix(native_instance, mLocalMatrix); + nativeSetLocalMatrix(native_instance, native_shader, localM.native_instance); } protected void finalize() throws Throwable { try { super.finalize(); } finally { - nativeDestructor(native_instance); + nativeDestructor(native_instance, native_shader); } } - private static native void nativeDestructor(int native_shader); + private static native void nativeDestructor(int native_shader, int native_skiaShader); private static native boolean nativeGetLocalMatrix(int native_shader, - int matrix_instance); + int matrix_instance); private static native void nativeSetLocalMatrix(int native_shader, - int matrix_instance); + int native_skiaShader, int matrix_instance); } |