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 #include "pathops/SkPathOps.h" 29 30 #include <Caches.h> 31 32 namespace android { 33 34 class SkPathGlue { 35 public: 36 37 static void finalizer(JNIEnv* env, jobject clazz, SkPath* obj) { 38 #ifdef USE_OPENGL_RENDERER 39 if (android::uirenderer::Caches::hasInstance()) { 40 android::uirenderer::Caches::getInstance().resourceCache.destructor(obj); 41 return; 42 } 43 #endif 44 delete obj; 45 } 46 47 static SkPath* init1(JNIEnv* env, jobject clazz) { 48 return new SkPath(); 49 } 50 51 static SkPath* init2(JNIEnv* env, jobject clazz, SkPath* val) { 52 return new SkPath(*val); 53 } 54 55 static void reset(JNIEnv* env, jobject clazz, SkPath* obj) { 56 obj->reset(); 57 } 58 59 static void rewind(JNIEnv* env, jobject clazz, SkPath* obj) { 60 obj->rewind(); 61 } 62 63 static void assign(JNIEnv* env, jobject clazz, SkPath* dst, const SkPath* src) { 64 *dst = *src; 65 } 66 67 static jint getFillType(JNIEnv* env, jobject clazz, SkPath* obj) { 68 return obj->getFillType(); 69 } 70 71 static void setFillType(JNIEnv* env, jobject clazz, SkPath* path, SkPath::FillType ft) { 72 path->setFillType(ft); 73 } 74 75 static jboolean isEmpty(JNIEnv* env, jobject clazz, SkPath* obj) { 76 return obj->isEmpty(); 77 } 78 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 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 91 static void incReserve(JNIEnv* env, jobject clazz, SkPath* obj, jint extraPtCount) { 92 obj->incReserve(extraPtCount); 93 } 94 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 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 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 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 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 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 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 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 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 163 static void close(JNIEnv* env, jobject clazz, SkPath* obj) { 164 obj->close(); 165 } 166 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 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 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 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 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 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 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 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 231 static void addPath__Path(JNIEnv* env, jobject clazz, SkPath* obj, SkPath* src) { 232 obj->addPath(*src); 233 } 234 235 static void addPath__PathMatrix(JNIEnv* env, jobject clazz, SkPath* obj, SkPath* src, SkMatrix* matrix) { 236 obj->addPath(*src, *matrix); 237 } 238 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 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 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 257 static void transform__MatrixPath(JNIEnv* env, jobject clazz, SkPath* obj, SkMatrix* matrix, SkPath* dst) { 258 obj->transform(*matrix, dst); 259 } 260 261 static void transform__Matrix(JNIEnv* env, jobject clazz, SkPath* obj, SkMatrix* matrix) { 262 obj->transform(*matrix); 263 } 264 265 static jboolean op(JNIEnv* env, jobject clazz, SkPath* p1, SkPath* p2, SkPathOp op, SkPath* r) { 266 return Op(*p1, *p2, op, r); 267 } 268 }; 269 270 static JNINativeMethod methods[] = { 271 {"finalizer", "(I)V", (void*) SkPathGlue::finalizer}, 272 {"init1","()I", (void*) SkPathGlue::init1}, 273 {"init2","(I)I", (void*) SkPathGlue::init2}, 274 {"native_reset","(I)V", (void*) SkPathGlue::reset}, 275 {"native_rewind","(I)V", (void*) SkPathGlue::rewind}, 276 {"native_set","(II)V", (void*) SkPathGlue::assign}, 277 {"native_getFillType","(I)I", (void*) SkPathGlue::getFillType}, 278 {"native_setFillType","(II)V", (void*) SkPathGlue::setFillType}, 279 {"native_isEmpty","(I)Z", (void*) SkPathGlue::isEmpty}, 280 {"native_isRect","(ILandroid/graphics/RectF;)Z", (void*) SkPathGlue::isRect}, 281 {"native_computeBounds","(ILandroid/graphics/RectF;)V", (void*) SkPathGlue::computeBounds}, 282 {"native_incReserve","(II)V", (void*) SkPathGlue::incReserve}, 283 {"native_moveTo","(IFF)V", (void*) SkPathGlue::moveTo__FF}, 284 {"native_rMoveTo","(IFF)V", (void*) SkPathGlue::rMoveTo}, 285 {"native_lineTo","(IFF)V", (void*) SkPathGlue::lineTo__FF}, 286 {"native_rLineTo","(IFF)V", (void*) SkPathGlue::rLineTo}, 287 {"native_quadTo","(IFFFF)V", (void*) SkPathGlue::quadTo__FFFF}, 288 {"native_rQuadTo","(IFFFF)V", (void*) SkPathGlue::rQuadTo}, 289 {"native_cubicTo","(IFFFFFF)V", (void*) SkPathGlue::cubicTo__FFFFFF}, 290 {"native_rCubicTo","(IFFFFFF)V", (void*) SkPathGlue::rCubicTo}, 291 {"native_arcTo","(ILandroid/graphics/RectF;FFZ)V", (void*) SkPathGlue::arcTo}, 292 {"native_close","(I)V", (void*) SkPathGlue::close}, 293 {"native_addRect","(ILandroid/graphics/RectF;I)V", (void*) SkPathGlue::addRect__RectFI}, 294 {"native_addRect","(IFFFFI)V", (void*) SkPathGlue::addRect__FFFFI}, 295 {"native_addOval","(ILandroid/graphics/RectF;I)V", (void*) SkPathGlue::addOval}, 296 {"native_addCircle","(IFFFI)V", (void*) SkPathGlue::addCircle}, 297 {"native_addArc","(ILandroid/graphics/RectF;FF)V", (void*) SkPathGlue::addArc}, 298 {"native_addRoundRect","(ILandroid/graphics/RectF;FFI)V", (void*) SkPathGlue::addRoundRectXY}, 299 {"native_addRoundRect","(ILandroid/graphics/RectF;[FI)V", (void*) SkPathGlue::addRoundRect8}, 300 {"native_addPath","(IIFF)V", (void*) SkPathGlue::addPath__PathFF}, 301 {"native_addPath","(II)V", (void*) SkPathGlue::addPath__Path}, 302 {"native_addPath","(III)V", (void*) SkPathGlue::addPath__PathMatrix}, 303 {"native_offset","(IFFI)V", (void*) SkPathGlue::offset__FFPath}, 304 {"native_offset","(IFF)V", (void*) SkPathGlue::offset__FF}, 305 {"native_setLastPoint","(IFF)V", (void*) SkPathGlue::setLastPoint}, 306 {"native_transform","(III)V", (void*) SkPathGlue::transform__MatrixPath}, 307 {"native_transform","(II)V", (void*) SkPathGlue::transform__Matrix}, 308 {"native_op","(IIII)Z", (void*) SkPathGlue::op} 309 }; 310 311 int register_android_graphics_Path(JNIEnv* env) { 312 int result = AndroidRuntime::registerNativeMethods(env, "android/graphics/Path", methods, 313 sizeof(methods) / sizeof(methods[0])); 314 return result; 315 } 316 317 } 318