implement android.graphics.Path using skia

This commit is contained in:
Julian Winkler 2024-03-24 20:17:24 +01:00
parent 35f26faa90
commit 3d9468aa9f
9 changed files with 327 additions and 162 deletions

View file

@ -98,6 +98,7 @@ libtranslationlayer_so = shared_library('translation_layer_main', [
'src/api-impl-jni/graphics/NinePatchPaintable.c',
'src/api-impl-jni/graphics/android_graphics_BitmapFactory.c',
'src/api-impl-jni/graphics/android_graphics_Matrix.c',
'src/api-impl-jni/graphics/android_graphics_Path.c',
'src/api-impl-jni/graphics/android_graphics_Typeface.c',
'src/api-impl-jni/graphics/android_graphics_Typeface.c',
'src/api-impl-jni/graphics/android_graphics_drawable_BitmapDrawable.c',

View file

@ -7,6 +7,7 @@
#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"
@ -105,3 +106,12 @@ JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1rotate_1and_1transla
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, long 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);
}

View file

@ -79,6 +79,14 @@ JNIEXPORT void JNICALL Java_android_graphics_Canvas_native_1rotate
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);
#ifdef __cplusplus
}
#endif

View file

@ -10,306 +10,306 @@ extern "C" {
/*
* Class: android_graphics_Path
* Method: init1
* Signature: ()I
* Signature: ()J
*/
JNIEXPORT jint JNICALL Java_android_graphics_Path_init1
JNIEXPORT jlong JNICALL Java_android_graphics_Path_init1
(JNIEnv *, jclass);
/*
* Class: android_graphics_Path
* Method: init2
* Signature: (I)I
* Signature: (J)J
*/
JNIEXPORT jint JNICALL Java_android_graphics_Path_init2
(JNIEnv *, jclass, jint);
JNIEXPORT jlong JNICALL Java_android_graphics_Path_init2
(JNIEnv *, jclass, jlong);
/*
* Class: android_graphics_Path
* Method: native_reset
* Signature: (I)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1reset
(JNIEnv *, jclass, jint);
(JNIEnv *, jclass, jlong);
/*
* Class: android_graphics_Path
* Method: native_rewind
* Signature: (I)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rewind
(JNIEnv *, jclass, jint);
(JNIEnv *, jclass, jlong);
/*
* Class: android_graphics_Path
* Method: native_set
* Signature: (II)V
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1set
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jlong, jlong);
/*
* Class: android_graphics_Path
* Method: native_getFillType
* Signature: (I)I
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_android_graphics_Path_native_1getFillType
(JNIEnv *, jclass, jint);
(JNIEnv *, jclass, jlong);
/*
* Class: android_graphics_Path
* Method: native_setFillType
* Signature: (II)V
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1setFillType
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jlong, jint);
/*
* Class: android_graphics_Path
* Method: native_isEmpty
* Signature: (I)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Path_native_1isEmpty
(JNIEnv *, jclass, jint);
(JNIEnv *, jclass, jlong);
/*
* Class: android_graphics_Path
* Method: native_isRect
* Signature: (ILandroid/graphics/RectF;)Z
* Signature: (JLandroid/graphics/RectF;)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Path_native_1isRect
(JNIEnv *, jclass, jint, jobject);
(JNIEnv *, jclass, jlong, jobject);
/*
* Class: android_graphics_Path
* Method: native_computeBounds
* Signature: (ILandroid/graphics/RectF;)V
* Signature: (JLandroid/graphics/RectF;)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1computeBounds
(JNIEnv *, jclass, jint, jobject);
(JNIEnv *, jclass, jlong, jobject);
/*
* Class: android_graphics_Path
* Method: native_incReserve
* Signature: (II)V
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1incReserve
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jlong, jint);
/*
* Class: android_graphics_Path
* Method: native_moveTo
* Signature: (IFF)V
* Signature: (JFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1moveTo
(JNIEnv *, jclass, jint, jfloat, jfloat);
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Path
* Method: native_rMoveTo
* Signature: (IFF)V
* Signature: (JFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rMoveTo
(JNIEnv *, jclass, jint, jfloat, jfloat);
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Path
* Method: native_lineTo
* Signature: (IFF)V
* Signature: (JFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1lineTo
(JNIEnv *, jclass, jint, jfloat, jfloat);
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Path
* Method: native_rLineTo
* Signature: (IFF)V
* Signature: (JFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rLineTo
(JNIEnv *, jclass, jint, jfloat, jfloat);
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Path
* Method: native_quadTo
* Signature: (IFFFF)V
* Signature: (JFFFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1quadTo
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat, jfloat);
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Path
* Method: native_rQuadTo
* Signature: (IFFFF)V
* Signature: (JFFFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rQuadTo
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat, jfloat);
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Path
* Method: native_cubicTo
* Signature: (IFFFFFF)V
* Signature: (JFFFFFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1cubicTo
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat);
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Path
* Method: native_rCubicTo
* Signature: (IFFFFFF)V
* Signature: (JFFFFFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rCubicTo
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat);
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Path
* Method: native_arcTo
* Signature: (ILandroid/graphics/RectF;FFZ)V
* Signature: (JLandroid/graphics/RectF;FFZ)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1arcTo
(JNIEnv *, jclass, jint, jobject, jfloat, jfloat, jboolean);
(JNIEnv *, jclass, jlong, jobject, jfloat, jfloat, jboolean);
/*
* Class: android_graphics_Path
* Method: native_close
* Signature: (I)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1close
(JNIEnv *, jclass, jint);
(JNIEnv *, jclass, jlong);
/*
* Class: android_graphics_Path
* Method: native_addRect
* Signature: (ILandroid/graphics/RectF;I)V
* Signature: (JLandroid/graphics/RectF;I)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addRect__ILandroid_graphics_RectF_2I
(JNIEnv *, jclass, jint, jobject, jint);
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: (IFFFFI)V
* Signature: (JFFFFI)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addRect__IFFFFI
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat, jfloat, jint);
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: (ILandroid/graphics/RectF;I)V
* Signature: (JLandroid/graphics/RectF;I)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addOval
(JNIEnv *, jclass, jint, jobject, jint);
(JNIEnv *, jclass, jlong, jobject, jint);
/*
* Class: android_graphics_Path
* Method: native_addCircle
* Signature: (IFFFI)V
* Signature: (JFFFI)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addCircle
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat, jint);
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jint);
/*
* Class: android_graphics_Path
* Method: native_addArc
* Signature: (ILandroid/graphics/RectF;FF)V
* Signature: (JLandroid/graphics/RectF;FF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addArc
(JNIEnv *, jclass, jint, jobject, jfloat, jfloat);
(JNIEnv *, jclass, jlong, jobject, jfloat, jfloat);
/*
* Class: android_graphics_Path
* Method: native_addRoundRect
* Signature: (ILandroid/graphics/RectF;FFI)V
* Signature: (JLandroid/graphics/RectF;FFI)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addRoundRect__ILandroid_graphics_RectF_2FFI
(JNIEnv *, jclass, jint, jobject, jfloat, jfloat, jint);
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addRoundRect__JLandroid_graphics_RectF_2FFI
(JNIEnv *, jclass, jlong, jobject, jfloat, jfloat, jint);
/*
* Class: android_graphics_Path
* Method: native_addRoundRect
* Signature: (ILandroid/graphics/RectF;[FI)V
* Signature: (JLandroid/graphics/RectF;[FI)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addRoundRect__ILandroid_graphics_RectF_2_3FI
(JNIEnv *, jclass, jint, jobject, jfloatArray, jint);
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: (IIFF)V
* Signature: (JJFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__IIFF
(JNIEnv *, jclass, jint, jint, jfloat, jfloat);
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__JJFF
(JNIEnv *, jclass, jlong, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Path
* Method: native_addPath
* Signature: (II)V
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__II
(JNIEnv *, jclass, jint, jint);
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__JJ
(JNIEnv *, jclass, jlong, jlong);
/*
* Class: android_graphics_Path
* Method: native_addPath
* Signature: (IIJ)V
* Signature: (JJJ)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__IIJ
(JNIEnv *, jclass, jint, jint, jlong);
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__JJJ
(JNIEnv *, jclass, jlong, jlong, jlong);
/*
* Class: android_graphics_Path
* Method: native_offset
* Signature: (IFFI)V
* Signature: (JFFJ)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1offset__IFFI
(JNIEnv *, jclass, jint, jfloat, jfloat, jint);
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1offset__JFFJ
(JNIEnv *, jclass, jlong, jfloat, jfloat, jlong);
/*
* Class: android_graphics_Path
* Method: native_offset
* Signature: (IFF)V
* Signature: (JFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1offset__IFF
(JNIEnv *, jclass, jint, jfloat, jfloat);
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1offset__JFF
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Path
* Method: native_setLastPoint
* Signature: (IFF)V
* Signature: (JFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1setLastPoint
(JNIEnv *, jclass, jint, jfloat, jfloat);
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Path
* Method: native_transform
* Signature: (IJI)V
* Signature: (JJJ)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1transform__IJI
(JNIEnv *, jclass, jint, jlong, jint);
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1transform__JJJ
(JNIEnv *, jclass, jlong, jlong, jlong);
/*
* Class: android_graphics_Path
* Method: native_transform
* Signature: (IJ)V
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1transform__IJ
(JNIEnv *, jclass, jint, jlong);
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1transform__JJ
(JNIEnv *, jclass, jlong, jlong);
/*
* Class: android_graphics_Path
* Method: native_op
* Signature: (IIII)Z
* Signature: (JJIJ)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Path_native_1op
(JNIEnv *, jclass, jint, jint, jint, jint);
(JNIEnv *, jclass, jlong, jlong, jint, jlong);
/*
* Class: android_graphics_Path
* Method: finalizer
* Signature: (I)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_finalizer
(JNIEnv *, jclass, jint);
(JNIEnv *, jclass, jlong);
#ifdef __cplusplus
}

View file

@ -116,10 +116,10 @@ JNIEXPORT jboolean JNICALL Java_android_graphics_Region_nativeSetRect
/*
* Class: android_graphics_Region
* Method: nativeSetPath
* Signature: (III)Z
* Signature: (IJI)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Region_nativeSetPath
(JNIEnv *, jclass, jint, jint, jint);
(JNIEnv *, jclass, jint, jlong, jint);
/*
* Class: android_graphics_Region
@ -132,10 +132,10 @@ JNIEXPORT jboolean JNICALL Java_android_graphics_Region_nativeGetBounds
/*
* Class: android_graphics_Region
* Method: nativeGetBoundaryPath
* Signature: (II)Z
* Signature: (IJ)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Region_nativeGetBoundaryPath
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jint, jlong);
/*
* Class: android_graphics_Region

View file

@ -0,0 +1,148 @@
#include "../sk_area/include/c/sk_path.h"
#include <graphene.h>
#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)
{
return _INTPTR(sk_path_new());
}
JNIEXPORT jlong JNICALL Java_android_graphics_Path_init2(JNIEnv *env, jclass class, jlong path_ptr)
{
sk_path_t *path = (sk_path_t *)_PTR(path_ptr);
return _INTPTR(sk_path_clone(path));
}
JNIEXPORT void JNICALL Java_android_graphics_Path_finalizer(JNIEnv *env, jclass class, jlong path_ptr)
{
sk_path_t *path = (sk_path_t *)_PTR(path_ptr);
if (path_ptr != -1)
sk_path_delete(path);
}
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)
{
sk_path_t *path = (sk_path_t *)_PTR(path_ptr);
sk_path_rcubic_to(path, x1, y1, x2, y2, x3, y3);
}
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rLineTo(JNIEnv *env, jclass class, jlong path_ptr, jfloat x, jfloat y)
{
sk_path_t *path = (sk_path_t *)_PTR(path_ptr);
sk_path_rline_to(path, x, y);
}
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)
{
sk_path_t *path = (sk_path_t *)_PTR(path_ptr);
sk_path_cubic_to(path, x1, y1, x2, y2, x3, y3);
}
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__JJJ(JNIEnv *env, jclass class, jlong path_ptr, jlong src_ptr, jlong matrix)
{
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 jint JNICALL Java_android_graphics_Path_native_1getFillType(JNIEnv *env, jclass class, jlong path_ptr)
{
sk_path_t *path = (sk_path_t *)_PTR(path_ptr);
return sk_path_get_filltype(path);
}
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1reset(JNIEnv *env, jclass class, jlong path_ptr)
{
sk_path_t *path = (sk_path_t *)_PTR(path_ptr);
sk_path_reset(path);
}
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1setFillType(JNIEnv *env, jclass class, jlong path_ptr, jint ft)
{
sk_path_t *path = (sk_path_t *)_PTR(path_ptr);
sk_path_set_filltype(path, ft);
}
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1moveTo(JNIEnv *env, jclass class, jlong path_ptr, jfloat x, jfloat y)
{
sk_path_t *path = (sk_path_t *)_PTR(path_ptr);
sk_path_move_to(path, x, y);
}
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1close(JNIEnv *env, jclass class, jlong path_ptr)
{
sk_path_t *path = (sk_path_t *)_PTR(path_ptr);
sk_path_close(path);
}
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1lineTo(JNIEnv *env, jclass class, jlong path_ptr, jfloat x, jfloat y)
{
sk_path_t *path = (sk_path_t *)_PTR(path_ptr);
sk_path_line_to(path, x, y);
}
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1rewind(JNIEnv *env, jclass class, jlong path_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);
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[1], v[3], v[4], v[5], v[7], v[12], v[13], v[15]};
sk_path_transform(path, &m);
}
JNIEXPORT jboolean JNICALL Java_android_graphics_Path_native_1op(JNIEnv *env, jclass class, jlong path_ptr, jlong other_ptr, jint op, jlong result_ptr)
{
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);
}

View file

@ -382,7 +382,9 @@ public class Canvas {
public void setBitmap(Bitmap bitmap) {}
public void drawPath(Path path, Paint paint) {}
public void drawPath(Path path, Paint paint) {
native_drawPath(skia_canvas, path.mNativePath, paint.skia_paint);
}
public boolean clipPath(Path path) {
return false;
@ -401,4 +403,5 @@ public class Canvas {
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);
}

View file

@ -26,7 +26,7 @@ public class Path {
/**
* @hide
*/
public final int mNativePath;
public final long mNativePath;
/**
* @hide
*/
@ -41,10 +41,8 @@ public class Path {
* Create an empty path
*/
public Path() {
mNativePath = -1; /*
mNativePath = init1();
mDetectSimplePaths = HardwareRenderer.isAvailable();
*/
mNativePath = init1();
// mDetectSimplePaths = HardwareRenderer.isAvailable();
}
/**
* Create a new path, copying the contents from the src path.
@ -52,18 +50,16 @@ public class Path {
* @param src The path to copy from when initializing the new path
*/
public Path(Path src) {
mNativePath = -1; /*
int 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();
*/
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();
}
/**
@ -80,7 +76,7 @@ mDetectSimplePaths = HardwareRenderer.isAvailable();
// 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);
native_reset(mNativePath);
setFillType(fillType);
}
/**
@ -213,8 +209,7 @@ mDetectSimplePaths = HardwareRenderer.isAvailable();
* @return the path's fill type
*/
public FillType getFillType() {
return FillType.WINDING;
// return sFillTypeArray[native_getFillType(mNativePath)];
return sFillTypeArray[native_getFillType(mNativePath)];
}
/**
* Set the path's fill type. This defines how "inside" is computed.
@ -222,7 +217,7 @@ mDetectSimplePaths = HardwareRenderer.isAvailable();
* @param ft The new fill type for this path
*/
public void setFillType(FillType ft) {
// native_setFillType(mNativePath, ft.nativeInt);
native_setFillType(mNativePath, ft.nativeInt);
}
/**
@ -293,7 +288,7 @@ mDetectSimplePaths = HardwareRenderer.isAvailable();
* @param y The y-coordinate of the start of a new contour
*/
public void moveTo(float x, float y) {
// native_moveTo(mNativePath, x, y);
native_moveTo(mNativePath, x, y);
}
/**
* Set the beginning of the next contour relative to the last point on the
@ -318,7 +313,7 @@ mDetectSimplePaths = HardwareRenderer.isAvailable();
*/
public void lineTo(float x, float y) {
isSimplePath = false;
// native_lineTo(mNativePath, x, y);
native_lineTo(mNativePath, x, y);
}
/**
* Same as lineTo, but the coordinates are considered relative to the last
@ -346,7 +341,7 @@ mDetectSimplePaths = HardwareRenderer.isAvailable();
*/
public void quadTo(float x1, float y1, float x2, float y2) {
isSimplePath = false;
// native_quadTo(mNativePath, x1, y1, x2, y2);
native_quadTo(mNativePath, x1, y1, x2, y2);
}
/**
* Same as quadTo, but the coordinates are considered relative to the last
@ -434,7 +429,7 @@ mDetectSimplePaths = HardwareRenderer.isAvailable();
*/
public void close() {
isSimplePath = false;
// native_close(mNativePath);
native_close(mNativePath);
}
/**
* Specifies how closed shapes (e.g. rects, ovals) are oriented when they
@ -609,7 +604,7 @@ mDetectSimplePaths = HardwareRenderer.isAvailable();
* the original path is modified.
*/
public void offset(float dx, float dy, Path dst) {
int dstNative = 0;
long dstNative = 0;
if (dst != null) {
dstNative = dst.mNativePath;
dst.isSimplePath = false;
@ -645,7 +640,7 @@ mDetectSimplePaths = HardwareRenderer.isAvailable();
* then the the original path is modified
*/
public void transform(Matrix matrix, Path dst) {
int dstNative = 0;
long dstNative = 0;
if (dst != null) {
dst.isSimplePath = false;
dstNative = dst.mNativePath;
@ -663,58 +658,58 @@ mDetectSimplePaths = HardwareRenderer.isAvailable();
}
protected void finalize() throws Throwable {
try {
// finalizer(mNativePath);
finalizer(mNativePath);
} finally {
super.finalize();
}
}
final int ni() {
final long ni() {
return mNativePath;
}
private static native int init1();
private static native int init2(int nPath);
private static native void native_reset(int nPath);
private static native void native_rewind(int nPath);
private static native void native_set(int native_dst, int native_src);
private static native int native_getFillType(int nPath);
private static native void native_setFillType(int nPath, int ft);
private static native boolean native_isEmpty(int nPath);
private static native boolean native_isRect(int nPath, RectF rect);
private static native void native_computeBounds(int nPath, RectF bounds);
private static native void native_incReserve(int nPath, int extraPtCount);
private static native void native_moveTo(int nPath, float x, float y);
private static native void native_rMoveTo(int nPath, float dx, float dy);
private static native void native_lineTo(int nPath, float x, float y);
private static native void native_rLineTo(int nPath, float dx, float dy);
private static native void native_quadTo(int nPath, float x1, float y1,
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(int nPath, float dx1, float dy1,
private static native void native_rQuadTo(long nPath, float dx1, float dy1,
float dx2, float dy2);
private static native void native_cubicTo(int nPath, float x1, float y1,
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(int nPath, float x1, float y1,
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(int nPath, RectF oval,
private static native void native_arcTo(long nPath, RectF oval,
float startAngle, float sweepAngle, boolean forceMoveTo);
private static native void native_close(int nPath);
private static native void native_addRect(int nPath, RectF rect, int dir);
private static native void native_addRect(int nPath, float left, float top,
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(int nPath, RectF oval, int dir);
private static native void native_addCircle(int nPath, float x, float y, float radius, int dir);
private static native void native_addArc(int nPath, RectF oval,
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(int nPath, RectF rect,
private static native void native_addRoundRect(long nPath, RectF rect,
float rx, float ry, int dir);
private static native void native_addRoundRect(int nPath, RectF r, float[] radii, int dir);
private static native void native_addPath(int nPath, int src, float dx, float dy);
private static native void native_addPath(int nPath, int src);
private static native void native_addPath(int nPath, int src, long matrix);
private static native void native_offset(int nPath, float dx, float dy, int dst_path);
private static native void native_offset(int nPath, float dx, float dy);
private static native void native_setLastPoint(int nPath, float dx, float dy);
private static native void native_transform(int nPath, long matrix, int dst_path);
private static native void native_transform(int nPath, long matrix);
private static native boolean native_op(int path1, int path2, int op, int result);
private static native void finalizer(int nPath);
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);
}

View file

@ -335,11 +335,11 @@ public class Region {
private static native void nativeSetRegion(int native_dst, int native_src);
private static native boolean nativeSetRect(int native_dst, int left,
int top, int right, int bottom);
private static native boolean nativeSetPath(int native_dst, int native_path,
private static native boolean nativeSetPath(int native_dst, long native_path,
int native_clip);
private static native boolean nativeGetBounds(int native_region, Rect rect);
private static native boolean nativeGetBoundaryPath(int native_region,
int native_path);
long native_path);
private static native boolean nativeOp(int native_dst, int left, int top,
int right, int bottom, int op);
private static native boolean nativeOp(int native_dst, Rect rect,