diff --git a/src/api-impl-jni/android_graphics_Bitmap.c b/src/api-impl-jni/android_graphics_Bitmap.c index be0c5c3d..ad9aa009 100644 --- a/src/api-impl-jni/android_graphics_Bitmap.c +++ b/src/api-impl-jni/android_graphics_Bitmap.c @@ -158,3 +158,9 @@ JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeCopyPixelsToBuffer(JNI memcpy(pixels, gdk_pixbuf_get_pixels(pixbuf), pixbuf_size); release_nio_buffer(env, array_ref, array); } + +JNIEXPORT void JNICALL Java_android_graphics_Bitmap_native_1unref_1texture(JNIEnv *env, jclass class, jlong texture_ptr) +{ + GdkTexture *texture = GDK_TEXTURE(_PTR(texture_ptr)); + g_object_unref(texture); +} diff --git a/src/api-impl-jni/generated_headers/android_graphics_Bitmap.h b/src/api-impl-jni/generated_headers/android_graphics_Bitmap.h index 3e585156..c7f16fa7 100644 --- a/src/api-impl-jni/generated_headers/android_graphics_Bitmap.h +++ b/src/api-impl-jni/generated_headers/android_graphics_Bitmap.h @@ -67,6 +67,14 @@ JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1create JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1paintable_1from_1pixbuf (JNIEnv *, jclass, jlong); +/* + * Class: android_graphics_Bitmap + * Method: native_unref_texture + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_android_graphics_Bitmap_native_1unref_1texture + (JNIEnv *, jclass, jlong); + /* * Class: android_graphics_Bitmap * Method: nativeCopy diff --git a/src/api-impl/android/graphics/Bitmap.java b/src/api-impl/android/graphics/Bitmap.java index cce03b5f..8452fdde 100644 --- a/src/api-impl/android/graphics/Bitmap.java +++ b/src/api-impl/android/graphics/Bitmap.java @@ -1607,13 +1607,24 @@ public final class Bitmap { return texture; } + /** + * internal ATL method to destroy the cached GdkTexture when the Bitmap was touched + */ + public void destroyTexture() { + if (texture != 0) { + native_unref_texture(texture); + texture = 0; + } + } + //////////// 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 long native_paintable_from_pixbuf(long pixbuf); + private static native void native_unref_texture(long texture); private static native Bitmap nativeCopy(int srcBitmap, int nativeConfig, boolean isMutable); diff --git a/src/api-impl/android/graphics/Canvas.java b/src/api-impl/android/graphics/Canvas.java index 908f1303..793a7cfd 100644 --- a/src/api-impl/android/graphics/Canvas.java +++ b/src/api-impl/android/graphics/Canvas.java @@ -9,6 +9,7 @@ public class Canvas { public Canvas() {} public Canvas(Bitmap bmp) { + bmp.destroyTexture(); // invalidate cached texture this.skia_canvas = native_canvas_from_bitmap(bmp.pixbuf); this.widget = 0; }