1 /* libs/android_runtime/android/graphics/Matrix.cpp
2 **
3 ** Copyright 2006, The Android Open Source Project
4 **
5 ** Licensed under the Apache License, Version 2.0 (the "License");
6 ** you may not use this file except in compliance with the License.
7 ** You may obtain a copy of the License at
8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17
18 #include "GraphicsJNI.h"
19 #include "Matrix.h"
20 #include "SkMatrix.h"
21
22 namespace android {
23
24 static_assert(sizeof(SkMatrix) == 40, "Unexpected sizeof(SkMatrix), "
25 "update size in Matrix.java#NATIVE_ALLOCATION_SIZE and here");
26 static_assert(SK_SCALAR_IS_FLOAT, "SK_SCALAR_IS_FLOAT is false, "
27 "only float scalar is supported");
28
29 class SkMatrixGlue {
30 public:
31
32 // ---------------- Regular JNI -----------------------------
33
finalizer(jlong objHandle)34 static void finalizer(jlong objHandle) {
35 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
36 delete obj;
37 }
38
getNativeFinalizer(JNIEnv * env,jobject clazz)39 static jlong getNativeFinalizer(JNIEnv* env, jobject clazz) {
40 return static_cast<jlong>(reinterpret_cast<uintptr_t>(&finalizer));
41 }
42
create(JNIEnv * env,jobject clazz,jlong srcHandle)43 static jlong create(JNIEnv* env, jobject clazz, jlong srcHandle) {
44 const SkMatrix* src = reinterpret_cast<SkMatrix*>(srcHandle);
45 SkMatrix* obj = new SkMatrix();
46 if (src)
47 *obj = *src;
48 else
49 obj->reset();
50 return reinterpret_cast<jlong>(obj);
51 }
52
53 // ---------------- @FastNative -----------------------------
54
mapPoints(JNIEnv * env,jobject clazz,jlong matrixHandle,jfloatArray dst,jint dstIndex,jfloatArray src,jint srcIndex,jint ptCount,jboolean isPts)55 static void mapPoints(JNIEnv* env, jobject clazz, jlong matrixHandle,
56 jfloatArray dst, jint dstIndex, jfloatArray src, jint srcIndex,
57 jint ptCount, jboolean isPts) {
58 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
59 SkASSERT(ptCount >= 0);
60 AutoJavaFloatArray autoSrc(env, src, srcIndex + (ptCount << 1),
61 kRO_JNIAccess);
62 AutoJavaFloatArray autoDst(env, dst, dstIndex + (ptCount << 1),
63 kRW_JNIAccess);
64 float* srcArray = autoSrc.ptr() + srcIndex;
65 float* dstArray = autoDst.ptr() + dstIndex;
66 if (isPts)
67 matrix->mapPoints((SkPoint*) dstArray, (const SkPoint*) srcArray,
68 ptCount);
69 else
70 matrix->mapVectors((SkVector*) dstArray, (const SkVector*) srcArray,
71 ptCount);
72 }
73
mapRect__RectFRectF(JNIEnv * env,jobject clazz,jlong matrixHandle,jobjectArray dst,jobject src)74 static jboolean mapRect__RectFRectF(JNIEnv* env, jobject clazz,
75 jlong matrixHandle, jobjectArray dst, jobject src) {
76 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
77 SkRect dst_, src_;
78 GraphicsJNI::jrectf_to_rect(env, src, &src_);
79 jboolean rectStaysRect = matrix->mapRect(&dst_, src_);
80 GraphicsJNI::rect_to_jrectf(dst_, env, dst);
81 return rectStaysRect ? JNI_TRUE : JNI_FALSE;
82 }
83
setRectToRect(JNIEnv * env,jobject clazz,jlong matrixHandle,jobject src,jobject dst,jint stfHandle)84 static jboolean setRectToRect(JNIEnv* env, jobject clazz,
85 jlong matrixHandle, jobject src, jobject dst, jint stfHandle) {
86 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
87 SkMatrix::ScaleToFit stf = static_cast<SkMatrix::ScaleToFit>(stfHandle);
88 SkRect src_;
89 GraphicsJNI::jrectf_to_rect(env, src, &src_);
90 SkRect dst_;
91 GraphicsJNI::jrectf_to_rect(env, dst, &dst_);
92 return matrix->setRectToRect(src_, dst_, stf) ? JNI_TRUE : JNI_FALSE;
93 }
94
setPolyToPoly(JNIEnv * env,jobject clazz,jlong matrixHandle,jfloatArray jsrc,jint srcIndex,jfloatArray jdst,jint dstIndex,jint ptCount)95 static jboolean setPolyToPoly(JNIEnv* env, jobject clazz,
96 jlong matrixHandle, jfloatArray jsrc, jint srcIndex,
97 jfloatArray jdst, jint dstIndex, jint ptCount) {
98 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
99 SkASSERT(srcIndex >= 0);
100 SkASSERT(dstIndex >= 0);
101 SkASSERT((unsigned )ptCount <= 4);
102
103 AutoJavaFloatArray autoSrc(env, jsrc, srcIndex + (ptCount << 1),
104 kRO_JNIAccess);
105 AutoJavaFloatArray autoDst(env, jdst, dstIndex + (ptCount << 1),
106 kRW_JNIAccess);
107 float* src = autoSrc.ptr() + srcIndex;
108 float* dst = autoDst.ptr() + dstIndex;
109 bool result;
110
111 result = matrix->setPolyToPoly((const SkPoint*) src,
112 (const SkPoint*) dst, ptCount);
113 return result ? JNI_TRUE : JNI_FALSE;
114 }
115
getValues(JNIEnv * env,jobject clazz,jlong matrixHandle,jfloatArray values)116 static void getValues(JNIEnv* env, jobject clazz, jlong matrixHandle,
117 jfloatArray values) {
118 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
119 AutoJavaFloatArray autoValues(env, values, 9, kRW_JNIAccess);
120 float* dst = autoValues.ptr();
121 for (int i = 0; i < 9; i++) {
122 dst[i] = matrix->get(i);
123 }
124 }
125
setValues(JNIEnv * env,jobject clazz,jlong matrixHandle,jfloatArray values)126 static void setValues(JNIEnv* env, jobject clazz, jlong matrixHandle,
127 jfloatArray values) {
128 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
129 AutoJavaFloatArray autoValues(env, values, 9, kRO_JNIAccess);
130 const float* src = autoValues.ptr();
131
132 for (int i = 0; i < 9; i++) {
133 matrix->set(i, src[i]);
134 }
135 }
136
137 // ---------------- @CriticalNative -----------------------------
138
isIdentity(CRITICAL_JNI_PARAMS_COMMA jlong objHandle)139 static jboolean isIdentity(CRITICAL_JNI_PARAMS_COMMA jlong objHandle) {
140 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
141 return obj->isIdentity() ? JNI_TRUE : JNI_FALSE;
142 }
143
isAffine(CRITICAL_JNI_PARAMS_COMMA jlong objHandle)144 static jboolean isAffine(CRITICAL_JNI_PARAMS_COMMA jlong objHandle) {
145 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
146 return obj->asAffine(NULL) ? JNI_TRUE : JNI_FALSE;
147 }
148
rectStaysRect(CRITICAL_JNI_PARAMS_COMMA jlong objHandle)149 static jboolean rectStaysRect(CRITICAL_JNI_PARAMS_COMMA jlong objHandle) {
150 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
151 return obj->rectStaysRect() ? JNI_TRUE : JNI_FALSE;
152 }
153
reset(CRITICAL_JNI_PARAMS_COMMA jlong objHandle)154 static void reset(CRITICAL_JNI_PARAMS_COMMA jlong objHandle) {
155 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
156 obj->reset();
157 }
158
set(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jlong otherHandle)159 static void set(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jlong otherHandle) {
160 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
161 SkMatrix* other = reinterpret_cast<SkMatrix*>(otherHandle);
162 *obj = *other;
163 }
164
setTranslate(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat dx,jfloat dy)165 static void setTranslate(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat dx, jfloat dy) {
166 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
167 obj->setTranslate(dx, dy);
168 }
169
setScale__FFFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat sx,jfloat sy,jfloat px,jfloat py)170 static void setScale__FFFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat sx, jfloat sy, jfloat px,
171 jfloat py) {
172 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
173 obj->setScale(sx, sy, px, py);
174 }
175
setScale__FF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat sx,jfloat sy)176 static void setScale__FF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat sx, jfloat sy) {
177 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
178 obj->setScale(sx, sy);
179 }
180
setRotate__FFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat degrees,jfloat px,jfloat py)181 static void setRotate__FFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat degrees, jfloat px,
182 jfloat py) {
183 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
184 obj->setRotate(degrees, px, py);
185 }
186
setRotate__F(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat degrees)187 static void setRotate__F(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat degrees) {
188 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
189 obj->setRotate(degrees);
190 }
191
setSinCos__FFFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat sinValue,jfloat cosValue,jfloat px,jfloat py)192 static void setSinCos__FFFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat sinValue,
193 jfloat cosValue, jfloat px, jfloat py) {
194 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
195 obj->setSinCos(sinValue, cosValue, px, py);
196 }
197
setSinCos__FF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat sinValue,jfloat cosValue)198 static void setSinCos__FF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat sinValue,
199 jfloat cosValue) {
200 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
201 obj->setSinCos(sinValue, cosValue);
202 }
203
setSkew__FFFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat kx,jfloat ky,jfloat px,jfloat py)204 static void setSkew__FFFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat kx, jfloat ky, jfloat px,
205 jfloat py) {
206 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
207 obj->setSkew(kx, ky, px, py);
208 }
209
setSkew__FF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat kx,jfloat ky)210 static void setSkew__FF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat kx, jfloat ky) {
211 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
212 obj->setSkew(kx, ky);
213 }
214
setConcat(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jlong aHandle,jlong bHandle)215 static void setConcat(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jlong aHandle, jlong bHandle) {
216 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
217 SkMatrix* a = reinterpret_cast<SkMatrix*>(aHandle);
218 SkMatrix* b = reinterpret_cast<SkMatrix*>(bHandle);
219 obj->setConcat(*a, *b);
220 }
221
preTranslate(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat dx,jfloat dy)222 static void preTranslate(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat dx, jfloat dy) {
223 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
224 obj->preTranslate(dx, dy);
225 }
226
preScale__FFFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat sx,jfloat sy,jfloat px,jfloat py)227 static void preScale__FFFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat sx, jfloat sy, jfloat px,
228 jfloat py) {
229 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
230 obj->preScale(sx, sy, px, py);
231 }
232
preScale__FF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat sx,jfloat sy)233 static void preScale__FF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat sx, jfloat sy) {
234 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
235 obj->preScale(sx, sy);
236 }
237
preRotate__FFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat degrees,jfloat px,jfloat py)238 static void preRotate__FFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat degrees, jfloat px,
239 jfloat py) {
240 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
241 obj->preRotate(degrees, px, py);
242 }
243
preRotate__F(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat degrees)244 static void preRotate__F(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat degrees) {
245 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
246 obj->preRotate(degrees);
247 }
248
preSkew__FFFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat kx,jfloat ky,jfloat px,jfloat py)249 static void preSkew__FFFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat kx, jfloat ky, jfloat px,
250 jfloat py) {
251 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
252 obj->preSkew(kx, ky, px, py);
253 }
254
preSkew__FF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat kx,jfloat ky)255 static void preSkew__FF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat kx, jfloat ky) {
256 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
257 obj->preSkew(kx, ky);
258 }
259
preConcat(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jlong otherHandle)260 static void preConcat(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jlong otherHandle) {
261 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
262 SkMatrix* other = reinterpret_cast<SkMatrix*>(otherHandle);
263 obj->preConcat(*other);
264 }
265
postTranslate(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat dx,jfloat dy)266 static void postTranslate(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat dx, jfloat dy) {
267 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
268 obj->postTranslate(dx, dy);
269 }
270
postScale__FFFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat sx,jfloat sy,jfloat px,jfloat py)271 static void postScale__FFFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat sx, jfloat sy,
272 jfloat px, jfloat py) {
273 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
274 obj->postScale(sx, sy, px, py);
275 }
276
postScale__FF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat sx,jfloat sy)277 static void postScale__FF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat sx, jfloat sy) {
278 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
279 obj->postScale(sx, sy);
280 }
281
postRotate__FFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat degrees,jfloat px,jfloat py)282 static void postRotate__FFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat degrees, jfloat px,
283 jfloat py) {
284 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
285 obj->postRotate(degrees, px, py);
286 }
287
postRotate__F(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat degrees)288 static void postRotate__F(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat degrees) {
289 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
290 obj->postRotate(degrees);
291 }
292
postSkew__FFFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle,jfloat kx,jfloat ky,jfloat px,jfloat py)293 static void postSkew__FFFF(CRITICAL_JNI_PARAMS_COMMA jlong objHandle, jfloat kx, jfloat ky, jfloat px,
294 jfloat py) {
295 SkMatrix* obj = reinterpret_cast<SkMatrix*>(objHandle);
296 obj->postSkew(kx, ky, px, py);
297 }
298
postSkew__FF(CRITICAL_JNI_PARAMS_COMMA jlong matrixHandle,jfloat kx,jfloat ky)299 static void postSkew__FF(CRITICAL_JNI_PARAMS_COMMA jlong matrixHandle, jfloat kx, jfloat ky) {
300 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
301 matrix->postSkew(kx, ky);
302 }
303
postConcat(CRITICAL_JNI_PARAMS_COMMA jlong matrixHandle,jlong otherHandle)304 static void postConcat(CRITICAL_JNI_PARAMS_COMMA jlong matrixHandle, jlong otherHandle) {
305 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
306 SkMatrix* other = reinterpret_cast<SkMatrix*>(otherHandle);
307 matrix->postConcat(*other);
308 }
309
invert(CRITICAL_JNI_PARAMS_COMMA jlong matrixHandle,jlong inverseHandle)310 static jboolean invert(CRITICAL_JNI_PARAMS_COMMA jlong matrixHandle, jlong inverseHandle) {
311 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
312 SkMatrix* inverse = reinterpret_cast<SkMatrix*>(inverseHandle);
313 return matrix->invert(inverse);
314 }
315
mapRadius(CRITICAL_JNI_PARAMS_COMMA jlong matrixHandle,jfloat radius)316 static jfloat mapRadius(CRITICAL_JNI_PARAMS_COMMA jlong matrixHandle, jfloat radius) {
317 SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle);
318 float result;
319 result = SkScalarToFloat(matrix->mapRadius(radius));
320 return static_cast<jfloat>(result);
321 }
322
equals(CRITICAL_JNI_PARAMS_COMMA jlong aHandle,jlong bHandle)323 static jboolean equals(CRITICAL_JNI_PARAMS_COMMA jlong aHandle, jlong bHandle) {
324 const SkMatrix* a = reinterpret_cast<SkMatrix*>(aHandle);
325 const SkMatrix* b = reinterpret_cast<SkMatrix*>(bHandle);
326 return *a == *b;
327 }
328 };
329
330 static const JNINativeMethod methods[] = {
331 {"nGetNativeFinalizer", "()J", (void*) SkMatrixGlue::getNativeFinalizer},
332 {"nCreate","(J)J", (void*) SkMatrixGlue::create},
333
334 // ------- @FastNative below here ---------------
335 {"nMapPoints","(J[FI[FIIZ)V", (void*) SkMatrixGlue::mapPoints},
336 {"nMapRect","(JLandroid/graphics/RectF;Landroid/graphics/RectF;)Z",
337 (void*) SkMatrixGlue::mapRect__RectFRectF},
338 {"nSetRectToRect","(JLandroid/graphics/RectF;Landroid/graphics/RectF;I)Z",
339 (void*) SkMatrixGlue::setRectToRect},
340 {"nSetPolyToPoly","(J[FI[FII)Z", (void*) SkMatrixGlue::setPolyToPoly},
341 {"nGetValues","(J[F)V", (void*) SkMatrixGlue::getValues},
342 {"nSetValues","(J[F)V", (void*) SkMatrixGlue::setValues},
343
344 // ------- @CriticalNative below here ---------------
345 {"nIsIdentity","(J)Z", (void*) SkMatrixGlue::isIdentity},
346 {"nIsAffine","(J)Z", (void*) SkMatrixGlue::isAffine},
347 {"nRectStaysRect","(J)Z", (void*) SkMatrixGlue::rectStaysRect},
348 {"nReset","(J)V", (void*) SkMatrixGlue::reset},
349 {"nSet","(JJ)V", (void*) SkMatrixGlue::set},
350 {"nSetTranslate","(JFF)V", (void*) SkMatrixGlue::setTranslate},
351 {"nSetScale","(JFFFF)V", (void*) SkMatrixGlue::setScale__FFFF},
352 {"nSetScale","(JFF)V", (void*) SkMatrixGlue::setScale__FF},
353 {"nSetRotate","(JFFF)V", (void*) SkMatrixGlue::setRotate__FFF},
354 {"nSetRotate","(JF)V", (void*) SkMatrixGlue::setRotate__F},
355 {"nSetSinCos","(JFFFF)V", (void*) SkMatrixGlue::setSinCos__FFFF},
356 {"nSetSinCos","(JFF)V", (void*) SkMatrixGlue::setSinCos__FF},
357 {"nSetSkew","(JFFFF)V", (void*) SkMatrixGlue::setSkew__FFFF},
358 {"nSetSkew","(JFF)V", (void*) SkMatrixGlue::setSkew__FF},
359 {"nSetConcat","(JJJ)V", (void*) SkMatrixGlue::setConcat},
360 {"nPreTranslate","(JFF)V", (void*) SkMatrixGlue::preTranslate},
361 {"nPreScale","(JFFFF)V", (void*) SkMatrixGlue::preScale__FFFF},
362 {"nPreScale","(JFF)V", (void*) SkMatrixGlue::preScale__FF},
363 {"nPreRotate","(JFFF)V", (void*) SkMatrixGlue::preRotate__FFF},
364 {"nPreRotate","(JF)V", (void*) SkMatrixGlue::preRotate__F},
365 {"nPreSkew","(JFFFF)V", (void*) SkMatrixGlue::preSkew__FFFF},
366 {"nPreSkew","(JFF)V", (void*) SkMatrixGlue::preSkew__FF},
367 {"nPreConcat","(JJ)V", (void*) SkMatrixGlue::preConcat},
368 {"nPostTranslate","(JFF)V", (void*) SkMatrixGlue::postTranslate},
369 {"nPostScale","(JFFFF)V", (void*) SkMatrixGlue::postScale__FFFF},
370 {"nPostScale","(JFF)V", (void*) SkMatrixGlue::postScale__FF},
371 {"nPostRotate","(JFFF)V", (void*) SkMatrixGlue::postRotate__FFF},
372 {"nPostRotate","(JF)V", (void*) SkMatrixGlue::postRotate__F},
373 {"nPostSkew","(JFFFF)V", (void*) SkMatrixGlue::postSkew__FFFF},
374 {"nPostSkew","(JFF)V", (void*) SkMatrixGlue::postSkew__FF},
375 {"nPostConcat","(JJ)V", (void*) SkMatrixGlue::postConcat},
376 {"nInvert","(JJ)Z", (void*) SkMatrixGlue::invert},
377 {"nMapRadius","(JF)F", (void*) SkMatrixGlue::mapRadius},
378 {"nEquals", "(JJ)Z", (void*) SkMatrixGlue::equals}
379 };
380
381 static jfieldID sNativeInstanceField;
382
register_android_graphics_Matrix(JNIEnv * env)383 int register_android_graphics_Matrix(JNIEnv* env) {
384 int result = RegisterMethodsOrDie(env, "android/graphics/Matrix", methods, NELEM(methods));
385
386 jclass clazz = FindClassOrDie(env, "android/graphics/Matrix");
387 sNativeInstanceField = GetFieldIDOrDie(env, clazz, "native_instance", "J");
388
389 return result;
390 }
391
android_graphics_Matrix_getSkMatrix(JNIEnv * env,jobject matrixObj)392 SkMatrix* android_graphics_Matrix_getSkMatrix(JNIEnv* env, jobject matrixObj) {
393 return reinterpret_cast<SkMatrix*>(env->GetLongField(matrixObj, sNativeInstanceField));
394 }
395
396 }
397