add back graphics APIs for the previously working applications

This commit is contained in:
Julian Winkler
2024-12-21 10:28:33 +01:00
parent f3bc468a1c
commit ba302d87ec
7 changed files with 180 additions and 11 deletions

View File

@@ -55,6 +55,22 @@ JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1erase_1color
JNIEXPORT void JNICALL Java_android_graphics_Bitmap_native_1recycle
(JNIEnv *, jclass, jlong, jlong);
/*
* Class: android_graphics_Bitmap
* Method: native_ref_texture
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1ref_1texture
(JNIEnv *, jclass, jlong);
/*
* Class: android_graphics_Bitmap
* Method: native_get_pixels
* Signature: (J[IIIIIII)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Bitmap_native_1get_1pixels
(JNIEnv *, jclass, jlong, jintArray, jint, jint, jint, jint, jint, jint);
#ifdef __cplusplus
}
#endif

View File

@@ -103,6 +103,14 @@ JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rel_1line_1to
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rel_1cubic_1to
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Path
* Method: native_rel_quad_to
* Signature: (JFFFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rel_1quad_1to
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Path
* Method: native_add_path
@@ -127,6 +135,14 @@ JNIEXPORT void JNICALL Java_android_graphics_Path_native_1add_1rect
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1get_1bounds
(JNIEnv *, jclass, jlong, jobject);
/*
* Class: android_graphics_Path
* Method: native_transform
* Signature: (JJ)J
*/
JNIEXPORT jlong JNICALL Java_android_graphics_Path_native_1transform
(JNIEnv *, jclass, jlong, jlong);
#ifdef __cplusplus
}
#endif

View File

@@ -73,3 +73,20 @@ JNIEXPORT void JNICALL Java_android_graphics_Bitmap_native_1recycle(JNIEnv *env,
if (snapshot_ptr)
g_object_unref(GTK_SNAPSHOT(_PTR(snapshot_ptr)));
}
JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1ref_1texture(JNIEnv *env, jclass class, jlong texture_ptr)
{
return _INTPTR(g_object_ref(GDK_TEXTURE(_PTR(texture_ptr))));
}
JNIEXPORT void JNICALL Java_android_graphics_Bitmap_native_1get_1pixels(JNIEnv *env, jclass class, jlong texture_ptr, jintArray pixels, jint offset, jint stride, jint x, jint y, jint width, jint height)
{
GdkTexture *texture = GDK_TEXTURE(_PTR(texture_ptr));
if (x != 0 || y != 0 || width != gdk_texture_get_width(texture) || height != gdk_texture_get_height(texture)) {
printf("Bitmap.readPixels: partial read not supported\n");
exit(1);
}
jint *array = (*env)->GetIntArrayElements(env, pixels, NULL);
gdk_texture_download(texture, (guchar *)(array + offset), stride*4);
(*env)->ReleaseIntArrayElements(env, pixels, array, 0);
}

View File

@@ -76,6 +76,11 @@ JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rel_1cubic_1to(JNIEnv
gsk_path_builder_rel_cubic_to(_PTR(builder_ptr), x1, y1, x2, y2, x3, y3);
}
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rel_1quad_1to(JNIEnv *env, jclass this, jlong builder_ptr, jfloat x1, jfloat y1, jfloat x2, jfloat y2)
{
gsk_path_builder_rel_quad_to(_PTR(builder_ptr), x1, y1, x2, y2);
}
struct path_foreach_data {
GskPathBuilder *builder;
graphene_matrix_t *matrix;
@@ -126,6 +131,19 @@ JNIEXPORT void JNICALL Java_android_graphics_Path_native_1add_1path(JNIEnv *env,
}
}
JNIEXPORT jlong JNICALL Java_android_graphics_Path_native_1transform(JNIEnv *env, jclass this, jlong path_ptr, jlong matrix_ptr)
{
GskPath *path = _PTR(path_ptr);
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr);
struct path_foreach_data data = {
.builder = gsk_path_builder_new(),
.matrix = matrix,
};
gsk_path_foreach(path, GSK_PATH_FOREACH_ALLOW_QUAD | GSK_PATH_FOREACH_ALLOW_CUBIC | GSK_PATH_FOREACH_ALLOW_CONIC, path_foreach_transform, &data);
gsk_path_unref(path);
return _INTPTR(data.builder);
}
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1add_1rect(JNIEnv *env, jclass this, jlong builder_ptr, jfloat left, jfloat top, jfloat right, jfloat bottom)
{
gsk_path_builder_add_rect(_PTR(builder_ptr), &GRAPHENE_RECT_INIT(left, top, right-left, bottom-top));