You've already forked android_translation_layer
mirror of
https://gitlab.com/android_translation_layer/android_translation_layer.git
synced 2025-10-27 11:48:10 -07:00
GskCanvas.drawBitmap(): reuse GdkTexture objects
This commit is contained in:
@@ -101,7 +101,6 @@ libtranslationlayer_so = shared_library('translation_layer_main', [
|
||||
'src/api-impl-jni/graphics/android_graphics_Path.c',
|
||||
'src/api-impl-jni/graphics/android_graphics_Typeface.c',
|
||||
'src/api-impl-jni/graphics/android_graphics_Typeface.c',
|
||||
'src/api-impl-jni/graphics/android_graphics_drawable_BitmapDrawable.c',
|
||||
'src/api-impl-jni/graphics/android_graphics_drawable_Drawable.c',
|
||||
'src/api-impl-jni/graphics/android_graphics_drawable_DrawableContainer.c',
|
||||
'src/api-impl-jni/location/android_location_LocationManager.c',
|
||||
|
||||
@@ -99,15 +99,18 @@ JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeGetPixels(JNIEnv *env,
|
||||
(*env)->ReleaseIntArrayElements(env, pixelArray, dst, 0);
|
||||
}
|
||||
|
||||
JNIEXPORT jboolean JNICALL Java_android_graphics_Bitmap_nativeRecycle(JNIEnv *env, jclass, jlong bitmapHandle)
|
||||
JNIEXPORT jboolean JNICALL Java_android_graphics_Bitmap_nativeRecycle(JNIEnv *env, jclass, jlong bitmapHandle, jlong textureHandle)
|
||||
{
|
||||
GdkPixbuf *pixbuf = _PTR(bitmapHandle);
|
||||
GdkTexture *texture = _PTR(textureHandle);
|
||||
sk_image_t *image = g_object_get_data(G_OBJECT(pixbuf), "sk_image");
|
||||
if(image)
|
||||
sk_image_unref(image);
|
||||
else
|
||||
fprintf(stderr, "nativeRecycle: pixbuf doesn't have a skia image associated: %p\n", pixbuf);
|
||||
g_object_unref(pixbuf);
|
||||
if (texture)
|
||||
g_object_unref(texture);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -137,3 +140,9 @@ JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_nativeRowBytes(JNIEnv *env,
|
||||
|
||||
return gdk_pixbuf_get_rowstride(pixbuf);
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1paintable_1from_1pixbuf(JNIEnv *env, jclass, jlong pixbuf_ptr)
|
||||
{
|
||||
GdkPixbuf *pixbuf = _PTR(pixbuf_ptr);
|
||||
return _INTPTR(gdk_texture_new_for_pixbuf(pixbuf));
|
||||
}
|
||||
|
||||
@@ -59,6 +59,14 @@ JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1subpixbuf
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1create
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Bitmap
|
||||
* Method: native_paintable_from_pixbuf
|
||||
* Signature: (J)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1paintable_1from_1pixbuf
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Bitmap
|
||||
* Method: nativeCopy
|
||||
@@ -78,10 +86,10 @@ JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeDestructor
|
||||
/*
|
||||
* Class: android_graphics_Bitmap
|
||||
* Method: nativeRecycle
|
||||
* Signature: (J)Z
|
||||
* Signature: (JJ)Z
|
||||
*/
|
||||
JNIEXPORT jboolean JNICALL Java_android_graphics_Bitmap_nativeRecycle
|
||||
(JNIEnv *, jclass, jlong);
|
||||
(JNIEnv *, jclass, jlong, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Bitmap
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/* DO NOT EDIT THIS FILE - it is machine generated */
|
||||
#include <jni.h>
|
||||
/* Header for class android_graphics_drawable_BitmapDrawable */
|
||||
|
||||
#ifndef _Included_android_graphics_drawable_BitmapDrawable
|
||||
#define _Included_android_graphics_drawable_BitmapDrawable
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: android_graphics_drawable_BitmapDrawable
|
||||
* Method: native_paintable_from_pixbuf
|
||||
* Signature: (J)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_drawable_BitmapDrawable_native_1paintable_1from_1pixbuf
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
@@ -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)
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package android.graphics;
|
||||
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.util.DisplayMetrics;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -102,6 +103,7 @@ public final class Bitmap {
|
||||
}
|
||||
|
||||
public long pixbuf = 0;
|
||||
private long texture = 0;
|
||||
|
||||
Bitmap() {
|
||||
mIsMutable = false;
|
||||
@@ -352,7 +354,7 @@ public final class Bitmap {
|
||||
*/
|
||||
public void recycle() {
|
||||
if (!mRecycled) {
|
||||
if (nativeRecycle(pixbuf)) {
|
||||
if (nativeRecycle(pixbuf, texture)) {
|
||||
// return value indicates whether native pixel object was actually recycled.
|
||||
// false indicates that it is still in use at the native level and these
|
||||
// objects should not be collected now. They will be collected later when the
|
||||
@@ -1594,17 +1596,29 @@ public final class Bitmap {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* internal ATL method to create or get a GdkTexture for the pixbuf
|
||||
* @return pointer to the GdkTexture
|
||||
*/
|
||||
public long getTexture() {
|
||||
if (texture == 0) {
|
||||
texture = native_paintable_from_pixbuf(pixbuf);
|
||||
}
|
||||
return texture;
|
||||
}
|
||||
|
||||
//////////// native methods
|
||||
|
||||
private native long native_bitmap_from_path(CharSequence path);
|
||||
static native long native_copy(long src);
|
||||
static native long native_subpixbuf(long src, int x, int y, int width, int height);
|
||||
private static native long native_create(int width, int height);
|
||||
public static native long native_paintable_from_pixbuf(long pixbuf);
|
||||
|
||||
private static native Bitmap nativeCopy(int srcBitmap, int nativeConfig,
|
||||
boolean isMutable);
|
||||
private static native void nativeDestructor(int nativeBitmap);
|
||||
private static native boolean nativeRecycle(long nativeBitmap);
|
||||
private static native boolean nativeRecycle(long nativeBitmap, long texture);
|
||||
private static native void nativeReconfigure(int nativeBitmap, int width, int height,
|
||||
int config, int allocSize);
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ public class GskCanvas extends Canvas {
|
||||
if (paint != null && paint.colorFilter instanceof PorterDuffColorFilter) {
|
||||
color = ((PorterDuffColorFilter) paint.colorFilter).getColor();
|
||||
}
|
||||
native_drawBitmap(snapshot, bitmap.pixbuf, dst.left, dst.top, dst.width(), dst.height(), color);
|
||||
native_drawBitmap(snapshot, bitmap.getTexture(), dst.left, dst.top, dst.width(), dst.height(), color);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -89,7 +89,7 @@ public class GskCanvas extends Canvas {
|
||||
drawBitmap(bitmap, src, new Rect((int)dst.left, (int)dst.top, (int)dst.right, (int)dst.bottom), paint);
|
||||
}
|
||||
|
||||
protected native void native_drawBitmap(long snapshot, long pixbuf, 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);
|
||||
protected native void native_drawRect(long snapshot, float left, float top, float right, float bottom, int color);
|
||||
protected native void native_drawPath(long snapshot, long path, long paint);
|
||||
protected native void native_translate(long snapshot, float dx, float dy);
|
||||
|
||||
@@ -25,7 +25,7 @@ public class BitmapDrawable extends Drawable {
|
||||
|
||||
public BitmapDrawable(Resources res, Bitmap bitmap) {
|
||||
this.bitmap = bitmap;
|
||||
this.paintable = native_paintable_from_pixbuf(bitmap.pixbuf);
|
||||
this.paintable = bitmap.getTexture();
|
||||
}
|
||||
|
||||
public Bitmap getBitmap() {
|
||||
@@ -40,6 +40,4 @@ public class BitmapDrawable extends Drawable {
|
||||
}
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
static native long native_paintable_from_pixbuf(long pixbuf);
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ public class VectorDrawable extends Drawable {
|
||||
String svg = sb.toString();
|
||||
byte[] bytes = svg.getBytes();
|
||||
Bitmap bm = BitmapFactory.decodeByteArray(bytes, 0, bytes.length);
|
||||
this.paintable = BitmapDrawable.native_paintable_from_pixbuf(bm.pixbuf);
|
||||
this.paintable = bm.getTexture();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user