drop Skia dependency

Everything is implementede using GTK Scene Graph now. Skia is no longer
needed.
This commit is contained in:
Julian Winkler
2024-12-19 21:11:53 +01:00
parent cd2c69cf73
commit f3bc468a1c
48 changed files with 45 additions and 3219 deletions

View File

@@ -1,101 +0,0 @@
#include <gtk/gtk.h>
#include "defines.h"
#include "util.h"
#include "../sk_area/include/c/sk_font.h"
#include "../sk_area/include/c/sk_paint.h"
#include "../sk_area/include/c/sk_typeface.h"
#include "generated_headers/android_graphics_Paint.h"
JNIEXPORT jlong JNICALL Java_android_graphics_Paint_native_1constructor(JNIEnv *env, jobject this)
{
return _INTPTR(sk_paint_new());
}
JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1antialias(JNIEnv *env, jobject this, jlong skia_paint, jboolean aa)
{
sk_paint_t *paint = (sk_paint_t *)_PTR(skia_paint);
sk_paint_set_antialias(paint, aa);
}
/* NOTE: sk_color_t seems to have the same internal representation as android uses for color, so we just pass that directly */
JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1color(JNIEnv *env, jobject this, jlong skia_paint, jint color)
{
sk_paint_t *paint = (sk_paint_t *)_PTR(skia_paint);
sk_paint_set_color(paint, color);
}
JNIEXPORT jint JNICALL Java_android_graphics_Paint_native_1get_1color(JNIEnv *env, jobject this, jlong skia_paint)
{
sk_paint_t *paint = (sk_paint_t *)_PTR(skia_paint);
return sk_paint_get_color(paint);
}
JNIEXPORT jlong JNICALL Java_android_graphics_Paint_native_1create_1font(JNIEnv *env, jclass this)
{
return _INTPTR(sk_font_new()); /* TODO: recycle this */
}
JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1typeface(JNIEnv *env, jclass this, jlong skia_font, jlong skia_typeface)
{
sk_font_t *font = _PTR(skia_font);
sk_typeface_t *typeface = _PTR(skia_typeface);
sk_font_set_typeface(font, typeface);
}
JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1text_1size(JNIEnv *env, jclass this, jlong skia_font, jfloat size)
{
sk_font_t *font = _PTR(skia_font);
sk_font_set_size(font, size);
}
JNIEXPORT jfloat JNICALL Java_android_graphics_Paint_native_1ascent(JNIEnv *env, jclass this, jlong skia_font)
{
sk_font_t *font = _PTR(skia_font);
sk_fontmetrics_t metrics;
sk_font_get_metrics(font, &metrics);
return metrics.fAscent;
}
JNIEXPORT jfloat JNICALL Java_android_graphics_Paint_native_1measure_1text(JNIEnv *env, jclass this, jlong skia_font, jobject _text, jint start, jint end, jlong skia_paint)
{
sk_font_t *font = _PTR(skia_font);
sk_paint_t *paint = (sk_paint_t *)_PTR(skia_paint);
const char *text = _CSTRING(_text);
return sk_font_measure_text(font, text + start, end - start, UTF8_SK_TEXT_ENCODING, NULL, paint);
}
JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1stroke_1width(JNIEnv *env, jclass this, jlong skia_paint, jfloat width)
{
sk_paint_set_stroke_width(_PTR(skia_paint), width);
}
JNIEXPORT jfloat JNICALL Java_android_graphics_Paint_native_1get_1stroke_1width(JNIEnv *env, jclass this, jlong skia_paint)
{
return sk_paint_get_stroke_width(_PTR(skia_paint));
}
JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1style(JNIEnv *env, jclass this, jlong skia_paint, jint style)
{
sk_paint_set_style(_PTR(skia_paint), (sk_paint_style_t)style);
}
JNIEXPORT void JNICALL Java_android_graphics_Paint_native_1set_1blendmode(JNIEnv *env, jclass this, jlong skia_paint, jint 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

@@ -6,7 +6,7 @@
#include "../defines.h"
#include "../util.h"
#include "../main-executable/back_button.h"
#include "../../main-executable/back_button.h"
#include "android_app_Activity.h"
#include "../generated_headers/android_app_Activity.h"

View File

@@ -28,10 +28,10 @@ JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawRect
/*
* Class: android_graphics_GskCanvas
* Method: native_drawPath
* Signature: (JJJ)V
* Signature: (JJII)V
*/
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawPath
(JNIEnv *, jobject, jlong, jlong, jlong);
(JNIEnv *, jobject, jlong, jlong, jint, jint);
/*
* Class: android_graphics_GskCanvas
@@ -68,18 +68,18 @@ JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1restore
/*
* Class: android_graphics_GskCanvas
* Method: native_drawLine
* Signature: (JFFFFJ)V
* Signature: (JFFFFIF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawLine
(JNIEnv *, jobject, jlong, jfloat, jfloat, jfloat, jfloat, jlong);
(JNIEnv *, jobject, jlong, jfloat, jfloat, jfloat, jfloat, jint, jfloat);
/*
* Class: android_graphics_GskCanvas
* Method: native_drawText
* Signature: (JLjava/lang/String;FFJJ)V
* Signature: (JLjava/lang/String;FFIF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawText
(JNIEnv *, jobject, jlong, jstring, jfloat, jfloat, jlong, jlong);
(JNIEnv *, jobject, jlong, jstring, jfloat, jfloat, jint, jfloat);
/*
* Class: android_graphics_GskCanvas

View File

@@ -1,29 +0,0 @@
/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class android_graphics_Typeface */
#ifndef _Included_android_graphics_Typeface
#define _Included_android_graphics_Typeface
#ifdef __cplusplus
extern "C" {
#endif
#undef android_graphics_Typeface_NORMAL
#define android_graphics_Typeface_NORMAL 0L
#undef android_graphics_Typeface_BOLD
#define android_graphics_Typeface_BOLD 1L
#undef android_graphics_Typeface_ITALIC
#define android_graphics_Typeface_ITALIC 2L
#undef android_graphics_Typeface_BOLD_ITALIC
#define android_graphics_Typeface_BOLD_ITALIC 3L
/*
* Class: android_graphics_Typeface
* Method: native_create
* Signature: (Ljava/lang/CharSequence;I)J
*/
JNIEXPORT jlong JNICALL Java_android_graphics_Typeface_native_1create
(JNIEnv *, jclass, jobject, jint);
#ifdef __cplusplus
}
#endif
#endif

View File

@@ -2,9 +2,6 @@
#include <graphene.h>
#include <pango/pango.h>
#include "include/c/sk_font.h"
#include "include/c/sk_paint.h"
#include "../defines.h"
#include "../generated_headers/android_graphics_GskCanvas.h"
@@ -13,6 +10,12 @@
#define STYLE_STROKE 1
#define STYLE_FILL_AND_STROKE 2
#define GDK_RGBA_INIT(color) ((GdkRGBA){ \
.red = ((color >> 16) & 0xFF) / 255.f, \
.green = ((color >> 8) & 0xFF) / 255.f, \
.blue = ((color >> 0) & 0xFF) / 255.f, \
.alpha = ((color >> 24) & 0xFF) / 255.f})
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);
@@ -37,28 +40,20 @@ JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawBitmap(JNIEnv
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawRect(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jfloat left, jfloat top, jfloat right, jfloat bottom, jint color)
{
GdkSnapshot *snapshot = (GdkSnapshot *)_PTR(snapshot_ptr);
GdkRGBA gdk_color = {
(float)((color >> 16) & 0xff) / 0xff,
(float)((color >> 8) & 0xff) / 0xff,
(float)((color >> 0) & 0xff) / 0xff,
(float)((color >> 24) & 0xff) / 0xff,
};
GdkRGBA gdk_color = GDK_RGBA_INIT(color);
graphene_rect_t bounds = GRAPHENE_RECT_INIT(left, top, right - left, bottom - top);
gtk_snapshot_append_color(snapshot, &gdk_color, &bounds);
}
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawPath(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jlong path_ptr, jlong paint_ptr)
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawPath(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jlong path_ptr, jint color, jint style)
{
GtkSnapshot *snapshot = GTK_SNAPSHOT(_PTR(snapshot_ptr));
GskPath *path = _PTR(path_ptr);
sk_paint_t *paint = (sk_paint_t *)_PTR(paint_ptr);
GdkRGBA gdk_color;
sk_paint_get_color4f(paint, (sk_color4f_t *)&gdk_color);
sk_paint_style_t style = sk_paint_get_style(paint);
if (style == STROKE_SK_PAINT_STYLE || style == STROKE_AND_FILL_SK_PAINT_STYLE) {
GdkRGBA gdk_color = GDK_RGBA_INIT(color);
if (style == STYLE_STROKE || style == STYLE_FILL_AND_STROKE) {
gtk_snapshot_append_stroke(snapshot, path, gsk_stroke_new(2), &gdk_color);
}
if (style == FILL_SK_PAINT_STYLE || style == STROKE_AND_FILL_SK_PAINT_STYLE) {
if (style == STYLE_FILL || style == STYLE_FILL_AND_STROKE) {
gtk_snapshot_append_fill(snapshot, path, GSK_FILL_RULE_WINDING, &gdk_color);
}
}
@@ -87,37 +82,31 @@ JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1restore(JNIEnv *e
gtk_snapshot_restore(snapshot);
}
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawLine(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jfloat x0, jfloat y0, jfloat x1, jfloat y1, jlong paint_ptr)
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawLine(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jfloat x0, jfloat y0, jfloat x1, jfloat y1, jint color, jfloat stroke_width)
{
if (isnan(x0) || isnan(y0) || isnan(x1) || isnan(y1)) {
return;
}
GdkSnapshot *snapshot = GTK_SNAPSHOT(_PTR(snapshot_ptr));
sk_paint_t *paint = (sk_paint_t *)_PTR(paint_ptr);
GdkRGBA gdk_color;
sk_paint_get_color4f(paint, (sk_color4f_t *)&gdk_color);
float width = sk_paint_get_stroke_width(paint);
GdkRGBA gdk_color = GDK_RGBA_INIT(color);
gtk_snapshot_save(snapshot);
gtk_snapshot_translate(snapshot, &GRAPHENE_POINT_INIT(x0, y0));
float rotation = atan2(y1 - y0, x1 - x0);
gtk_snapshot_rotate(snapshot, rotation * 180 / M_PI);
float length = sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
gtk_snapshot_append_color(snapshot, &gdk_color, &GRAPHENE_RECT_INIT(0, -width / 2, length, width));
gtk_snapshot_append_color(snapshot, &gdk_color, &GRAPHENE_RECT_INIT(0, -stroke_width / 2, length, stroke_width));
gtk_snapshot_restore(snapshot);
}
extern GtkWidget *window;
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawText(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jstring text, jfloat x, jfloat y, jlong paint_ptr, jlong font_ptr)
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawText(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jstring text, jfloat x, jfloat y, jint color, jfloat text_size)
{
GdkSnapshot *snapshot = GTK_SNAPSHOT(_PTR(snapshot_ptr));
sk_paint_t *paint = (sk_paint_t *)_PTR(paint_ptr);
sk_font_t *font = (sk_font_t *)_PTR(font_ptr);
GdkRGBA gdk_color;
sk_paint_get_color4f(paint, (sk_color4f_t *)&gdk_color);
GdkRGBA gdk_color = GDK_RGBA_INIT(color);
PangoLayout *layout = pango_layout_new(gtk_widget_get_pango_context(window));
PangoFontDescription *description = pango_font_description_new();
pango_font_description_set_size(description, sk_font_get_size(font) * .8f * PANGO_SCALE);
pango_font_description_set_size(description, text_size * .8f * PANGO_SCALE);
pango_layout_set_font_description(layout, description);
const char *str = (*env)->GetStringUTFChars(env, text, NULL);
pango_layout_set_text(layout, str, -1);

View File

@@ -1,14 +0,0 @@
#include <gtk/gtk.h>
#include "../defines.h"
#include "../util.h"
#include "../../sk_area/include/c/sk_typeface.h"
#include "../generated_headers/android_graphics_Typeface.h"
JNIEXPORT jlong JNICALL Java_android_graphics_Typeface_native_1create(JNIEnv *env, jclass this, jobject _family_name, jint style)
{
/* TODO: use the family name */
return _INTPTR(sk_typeface_create_default()); /* TODO: recycle this */
}