implement Canvas.scale() for skia and GtkSnapshot

This commit is contained in:
Julian Winkler
2024-12-13 23:10:28 +01:00
parent 597c73f334
commit c8ed103516
6 changed files with 40 additions and 3 deletions

View File

@@ -121,3 +121,9 @@ JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1destroy_1canvas(JNIE
sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas); sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas);
sk_canvas_destroy(canvas); sk_canvas_destroy(canvas);
} }
JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1scale(JNIEnv *env, jclass class, jlong skia_canvas, jfloat sx, jfloat sy)
{
sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas);
sk_canvas_scale(canvas, sx, sy);
}

View File

@@ -97,6 +97,14 @@ JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawPath
JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1destroy_1canvas JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1destroy_1canvas
(JNIEnv *, jclass, jlong); (JNIEnv *, jclass, jlong);
/*
* Class: android_graphics_Canvas
* Method: native_scale
* Signature: (JFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1scale
(JNIEnv *, jclass, jlong, jfloat, jfloat);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -89,6 +89,14 @@ JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawText
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawRoundRect JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawRoundRect
(JNIEnv *, jobject, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jint, jfloat, jint); (JNIEnv *, jobject, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jint, jfloat, jint);
/*
* Class: android_graphics_GskCanvas
* Method: native_scale
* Signature: (JFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1scale
(JNIEnv *, jobject, jlong, jfloat, jfloat);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -154,3 +154,9 @@ JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawRoundRect(JNI
gtk_snapshot_append_border(snapshot, &round_rect, widths, gdk_color); gtk_snapshot_append_border(snapshot, &round_rect, widths, gdk_color);
} }
} }
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1scale(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jfloat x, jfloat y)
{
GdkSnapshot *snapshot = GTK_SNAPSHOT(_PTR(snapshot_ptr));
gtk_snapshot_scale(snapshot, x, y);
}

View File

@@ -201,7 +201,9 @@ public class Canvas {
* @param sx The amount to scale in X * @param sx The amount to scale in X
* @param sy The amount to scale in Y * @param sy The amount to scale in Y
*/ */
public /*native*/ void scale(float sx, float sy) {/*used by gd*/} public /*native*/ void scale(float sx, float sy) {
native_scale(skia_canvas, sx, sy);
}
/** /**
* Preconcat the current matrix with the specified scale. * Preconcat the current matrix with the specified scale.
@@ -213,9 +215,9 @@ public class Canvas {
*/ */
public final void scale(float sx, float sy, float px, float py) { public final void scale(float sx, float sy, float px, float py) {
System.out.println("XXXXXXX scale(sx, sy, px, py)"); System.out.println("XXXXXXX scale(sx, sy, px, py)");
/*translate(px, py); translate(px, py);
scale(sx, sy); scale(sx, sy);
translate(-px, -py);*/ translate(-px, -py);
} }
// --- // ---
/** /**
@@ -504,4 +506,5 @@ public class Canvas {
private static native void native_rotate_and_translate(long skia_canvas, long widget, float angle, float tx, float ty); private static native void native_rotate_and_translate(long skia_canvas, long widget, float angle, float tx, float ty);
private static native void native_drawPath(long skia_canvas, long path, long skia_paint); private static native void native_drawPath(long skia_canvas, long path, long skia_paint);
private static native void native_destroy_canvas(long skia_canvas); private static native void native_destroy_canvas(long skia_canvas);
private static native void native_scale(long skia_canvas, float sx, float sy);
} }

View File

@@ -94,6 +94,11 @@ public class GskCanvas extends Canvas {
native_drawRoundRect(snapshot, left, top, right, bottom, rx, ry, paint.getColor(), paint.getStrokeWidth(), paint.getStyle().nativeInt); native_drawRoundRect(snapshot, left, top, right, bottom, rx, ry, paint.getColor(), paint.getStrokeWidth(), paint.getStyle().nativeInt);
} }
@Override
public void scale(float sx, float sy) {
native_scale(snapshot, sx, sy);
}
protected native void native_drawBitmap(long snapshot, long texture, int x, int y, int width, int height, int color); protected native void native_drawBitmap(long snapshot, long texture, int x, int y, int width, int height, int color);
protected native void native_drawRect(long snapshot, float left, float top, float right, float bottom, int color); protected native void native_drawRect(long snapshot, float left, float top, float right, float bottom, int color);
protected native void native_drawPath(long snapshot, long path, long paint); protected native void native_drawPath(long snapshot, long path, long paint);
@@ -104,4 +109,5 @@ public class GskCanvas extends Canvas {
protected native void native_drawLine(long snapshot, float startX, float startY, float stopX, float stopY, long paint); 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, long font); protected native void native_drawText(long snapshot, String text, float x, float y, long paint, long font);
protected native void native_drawRoundRect(long snapshot, float left, float top, float right, float bottom, float rx, float ry, int color, float strokeWidth, int style); protected native void native_drawRoundRect(long snapshot, float left, float top, float right, float bottom, float rx, float ry, int color, float strokeWidth, int style);
protected native void native_scale(long snapshot, float sx, float sy);
} }