You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
Canvas: add more Bitmap drawing methods
This commit is contained in:
@@ -2,7 +2,11 @@ package android.graphics;
|
||||
|
||||
public class BitmapShader extends Shader {
|
||||
|
||||
public BitmapShader(Bitmap bitmap, TileMode tileX, TileMode tileY) {}
|
||||
Bitmap bitmap;
|
||||
|
||||
public BitmapShader(Bitmap bitmap, TileMode tileX, TileMode tileY) {
|
||||
this.bitmap = bitmap;
|
||||
}
|
||||
|
||||
public void setLocalMatrix(Matrix matrix) {}
|
||||
}
|
||||
|
||||
@@ -356,7 +356,8 @@ public class Canvas {
|
||||
* @param paint May be null. The paint used to draw the bitmap
|
||||
*/
|
||||
public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) {
|
||||
System.out.println("XXXXXXX bitmap(bitmap, matrix, paint)");
|
||||
gsk_canvas.snapshot = this.bitmap.getSnapshot();
|
||||
gsk_canvas.drawBitmap(bitmap, matrix, paint);
|
||||
/* nativeDrawBitmapMatrix(mNativeCanvas, bitmap.ni(), matrix.ni(),
|
||||
paint != null ? paint.mNativePaint : 0);*/
|
||||
}
|
||||
@@ -380,7 +381,7 @@ public class Canvas {
|
||||
|
||||
public void setBitmap(Bitmap bitmap) {
|
||||
this.bitmap = bitmap;
|
||||
gsk_canvas.snapshot = bitmap.getSnapshot();
|
||||
gsk_canvas.snapshot = bitmap == null ? 0 : bitmap.getSnapshot();
|
||||
}
|
||||
|
||||
public void drawPath(Path path, Paint paint) {
|
||||
@@ -394,7 +395,12 @@ public class Canvas {
|
||||
|
||||
public void restoreToCount(int count) {}
|
||||
|
||||
public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) {}
|
||||
public void drawRoundRect(RectF rect, float rx, float ry, Paint paint) {
|
||||
if (paint.getShader() instanceof BitmapShader) {
|
||||
BitmapShader shader = (BitmapShader)paint.getShader();
|
||||
drawBitmap(shader.bitmap, 0, 0, paint);
|
||||
}
|
||||
}
|
||||
|
||||
public void getMatrix(Matrix matrix) {
|
||||
matrix.reset();
|
||||
|
||||
@@ -87,6 +87,15 @@ public class GskCanvas extends Canvas {
|
||||
drawBitmap(bitmap, src, new Rect((int)dst.left, (int)dst.top, (int)dst.right, (int)dst.bottom), paint);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBitmap(Bitmap bitmap, Matrix matrix, Paint paint) {
|
||||
save();
|
||||
concat(matrix);
|
||||
drawBitmap(bitmap, 0, 0, paint);
|
||||
restore();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint) {
|
||||
native_drawRoundRect(snapshot, left, top, right, bottom, rx, ry, paint != null ? paint.paint : default_paint.paint);
|
||||
@@ -97,6 +106,11 @@ public class GskCanvas extends Canvas {
|
||||
native_scale(snapshot, sx, sy);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void concat(Matrix matrix) {
|
||||
native_concat(snapshot, matrix.native_instance);
|
||||
}
|
||||
|
||||
protected native void native_drawBitmap(long snapshot, long texture, int x, int y, int width, int height, long paint);
|
||||
protected native void native_drawRect(long snapshot, float left, float top, float right, float bottom, long paint);
|
||||
protected native void native_drawPath(long snapshot, long path, long paint);
|
||||
@@ -108,4 +122,5 @@ public class GskCanvas extends Canvas {
|
||||
protected native void native_drawText(long snapshot, String text, float x, float y, long paint);
|
||||
protected native void native_drawRoundRect(long snapshot, float left, float top, float right, float bottom, float rx, float ry, long paint);
|
||||
protected native void native_scale(long snapshot, float sx, float sy);
|
||||
protected native void native_concat(long snapshot, long matrix);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ public class Paint {
|
||||
|
||||
long paint; // native paint
|
||||
private Xfermode xfermode;
|
||||
private Shader shader;
|
||||
|
||||
public Paint() {
|
||||
paint = native_create();
|
||||
@@ -100,7 +101,10 @@ public class Paint {
|
||||
return colorFilter;
|
||||
}
|
||||
|
||||
public Shader setShader(Shader shader) { return shader; }
|
||||
public Shader setShader(Shader shader) {
|
||||
this.shader = shader;
|
||||
return shader;
|
||||
}
|
||||
|
||||
public enum Style {
|
||||
/**
|
||||
@@ -268,7 +272,7 @@ public class Paint {
|
||||
public void setTextAlign(Align align) {}
|
||||
|
||||
public Shader getShader() {
|
||||
return new Shader();
|
||||
return shader;
|
||||
}
|
||||
|
||||
public PathEffect getPathEffect() {
|
||||
|
||||
Reference in New Issue
Block a user