2024-03-24 21:01:47 +01:00
|
|
|
package android.graphics;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* GskCanvas:
|
|
|
|
|
* - implements Canvas for onscreen rendering inside GTKs snapshot function
|
|
|
|
|
*/
|
|
|
|
|
public class GskCanvas extends Canvas {
|
|
|
|
|
private long snapshot;
|
2024-04-08 23:15:05 +02:00
|
|
|
private int save_count = 0;
|
2024-03-24 21:01:47 +01:00
|
|
|
|
|
|
|
|
public GskCanvas(long snapshot) {
|
|
|
|
|
this.snapshot = snapshot;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int save() {
|
2024-04-08 23:15:05 +02:00
|
|
|
native_save(snapshot);
|
|
|
|
|
return save_count++;
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void restore() {
|
2024-04-08 23:15:05 +02:00
|
|
|
save_count--;
|
|
|
|
|
native_restore(snapshot);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void restoreToCount(int count) {
|
|
|
|
|
while (save_count > count) {
|
|
|
|
|
restore();
|
|
|
|
|
}
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void translate(float dx, float dy) {
|
2024-04-08 23:15:05 +02:00
|
|
|
native_translate(snapshot, dx, dy);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void rotate(float degrees) {
|
2024-04-08 23:15:05 +02:00
|
|
|
native_rotate(snapshot, degrees);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) {
|
2024-03-24 21:12:13 +01:00
|
|
|
int color = 0;
|
|
|
|
|
if (paint != null && paint.colorFilter instanceof PorterDuffColorFilter) {
|
|
|
|
|
color = ((PorterDuffColorFilter) paint.colorFilter).getColor();
|
|
|
|
|
}
|
|
|
|
|
native_drawBitmap(snapshot, bitmap.pixbuf, dst.left, dst.top, dst.width(), dst.height(), color);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drawPath(Path path, Paint paint) {
|
2024-04-08 23:15:05 +02:00
|
|
|
native_drawPath(snapshot, path.mNativePath, paint.skia_paint);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drawRect(float left, float top, float right, float bottom, Paint paint) {
|
2024-04-07 21:49:40 +02:00
|
|
|
native_drawRect(snapshot, left, top, right, bottom, paint.getColor());
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void rotate(float degrees, float px, float py) {
|
2024-05-25 16:32:01 +02:00
|
|
|
native_translate(snapshot, px, py);
|
|
|
|
|
native_rotate(snapshot, degrees);
|
|
|
|
|
native_translate(snapshot, -px, -py);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drawText(String text, float x, float y, Paint paint) {
|
2024-05-25 16:32:01 +02:00
|
|
|
native_drawText(snapshot, text, x, y, paint.skia_paint);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) {
|
2024-05-25 16:32:01 +02:00
|
|
|
native_drawLine(snapshot, startX, startY, stopX, stopY, paint.skia_paint);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) {
|
|
|
|
|
Rect src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
|
|
|
|
|
Rect dst = new Rect((int)left, (int)top, (int)left + bitmap.getWidth(), (int)top + bitmap.getHeight());
|
|
|
|
|
drawBitmap(bitmap, src, dst, paint);
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-25 16:32:01 +02:00
|
|
|
@Override
|
|
|
|
|
public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) {
|
|
|
|
|
drawBitmap(bitmap, src, new Rect((int)dst.left, (int)dst.top, (int)dst.right, (int)dst.bottom), paint);
|
|
|
|
|
}
|
|
|
|
|
|
2024-03-24 21:12:13 +01:00
|
|
|
protected native void native_drawBitmap(long snapshot, long pixbuf, int x, int y, int width, int height, int color);
|
2024-04-07 21:49:40 +02:00
|
|
|
protected native void native_drawRect(long snapshot, float left, float top, float right, float bottom, int color);
|
2024-04-08 23:15:05 +02:00
|
|
|
protected native void native_drawPath(long snapshot, long path, long paint);
|
|
|
|
|
protected native void native_translate(long snapshot, float dx, float dy);
|
|
|
|
|
protected native void native_rotate(long snapshot, float degrees);
|
|
|
|
|
protected native void native_save(long snapshot);
|
|
|
|
|
protected native void native_restore(long snapshot);
|
2024-05-25 16:32:01 +02:00
|
|
|
protected native void native_drawLine(long snapshot, float startX, float startY, float stopX, float stopY, long paint);
|
|
|
|
|
protected native void native_drawText(long snapshot, String text, float x, float y, long paint);
|
2024-03-24 21:01:47 +01:00
|
|
|
}
|