implement android.graphics.Matrix and View.getMatrix()

This is needed for androidx CoordinatorLayout and will also be required
for VectorDrawables
This commit is contained in:
Julian Winkler
2024-03-13 22:51:34 +01:00
parent f852c2bbc9
commit 796742c0fc
10 changed files with 369 additions and 180 deletions

View File

@@ -30,6 +30,8 @@
#define _GET_INT_FIELD(object, field) ((*env)->GetIntField(env, object, _FIELD_ID(_CLASS(object), field, "I")))
#define _SET_BOOL_FIELD(object, field, value) ((*env)->SetBooleanField(env, object, _FIELD_ID(_CLASS(object), field, "Z"), value))
#define _GET_BOOL_FIELD(object, field) ((*env)->GetBooleanField(env, object, _FIELD_ID(_CLASS(object), field, "Z")))
#define _GET_FLOAT_FIELD(object, field) ((*env)->GetFloatField(env, object, _FIELD_ID(_CLASS(object), field, "F")))
#define _SET_FLOAT_FIELD(object, field, value) ((*env)->SetFloatField(env, object, _FIELD_ID(_CLASS(object), field, "F"), value))
#define _SET_STATIC_INT_FIELD(class, field, value) ((*env)->SetStaticIntField(env, class, _STATIC_FIELD_ID(class, field, "I"), value))
#define _SET_STATIC_OBJ_FIELD(class, field, type, value) ((*env)->SetStaticObjectField(env, class, _STATIC_FIELD_ID(class, field, type), value))
#define _GET_STATIC_OBJ_FIELD(class, field, type) ((*env)->GetStaticObjectField(env, class, _STATIC_FIELD_ID(class, field, type)))

View File

@@ -25,325 +25,333 @@ extern "C" {
#define android_graphics_Matrix_MPERSP_1 7L
#undef android_graphics_Matrix_MPERSP_2
#define android_graphics_Matrix_MPERSP_2 8L
/*
* Class: android_graphics_Matrix
* Method: native_create
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_android_graphics_Matrix_native_1create
(JNIEnv *, jclass, jlong);
/*
* Class: android_graphics_Matrix
* Method: native_isIdentity
* Signature: (I)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1isIdentity
(JNIEnv *, jclass, jint);
(JNIEnv *, jclass, jlong);
/*
* Class: android_graphics_Matrix
* Method: native_rectStaysRect
* Signature: (I)Z
* Signature: (J)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1rectStaysRect
(JNIEnv *, jclass, jint);
(JNIEnv *, jclass, jlong);
/*
* Class: android_graphics_Matrix
* Method: native_reset
* Signature: (I)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1reset
(JNIEnv *, jclass, jint);
(JNIEnv *, jclass, jlong);
/*
* Class: android_graphics_Matrix
* Method: native_set
* Signature: (II)V
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1set
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jlong, jlong);
/*
* Class: android_graphics_Matrix
* Method: native_setTranslate
* Signature: (IFF)V
* Signature: (JFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setTranslate
(JNIEnv *, jclass, jint, jfloat, jfloat);
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_setScale
* Signature: (IFFFF)V
* Signature: (JFFFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setScale__IFFFF
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat, jfloat);
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setScale__JFFFF
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_setScale
* Signature: (IFF)V
* Signature: (JFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setScale__IFF
(JNIEnv *, jclass, jint, jfloat, jfloat);
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setScale__JFF
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_setRotate
* Signature: (IFFF)V
* Signature: (JFFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setRotate__IFFF
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat);
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setRotate__JFFF
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_setRotate
* Signature: (IF)V
* Signature: (JF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setRotate__IF
(JNIEnv *, jclass, jint, jfloat);
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setRotate__JF
(JNIEnv *, jclass, jlong, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_setSinCos
* Signature: (IFFFF)V
* Signature: (JFFFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setSinCos__IFFFF
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat, jfloat);
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setSinCos__JFFFF
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_setSinCos
* Signature: (IFF)V
* Signature: (JFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setSinCos__IFF
(JNIEnv *, jclass, jint, jfloat, jfloat);
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setSinCos__JFF
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_setSkew
* Signature: (IFFFF)V
* Signature: (JFFFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setSkew__IFFFF
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat, jfloat);
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setSkew__JFFFF
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_setSkew
* Signature: (IFF)V
* Signature: (JFF)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setSkew__IFF
(JNIEnv *, jclass, jint, jfloat, jfloat);
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setSkew__JFF
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_setConcat
* Signature: (III)Z
* Signature: (JJJ)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1setConcat
(JNIEnv *, jclass, jint, jint, jint);
(JNIEnv *, jclass, jlong, jlong, jlong);
/*
* Class: android_graphics_Matrix
* Method: native_preTranslate
* Signature: (IFF)Z
* Signature: (JFF)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preTranslate
(JNIEnv *, jclass, jint, jfloat, jfloat);
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_preScale
* Signature: (IFFFF)Z
* Signature: (JFFFF)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preScale__IFFFF
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat, jfloat);
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preScale__JFFFF
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_preScale
* Signature: (IFF)Z
* Signature: (JFF)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preScale__IFF
(JNIEnv *, jclass, jint, jfloat, jfloat);
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preScale__JFF
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_preRotate
* Signature: (IFFF)Z
* Signature: (JFFF)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preRotate__IFFF
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat);
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preRotate__JFFF
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_preRotate
* Signature: (IF)Z
* Signature: (JF)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preRotate__IF
(JNIEnv *, jclass, jint, jfloat);
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preRotate__JF
(JNIEnv *, jclass, jlong, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_preSkew
* Signature: (IFFFF)Z
* Signature: (JFFFF)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preSkew__IFFFF
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat, jfloat);
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preSkew__JFFFF
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_preSkew
* Signature: (IFF)Z
* Signature: (JFF)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preSkew__IFF
(JNIEnv *, jclass, jint, jfloat, jfloat);
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preSkew__JFF
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_preConcat
* Signature: (II)Z
* Signature: (JJ)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preConcat
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jlong, jlong);
/*
* Class: android_graphics_Matrix
* Method: native_postTranslate
* Signature: (IFF)Z
* Signature: (JFF)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postTranslate
(JNIEnv *, jclass, jint, jfloat, jfloat);
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_postScale
* Signature: (IFFFF)Z
* Signature: (JFFFF)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postScale__IFFFF
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat, jfloat);
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postScale__JFFFF
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_postScale
* Signature: (IFF)Z
* Signature: (JFF)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postScale__IFF
(JNIEnv *, jclass, jint, jfloat, jfloat);
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postScale__JFF
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_postRotate
* Signature: (IFFF)Z
* Signature: (JFFF)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postRotate__IFFF
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat);
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postRotate__JFFF
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_postRotate
* Signature: (IF)Z
* Signature: (JF)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postRotate__IF
(JNIEnv *, jclass, jint, jfloat);
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postRotate__JF
(JNIEnv *, jclass, jlong, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_postSkew
* Signature: (IFFFF)Z
* Signature: (JFFFF)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postSkew__IFFFF
(JNIEnv *, jclass, jint, jfloat, jfloat, jfloat, jfloat);
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postSkew__JFFFF
(JNIEnv *, jclass, jlong, jfloat, jfloat, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_postSkew
* Signature: (IFF)Z
* Signature: (JFF)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postSkew__IFF
(JNIEnv *, jclass, jint, jfloat, jfloat);
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postSkew__JFF
(JNIEnv *, jclass, jlong, jfloat, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_postConcat
* Signature: (II)Z
* Signature: (JJ)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postConcat
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jlong, jlong);
/*
* Class: android_graphics_Matrix
* Method: native_setRectToRect
* Signature: (ILandroid/graphics/RectF;Landroid/graphics/RectF;I)Z
* Signature: (JLandroid/graphics/RectF;Landroid/graphics/RectF;I)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1setRectToRect
(JNIEnv *, jclass, jint, jobject, jobject, jint);
(JNIEnv *, jclass, jlong, jobject, jobject, jint);
/*
* Class: android_graphics_Matrix
* Method: native_setPolyToPoly
* Signature: (I[FI[FII)Z
* Signature: (J[FI[FII)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1setPolyToPoly
(JNIEnv *, jclass, jint, jfloatArray, jint, jfloatArray, jint, jint);
(JNIEnv *, jclass, jlong, jfloatArray, jint, jfloatArray, jint, jint);
/*
* Class: android_graphics_Matrix
* Method: native_invert
* Signature: (II)Z
* Signature: (JJ)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1invert
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jlong, jlong);
/*
* Class: android_graphics_Matrix
* Method: native_mapPoints
* Signature: (I[FI[FIIZ)V
* Signature: (J[FI[FIIZ)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1mapPoints
(JNIEnv *, jclass, jint, jfloatArray, jint, jfloatArray, jint, jint, jboolean);
(JNIEnv *, jclass, jlong, jfloatArray, jint, jfloatArray, jint, jint, jboolean);
/*
* Class: android_graphics_Matrix
* Method: native_mapRect
* Signature: (ILandroid/graphics/RectF;Landroid/graphics/RectF;)Z
* Signature: (JLandroid/graphics/RectF;Landroid/graphics/RectF;)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1mapRect
(JNIEnv *, jclass, jint, jobject, jobject);
(JNIEnv *, jclass, jlong, jobject, jobject);
/*
* Class: android_graphics_Matrix
* Method: native_mapRadius
* Signature: (IF)F
* Signature: (JF)F
*/
JNIEXPORT jfloat JNICALL Java_android_graphics_Matrix_native_1mapRadius
(JNIEnv *, jclass, jint, jfloat);
(JNIEnv *, jclass, jlong, jfloat);
/*
* Class: android_graphics_Matrix
* Method: native_getValues
* Signature: (I[F)V
* Signature: (J[F)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1getValues
(JNIEnv *, jclass, jint, jfloatArray);
(JNIEnv *, jclass, jlong, jfloatArray);
/*
* Class: android_graphics_Matrix
* Method: native_setValues
* Signature: (I[F)V
* Signature: (J[F)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setValues
(JNIEnv *, jclass, jint, jfloatArray);
(JNIEnv *, jclass, jlong, jfloatArray);
/*
* Class: android_graphics_Matrix
* Method: native_equals
* Signature: (II)Z
* Signature: (JJ)Z
*/
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1equals
(JNIEnv *, jclass, jint, jint);
(JNIEnv *, jclass, jlong, jlong);
/*
* Class: android_graphics_Matrix
* Method: finalizer
* Signature: (I)V
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Matrix_finalizer
(JNIEnv *, jclass, jint);
(JNIEnv *, jclass, jlong);
#ifdef __cplusplus
}

View File

@@ -250,10 +250,10 @@ JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__II
/*
* Class: android_graphics_Path
* Method: native_addPath
* Signature: (III)V
* Signature: (IIJ)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__III
(JNIEnv *, jclass, jint, jint, jint);
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1addPath__IIJ
(JNIEnv *, jclass, jint, jint, jlong);
/*
* Class: android_graphics_Path
@@ -282,18 +282,18 @@ JNIEXPORT void JNICALL Java_android_graphics_Path_native_1setLastPoint
/*
* Class: android_graphics_Path
* Method: native_transform
* Signature: (III)V
* Signature: (IJI)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1transform__III
(JNIEnv *, jclass, jint, jint, jint);
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1transform__IJI
(JNIEnv *, jclass, jint, jlong, jint);
/*
* Class: android_graphics_Path
* Method: native_transform
* Signature: (II)V
* Signature: (IJ)V
*/
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1transform__II
(JNIEnv *, jclass, jint, jint);
JNIEXPORT void JNICALL Java_android_graphics_Path_native_1transform__IJ
(JNIEnv *, jclass, jint, jlong);
/*
* Class: android_graphics_Path

View File

@@ -319,6 +319,14 @@ JNIEXPORT void JNICALL Java_android_view_View_native_1setVisibility
JNIEXPORT void JNICALL Java_android_view_View_setOnLongClickListener
(JNIEnv *, jobject, jobject);
/*
* Class: android_view_View
* Method: native_getMatrix
* Signature: (JJ)Z
*/
JNIEXPORT jboolean JNICALL Java_android_view_View_native_1getMatrix
(JNIEnv *, jobject, jlong, jlong);
/*
* Class: android_view_View
* Method: native_getGlobalVisibleRect

View File

@@ -0,0 +1,167 @@
#include <graphene.h>
#include <stdint.h>
#include "../defines.h"
#include "../util.h"
#include "../generated_headers/android_graphics_Matrix.h"
JNIEXPORT jlong JNICALL Java_android_graphics_Matrix_native_1create(JNIEnv *env, jclass class, jlong src)
{
return _INTPTR(graphene_matrix_init_identity(graphene_matrix_alloc()));
}
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1getValues(JNIEnv *env, jclass class, jlong src, jfloatArray values_ref)
{
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(src);
jfloat *value = (*env)->GetFloatArrayElements(env, values_ref, NULL);
value[android_graphics_Matrix_MSCALE_X] = graphene_matrix_get_value(matrix, 0, 0);
value[android_graphics_Matrix_MSKEW_X] = graphene_matrix_get_value(matrix, 0, 1);
value[android_graphics_Matrix_MTRANS_X] = graphene_matrix_get_value(matrix, 0, 3);
value[android_graphics_Matrix_MSKEW_Y] = graphene_matrix_get_value(matrix, 1, 0);
value[android_graphics_Matrix_MSCALE_Y] = graphene_matrix_get_value(matrix, 1, 1);
value[android_graphics_Matrix_MTRANS_Y] = graphene_matrix_get_value(matrix, 1, 3);
value[android_graphics_Matrix_MPERSP_0] = graphene_matrix_get_value(matrix, 3, 0);
value[android_graphics_Matrix_MPERSP_1] = graphene_matrix_get_value(matrix, 3, 1);
value[android_graphics_Matrix_MPERSP_2] = graphene_matrix_get_value(matrix, 3, 3);
(*env)->ReleaseFloatArrayElements(env, values_ref, value, 0);
}
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1set(JNIEnv *env, jclass class, jlong dest_ptr, jlong src_ptr)
{
graphene_matrix_t *dest = (graphene_matrix_t *)_PTR(dest_ptr);
graphene_matrix_t *src = (graphene_matrix_t *)_PTR(src_ptr);
graphene_matrix_init_from_matrix(dest, src);
}
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1isIdentity(JNIEnv *env, jclass class, jlong matrix_ptr)
{
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr);
return graphene_matrix_is_identity(matrix);
}
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1preConcat(JNIEnv *env, jclass class, jlong matrix_ptr, jlong other_ptr)
{
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr);
graphene_matrix_t *other = (graphene_matrix_t *)_PTR(other_ptr);
graphene_matrix_multiply(matrix, other, matrix);
return true;
}
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1mapRect(JNIEnv *env, jclass class, jlong matrix_ptr, jobject dest, jobject src)
{
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr);
graphene_rect_t src_rect = GRAPHENE_RECT_INIT(
_GET_FLOAT_FIELD(src, "left"),
_GET_FLOAT_FIELD(src, "top"),
_GET_FLOAT_FIELD(src, "right") - _GET_FLOAT_FIELD(src, "left"),
_GET_FLOAT_FIELD(src, "bottom") - _GET_FLOAT_FIELD(src, "top")
);
graphene_quad_t dest_quad;
graphene_matrix_transform_rect(matrix, &src_rect, &dest_quad);
graphene_rect_t dest_rect;
graphene_quad_bounds(&dest_quad, &dest_rect);
_SET_FLOAT_FIELD(dest, "left", dest_rect.origin.x);
_SET_FLOAT_FIELD(dest, "top", dest_rect.origin.y);
_SET_FLOAT_FIELD(dest, "right", dest_rect.origin.x + dest_rect.size.width);
_SET_FLOAT_FIELD(dest, "bottom", dest_rect.origin.y + dest_rect.size.height);
return true;
}
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1reset(JNIEnv *env, jclass class, jlong matrix_ptr)
{
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr);
graphene_matrix_init_identity(matrix);
}
JNIEXPORT void JNICALL Java_android_graphics_Matrix_finalizer(JNIEnv *env, jclass class, jlong matrix_ptr)
{
graphene_matrix_free((graphene_matrix_t *)_PTR(matrix_ptr));
}
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postTranslate(JNIEnv *env, jclass class, jlong matrix_ptr, jfloat x, jfloat y)
{
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr);
graphene_point3d_t translation = GRAPHENE_POINT3D_INIT(x, y, 0);
graphene_matrix_translate(matrix, &translation);
return true;
}
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postScale__JFF(JNIEnv *env, jclass class, jlong matrix_ptr, jfloat x, jfloat y)
{
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr);
graphene_matrix_scale(matrix, x, y, 1.f);
return true;
}
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postRotate__JFFF(JNIEnv *env, jclass class, jlong matrix_ptr, jfloat degrees, jfloat px, jfloat py)
{
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr);
graphene_matrix_translate(matrix, &GRAPHENE_POINT3D_INIT(-px, -py, 0));
graphene_matrix_rotate_z(matrix, degrees);
graphene_matrix_translate(matrix, &GRAPHENE_POINT3D_INIT(px, py, 0));
return true;
}
JNIEXPORT void Java_android_graphics_Matrix_native_1setScale__JFF(JNIEnv *env, jclass class, jlong matrix_ptr, jfloat x, jfloat y)
{
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr);
graphene_matrix_init_scale(matrix, x, y, 1.f);
}
JNIEXPORT void JNICALL Java_android_graphics_Matrix_native_1setScale__JFFFF(JNIEnv *env, jclass class, jlong matrix_ptr, jfloat x, jfloat y, jfloat px, jfloat py)
{
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr);
graphene_matrix_init_translate(matrix, &GRAPHENE_POINT3D_INIT(-px, -py, 0));
graphene_matrix_scale(matrix, x, y, 1.f);
graphene_matrix_translate(matrix, &GRAPHENE_POINT3D_INIT(px, py, 0));
}
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postScale__JFFFF(JNIEnv *env, jclass class, jlong matrix_ptr, jfloat x, jfloat y, jfloat px, jfloat py)
{
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr);
graphene_matrix_translate(matrix, &GRAPHENE_POINT3D_INIT(-px, -py, 0));
graphene_matrix_scale(matrix, x, y, 1.f);
graphene_matrix_translate(matrix, &GRAPHENE_POINT3D_INIT(px, py, 0));
return true;
}
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1postRotate__JF(JNIEnv *env, jclass class, jlong matrix_ptr, jfloat degrees)
{
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr);
graphene_matrix_rotate_z(matrix, degrees);
return true;
}
#define SCALE_TO_FIT_FILL 0
#define SCALE_TO_FIT_START 1
#define SCALE_TO_FIT_CENTER 2
#define SCALE_TO_FIT_END 3
JNIEXPORT jboolean JNICALL Java_android_graphics_Matrix_native_1setRectToRect(JNIEnv *env, jclass class, jlong matrix_ptr, jobject src, jobject dest, jint stf)
{
graphene_matrix_t *matrix = (graphene_matrix_t *)_PTR(matrix_ptr);
graphene_matrix_init_translate(matrix, &GRAPHENE_POINT3D_INIT(-_GET_FLOAT_FIELD(src, "left"), -_GET_FLOAT_FIELD(src, "top"), 0));
float src_width = _GET_FLOAT_FIELD(src, "right") - _GET_FLOAT_FIELD(src, "left");
float src_height = _GET_FLOAT_FIELD(src, "bottom") - _GET_FLOAT_FIELD(src, "top");
float dest_width = _GET_FLOAT_FIELD(dest, "right") - _GET_FLOAT_FIELD(dest, "left");
float dest_height = _GET_FLOAT_FIELD(dest, "bottom") - _GET_FLOAT_FIELD(dest, "top");
float factor_x = dest_width / src_width;
float factor_y = dest_height / src_height;
if (stf != SCALE_TO_FIT_FILL) {
factor_x = factor_y = (factor_x < factor_y) ? factor_x : factor_y;
}
graphene_matrix_scale(matrix, factor_x, factor_y, 1.f);
graphene_point3d_t translation = GRAPHENE_POINT3D_INIT(_GET_FLOAT_FIELD(dest, "left"), _GET_FLOAT_FIELD(dest, "top"), 0);
if (stf == SCALE_TO_FIT_CENTER) {
translation.x += (dest_width - src_width * factor_x) / 2;
translation.y += (dest_height - src_height * factor_y) / 2;
} else if (stf == SCALE_TO_FIT_END) {
translation.x += (dest_width - src_width * factor_x);
translation.y += (dest_height - src_height * factor_y);
}
graphene_matrix_translate(matrix, &translation);
return true;
}

View File

@@ -523,3 +523,9 @@ JNIEXPORT void JNICALL Java_android_view_View_setOnLongClickListener(JNIEnv *env
gtk_widget_add_controller(widget, controller);
g_object_set_data(G_OBJECT(widget), "on_long_click_listener", controller);
}
JNIEXPORT jboolean JNICALL Java_android_view_View_native_1getMatrix(JNIEnv *env, jobject this, jlong widget_ptr, jlong matrix_ptr)
{
GtkWidget *widget = GTK_WIDGET(_PTR(widget_ptr));
return gtk_widget_compute_transform(gtk_widget_get_parent(gtk_widget_get_parent(widget)), widget, _PTR(matrix_ptr));
}