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 JNIEXPORT void JNICALL Java_android_graphics_Bitmap_native_1recycle
(JNIEnv *, jclass, jlong, jlong); (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 #ifdef __cplusplus
} }
#endif #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 JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rel_1cubic_1to
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat); (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 * Class: android_graphics_Path
* Method: native_add_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 JNIEXPORT void JNICALL Java_android_graphics_Path_native_1get_1bounds
(JNIEnv *, jclass, jlong, jobject); (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 #ifdef __cplusplus
} }
#endif #endif

View File

@@ -73,3 +73,20 @@ JNIEXPORT void JNICALL Java_android_graphics_Bitmap_native_1recycle(JNIEnv *env,
if (snapshot_ptr) if (snapshot_ptr)
g_object_unref(GTK_SNAPSHOT(_PTR(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); 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 { struct path_foreach_data {
GskPathBuilder *builder; GskPathBuilder *builder;
graphene_matrix_t *matrix; 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) 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)); gsk_path_builder_add_rect(_PTR(builder_ptr), &GRAPHENE_RECT_INIT(left, top, right-left, bottom-top));

View File

@@ -1,5 +1,7 @@
package android.graphics; package android.graphics;
import android.util.DisplayMetrics;
/* /*
* Bitmap is implemented as GdkTexture or GtkSnapshot. It can only be one of the two at a time. * Bitmap is implemented as GdkTexture or GtkSnapshot. It can only be one of the two at a time.
* The methods getTexture() and getSnapshot() automatically convert between the two as needed. * The methods getTexture() and getSnapshot() automatically convert between the two as needed.
@@ -9,12 +11,15 @@ public final class Bitmap {
public enum Config { public enum Config {
RGB_565, RGB_565,
ARGB_8888, ARGB_8888,
ARGB_4444,
ALPHA_8,
} }
private int width; private int width;
private int height; private int height;
private long texture; private long texture;
private long snapshot; private long snapshot;
private Config config = Config.ARGB_8888;
Bitmap(long texture) { Bitmap(long texture) {
this.texture = texture; this.texture = texture;
@@ -22,13 +27,46 @@ public final class Bitmap {
this.height = native_get_height(texture); this.height = native_get_height(texture);
} }
private Bitmap(int width, int height) { private Bitmap(int width, int height, Config config) {
this.config = config;
this.width = width; this.width = width;
this.height = height; this.height = height;
} }
public static Bitmap createBitmap(int width, int height, Config config) { public static Bitmap createBitmap(int width, int height, Config config) {
return new Bitmap(width, height); return new Bitmap(width, height, config);
}
public static Bitmap createBitmap(DisplayMetrics metrics, int width, int height, Config config) {
return new Bitmap(width, height, config);
}
public static Bitmap createBitmap(DisplayMetrics metrics, int width, int height, Config config, boolean hasAlpha, ColorSpace colorSpace) {
return new Bitmap(width, height, config);
}
public static Bitmap createBitmap(Bitmap src, int x, int y, int width, int height) {
Bitmap dest = new Bitmap(width, height, src.getConfig());
new Canvas(dest).drawBitmap(src, new Rect(x, y, x + width, y + height), new Rect(0, 0, width, height), null);
return dest;
}
public static Bitmap createBitmap(Bitmap src, int x, int y, int width, int height, Matrix matrix, boolean filter) {
Bitmap dest = new Bitmap(width, height, src.getConfig());
Canvas canvas = new Canvas(dest);
canvas.concat(matrix);
canvas.drawBitmap(src, new Rect(x, y, x + width, y + height), new Rect(0, 0, width, height), null);
return dest;
}
public static Bitmap createBitmap(Bitmap src) {
return new Bitmap(native_ref_texture(src.getTexture()));
}
public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, boolean filter) {
Bitmap dest = new Bitmap(dstWidth, dstHeight, src.getConfig());
new Canvas(dest).drawBitmap(src, new Rect(0, 0, src.getWidth(), src.getHeight()), new Rect(0, 0, dstWidth, dstHeight), null);
return dest;
} }
public int getWidth() { public int getWidth() {
@@ -39,6 +77,10 @@ public final class Bitmap {
return height; return height;
} }
public Config getConfig() {
return config;
}
public synchronized long getTexture() { public synchronized long getTexture() {
if (texture == 0) { if (texture == 0) {
texture = native_create_texture(snapshot, width, height); texture = native_create_texture(snapshot, width, height);
@@ -75,6 +117,32 @@ public final class Bitmap {
getTexture(); getTexture();
} }
public void setDensity(int density) {}
public int getScaledWidth(int density) {
return width;
}
public int getScaledHeight(int density) {
return height;
}
public boolean isRecycled() {
return texture == 0 && snapshot == 0;
}
public void setHasAlpha(boolean hasAlpha) {}
public Bitmap copy(Bitmap.Config config, boolean hasAlpha) {
Bitmap bitmap = new Bitmap(width, height, config);
bitmap.texture = native_ref_texture(getTexture());
return bitmap;
}
public void getPixels(int[] pixels, int offset, int stride, int x, int y, int width, int height) {
native_get_pixels(getTexture(), pixels, offset, stride, x, y, width, height);
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
@@ -91,4 +159,6 @@ public final class Bitmap {
private static native int native_get_height(long texture); private static native int native_get_height(long texture);
private static native long native_erase_color(int color, int width, int height); private static native long native_erase_color(int color, int width, int height);
private static native void native_recycle(long texture, long snapshot); private static native void native_recycle(long texture, long snapshot);
private static native long native_ref_texture(long texture);
private static native void native_get_pixels(long texture, int[] pixels, int offset, int stride, int x, int y, int width, int height);
} }

View File

@@ -279,13 +279,8 @@ public class Canvas {
* @param paint May be null. The paint used to draw the bitmap * @param paint May be null. The paint used to draw the bitmap
*/ */
public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) { public void drawBitmap(Bitmap bitmap, Rect src, Rect dst, Paint paint) {
System.out.println("XXXXXXX bitmap(bitmap, src, dst, paint)"); gsk_canvas.snapshot = this.bitmap.getSnapshot();
/* gsk_canvas.drawBitmap(bitmap, src, dst, paint);
if (dst == null) {
throw new NullPointerException();
}
native_drawBitmap(mNativeCanvas, bitmap.ni(), src, dst, paint != null ? paint.mNativePaint : 0, mScreenDensity, bitmap.mDensity);
*/
} }
/** /**

View File

@@ -9,6 +9,8 @@ public class Path {
public enum FillType { public enum FillType {
WINDING, WINDING,
EVEN_ODD, EVEN_ODD,
INVERSE_WINDING,
INVERSE_EVEN_ODD,
} }
public enum Direction { public enum Direction {
@@ -17,12 +19,16 @@ public class Path {
} }
public enum Op { public enum Op {
DIFFERENCE,
INTERSECT, INTERSECT,
UNION, UNION,
XOR,
REVERSE_DIFFERENCE,
} }
private long builder; private long builder;
private long path; private long path;
private FillType fillType = FillType.WINDING;
public Path() {} public Path() {}
@@ -60,7 +66,13 @@ public class Path {
native_close(getBuilder()); native_close(getBuilder());
} }
public void setFillType(FillType fillType) {} public void setFillType(FillType fillType) {
this.fillType = fillType;
}
public FillType getFillType() {
return fillType;
}
public void moveTo(float x, float y) { public void moveTo(float x, float y) {
native_move_to(getBuilder(), x, y); native_move_to(getBuilder(), x, y);
@@ -92,10 +104,20 @@ public class Path {
native_rel_cubic_to(getBuilder(), x1, y1, x2, y2, x3, y3); native_rel_cubic_to(getBuilder(), x1, y1, x2, y2, x3, y3);
} }
public void rQuadTo(float x1, float y1, float x2, float y2) {
native_rel_quad_to(getBuilder(), x1, y1, x2, y2);
}
public void addPath(Path path, Matrix matrix) { public void addPath(Path path, Matrix matrix) {
native_add_path(getBuilder(), path.getGskPath(), matrix.ni()); native_add_path(getBuilder(), path.getGskPath(), matrix.ni());
} }
public void addPath(Path path, float deltaX, float deltaY) {
Matrix matrix = new Matrix();
matrix.setTranslate(deltaX, deltaY);
addPath(path, matrix);
}
public void addRect(RectF rect, Direction direction) { public void addRect(RectF rect, Direction direction) {
native_add_rect(getBuilder(), rect.left, rect.top, rect.right, rect.bottom); native_add_rect(getBuilder(), rect.left, rect.top, rect.right, rect.bottom);
} }
@@ -104,7 +126,10 @@ public class Path {
public void addOval(RectF rect, Direction direction) {} public void addOval(RectF rect, Direction direction) {}
public void transform(Matrix matrix) {} public void transform(Matrix matrix) {
builder = native_transform(getGskPath(), matrix.ni());
path = 0;
}
public void computeBounds(RectF bounds, boolean exact) { public void computeBounds(RectF bounds, boolean exact) {
native_get_bounds(getGskPath(), bounds); native_get_bounds(getGskPath(), bounds);
@@ -114,10 +139,20 @@ public class Path {
return false; return false;
} }
public boolean op(Path path, Path dst, Op op) {
return false;
}
public boolean isEmpty() { public boolean isEmpty() {
return path == 0 && builder == 0; return path == 0 && builder == 0;
} }
public void incReserve(int additionalPoints) {}
public boolean isConvex() {
return false;
}
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@Override @Override
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
@@ -140,7 +175,9 @@ public class Path {
private static native void native_rel_move_to(long builder, float x, float y); private static native void native_rel_move_to(long builder, float x, float y);
private static native void native_rel_line_to(long builder, float x, float y); private static native void native_rel_line_to(long builder, float x, float y);
private static native void native_rel_cubic_to(long builder, float x1, float y1, float x2, float y2, float x3, float y3); private static native void native_rel_cubic_to(long builder, float x1, float y1, float x2, float y2, float x3, float y3);
private static native void native_rel_quad_to(long builder, float x1, float y1, float x2, float y2);
private static native void native_add_path(long builder, long path, long matrix); private static native void native_add_path(long builder, long path, long matrix);
private static native void native_add_rect(long builder, float left, float top, float right, float bottom); private static native void native_add_rect(long builder, float left, float top, float right, float bottom);
private static native void native_get_bounds(long path, RectF rect); private static native void native_get_bounds(long path, RectF rect);
private static native long native_transform(long path, long matrix);
} }