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
implement drawing into Bitmaps with Canvas, make BitmapDrawable use use paintable, misc Bitmap improvements
This commit is contained in:
55
meson.build
55
meson.build
@@ -54,21 +54,21 @@ viewporter = wl_mod.scan_xml(xml)
|
||||
|
||||
# libandroid
|
||||
libandroid_so = shared_library('android', [
|
||||
'src/libandroid/asset_manager.c',
|
||||
'src/libandroid/bitmap.c',
|
||||
'src/libandroid/configuration.c',
|
||||
'src/libandroid/input.c',
|
||||
'src/libandroid/looper.c',
|
||||
'src/libandroid/media.c',
|
||||
'src/libandroid/native_window.c',
|
||||
'src/libandroid/sensor.c',
|
||||
'src/libandroid/trace.c',
|
||||
],
|
||||
install: true,
|
||||
soversion: 0,
|
||||
dependencies: [
|
||||
dependency('gtk4'), dependency('jni'), dependency('vulkan')
|
||||
])
|
||||
'src/libandroid/asset_manager.c',
|
||||
'src/libandroid/bitmap.c',
|
||||
'src/libandroid/configuration.c',
|
||||
'src/libandroid/input.c',
|
||||
'src/libandroid/looper.c',
|
||||
'src/libandroid/media.c',
|
||||
'src/libandroid/native_window.c',
|
||||
'src/libandroid/sensor.c',
|
||||
'src/libandroid/trace.c',
|
||||
],
|
||||
install: true,
|
||||
soversion: 0,
|
||||
dependencies: [
|
||||
dependency('gtk4'), dependency('jni'), dependency('vulkan')
|
||||
])
|
||||
|
||||
libtranslationlayer_so = shared_library('translation_layer_main', [
|
||||
'src/api-impl-jni/android_app_NativeActivity.c',
|
||||
@@ -97,6 +97,7 @@ libtranslationlayer_so = shared_library('translation_layer_main', [
|
||||
'src/api-impl-jni/graphics/android_graphics_Matrix.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',
|
||||
@@ -130,7 +131,7 @@ libtranslationlayer_so = shared_library('translation_layer_main', [
|
||||
dependencies: [
|
||||
dependency('gtk4', version: '>=4.8'), dependency('gl'), dependency('egl'), dependency('wayland-client'), dependency('jni'),
|
||||
dependency('libportal'), dependency('sqlite3'), libskia_dep, dependency('libavcodec', version: '>=59'), dependency('libdrm'),
|
||||
libandroidfw_dep
|
||||
libandroidfw_dep
|
||||
],
|
||||
link_with: [ libandroid_so ],
|
||||
link_args: [
|
||||
@@ -138,17 +139,17 @@ libtranslationlayer_so = shared_library('translation_layer_main', [
|
||||
])
|
||||
|
||||
executable('android-translation-layer', [
|
||||
'src/main-executable/main.c',
|
||||
'src/main-executable/r_debug.c'
|
||||
],
|
||||
install: true,
|
||||
dependencies: [
|
||||
dependency('gtk4'), dependency('jni'), declare_dependency(link_with: libtranslationlayer_so), libart_dep, dependency('dl'), libdl_bio_dep
|
||||
],
|
||||
link_args: [
|
||||
'-rdynamic'
|
||||
],
|
||||
install_rpath: get_option('prefix') / get_option('libdir') / 'art:' + get_option('prefix') / get_option('libdir') / 'java/dex/android_translation_layer/natives')
|
||||
'src/main-executable/main.c',
|
||||
'src/main-executable/r_debug.c'
|
||||
],
|
||||
install: true,
|
||||
dependencies: [
|
||||
dependency('gtk4'), dependency('jni'), declare_dependency(link_with: libtranslationlayer_so), libart_dep, dependency('dl'), libdl_bio_dep
|
||||
],
|
||||
link_args: [
|
||||
'-rdynamic'
|
||||
],
|
||||
install_rpath: get_option('prefix') / get_option('libdir') / 'art:' + get_option('prefix') / get_option('libdir') / 'java/dex/android_translation_layer/natives')
|
||||
|
||||
# hax_arsc_lib.dex (named as classes2.dex so it works inside a jar)
|
||||
subdir('src/ARSCLib')
|
||||
|
||||
@@ -8,16 +8,8 @@
|
||||
|
||||
#include "generated_headers/android_graphics_Bitmap.h"
|
||||
|
||||
/*
|
||||
* We use a GdkPixbuf as the backing for a bitmap.
|
||||
* We additionally create a view into it as a skia image,
|
||||
* so we can pass it to skia functions.
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1bitmap_1from_1path(JNIEnv *env, jobject this, jobject path)
|
||||
void attach_sk_image(GdkPixbuf *pixbuf)
|
||||
{
|
||||
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(_CSTRING(path), NULL);
|
||||
android_log_printf(ANDROID_LOG_VERBOSE, "["__FILE__"]", ">>> made pixbuf from path: >%s<, >%p<\n", _CSTRING(path), pixbuf);
|
||||
|
||||
sk_imageinfo_t info = {
|
||||
.width = gdk_pixbuf_get_width(pixbuf),
|
||||
.height = gdk_pixbuf_get_height(pixbuf),
|
||||
@@ -34,10 +26,32 @@ JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1bitmap_1from_1path(
|
||||
|
||||
sk_image_t *image = sk_image_new_raster_data(&info, pixels, rowstride);
|
||||
g_object_set_data(G_OBJECT(pixbuf), "sk_image", image);
|
||||
}
|
||||
|
||||
/*
|
||||
* We use a GdkPixbuf as the backing for a bitmap.
|
||||
* We additionally create a view into it as a skia image,
|
||||
* so we can pass it to skia functions.
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1bitmap_1from_1path(JNIEnv *env, jobject this, jobject path)
|
||||
{
|
||||
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(_CSTRING(path), NULL);
|
||||
android_log_printf(ANDROID_LOG_VERBOSE, "["__FILE__"]", ">>> made pixbuf from path: >%s<, >%p<\n", _CSTRING(path), pixbuf);
|
||||
|
||||
attach_sk_image(pixbuf);
|
||||
|
||||
g_object_ref(pixbuf);
|
||||
return _INTPTR(pixbuf);
|
||||
}
|
||||
/* new empty bitmap */
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1create(JNIEnv *env, jclass this, jint width, jint height)
|
||||
{
|
||||
GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, width, height);
|
||||
|
||||
attach_sk_image(pixbuf);
|
||||
|
||||
return _INTPTR(pixbuf);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_getWidth(JNIEnv *env, jobject this)
|
||||
{
|
||||
@@ -59,7 +73,8 @@ JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_getHeight(JNIEnv *env, jobje
|
||||
return gdk_pixbuf_get_height(pixbuf);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeGetPixels(JNIEnv *env, jclass, jlong bitmapHandle, jintArray pixelArray, jint offset, jint stride, jint x, jint y, jint width, jint height, jboolean premultiplied) {
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeGetPixels(JNIEnv *env, jclass, jlong bitmapHandle, jintArray pixelArray, jint offset, jint stride, jint x, jint y, jint width, jint height, jboolean premultiplied)
|
||||
{
|
||||
int i,j;
|
||||
GdkPixbuf *pixbuf = _PTR(bitmapHandle);
|
||||
g_assert(gdk_pixbuf_get_n_channels(pixbuf) == 4);
|
||||
@@ -79,26 +94,41 @@ 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)
|
||||
{
|
||||
GdkPixbuf *pixbuf = _PTR(bitmapHandle);
|
||||
sk_image_t *image = g_object_get_data(G_OBJECT(pixbuf), "sk_image");
|
||||
if(!image) {
|
||||
fprintf(stderr, "pixbuf doesn't have a skia image associated: %p\n", pixbuf);
|
||||
g_object_unref(pixbuf);
|
||||
return true;
|
||||
}
|
||||
sk_image_unref(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);
|
||||
return true;
|
||||
}
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1copy(JNIEnv *env, jclass, jlong src_ptr) {
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1copy(JNIEnv *env, jclass, jlong src_ptr)
|
||||
{
|
||||
GdkPixbuf *src = _PTR(src_ptr);
|
||||
GdkPixbuf *copy = gdk_pixbuf_copy(src);
|
||||
sk_image_t *image = g_object_get_data(G_OBJECT(src), "sk_image");
|
||||
printf("native_copy: dbg: %p\n", image);
|
||||
if(image)
|
||||
g_object_set_data(G_OBJECT(copy), "sk_image", sk_image_make_raster_image(image)); // probably?
|
||||
else
|
||||
fprintf(stderr, "native_copy: pixbuf doesn't have a skia image associated: %p\n", src);
|
||||
return _INTPTR(copy);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_nativeRowBytes(JNIEnv *env, jclass, jlong pixbuf_ptr) {
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1subpixbuf(JNIEnv *env, jclass, jlong _pixbuf, jint x, jint y, jint width, jint height)
|
||||
{
|
||||
GdkPixbuf *pixbuf = _PTR(_pixbuf);
|
||||
GdkPixbuf *subpixbuf = gdk_pixbuf_new_subpixbuf(pixbuf, x, y, width, height);
|
||||
attach_sk_image(subpixbuf);
|
||||
return _INTPTR(subpixbuf);
|
||||
}
|
||||
|
||||
JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_nativeRowBytes(JNIEnv *env, jclass, jlong pixbuf_ptr)
|
||||
{
|
||||
GdkPixbuf *pixbuf = _PTR(pixbuf_ptr);
|
||||
|
||||
return gdk_pixbuf_get_rowstride(pixbuf);
|
||||
|
||||
@@ -10,6 +10,26 @@
|
||||
|
||||
#include "generated_headers/android_graphics_Canvas.h"
|
||||
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Canvas_native_1canvas_1from_1bitmap(JNIEnv *env, jclass this, jlong _pixbuf)
|
||||
{
|
||||
GdkPixbuf *pixbuf = (GdkPixbuf *)_PTR(_pixbuf);
|
||||
|
||||
/* - copied from bitmap (TODO: refactor) - */
|
||||
sk_imageinfo_t info = {
|
||||
.width = gdk_pixbuf_get_width(pixbuf),
|
||||
.height = gdk_pixbuf_get_height(pixbuf),
|
||||
.colorType = RGBA_8888_SK_COLORTYPE, // is this correct?
|
||||
.alphaType = PREMUL_SK_ALPHATYPE,
|
||||
};
|
||||
void *pixbuf_pixels = gdk_pixbuf_get_pixels(pixbuf);
|
||||
int rowstride = gdk_pixbuf_get_rowstride(pixbuf);
|
||||
// size_t pixbuf_size = rowstride * (info.height - 1)
|
||||
// + /* last row: */ info.width * ((gdk_pixbuf_get_n_channels(pixbuf) * gdk_pixbuf_get_bits_per_sample(pixbuf) + 7) / 8);
|
||||
/* --------------------------------------- */
|
||||
|
||||
return _INTPTR(sk_canvas_new_from_raster(&info, pixbuf_pixels, /*pixbuf_size*/rowstride, NULL));
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1save(JNIEnv *env, jclass this, jlong skia_canvas, jlong widget)
|
||||
{
|
||||
sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas);
|
||||
@@ -32,7 +52,10 @@ JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawLine(JNIEnv *env
|
||||
sk_canvas_draw_line(canvas, start_x, start_y, stop_x, stop_y, paint);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawBitmap(JNIEnv *env , jclass this_class, jlong skia_canvas, jlong widget, jlong _pixbuf, jfloat src_x, jfloat src_y, jfloat dest_x , jfloat dest_y, jfloat dest_w , jfloat dest_h, jlong skia_paint)
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawBitmap(JNIEnv *env , jclass this_class, jlong skia_canvas, jlong widget, jlong _pixbuf,
|
||||
jfloat src_left, jfloat src_top, jfloat src_right, jfloat src_bottom,
|
||||
jfloat dst_left, jfloat dst_top, jfloat dst_right, jfloat dst_bottom,
|
||||
jlong skia_paint)
|
||||
{
|
||||
sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas);
|
||||
GdkPixbuf *pixbuf = (GdkPixbuf *)_PTR(_pixbuf);
|
||||
@@ -40,10 +63,11 @@ JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawBitmap(JNIEnv *e
|
||||
|
||||
sk_image_t *image = g_object_get_data(G_OBJECT(pixbuf), "sk_image");
|
||||
if(!image) {
|
||||
fprintf(stderr, "pixbuf doesn't have a skia image associated: %p\n", pixbuf);
|
||||
fprintf(stderr, "drawBitmap: pixbuf doesn't have a skia image associated: %p\n", pixbuf);
|
||||
return;
|
||||
}
|
||||
sk_canvas_draw_image(canvas, image, dest_x, dest_y, paint);
|
||||
sk_canvas_draw_image_rect(canvas, image, &(sk_rect_t){src_left, src_top, src_right, src_bottom},
|
||||
&(sk_rect_t){dst_left, dst_top, dst_right, dst_bottom}, paint);
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawRect(JNIEnv *env, jclass this, jlong skia_canvas, jfloat left, jfloat top, jfloat right, jfloat bottom, jlong skia_paint)
|
||||
|
||||
@@ -11,6 +11,22 @@ extern "C" {
|
||||
#define android_graphics_Bitmap_DENSITY_NONE 0L
|
||||
#undef android_graphics_Bitmap_WORKING_COMPRESS_STORAGE
|
||||
#define android_graphics_Bitmap_WORKING_COMPRESS_STORAGE 4096L
|
||||
/*
|
||||
* Class: android_graphics_Bitmap
|
||||
* Method: getWidth
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_getWidth
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Bitmap
|
||||
* Method: getHeight
|
||||
* Signature: ()I
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_getHeight
|
||||
(JNIEnv *, jobject);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Bitmap
|
||||
* Method: native_bitmap_from_path
|
||||
@@ -29,19 +45,19 @@ JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1copy
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Bitmap
|
||||
* Method: getWidth
|
||||
* Signature: ()I
|
||||
* Method: native_subpixbuf
|
||||
* Signature: (JIIII)J
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_getWidth
|
||||
(JNIEnv *, jobject);
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1subpixbuf
|
||||
(JNIEnv *, jclass, jlong, jint, jint, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Bitmap
|
||||
* Method: getHeight
|
||||
* Signature: ()I
|
||||
* Method: native_create
|
||||
* Signature: (II)J
|
||||
*/
|
||||
JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_getHeight
|
||||
(JNIEnv *, jobject);
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1create
|
||||
(JNIEnv *, jclass, jint, jint);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Bitmap
|
||||
|
||||
@@ -7,6 +7,14 @@
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
/*
|
||||
* Class: android_graphics_Canvas
|
||||
* Method: native_canvas_from_bitmap
|
||||
* Signature: (J)J
|
||||
*/
|
||||
JNIEXPORT jlong JNICALL Java_android_graphics_Canvas_native_1canvas_1from_1bitmap
|
||||
(JNIEnv *, jclass, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Canvas
|
||||
* Method: native_save
|
||||
@@ -50,10 +58,10 @@ JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawLine
|
||||
/*
|
||||
* Class: android_graphics_Canvas
|
||||
* Method: native_drawBitmap
|
||||
* Signature: (JJJFFFFFFJ)V
|
||||
* Signature: (JJJFFFFFFFFJ)V
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawBitmap
|
||||
(JNIEnv *, jclass, jlong, jlong, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jlong);
|
||||
(JNIEnv *, jclass, jlong, jlong, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jlong);
|
||||
|
||||
/*
|
||||
* Class: android_graphics_Canvas
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
/* 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
|
||||
@@ -0,0 +1,11 @@
|
||||
#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));
|
||||
}
|
||||
@@ -141,9 +141,6 @@ public final class Bitmap {
|
||||
this.pixbuf = pixbuf;
|
||||
}
|
||||
|
||||
private native long native_bitmap_from_path(CharSequence path);
|
||||
static native long native_copy(long src);
|
||||
|
||||
/**
|
||||
* Private constructor that must received an already allocated native bitmap
|
||||
* int (pointer).
|
||||
@@ -790,7 +787,7 @@ public final class Bitmap {
|
||||
|
||||
return bitmap;
|
||||
*/
|
||||
return new Bitmap(native_copy(source.pixbuf));
|
||||
return new Bitmap(native_copy(native_subpixbuf(source.pixbuf, x, y, width, height)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -859,7 +856,7 @@ public final class Bitmap {
|
||||
if (width <= 0 || height <= 0) {
|
||||
throw new IllegalArgumentException("width and height must be > 0");
|
||||
}
|
||||
Bitmap bm = nativeCreate(null, 0, width, width, height, config.nativeInt, true);
|
||||
Bitmap bm = new Bitmap(native_create(/*null, 0, width, */width, height/*, config.nativeInt, true*/));
|
||||
if (display != null) {
|
||||
bm.mDensity = display.densityDpi;
|
||||
}
|
||||
@@ -932,8 +929,7 @@ public final class Bitmap {
|
||||
if (width <= 0 || height <= 0) {
|
||||
throw new IllegalArgumentException("width and height must be > 0");
|
||||
}
|
||||
Bitmap bm = nativeCreate(colors, offset, stride, width, height,
|
||||
config.nativeInt, false);
|
||||
Bitmap bm = new Bitmap(native_create(/*colors, offset, stride, */width, height/*, config.nativeInt, false*/));
|
||||
if (display != null) {
|
||||
bm.mDensity = display.densityDpi;
|
||||
}
|
||||
@@ -1600,9 +1596,11 @@ public final class Bitmap {
|
||||
|
||||
//////////// native methods
|
||||
|
||||
private static /*native*/ Bitmap nativeCreate(int[] colors, int offset,
|
||||
int stride, int width, int height,
|
||||
int nativeConfig, boolean mutable) { return new Bitmap(); }
|
||||
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);
|
||||
|
||||
private static native Bitmap nativeCopy(int srcBitmap, int nativeConfig,
|
||||
boolean isMutable);
|
||||
private static native void nativeDestructor(int nativeBitmap);
|
||||
|
||||
@@ -6,7 +6,10 @@ public class Canvas {
|
||||
|
||||
public Canvas() {}
|
||||
|
||||
public Canvas(Bitmap bmp) {}
|
||||
public Canvas(Bitmap bmp) {
|
||||
this.skia_canvas = native_canvas_from_bitmap(bmp.pixbuf);
|
||||
this.widget = 0;
|
||||
}
|
||||
|
||||
public Canvas(long skia_canvas, long widget) {
|
||||
this.skia_canvas = skia_canvas;
|
||||
@@ -23,9 +26,6 @@ public class Canvas {
|
||||
native_restore(skia_canvas, widget);
|
||||
}
|
||||
|
||||
private static native void native_save(long skia_canvas, long widget);
|
||||
private static native void native_restore(long skia_canvas, long widget);
|
||||
|
||||
// ---
|
||||
|
||||
/**
|
||||
@@ -222,10 +222,13 @@ public class Canvas {
|
||||
* @param paint The paint used to draw the bitmap (may be null)
|
||||
*/
|
||||
public void drawBitmap(Bitmap bitmap, float left, float top, Paint paint) {
|
||||
System.out.println("XXXXXXX bitmap(bitmap, left, top, paint)");
|
||||
/*
|
||||
native_drawBitmap(mNativeCanvas, bitmap.ni(), left, top, paint != null ? paint.mNativePaint : 0, mDensity, mScreenDensity, bitmap.mDensity);
|
||||
*/
|
||||
if(skia_canvas == 0) {
|
||||
System.out.println(this + " doesn't have a skia canvas");
|
||||
return;
|
||||
}
|
||||
native_drawBitmap(skia_canvas, widget, bitmap.pixbuf, 0, 0, bitmap.getWidth(), bitmap.getHeight(),
|
||||
left, top, left + bitmap.getWidth(), top + bitmap.getHeight(),
|
||||
(paint != null) ? paint.skia_paint : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -254,7 +257,9 @@ public class Canvas {
|
||||
if (dst == null) {
|
||||
throw new NullPointerException();
|
||||
}
|
||||
native_drawBitmap(skia_canvas, widget, bitmap.pixbuf, src.left, src.top, dst.left, dst.top, dst.width(), dst.height(), (paint != null) ? paint.skia_paint : 0); // FIXME - ignores width/height of source
|
||||
native_drawBitmap(skia_canvas, widget, bitmap.pixbuf, src.left, src.top, src.right, src.bottom,
|
||||
dst.left, dst.top, dst.right, dst.bottom,
|
||||
(paint != null) ? paint.skia_paint : 0);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -385,10 +390,15 @@ public class Canvas {
|
||||
|
||||
public void restoreToCount(int count) {}
|
||||
|
||||
private static native long native_canvas_from_bitmap(long pixbuf);
|
||||
|
||||
private static native void native_save(long skia_canvas, long widget);
|
||||
private static native void native_restore(long skia_canvas, long widget);
|
||||
|
||||
private static native void native_drawText(long skia_canvas, CharSequence text, int start, int end, float x, float y, long skia_font, long skia_paint);
|
||||
private static native void native_drawRect(long skia_canvas, float left, float top, float right, float bottom, long skia_paint);
|
||||
private static native void native_drawLine(long skia_canvas, long widget, float startX, float startY, float stopX, float stopY, long skia_paint);
|
||||
private static native void native_drawBitmap(long skia_canvas, long widget, long pixbuf, float src_x, float src_y, float dest_x, float dest_y, float dest_w, float dest_h, long skia_paint);
|
||||
private static native void native_drawBitmap(long skia_canvas, long widget, long pixbuf, float src_left, float src_top, float src_right, float src_bottom, float dest_left, float dest_top, float dest_right, float dest_bottm, long skia_paint);
|
||||
private static native void native_rotate(long skia_canvas, long widget, float angle);
|
||||
private static native void native_rotate_and_translate(long skia_canvas, long widget, float angle, float tx, float ty);
|
||||
}
|
||||
|
||||
@@ -25,11 +25,7 @@ public class BitmapDrawable extends Drawable {
|
||||
|
||||
public BitmapDrawable(Resources res, Bitmap bitmap) {
|
||||
this.bitmap = bitmap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getWidth()), new RectF(getBounds()), null);
|
||||
this.paintable = native_paintable_from_pixbuf(bitmap.pixbuf);
|
||||
}
|
||||
|
||||
public Bitmap getBitmap() {
|
||||
@@ -45,4 +41,5 @@ public class BitmapDrawable extends Drawable {
|
||||
a.recycle();
|
||||
}
|
||||
|
||||
private static native long native_paintable_from_pixbuf(long pixbuf);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user