GskCanvas.drawBitmap(): reuse GdkTexture objects

This commit is contained in:
Julian Winkler
2024-05-25 23:57:31 +02:00
committed by Mis012
parent 6f02565920
commit e8eabb2027
11 changed files with 44 additions and 49 deletions

View File

@@ -10,11 +10,10 @@
#include "../generated_headers/android_graphics_GskCanvas.h"
JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawBitmap(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jlong pixbuf_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);
GdkPixbuf *pixbuf = (GdkPixbuf *)_PTR(pixbuf_ptr);
GdkTexture *texture = gdk_texture_new_for_pixbuf(pixbuf);
GdkTexture *texture = GDK_TEXTURE(_PTR(texture_ptr));
if (color) { // use only alpha from pixbuf, color is fixed
graphene_matrix_t color_matrix;
graphene_vec4_t color_offset;
@@ -30,7 +29,6 @@ JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawBitmap(JNIEnv
gtk_snapshot_append_texture(snapshot, texture, &GRAPHENE_RECT_INIT(x, y, width, height));
if (color)
gtk_snapshot_pop(snapshot);
g_object_unref(texture);
}
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)

View File

@@ -1,11 +0,0 @@
#include <gtk/gtk.h>
#include "../defines.h"
#include "../util.h"
JNIEXPORT jlong JNICALL Java_android_graphics_drawable_BitmapDrawable_native_1paintable_1from_1pixbuf(JNIEnv *env, jclass this, jlong _pixbuf)
{
GdkPixbuf *pixbuf = (GdkPixbuf *)_PTR(_pixbuf);
return _INTPTR(gdk_texture_new_for_pixbuf(pixbuf));
}

View File

@@ -93,5 +93,6 @@ JNIEXPORT void JNICALL Java_android_graphics_drawable_Drawable_native_1invalidat
JNIEXPORT void JNICALL Java_android_graphics_drawable_Drawable_native_1draw(JNIEnv *env, jobject this, jlong paintable_ptr, jlong snapshot_ptr, jint width, jint height) {
GdkSnapshot *snapshot = (GdkSnapshot *)_PTR(snapshot_ptr);
GdkPaintable *paintable = GDK_PAINTABLE(_PTR(paintable_ptr));
gdk_paintable_snapshot(paintable, snapshot, width, height);
if (!JAVA_IS_PAINTABLE(paintable))
gdk_paintable_snapshot(paintable, snapshot, width, height);
}