diff --git a/meson.build b/meson.build index fce6a79b..2e9801d6 100644 --- a/meson.build +++ b/meson.build @@ -84,8 +84,6 @@ libandroid_so = shared_library('android', [ libtranslationlayer_so = shared_library('translation_layer_main', [ 'src/api-impl-jni/android_app_NativeActivity.c', 'src/api-impl-jni/android_content_res_AssetManager.c', - 'src/api-impl-jni/android_graphics_Bitmap.c', - 'src/api-impl-jni/android_graphics_Canvas.c', 'src/api-impl-jni/android_graphics_Paint.c', 'src/api-impl-jni/android_opengl_GLES20.c', 'src/api-impl-jni/android_os_Environment.c', @@ -111,6 +109,7 @@ libtranslationlayer_so = shared_library('translation_layer_main', [ 'src/api-impl-jni/egl/com_google_android_gles_jni_EGLImpl.c', 'src/api-impl-jni/graphics/NinePatchPaintable.c', 'src/api-impl-jni/graphics/NinePatchPaintable.c', + 'src/api-impl-jni/graphics/android_graphics_Bitmap.c', 'src/api-impl-jni/graphics/android_graphics_BitmapFactory.c', 'src/api-impl-jni/graphics/android_graphics_GskCanvas.c', 'src/api-impl-jni/graphics/android_graphics_Matrix.c', @@ -157,7 +156,7 @@ libtranslationlayer_so = shared_library('translation_layer_main', [ install_dir : get_option('libdir') / 'java/dex/android_translation_layer/natives', install_rpath: '$ORIGIN/:' + get_option('prefix') / get_option('libdir') / 'art', dependencies: [ - dependency('gtk4', version: '>=4.8'), dependency('gl'), dependency('egl'), dependency('wayland-client'), dependency('jni'), + dependency('gtk4', version: '>=4.14'), dependency('gl'), dependency('egl'), dependency('wayland-client'), dependency('jni'), dependency('libportal'), dependency('sqlite3'), libskia_dep, dependency('libavcodec', version: '>=59'), dependency('libdrm'), dependency('gudev-1.0'), dependency('libswscale'), dependency('webkitgtk-6.0'), libandroidfw_dep diff --git a/src/api-impl-jni/android_graphics_Bitmap.c b/src/api-impl-jni/android_graphics_Bitmap.c deleted file mode 100644 index 9cc17149..00000000 --- a/src/api-impl-jni/android_graphics_Bitmap.c +++ /dev/null @@ -1,177 +0,0 @@ -#include - -#include "defines.h" -#include "util.h" - -#include "../sk_area/include/c/sk_data.h" -#include "../sk_area/include/c/sk_image.h" - -#include "generated_headers/android_graphics_Bitmap.h" - -void attach_sk_image(GdkPixbuf *pixbuf) -{ - sk_imageinfo_t info = { - .width = gdk_pixbuf_get_width(pixbuf), - .height = gdk_pixbuf_get_height(pixbuf), - .colorType = RGBA_8888_SK_COLORTYPE, - .alphaType = UNPREMUL_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); - /* use the data as-is, and don't ever free it because the pixbuf owns it */ - sk_data_t *pixels = sk_data_new_with_proc(pixbuf_pixels, pixbuf_size, NULL, NULL); - - 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); - if(gdk_pixbuf_get_n_channels(pixbuf) == 3) { // no alpha, add it (skia doesn't support 24bpp) - GdkPixbuf *old_pixbuf = pixbuf; - pixbuf = gdk_pixbuf_add_alpha(pixbuf, false, 0, 0, 0); - g_object_unref(old_pixbuf); - } - - attach_sk_image(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) -{ - GdkPixbuf *pixbuf = _PTR(_GET_LONG_FIELD(this, "pixbuf")); - if (!pixbuf) { - return 10; - } - - return gdk_pixbuf_get_width(pixbuf); -} - -JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_getHeight(JNIEnv *env, jobject this) -{ - GdkPixbuf *pixbuf = _PTR(_GET_LONG_FIELD(this, "pixbuf")); - if (!pixbuf) { - return 10; - } - - 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) -{ - int i,j; - GdkPixbuf *pixbuf = _PTR(bitmapHandle); - g_assert(gdk_pixbuf_get_n_channels(pixbuf) == 4); - g_assert(gdk_pixbuf_get_colorspace(pixbuf) == GDK_COLORSPACE_RGB); - jint *dst = (*env)->GetIntArrayElements(env, pixelArray, NULL); - jint *d = dst + offset; - const guint8 *src = gdk_pixbuf_read_pixels(pixbuf); - int rowstride = gdk_pixbuf_get_rowstride(pixbuf); - src += y * rowstride + x; - for (i=0; iReleaseIntArrayElements(env, pixelArray, dst, 0); -} - -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; -} - -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"); - 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 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); -} - -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)); -} - -JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeCopyPixelsToBuffer(JNIEnv *env, jclass this, jlong _pixbuf, jobject buffer) -{ - GdkPixbuf *pixbuf = _PTR(_pixbuf); - size_t pixbuf_size = gdk_pixbuf_get_rowstride(pixbuf) * (gdk_pixbuf_get_height(pixbuf) - 1) - + /* last row: */ gdk_pixbuf_get_width(pixbuf) * ((gdk_pixbuf_get_n_channels(pixbuf) * gdk_pixbuf_get_bits_per_sample(pixbuf) + 7) / 8); - jarray array_ref; - jbyte *array; - uint8_t *pixels = get_nio_buffer(env, buffer, &array_ref, &array); - memcpy(pixels, gdk_pixbuf_get_pixels(pixbuf), pixbuf_size); - release_nio_buffer(env, array_ref, array); -} - -JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeCopyPixelsFromBuffer(JNIEnv *env, jclass this, jlong _pixbuf, jobject buffer) -{ - GdkPixbuf *pixbuf = _PTR(_pixbuf); - size_t pixbuf_size = gdk_pixbuf_get_rowstride(pixbuf) * (gdk_pixbuf_get_height(pixbuf) - 1) - + /* last row: */ gdk_pixbuf_get_width(pixbuf) * ((gdk_pixbuf_get_n_channels(pixbuf) * gdk_pixbuf_get_bits_per_sample(pixbuf) + 7) / 8); - jarray array_ref; - jbyte *array; - uint8_t *pixels = get_nio_buffer(env, buffer, &array_ref, &array); - memcpy(gdk_pixbuf_get_pixels(pixbuf), pixels, 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/android_graphics_Canvas.c b/src/api-impl-jni/android_graphics_Canvas.c deleted file mode 100644 index 0dc1a9de..00000000 --- a/src/api-impl-jni/android_graphics_Canvas.c +++ /dev/null @@ -1,129 +0,0 @@ -#include - -#include "defines.h" -#include "util.h" - -#include "../sk_area/include/c/sk_canvas.h" -#include "../sk_area/include/c/sk_font.h" -#include "../sk_area/include/c/sk_image.h" -#include "../sk_area/include/c/sk_typeface.h" -#include "../sk_area/include/c/sk_types.h" - -#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); - - sk_canvas_save(canvas); -} - -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1restore(JNIEnv *env, jclass this, jlong skia_canvas, jlong widget) -{ - sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas); - - sk_canvas_restore(canvas); -} - -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawLine(JNIEnv *env, jclass this_class, jlong skia_canvas, jlong widget, jfloat start_x, jfloat start_y, jfloat stop_x, jfloat stop_y, jlong skia_paint) -{ - sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas); - sk_paint_t *paint = (sk_paint_t *)_PTR(skia_paint); - - 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_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); - sk_paint_t *paint = (sk_paint_t *)_PTR(skia_paint); - - sk_image_t *image = g_object_get_data(G_OBJECT(pixbuf), "sk_image"); - if(!image) { - fprintf(stderr, "drawBitmap: pixbuf doesn't have a skia image associated: %p\n", pixbuf); - return; - } - 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) -{ - sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas); - sk_paint_t *paint = (sk_paint_t *)_PTR(skia_paint); - - sk_canvas_draw_rect(canvas, &(sk_rect_t){left, top, right, bottom}, paint); -} - -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawText(JNIEnv *env, jclass this, jlong skia_canvas, jobject _text, jint start, jint end, jfloat x, jfloat y, jlong skia_font, jlong skia_paint) -{ - sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas); - sk_paint_t *paint = (sk_paint_t *)_PTR(skia_paint); - sk_font_t *font = _PTR(skia_font); - - const char *text = _CSTRING(_text); - - sk_canvas_draw_simple_text(canvas, text + start, end - start, UTF8_SK_TEXT_ENCODING, x, y, font, paint); -} - -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1rotate(JNIEnv *env, jclass this, jlong skia_canvas, jlong widget, jfloat angle) -{ - sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas); - - sk_canvas_rotate_degrees(canvas, angle); -} - -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1rotate_1and_1translate(JNIEnv *env, jclass this, jlong skia_canvas, jlong widget, jfloat angle, jfloat tx, jfloat ty) -{ - sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas); - - sk_canvas_translate(canvas, tx, ty); - sk_canvas_rotate_degrees(canvas, angle); - sk_canvas_translate(canvas, -tx, -ty); - -} - -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawPath(JNIEnv *env, jclass class, jlong skia_canvas, jlong path_ptr, jlong skia_paint) -{ - sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas); - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_paint_t *paint = (sk_paint_t *)_PTR(skia_paint); - - sk_canvas_draw_path(canvas, path, paint); -} - -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1destroy_1canvas(JNIEnv *env, jclass class, jlong skia_canvas) -{ - sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas); - sk_canvas_destroy(canvas); -} - -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1scale(JNIEnv *env, jclass class, jlong skia_canvas, jfloat sx, jfloat sy) -{ - sk_canvas_t *canvas = (sk_canvas_t *)_PTR(skia_canvas); - sk_canvas_scale(canvas, sx, sy); -} diff --git a/src/api-impl-jni/app/android_app_WallpaperManager.c b/src/api-impl-jni/app/android_app_WallpaperManager.c index f2f10218..9661b4cb 100644 --- a/src/api-impl-jni/app/android_app_WallpaperManager.c +++ b/src/api-impl-jni/app/android_app_WallpaperManager.c @@ -1,4 +1,4 @@ -#include +#include #include #include "../defines.h" @@ -12,14 +12,14 @@ static void wallpaper_ready_cb(GObject *source, GAsyncResult *res, gpointer user g_object_unref(file); } -JNIEXPORT void JNICALL Java_android_app_WallpaperManager_set_1bitmap(JNIEnv *env, jclass clazz, jlong pixbuf_ptr) +JNIEXPORT void JNICALL Java_android_app_WallpaperManager_set_1bitmap(JNIEnv *env, jclass clazz, jlong texture_ptr) { - GdkPixbuf *pixbuf = _PTR(pixbuf_ptr); + GdkTexture *texture = _PTR(texture_ptr); GFileIOStream *stream; GFile *file = g_file_new_tmp("XXXXXX.png", &stream, NULL); g_io_stream_close(G_IO_STREAM(stream), NULL, NULL); g_object_unref(stream); - gdk_pixbuf_save(pixbuf, g_file_get_path(file), "png", NULL, NULL); + gdk_texture_save_to_png(texture, g_file_get_path(file)); XdpPortal *portal = xdp_portal_new(); xdp_portal_set_wallpaper(portal, NULL, g_file_get_uri(file), XDP_WALLPAPER_FLAG_NONE, NULL, wallpaper_ready_cb, file); g_object_unref(portal); 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 5958ae4c..8851257a 100644 --- a/src/api-impl-jni/generated_headers/android_graphics_Bitmap.h +++ b/src/api-impl-jni/generated_headers/android_graphics_Bitmap.h @@ -7,241 +7,53 @@ #ifdef __cplusplus extern "C" { #endif -#undef android_graphics_Bitmap_DENSITY_NONE -#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 - * Signature: (Ljava/lang/CharSequence;)J - */ -JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1bitmap_1from_1path - (JNIEnv *, jobject, jobject); - -/* - * Class: android_graphics_Bitmap - * Method: native_copy + * Method: native_create_snapshot * Signature: (J)J */ -JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1copy +JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1create_1snapshot (JNIEnv *, jclass, jlong); /* * Class: android_graphics_Bitmap - * Method: native_subpixbuf - * Signature: (JIIII)J + * Method: native_create_texture + * Signature: (JII)J */ -JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1subpixbuf - (JNIEnv *, jclass, jlong, jint, jint, jint, jint); +JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1create_1texture + (JNIEnv *, jclass, jlong, jint, jint); /* * Class: android_graphics_Bitmap - * Method: native_create - * Signature: (II)J - */ -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: 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 - * Signature: (IIZ)Landroid/graphics/Bitmap; - */ -JNIEXPORT jobject JNICALL Java_android_graphics_Bitmap_nativeCopy - (JNIEnv *, jclass, jint, jint, jboolean); - -/* - * Class: android_graphics_Bitmap - * Method: nativeDestructor - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeDestructor - (JNIEnv *, jclass, jint); - -/* - * Class: android_graphics_Bitmap - * Method: nativeRecycle - * Signature: (JJ)Z - */ -JNIEXPORT jboolean JNICALL Java_android_graphics_Bitmap_nativeRecycle - (JNIEnv *, jclass, jlong, jlong); - -/* - * Class: android_graphics_Bitmap - * Method: nativeReconfigure - * Signature: (IIIII)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeReconfigure - (JNIEnv *, jclass, jint, jint, jint, jint, jint); - -/* - * Class: android_graphics_Bitmap - * Method: nativeCompress - * Signature: (IIILjava/io/OutputStream;[B)Z - */ -JNIEXPORT jboolean JNICALL Java_android_graphics_Bitmap_nativeCompress - (JNIEnv *, jclass, jint, jint, jint, jobject, jbyteArray); - -/* - * Class: android_graphics_Bitmap - * Method: nativeErase - * Signature: (II)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeErase - (JNIEnv *, jclass, jint, jint); - -/* - * Class: android_graphics_Bitmap - * Method: nativeRowBytes + * Method: native_get_width * Signature: (J)I */ -JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_nativeRowBytes +JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_native_1get_1width (JNIEnv *, jclass, jlong); /* * Class: android_graphics_Bitmap - * Method: nativeConfig - * Signature: (I)I + * Method: native_get_height + * Signature: (J)I */ -JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_nativeConfig - (JNIEnv *, jclass, jint); +JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_native_1get_1height + (JNIEnv *, jclass, jlong); /* * Class: android_graphics_Bitmap - * Method: nativeGetPixel - * Signature: (IIIZ)I + * Method: native_erase_color + * Signature: (III)J */ -JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_nativeGetPixel - (JNIEnv *, jclass, jint, jint, jint, jboolean); +JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1erase_1color + (JNIEnv *, jclass, jint, jint, jint); /* * Class: android_graphics_Bitmap - * Method: nativeGetPixels - * Signature: (J[IIIIIIIZ)V + * Method: native_recycle + * Signature: (JJ)V */ -JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeGetPixels - (JNIEnv *, jclass, jlong, jintArray, jint, jint, jint, jint, jint, jint, jboolean); - -/* - * Class: android_graphics_Bitmap - * Method: nativeSetPixel - * Signature: (IIIIZ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeSetPixel - (JNIEnv *, jclass, jint, jint, jint, jint, jboolean); - -/* - * Class: android_graphics_Bitmap - * Method: nativeSetPixels - * Signature: (I[IIIIIIIZ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeSetPixels - (JNIEnv *, jclass, jint, jintArray, jint, jint, jint, jint, jint, jint, jboolean); - -/* - * Class: android_graphics_Bitmap - * Method: nativeCopyPixelsToBuffer - * Signature: (JLjava/nio/Buffer;)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeCopyPixelsToBuffer - (JNIEnv *, jclass, jlong, jobject); - -/* - * Class: android_graphics_Bitmap - * Method: nativeCopyPixelsFromBuffer - * Signature: (JLjava/nio/Buffer;)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeCopyPixelsFromBuffer - (JNIEnv *, jclass, jlong, jobject); - -/* - * Class: android_graphics_Bitmap - * Method: nativeGenerationId - * Signature: (I)I - */ -JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_nativeGenerationId - (JNIEnv *, jclass, jint); - -/* - * Class: android_graphics_Bitmap - * Method: nativeExtractAlpha - * Signature: (II[I)Landroid/graphics/Bitmap; - */ -JNIEXPORT jobject JNICALL Java_android_graphics_Bitmap_nativeExtractAlpha - (JNIEnv *, jclass, jint, jint, jintArray); - -/* - * Class: android_graphics_Bitmap - * Method: nativePrepareToDraw - * Signature: (I)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativePrepareToDraw - (JNIEnv *, jclass, jint); - -/* - * Class: android_graphics_Bitmap - * Method: nativeSetAlphaAndPremultiplied - * Signature: (IZZ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeSetAlphaAndPremultiplied - (JNIEnv *, jclass, jint, jboolean, jboolean); - -/* - * Class: android_graphics_Bitmap - * Method: nativeHasMipMap - * Signature: (I)Z - */ -JNIEXPORT jboolean JNICALL Java_android_graphics_Bitmap_nativeHasMipMap - (JNIEnv *, jclass, jint); - -/* - * Class: android_graphics_Bitmap - * Method: nativeSetHasMipMap - * Signature: (IZ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Bitmap_nativeSetHasMipMap - (JNIEnv *, jclass, jint, jboolean); - -/* - * Class: android_graphics_Bitmap - * Method: nativeSameAs - * Signature: (II)Z - */ -JNIEXPORT jboolean JNICALL Java_android_graphics_Bitmap_nativeSameAs - (JNIEnv *, jclass, jint, jint); +JNIEXPORT void JNICALL Java_android_graphics_Bitmap_native_1recycle + (JNIEnv *, jclass, jlong, jlong); #ifdef __cplusplus } diff --git a/src/api-impl-jni/generated_headers/android_graphics_Canvas.h b/src/api-impl-jni/generated_headers/android_graphics_Canvas.h deleted file mode 100644 index 93569114..00000000 --- a/src/api-impl-jni/generated_headers/android_graphics_Canvas.h +++ /dev/null @@ -1,111 +0,0 @@ -/* DO NOT EDIT THIS FILE - it is machine generated */ -#include -/* Header for class android_graphics_Canvas */ - -#ifndef _Included_android_graphics_Canvas -#define _Included_android_graphics_Canvas -#ifdef __cplusplus -extern "C" { -#endif -#undef android_graphics_Canvas_HAS_ALPHA_LAYER_SAVE_FLAG -#define android_graphics_Canvas_HAS_ALPHA_LAYER_SAVE_FLAG 4L -/* - * 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 - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1save - (JNIEnv *, jclass, jlong, jlong); - -/* - * Class: android_graphics_Canvas - * Method: native_restore - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1restore - (JNIEnv *, jclass, jlong, jlong); - -/* - * Class: android_graphics_Canvas - * Method: native_drawText - * Signature: (JLjava/lang/CharSequence;IIFFJJ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawText - (JNIEnv *, jclass, jlong, jobject, jint, jint, jfloat, jfloat, jlong, jlong); - -/* - * Class: android_graphics_Canvas - * Method: native_drawRect - * Signature: (JFFFFJ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawRect - (JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat, jlong); - -/* - * Class: android_graphics_Canvas - * Method: native_drawLine - * Signature: (JJFFFFJ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawLine - (JNIEnv *, jclass, jlong, jlong, jfloat, jfloat, jfloat, jfloat, jlong); - -/* - * Class: android_graphics_Canvas - * Method: native_drawBitmap - * Signature: (JJJFFFFFFFFJ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawBitmap - (JNIEnv *, jclass, jlong, jlong, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jlong); - -/* - * Class: android_graphics_Canvas - * Method: native_rotate - * Signature: (JJF)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1rotate - (JNIEnv *, jclass, jlong, jlong, jfloat); - -/* - * Class: android_graphics_Canvas - * Method: native_rotate_and_translate - * Signature: (JJFFF)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1rotate_1and_1translate - (JNIEnv *, jclass, jlong, jlong, jfloat, jfloat, jfloat); - -/* - * Class: android_graphics_Canvas - * Method: native_drawPath - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1drawPath - (JNIEnv *, jclass, jlong, jlong, jlong); - -/* - * Class: android_graphics_Canvas - * Method: native_destroy_canvas - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1destroy_1canvas - (JNIEnv *, jclass, jlong); - -/* - * Class: android_graphics_Canvas - * Method: native_scale - * Signature: (JFF)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1scale - (JNIEnv *, jclass, jlong, jfloat, jfloat); - -#ifdef __cplusplus -} -#endif -#endif diff --git a/src/api-impl-jni/generated_headers/android_graphics_Path.h b/src/api-impl-jni/generated_headers/android_graphics_Path.h index 79220df4..25f58be4 100644 --- a/src/api-impl-jni/generated_headers/android_graphics_Path.h +++ b/src/api-impl-jni/generated_headers/android_graphics_Path.h @@ -9,164 +9,36 @@ extern "C" { #endif /* * Class: android_graphics_Path - * Method: init1 - * Signature: ()J + * Method: native_create_builder + * Signature: (J)J */ -JNIEXPORT jlong JNICALL Java_android_graphics_Path_init1 - (JNIEnv *, jclass); +JNIEXPORT jlong JNICALL Java_android_graphics_Path_native_1create_1builder + (JNIEnv *, jclass, jlong); /* * Class: android_graphics_Path - * Method: init2 + * Method: native_create_path * Signature: (J)J */ -JNIEXPORT jlong JNICALL Java_android_graphics_Path_init2 +JNIEXPORT jlong JNICALL Java_android_graphics_Path_native_1create_1path + (JNIEnv *, jclass, jlong); + +/* + * Class: android_graphics_Path + * Method: native_ref_path + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_android_graphics_Path_native_1ref_1path (JNIEnv *, jclass, jlong); /* * Class: android_graphics_Path * Method: native_reset - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1reset - (JNIEnv *, jclass, jlong); - -/* - * Class: android_graphics_Path - * Method: native_rewind - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rewind - (JNIEnv *, jclass, jlong); - -/* - * Class: android_graphics_Path - * Method: native_set * Signature: (JJ)V */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1set +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1reset (JNIEnv *, jclass, jlong, jlong); -/* - * Class: android_graphics_Path - * Method: native_getFillType - * Signature: (J)I - */ -JNIEXPORT jint JNICALL Java_android_graphics_Path_native_1getFillType - (JNIEnv *, jclass, jlong); - -/* - * Class: android_graphics_Path - * Method: native_setFillType - * Signature: (JI)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1setFillType - (JNIEnv *, jclass, jlong, jint); - -/* - * Class: android_graphics_Path - * Method: native_isEmpty - * Signature: (J)Z - */ -JNIEXPORT jboolean JNICALL Java_android_graphics_Path_native_1isEmpty - (JNIEnv *, jclass, jlong); - -/* - * Class: android_graphics_Path - * Method: native_isRect - * Signature: (JLandroid/graphics/RectF;)Z - */ -JNIEXPORT jboolean JNICALL Java_android_graphics_Path_native_1isRect - (JNIEnv *, jclass, jlong, jobject); - -/* - * Class: android_graphics_Path - * Method: native_computeBounds - * Signature: (JLandroid/graphics/RectF;)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1computeBounds - (JNIEnv *, jclass, jlong, jobject); - -/* - * Class: android_graphics_Path - * Method: native_incReserve - * Signature: (JI)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1incReserve - (JNIEnv *, jclass, jlong, jint); - -/* - * Class: android_graphics_Path - * Method: native_moveTo - * Signature: (JFF)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1moveTo - (JNIEnv *, jclass, jlong, jfloat, jfloat); - -/* - * Class: android_graphics_Path - * Method: native_rMoveTo - * Signature: (JFF)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rMoveTo - (JNIEnv *, jclass, jlong, jfloat, jfloat); - -/* - * Class: android_graphics_Path - * Method: native_lineTo - * Signature: (JFF)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1lineTo - (JNIEnv *, jclass, jlong, jfloat, jfloat); - -/* - * Class: android_graphics_Path - * Method: native_rLineTo - * Signature: (JFF)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rLineTo - (JNIEnv *, jclass, jlong, jfloat, jfloat); - -/* - * Class: android_graphics_Path - * Method: native_quadTo - * Signature: (JFFFF)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1quadTo - (JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat); - -/* - * Class: android_graphics_Path - * Method: native_rQuadTo - * Signature: (JFFFF)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rQuadTo - (JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat); - -/* - * Class: android_graphics_Path - * Method: native_cubicTo - * Signature: (JFFFFFF)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1cubicTo - (JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat); - -/* - * Class: android_graphics_Path - * Method: native_rCubicTo - * Signature: (JFFFFFF)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rCubicTo - (JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat); - -/* - * Class: android_graphics_Path - * Method: native_arcTo - * Signature: (JLandroid/graphics/RectF;FFZ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1arcTo - (JNIEnv *, jclass, jlong, jobject, jfloat, jfloat, jboolean); - /* * Class: android_graphics_Path * Method: native_close @@ -177,139 +49,83 @@ JNIEXPORT void JNICALL Java_android_graphics_Path_native_1close /* * Class: android_graphics_Path - * Method: native_addRect - * Signature: (JLandroid/graphics/RectF;I)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addRect__JLandroid_graphics_RectF_2I - (JNIEnv *, jclass, jlong, jobject, jint); - -/* - * Class: android_graphics_Path - * Method: native_addRect - * Signature: (JFFFFI)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addRect__JFFFFI - (JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat, jint); - -/* - * Class: android_graphics_Path - * Method: native_addOval - * Signature: (JLandroid/graphics/RectF;I)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addOval - (JNIEnv *, jclass, jlong, jobject, jint); - -/* - * Class: android_graphics_Path - * Method: native_addCircle - * Signature: (JFFFI)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addCircle - (JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jint); - -/* - * Class: android_graphics_Path - * Method: native_addArc - * Signature: (JLandroid/graphics/RectF;FF)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addArc - (JNIEnv *, jclass, jlong, jobject, jfloat, jfloat); - -/* - * Class: android_graphics_Path - * Method: native_addRoundRect - * Signature: (JFFFFFFI)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addRoundRect__JFFFFFFI - (JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat, jint); - -/* - * Class: android_graphics_Path - * Method: native_addRoundRect - * Signature: (JLandroid/graphics/RectF;[FI)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addRoundRect__JLandroid_graphics_RectF_2_3FI - (JNIEnv *, jclass, jlong, jobject, jfloatArray, jint); - -/* - * Class: android_graphics_Path - * Method: native_addPath - * Signature: (JJFF)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__JJFF - (JNIEnv *, jclass, jlong, jlong, jfloat, jfloat); - -/* - * Class: android_graphics_Path - * Method: native_addPath - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__JJ - (JNIEnv *, jclass, jlong, jlong); - -/* - * Class: android_graphics_Path - * Method: native_addPath - * Signature: (JJJ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__JJJ - (JNIEnv *, jclass, jlong, jlong, jlong); - -/* - * Class: android_graphics_Path - * Method: native_offset - * Signature: (JFFJ)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1offset__JFFJ - (JNIEnv *, jclass, jlong, jfloat, jfloat, jlong); - -/* - * Class: android_graphics_Path - * Method: native_offset + * Method: native_move_to * Signature: (JFF)V */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1offset__JFF +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1move_1to (JNIEnv *, jclass, jlong, jfloat, jfloat); /* * Class: android_graphics_Path - * Method: native_setLastPoint + * Method: native_line_to * Signature: (JFF)V */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1setLastPoint +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1line_1to (JNIEnv *, jclass, jlong, jfloat, jfloat); /* * Class: android_graphics_Path - * Method: native_transform + * Method: native_cubic_to + * Signature: (JFFFFFF)V + */ +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1cubic_1to + (JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat); + +/* + * Class: android_graphics_Path + * Method: native_quad_to + * Signature: (JFFFF)V + */ +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1quad_1to + (JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat); + +/* + * Class: android_graphics_Path + * Method: native_rel_move_to + * Signature: (JFF)V + */ +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rel_1move_1to + (JNIEnv *, jclass, jlong, jfloat, jfloat); + +/* + * Class: android_graphics_Path + * Method: native_rel_line_to + * Signature: (JFF)V + */ +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rel_1line_1to + (JNIEnv *, jclass, jlong, jfloat, jfloat); + +/* + * Class: android_graphics_Path + * Method: native_rel_cubic_to + * Signature: (JFFFFFF)V + */ +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rel_1cubic_1to + (JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat); + +/* + * Class: android_graphics_Path + * Method: native_add_path * Signature: (JJJ)V */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1transform__JJJ +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1add_1path (JNIEnv *, jclass, jlong, jlong, jlong); /* * Class: android_graphics_Path - * Method: native_transform - * Signature: (JJ)V + * Method: native_add_rect + * Signature: (JFFFF)V */ -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1transform__JJ - (JNIEnv *, jclass, jlong, jlong); +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1add_1rect + (JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat); /* * Class: android_graphics_Path - * Method: native_op - * Signature: (JJIJ)Z + * Method: native_get_bounds + * Signature: (JLandroid/graphics/RectF;)V */ -JNIEXPORT jboolean JNICALL Java_android_graphics_Path_native_1op - (JNIEnv *, jclass, jlong, jlong, jint, jlong); - -/* - * Class: android_graphics_Path - * Method: finalizer - * Signature: (J)V - */ -JNIEXPORT void JNICALL Java_android_graphics_Path_finalizer - (JNIEnv *, jclass, jlong); +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1get_1bounds + (JNIEnv *, jclass, jlong, jobject); #ifdef __cplusplus } diff --git a/src/api-impl-jni/generated_headers/android_widget_ImageButton.h b/src/api-impl-jni/generated_headers/android_widget_ImageButton.h index 8deb4bf9..028fc666 100644 --- a/src/api-impl-jni/generated_headers/android_widget_ImageButton.h +++ b/src/api-impl-jni/generated_headers/android_widget_ImageButton.h @@ -207,14 +207,6 @@ extern "C" { JNIEXPORT jlong JNICALL Java_android_widget_ImageButton_native_1constructor (JNIEnv *, jobject, jobject, jobject); -/* - * Class: android_widget_ImageButton - * Method: native_setPixbuf - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setPixbuf - (JNIEnv *, jobject, jlong, jlong); - /* * Class: android_widget_ImageButton * Method: native_setDrawable diff --git a/src/api-impl-jni/generated_headers/android_widget_ImageView.h b/src/api-impl-jni/generated_headers/android_widget_ImageView.h index 63ae70d6..2d6f42c3 100644 --- a/src/api-impl-jni/generated_headers/android_widget_ImageView.h +++ b/src/api-impl-jni/generated_headers/android_widget_ImageView.h @@ -207,14 +207,6 @@ extern "C" { JNIEXPORT jlong JNICALL Java_android_widget_ImageView_native_1constructor (JNIEnv *, jobject, jobject, jobject); -/* - * Class: android_widget_ImageView - * Method: native_setPixbuf - * Signature: (JJ)V - */ -JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setPixbuf - (JNIEnv *, jobject, jlong, jlong); - /* * Class: android_widget_ImageView * Method: native_setDrawable diff --git a/src/api-impl-jni/graphics/android_graphics_Bitmap.c b/src/api-impl-jni/graphics/android_graphics_Bitmap.c new file mode 100644 index 00000000..69b85357 --- /dev/null +++ b/src/api-impl-jni/graphics/android_graphics_Bitmap.c @@ -0,0 +1,75 @@ +#include + +#include "../defines.h" + +#include "../generated_headers/android_graphics_Bitmap.h" + +JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1create_1snapshot(JNIEnv *env, jclass class, jlong texture_ptr) +{ + GtkSnapshot *snapshot = gtk_snapshot_new(); + if (texture_ptr) { + GdkTexture *texture = GDK_TEXTURE(_PTR(texture_ptr)); + gtk_snapshot_append_texture(snapshot, texture, &GRAPHENE_RECT_INIT(0, 0, gdk_texture_get_width(texture), gdk_texture_get_height(texture))); + g_object_unref(texture); + } + return _INTPTR(snapshot); +} + +JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1create_1texture(JNIEnv *env, jclass class, jlong snapshot_ptr, jint width, jint height) +{ + GtkSnapshot *snapshot = _PTR(snapshot_ptr); + static GType renderer_type = 0; + if (!renderer_type) { + // Use same renderer type as for onscreen rendering. + GdkSurface *surface = gdk_surface_new_toplevel(gdk_display_get_default()); + GskRenderer *renderer = gsk_renderer_new_for_surface(surface); + renderer_type = G_OBJECT_TYPE(renderer); + gsk_renderer_unrealize(renderer); + g_object_unref(renderer); + gdk_surface_destroy(surface); + } + GskRenderer *renderer = g_object_new(renderer_type, NULL); + gsk_renderer_realize(renderer, NULL, NULL); + GskRenderNode *node = snapshot ? gtk_snapshot_free_to_node(snapshot) : NULL; + graphene_rect_t bounds = GRAPHENE_RECT_INIT(0, 0, width, height); + if (!node) + node = gsk_color_node_new(&(GdkRGBA){.alpha = 0}, &bounds); + GdkTexture *texture = gsk_renderer_render_texture(renderer, node, &bounds); + gsk_render_node_unref(node); + gsk_renderer_unrealize(renderer); + g_object_unref(renderer); + + return _INTPTR(texture); +} + +JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_native_1get_1width(JNIEnv *env, jclass class, jlong texture_ptr) +{ + return gdk_texture_get_width(GDK_TEXTURE(_PTR(texture_ptr))); +} + +JNIEXPORT jint JNICALL Java_android_graphics_Bitmap_native_1get_1height(JNIEnv *env, jclass class, jlong texture_ptr) +{ + return gdk_texture_get_height(GDK_TEXTURE(_PTR(texture_ptr))); +} + +JNIEXPORT jlong JNICALL Java_android_graphics_Bitmap_native_1erase_1color(JNIEnv *env, jclass class, jint color, jint width, jint height) +{ + GdkRGBA rgba = { + .red = ((color >> 16) & 0xFF) / 255.f, + .green = ((color >> 8) & 0xFF) / 255.f, + .blue = ((color >> 0) & 0xFF) / 255.f, + .alpha = ((color >> 24) & 0xFF) / 255.f, + }; + graphene_rect_t bounds = GRAPHENE_RECT_INIT(0, 0, width, height); + GtkSnapshot *snapshot = gtk_snapshot_new(); + gtk_snapshot_append_color(snapshot, &rgba, &bounds); + return _INTPTR(snapshot); +} + +JNIEXPORT void JNICALL Java_android_graphics_Bitmap_native_1recycle(JNIEnv *env, jclass class, jlong texture_ptr, jlong snapshot_ptr) +{ + if (texture_ptr) + g_object_unref(GDK_TEXTURE(_PTR(texture_ptr))); + if (snapshot_ptr) + g_object_unref(GTK_SNAPSHOT(_PTR(snapshot_ptr))); +} diff --git a/src/api-impl-jni/graphics/android_graphics_BitmapFactory.c b/src/api-impl-jni/graphics/android_graphics_BitmapFactory.c index 17c10313..1fe88e09 100644 --- a/src/api-impl-jni/graphics/android_graphics_BitmapFactory.c +++ b/src/api-impl-jni/graphics/android_graphics_BitmapFactory.c @@ -56,5 +56,7 @@ JNIEXPORT jlong JNICALL Java_android_graphics_BitmapFactory_nativeDecodeStream(J GdkPixbuf *pixbuf = gdk_pixbuf_new_from_stream(stream, NULL, NULL); g_object_unref(stream); - return _INTPTR(pixbuf); + GdkTexture *texture = gdk_texture_new_for_pixbuf(pixbuf); + g_object_unref(pixbuf); + return _INTPTR(texture); } diff --git a/src/api-impl-jni/graphics/android_graphics_GskCanvas.c b/src/api-impl-jni/graphics/android_graphics_GskCanvas.c index 662328db..51b3c19c 100644 --- a/src/api-impl-jni/graphics/android_graphics_GskCanvas.c +++ b/src/api-impl-jni/graphics/android_graphics_GskCanvas.c @@ -4,10 +4,8 @@ #include "include/c/sk_font.h" #include "include/c/sk_paint.h" -#include "include/c/sk_path.h" #include "../defines.h" -#include "../util.h" #include "../generated_headers/android_graphics_GskCanvas.h" @@ -51,17 +49,18 @@ JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawRect(JNIEnv * JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1drawPath(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jlong path_ptr, jlong paint_ptr) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_iterator_t *iterator = sk_path_create_iter(path, 0); - sk_path_verb_t verb; - sk_point_t line[4]; - while ((verb = sk_path_iter_next(iterator, line)) != DONE_SK_PATH_VERB) { - // TODO: use GskPath to support other verbs - if (verb == LINE_SK_PATH_VERB) { - Java_android_graphics_GskCanvas_native_1drawLine(env, this_class, snapshot_ptr, line[0].x, line[0].y, line[1].x, line[1].y, paint_ptr); - } + GtkSnapshot *snapshot = GTK_SNAPSHOT(_PTR(snapshot_ptr)); + GskPath *path = _PTR(path_ptr); + sk_paint_t *paint = (sk_paint_t *)_PTR(paint_ptr); + GdkRGBA gdk_color; + sk_paint_get_color4f(paint, (sk_color4f_t *)&gdk_color); + sk_paint_style_t style = sk_paint_get_style(paint); + if (style == STROKE_SK_PAINT_STYLE || style == STROKE_AND_FILL_SK_PAINT_STYLE) { + gtk_snapshot_append_stroke(snapshot, path, gsk_stroke_new(2), &gdk_color); + } + if (style == FILL_SK_PAINT_STYLE || style == STROKE_AND_FILL_SK_PAINT_STYLE) { + gtk_snapshot_append_fill(snapshot, path, GSK_FILL_RULE_WINDING, &gdk_color); } - sk_path_iter_destroy(iterator); } JNIEXPORT void JNICALL Java_android_graphics_GskCanvas_native_1translate(JNIEnv *env, jclass this_class, jlong snapshot_ptr, jfloat dx, jfloat dy) diff --git a/src/api-impl-jni/graphics/android_graphics_Path.c b/src/api-impl-jni/graphics/android_graphics_Path.c index 90c0dec7..2b266b0f 100644 --- a/src/api-impl-jni/graphics/android_graphics_Path.c +++ b/src/api-impl-jni/graphics/android_graphics_Path.c @@ -1,216 +1,142 @@ -#include "../sk_area/include/c/sk_path.h" -#include +#include #include "../defines.h" -#include "../util.h" #include "../generated_headers/android_graphics_Path.h" -#include "include/c/sk_types.h" -JNIEXPORT jlong JNICALL Java_android_graphics_Path_init1(JNIEnv *env, jclass class) +JNIEXPORT jlong JNICALL Java_android_graphics_Path_native_1create_1builder(JNIEnv *env, jclass this, jlong path_ptr) { - return _INTPTR(sk_path_new()); + GskPathBuilder *builder = gsk_path_builder_new(); + if (path_ptr) { + GskPath *path = _PTR(path_ptr); + gsk_path_builder_add_path(builder, path); + gsk_path_unref(path); + } + return _INTPTR(builder); } -JNIEXPORT jlong JNICALL Java_android_graphics_Path_init2(JNIEnv *env, jclass class, jlong path_ptr) +JNIEXPORT jlong JNICALL Java_android_graphics_Path_native_1create_1path(JNIEnv *env, jclass this, jlong builder_ptr) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - return _INTPTR(sk_path_clone(path)); + GskPathBuilder *builder = _PTR(builder_ptr); + if (!builder) + builder = gsk_path_builder_new(); + return _INTPTR(gsk_path_builder_free_to_path(builder)); } -JNIEXPORT void JNICALL Java_android_graphics_Path_finalizer(JNIEnv *env, jclass class, jlong path_ptr) +JNIEXPORT jlong JNICALL Java_android_graphics_Path_native_1ref_1path(JNIEnv *env, jclass this, jlong path_ptr) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - if (path_ptr != -1) - sk_path_delete(path); + return _INTPTR(gsk_path_ref(_PTR(path_ptr))); } -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rCubicTo(JNIEnv *env, jclass class, jlong path_ptr, jfloat x1, jfloat y1, jfloat x2, jfloat y2, jfloat x3, jfloat y3) +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1reset(JNIEnv *env, jclass this, jlong path_ptr, jlong builder_ptr) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_rcubic_to(path, x1, y1, x2, y2, x3, y3); + if (path_ptr) + gsk_path_unref(_PTR(path_ptr)); + if (builder_ptr) + gsk_path_builder_unref(_PTR(builder_ptr)); } -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rLineTo(JNIEnv *env, jclass class, jlong path_ptr, jfloat x, jfloat y) +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1close(JNIEnv *env, jclass this, jlong builder_ptr) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_rline_to(path, x, y); + gsk_path_builder_close(_PTR(builder_ptr)); } -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1cubicTo(JNIEnv *env, jclass class, jlong path_ptr, jfloat x1, jfloat y1, jfloat x2, jfloat y2, jfloat x3, jfloat y3) +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1move_1to(JNIEnv *env, jclass this, jlong builder_ptr, jfloat x, jfloat y) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_cubic_to(path, x1, y1, x2, y2, x3, y3); + gsk_path_builder_move_to(_PTR(builder_ptr), x, y); } -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__JJJ(JNIEnv *env, jclass class, jlong path_ptr, jlong src_ptr, jlong matrix) +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1line_1to(JNIEnv *env, jclass this, jlong builder_ptr, jfloat x, jfloat y) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_t *src = (sk_path_t *)_PTR(src_ptr); - sk_path_add_path(path, src, APPEND_SK_PATH_ADD_MODE); + gsk_path_builder_line_to(_PTR(builder_ptr), x, y); } -JNIEXPORT jint JNICALL Java_android_graphics_Path_native_1getFillType(JNIEnv *env, jclass class, jlong path_ptr) +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1cubic_1to(JNIEnv *env, jclass this, jlong builder_ptr, jfloat x1, jfloat y1, jfloat x2, jfloat y2, jfloat x3, jfloat y3) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - return sk_path_get_filltype(path); + gsk_path_builder_cubic_to(_PTR(builder_ptr), x1, y1, x2, y2, x3, y3); } -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1reset(JNIEnv *env, jclass class, jlong path_ptr) +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1quad_1to(JNIEnv *env, jclass this, jlong builder_ptr, jfloat x1, jfloat y1, jfloat x2, jfloat y2) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_reset(path); + gsk_path_builder_quad_to(_PTR(builder_ptr), x1, y1, x2, y2); } -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1setFillType(JNIEnv *env, jclass class, jlong path_ptr, jint ft) +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rel_1move_1to(JNIEnv *env, jclass this, jlong builder_ptr, jfloat x, jfloat y) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_set_filltype(path, ft); + gsk_path_builder_rel_move_to(_PTR(builder_ptr), x, y); } -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1moveTo(JNIEnv *env, jclass class, jlong path_ptr, jfloat x, jfloat y) +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rel_1line_1to(JNIEnv *env, jclass this, jlong builder_ptr, jfloat x, jfloat y) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_move_to(path, x, y); + gsk_path_builder_rel_line_to(_PTR(builder_ptr), x, y); } -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1close(JNIEnv *env, jclass class, jlong path_ptr) +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rel_1cubic_1to(JNIEnv *env, jclass this, jlong builder_ptr, jfloat x1, jfloat y1, jfloat x2, jfloat y2, jfloat x3, jfloat y3) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_close(path); + gsk_path_builder_rel_cubic_to(_PTR(builder_ptr), x1, y1, x2, y2, x3, y3); } -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1lineTo(JNIEnv *env, jclass class, jlong path_ptr, jfloat x, jfloat y) +struct path_foreach_data { + GskPathBuilder *builder; + graphene_matrix_t *matrix; + graphene_point_t tmp_pts[4]; +}; +static gboolean path_foreach_transform(GskPathOperation op, const graphene_point_t* pts, gsize n_pts, float weight, gpointer user_data) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_line_to(path, x, y); + struct path_foreach_data *data = user_data; + for (gsize i = 0; i < n_pts; i++) { + graphene_matrix_transform_point(data->matrix, &pts[i], &data->tmp_pts[i]); + } + switch (op) { + case GSK_PATH_MOVE: + gsk_path_builder_move_to(data->builder, data->tmp_pts[0].x, data->tmp_pts[0].y); + break; + case GSK_PATH_CLOSE: + gsk_path_builder_close(data->builder); + break; + case GSK_PATH_LINE: + gsk_path_builder_line_to(data->builder, data->tmp_pts[1].x, data->tmp_pts[1].y); + break; + case GSK_PATH_QUAD: + gsk_path_builder_quad_to(data->builder, data->tmp_pts[1].x, data->tmp_pts[1].y, data->tmp_pts[2].x, data->tmp_pts[2].y); + break; + case GSK_PATH_CUBIC: + gsk_path_builder_cubic_to(data->builder, data->tmp_pts[1].x, data->tmp_pts[1].y, data->tmp_pts[2].x, data->tmp_pts[2].y, data->tmp_pts[3].x, data->tmp_pts[3].y); + break; + case GSK_PATH_CONIC: + gsk_path_builder_conic_to(data->builder, data->tmp_pts[1].x, data->tmp_pts[1].y, data->tmp_pts[2].x, data->tmp_pts[2].y, weight); + break; + } + return TRUE; } -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rewind(JNIEnv *env, jclass class, jlong path_ptr) +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1add_1path(JNIEnv *env, jclass this, jlong builder_ptr, jlong path_ptr, jlong matrix_ptr) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_rewind(path); -} - -JNIEXPORT jboolean JNICALL Java_android_graphics_Path_native_1isEmpty(JNIEnv *env, jclass class, jlong path_ptr) -{ - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - return !sk_path_count_points(path) && !sk_path_count_verbs(path); -} - -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1computeBounds(JNIEnv *env, jclass class, jlong path_ptr, jobject rect) -{ - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_rect_t bounds; - sk_path_get_bounds(path, &bounds); - _SET_FLOAT_FIELD(rect, "left", bounds.left); - _SET_FLOAT_FIELD(rect, "top", bounds.top); - _SET_FLOAT_FIELD(rect, "right", bounds.right); - _SET_FLOAT_FIELD(rect, "bottom", bounds.bottom); -} - -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1arcTo(JNIEnv *env, jclass class, jlong path_ptr, jobject oval, jfloat startAngle, jfloat sweepAngle, jboolean forceMoveTo) -{ - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - float left = _GET_FLOAT_FIELD(oval, "left"); - float top = _GET_FLOAT_FIELD(oval, "top"); - float right = _GET_FLOAT_FIELD(oval, "right"); - float bottom = _GET_FLOAT_FIELD(oval, "bottom"); - sk_path_arc_to_with_oval(path, &(sk_rect_t){left, top, right, bottom}, startAngle, sweepAngle, forceMoveTo); -} - -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addRect__JLandroid_graphics_RectF_2I(JNIEnv *env, jclass class, jlong path_ptr, jobject rect, jint dir) -{ - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - float left = _GET_FLOAT_FIELD(rect, "left"); - float top = _GET_FLOAT_FIELD(rect, "top"); - float right = _GET_FLOAT_FIELD(rect, "right"); - float bottom = _GET_FLOAT_FIELD(rect, "bottom"); - sk_path_add_rect(path, &(sk_rect_t){left, top, right, bottom}, (sk_path_direction_t)dir); -} - -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1transform__JJ(JNIEnv *env, jclass class, jlong path_ptr, jlong matrix_ptr) -{ - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); + GskPathBuilder *builder = _PTR(builder_ptr); + GskPath *path = _PTR(path_ptr); graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr); - float v[16]; - graphene_matrix_to_float(matrix, v); - sk_matrix_t m = {v[0], v[4], v[12], - v[1], v[5], v[13], - v[3], v[7], v[15]}; - sk_path_transform(path, &m); + if (graphene_matrix_is_identity(matrix)) { + gsk_path_builder_add_path(builder, path); + } else { + struct path_foreach_data data = { + .builder = builder, + .matrix = matrix, + }; + gsk_path_foreach(path, GSK_PATH_FOREACH_ALLOW_QUAD | GSK_PATH_FOREACH_ALLOW_CUBIC | GSK_PATH_FOREACH_ALLOW_CONIC, path_foreach_transform, &data); + } } -JNIEXPORT jboolean JNICALL Java_android_graphics_Path_native_1op(JNIEnv *env, jclass class, jlong path_ptr, jlong other_ptr, jint op, jlong result_ptr) +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1add_1rect(JNIEnv *env, jclass this, jlong builder_ptr, jfloat left, jfloat top, jfloat right, jfloat bottom) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_t *other = (sk_path_t *)_PTR(other_ptr); - sk_path_t *result = (sk_path_t *)_PTR(result_ptr); - return sk_pathop_op(path, other, (sk_pathop_t)op, result); + gsk_path_builder_add_rect(_PTR(builder_ptr), &GRAPHENE_RECT_INIT(left, top, right-left, bottom-top)); } -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1quadTo(JNIEnv *env, jclass class, jlong path_ptr, jfloat x1, jfloat y1, jfloat x2, jfloat y2) +JNIEXPORT void JNICALL Java_android_graphics_Path_native_1get_1bounds(JNIEnv *env, jclass this, jlong path_ptr, jobject bounds) { - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_quad_to(path, x1, y1, x2, y2); -} - -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rQuadTo(JNIEnv *env, jclass class, jlong path_ptr, jfloat dx1, jfloat dy1, jfloat dx2, jfloat dy2) -{ - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_rquad_to(path, dx1, dy1, dx2, dy2); -} - -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rMoveTo(JNIEnv *env, jclass class, jlong path_ptr, jfloat dx, jfloat dy) -{ - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_rmove_to(path, dx, dy); -} - -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addRoundRect__JFFFFFFI(JNIEnv *env, jclass class, jlong path_ptr, jfloat left, jfloat top, jfloat right, jfloat bottom, jfloat rx, jfloat ry, jint dir) -{ - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_add_rounded_rect(path, &(sk_rect_t){left, top, right, bottom}, rx, ry, (sk_path_direction_t)dir); -} - -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addRoundRect__JLandroid_graphics_RectF_2_3FI(JNIEnv *env, jclass class, jlong path_ptr, jobject rect, jfloatArray radii, jint dir) -{ - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - float left = _GET_FLOAT_FIELD(rect, "left"); - float top = _GET_FLOAT_FIELD(rect, "top"); - float right = _GET_FLOAT_FIELD(rect, "right"); - float bottom = _GET_FLOAT_FIELD(rect, "bottom"); - jfloat *radii_array = (*env)->GetFloatArrayElements(env, radii, 0); - sk_path_add_rounded_rect(path, &(sk_rect_t){left, top, right, bottom}, radii_array[0], radii_array[1], (sk_path_direction_t)dir); - (*env)->ReleaseFloatArrayElements(env, radii, radii_array, 0); -} - -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addOval(JNIEnv *env, jclass class, jlong path_ptr, jobject rect, jint dir) -{ - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - float left = _GET_FLOAT_FIELD(rect, "left"); - float top = _GET_FLOAT_FIELD(rect, "top"); - float right = _GET_FLOAT_FIELD(rect, "right"); - float bottom = _GET_FLOAT_FIELD(rect, "bottom"); - sk_path_add_oval(path, &(sk_rect_t){left, top, right, bottom}, (sk_path_direction_t)dir); -} - -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addCircle(JNIEnv *env, jclass class, jlong path_ptr, jfloat x, jfloat y, jfloat radius, jint dir) -{ - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_add_circle(path, x, y, radius, (sk_path_direction_t)dir); -} - -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__JJ(JNIEnv *env, jclass class, jlong path_ptr, jlong src_ptr) -{ - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_t *src = (sk_path_t *)_PTR(src_ptr); - sk_path_add_path(path, src, APPEND_SK_PATH_ADD_MODE); -} - -JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__JJFF(JNIEnv *env, jclass class, jlong path_ptr, jlong src_ptr, jfloat dx, jfloat dy) -{ - sk_path_t *path = (sk_path_t *)_PTR(path_ptr); - sk_path_t *src = (sk_path_t *)_PTR(src_ptr); - sk_path_add_path_offset(path, src, dx, dy, APPEND_SK_PATH_ADD_MODE); + graphene_rect_t rect; + gsk_path_get_bounds(_PTR(path_ptr), &rect); + _SET_FLOAT_FIELD(bounds, "left", rect.origin.x); + _SET_FLOAT_FIELD(bounds, "top", rect.origin.y); + _SET_FLOAT_FIELD(bounds, "right", rect.origin.x + rect.size.width); + _SET_FLOAT_FIELD(bounds, "bottom", rect.origin.y + rect.size.height); } diff --git a/src/api-impl-jni/util.c b/src/api-impl-jni/util.c index 26aa6718..f008c942 100644 --- a/src/api-impl-jni/util.c +++ b/src/api-impl-jni/util.c @@ -99,9 +99,6 @@ void set_up_handle_cache(JNIEnv *env) handle_cache.sensor_event.class = _REF((*env)->FindClass(env, "android/hardware/SensorEvent")); handle_cache.sensor_event.constructor = _METHOD(handle_cache.sensor_event.class, "", "([FLandroid/hardware/Sensor;)V"); - handle_cache.canvas.class = _REF((*env)->FindClass(env, "android/graphics/Canvas")); - handle_cache.canvas.constructor = _METHOD(handle_cache.canvas.class, "", "(JJ)V"); - handle_cache.audio_track_periodic_listener.class = _REF((*env)->FindClass(env, "android/media/AudioTrack$OnPlaybackPositionUpdateListener")); handle_cache.audio_track_periodic_listener.onPeriodicNotification = _METHOD(handle_cache.audio_track_periodic_listener.class, "onPeriodicNotification", "(Landroid/media/AudioTrack;)V"); diff --git a/src/api-impl-jni/util.h b/src/api-impl-jni/util.h index d34bd40c..a57d21cd 100644 --- a/src/api-impl-jni/util.h +++ b/src/api-impl-jni/util.h @@ -44,10 +44,6 @@ struct handle_cache { jclass class; jmethodID constructor; } sensor_event; - struct { - jclass class; - jmethodID constructor; - } canvas; struct { jclass class; jmethodID onPeriodicNotification; diff --git a/src/api-impl-jni/widgets/android_widget_ImageButton.c b/src/api-impl-jni/widgets/android_widget_ImageButton.c index f246e501..2e585844 100644 --- a/src/api-impl-jni/widgets/android_widget_ImageButton.c +++ b/src/api-impl-jni/widgets/android_widget_ImageButton.c @@ -20,12 +20,6 @@ JNIEXPORT jlong JNICALL Java_android_widget_ImageButton_native_1constructor(JNIE return _INTPTR(button); } -JNIEXPORT void JNICALL Java_android_widget_ImageButton_native_1setPixbuf(JNIEnv *env, jobject this, jlong widget_ptr, jlong pixbuf_ptr) -{ - GdkPaintable *paintable = GDK_PAINTABLE(gdk_texture_new_for_pixbuf(_PTR(pixbuf_ptr))); - Java_android_widget_ImageButton_native_1setDrawable(env, this, widget_ptr, _INTPTR(paintable)); -} - static void clicked_cb(GtkWidget *button, gpointer user_data) { printf("clicked_cb\n"); JNIEnv *env = get_jni_env(); diff --git a/src/api-impl-jni/widgets/android_widget_ImageView.c b/src/api-impl-jni/widgets/android_widget_ImageView.c index 701d89c5..9df8aa53 100644 --- a/src/api-impl-jni/widgets/android_widget_ImageView.c +++ b/src/api-impl-jni/widgets/android_widget_ImageView.c @@ -25,12 +25,6 @@ JNIEXPORT jlong JNICALL Java_android_widget_ImageView_native_1constructor(JNIEnv return _INTPTR(image); } -JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setPixbuf(JNIEnv *env, jobject this, jlong widget_ptr, jlong pixbuf_ptr) -{ - GdkPaintable *paintable = GDK_PAINTABLE(gdk_texture_new_for_pixbuf(_PTR(pixbuf_ptr))); - Java_android_widget_ImageView_native_1setDrawable(env, this, widget_ptr, _INTPTR(paintable)); -} - JNIEXPORT void JNICALL Java_android_widget_ImageView_native_1setDrawable(JNIEnv *env, jobject this, jlong widget_ptr, jlong paintable_ptr) { GtkPicture *picture = _PTR(widget_ptr); diff --git a/src/api-impl/android/app/WallpaperManager.java b/src/api-impl/android/app/WallpaperManager.java index a8abbef6..249228a0 100644 --- a/src/api-impl/android/app/WallpaperManager.java +++ b/src/api-impl/android/app/WallpaperManager.java @@ -10,9 +10,9 @@ public class WallpaperManager { } public void setBitmap(Bitmap bitmap) { - set_bitmap(bitmap.pixbuf); + set_bitmap(bitmap.getTexture()); } - private static native void set_bitmap(long pixbuf); + private static native void set_bitmap(long texture); } diff --git a/src/api-impl/android/graphics/Bitmap.java b/src/api-impl/android/graphics/Bitmap.java index e376ccb1..7954cdda 100644 --- a/src/api-impl/android/graphics/Bitmap.java +++ b/src/api-impl/android/graphics/Bitmap.java @@ -1,1693 +1,94 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - package android.graphics; -import android.graphics.drawable.BitmapDrawable; -import android.util.DisplayMetrics; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.nio.Buffer; -import java.nio.ByteBuffer; -import java.nio.IntBuffer; -import java.nio.ShortBuffer; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; - +/* + * Bitmap is implemented as GdkTexture or GtkSnapshot. It can only be one of the two at a time. + * The methods getTexture() and getSnapshot() automatically convert between the two as needed. + */ public final class Bitmap { - /** - * Indicates that the bitmap was created for an unknown pixel density. - * - * @see Bitmap#getDensity() - * @see Bitmap#setDensity(int) - */ - public static final int DENSITY_NONE = 0; - /** - * Note: mNativeBitmap is used by FaceDetector_jni.cpp - * Don't change/rename without updating FaceDetector_jni.cpp - * - * @hide - */ - public final int mNativeBitmap = 0; - - /** - * Backing buffer for the Bitmap. - * Made public for quick access from drawing methods -- do NOT modify - * from outside this class - * - * @hide - */ - @SuppressWarnings("UnusedDeclaration") // native code only - public byte[] mBuffer; - - @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"}) // Keep to finalize native resources - private final BitmapFinalizer mFinalizer; - - private final boolean mIsMutable; - - /** - * Represents whether the Bitmap's content is expected to be pre-multiplied. - * Note that isPremultiplied() does not directly return this value, because - * isPremultiplied() may never return true for a 565 Bitmap. - * - * setPremultiplied() does directly set the value so that setConfig() and - * setPremultiplied() aren't order dependent, despite being setters. - */ - private boolean mIsPremultiplied; - - private byte[] mNinePatchChunk; // may be null - private int[] mLayoutBounds; // may be null - private int mWidth = 10; - private int mHeight = 10; - private boolean mRecycled; - - // Package-scoped for fast access. - int mDensity = getDefaultDensity(); - - private static volatile Matrix sScaleMatrix; - - private static volatile int sDefaultDensity = -1; - - /** - * For backwards compatibility, allows the app layer to change the default - * density when running old apps. - * @hide - */ - public static void setDefaultDensity(int density) { - sDefaultDensity = density; - } - - static int getDefaultDensity() { - if (sDefaultDensity >= 0) { - return sDefaultDensity; - } - // noinspection deprecation - sDefaultDensity = DisplayMetrics.DENSITY_DEVICE; - return sDefaultDensity; - } - - public long pixbuf = 0; - private long texture = 0; - - Bitmap() { - mIsMutable = false; - mIsPremultiplied = false; - mBuffer = null; - - mFinalizer = null; - - mNinePatchChunk = null; - mLayoutBounds = null; - } // FIXME - - Bitmap(String path) { - Path file = Paths.get(android.os.Environment.getExternalStorageDirectory().getPath(), path); - if (!Files.exists(file)) { - try (InputStream inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream(path)) { - if (inputStream != null) { - Files.createDirectories(file.getParent()); - Files.copy(inputStream, file); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - pixbuf = native_bitmap_from_path(file.toString()); - - mIsMutable = false; - mIsPremultiplied = false; - mBuffer = null; - mFinalizer = null; - mNinePatchChunk = null; - mLayoutBounds = null; - } - - Bitmap(long pixbuf) { - this(); - this.pixbuf = pixbuf; - } - - /** - * Private constructor that must received an already allocated native bitmap - * int (pointer). - */ - @SuppressWarnings({"UnusedDeclaration"}) // called from JNI - Bitmap(int nativeBitmap, byte[] buffer, int width, int height, int density, - boolean isMutable, boolean isPremultiplied, - byte[] ninePatchChunk, int[] layoutBounds) { /* - if (nativeBitmap == 0) { - throw new RuntimeException("internal error: native bitmap is 0"); - } - - mWidth = width; - mHeight = height; - mIsMutable = isMutable; - mIsPremultiplied = isPremultiplied; - mBuffer = buffer; - // we delete this in our finalizer - mNativeBitmap = nativeBitmap; - mFinalizer = new BitmapFinalizer(nativeBitmap); - - mNinePatchChunk = ninePatchChunk; - mLayoutBounds = layoutBounds; - if (density >= 0) { - mDensity = density; - }*/ - mIsMutable = false; - mIsPremultiplied = false; - mBuffer = null; - mFinalizer = null; - mNinePatchChunk = null; - mLayoutBounds = null; - } - - /** - * Native bitmap has been reconfigured, so set premult and cached - * width/height values - */ - @SuppressWarnings({"UnusedDeclaration"}) // called from JNI - void reinit(int width, int height, boolean isPremultiplied) { - mWidth = width; - mHeight = height; - mIsPremultiplied = isPremultiplied; - } - - /** - *

Returns the density for this bitmap.

- * - *

The default density is the same density as the current display, - * unless the current application does not support different screen - * densities in which case it is - * {@link android.util.DisplayMetrics#DENSITY_DEFAULT}. Note that - * compatibility mode is determined by the application that was initially - * loaded into a process -- applications that share the same process should - * all have the same compatibility, or ensure they explicitly set the - * density of their bitmaps appropriately.

- * - * @return A scaling factor of the default density or {@link #DENSITY_NONE} - * if the scaling factor is unknown. - * - * @see #setDensity(int) - * @see android.util.DisplayMetrics#DENSITY_DEFAULT - * @see android.util.DisplayMetrics#densityDpi - * @see #DENSITY_NONE - */ - public int getDensity() { - return mDensity; - } - - /** - *

Specifies the density for this bitmap. When the bitmap is - * drawn to a Canvas that also has a density, it will be scaled - * appropriately.

- * - * @param density The density scaling factor to use with this bitmap or - * {@link #DENSITY_NONE} if the density is unknown. - * - * @see #getDensity() - * @see android.util.DisplayMetrics#DENSITY_DEFAULT - * @see android.util.DisplayMetrics#densityDpi - * @see #DENSITY_NONE - */ - public void setDensity(int density) { - mDensity = density; - } - - /** - *

Modifies the bitmap to have a specified width, height, and {@link - * Config}, without affecting the underlying allocation backing the bitmap. - * Bitmap pixel data is not re-initialized for the new configuration.

- * - *

This method can be used to avoid allocating a new bitmap, instead - * reusing an existing bitmap's allocation for a new configuration of equal - * or lesser size. If the Bitmap's allocation isn't large enough to support - * the new configuration, an IllegalArgumentException will be thrown and the - * bitmap will not be modified.

- * - *

The result of {@link #getByteCount()} will reflect the new configuration, - * while {@link #getAllocationByteCount()} will reflect that of the initial - * configuration.

- * - *

WARNING: This method should NOT be called on a bitmap currently used - * by the view system. It does not make guarantees about how the underlying - * pixel buffer is remapped to the new config, just that the allocation is - * reused. Additionally, the view system does not account for bitmap - * properties being modifying during use, e.g. while attached to - * drawables.

- * - * @see #setWidth(int) - * @see #setHeight(int) - * @see #setConfig(Config) - */ - public void reconfigure(int width, int height, Config config) { - checkRecycled("Can't call reconfigure() on a recycled bitmap"); - if (width <= 0 || height <= 0) { - throw new IllegalArgumentException("width and height must be > 0"); - } - if (!isMutable()) { - throw new IllegalStateException("only mutable bitmaps may be reconfigured"); - } - if (mBuffer == null) { - throw new IllegalStateException("native-backed bitmaps may not be reconfigured"); - } - - nativeReconfigure(mNativeBitmap, width, height, config.nativeInt, mBuffer.length); - mWidth = width; - mHeight = height; - } - - /** - *

Convenience method for calling {@link #reconfigure(int, int, Config)} - * with the current height and config.

- * - *

WARNING: this method should not be used on bitmaps currently used by - * the view system, see {@link #reconfigure(int, int, Config)} for more - * details.

- * - * @see #reconfigure(int, int, Config) - * @see #setHeight(int) - * @see #setConfig(Config) - */ - public void setWidth(int width) { - reconfigure(width, getHeight(), getConfig()); - } - - /** - *

Convenience method for calling {@link #reconfigure(int, int, Config)} - * with the current width and config.

- * - *

WARNING: this method should not be used on bitmaps currently used by - * the view system, see {@link #reconfigure(int, int, Config)} for more - * details.

- * - * @see #reconfigure(int, int, Config) - * @see #setWidth(int) - * @see #setConfig(Config) - */ - public void setHeight(int height) { - // reconfigure(getWidth(), height, getConfig()); - } - - /** - *

Convenience method for calling {@link #reconfigure(int, int, Config)} - * with the current height and width.

- * - *

WARNING: this method should not be used on bitmaps currently used by - * the view system, see {@link #reconfigure(int, int, Config)} for more - * details.

- * - * @see #reconfigure(int, int, Config) - * @see #setWidth(int) - * @see #setHeight(int) - */ - public void setConfig(Config config) { - // reconfigure(getWidth(), getHeight(), config); - } - - /** - * Sets the nine patch chunk. - * - * @param chunk The definition of the nine patch - * - * @hide - */ - public void setNinePatchChunk(byte[] chunk) { - mNinePatchChunk = chunk; - } - - /** - * Sets the layout bounds as an array of left, top, right, bottom integers - * @param bounds the array containing the padding values - * - * @hide - */ - public void setLayoutBounds(int[] bounds) { - mLayoutBounds = bounds; - } - - /** - * Free the native object associated with this bitmap, and clear the - * reference to the pixel data. This will not free the pixel data synchronously; - * it simply allows it to be garbage collected if there are no other references. - * The bitmap is marked as "dead", meaning it will throw an exception if - * getPixels() or setPixels() is called, and will draw nothing. This operation - * cannot be reversed, so it should only be called if you are sure there are no - * further uses for the bitmap. This is an advanced call, and normally need - * not be called, since the normal GC process will free up this memory when - * there are no more references to this bitmap. - */ - public void recycle() { - if (!mRecycled) { - 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 - // Bitmap itself is collected. - mBuffer = null; - mNinePatchChunk = null; - } - mRecycled = true; - } - } - - /** - * Returns true if this bitmap has been recycled. If so, then it is an error - * to try to access its pixels, and the bitmap will not draw. - * - * @return true if the bitmap has been recycled - */ - public final boolean isRecycled() { - return mRecycled; - } - - /** - * Returns the generation ID of this bitmap. The generation ID changes - * whenever the bitmap is modified. This can be used as an efficient way to - * check if a bitmap has changed. - * - * @return The current generation ID for this bitmap. - */ - public int getGenerationId() { - return nativeGenerationId(mNativeBitmap); - } - - /** - * This is called by methods that want to throw an exception if the bitmap - * has already been recycled. - */ - private void checkRecycled(String errorMessage) { - if (mRecycled) { - throw new IllegalStateException(errorMessage); - } - } - - /** - * Common code for checking that x and y are >= 0 - * - * @param x x coordinate to ensure is >= 0 - * @param y y coordinate to ensure is >= 0 - */ - private static void checkXYSign(int x, int y) { - if (x < 0) { - throw new IllegalArgumentException("x must be >= 0"); - } - if (y < 0) { - throw new IllegalArgumentException("y must be >= 0"); - } - } - - /** - * Common code for checking that width and height are > 0 - * - * @param width width to ensure is > 0 - * @param height height to ensure is > 0 - */ - private static void checkWidthHeight(int width, int height) { - if (width <= 0) { - throw new IllegalArgumentException("width must be > 0"); - } - if (height <= 0) { - throw new IllegalArgumentException("height must be > 0"); - } - } - - /** - * Possible bitmap configurations. A bitmap configuration describes - * how pixels are stored. This affects the quality (color depth) as - * well as the ability to display transparent/translucent colors. - */ public enum Config { - // these native values must match up with the enum in SkBitmap.h - - /** - * Each pixel is stored as a single translucency (alpha) channel. - * This is very useful to efficiently store masks for instance. - * No color information is stored. - * With this configuration, each pixel requires 1 byte of memory. - */ - ALPHA_8(1), - - /** - * Each pixel is stored on 2 bytes and only the RGB channels are - * encoded: red is stored with 5 bits of precision (32 possible - * values), green is stored with 6 bits of precision (64 possible - * values) and blue is stored with 5 bits of precision. - * - * This configuration can produce slight visual artifacts depending - * on the configuration of the source. For instance, without - * dithering, the result might show a greenish tint. To get better - * results dithering should be applied. - * - * This configuration may be useful when using opaque bitmaps - * that do not require high color fidelity. - */ - RGB_565(3), - - /** - * Each pixel is stored on 2 bytes. The three RGB color channels - * and the alpha channel (translucency) are stored with a 4 bits - * precision (16 possible values.) - * - * This configuration is mostly useful if the application needs - * to store translucency information but also needs to save - * memory. - * - * It is recommended to use {@link #ARGB_8888} instead of this - * configuration. - * - * Note: as of {@link android.os.Build.VERSION_CODES#KITKAT}, - * any bitmap created with this configuration will be created - * using {@link #ARGB_8888} instead. - * - * @deprecated Because of the poor quality of this configuration, - * it is advised to use {@link #ARGB_8888} instead. - */ - @Deprecated - ARGB_4444(4), - - /** - * Each pixel is stored on 4 bytes. Each channel (RGB and alpha - * for translucency) is stored with 8 bits of precision (256 - * possible values.) - * - * This configuration is very flexible and offers the best - * quality. It should be used whenever possible. - */ - ARGB_8888(5), - - RGBA_F16(6), - - HARDWARE(7); - - final int nativeInt; - - @SuppressWarnings({"deprecation"}) - private static Config sConfigs[] = { - null, ALPHA_8, null, RGB_565, ARGB_4444, ARGB_8888}; - - Config(int ni) { - this.nativeInt = ni; - } - - static Config nativeToConfig(int ni) { - return sConfigs[ni]; - } + RGB_565, + ARGB_8888, } - /** - *

Copy the bitmap's pixels into the specified buffer (allocated by the - * caller). An exception is thrown if the buffer is not large enough to - * hold all of the pixels (taking into account the number of bytes per - * pixel) or if the Buffer subclass is not one of the support types - * (ByteBuffer, ShortBuffer, IntBuffer).

- *

The content of the bitmap is copied into the buffer as-is. This means - * that if this bitmap stores its pixels pre-multiplied - * (see {@link #isPremultiplied()}, the values in the buffer will also be - * pre-multiplied.

- *

After this method returns, the current position of the buffer is - * updated: the position is incremented by the number of elements written - * in the buffer.

- */ - public void copyPixelsToBuffer(Buffer dst) { - int elements = dst.remaining(); - int shift; - if (dst instanceof ByteBuffer) { - shift = 0; - } else if (dst instanceof ShortBuffer) { - shift = 1; - } else if (dst instanceof IntBuffer) { - shift = 2; - } else { - throw new RuntimeException("unsupported Buffer subclass"); - } + private int width; + private int height; + private long texture; + private long snapshot; - long bufferSize = (long)elements << shift; - long pixelSize = getByteCount(); - - if (bufferSize < pixelSize) { - throw new RuntimeException("Buffer not large enough for pixels"); - } - - nativeCopyPixelsToBuffer(pixbuf, dst); - - // now update the buffer's position - int position = dst.position(); - position += pixelSize >> shift; - dst.position(position); + Bitmap(long texture) { + this.texture = texture; + this.width = native_get_width(texture); + this.height = native_get_height(texture); } - /** - *

Copy the pixels from the buffer, beginning at the current position, - * overwriting the bitmap's pixels. The data in the buffer is not changed - * in any way (unlike setPixels(), which converts from unpremultipled 32bit - * to whatever the bitmap's native format is.

- *

After this method returns, the current position of the buffer is - * updated: the position is incremented by the number of elements read from - * the buffer. If you need to read the bitmap from the buffer again you must - * first rewind the buffer.

- */ - public void copyPixelsFromBuffer(Buffer src) { - checkRecycled("copyPixelsFromBuffer called on recycled bitmap"); - - int elements = src.remaining(); - int shift; - if (src instanceof ByteBuffer) { - shift = 0; - } else if (src instanceof ShortBuffer) { - shift = 1; - } else if (src instanceof IntBuffer) { - shift = 2; - } else { - throw new RuntimeException("unsupported Buffer subclass"); - } - - long bufferBytes = (long)elements << shift; - long bitmapBytes = getByteCount(); - - if (bufferBytes < bitmapBytes) { - throw new RuntimeException("Buffer not large enough for pixels"); - } - - nativeCopyPixelsFromBuffer(pixbuf, src); - - // now update the buffer's position - int position = src.position(); - position += bitmapBytes >> shift; - src.position(position); + private Bitmap(int width, int height) { + this.width = width; + this.height = height; } - /** - * Tries to make a new bitmap based on the dimensions of this bitmap, - * setting the new bitmap's config to the one specified, and then copying - * this bitmap's pixels into the new bitmap. If the conversion is not - * supported, or the allocator fails, then this returns NULL. The returned - * bitmap initially has the same density as the original. - * - * @param config The desired config for the resulting bitmap - * @param isMutable True if the resulting bitmap should be mutable (i.e. - * its pixels can be modified) - * @return the new bitmap, or null if the copy could not be made. - */ - public Bitmap copy(Config config, boolean isMutable) { - checkRecycled("Can't copy a recycled bitmap"); - Bitmap b = new Bitmap(native_copy(pixbuf)); - if (b != null) { - // b.setAlphaAndPremultiplied(hasAlpha(), mIsPremultiplied); - b.mDensity = mDensity; - } - return b; - } - - /** - * Creates a new bitmap, scaled from an existing bitmap, when possible. If the - * specified width and height are the same as the current width and height of - * the source bitmap, the source bitmap is returned and no new bitmap is - * created. - * - * @param src The source bitmap. - * @param dstWidth The new bitmap's desired width. - * @param dstHeight The new bitmap's desired height. - * @param filter true if the source should be filtered. - * @return The new scaled bitmap or the source bitmap if no scaling is required. - * @throws IllegalArgumentException if width is <= 0, or height is <= 0 - */ - public static Bitmap createScaledBitmap(Bitmap src, int dstWidth, int dstHeight, - boolean filter) { - Matrix m; - synchronized (Bitmap.class) { - // small pool of just 1 matrix - m = sScaleMatrix; - sScaleMatrix = null; - } - - if (m == null) { - m = new Matrix(); - } - - final int width = src.getWidth(); - final int height = src.getHeight(); - final float sx = dstWidth / (float)width; - final float sy = dstHeight / (float)height; - m.setScale(sx, sy); - Bitmap b = Bitmap.createBitmap(src, 0, 0, width, height, m, filter); - - synchronized (Bitmap.class) { - // do we need to check for null? why not just assign everytime? - if (sScaleMatrix == null) { - sScaleMatrix = m; - } - } - - return b; - } - - /** - * Returns an immutable bitmap from the source bitmap. The new bitmap may - * be the same object as source, or a copy may have been made. It is - * initialized with the same density as the original bitmap. - */ - public static Bitmap createBitmap(Bitmap src) { - return createBitmap(src, 0, 0, src.getWidth(), src.getHeight()); - } - - /** - * Returns an immutable bitmap from the specified subset of the source - * bitmap. The new bitmap may be the same object as source, or a copy may - * have been made. It is initialized with the same density as the original - * bitmap. - * - * @param source The bitmap we are subsetting - * @param x The x coordinate of the first pixel in source - * @param y The y coordinate of the first pixel in source - * @param width The number of pixels in each row - * @param height The number of rows - * @return A copy of a subset of the source bitmap or the source bitmap itself. - * @throws IllegalArgumentException if the x, y, width, height values are - * outside of the dimensions of the source bitmap, or width is <= 0, - * or height is <= 0 - */ - public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height) { - return createBitmap(source, x, y, width, height, null, false); - } - - /** - * Returns an immutable bitmap from subset of the source bitmap, - * transformed by the optional matrix. The new bitmap may be the - * same object as source, or a copy may have been made. It is - * initialized with the same density as the original bitmap. - * - * If the source bitmap is immutable and the requested subset is the - * same as the source bitmap itself, then the source bitmap is - * returned and no new bitmap is created. - * - * @param source The bitmap we are subsetting - * @param x The x coordinate of the first pixel in source - * @param y The y coordinate of the first pixel in source - * @param width The number of pixels in each row - * @param height The number of rows - * @param m Optional matrix to be applied to the pixels - * @param filter true if the source should be filtered. - * Only applies if the matrix contains more than just - * translation. - * @return A bitmap that represents the specified subset of source - * @throws IllegalArgumentException if the x, y, width, height values are - * outside of the dimensions of the source bitmap, or width is <= 0, - * or height is <= 0 - */ - public static Bitmap createBitmap(Bitmap source, int x, int y, int width, int height, - Matrix m, boolean filter) { /* - - checkXYSign(x, y); - checkWidthHeight(width, height); - if (x + width > source.getWidth()) { - throw new IllegalArgumentException("x + width must be <= bitmap.width()"); - } - if (y + height > source.getHeight()) { - throw new IllegalArgumentException("y + height must be <= bitmap.height()"); - } - - // check if we can just return our argument unchanged - if (!source.isMutable() && x == 0 && y == 0 && width == source.getWidth() && - height == source.getHeight() && (m == null || m.isIdentity())) { - return source; - } - - int neww = width; - int newh = height; - Canvas canvas = new Canvas(); - Bitmap bitmap; - Paint paint; - - Rect srcR = new Rect(x, y, x + width, y + height); - RectF dstR = new RectF(0, 0, width, height); - - Config newConfig = Config.ARGB_8888; - final Config config = source.getConfig(); - // GIF files generate null configs, assume ARGB_8888 - if (config != null) { - switch (config) { - case RGB_565: - newConfig = Config.RGB_565; - break; - case ALPHA_8: - newConfig = Config.ALPHA_8; - break; - //noinspection deprecation - case ARGB_4444: - case ARGB_8888: - default: - newConfig = Config.ARGB_8888; - break; - } - } - - if (m == null || m.isIdentity()) { - bitmap = createBitmap(neww, newh, newConfig, source.hasAlpha()); - paint = null; // not needed - } else { - final boolean transformed = !m.rectStaysRect(); - - RectF deviceR = new RectF(); - m.mapRect(deviceR, dstR); - - neww = Math.round(deviceR.width()); - newh = Math.round(deviceR.height()); - - bitmap = createBitmap(neww, newh, transformed ? Config.ARGB_8888 : newConfig, - transformed || source.hasAlpha()); - - canvas.translate(-deviceR.left, -deviceR.top); - canvas.concat(m); - - paint = new Paint(); - paint.setFilterBitmap(filter); - if (transformed) { - paint.setAntiAlias(true); - } - } - - // The new bitmap was created from a known bitmap source so assume that - // they use the same density - bitmap.mDensity = source.mDensity; - bitmap.setAlphaAndPremultiplied(source.hasAlpha(), source.mIsPremultiplied); - - canvas.setBitmap(bitmap); - canvas.drawBitmap(source, srcR, dstR, paint); - canvas.setBitmap(null); - - return bitmap; - */ - return new Bitmap(native_copy(native_subpixbuf(source.pixbuf, x, y, width, height))); - } - - /** - * Returns a mutable bitmap with the specified width and height. Its - * initial density is as per {@link #getDensity}. - * - * @param width The width of the bitmap - * @param height The height of the bitmap - * @param config The bitmap config to create. - * @throws IllegalArgumentException if the width or height are <= 0 - */ public static Bitmap createBitmap(int width, int height, Config config) { - return createBitmap(width, height, config, true); + return new Bitmap(width, height); } - /** - * Returns a mutable bitmap with the specified width and height. Its - * initial density is determined from the given {@link DisplayMetrics}. - * - * @param display Display metrics for the display this bitmap will be - * drawn on. - * @param width The width of the bitmap - * @param height The height of the bitmap - * @param config The bitmap config to create. - * @throws IllegalArgumentException if the width or height are <= 0 - */ - public static Bitmap createBitmap(DisplayMetrics display, int width, - int height, Config config) { - return createBitmap(display, width, height, config, true); + public int getWidth() { + return width; } - /** - * Returns a mutable bitmap with the specified width and height. Its - * initial density is as per {@link #getDensity}. - * - * @param width The width of the bitmap - * @param height The height of the bitmap - * @param config The bitmap config to create. - * @param hasAlpha If the bitmap is ARGB_8888 this flag can be used to mark the - * bitmap as opaque. Doing so will clear the bitmap in black - * instead of transparent. - * - * @throws IllegalArgumentException if the width or height are <= 0 - */ - private static Bitmap createBitmap(int width, int height, Config config, boolean hasAlpha) { - return createBitmap(null, width, height, config, hasAlpha); + public int getHeight() { + return height; } - /** - * Returns a mutable bitmap with the specified width and height. Its - * initial density is determined from the given {@link DisplayMetrics}. - * - * @param display Display metrics for the display this bitmap will be - * drawn on. - * @param width The width of the bitmap - * @param height The height of the bitmap - * @param config The bitmap config to create. - * @param hasAlpha If the bitmap is ARGB_8888 this flag can be used to mark the - * bitmap as opaque. Doing so will clear the bitmap in black - * instead of transparent. - * - * @throws IllegalArgumentException if the width or height are <= 0 - */ - private static Bitmap createBitmap(DisplayMetrics display, int width, int height, - Config config, boolean hasAlpha) { - if (width <= 0 || height <= 0) { - throw new IllegalArgumentException("width and height must be > 0"); - } - Bitmap bm = new Bitmap(native_create(/*null, 0, width, */width, height/*, config.nativeInt, true*/)); - if (display != null) { - bm.mDensity = display.densityDpi; - } - bm.setHasAlpha(hasAlpha); - if (config == Config.ARGB_8888 && !hasAlpha) { - nativeErase(bm.mNativeBitmap, 0xff000000); - } - // No need to initialize the bitmap to zeroes with other configs; - // it is backed by a VM byte array which is by definition preinitialized - // to all zeroes. - return bm; - } - - /** - * Returns a immutable bitmap with the specified width and height, with each - * pixel value set to the corresponding value in the colors array. Its - * initial density is as per {@link #getDensity}. - * - * @param colors Array of {@link Color} used to initialize the pixels. - * @param offset Number of values to skip before the first color in the - * array of colors. - * @param stride Number of colors in the array between rows (must be >= - * width or <= -width). - * @param width The width of the bitmap - * @param height The height of the bitmap - * @param config The bitmap config to create. If the config does not - * support per-pixel alpha (e.g. RGB_565), then the alpha - * bytes in the colors[] will be ignored (assumed to be FF) - * @throws IllegalArgumentException if the width or height are <= 0, or if - * the color array's length is less than the number of pixels. - */ - public static Bitmap createBitmap(int colors[], int offset, int stride, - int width, int height, Config config) { - return createBitmap(null, colors, offset, stride, width, height, config); - } - - /** - * Returns a immutable bitmap with the specified width and height, with each - * pixel value set to the corresponding value in the colors array. Its - * initial density is determined from the given {@link DisplayMetrics}. - * - * @param display Display metrics for the display this bitmap will be - * drawn on. - * @param colors Array of {@link Color} used to initialize the pixels. - * @param offset Number of values to skip before the first color in the - * array of colors. - * @param stride Number of colors in the array between rows (must be >= - * width or <= -width). - * @param width The width of the bitmap - * @param height The height of the bitmap - * @param config The bitmap config to create. If the config does not - * support per-pixel alpha (e.g. RGB_565), then the alpha - * bytes in the colors[] will be ignored (assumed to be FF) - * @throws IllegalArgumentException if the width or height are <= 0, or if - * the color array's length is less than the number of pixels. - */ - public static Bitmap createBitmap(DisplayMetrics display, int colors[], - int offset, int stride, int width, int height, Config config) { - - checkWidthHeight(width, height); - if (Math.abs(stride) < width) { - throw new IllegalArgumentException("abs(stride) must be >= width"); - } - int lastScanline = offset + (height - 1) * stride; - int length = colors.length; - if (offset < 0 || (offset + width > length) || lastScanline < 0 || - (lastScanline + width > length)) { - throw new ArrayIndexOutOfBoundsException(); - } - if (width <= 0 || height <= 0) { - throw new IllegalArgumentException("width and height must be > 0"); - } - Bitmap bm = new Bitmap(native_create(/*colors, offset, stride, */width, height/*, config.nativeInt, false*/)); - if (display != null) { - bm.mDensity = display.densityDpi; - } - return bm; - } - - /** - * Returns a immutable bitmap with the specified width and height, with each - * pixel value set to the corresponding value in the colors array. Its - * initial density is as per {@link #getDensity}. - * - * @param colors Array of {@link Color} used to initialize the pixels. - * This array must be at least as large as width * height. - * @param width The width of the bitmap - * @param height The height of the bitmap - * @param config The bitmap config to create. If the config does not - * support per-pixel alpha (e.g. RGB_565), then the alpha - * bytes in the colors[] will be ignored (assumed to be FF) - * @throws IllegalArgumentException if the width or height are <= 0, or if - * the color array's length is less than the number of pixels. - */ - public static Bitmap createBitmap(int colors[], int width, int height, Config config) { - return createBitmap(null, colors, 0, width, width, height, config); - } - - /** - * Returns a immutable bitmap with the specified width and height, with each - * pixel value set to the corresponding value in the colors array. Its - * initial density is determined from the given {@link DisplayMetrics}. - * - * @param display Display metrics for the display this bitmap will be - * drawn on. - * @param colors Array of {@link Color} used to initialize the pixels. - * This array must be at least as large as width * height. - * @param width The width of the bitmap - * @param height The height of the bitmap - * @param config The bitmap config to create. If the config does not - * support per-pixel alpha (e.g. RGB_565), then the alpha - * bytes in the colors[] will be ignored (assumed to be FF) - * @throws IllegalArgumentException if the width or height are <= 0, or if - * the color array's length is less than the number of pixels. - */ - public static Bitmap createBitmap(DisplayMetrics display, int colors[], - int width, int height, Config config) { - return createBitmap(display, colors, 0, width, width, height, config); - } - - public static Bitmap createBitmap(DisplayMetrics display, int width, int height, Config config, boolean hasAlpha, ColorSpace colorSpace) { - return createBitmap(display, width, height, config, hasAlpha); - } - - /** - * Returns an optional array of private data, used by the UI system for - * some bitmaps. Not intended to be called by applications. - */ - public byte[] getNinePatchChunk() { - return mNinePatchChunk; - } - - /** - * @hide - * @return the layout padding [left, right, top, bottom] - */ - public int[] getLayoutBounds() { - return mLayoutBounds; - } - - /** - * Specifies the known formats a bitmap can be compressed into - */ - public enum CompressFormat { - JPEG(0), - PNG(1), - WEBP(2); - - CompressFormat(int nativeInt) { - this.nativeInt = nativeInt; - } - final int nativeInt; - } - - /** - * Number of bytes of temp storage we use for communicating between the - * native compressor and the java OutputStream. - */ - private final static int WORKING_COMPRESS_STORAGE = 4096; - - /** - * Write a compressed version of the bitmap to the specified outputstream. - * If this returns true, the bitmap can be reconstructed by passing a - * corresponding inputstream to BitmapFactory.decodeStream(). Note: not - * all Formats support all bitmap configs directly, so it is possible that - * the returned bitmap from BitmapFactory could be in a different bitdepth, - * and/or may have lost per-pixel alpha (e.g. JPEG only supports opaque - * pixels). - * - * @param format The format of the compressed image - * @param quality Hint to the compressor, 0-100. 0 meaning compress for - * small size, 100 meaning compress for max quality. Some - * formats, like PNG which is lossless, will ignore the - * quality setting - * @param stream The outputstream to write the compressed data. - * @return true if successfully compressed to the specified stream. - */ - public boolean compress(CompressFormat format, int quality, OutputStream stream) { - checkRecycled("Can't compress a recycled bitmap"); - // do explicit check before calling the native method - if (stream == null) { - throw new NullPointerException(); - } - if (quality < 0 || quality > 100) { - throw new IllegalArgumentException("quality must be 0..100"); - } - return nativeCompress(mNativeBitmap, format.nativeInt, quality, - stream, new byte[WORKING_COMPRESS_STORAGE]); - } - - /** - * Returns true if the bitmap is marked as mutable (i.e. can be drawn into) - */ - public final boolean isMutable() { - return mIsMutable; - } - - /** - *

Indicates whether pixels stored in this bitmaps are stored pre-multiplied. - * When a pixel is pre-multiplied, the RGB components have been multiplied by - * the alpha component. For instance, if the original color is a 50% - * translucent red (128, 255, 0, 0), the pre-multiplied form is - * (128, 128, 0, 0).

- * - *

This method always returns false if {@link #getConfig()} is - * {@link Bitmap.Config#RGB_565}.

- * - *

This method only returns true if {@link #hasAlpha()} returns true. - * A bitmap with no alpha channel can be used both as a pre-multiplied and - * as a non pre-multiplied bitmap.

- * - *

Only pre-multiplied bitmaps may be drawn by the view system or - * {@link Canvas}. If a non-pre-multiplied bitmap with an alpha channel is - * drawn to a Canvas, a RuntimeException will be thrown.

- * - * @return true if the underlying pixels have been pre-multiplied, false - * otherwise - * - * @see Bitmap#setPremultiplied(boolean) - * @see BitmapFactory.Options#inPremultiplied - */ - public final boolean isPremultiplied() { - return mIsPremultiplied && getConfig() != Config.RGB_565 && hasAlpha(); - } - - /** - * Sets whether the bitmap should treat its data as pre-multiplied. - * - *

Bitmaps are always treated as pre-multiplied by the view system and - * {@link Canvas} for performance reasons. Storing un-pre-multiplied data in - * a Bitmap (through {@link #setPixel}, {@link #setPixels}, or {@link - * BitmapFactory.Options#inPremultiplied BitmapFactory.Options.inPremultiplied}) - * can lead to incorrect blending if drawn by the framework.

- * - *

This method will not affect the behavior of a bitmap without an alpha - * channel, or if {@link #hasAlpha()} returns false.

- * - *

Calling createBitmap() or createScaledBitmap() with a source - * Bitmap whose colors are not pre-multiplied may result in a RuntimeException, - * since those functions require drawing the source, which is not supported for - * un-pre-multiplied Bitmaps.

- * - * @see Bitmap#isPremultiplied() - * @see BitmapFactory.Options#inPremultiplied - */ - public final void setPremultiplied(boolean premultiplied) { - mIsPremultiplied = premultiplied; - nativeSetAlphaAndPremultiplied(mNativeBitmap, hasAlpha(), premultiplied); - } - - /** - * Helper function to set both alpha and premultiplied. * - */ - private final void setAlphaAndPremultiplied(boolean hasAlpha, boolean premultiplied) { - mIsPremultiplied = premultiplied; - nativeSetAlphaAndPremultiplied(mNativeBitmap, hasAlpha, premultiplied); - } - - /** - * Returns the bitmap's width - */ - public native final int getWidth(); - - /** - * Returns the bitmap's height - */ - public native final int getHeight(); - - /** - * Convenience for calling {@link #getScaledWidth(int)} with the target - * density of the given {@link Canvas}. - */ - public int getScaledWidth(Canvas canvas) { /* - return scaleFromDensity(getWidth(), mDensity, canvas.mDensity); - */ - return -1; - } - - /** - * Convenience for calling {@link #getScaledHeight(int)} with the target - * density of the given {@link Canvas}. - */ - public int getScaledHeight(Canvas canvas) { /* - return scaleFromDensity(getHeight(), mDensity, canvas.mDensity); - */ - return -1; - } - - /** - * Convenience for calling {@link #getScaledWidth(int)} with the target - * density of the given {@link DisplayMetrics}. - */ - public int getScaledWidth(DisplayMetrics metrics) { - return scaleFromDensity(getWidth(), mDensity, metrics.densityDpi); - } - - /** - * Convenience for calling {@link #getScaledHeight(int)} with the target - * density of the given {@link DisplayMetrics}. - */ - public int getScaledHeight(DisplayMetrics metrics) { - return scaleFromDensity(getHeight(), mDensity, metrics.densityDpi); - } - - /** - * Convenience method that returns the width of this bitmap divided - * by the density scale factor. - * - * @param targetDensity The density of the target canvas of the bitmap. - * @return The scaled width of this bitmap, according to the density scale factor. - */ - public int getScaledWidth(int targetDensity) { - return scaleFromDensity(getWidth(), mDensity, targetDensity); - } - - /** - * Convenience method that returns the height of this bitmap divided - * by the density scale factor. - * - * @param targetDensity The density of the target canvas of the bitmap. - * @return The scaled height of this bitmap, according to the density scale factor. - */ - public int getScaledHeight(int targetDensity) { - return scaleFromDensity(getHeight(), mDensity, targetDensity); - } - - /** - * @hide - */ - static public int scaleFromDensity(int size, int sdensity, int tdensity) { - if (sdensity == DENSITY_NONE || tdensity == DENSITY_NONE || sdensity == tdensity) { - return size; - } - - // Scale by tdensity / sdensity, rounding up. - return ((size * tdensity) + (sdensity >> 1)) / sdensity; - } - - /** - * Return the number of bytes between rows in the bitmap's pixels. Note that - * this refers to the pixels as stored natively by the bitmap. If you call - * getPixels() or setPixels(), then the pixels are uniformly treated as - * 32bit values, packed according to the Color class. - * - *

As of {@link android.os.Build.VERSION_CODES#KITKAT}, this method - * should not be used to calculate the memory usage of the bitmap. Instead, - * see {@link #getAllocationByteCount()}. - * - * @return number of bytes between rows of the native bitmap pixels. - */ - public final int getRowBytes() { - return nativeRowBytes(pixbuf); - } - - /** - * Returns the minimum number of bytes that can be used to store this bitmap's pixels. - * - *

As of {@link android.os.Build.VERSION_CODES#KITKAT}, the result of this method can - * no longer be used to determine memory usage of a bitmap. See {@link - * #getAllocationByteCount()}.

- */ - public final int getByteCount() { - // int result permits bitmaps up to 46,340 x 46,340 - return getRowBytes() * getHeight(); - } - - /** - * Returns the size of the allocated memory used to store this bitmap's pixels. - * - *

This can be larger than the result of {@link #getByteCount()} if a bitmap is reused to - * decode other bitmaps of smaller size, or by manual reconfiguration. See {@link - * #reconfigure(int, int, Config)}, {@link #setWidth(int)}, {@link #setHeight(int)}, {@link - * #setConfig(Bitmap.Config)}, and {@link BitmapFactory.Options#inBitmap - * BitmapFactory.Options.inBitmap}. If a bitmap is not modified in this way, this value will be - * the same as that returned by {@link #getByteCount()}.

- * - *

This value will not change over the lifetime of a Bitmap.

- * - * @see #reconfigure(int, int, Config) - */ - public final int getAllocationByteCount() { - if (mBuffer == null) { - // native backed bitmaps don't support reconfiguration, - // so alloc size is always content size - return getByteCount(); - } - return mBuffer.length; - } - - /** - * If the bitmap's internal config is in one of the public formats, return - * that config, otherwise return null. - */ - public final Config getConfig() { - // return Config.nativeToConfig(nativeConfig(mNativeBitmap)); - return Config.ARGB_8888; - } - - /** - * Returns true if the bitmap's config supports per-pixel alpha, and - * if the pixels may contain non-opaque alpha values. For some configs, - * this is always false (e.g. RGB_565), since they do not support per-pixel - * alpha. However, for configs that do, the bitmap may be flagged to be - * known that all of its pixels are opaque. In this case hasAlpha() will - * also return false. If a config such as ARGB_8888 is not so flagged, - * it will return true by default. - */ - public final boolean hasAlpha() { - return true; // we only support ARGB_8888 - } - - /** - * Tell the bitmap if all of the pixels are known to be opaque (false) - * or if some of the pixels may contain non-opaque alpha values (true). - * Note, for some configs (e.g. RGB_565) this call is ignored, since it - * does not support per-pixel alpha values. - * - * This is meant as a drawing hint, as in some cases a bitmap that is known - * to be opaque can take a faster drawing case than one that may have - * non-opaque per-pixel alpha values. - */ - public void setHasAlpha(boolean hasAlpha) { - // nativeSetAlphaAndPremultiplied(mNativeBitmap, hasAlpha, mIsPremultiplied); - } - - /** - * Indicates whether the renderer responsible for drawing this - * bitmap should attempt to use mipmaps when this bitmap is drawn - * scaled down. - * - * If you know that you are going to draw this bitmap at less than - * 50% of its original size, you may be able to obtain a higher - * quality - * - * This property is only a suggestion that can be ignored by the - * renderer. It is not guaranteed to have any effect. - * - * @return true if the renderer should attempt to use mipmaps, - * false otherwise - * - * @see #setHasMipMap(boolean) - */ - public final boolean hasMipMap() { - return nativeHasMipMap(mNativeBitmap); - } - - /** - * Set a hint for the renderer responsible for drawing this bitmap - * indicating that it should attempt to use mipmaps when this bitmap - * is drawn scaled down. - * - * If you know that you are going to draw this bitmap at less than - * 50% of its original size, you may be able to obtain a higher - * quality by turning this property on. - * - * Note that if the renderer respects this hint it might have to - * allocate extra memory to hold the mipmap levels for this bitmap. - * - * This property is only a suggestion that can be ignored by the - * renderer. It is not guaranteed to have any effect. - * - * @param hasMipMap indicates whether the renderer should attempt - * to use mipmaps - * - * @see #hasMipMap() - */ - public final void setHasMipMap(boolean hasMipMap) { - nativeSetHasMipMap(mNativeBitmap, hasMipMap); - } - - /** - * Fills the bitmap's pixels with the specified {@link Color}. - * - * @throws IllegalStateException if the bitmap is not mutable. - */ - public void eraseColor(int c) { - checkRecycled("Can't erase a recycled bitmap"); - if (!isMutable()) { -// throw new IllegalStateException("cannot erase immutable bitmaps"); - System.out.println("cannot erase immutable bitmaps"); - return; - } - nativeErase(mNativeBitmap, c); - } - - /** - * Returns the {@link Color} at the specified location. Throws an exception - * if x or y are out of bounds (negative or >= to the width or height - * respectively). The returned color is a non-premultiplied ARGB value. - * - * @param x The x coordinate (0...width-1) of the pixel to return - * @param y The y coordinate (0...height-1) of the pixel to return - * @return The argb {@link Color} at the specified coordinate - * @throws IllegalArgumentException if x, y exceed the bitmap's bounds - */ - public int getPixel(int x, int y) { - checkRecycled("Can't call getPixel() on a recycled bitmap"); - checkPixelAccess(x, y); - return nativeGetPixel(mNativeBitmap, x, y, mIsPremultiplied); - } - - /** - * Returns in pixels[] a copy of the data in the bitmap. Each value is - * a packed int representing a {@link Color}. The stride parameter allows - * the caller to allow for gaps in the returned pixels array between - * rows. For normal packed results, just pass width for the stride value. - * The returned colors are non-premultiplied ARGB values. - * - * @param pixels The array to receive the bitmap's colors - * @param offset The first index to write into pixels[] - * @param stride The number of entries in pixels[] to skip between - * rows (must be >= bitmap's width). Can be negative. - * @param x The x coordinate of the first pixel to read from - * the bitmap - * @param y The y coordinate of the first pixel to read from - * the bitmap - * @param width The number of pixels to read from each row - * @param height The number of rows to read - * - * @throws IllegalArgumentException if x, y, width, height exceed the - * bounds of the bitmap, or if abs(stride) < width. - * @throws ArrayIndexOutOfBoundsException if the pixels array is too small - * to receive the specified number of pixels. - */ - public void getPixels(int[] pixels, int offset, int stride, - int x, int y, int width, int height) { - checkRecycled("Can't call getPixels() on a recycled bitmap"); - if (width == 0 || height == 0) { - return; // nothing to do - } - checkPixelsAccess(x, y, width, height, offset, stride, pixels); - nativeGetPixels(pixbuf, pixels, offset, stride, - x, y, width, height, mIsPremultiplied); - } - - /** - * Shared code to check for illegal arguments passed to getPixel() - * or setPixel() - * - * @param x x coordinate of the pixel - * @param y y coordinate of the pixel - */ - private void checkPixelAccess(int x, int y) { - checkXYSign(x, y); - if (x >= getWidth()) { - throw new IllegalArgumentException("x must be < bitmap.width()"); - } - if (y >= getHeight()) { - throw new IllegalArgumentException("y must be < bitmap.height()"); - } - } - - /** - * Shared code to check for illegal arguments passed to getPixels() - * or setPixels() - * - * @param x left edge of the area of pixels to access - * @param y top edge of the area of pixels to access - * @param width width of the area of pixels to access - * @param height height of the area of pixels to access - * @param offset offset into pixels[] array - * @param stride number of elements in pixels[] between each logical row - * @param pixels array to hold the area of pixels being accessed - */ - private void checkPixelsAccess(int x, int y, int width, int height, - int offset, int stride, int pixels[]) { - checkXYSign(x, y); - if (width < 0) { - throw new IllegalArgumentException("width must be >= 0"); - } - if (height < 0) { - throw new IllegalArgumentException("height must be >= 0"); - } - if (x + width > getWidth()) { - throw new IllegalArgumentException( - "x + width must be <= bitmap.width()"); - } - if (y + height > getHeight()) { - throw new IllegalArgumentException( - "y + height must be <= bitmap.height()"); - } - if (Math.abs(stride) < width) { - throw new IllegalArgumentException("abs(stride) must be >= width"); - } - int lastScanline = offset + (height - 1) * stride; - int length = pixels.length; - if (offset < 0 || (offset + width > length) || lastScanline < 0 || (lastScanline + width > length)) { - throw new ArrayIndexOutOfBoundsException(); - } - } - - /** - *

Write the specified {@link Color} into the bitmap (assuming it is - * mutable) at the x,y coordinate. The color must be a - * non-premultiplied ARGB value.

- * - * @param x The x coordinate of the pixel to replace (0...width-1) - * @param y The y coordinate of the pixel to replace (0...height-1) - * @param color The ARGB color to write into the bitmap - * - * @throws IllegalStateException if the bitmap is not mutable - * @throws IllegalArgumentException if x, y are outside of the bitmap's - * bounds. - */ - public void setPixel(int x, int y, int color) { - checkRecycled("Can't call setPixel() on a recycled bitmap"); - if (!isMutable()) { - throw new IllegalStateException(); - } - checkPixelAccess(x, y); - nativeSetPixel(mNativeBitmap, x, y, color, mIsPremultiplied); - } - - /** - *

Replace pixels in the bitmap with the colors in the array. Each element - * in the array is a packed int prepresenting a non-premultiplied ARGB - * {@link Color}.

- * - * @param pixels The colors to write to the bitmap - * @param offset The index of the first color to read from pixels[] - * @param stride The number of colors in pixels[] to skip between rows. - * Normally this value will be the same as the width of - * the bitmap, but it can be larger (or negative). - * @param x The x coordinate of the first pixel to write to in - * the bitmap. - * @param y The y coordinate of the first pixel to write to in - * the bitmap. - * @param width The number of colors to copy from pixels[] per row - * @param height The number of rows to write to the bitmap - * - * @throws IllegalStateException if the bitmap is not mutable - * @throws IllegalArgumentException if x, y, width, height are outside of - * the bitmap's bounds. - * @throws ArrayIndexOutOfBoundsException if the pixels array is too small - * to receive the specified number of pixels. - */ - public void setPixels(int[] pixels, int offset, int stride, - int x, int y, int width, int height) { - checkRecycled("Can't call setPixels() on a recycled bitmap"); - if (!isMutable()) { - throw new IllegalStateException(); - } - if (width == 0 || height == 0) { - return; // nothing to do - } - checkPixelsAccess(x, y, width, height, offset, stride, pixels); - nativeSetPixels(mNativeBitmap, pixels, offset, stride, - x, y, width, height, mIsPremultiplied); - } - - /** - * Returns a new bitmap that captures the alpha values of the original. - * This may be drawn with Canvas.drawBitmap(), where the color(s) will be - * taken from the paint that is passed to the draw call. - * - * @return new bitmap containing the alpha channel of the original bitmap. - */ - public Bitmap extractAlpha() { - return extractAlpha(null, null); - } - - /** - * Returns a new bitmap that captures the alpha values of the original. - * These values may be affected by the optional Paint parameter, which - * can contain its own alpha, and may also contain a MaskFilter which - * could change the actual dimensions of the resulting bitmap (e.g. - * a blur maskfilter might enlarge the resulting bitmap). If offsetXY - * is not null, it returns the amount to offset the returned bitmap so - * that it will logically align with the original. For example, if the - * paint contains a blur of radius 2, then offsetXY[] would contains - * -2, -2, so that drawing the alpha bitmap offset by (-2, -2) and then - * drawing the original would result in the blur visually aligning with - * the original. - * - *

The initial density of the returned bitmap is the same as the original's. - * - * @param paint Optional paint used to modify the alpha values in the - * resulting bitmap. Pass null for default behavior. - * @param offsetXY Optional array that returns the X (index 0) and Y - * (index 1) offset needed to position the returned bitmap - * so that it visually lines up with the original. - * @return new bitmap containing the (optionally modified by paint) alpha - * channel of the original bitmap. This may be drawn with - * Canvas.drawBitmap(), where the color(s) will be taken from the - * paint that is passed to the draw call. - */ - public Bitmap extractAlpha(Paint paint, int[] offsetXY) { - checkRecycled("Can't extractAlpha on a recycled bitmap"); - int nativePaint = /*paint != null ? paint.mNativePaint : */ 0; - Bitmap bm = nativeExtractAlpha(mNativeBitmap, nativePaint, offsetXY); - if (bm == null) { - throw new RuntimeException("Failed to extractAlpha on Bitmap"); - } - bm.mDensity = mDensity; - return bm; - } - - /** - * Given another bitmap, return true if it has the same dimensions, config, - * and pixel data as this bitmap. If any of those differ, return false. - * If other is null, return false. - */ - public boolean sameAs(Bitmap other) { - return this == other || (other != null && nativeSameAs(mNativeBitmap, other.mNativeBitmap)); - } - - /** - * Rebuilds any caches associated with the bitmap that are used for - * drawing it. In the case of purgeable bitmaps, this call will attempt to - * ensure that the pixels have been decoded. - * If this is called on more than one bitmap in sequence, the priority is - * given in LRU order (i.e. the last bitmap called will be given highest - * priority). - * - * For bitmaps with no associated caches, this call is effectively a no-op, - * and therefore is harmless. - */ - public void prepareToDraw() { - // nativePrepareToDraw(mNativeBitmap); - System.out.println("Bitmap.prepareToDraw() called"); - } - - private static class BitmapFinalizer { - private final int mNativeBitmap; - - BitmapFinalizer(int nativeBitmap) { - mNativeBitmap = nativeBitmap; - } - - @Override - public void finalize() { - try { - super.finalize(); - } catch (Throwable t) { - // Ignore - } finally { - nativeDestructor(mNativeBitmap); - } - } - } - - @Override - @SuppressWarnings("deprecation") - protected void finalize() throws Throwable { - try { - super.finalize(); - } finally { - if (!isRecycled()) { - recycle(); - } - } - } - - /** - * internal ATL method to create or get a GdkTexture for the pixbuf - * @return pointer to the GdkTexture - */ - public long getTexture() { + public synchronized long getTexture() { if (texture == 0) { - texture = native_paintable_from_pixbuf(pixbuf); + texture = native_create_texture(snapshot, width, height); + snapshot = 0; } 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); + synchronized long getSnapshot() { + if (snapshot == 0) { + snapshot = native_create_snapshot(texture); texture = 0; } + return snapshot; + } + + public void eraseColor(int color) { + recycle(); + snapshot = native_erase_color(color, width, height); + texture = 0; + } + + public void recycle() { + native_recycle(texture, snapshot); + texture = 0; + snapshot = 0; + } + + public int getAllocationByteCount() { + return width * height * 4; + } + + public void prepareToDraw() { + getTexture(); + } + + @SuppressWarnings("deprecation") + @Override + protected void finalize() throws Throwable { + try { + recycle(); + } finally { + super.finalize(); + } } - //////////// 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); - 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); - private static native void nativeDestructor(int nativeBitmap); - private static native boolean nativeRecycle(long pixbuf, long texture); - private static native void nativeReconfigure(int nativeBitmap, int width, int height, - int config, int allocSize); - - private static native boolean nativeCompress(int nativeBitmap, int format, - int quality, OutputStream stream, - byte[] tempStorage); - private static native void nativeErase(int nativeBitmap, int color); - private static native int nativeRowBytes(long pixbuf); - private static native int nativeConfig(int nativeBitmap); - - private static native int nativeGetPixel(int nativeBitmap, int x, int y, - boolean isPremultiplied); - private static native void nativeGetPixels(long pixbuf, int[] pixels, - int offset, int stride, int x, int y, - int width, int height, boolean isPremultiplied); - - private static native void nativeSetPixel(int nativeBitmap, int x, int y, - int color, boolean isPremultiplied); - private static native void nativeSetPixels(int nativeBitmap, int[] colors, - int offset, int stride, int x, int y, - int width, int height, boolean isPremultiplied); - private static native void nativeCopyPixelsToBuffer(long pixbuf, Buffer dst); - private static native void nativeCopyPixelsFromBuffer(long pixbuf, Buffer src); - private static native int nativeGenerationId(int nativeBitmap); - - // returns a new bitmap built from the native bitmap's alpha, and the paint - private static native Bitmap nativeExtractAlpha(int nativeBitmap, - int nativePaint, - int[] offsetXY); - - private static native void nativePrepareToDraw(int nativeBitmap); - private static native void nativeSetAlphaAndPremultiplied(int nBitmap, boolean hasAlpha, - boolean isPremul); - private static native boolean nativeHasMipMap(int nativeBitmap); - private static native void nativeSetHasMipMap(int nBitmap, boolean hasMipMap); - private static native boolean nativeSameAs(int nb0, int nb1); - - /* package */ final int ni() { - return mNativeBitmap; - } + private static native long native_create_snapshot(long texture); + private static native long native_create_texture(long snapshot, int width, int height); + private static native int native_get_width(long texture); + private static native int native_get_height(long texture); + private static native long native_erase_color(int color, int width, int height); + private static native void native_recycle(long texture, long snapshot); } diff --git a/src/api-impl/android/graphics/BitmapFactory.java b/src/api-impl/android/graphics/BitmapFactory.java index a83de361..6261f914 100644 --- a/src/api-impl/android/graphics/BitmapFactory.java +++ b/src/api-impl/android/graphics/BitmapFactory.java @@ -16,8 +16,8 @@ package android.graphics; -import android.content.res.AssetManager; import android.content.res.Resources; +import android.content.res.Resources.NotFoundException; import android.os.Trace; import android.util.DisplayMetrics; import android.util.Log; @@ -442,10 +442,8 @@ public class BitmapFactory { * decoded, or, if opts is non-null, if opts requested only the * size be returned (in opts.outWidth and opts.outHeight) */ - public static Bitmap decodeResource(Resources res, int id, Options opts) { - String path = res.getString(id); - - return new Bitmap(path); + public static Bitmap decodeResource(Resources res, int id, Options opts) throws NotFoundException { + return decodeStreamInternal(res.openRawResource(id), null, opts); } /** @@ -456,7 +454,7 @@ public class BitmapFactory { * @param id The resource id of the image data * @return The decoded bitmap, or null if the image could not be decode. */ - public static Bitmap decodeResource(Resources res, int id) { + public static Bitmap decodeResource(Resources res, int id) throws NotFoundException { return decodeResource(res, id, null); } diff --git a/src/api-impl/android/graphics/Canvas.java b/src/api-impl/android/graphics/Canvas.java index 581528a7..2e6e0a22 100644 --- a/src/api-impl/android/graphics/Canvas.java +++ b/src/api-impl/android/graphics/Canvas.java @@ -3,43 +3,23 @@ package android.graphics; public class Canvas { public static final int HAS_ALPHA_LAYER_SAVE_FLAG = (1 << 2); - public long skia_canvas; - public long widget; + private Bitmap bitmap; + private GskCanvas gsk_canvas; public Canvas() {} public Canvas(Bitmap bmp) { - bmp.destroyTexture(); // invalidate cached texture - this.skia_canvas = native_canvas_from_bitmap(bmp.pixbuf); - this.widget = 0; + this.bitmap = bmp; + gsk_canvas = new GskCanvas(bmp.getSnapshot()); } - public Canvas(long skia_canvas, long widget) { - this.skia_canvas = skia_canvas; - this.widget = widget; - } - - @Override - @SuppressWarnings("deprecation") - protected void finalize() throws Throwable { - try { - super.finalize(); - } finally { - if (skia_canvas != 0) { - native_destroy_canvas(skia_canvas); - skia_canvas = 0; - } - } - } - - // FIXME: are these _needed_ ? - public int save() { - native_save(skia_canvas, widget); - return -1; // FIXME: wtf should we return + gsk_canvas.snapshot = bitmap.getSnapshot(); + return gsk_canvas.save(); } public void restore() { - native_restore(skia_canvas, widget); + gsk_canvas.snapshot = bitmap.getSnapshot(); + gsk_canvas.restore(); } // --- @@ -77,7 +57,8 @@ public class Canvas { * @param paint The paint used to draw the rect */ public void drawRect(float left, float top, float right, float bottom, Paint paint) { - native_drawRect(skia_canvas, left, top, right, bottom, paint.skia_paint); + gsk_canvas.snapshot = bitmap.getSnapshot(); + gsk_canvas.drawRect(left, top, right, bottom, paint); } // --- @@ -87,7 +68,8 @@ public class Canvas { * @param degrees The amount to rotate, in degrees */ public void rotate(float degrees) { - native_rotate(skia_canvas, widget, degrees); + gsk_canvas.snapshot = bitmap.getSnapshot(); + gsk_canvas.rotate(degrees); } /** @@ -98,7 +80,8 @@ public class Canvas { * @param py The y-coord for the pivot point (unchanged by the rotation) */ public void rotate(float degrees, float px, float py) { - native_rotate_and_translate(skia_canvas, widget, degrees, px, py); + gsk_canvas.snapshot = bitmap.getSnapshot(); + gsk_canvas.rotate(degrees, px, py); } // --- /** @@ -111,7 +94,8 @@ public class Canvas { * @param paint The paint used for the text (e.g. color, size, style) */ public void drawText(String text, float x, float y, Paint paint) { - native_drawText(skia_canvas, text, 0, text.length(), x, y, paint.skia_font, paint.skia_paint); + gsk_canvas.snapshot = bitmap.getSnapshot(); + gsk_canvas.drawText(text, x, y, paint); } /** @@ -202,7 +186,8 @@ public class Canvas { * @param sy The amount to scale in Y */ public /*native*/ void scale(float sx, float sy) { - native_scale(skia_canvas, sx, sy); + gsk_canvas.snapshot = bitmap.getSnapshot(); + gsk_canvas.scale(sx, sy); } /** @@ -240,13 +225,8 @@ 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) { - 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); + gsk_canvas.snapshot = this.bitmap.getSnapshot(); + gsk_canvas.drawBitmap(bitmap, left, top, paint); } /** @@ -272,15 +252,8 @@ public class Canvas { * @param paint May be null. The paint used to draw the bitmap */ public void drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) { - if (dst == null) { - throw new NullPointerException(); - } - if(src == null) { - src = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()); - } - 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); + gsk_canvas.snapshot = this.bitmap.getSnapshot(); + gsk_canvas.drawBitmap(bitmap, src, dst, paint); } /** @@ -398,20 +371,18 @@ public class Canvas { * @param paint The paint used to draw the line */ public void drawLine(float startX, float startY, float stopX, float stopY, Paint paint) { - native_drawLine(skia_canvas, widget, startX, startY, stopX, stopY, paint.skia_paint); + gsk_canvas.snapshot = bitmap.getSnapshot(); + gsk_canvas.drawLine(startX, startY, stopX, stopY, paint); } public void setBitmap(Bitmap bitmap) { - if (skia_canvas != 0) { - native_destroy_canvas(skia_canvas); - } - bitmap.destroyTexture(); // invalidate cached texture - this.skia_canvas = native_canvas_from_bitmap(bitmap.pixbuf); - this.widget = 0; + this.bitmap = bitmap; + gsk_canvas.snapshot = bitmap.getSnapshot(); } public void drawPath(Path path, Paint paint) { - native_drawPath(skia_canvas, path.mNativePath, paint.skia_paint); + gsk_canvas.snapshot = bitmap.getSnapshot(); + gsk_canvas.drawPath(path, paint); } public boolean clipPath(Path path) { @@ -492,19 +463,4 @@ public class Canvas { outRect.set(0, 0, 100, 100); return true; } - - 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_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); - private static native void native_drawPath(long skia_canvas, long path, long skia_paint); - private static native void native_destroy_canvas(long skia_canvas); - private static native void native_scale(long skia_canvas, float sx, float sy); } diff --git a/src/api-impl/android/graphics/GskCanvas.java b/src/api-impl/android/graphics/GskCanvas.java index b86fcfa6..cb85c2eb 100644 --- a/src/api-impl/android/graphics/GskCanvas.java +++ b/src/api-impl/android/graphics/GskCanvas.java @@ -52,7 +52,7 @@ public class GskCanvas extends Canvas { @Override public void drawPath(Path path, Paint paint) { - native_drawPath(snapshot, path.mNativePath, paint.skia_paint); + native_drawPath(snapshot, path.getGskPath(), paint.skia_paint); } @Override diff --git a/src/api-impl/android/graphics/Path.java b/src/api-impl/android/graphics/Path.java index 0991db59..8ab41ec2 100644 --- a/src/api-impl/android/graphics/Path.java +++ b/src/api-impl/android/graphics/Path.java @@ -1,736 +1,146 @@ -/* - * Copyright (C) 2006 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ package android.graphics; -// import android.view.HardwareRenderer; -/** - * The Path class encapsulates compound (multiple contour) geometric paths - * consisting of straight line segments, quadratic curves, and cubic curves. - * It can be drawn with canvas.drawPath(path, paint), either filled or stroked - * (based on the paint's Style), or it can be used for clipping or to draw - * text on a path. + +/* + * Path is implemented as a GskPath or a GskPathBuilder. It can only be one of the two at a time. + * The methods getGskPath() and getBuilder() automatically convert between the two as needed. */ public class Path { - /** - * @hide - */ - public final long mNativePath; - /** - * @hide - */ - public boolean isSimplePath = true; - /** - * @hide - */ - public Region rects; - private boolean mDetectSimplePaths; - private Direction mLastDirection = null; - /** - * Create an empty path - */ - public Path() { - mNativePath = init1(); - // mDetectSimplePaths = HardwareRenderer.isAvailable(); - } - /** - * Create a new path, copying the contents from the src path. - * - * @param src The path to copy from when initializing the new path - */ - public Path(Path src) { - long valNative = 0; - if (src != null) { - valNative = src.mNativePath; - isSimplePath = src.isSimplePath; - if (src.rects != null) { - rects = new Region(src.rects); - } - } - mNativePath = init2(valNative); - // mDetectSimplePaths = HardwareRenderer.isAvailable(); + + public enum FillType { + WINDING, + EVEN_ODD, } - /** - * Clear any lines and curves from the path, making it empty. - * This does NOT change the fill-type setting. - */ - public void reset() { - isSimplePath = true; - if (mDetectSimplePaths) { - mLastDirection = null; - if (rects != null) - rects.setEmpty(); - } - // We promised not to change this, so preserve it around the native - // call, which does now reset fill type. - final FillType fillType = getFillType(); - native_reset(mNativePath); - setFillType(fillType); + public enum Direction { + CW, + CCW, } - /** - * Rewinds the path: clears any lines and curves from the path but - * keeps the internal data structure for faster reuse. - */ - public void rewind() { - isSimplePath = true; - if (mDetectSimplePaths) { - mLastDirection = null; - if (rects != null) - rects.setEmpty(); - } - native_rewind(mNativePath); - } - /** - * Replace the contents of this with the contents of src. - */ - public void set(Path src) { - if (this != src) { - isSimplePath = src.isSimplePath; - native_set(mNativePath, src.mNativePath); - } - } - /** - * The logical operations that can be performed when combining two paths. - * - * @see #op(Path, android.graphics.Path.Op) - * @see #op(Path, Path, android.graphics.Path.Op) - */ + public enum Op { - /** - * Subtract the second path from the first path. - */ - DIFFERENCE, - /** - * Intersect the two paths. - */ INTERSECT, - /** - * Union (inclusive-or) the two paths. - */ UNION, - /** - * Exclusive-or the two paths. - */ - XOR, - /** - * Subtract the first path from the second path. - */ - REVERSE_DIFFERENCE } - /** - * Set this path to the result of applying the Op to this path and the specified path. - * The resulting path will be constructed from non-overlapping contours. - * The curve order is reduced where possible so that cubics may be turned - * into quadratics, and quadratics maybe turned into lines. - * - * @param path The second operand (for difference, the subtrahend) - * - * @return True if operation succeeded, false otherwise and this path remains unmodified. - * - * @see Op - * @see #op(Path, Path, android.graphics.Path.Op) - */ - public boolean op(Path path, Op op) { - return op(this, path, op); + + private long builder; + private long path; + + public Path() {} + + public Path(Path path) { + this.path = native_ref_path(path.getGskPath()); } - /** - * Set this path to the result of applying the Op to the two specified paths. - * The resulting path will be constructed from non-overlapping contours. - * The curve order is reduced where possible so that cubics may be turned - * into quadratics, and quadratics maybe turned into lines. - * - * @param path1 The first operand (for difference, the minuend) - * @param path2 The second operand (for difference, the subtrahend) - * - * @return True if operation succeeded, false otherwise and this path remains unmodified. - * - * @see Op - * @see #op(Path, android.graphics.Path.Op) - */ - public boolean op(Path path1, Path path2, Op op) { - if (native_op(path1.mNativePath, path2.mNativePath, op.ordinal(), this.mNativePath)) { - isSimplePath = false; - rects = null; - return true; + + private long getBuilder() { + if (builder == 0) { + builder = native_create_builder(path); + path = 0; } + return builder; + } + + long getGskPath() { + if (path == 0) { + path = native_create_path(builder); + builder = 0; + } + return path; + } + + public void reset() { + native_reset(path, builder); + path = 0; + builder = 0; + } + + public void rewind() { + reset(); + } + + public void close() { + native_close(getBuilder()); + } + + public void setFillType(FillType fillType) {} + + public void moveTo(float x, float y) { + native_move_to(getBuilder(), x, y); + } + + public void lineTo(float x, float y) { + native_line_to(getBuilder(), x, y); + } + + public void cubicTo(float x1, float y1, float x2, float y2, float x3, float y3) { + native_cubic_to(getBuilder(), x1, y1, x2, y2, x3, y3); + } + + public void quadTo(float x1, float y1, float x2, float y2) { + native_quad_to(getBuilder(), x1, y1, x2, y2); + } + + public void arcTo(RectF oval, float startAngle, float sweepAngle, boolean forceMoveTo) {} + + public void rMoveTo(float x, float y) { + native_rel_move_to(getBuilder(), x, y); + } + + public void rLineTo(float x, float y) { + native_rel_line_to(getBuilder(), x, y); + } + + public void rCubicTo(float x1, float y1, float x2, float y2, float x3, float y3) { + native_rel_cubic_to(getBuilder(), x1, y1, x2, y2, x3, y3); + } + + public void addPath(Path path, Matrix matrix) { + native_add_path(getBuilder(), path.getGskPath(), matrix.ni()); + } + + public void addRect(RectF rect, Direction direction) { + native_add_rect(getBuilder(), rect.left, rect.top, rect.right, rect.bottom); + } + + public void addRoundRect(RectF rect, float[] radii, Direction direction) {} + + public void addOval(RectF rect, Direction direction) {} + + public void transform(Matrix matrix) {} + + public void computeBounds(RectF bounds, boolean exact) { + native_get_bounds(getGskPath(), bounds); + } + + public boolean op(Path path, Op op) { return false; } - /** - * Enum for the ways a path may be filled. - */ - public enum FillType { - // these must match the values in SkPath.h - /** - * Specifies that "inside" is computed by a non-zero sum of signed - * edge crossings. - */ - WINDING(0), - /** - * Specifies that "inside" is computed by an odd number of edge - * crossings. - */ - EVEN_ODD(1), - /** - * Same as {@link #WINDING}, but draws outside of the path, rather than inside. - */ - INVERSE_WINDING(2), - /** - * Same as {@link #EVEN_ODD}, but draws outside of the path, rather than inside. - */ - INVERSE_EVEN_ODD(3); - FillType(int ni) { - nativeInt = ni; - } - final int nativeInt; - } - // these must be in the same order as their native values - static final FillType[] sFillTypeArray = { - FillType.WINDING, - FillType.EVEN_ODD, - FillType.INVERSE_WINDING, - FillType.INVERSE_EVEN_ODD}; - /** - * Return the path's fill type. This defines how "inside" is - * computed. The default value is WINDING. - * - * @return the path's fill type - */ - public FillType getFillType() { - return sFillTypeArray[native_getFillType(mNativePath)]; - } - /** - * Set the path's fill type. This defines how "inside" is computed. - * - * @param ft The new fill type for this path - */ - public void setFillType(FillType ft) { - native_setFillType(mNativePath, ft.nativeInt); - } - - /** - * Returns true if the filltype is one of the INVERSE variants - * - * @return true if the filltype is one of the INVERSE variants - */ - public boolean isInverseFillType() { - final int ft = native_getFillType(mNativePath); - return (ft & 2) != 0; - } - - /** - * Toggles the INVERSE state of the filltype - */ - public void toggleInverseFillType() { - int ft = native_getFillType(mNativePath); - ft ^= 2; - native_setFillType(mNativePath, ft); - } - - /** - * Returns true if the path is empty (contains no lines or curves) - * - * @return true if the path is empty (contains no lines or curves) - */ public boolean isEmpty() { - return native_isEmpty(mNativePath); - } - /** - * Returns true if the path specifies a rectangle. If so, and if rect is - * not null, set rect to the bounds of the path. If the path does not - * specify a rectangle, return false and ignore rect. - * - * @param rect If not null, returns the bounds of the path if it specifies - * a rectangle - * @return true if the path specifies a rectangle - */ - public boolean isRect(RectF rect) { - return native_isRect(mNativePath, rect); - } - /** - * Compute the bounds of the control points of the path, and write the - * answer into bounds. If the path contains 0 or 1 points, the bounds is - * set to (0,0,0,0) - * - * @param bounds Returns the computed bounds of the path's control points. - * @param exact This parameter is no longer used. - */ - @SuppressWarnings({"UnusedDeclaration"}) - public void computeBounds(RectF bounds, boolean exact) { - native_computeBounds(mNativePath, bounds); - } - /** - * Hint to the path to prepare for adding more points. This can allow the - * path to more efficiently allocate its storage. - * - * @param extraPtCount The number of extra points that may be added to this - * path - */ - public void incReserve(int extraPtCount) { - native_incReserve(mNativePath, extraPtCount); - } - /** - * Set the beginning of the next contour to the point (x,y). - * - * @param x The x-coordinate of the start of a new contour - * @param y The y-coordinate of the start of a new contour - */ - public void moveTo(float x, float y) { - native_moveTo(mNativePath, x, y); - } - /** - * Set the beginning of the next contour relative to the last point on the - * previous contour. If there is no previous contour, this is treated the - * same as moveTo(). - * - * @param dx The amount to add to the x-coordinate of the end of the - * previous contour, to specify the start of a new contour - * @param dy The amount to add to the y-coordinate of the end of the - * previous contour, to specify the start of a new contour - */ - public void rMoveTo(float dx, float dy) { - native_rMoveTo(mNativePath, dx, dy); - } - /** - * Add a line from the last point to the specified point (x,y). - * If no moveTo() call has been made for this contour, the first point is - * automatically set to (0,0). - * - * @param x The x-coordinate of the end of a line - * @param y The y-coordinate of the end of a line - */ - public void lineTo(float x, float y) { - isSimplePath = false; - native_lineTo(mNativePath, x, y); - } - /** - * Same as lineTo, but the coordinates are considered relative to the last - * point on this contour. If there is no previous point, then a moveTo(0,0) - * is inserted automatically. - * - * @param dx The amount to add to the x-coordinate of the previous point on - * this contour, to specify a line - * @param dy The amount to add to the y-coordinate of the previous point on - * this contour, to specify a line - */ - public void rLineTo(float dx, float dy) { - isSimplePath = false; - native_rLineTo(mNativePath, dx, dy); - } - /** - * Add a quadratic bezier from the last point, approaching control point - * (x1,y1), and ending at (x2,y2). If no moveTo() call has been made for - * this contour, the first point is automatically set to (0,0). - * - * @param x1 The x-coordinate of the control point on a quadratic curve - * @param y1 The y-coordinate of the control point on a quadratic curve - * @param x2 The x-coordinate of the end point on a quadratic curve - * @param y2 The y-coordinate of the end point on a quadratic curve - */ - public void quadTo(float x1, float y1, float x2, float y2) { - isSimplePath = false; - native_quadTo(mNativePath, x1, y1, x2, y2); - } - /** - * Same as quadTo, but the coordinates are considered relative to the last - * point on this contour. If there is no previous point, then a moveTo(0,0) - * is inserted automatically. - * - * @param dx1 The amount to add to the x-coordinate of the last point on - * this contour, for the control point of a quadratic curve - * @param dy1 The amount to add to the y-coordinate of the last point on - * this contour, for the control point of a quadratic curve - * @param dx2 The amount to add to the x-coordinate of the last point on - * this contour, for the end point of a quadratic curve - * @param dy2 The amount to add to the y-coordinate of the last point on - * this contour, for the end point of a quadratic curve - */ - public void rQuadTo(float dx1, float dy1, float dx2, float dy2) { - isSimplePath = false; - native_rQuadTo(mNativePath, dx1, dy1, dx2, dy2); - } - /** - * Add a cubic bezier from the last point, approaching control points - * (x1,y1) and (x2,y2), and ending at (x3,y3). If no moveTo() call has been - * made for this contour, the first point is automatically set to (0,0). - * - * @param x1 The x-coordinate of the 1st control point on a cubic curve - * @param y1 The y-coordinate of the 1st control point on a cubic curve - * @param x2 The x-coordinate of the 2nd control point on a cubic curve - * @param y2 The y-coordinate of the 2nd control point on a cubic curve - * @param x3 The x-coordinate of the end point on a cubic curve - * @param y3 The y-coordinate of the end point on a cubic curve - */ - public void cubicTo(float x1, float y1, float x2, float y2, - float x3, float y3) { - isSimplePath = false; - native_cubicTo(mNativePath, x1, y1, x2, y2, x3, y3); - } - /** - * Same as cubicTo, but the coordinates are considered relative to the - * current point on this contour. If there is no previous point, then a - * moveTo(0,0) is inserted automatically. - */ - public void rCubicTo(float x1, float y1, float x2, float y2, - float x3, float y3) { - isSimplePath = false; - native_rCubicTo(mNativePath, x1, y1, x2, y2, x3, y3); - } - /** - * Append the specified arc to the path as a new contour. If the start of - * the path is different from the path's current last point, then an - * automatic lineTo() is added to connect the current contour to the - * start of the arc. However, if the path is empty, then we call moveTo() - * with the first point of the arc. The sweep angle is tread mod 360. - * - * @param oval The bounds of oval defining shape and size of the arc - * @param startAngle Starting angle (in degrees) where the arc begins - * @param sweepAngle Sweep angle (in degrees) measured clockwise, treated - * mod 360. - * @param forceMoveTo If true, always begin a new contour with the arc - */ - public void arcTo(RectF oval, float startAngle, float sweepAngle, - boolean forceMoveTo) { - isSimplePath = false; - native_arcTo(mNativePath, oval, startAngle, sweepAngle, forceMoveTo); + return path == 0 && builder == 0; } - /** - * Append the specified arc to the path as a new contour. If the start of - * the path is different from the path's current last point, then an - * automatic lineTo() is added to connect the current contour to the - * start of the arc. However, if the path is empty, then we call moveTo() - * with the first point of the arc. - * - * @param oval The bounds of oval defining shape and size of the arc - * @param startAngle Starting angle (in degrees) where the arc begins - * @param sweepAngle Sweep angle (in degrees) measured clockwise - */ - public void arcTo(RectF oval, float startAngle, float sweepAngle) { - isSimplePath = false; - native_arcTo(mNativePath, oval, startAngle, sweepAngle, false); - } - - public void arcTo(float left, float top, float right, float bottom, float startAngle, float sweepAngle, boolean forceMoveTo) { - arcTo(new RectF(left, top, right, bottom), startAngle, sweepAngle, forceMoveTo); - } - - /** - * Close the current contour. If the current point is not equal to the - * first point of the contour, a line segment is automatically added. - */ - public void close() { - isSimplePath = false; - native_close(mNativePath); - } - /** - * Specifies how closed shapes (e.g. rects, ovals) are oriented when they - * are added to a path. - */ - public enum Direction { - /** - * clockwise - */ - CW(1), // must match enum in SkPath.h - /** - * counter-clockwise - */ - CCW(2); // must match enum in SkPath.h - - Direction(int ni) { - nativeInt = ni; - } - final int nativeInt; - } - - private void detectSimplePath(float left, float top, float right, float bottom, Direction dir) { - if (mDetectSimplePaths) { - if (mLastDirection == null) { - mLastDirection = dir; - } - if (mLastDirection != dir) { - isSimplePath = false; - } else { - if (rects == null) - rects = new Region(); - rects.op((int)left, (int)top, (int)right, (int)bottom, Region.Op.UNION); - } - } - } - /** - * Add a closed rectangle contour to the path - * - * @param rect The rectangle to add as a closed contour to the path - * @param dir The direction to wind the rectangle's contour - */ - public void addRect(RectF rect, Direction dir) { - if (rect == null) { - throw new NullPointerException("need rect parameter"); - } - detectSimplePath(rect.left, rect.top, rect.right, rect.bottom, dir); - native_addRect(mNativePath, rect, dir.nativeInt); - } - /** - * Add a closed rectangle contour to the path - * - * @param left The left side of a rectangle to add to the path - * @param top The top of a rectangle to add to the path - * @param right The right side of a rectangle to add to the path - * @param bottom The bottom of a rectangle to add to the path - * @param dir The direction to wind the rectangle's contour - */ - public void addRect(float left, float top, float right, float bottom, Direction dir) { - detectSimplePath(left, top, right, bottom, dir); - native_addRect(mNativePath, left, top, right, bottom, dir.nativeInt); - } - /** - * Add a closed oval contour to the path - * - * @param oval The bounds of the oval to add as a closed contour to the path - * @param dir The direction to wind the oval's contour - */ - public void addOval(RectF oval, Direction dir) { - if (oval == null) { - throw new NullPointerException("need oval parameter"); - } - isSimplePath = false; - native_addOval(mNativePath, oval, dir.nativeInt); - } - /** - * Add a closed circle contour to the path - * - * @param x The x-coordinate of the center of a circle to add to the path - * @param y The y-coordinate of the center of a circle to add to the path - * @param radius The radius of a circle to add to the path - * @param dir The direction to wind the circle's contour - */ - public void addCircle(float x, float y, float radius, Direction dir) { - isSimplePath = false; - native_addCircle(mNativePath, x, y, radius, dir.nativeInt); - } - /** - * Add the specified arc to the path as a new contour. - * - * @param oval The bounds of oval defining the shape and size of the arc - * @param startAngle Starting angle (in degrees) where the arc begins - * @param sweepAngle Sweep angle (in degrees) measured clockwise - */ - public void addArc(RectF oval, float startAngle, float sweepAngle) { - if (oval == null) { - throw new NullPointerException("need oval parameter"); - } - isSimplePath = false; - native_addArc(mNativePath, oval, startAngle, sweepAngle); - } - - /** - * Add a closed round-rectangle contour to the path - * - * @param rx The x-radius of the rounded corners on the round-rectangle - * @param ry The y-radius of the rounded corners on the round-rectangle - * @param dir The direction to wind the round-rectangle's contour - * - */ - public void addRoundRect(float left, float top, float right, float bottom, float rx, float ry, Direction dir) { - native_addRoundRect(mNativePath, left, top, right, bottom, rx, ry, dir.nativeInt); - } - - /** - * Add a closed round-rectangle contour to the path - * - * @param rect The bounds of a round-rectangle to add to the path - * @param rx The x-radius of the rounded corners on the round-rectangle - * @param ry The y-radius of the rounded corners on the round-rectangle - * @param dir The direction to wind the round-rectangle's contour - */ - public void addRoundRect(RectF rect, float rx, float ry, Direction dir) { - if (rect == null) { - throw new NullPointerException("need rect parameter"); - } - isSimplePath = false; - addRoundRect(rect.left, rect.top, rect.right, rect.bottom, rx, ry, dir); - } - - /** - * Add a closed round-rectangle contour to the path. Each corner receives - * two radius values [X, Y]. The corners are ordered top-left, top-right, - * bottom-right, bottom-left - * - * @param rect The bounds of a round-rectangle to add to the path - * @param radii Array of 8 values, 4 pairs of [X,Y] radii - * @param dir The direction to wind the round-rectangle's contour - */ - public void addRoundRect(RectF rect, float[] radii, Direction dir) { - if (rect == null) { - throw new NullPointerException("need rect parameter"); - } - if (radii.length < 8) { - throw new ArrayIndexOutOfBoundsException("radii[] needs 8 values"); - } - isSimplePath = false; - native_addRoundRect(mNativePath, rect, radii, dir.nativeInt); - } - - /** - * Add a copy of src to the path, offset by (dx,dy) - * - * @param src The path to add as a new contour - * @param dx The amount to translate the path in X as it is added - */ - public void addPath(Path src, float dx, float dy) { - isSimplePath = false; - native_addPath(mNativePath, src.mNativePath, dx, dy); - } - /** - * Add a copy of src to the path - * - * @param src The path that is appended to the current path - */ - public void addPath(Path src) { - isSimplePath = false; - native_addPath(mNativePath, src.mNativePath); - } - /** - * Add a copy of src to the path, transformed by matrix - * - * @param src The path to add as a new contour - */ - public void addPath(Path src, Matrix matrix) { - if (!src.isSimplePath) - isSimplePath = false; - native_addPath(mNativePath, src.mNativePath, matrix.native_instance); - } - /** - * Offset the path by (dx,dy), returning true on success - * - * @param dx The amount in the X direction to offset the entire path - * @param dy The amount in the Y direction to offset the entire path - * @param dst The translated path is written here. If this is null, then - * the original path is modified. - */ - public void offset(float dx, float dy, Path dst) { - long dstNative = 0; - if (dst != null) { - dstNative = dst.mNativePath; - dst.isSimplePath = false; - } - native_offset(mNativePath, dx, dy, dstNative); - } - /** - * Offset the path by (dx,dy), returning true on success - * - * @param dx The amount in the X direction to offset the entire path - * @param dy The amount in the Y direction to offset the entire path - */ - public void offset(float dx, float dy) { - isSimplePath = false; - native_offset(mNativePath, dx, dy); - } - /** - * Sets the last point of the path. - * - * @param dx The new X coordinate for the last point - * @param dy The new Y coordinate for the last point - */ - public void setLastPoint(float dx, float dy) { - isSimplePath = false; - native_setLastPoint(mNativePath, dx, dy); - } - /** - * Transform the points in this path by matrix, and write the answer - * into dst. If dst is null, then the the original path is modified. - * - * @param matrix The matrix to apply to the path - * @param dst The transformed path is written here. If dst is null, - * then the the original path is modified - */ - public void transform(Matrix matrix, Path dst) { - long dstNative = 0; - if (dst != null) { - dst.isSimplePath = false; - dstNative = dst.mNativePath; - } - native_transform(mNativePath, matrix.native_instance, dstNative); - } - /** - * Transform the points in this path by matrix. - * - * @param matrix The matrix to apply to the path - */ - public void transform(Matrix matrix) { - isSimplePath = false; - native_transform(mNativePath, matrix.native_instance); - } + @SuppressWarnings("deprecation") + @Override protected void finalize() throws Throwable { try { - finalizer(mNativePath); + reset(); } finally { super.finalize(); } } - final long ni() { - return mNativePath; - } - public boolean isConvex() { - return false; - } - private static native long init1(); - private static native long init2(long nPath); - private static native void native_reset(long nPath); - private static native void native_rewind(long nPath); - private static native void native_set(long native_dst, long native_src); - private static native int native_getFillType(long nPath); - private static native void native_setFillType(long nPath, int ft); - private static native boolean native_isEmpty(long nPath); - private static native boolean native_isRect(long nPath, RectF rect); - private static native void native_computeBounds(long nPath, RectF bounds); - private static native void native_incReserve(long nPath, int extraPtCount); - private static native void native_moveTo(long nPath, float x, float y); - private static native void native_rMoveTo(long nPath, float dx, float dy); - private static native void native_lineTo(long nPath, float x, float y); - private static native void native_rLineTo(long nPath, float dx, float dy); - private static native void native_quadTo(long nPath, float x1, float y1, - float x2, float y2); - private static native void native_rQuadTo(long nPath, float dx1, float dy1, - float dx2, float dy2); - private static native void native_cubicTo(long nPath, float x1, float y1, - float x2, float y2, float x3, float y3); - private static native void native_rCubicTo(long nPath, float x1, float y1, - float x2, float y2, float x3, float y3); - private static native void native_arcTo(long nPath, RectF oval, - float startAngle, float sweepAngle, boolean forceMoveTo); - private static native void native_close(long nPath); - private static native void native_addRect(long nPath, RectF rect, int dir); - private static native void native_addRect(long nPath, float left, float top, - float right, float bottom, int dir); - private static native void native_addOval(long nPath, RectF oval, int dir); - private static native void native_addCircle(long nPath, float x, float y, float radius, int dir); - private static native void native_addArc(long nPath, RectF oval, - float startAngle, float sweepAngle); - private static native void native_addRoundRect(long nPath, float left, float top, float right, float bottom, - float rx, float ry, int dir); - private static native void native_addRoundRect(long nPath, RectF r, float[] radii, int dir); - private static native void native_addPath(long nPath, long src, float dx, float dy); - private static native void native_addPath(long nPath, long src); - private static native void native_addPath(long nPath, long src, long matrix); - private static native void native_offset(long nPath, float dx, float dy, long dst_path); - private static native void native_offset(long nPath, float dx, float dy); - private static native void native_setLastPoint(long nPath, float dx, float dy); - private static native void native_transform(long nPath, long matrix, long dst_path); - private static native void native_transform(long nPath, long matrix); - private static native boolean native_op(long path1, long path2, int op, long result); - private static native void finalizer(long nPath); + private static native long native_create_builder(long path); + private static native long native_create_path(long builder); + private static native long native_ref_path(long path); + private static native void native_reset(long path, long builder); + private static native void native_close(long builder); + private static native void native_move_to(long builder, float x, float y); + private static native void native_line_to(long builder, float x, float y); + private static native void native_cubic_to(long builder, float x1, float y1, float x2, float y2, float x3, float y3); + private static native void native_quad_to(long builder, float x1, float y1, float x2, float y2); + private static native void native_rel_move_to(long builder, float x, float y); + private static native void native_rel_line_to(long builder, float x, float y); + private static native void native_rel_cubic_to(long builder, float x1, float y1, float x2, float y2, float x3, float y3); + private static native void native_add_path(long builder, long path, long matrix); + private static native void native_add_rect(long builder, float left, float top, float right, float bottom); + private static native void native_get_bounds(long path, RectF rect); } diff --git a/src/api-impl/android/graphics/Region.java b/src/api-impl/android/graphics/Region.java index d1b700dc..9181399f 100644 --- a/src/api-impl/android/graphics/Region.java +++ b/src/api-impl/android/graphics/Region.java @@ -99,7 +99,7 @@ public class Region { * (with no antialiasing). */ public boolean setPath(Path path, Region clip) { - return nativeSetPath(mNativeRegion, path.ni(), clip.mNativeRegion); + return nativeSetPath(mNativeRegion, path.getGskPath(), clip.mNativeRegion); } /** * Return true if this region is empty @@ -141,7 +141,7 @@ public class Region { */ public Path getBoundaryPath() { Path path = new Path(); - nativeGetBoundaryPath(mNativeRegion, path.ni()); + nativeGetBoundaryPath(mNativeRegion, path.getGskPath()); return path; } /** @@ -149,7 +149,7 @@ public class Region { * path will also be empty. */ public boolean getBoundaryPath(Path path) { - return nativeGetBoundaryPath(mNativeRegion, path.ni()); + return nativeGetBoundaryPath(mNativeRegion, path.getGskPath()); } /** diff --git a/src/api-impl/android/widget/ImageButton.java b/src/api-impl/android/widget/ImageButton.java index 8e2cbd9a..1c3c2281 100644 --- a/src/api-impl/android/widget/ImageButton.java +++ b/src/api-impl/android/widget/ImageButton.java @@ -20,8 +20,6 @@ public class ImageButton extends ImageView { @Override protected native long native_constructor(Context context, AttributeSet attrs); @Override - protected native void native_setPixbuf(long widget, long pixbuf); - @Override protected native void native_setDrawable(long widget, long paintable); @Override protected native void nativeSetOnClickListener(long widget); diff --git a/src/api-impl/android/widget/ImageView.java b/src/api-impl/android/widget/ImageView.java index 0b5efd9a..4b6eccc8 100644 --- a/src/api-impl/android/widget/ImageView.java +++ b/src/api-impl/android/widget/ImageView.java @@ -51,7 +51,7 @@ public class ImageView extends View { return; } bitmap = BitmapFactory.decodeResource(Context.this_application.getResources(), resid); - native_setPixbuf(widget, bitmap.pixbuf); + native_setDrawable(widget, bitmap.getTexture()); } public void setAdjustViewBounds(boolean adjustViewBounds) {} @@ -84,7 +84,7 @@ public class ImageView extends View { public void setImageBitmap(Bitmap bitmap) { if (bitmap != null) - native_setPixbuf(widget, bitmap.pixbuf); + native_setDrawable(widget, bitmap.getTexture()); } /** @@ -184,7 +184,6 @@ public class ImageView extends View { @Override protected native long native_constructor(Context context, AttributeSet attrs); - protected native void native_setPixbuf(long widget, long pixbuf); protected native void native_setDrawable(long widget, long paintable); protected native void native_setScaleType(long widget, int scale_type); }