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:
@@ -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