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