Update Shader delegates following Change Ib5d33a80

Test: layoutlib tests
Change-Id: If0db59dd2400ced9019bb999c014d7d655021fd3
This commit is contained in:
Jerome Gaillard
2017-03-10 14:03:05 +00:00
parent 19d1e1d09d
commit afac7771f4
7 changed files with 50 additions and 47 deletions

View File

@@ -75,14 +75,14 @@ public class BitmapShader_Delegate extends Shader_Delegate {
// ---- native methods ----
@LayoutlibDelegate
/*package*/ static long nativeCreate(Bitmap androidBitmap, int shaderTileModeX,
int shaderTileModeY) {
/*package*/ static long nativeCreate(long nativeMatrix, Bitmap androidBitmap,
int shaderTileModeX, int shaderTileModeY) {
Bitmap_Delegate bitmap = Bitmap_Delegate.getDelegate(androidBitmap);
if (bitmap == null) {
return 0;
}
BitmapShader_Delegate newDelegate = new BitmapShader_Delegate(
BitmapShader_Delegate newDelegate = new BitmapShader_Delegate(nativeMatrix,
bitmap.getImage(),
Shader_Delegate.getTileMode(shaderTileModeX),
Shader_Delegate.getTileMode(shaderTileModeY));
@@ -91,8 +91,9 @@ public class BitmapShader_Delegate extends Shader_Delegate {
// ---- Private delegate/helper methods ----
private BitmapShader_Delegate(BufferedImage image,
private BitmapShader_Delegate(long matrix, BufferedImage image,
TileMode tileModeX, TileMode tileModeY) {
super(matrix);
mJavaPaint = new BitmapShaderPaint(image, tileModeX, tileModeY);
}

View File

@@ -63,14 +63,17 @@ public class ComposeShader_Delegate extends Shader_Delegate {
// ---- native methods ----
@LayoutlibDelegate
/*package*/ static long nativeCreate(long native_shaderA, long native_shaderB,
int native_mode) {
/*package*/ static long nativeCreate(long nativeMatrix, long native_shaderA,
long native_shaderB, int native_mode) {
// FIXME not supported yet.
ComposeShader_Delegate newDelegate = new ComposeShader_Delegate();
ComposeShader_Delegate newDelegate = new ComposeShader_Delegate(nativeMatrix);
return sManager.addNewDelegate(newDelegate);
}
// ---- Private delegate/helper methods ----
private ComposeShader_Delegate(long nativeMatrix) {
super(nativeMatrix);
}
}

View File

@@ -41,12 +41,14 @@ public abstract class Gradient_Delegate extends Shader_Delegate {
/**
* Creates the base shader and do some basic test on the parameters.
*
* @param nativeMatrix reference to the shader's native transformation matrix
* @param colors The colors to be distributed along the gradient line
* @param positions May be null. The relative positions [0..1] of each
* corresponding color in the colors array. If this is null, the
* the colors are distributed evenly along the gradient line.
*/
protected Gradient_Delegate(int colors[], float positions[]) {
protected Gradient_Delegate(long nativeMatrix, int colors[], float positions[]) {
super(nativeMatrix);
if (colors.length < 2) {
throw new IllegalArgumentException("needs >= 2 number of colors");
}

View File

@@ -56,21 +56,20 @@ public final class LinearGradient_Delegate extends Gradient_Delegate {
// ---- native methods ----
@LayoutlibDelegate
/*package*/ static long nativeCreate1(LinearGradient thisGradient,
/*package*/ static long nativeCreate1(LinearGradient thisGradient, long matrix,
float x0, float y0, float x1, float y1,
int colors[], float positions[], int tileMode) {
LinearGradient_Delegate newDelegate = new LinearGradient_Delegate(x0, y0, x1, y1,
colors, positions, Shader_Delegate.getTileMode(tileMode));
LinearGradient_Delegate newDelegate = new LinearGradient_Delegate(matrix, x0, y0,
x1, y1, colors, positions, Shader_Delegate.getTileMode(tileMode));
return sManager.addNewDelegate(newDelegate);
}
@LayoutlibDelegate
/*package*/ static long nativeCreate2(LinearGradient thisGradient,
/*package*/ static long nativeCreate2(LinearGradient thisGradient, long matrix,
float x0, float y0, float x1, float y1,
int color0, int color1, int tileMode) {
return nativeCreate1(thisGradient,
x0, y0, x1, y1, new int[] { color0, color1}, null /*positions*/,
tileMode);
return nativeCreate1(thisGradient, matrix, x0, y0, x1, y1, new int[] { color0, color1},
null /*positions*/, tileMode);
}
// ---- Private delegate/helper methods ----
@@ -78,6 +77,7 @@ public final class LinearGradient_Delegate extends Gradient_Delegate {
/**
* Create a shader that draws a linear gradient along a line.
*
* @param nativeMatrix reference to the shader's native transformation matrix
* @param x0 The x-coordinate for the start of the gradient line
* @param y0 The y-coordinate for the start of the gradient line
* @param x1 The x-coordinate for the end of the gradient line
@@ -88,9 +88,9 @@ public final class LinearGradient_Delegate extends Gradient_Delegate {
* the colors are distributed evenly along the gradient line.
* @param tile The Shader tiling mode
*/
private LinearGradient_Delegate(float x0, float y0, float x1, float y1,
int colors[], float positions[], TileMode tile) {
super(colors, positions);
private LinearGradient_Delegate(long nativeMatrix, float x0, float y0, float x1,
float y1, int colors[], float positions[], TileMode tile) {
super(nativeMatrix, colors, positions);
mJavaPaint = new LinearGradientPaint(x0, y0, x1, y1, mColors, mPositions, tile);
}

View File

@@ -56,18 +56,18 @@ public class RadialGradient_Delegate extends Gradient_Delegate {
// ---- native methods ----
@LayoutlibDelegate
/*package*/ static long nativeCreate1(float x, float y, float radius,
/*package*/ static long nativeCreate1(long matrix, float x, float y, float radius,
int colors[], float positions[], int tileMode) {
RadialGradient_Delegate newDelegate = new RadialGradient_Delegate(x, y, radius,
RadialGradient_Delegate newDelegate = new RadialGradient_Delegate(matrix, x, y, radius,
colors, positions, Shader_Delegate.getTileMode(tileMode));
return sManager.addNewDelegate(newDelegate);
}
@LayoutlibDelegate
/*package*/ static long nativeCreate2(float x, float y, float radius,
/*package*/ static long nativeCreate2(long matrix, float x, float y, float radius,
int color0, int color1, int tileMode) {
return nativeCreate1(x, y, radius, new int[] { color0, color1 }, null /*positions*/,
tileMode);
return nativeCreate1(matrix, x, y, radius, new int[] { color0, color1 },
null /*positions*/, tileMode);
}
// ---- Private delegate/helper methods ----
@@ -75,6 +75,7 @@ public class RadialGradient_Delegate extends Gradient_Delegate {
/**
* Create a shader that draws a radial gradient given the center and radius.
*
* @param nativeMatrix reference to the shader's native transformation matrix
* @param x The x-coordinate of the center of the radius
* @param y The y-coordinate of the center of the radius
* @param radius Must be positive. The radius of the circle for this
@@ -86,9 +87,9 @@ public class RadialGradient_Delegate extends Gradient_Delegate {
* distributed evenly between the center and edge of the circle.
* @param tile The Shader tiling mode
*/
private RadialGradient_Delegate(float x, float y, float radius, int colors[], float positions[],
TileMode tile) {
super(colors, positions);
private RadialGradient_Delegate(long nativeMatrix, float x, float y, float radius,
int colors[], float positions[], TileMode tile) {
super(nativeMatrix, colors, positions);
mJavaPaint = new RadialGradientPaint(x, y, radius, mColors, mPositions, tile);
}

View File

@@ -76,24 +76,16 @@ public abstract class Shader_Delegate {
// ---- native methods ----
@LayoutlibDelegate
/*package*/ static void nativeDestructor(long native_shader) {
sManager.removeJavaReferenceFor(native_shader);
}
@LayoutlibDelegate
/*package*/ static long nativeSetLocalMatrix(long native_shader, long matrix_instance) {
// get the delegate from the native int.
Shader_Delegate shaderDelegate = sManager.getDelegate(native_shader);
if (shaderDelegate == null) {
return native_shader;
}
shaderDelegate.mLocalMatrix = Matrix_Delegate.getDelegate(matrix_instance);
return native_shader;
/*package*/ static void nativeSafeUnref(long nativeInstance) {
sManager.removeJavaReferenceFor(nativeInstance);
}
// ---- Private delegate/helper methods ----
protected Shader_Delegate(long nativeMatrix) {
mLocalMatrix = Matrix_Delegate.getDelegate(nativeMatrix);
}
protected java.awt.geom.AffineTransform getLocalMatrix() {
if (mLocalMatrix != null) {
return mLocalMatrix.getAffineTransform();

View File

@@ -52,14 +52,17 @@ public class SweepGradient_Delegate extends Gradient_Delegate {
// ---- native methods ----
@LayoutlibDelegate
/*package*/ static long nativeCreate1(float x, float y, int colors[], float positions[]) {
SweepGradient_Delegate newDelegate = new SweepGradient_Delegate(x, y, colors, positions);
/*package*/ static long nativeCreate1(long matrix, float x, float y, int colors[], float
positions[]) {
SweepGradient_Delegate newDelegate = new SweepGradient_Delegate(matrix, x, y, colors,
positions);
return sManager.addNewDelegate(newDelegate);
}
@LayoutlibDelegate
/*package*/ static long nativeCreate2(float x, float y, int color0, int color1) {
return nativeCreate1(x, y, new int[] { color0, color1 }, null /*positions*/);
/*package*/ static long nativeCreate2(long matrix, float x, float y, int color0, int color1) {
return nativeCreate1(matrix, x, y, new int[] { color0, color1 },
null /*positions*/);
}
// ---- Private delegate/helper methods ----
@@ -67,6 +70,7 @@ public class SweepGradient_Delegate extends Gradient_Delegate {
/**
* A subclass of Shader that draws a sweep gradient around a center point.
*
* @param nativeMatrix reference to the shader's native transformation matrix
* @param cx The x-coordinate of the center
* @param cy The y-coordinate of the center
* @param colors The colors to be distributed between around the center.
@@ -78,9 +82,9 @@ public class SweepGradient_Delegate extends Gradient_Delegate {
* If positions is NULL, then the colors are automatically
* spaced evenly.
*/
private SweepGradient_Delegate(float cx, float cy,
int colors[], float positions[]) {
super(colors, positions);
private SweepGradient_Delegate(long nativeMatrix, float cx, float cy,
int colors[], float positions[]) {
super(nativeMatrix, colors, positions);
mJavaPaint = new SweepGradientPaint(cx, cy, mColors, mPositions);
}