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