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
Bitmap: implement pixel buffer access
For GPU textures, the GdkTextureDownloader will take care of format conversions, so the application never sees the actual format. If the application calls AndroidBitmap_unlockPixels(), the texture is converted into a GdkMemoryTexture and can be accessed zero copy.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "../defines.h"
|
||||
#include "../util.h"
|
||||
|
||||
#include "../generated_headers/android_graphics_Bitmap.h"
|
||||
|
||||
@@ -90,3 +91,16 @@ JNIEXPORT void JNICALL Java_android_graphics_Bitmap_native_1get_1pixels(JNIEnv *
|
||||
gdk_texture_download(texture, (guchar *)(array + offset), stride*4);
|
||||
(*env)->ReleaseIntArrayElements(env, pixels, array, 0);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Bitmap_native_1copy_1to_1buffer(JNIEnv *env, jclass class, jlong texture_ptr, jobject buffer, jint memory_format, jint stride)
|
||||
{
|
||||
GdkTexture *texture = GDK_TEXTURE(_PTR(texture_ptr));
|
||||
GdkTextureDownloader *downloader = gdk_texture_downloader_new(texture);
|
||||
gdk_texture_downloader_set_format(downloader, memory_format);
|
||||
jarray array_ref;
|
||||
jbyte *array;
|
||||
guchar *data = get_nio_buffer(env, buffer, &array_ref, &array);
|
||||
gdk_texture_downloader_download_into(downloader, data, stride);
|
||||
release_nio_buffer(env, array_ref, array);
|
||||
gdk_texture_downloader_free(downloader);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user