GskCanvas: implement RoundedRect filling

This commit is contained in:
Julian Winkler
2024-12-13 22:35:40 +01:00
parent 0e078894ce
commit 597c73f334
6 changed files with 35 additions and 6 deletions

View File

@@ -94,3 +94,8 @@ JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1blendmode(JNIEnv
{ {
sk_paint_set_blendmode(_PTR(skia_paint), (sk_blendmode_t)blendmode); sk_paint_set_blendmode(_PTR(skia_paint), (sk_blendmode_t)blendmode);
} }
JNIEXPORT jint JNICALL Java_android_graphics_Paint_native_1get_1style(JNIEnv *env, jclass this, jlong skia_paint)
{
return sk_paint_get_style(_PTR(skia_paint));
}

View File

@@ -84,10 +84,10 @@ JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawText
/* /*
* Class: android_graphics_GskCanvas * Class: android_graphics_GskCanvas
* Method: native_drawRoundRect * Method: native_drawRoundRect
* Signature: (JFFFFFFIF)V * Signature: (JFFFFFFIFI)V
*/ */
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); (JNIEnv *, jobject, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jint, jfloat, jint);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@@ -137,6 +137,14 @@ JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1style
JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1blendmode JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1blendmode
(JNIEnv *, jclass, jlong, jint); (JNIEnv *, jclass, jlong, jint);
/*
* Class: android_graphics_Paint
* Method: native_get_style
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_android_graphics_Paint_native_1get_1style
(JNIEnv *, jclass, jlong);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@@ -11,6 +11,10 @@
#include "../generated_headers/android_graphics_GskCanvas.h" #include "../generated_headers/android_graphics_GskCanvas.h"
#define STYLE_FILL 0
#define STYLE_STROKE 1
#define STYLE_FILL_AND_STROKE 2
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawBitmap(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jlong texture_ptr, jint x, jint y, jint width, jint height, jint color) JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawBitmap(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jlong texture_ptr, jint x, jint y, jint width, jint height, jint color)
{ {
GdkSnapshot *snapshot = (GdkSnapshot *)_PTR(snapshot_ptr); GdkSnapshot *snapshot = (GdkSnapshot *)_PTR(snapshot_ptr);
@@ -126,7 +130,7 @@ JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawText(JNIEnv *
g_object_unref(description); g_object_unref(description);
} }
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawRoundRect(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jfloat left, jfloat top, jfloat right, jfloat bottom, jfloat rx, jfloat ry, jint color, jfloat width) JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawRoundRect(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jfloat left, jfloat top, jfloat right, jfloat bottom, jfloat rx, jfloat ry, jint color, jfloat width, int style)
{ {
GdkSnapshot *snapshot = (GdkSnapshot *)_PTR(snapshot_ptr); GdkSnapshot *snapshot = (GdkSnapshot *)_PTR(snapshot_ptr);
GdkRGBA gdk_color[4]; GdkRGBA gdk_color[4];
@@ -141,5 +145,12 @@ JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawRoundRect(JNI
.corner = {{rx, ry}, {rx, ry}, {rx, ry}, {rx, ry}}, .corner = {{rx, ry}, {rx, ry}, {rx, ry}, {rx, ry}},
}; };
const float widths[4] = {width, width, width, width}; const float widths[4] = {width, width, width, width};
gtk_snapshot_append_border(snapshot, &round_rect, widths, gdk_color); if (style == STYLE_FILL || style == STYLE_FILL_AND_STROKE) {
gtk_snapshot_push_rounded_clip(snapshot, &round_rect);
gtk_snapshot_append_color(snapshot, gdk_color, &round_rect.bounds);
gtk_snapshot_pop(snapshot);
}
if (style == STYLE_STROKE || style == STYLE_FILL_AND_STROKE) {
gtk_snapshot_append_border(snapshot, &round_rect, widths, gdk_color);
}
} }

View File

@@ -91,7 +91,7 @@ public class GskCanvas extends Canvas {
@Override @Override
public void drawRoundRect(float left, float top, float right, float bottom, float rx, float ry, Paint paint) { 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.getColor(), paint.getStrokeWidth()); native_drawRoundRect(snapshot, left, top, right, bottom, rx, ry, paint.getColor(), paint.getStrokeWidth(), paint.getStyle().nativeInt);
} }
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);
@@ -103,5 +103,5 @@ public class GskCanvas extends Canvas {
protected native void native_restore(long snapshot); protected native void native_restore(long snapshot);
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); 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);
} }

View File

@@ -307,6 +307,10 @@ public class Paint {
public float getLetterSpacing() { return 1.0f; } public float getLetterSpacing() { return 1.0f; }
public Style getStyle() {
return Style.values()[native_get_style(skia_paint)];
}
private native long native_constructor(); private native long native_constructor();
private native void native_set_antialias(long skia_paint, boolean aa); private native void native_set_antialias(long skia_paint, boolean aa);
private native void native_set_color(long skia_paint, int color); private native void native_set_color(long skia_paint, int color);
@@ -320,4 +324,5 @@ public class Paint {
private static native float native_get_stroke_width(long skia_font); private static native float native_get_stroke_width(long skia_font);
private static native void native_set_style(long skia_paint, int style); private static native void native_set_style(long skia_paint, int style);
private static native void native_set_blendmode(long skia_paint, int mode); private static native void native_set_blendmode(long skia_paint, int mode);
private static native int native_get_style(long skia_paint);
} }