1 /* libs/android_runtime/android/graphics/Path.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 // This file was generated from the C++ include file: SkPath.h
19 // Any changes made to this file will be discarded by the build.
20 // To change this file, either edit the include, or device/tools/gluemaker/main.cpp,
21 // or one of the auxilary file specifications in device/tools/gluemaker.
22
23 #include "jni.h"
24 #include "GraphicsJNI.h"
25 #include <android_runtime/AndroidRuntime.h>
26
27 #include "SkPath.h"
28
29 #include <Caches.h>
30
31 namespace android {
32
33 class SkPathGlue {
34 public:
35
finalizer(JNIEnv * env,jobject clazz,SkPath * obj)36 static void finalizer(JNIEnv* env, jobject clazz, SkPath* obj) {
37 #ifdef USE_OPENGL_RENDERER
38 if (android::uirenderer::Caches::hasInstance()) {
39 android::uirenderer::Caches::getInstance().resourceCache.destructor(obj);
40 return;
41 }
42 #endif
43 delete obj;
44 }
45
init1(JNIEnv * env,jobject clazz)46 static SkPath* init1(JNIEnv* env, jobject clazz) {
47 return new SkPath();
48 }
49
init2(JNIEnv * env,jobject clazz,SkPath * val)50 static SkPath* init2(JNIEnv* env, jobject clazz, SkPath* val) {
51 return new SkPath(*val);
52 }
53
reset(JNIEnv * env,jobject clazz,SkPath * obj)54 static void reset(JNIEnv* env, jobject clazz, SkPath* obj) {
55 obj->reset();
56 }
57
rewind(JNIEnv * env,jobject clazz,SkPath * obj)58 static void rewind(JNIEnv* env, jobject clazz, SkPath* obj) {
59 obj->rewind();
60 }
61
assign(JNIEnv * env,jobject clazz,SkPath * dst,const SkPath * src)62 static void assign(JNIEnv* env, jobject clazz, SkPath* dst, const SkPath* src) {
63 *dst = *src;
64 }
65
getFillType(JNIEnv * env,jobject clazz,SkPath * obj)66 static jint getFillType(JNIEnv* env, jobject clazz, SkPath* obj) {
67 return obj->getFillType();
68 }
69
setFillType(JNIEnv * env,jobject clazz,SkPath * path,SkPath::FillType ft)70 static void setFillType(JNIEnv* env, jobject clazz, SkPath* path,
71 SkPath::FillType ft) {
72 path->setFillType(ft);
73 }
74
isEmpty(JNIEnv * env,jobject clazz,SkPath * obj)75 static jboolean isEmpty(JNIEnv* env, jobject clazz, SkPath* obj) {
76 return obj->isEmpty();
77 }
78
isRect(JNIEnv * env,jobject clazz,SkPath * obj,jobject rect)79 static jboolean isRect(JNIEnv* env, jobject clazz, SkPath* obj, jobject rect) {
80 SkRect rect_;
81 jboolean result = obj->isRect(&rect_);
82 GraphicsJNI::rect_to_jrectf(rect_, env, rect);
83 return result;
84 }
85
computeBounds(JNIEnv * env,jobject clazz,SkPath * obj,jobject bounds)86 static void computeBounds(JNIEnv* env, jobject clazz, SkPath* obj, jobject bounds) {
87 const SkRect& bounds_ = obj->getBounds();
88 GraphicsJNI::rect_to_jrectf(bounds_, env, bounds);
89 }
90
incReserve(JNIEnv * env,jobject clazz,SkPath * obj,jint extraPtCount)91 static void incReserve(JNIEnv* env, jobject clazz, SkPath* obj, jint extraPtCount) {
92 obj->incReserve(extraPtCount);
93 }
94
moveTo__FF(JNIEnv * env,jobject clazz,SkPath * obj,jfloat x,jfloat y)95 static void moveTo__FF(JNIEnv* env, jobject clazz, SkPath* obj, jfloat x, jfloat y) {
96 SkScalar x_ = SkFloatToScalar(x);
97 SkScalar y_ = SkFloatToScalar(y);
98 obj->moveTo(x_, y_);
99 }
100
rMoveTo(JNIEnv * env,jobject clazz,SkPath * obj,jfloat dx,jfloat dy)101 static void rMoveTo(JNIEnv* env, jobject clazz, SkPath* obj, jfloat dx, jfloat dy) {
102 SkScalar dx_ = SkFloatToScalar(dx);
103 SkScalar dy_ = SkFloatToScalar(dy);
104 obj->rMoveTo(dx_, dy_);
105 }
106
lineTo__FF(JNIEnv * env,jobject clazz,SkPath * obj,jfloat x,jfloat y)107 static void lineTo__FF(JNIEnv* env, jobject clazz, SkPath* obj, jfloat x, jfloat y) {
108 SkScalar x_ = SkFloatToScalar(x);
109 SkScalar y_ = SkFloatToScalar(y);
110 obj->lineTo(x_, y_);
111 }
112
rLineTo(JNIEnv * env,jobject clazz,SkPath * obj,jfloat dx,jfloat dy)113 static void rLineTo(JNIEnv* env, jobject clazz, SkPath* obj, jfloat dx, jfloat dy) {
114 SkScalar dx_ = SkFloatToScalar(dx);
115 SkScalar dy_ = SkFloatToScalar(dy);
116 obj->rLineTo(dx_, dy_);
117 }
118
quadTo__FFFF(JNIEnv * env,jobject clazz,SkPath * obj,jfloat x1,jfloat y1,jfloat x2,jfloat y2)119 static void quadTo__FFFF(JNIEnv* env, jobject clazz, SkPath* obj, jfloat x1, jfloat y1, jfloat x2, jfloat y2) {
120 SkScalar x1_ = SkFloatToScalar(x1);
121 SkScalar y1_ = SkFloatToScalar(y1);
122 SkScalar x2_ = SkFloatToScalar(x2);
123 SkScalar y2_ = SkFloatToScalar(y2);
124 obj->quadTo(x1_, y1_, x2_, y2_);
125 }
126
rQuadTo(JNIEnv * env,jobject clazz,SkPath * obj,jfloat dx1,jfloat dy1,jfloat dx2,jfloat dy2)127 static void rQuadTo(JNIEnv* env, jobject clazz, SkPath* obj, jfloat dx1, jfloat dy1, jfloat dx2, jfloat dy2) {
128 SkScalar dx1_ = SkFloatToScalar(dx1);
129 SkScalar dy1_ = SkFloatToScalar(dy1);
130 SkScalar dx2_ = SkFloatToScalar(dx2);
131 SkScalar dy2_ = SkFloatToScalar(dy2);
132 obj->rQuadTo(dx1_, dy1_, dx2_, dy2_);
133 }
134
cubicTo__FFFFFF(JNIEnv * env,jobject clazz,SkPath * obj,jfloat x1,jfloat y1,jfloat x2,jfloat y2,jfloat x3,jfloat y3)135 static void cubicTo__FFFFFF(JNIEnv* env, jobject clazz, SkPath* obj, jfloat x1, jfloat y1, jfloat x2, jfloat y2, jfloat x3, jfloat y3) {
136 SkScalar x1_ = SkFloatToScalar(x1);
137 SkScalar y1_ = SkFloatToScalar(y1);
138 SkScalar x2_ = SkFloatToScalar(x2);
139 SkScalar y2_ = SkFloatToScalar(y2);
140 SkScalar x3_ = SkFloatToScalar(x3);
141 SkScalar y3_ = SkFloatToScalar(y3);
142 obj->cubicTo(x1_, y1_, x2_, y2_, x3_, y3_);
143 }
144
rCubicTo(JNIEnv * env,jobject clazz,SkPath * obj,jfloat x1,jfloat y1,jfloat x2,jfloat y2,jfloat x3,jfloat y3)145 static void rCubicTo(JNIEnv* env, jobject clazz, SkPath* obj, jfloat x1, jfloat y1, jfloat x2, jfloat y2, jfloat x3, jfloat y3) {
146 SkScalar x1_ = SkFloatToScalar(x1);
147 SkScalar y1_ = SkFloatToScalar(y1);
148 SkScalar x2_ = SkFloatToScalar(x2);
149 SkScalar y2_ = SkFloatToScalar(y2);
150 SkScalar x3_ = SkFloatToScalar(x3);
151 SkScalar y3_ = SkFloatToScalar(y3);
152 obj->rCubicTo(x1_, y1_, x2_, y2_, x3_, y3_);
153 }
154
arcTo(JNIEnv * env,jobject clazz,SkPath * obj,jobject oval,jfloat startAngle,jfloat sweepAngle,jboolean forceMoveTo)155 static void arcTo(JNIEnv* env, jobject clazz, SkPath* obj, jobject oval, jfloat startAngle, jfloat sweepAngle, jboolean forceMoveTo) {
156 SkRect oval_;
157 GraphicsJNI::jrectf_to_rect(env, oval, &oval_);
158 SkScalar startAngle_ = SkFloatToScalar(startAngle);
159 SkScalar sweepAngle_ = SkFloatToScalar(sweepAngle);
160 obj->arcTo(oval_, startAngle_, sweepAngle_, forceMoveTo);
161 }
162
close(JNIEnv * env,jobject clazz,SkPath * obj)163 static void close(JNIEnv* env, jobject clazz, SkPath* obj) {
164 obj->close();
165 }
166
addRect__RectFI(JNIEnv * env,jobject clazz,SkPath * obj,jobject rect,SkPath::Direction dir)167 static void addRect__RectFI(JNIEnv* env, jobject clazz, SkPath* obj, jobject rect, SkPath::Direction dir) {
168 SkRect rect_;
169 GraphicsJNI::jrectf_to_rect(env, rect, &rect_);
170 obj->addRect(rect_, dir);
171 }
172
addRect__FFFFI(JNIEnv * env,jobject clazz,SkPath * obj,jfloat left,jfloat top,jfloat right,jfloat bottom,SkPath::Direction dir)173 static void addRect__FFFFI(JNIEnv* env, jobject clazz, SkPath* obj, jfloat left, jfloat top, jfloat right, jfloat bottom, SkPath::Direction dir) {
174 SkScalar left_ = SkFloatToScalar(left);
175 SkScalar top_ = SkFloatToScalar(top);
176 SkScalar right_ = SkFloatToScalar(right);
177 SkScalar bottom_ = SkFloatToScalar(bottom);
178 obj->addRect(left_, top_, right_, bottom_, dir);
179 }
180
addOval(JNIEnv * env,jobject clazz,SkPath * obj,jobject oval,SkPath::Direction dir)181 static void addOval(JNIEnv* env, jobject clazz, SkPath* obj, jobject oval, SkPath::Direction dir) {
182 SkRect oval_;
183 GraphicsJNI::jrectf_to_rect(env, oval, &oval_);
184 obj->addOval(oval_, dir);
185 }
186
addCircle(JNIEnv * env,jobject clazz,SkPath * obj,jfloat x,jfloat y,jfloat radius,SkPath::Direction dir)187 static void addCircle(JNIEnv* env, jobject clazz, SkPath* obj, jfloat x, jfloat y, jfloat radius, SkPath::Direction dir) {
188 SkScalar x_ = SkFloatToScalar(x);
189 SkScalar y_ = SkFloatToScalar(y);
190 SkScalar radius_ = SkFloatToScalar(radius);
191 obj->addCircle(x_, y_, radius_, dir);
192 }
193
addArc(JNIEnv * env,jobject clazz,SkPath * obj,jobject oval,jfloat startAngle,jfloat sweepAngle)194 static void addArc(JNIEnv* env, jobject clazz, SkPath* obj, jobject oval, jfloat startAngle, jfloat sweepAngle) {
195 SkRect oval_;
196 GraphicsJNI::jrectf_to_rect(env, oval, &oval_);
197 SkScalar startAngle_ = SkFloatToScalar(startAngle);
198 SkScalar sweepAngle_ = SkFloatToScalar(sweepAngle);
199 obj->addArc(oval_, startAngle_, sweepAngle_);
200 }
201
addRoundRectXY(JNIEnv * env,jobject clazz,SkPath * obj,jobject rect,jfloat rx,jfloat ry,SkPath::Direction dir)202 static void addRoundRectXY(JNIEnv* env, jobject clazz, SkPath* obj, jobject rect,
203 jfloat rx, jfloat ry, SkPath::Direction dir) {
204 SkRect rect_;
205 GraphicsJNI::jrectf_to_rect(env, rect, &rect_);
206 SkScalar rx_ = SkFloatToScalar(rx);
207 SkScalar ry_ = SkFloatToScalar(ry);
208 obj->addRoundRect(rect_, rx_, ry_, dir);
209 }
210
addRoundRect8(JNIEnv * env,jobject,SkPath * obj,jobject rect,jfloatArray array,SkPath::Direction dir)211 static void addRoundRect8(JNIEnv* env, jobject, SkPath* obj, jobject rect,
212 jfloatArray array, SkPath::Direction dir) {
213 SkRect rect_;
214 GraphicsJNI::jrectf_to_rect(env, rect, &rect_);
215 AutoJavaFloatArray afa(env, array, 8);
216 const float* src = afa.ptr();
217 SkScalar dst[8];
218
219 for (int i = 0; i < 8; i++) {
220 dst[i] = SkFloatToScalar(src[i]);
221 }
222 obj->addRoundRect(rect_, dst, dir);
223 }
224
addPath__PathFF(JNIEnv * env,jobject clazz,SkPath * obj,SkPath * src,jfloat dx,jfloat dy)225 static void addPath__PathFF(JNIEnv* env, jobject clazz, SkPath* obj, SkPath* src, jfloat dx, jfloat dy) {
226 SkScalar dx_ = SkFloatToScalar(dx);
227 SkScalar dy_ = SkFloatToScalar(dy);
228 obj->addPath(*src, dx_, dy_);
229 }
230
addPath__Path(JNIEnv * env,jobject clazz,SkPath * obj,SkPath * src)231 static void addPath__Path(JNIEnv* env, jobject clazz, SkPath* obj, SkPath* src) {
232 obj->addPath(*src);
233 }
234
addPath__PathMatrix(JNIEnv * env,jobject clazz,SkPath * obj,SkPath * src,SkMatrix * matrix)235 static void addPath__PathMatrix(JNIEnv* env, jobject clazz, SkPath* obj, SkPath* src, SkMatrix* matrix) {
236 obj->addPath(*src, *matrix);
237 }
238
offset__FFPath(JNIEnv * env,jobject clazz,SkPath * obj,jfloat dx,jfloat dy,SkPath * dst)239 static void offset__FFPath(JNIEnv* env, jobject clazz, SkPath* obj, jfloat dx, jfloat dy, SkPath* dst) {
240 SkScalar dx_ = SkFloatToScalar(dx);
241 SkScalar dy_ = SkFloatToScalar(dy);
242 obj->offset(dx_, dy_, dst);
243 }
244
offset__FF(JNIEnv * env,jobject clazz,SkPath * obj,jfloat dx,jfloat dy)245 static void offset__FF(JNIEnv* env, jobject clazz, SkPath* obj, jfloat dx, jfloat dy) {
246 SkScalar dx_ = SkFloatToScalar(dx);
247 SkScalar dy_ = SkFloatToScalar(dy);
248 obj->offset(dx_, dy_);
249 }
250
setLastPoint(JNIEnv * env,jobject clazz,SkPath * obj,jfloat dx,jfloat dy)251 static void setLastPoint(JNIEnv* env, jobject clazz, SkPath* obj, jfloat dx, jfloat dy) {
252 SkScalar dx_ = SkFloatToScalar(dx);
253 SkScalar dy_ = SkFloatToScalar(dy);
254 obj->setLastPt(dx_, dy_);
255 }
256
transform__MatrixPath(JNIEnv * env,jobject clazz,SkPath * obj,SkMatrix * matrix,SkPath * dst)257 static void transform__MatrixPath(JNIEnv* env, jobject clazz, SkPath* obj, SkMatrix* matrix, SkPath* dst) {
258 obj->transform(*matrix, dst);
259 }
260
transform__Matrix(JNIEnv * env,jobject clazz,SkPath * obj,SkMatrix * matrix)261 static void transform__Matrix(JNIEnv* env, jobject clazz, SkPath* obj, SkMatrix* matrix) {
262 obj->transform(*matrix);
263 }
264
265 };
266
267 static JNINativeMethod methods[] = {
268 {"finalizer", "(I)V", (void*) SkPathGlue::finalizer},
269 {"init1","()I", (void*) SkPathGlue::init1},
270 {"init2","(I)I", (void*) SkPathGlue::init2},
271 {"native_reset","(I)V", (void*) SkPathGlue::reset},
272 {"native_rewind","(I)V", (void*) SkPathGlue::rewind},
273 {"native_set","(II)V", (void*) SkPathGlue::assign},
274 {"native_getFillType","(I)I", (void*) SkPathGlue::getFillType},
275 {"native_setFillType","(II)V", (void*) SkPathGlue::setFillType},
276 {"native_isEmpty","(I)Z", (void*) SkPathGlue::isEmpty},
277 {"native_isRect","(ILandroid/graphics/RectF;)Z", (void*) SkPathGlue::isRect},
278 {"native_computeBounds","(ILandroid/graphics/RectF;)V", (void*) SkPathGlue::computeBounds},
279 {"native_incReserve","(II)V", (void*) SkPathGlue::incReserve},
280 {"native_moveTo","(IFF)V", (void*) SkPathGlue::moveTo__FF},
281 {"native_rMoveTo","(IFF)V", (void*) SkPathGlue::rMoveTo},
282 {"native_lineTo","(IFF)V", (void*) SkPathGlue::lineTo__FF},
283 {"native_rLineTo","(IFF)V", (void*) SkPathGlue::rLineTo},
284 {"native_quadTo","(IFFFF)V", (void*) SkPathGlue::quadTo__FFFF},
285 {"native_rQuadTo","(IFFFF)V", (void*) SkPathGlue::rQuadTo},
286 {"native_cubicTo","(IFFFFFF)V", (void*) SkPathGlue::cubicTo__FFFFFF},
287 {"native_rCubicTo","(IFFFFFF)V", (void*) SkPathGlue::rCubicTo},
288 {"native_arcTo","(ILandroid/graphics/RectF;FFZ)V", (void*) SkPathGlue::arcTo},
289 {"native_close","(I)V", (void*) SkPathGlue::close},
290 {"native_addRect","(ILandroid/graphics/RectF;I)V", (void*) SkPathGlue::addRect__RectFI},
291 {"native_addRect","(IFFFFI)V", (void*) SkPathGlue::addRect__FFFFI},
292 {"native_addOval","(ILandroid/graphics/RectF;I)V", (void*) SkPathGlue::addOval},
293 {"native_addCircle","(IFFFI)V", (void*) SkPathGlue::addCircle},
294 {"native_addArc","(ILandroid/graphics/RectF;FF)V", (void*) SkPathGlue::addArc},
295 {"native_addRoundRect","(ILandroid/graphics/RectF;FFI)V", (void*) SkPathGlue::addRoundRectXY},
296 {"native_addRoundRect","(ILandroid/graphics/RectF;[FI)V", (void*) SkPathGlue::addRoundRect8},
297 {"native_addPath","(IIFF)V", (void*) SkPathGlue::addPath__PathFF},
298 {"native_addPath","(II)V", (void*) SkPathGlue::addPath__Path},
299 {"native_addPath","(III)V", (void*) SkPathGlue::addPath__PathMatrix},
300 {"native_offset","(IFFI)V", (void*) SkPathGlue::offset__FFPath},
301 {"native_offset","(IFF)V", (void*) SkPathGlue::offset__FF},
302 {"native_setLastPoint","(IFF)V", (void*) SkPathGlue::setLastPoint},
303 {"native_transform","(III)V", (void*) SkPathGlue::transform__MatrixPath},
304 {"native_transform","(II)V", (void*) SkPathGlue::transform__Matrix}
305 };
306
register_android_graphics_Path(JNIEnv * env)307 int register_android_graphics_Path(JNIEnv* env) {
308 int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Path", methods,
309 sizeof(methods) / sizeof(methods[0]));
310 return result;
311 }
312
313 }
314