Flutter Engine
The Flutter Engine
Matrix.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2021 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include <jni.h>
9
10#include "include/core/SkM44.h"
11
12#include <algorithm>
13
14namespace {
15
16static jlong Matrix_Create(JNIEnv* env, jobject, jfloat m0, jfloat m4, jfloat m8, jfloat m12,
17 jfloat m1, jfloat m5, jfloat m9, jfloat m13,
18 jfloat m2, jfloat m6, jfloat m10, jfloat m14,
19 jfloat m3, jfloat m7, jfloat m11, jfloat m15) {
20 return reinterpret_cast<jlong>(new SkM44(m0, m4, m8, m12,
21 m1, m5, m9, m13,
22 m2, m6, m10, m14,
23 m3, m7, m11, m15));
24}
25
26static jlong Matrix_CreateLookAt(JNIEnv* env, jobject, float eyeX, float eyeY, float eyeZ,
27 float coaX, float coaY, float coaZ,
28 float upX, float upY, float upZ) {
29 return reinterpret_cast<jlong>(new SkM44(SkM44::LookAt({eyeX, eyeY, eyeZ},
30 {coaX, coaY, coaZ},
31 {upX, upY, upZ})));
32}
33
34static jlong Matrix_CreatePerspective(JNIEnv* env, jobject, float near, float far, float angle) {
35 return reinterpret_cast<jlong>(new SkM44(SkM44::Perspective(near, far, angle)));
36}
37
38static jfloatArray Matrix_GetRowMajor(JNIEnv* env, jobject, jlong native_matrix) {
39 jfloatArray result = nullptr;
40 if (auto* m = reinterpret_cast<SkM44*>(native_matrix)) {
41 SkScalar temp[16];
42 m->getRowMajor(temp);
43
44 result = env->NewFloatArray(16);
45 if (result) {
46 env->SetFloatArrayRegion(result, 0, 16, temp);
47 }
48 }
49 return result;
50}
51
52static void Matrix_Release(JNIEnv* env, jobject, jlong native_matrix) {
53 delete reinterpret_cast<SkM44*>(native_matrix);
54}
55
56static void Matrix_PreConcat(JNIEnv* env, jobject, jlong native_matrixA, jlong native_matrixB) {
57 if (auto* mA = reinterpret_cast<SkM44*>(native_matrixA),
58 * mB = reinterpret_cast<SkM44*>(native_matrixB); mA && mB) {
59 mA->preConcat(*mB);
60 }
61}
62
63static jlong Matrix_Inverse(JNIEnv* env, jobject, jlong native_matrix) {
64 if (auto* m = reinterpret_cast<SkM44*>(native_matrix)) {
66 if (m->invert(&inverse)) {
67 return reinterpret_cast<jlong>(new SkM44(inverse));
68 }
69 }
70 return 0;
71}
72
73static jlong Matrix_Transpose(JNIEnv* env, jobject, jlong native_matrix) {
74 if (auto* matrix = reinterpret_cast<SkM44*>(native_matrix)) {
75 SkM44 trans(matrix->transpose());
76 return reinterpret_cast<jlong>(new SkM44(trans));
77 }
78 return 0;
79}
80
81static jlong Matrix_Concat(JNIEnv* env, jobject, jlong native_matrixA, jlong native_matrixB) {
82 if (auto* mA = reinterpret_cast<SkM44*>(native_matrixA),
83 * mB = reinterpret_cast<SkM44*>(native_matrixB); mA && mB) {
84 return reinterpret_cast<jlong>(new SkM44(*mA, *mB));
85 }
86 return 0;
87}
88
89static void Matrix_Translate(JNIEnv* env, jobject, jlong native_matrix, jfloat x, jfloat y, jfloat z) {
90 if (auto* matrix = reinterpret_cast<SkM44*>(native_matrix)) {
91 matrix->preTranslate(x, y, z);
92 }
93}
94
95static void Matrix_Scale(JNIEnv* env, jobject, jlong native_matrix, jfloat x, jfloat y, jfloat z) {
96 if (auto* matrix = reinterpret_cast<SkM44*>(native_matrix)) {
97 matrix->preScale(x, y, z);
98 }
99}
100
101static void Matrix_Rotate(JNIEnv* env, jobject, jlong native_matrix, jfloat x, jfloat y, jfloat z, jfloat rad) {
102 if (auto* matrix = reinterpret_cast<SkM44*>(native_matrix)) {
103 SkM44 rotate = SkM44::Rotate({x, y, z}, rad);
104 matrix->preConcat(rotate);
105 }
106}
107
108} // namespace
109
111 static const JNINativeMethod methods[] = {
112 {"nCreate" , "(FFFFFFFFFFFFFFFF)J" , reinterpret_cast<void*>(Matrix_Create)},
113 {"nCreateLookAt" , "(FFFFFFFFF)J" , reinterpret_cast<void*>(Matrix_CreateLookAt)},
114 {"nCreatePerspective" , "(FFF)J" , reinterpret_cast<void*>(Matrix_CreatePerspective)},
115 {"nGetRowMajor" , "(J)[F" , reinterpret_cast<void*>(Matrix_GetRowMajor)},
116 {"nRelease" , "(J)V" , reinterpret_cast<void*>(Matrix_Release)},
117 {"nInverse" , "(J)J" , reinterpret_cast<void*>(Matrix_Inverse)},
118 {"nTranspose" , "(J)J" , reinterpret_cast<void*>(Matrix_Transpose)},
119 {"nPreConcat" , "(JJ)V" , reinterpret_cast<void*>(Matrix_PreConcat)},
120 {"nConcat" , "(JJ)J" , reinterpret_cast<void*>(Matrix_Concat)},
121 {"nTranslate" , "(JFFF)V" , reinterpret_cast<void*>(Matrix_Translate)},
122 {"nScale" , "(JFFF)V" , reinterpret_cast<void*>(Matrix_Scale)},
123 {"nRotate" , "(JFFFF)V" , reinterpret_cast<void*>(Matrix_Rotate)},
124 };
125
126 const auto clazz = env->FindClass("org/skia/jetski/Matrix");
127 return clazz
128 ? env->RegisterNatives(clazz, methods, std::size(methods))
129 : JNI_ERR;
130}
int register_jetski_Matrix(JNIEnv *env)
Definition: Matrix.cpp:110
static bool rotate(const SkDCubic &cubic, int zero, int index, SkDCubic &rotPath)
Definition: SkM44.h:150
static SkM44 LookAt(const SkV3 &eye, const SkV3 &center, const SkV3 &up)
Definition: SkM44.cpp:331
static SkM44 Rotate(SkV3 axis, SkScalar radians)
Definition: SkM44.h:239
@ kUninitialized_Constructor
Definition: SkM44.h:167
SkM44 & preConcat(const SkM44 &m)
Definition: SkM44.h:351
static SkM44 Perspective(float near, float far, float angle)
Definition: SkM44.cpp:343
float SkScalar
Definition: extension.cpp:12
GAsyncResult * result
double y
double x
unsigned useCenter Optional< SkMatrix > matrix
Definition: SkRecords.h:258
Definition: __init__.py:1
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
Definition: switches.h:259