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 | ** |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 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 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 8 | ** |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 9 | ** http://www.apache.org/licenses/LICENSE-2.0 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 10 | ** |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 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 |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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. |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 20 | // To change this file, either edit the include, or device/tools/gluemaker/main.cpp, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | // or one of the auxilary file specifications in device/tools/gluemaker. |
| 22 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | #include "GraphicsJNI.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | |
| 25 | #include "SkPath.h" |
Derek Sollenberger | eece0dd | 2014-02-27 14:31:29 -0500 | [diff] [blame] | 26 | #include "SkPathOps.h" |
Chris Craik | 96202d5 | 2017-04-27 15:26:17 -0700 | [diff] [blame] | 27 | #include "SkGeometry.h" // WARNING: Internal Skia Header |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
George Mount | c96c7b2 | 2013-08-23 13:31:31 -0700 | [diff] [blame] | 29 | #include <vector> |
| 30 | #include <map> |
Romain Guy | a2341a9 | 2010-09-08 18:04:33 -0700 | [diff] [blame] | 31 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | namespace android { |
| 33 | |
| 34 | class SkPathGlue { |
| 35 | public: |
| 36 | |
John Reck | 205d83e | 2018-03-28 14:36:58 -0700 | [diff] [blame] | 37 | static void finalizer(SkPath* obj) { |
John Reck | 205d83e | 2018-03-28 14:36:58 -0700 | [diff] [blame] | 38 | delete obj; |
| 39 | } |
| 40 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 41 | // ---------------- Regular JNI ----------------------------- |
| 42 | |
| 43 | static jlong init(JNIEnv* env, jclass clazz) { |
| 44 | return reinterpret_cast<jlong>(new SkPath()); |
| 45 | } |
| 46 | |
| 47 | static jlong init_Path(JNIEnv* env, jclass clazz, jlong valHandle) { |
| 48 | SkPath* val = reinterpret_cast<SkPath*>(valHandle); |
| 49 | return reinterpret_cast<jlong>(new SkPath(*val)); |
| 50 | } |
| 51 | |
John Reck | 205d83e | 2018-03-28 14:36:58 -0700 | [diff] [blame] | 52 | static jlong getFinalizer(JNIEnv* env, jclass clazz) { |
| 53 | return static_cast<jlong>(reinterpret_cast<uintptr_t>(&finalizer)); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | } |
| 55 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 56 | static void set(JNIEnv* env, jclass clazz, jlong dstHandle, jlong srcHandle) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 57 | SkPath* dst = reinterpret_cast<SkPath*>(dstHandle); |
| 58 | const SkPath* src = reinterpret_cast<SkPath*>(srcHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | *dst = *src; |
| 60 | } |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 61 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 62 | static void computeBounds(JNIEnv* env, jclass clazz, jlong objHandle, jobject jbounds) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 63 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 64 | const SkRect& bounds = obj->getBounds(); |
| 65 | GraphicsJNI::rect_to_jrectf(bounds, env, jbounds); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 67 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 68 | static void incReserve(JNIEnv* env, jclass clazz, jlong objHandle, jint extraPtCount) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 69 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | obj->incReserve(extraPtCount); |
| 71 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 72 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 73 | static void moveTo__FF(JNIEnv* env, jclass clazz, jlong objHandle, jfloat x, jfloat y) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 74 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 75 | obj->moveTo(x, y); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 77 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 78 | static void rMoveTo(JNIEnv* env, jclass clazz, jlong objHandle, jfloat dx, jfloat dy) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 79 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 80 | obj->rMoveTo(dx, dy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 82 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 83 | static void lineTo__FF(JNIEnv* env, jclass clazz, jlong objHandle, jfloat x, jfloat y) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 84 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 85 | obj->lineTo(x, y); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 87 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 88 | static void rLineTo(JNIEnv* env, jclass clazz, jlong objHandle, jfloat dx, jfloat dy) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 89 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 90 | obj->rLineTo(dx, dy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 92 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 93 | static void quadTo__FFFF(JNIEnv* env, jclass clazz, jlong objHandle, jfloat x1, jfloat y1, |
| 94 | jfloat x2, jfloat y2) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 95 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 96 | obj->quadTo(x1, y1, x2, y2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 98 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 99 | static void rQuadTo(JNIEnv* env, jclass clazz, jlong objHandle, jfloat dx1, jfloat dy1, |
| 100 | jfloat dx2, jfloat dy2) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 101 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 102 | obj->rQuadTo(dx1, dy1, dx2, dy2); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 104 | |
Chet Haase | 0834e9f | 2022-08-15 23:01:03 +0000 | [diff] [blame^] | 105 | static void conicTo(JNIEnv* env, jclass clazz, jlong objHandle, jfloat x1, jfloat y1, jfloat x2, |
| 106 | jfloat y2, jfloat weight) { |
| 107 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
| 108 | obj->conicTo(x1, y1, x2, y2, weight); |
| 109 | } |
| 110 | |
| 111 | static void rConicTo(JNIEnv* env, jclass clazz, jlong objHandle, jfloat dx1, jfloat dy1, |
| 112 | jfloat dx2, jfloat dy2, jfloat weight) { |
| 113 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
| 114 | obj->rConicTo(dx1, dy1, dx2, dy2, weight); |
| 115 | } |
| 116 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 117 | static void cubicTo__FFFFFF(JNIEnv* env, jclass clazz, jlong objHandle, jfloat x1, jfloat y1, |
| 118 | jfloat x2, jfloat y2, jfloat x3, jfloat y3) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 119 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 120 | obj->cubicTo(x1, y1, x2, y2, x3, y3); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 122 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 123 | static void rCubicTo(JNIEnv* env, jclass clazz, jlong objHandle, jfloat x1, jfloat y1, |
| 124 | jfloat x2, jfloat y2, jfloat x3, jfloat y3) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 125 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 126 | obj->rCubicTo(x1, y1, x2, y2, x3, y3); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 128 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 129 | static void arcTo(JNIEnv* env, jclass clazz, jlong objHandle, jfloat left, jfloat top, |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 130 | jfloat right, jfloat bottom, jfloat startAngle, jfloat sweepAngle, |
| 131 | jboolean forceMoveTo) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 132 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 133 | SkRect oval = SkRect::MakeLTRB(left, top, right, bottom); |
| 134 | obj->arcTo(oval, startAngle, sweepAngle, forceMoveTo); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 136 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 137 | static void close(JNIEnv* env, jclass clazz, jlong objHandle) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 138 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | obj->close(); |
| 140 | } |
Chris Craik | 7979388 | 2014-04-25 13:08:25 -0700 | [diff] [blame] | 141 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 142 | static void addRect(JNIEnv* env, jclass clazz, jlong objHandle, |
Chris Craik | 7979388 | 2014-04-25 13:08:25 -0700 | [diff] [blame] | 143 | jfloat left, jfloat top, jfloat right, jfloat bottom, jint dirHandle) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 144 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Mike Reed | 15760c9 | 2019-11-25 11:43:48 -0500 | [diff] [blame] | 145 | SkPathDirection dir = static_cast<SkPathDirection>(dirHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 146 | obj->addRect(left, top, right, bottom, dir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 147 | } |
Chris Craik | 7979388 | 2014-04-25 13:08:25 -0700 | [diff] [blame] | 148 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 149 | static void addOval(JNIEnv* env, jclass clazz, jlong objHandle, |
Chris Craik | 7979388 | 2014-04-25 13:08:25 -0700 | [diff] [blame] | 150 | jfloat left, jfloat top, jfloat right, jfloat bottom, jint dirHandle) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 151 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Mike Reed | 15760c9 | 2019-11-25 11:43:48 -0500 | [diff] [blame] | 152 | SkPathDirection dir = static_cast<SkPathDirection>(dirHandle); |
Chris Craik | 7979388 | 2014-04-25 13:08:25 -0700 | [diff] [blame] | 153 | SkRect oval = SkRect::MakeLTRB(left, top, right, bottom); |
| 154 | obj->addOval(oval, dir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | } |
Chris Craik | 7979388 | 2014-04-25 13:08:25 -0700 | [diff] [blame] | 156 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 157 | static void addCircle(JNIEnv* env, jclass clazz, jlong objHandle, jfloat x, jfloat y, |
| 158 | jfloat radius, jint dirHandle) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 159 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Mike Reed | 15760c9 | 2019-11-25 11:43:48 -0500 | [diff] [blame] | 160 | SkPathDirection dir = static_cast<SkPathDirection>(dirHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 161 | obj->addCircle(x, y, radius, dir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | } |
Chris Craik | 7979388 | 2014-04-25 13:08:25 -0700 | [diff] [blame] | 163 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 164 | static void addArc(JNIEnv* env, jclass clazz, jlong objHandle, jfloat left, jfloat top, |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 165 | jfloat right, jfloat bottom, jfloat startAngle, jfloat sweepAngle) { |
| 166 | SkRect oval = SkRect::MakeLTRB(left, top, right, bottom); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 167 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 168 | obj->addArc(oval, startAngle, sweepAngle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | } |
Chris Craik | 7979388 | 2014-04-25 13:08:25 -0700 | [diff] [blame] | 170 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 171 | static void addRoundRectXY(JNIEnv* env, jclass clazz, jlong objHandle, jfloat left, jfloat top, |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 172 | jfloat right, jfloat bottom, jfloat rx, jfloat ry, jint dirHandle) { |
| 173 | SkRect rect = SkRect::MakeLTRB(left, top, right, bottom); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 174 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Mike Reed | 15760c9 | 2019-11-25 11:43:48 -0500 | [diff] [blame] | 175 | SkPathDirection dir = static_cast<SkPathDirection>(dirHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 176 | obj->addRoundRect(rect, rx, ry, dir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 177 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 178 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 179 | static void addRoundRect8(JNIEnv* env, jclass clazz, jlong objHandle, jfloat left, jfloat top, |
| 180 | jfloat right, jfloat bottom, jfloatArray array, jint dirHandle) { |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 181 | SkRect rect = SkRect::MakeLTRB(left, top, right, bottom); |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 182 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Mike Reed | 15760c9 | 2019-11-25 11:43:48 -0500 | [diff] [blame] | 183 | SkPathDirection dir = static_cast<SkPathDirection>(dirHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | AutoJavaFloatArray afa(env, array, 8); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 185 | #ifdef SK_SCALAR_IS_FLOAT |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | const float* src = afa.ptr(); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 187 | #else |
| 188 | #error Need to convert float array to SkScalar array before calling the following function. |
| 189 | #endif |
| 190 | obj->addRoundRect(rect, src, dir); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 191 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 192 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 193 | static void addPath__PathFF(JNIEnv* env, jclass clazz, jlong objHandle, jlong srcHandle, |
| 194 | jfloat dx, jfloat dy) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 195 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
| 196 | SkPath* src = reinterpret_cast<SkPath*>(srcHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 197 | obj->addPath(*src, dx, dy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 198 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 199 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 200 | static void addPath__Path(JNIEnv* env, jclass clazz, jlong objHandle, jlong srcHandle) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 201 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
| 202 | SkPath* src = reinterpret_cast<SkPath*>(srcHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | obj->addPath(*src); |
| 204 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 205 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 206 | static void addPath__PathMatrix(JNIEnv* env, jclass clazz, jlong objHandle, jlong srcHandle, |
| 207 | jlong matrixHandle) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 208 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
| 209 | SkPath* src = reinterpret_cast<SkPath*>(srcHandle); |
| 210 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | obj->addPath(*src, *matrix); |
| 212 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 213 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 214 | static void offset__FF(JNIEnv* env, jclass clazz, jlong objHandle, jfloat dx, jfloat dy) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 215 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 216 | obj->offset(dx, dy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 217 | } |
| 218 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 219 | static void setLastPoint(JNIEnv* env, jclass clazz, jlong objHandle, jfloat dx, jfloat dy) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 220 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Leon Scroggins III | 2e0103e | 2014-04-04 17:05:24 -0400 | [diff] [blame] | 221 | obj->setLastPt(dx, dy); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 222 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 223 | |
Chet Haase | 0834e9f | 2022-08-15 23:01:03 +0000 | [diff] [blame^] | 224 | static jboolean interpolate(JNIEnv* env, jclass clazz, jlong startHandle, jlong endHandle, |
| 225 | jfloat t, jlong interpolatedHandle) { |
| 226 | SkPath* startPath = reinterpret_cast<SkPath*>(startHandle); |
| 227 | SkPath* endPath = reinterpret_cast<SkPath*>(endHandle); |
| 228 | SkPath* interpolatedPath = reinterpret_cast<SkPath*>(interpolatedHandle); |
| 229 | return startPath->interpolate(*endPath, t, interpolatedPath); |
| 230 | } |
| 231 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 232 | static void transform__MatrixPath(JNIEnv* env, jclass clazz, jlong objHandle, jlong matrixHandle, |
| 233 | jlong dstHandle) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 234 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
| 235 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); |
| 236 | SkPath* dst = reinterpret_cast<SkPath*>(dstHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | obj->transform(*matrix, dst); |
| 238 | } |
Antonio Calabrese | 2460958 | 2014-06-12 16:32:03 -0700 | [diff] [blame] | 239 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 240 | static void transform__Matrix(JNIEnv* env, jclass clazz, jlong objHandle, jlong matrixHandle) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 241 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
| 242 | SkMatrix* matrix = reinterpret_cast<SkMatrix*>(matrixHandle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | obj->transform(*matrix); |
| 244 | } |
Romain Guy | 8018c8d | 2013-07-29 19:17:59 -0700 | [diff] [blame] | 245 | |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 246 | static jboolean op(JNIEnv* env, jclass clazz, jlong p1Handle, jlong p2Handle, jint opHandle, |
| 247 | jlong rHandle) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 248 | SkPath* p1 = reinterpret_cast<SkPath*>(p1Handle); |
| 249 | SkPath* p2 = reinterpret_cast<SkPath*>(p2Handle); |
| 250 | SkPathOp op = static_cast<SkPathOp>(opHandle); |
| 251 | SkPath* r = reinterpret_cast<SkPath*>(rHandle); |
| 252 | return Op(*p1, *p2, op, r); |
Romain Guy | 8018c8d | 2013-07-29 19:17:59 -0700 | [diff] [blame] | 253 | } |
George Mount | c96c7b2 | 2013-08-23 13:31:31 -0700 | [diff] [blame] | 254 | |
George Mount | c96c7b2 | 2013-08-23 13:31:31 -0700 | [diff] [blame] | 255 | typedef SkPoint (*bezierCalculation)(float t, const SkPoint* points); |
| 256 | |
| 257 | static void addMove(std::vector<SkPoint>& segmentPoints, std::vector<float>& lengths, |
| 258 | const SkPoint& point) { |
| 259 | float length = 0; |
| 260 | if (!lengths.empty()) { |
| 261 | length = lengths.back(); |
| 262 | } |
| 263 | segmentPoints.push_back(point); |
| 264 | lengths.push_back(length); |
| 265 | } |
| 266 | |
| 267 | static void addLine(std::vector<SkPoint>& segmentPoints, std::vector<float>& lengths, |
| 268 | const SkPoint& toPoint) { |
| 269 | if (segmentPoints.empty()) { |
| 270 | segmentPoints.push_back(SkPoint::Make(0, 0)); |
| 271 | lengths.push_back(0); |
| 272 | } else if (segmentPoints.back() == toPoint) { |
| 273 | return; // Empty line |
| 274 | } |
| 275 | float length = lengths.back() + SkPoint::Distance(segmentPoints.back(), toPoint); |
| 276 | segmentPoints.push_back(toPoint); |
| 277 | lengths.push_back(length); |
| 278 | } |
| 279 | |
| 280 | static float cubicCoordinateCalculation(float t, float p0, float p1, float p2, float p3) { |
| 281 | float oneMinusT = 1 - t; |
| 282 | float oneMinusTSquared = oneMinusT * oneMinusT; |
| 283 | float oneMinusTCubed = oneMinusTSquared * oneMinusT; |
| 284 | float tSquared = t * t; |
| 285 | float tCubed = tSquared * t; |
| 286 | return (oneMinusTCubed * p0) + (3 * oneMinusTSquared * t * p1) |
| 287 | + (3 * oneMinusT * tSquared * p2) + (tCubed * p3); |
| 288 | } |
| 289 | |
| 290 | static SkPoint cubicBezierCalculation(float t, const SkPoint* points) { |
| 291 | float x = cubicCoordinateCalculation(t, points[0].x(), points[1].x(), |
| 292 | points[2].x(), points[3].x()); |
| 293 | float y = cubicCoordinateCalculation(t, points[0].y(), points[1].y(), |
| 294 | points[2].y(), points[3].y()); |
| 295 | return SkPoint::Make(x, y); |
| 296 | } |
| 297 | |
| 298 | static float quadraticCoordinateCalculation(float t, float p0, float p1, float p2) { |
| 299 | float oneMinusT = 1 - t; |
| 300 | return oneMinusT * ((oneMinusT * p0) + (t * p1)) + t * ((oneMinusT * p1) + (t * p2)); |
| 301 | } |
| 302 | |
| 303 | static SkPoint quadraticBezierCalculation(float t, const SkPoint* points) { |
| 304 | float x = quadraticCoordinateCalculation(t, points[0].x(), points[1].x(), points[2].x()); |
| 305 | float y = quadraticCoordinateCalculation(t, points[0].y(), points[1].y(), points[2].y()); |
| 306 | return SkPoint::Make(x, y); |
| 307 | } |
| 308 | |
| 309 | // Subdivide a section of the Bezier curve, set the mid-point and the mid-t value. |
| 310 | // Returns true if further subdivision is necessary as defined by errorSquared. |
| 311 | static bool subdividePoints(const SkPoint* points, bezierCalculation bezierFunction, |
| 312 | float t0, const SkPoint &p0, float t1, const SkPoint &p1, |
| 313 | float& midT, SkPoint &midPoint, float errorSquared) { |
| 314 | midT = (t1 + t0) / 2; |
| 315 | float midX = (p1.x() + p0.x()) / 2; |
| 316 | float midY = (p1.y() + p0.y()) / 2; |
| 317 | |
| 318 | midPoint = (*bezierFunction)(midT, points); |
| 319 | float xError = midPoint.x() - midX; |
| 320 | float yError = midPoint.y() - midY; |
| 321 | float midErrorSquared = (xError * xError) + (yError * yError); |
| 322 | return midErrorSquared > errorSquared; |
| 323 | } |
| 324 | |
| 325 | // Divides Bezier curves until linear interpolation is very close to accurate, using |
| 326 | // errorSquared as a metric. Cubic Bezier curves can have an inflection point that improperly |
| 327 | // short-circuit subdivision. If you imagine an S shape, the top and bottom points being the |
| 328 | // starting and end points, linear interpolation would mark the center where the curve places |
| 329 | // the point. It is clearly not the case that we can linearly interpolate at that point. |
| 330 | // doubleCheckDivision forces a second examination between subdivisions to ensure that linear |
| 331 | // interpolation works. |
| 332 | static void addBezier(const SkPoint* points, |
| 333 | bezierCalculation bezierFunction, std::vector<SkPoint>& segmentPoints, |
| 334 | std::vector<float>& lengths, float errorSquared, bool doubleCheckDivision) { |
| 335 | typedef std::map<float, SkPoint> PointMap; |
| 336 | PointMap tToPoint; |
| 337 | |
| 338 | tToPoint[0] = (*bezierFunction)(0, points); |
| 339 | tToPoint[1] = (*bezierFunction)(1, points); |
| 340 | |
| 341 | PointMap::iterator iter = tToPoint.begin(); |
| 342 | PointMap::iterator next = iter; |
| 343 | ++next; |
| 344 | while (next != tToPoint.end()) { |
| 345 | bool needsSubdivision = true; |
| 346 | SkPoint midPoint; |
| 347 | do { |
| 348 | float midT; |
| 349 | needsSubdivision = subdividePoints(points, bezierFunction, iter->first, |
| 350 | iter->second, next->first, next->second, midT, midPoint, errorSquared); |
| 351 | if (!needsSubdivision && doubleCheckDivision) { |
| 352 | SkPoint quarterPoint; |
| 353 | float quarterT; |
| 354 | needsSubdivision = subdividePoints(points, bezierFunction, iter->first, |
| 355 | iter->second, midT, midPoint, quarterT, quarterPoint, errorSquared); |
| 356 | if (needsSubdivision) { |
| 357 | // Found an inflection point. No need to double-check. |
| 358 | doubleCheckDivision = false; |
| 359 | } |
| 360 | } |
| 361 | if (needsSubdivision) { |
| 362 | next = tToPoint.insert(iter, PointMap::value_type(midT, midPoint)); |
| 363 | } |
| 364 | } while (needsSubdivision); |
| 365 | iter = next; |
| 366 | next++; |
| 367 | } |
| 368 | |
| 369 | // Now that each division can use linear interpolation with less than the allowed error |
| 370 | for (iter = tToPoint.begin(); iter != tToPoint.end(); ++iter) { |
| 371 | addLine(segmentPoints, lengths, iter->second); |
| 372 | } |
| 373 | } |
| 374 | |
Chris Craik | 96202d5 | 2017-04-27 15:26:17 -0700 | [diff] [blame] | 375 | static void createVerbSegments(const SkPath::Iter& pathIter, SkPath::Verb verb, |
| 376 | const SkPoint* points, std::vector<SkPoint>& segmentPoints, |
| 377 | std::vector<float>& lengths, float errorSquared, float errorConic) { |
George Mount | c96c7b2 | 2013-08-23 13:31:31 -0700 | [diff] [blame] | 378 | switch (verb) { |
| 379 | case SkPath::kMove_Verb: |
| 380 | addMove(segmentPoints, lengths, points[0]); |
| 381 | break; |
| 382 | case SkPath::kClose_Verb: |
George Mount | 7fe03a2 | 2013-11-22 17:08:28 -0800 | [diff] [blame] | 383 | addLine(segmentPoints, lengths, points[0]); |
| 384 | break; |
George Mount | c96c7b2 | 2013-08-23 13:31:31 -0700 | [diff] [blame] | 385 | case SkPath::kLine_Verb: |
| 386 | addLine(segmentPoints, lengths, points[1]); |
| 387 | break; |
| 388 | case SkPath::kQuad_Verb: |
| 389 | addBezier(points, quadraticBezierCalculation, segmentPoints, lengths, |
| 390 | errorSquared, false); |
| 391 | break; |
| 392 | case SkPath::kCubic_Verb: |
| 393 | addBezier(points, cubicBezierCalculation, segmentPoints, lengths, |
| 394 | errorSquared, true); |
| 395 | break; |
Chris Craik | 96202d5 | 2017-04-27 15:26:17 -0700 | [diff] [blame] | 396 | case SkPath::kConic_Verb: { |
| 397 | SkAutoConicToQuads converter; |
| 398 | const SkPoint* quads = converter.computeQuads( |
| 399 | points, pathIter.conicWeight(), errorConic); |
| 400 | for (int i = 0; i < converter.countQuads(); i++) { |
| 401 | // Note: offset each subsequent quad by 2, since end points are shared |
| 402 | const SkPoint* quad = quads + i * 2; |
| 403 | addBezier(quad, quadraticBezierCalculation, segmentPoints, lengths, |
| 404 | errorConic, false); |
| 405 | } |
| 406 | break; |
| 407 | } |
George Mount | c96c7b2 | 2013-08-23 13:31:31 -0700 | [diff] [blame] | 408 | default: |
Chris Craik | 96202d5 | 2017-04-27 15:26:17 -0700 | [diff] [blame] | 409 | static_assert(SkPath::kMove_Verb == 0 |
| 410 | && SkPath::kLine_Verb == 1 |
| 411 | && SkPath::kQuad_Verb == 2 |
| 412 | && SkPath::kConic_Verb == 3 |
| 413 | && SkPath::kCubic_Verb == 4 |
| 414 | && SkPath::kClose_Verb == 5 |
| 415 | && SkPath::kDone_Verb == 6, |
| 416 | "Path enum changed, new types may have been added."); |
George Mount | c96c7b2 | 2013-08-23 13:31:31 -0700 | [diff] [blame] | 417 | break; |
| 418 | } |
| 419 | } |
| 420 | |
| 421 | // Returns a float[] with each point along the path represented by 3 floats |
| 422 | // * fractional length along the path that the point resides |
| 423 | // * x coordinate |
| 424 | // * y coordinate |
| 425 | // Note that more than one point may have the same length along the path in |
| 426 | // the case of a move. |
| 427 | // NULL can be returned if the Path is empty. |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 428 | static jfloatArray approximate(JNIEnv* env, jclass clazz, jlong pathHandle, |
| 429 | float acceptableError) { |
Ashok Bhat | 36bef0b | 2014-01-20 20:08:01 +0000 | [diff] [blame] | 430 | SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
George Mount | c96c7b2 | 2013-08-23 13:31:31 -0700 | [diff] [blame] | 431 | SkASSERT(path); |
| 432 | SkPath::Iter pathIter(*path, false); |
| 433 | SkPath::Verb verb; |
| 434 | SkPoint points[4]; |
| 435 | std::vector<SkPoint> segmentPoints; |
| 436 | std::vector<float> lengths; |
| 437 | float errorSquared = acceptableError * acceptableError; |
Chris Craik | 96202d5 | 2017-04-27 15:26:17 -0700 | [diff] [blame] | 438 | float errorConic = acceptableError / 2; // somewhat arbitrary |
George Mount | c96c7b2 | 2013-08-23 13:31:31 -0700 | [diff] [blame] | 439 | |
Mike Reed | 7d48969 | 2019-11-27 11:15:43 -0500 | [diff] [blame] | 440 | while ((verb = pathIter.next(points)) != SkPath::kDone_Verb) { |
Chris Craik | 96202d5 | 2017-04-27 15:26:17 -0700 | [diff] [blame] | 441 | createVerbSegments(pathIter, verb, points, segmentPoints, lengths, |
| 442 | errorSquared, errorConic); |
George Mount | c96c7b2 | 2013-08-23 13:31:31 -0700 | [diff] [blame] | 443 | } |
| 444 | |
| 445 | if (segmentPoints.empty()) { |
George Mount | 68cfdad | 2014-09-11 10:25:31 -0700 | [diff] [blame] | 446 | int numVerbs = path->countVerbs(); |
| 447 | if (numVerbs == 1) { |
| 448 | addMove(segmentPoints, lengths, path->getPoint(0)); |
| 449 | } else { |
| 450 | // Invalid or empty path. Fall back to point(0,0) |
| 451 | addMove(segmentPoints, lengths, SkPoint()); |
| 452 | } |
| 453 | } |
| 454 | |
| 455 | float totalLength = lengths.back(); |
| 456 | if (totalLength == 0) { |
| 457 | // Lone Move instructions should still be able to animate at the same value. |
| 458 | segmentPoints.push_back(segmentPoints.back()); |
| 459 | lengths.push_back(1); |
| 460 | totalLength = 1; |
George Mount | c96c7b2 | 2013-08-23 13:31:31 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | size_t numPoints = segmentPoints.size(); |
| 464 | size_t approximationArraySize = numPoints * 3; |
| 465 | |
| 466 | float* approximation = new float[approximationArraySize]; |
George Mount | c96c7b2 | 2013-08-23 13:31:31 -0700 | [diff] [blame] | 467 | |
| 468 | int approximationIndex = 0; |
George Mount | 7fe03a2 | 2013-11-22 17:08:28 -0800 | [diff] [blame] | 469 | for (size_t i = 0; i < numPoints; i++) { |
George Mount | c96c7b2 | 2013-08-23 13:31:31 -0700 | [diff] [blame] | 470 | const SkPoint& point = segmentPoints[i]; |
| 471 | approximation[approximationIndex++] = lengths[i] / totalLength; |
| 472 | approximation[approximationIndex++] = point.x(); |
| 473 | approximation[approximationIndex++] = point.y(); |
| 474 | } |
| 475 | |
| 476 | jfloatArray result = env->NewFloatArray(approximationArraySize); |
| 477 | env->SetFloatArrayRegion(result, 0, approximationArraySize, approximation); |
| 478 | delete[] approximation; |
| 479 | return result; |
| 480 | } |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 481 | |
| 482 | // ---------------- @FastNative ----------------------------- |
| 483 | |
| 484 | static jboolean isRect(JNIEnv* env, jclass clazz, jlong objHandle, jobject jrect) { |
| 485 | SkRect rect; |
| 486 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
| 487 | jboolean result = obj->isRect(&rect); |
John Reck | 205d83e | 2018-03-28 14:36:58 -0700 | [diff] [blame] | 488 | if (jrect) { |
| 489 | GraphicsJNI::rect_to_jrectf(rect, env, jrect); |
| 490 | } |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 491 | return result; |
| 492 | } |
| 493 | |
| 494 | // ---------------- @CriticalNative ------------------------- |
| 495 | |
Chet Haase | 0834e9f | 2022-08-15 23:01:03 +0000 | [diff] [blame^] | 496 | static jint getGenerationID(CRITICAL_JNI_PARAMS_COMMA jlong pathHandle) { |
| 497 | return (reinterpret_cast<SkPath*>(pathHandle)->getGenerationID()); |
| 498 | } |
| 499 | |
| 500 | static jboolean isInterpolatable(CRITICAL_JNI_PARAMS_COMMA jlong startHandle, jlong endHandle) { |
| 501 | SkPath* startPath = reinterpret_cast<SkPath*>(startHandle); |
| 502 | SkPath* endPath = reinterpret_cast<SkPath*>(endHandle); |
| 503 | return startPath->isInterpolatable(*endPath); |
| 504 | } |
| 505 | |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 506 | static void reset(CRITICAL_JNI_PARAMS_COMMA jlong objHandle) { |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 507 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
| 508 | obj->reset(); |
| 509 | } |
| 510 | |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 511 | static void rewind(CRITICAL_JNI_PARAMS_COMMA jlong objHandle) { |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 512 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
| 513 | obj->rewind(); |
| 514 | } |
| 515 | |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 516 | static jboolean isEmpty(CRITICAL_JNI_PARAMS_COMMA jlong objHandle) { |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 517 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
| 518 | return obj->isEmpty(); |
| 519 | } |
| 520 | |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 521 | static jboolean isConvex(CRITICAL_JNI_PARAMS_COMMA jlong objHandle) { |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 522 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
| 523 | return obj->isConvex(); |
| 524 | } |
| 525 | |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 526 | static jint getFillType(CRITICAL_JNI_PARAMS_COMMA jlong objHandle) { |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 527 | SkPath* obj = reinterpret_cast<SkPath*>(objHandle); |
Mike Reed | 6a8bf8e | 2019-12-03 13:01:07 -0500 | [diff] [blame] | 528 | return static_cast<int>(obj->getFillType()); |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 529 | } |
| 530 | |
Jerome Gaillard | 21e7e2d | 2019-05-14 14:34:46 +0100 | [diff] [blame] | 531 | static void setFillType(CRITICAL_JNI_PARAMS_COMMA jlong pathHandle, jint ftHandle) {; |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 532 | SkPath* path = reinterpret_cast<SkPath*>(pathHandle); |
Mike Reed | 6a8bf8e | 2019-12-03 13:01:07 -0500 | [diff] [blame] | 533 | SkPathFillType ft = static_cast<SkPathFillType>(ftHandle); |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 534 | path->setFillType(ft); |
| 535 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 536 | }; |
| 537 | |
Daniel Micay | 76f6a86 | 2015-09-19 17:31:01 -0400 | [diff] [blame] | 538 | static const JNINativeMethod methods[] = { |
Chet Haase | 0834e9f | 2022-08-15 23:01:03 +0000 | [diff] [blame^] | 539 | {"nInit", "()J", (void*)SkPathGlue::init}, |
| 540 | {"nInit", "(J)J", (void*)SkPathGlue::init_Path}, |
| 541 | {"nGetFinalizer", "()J", (void*)SkPathGlue::getFinalizer}, |
| 542 | {"nSet", "(JJ)V", (void*)SkPathGlue::set}, |
| 543 | {"nComputeBounds", "(JLandroid/graphics/RectF;)V", (void*)SkPathGlue::computeBounds}, |
| 544 | {"nIncReserve", "(JI)V", (void*)SkPathGlue::incReserve}, |
| 545 | {"nMoveTo", "(JFF)V", (void*)SkPathGlue::moveTo__FF}, |
| 546 | {"nRMoveTo", "(JFF)V", (void*)SkPathGlue::rMoveTo}, |
| 547 | {"nLineTo", "(JFF)V", (void*)SkPathGlue::lineTo__FF}, |
| 548 | {"nRLineTo", "(JFF)V", (void*)SkPathGlue::rLineTo}, |
| 549 | {"nQuadTo", "(JFFFF)V", (void*)SkPathGlue::quadTo__FFFF}, |
| 550 | {"nRQuadTo", "(JFFFF)V", (void*)SkPathGlue::rQuadTo}, |
| 551 | {"nConicTo", "(JFFFFF)V", (void*)SkPathGlue::conicTo}, |
| 552 | {"nRConicTo", "(JFFFFF)V", (void*)SkPathGlue::rConicTo}, |
| 553 | {"nCubicTo", "(JFFFFFF)V", (void*)SkPathGlue::cubicTo__FFFFFF}, |
| 554 | {"nRCubicTo", "(JFFFFFF)V", (void*)SkPathGlue::rCubicTo}, |
| 555 | {"nArcTo", "(JFFFFFFZ)V", (void*)SkPathGlue::arcTo}, |
| 556 | {"nClose", "(J)V", (void*)SkPathGlue::close}, |
| 557 | {"nAddRect", "(JFFFFI)V", (void*)SkPathGlue::addRect}, |
| 558 | {"nAddOval", "(JFFFFI)V", (void*)SkPathGlue::addOval}, |
| 559 | {"nAddCircle", "(JFFFI)V", (void*)SkPathGlue::addCircle}, |
| 560 | {"nAddArc", "(JFFFFFF)V", (void*)SkPathGlue::addArc}, |
| 561 | {"nAddRoundRect", "(JFFFFFFI)V", (void*)SkPathGlue::addRoundRectXY}, |
| 562 | {"nAddRoundRect", "(JFFFF[FI)V", (void*)SkPathGlue::addRoundRect8}, |
| 563 | {"nAddPath", "(JJFF)V", (void*)SkPathGlue::addPath__PathFF}, |
| 564 | {"nAddPath", "(JJ)V", (void*)SkPathGlue::addPath__Path}, |
| 565 | {"nAddPath", "(JJJ)V", (void*)SkPathGlue::addPath__PathMatrix}, |
| 566 | {"nInterpolate", "(JJFJ)Z", (void*)SkPathGlue::interpolate}, |
| 567 | {"nOffset", "(JFF)V", (void*)SkPathGlue::offset__FF}, |
| 568 | {"nSetLastPoint", "(JFF)V", (void*)SkPathGlue::setLastPoint}, |
| 569 | {"nTransform", "(JJJ)V", (void*)SkPathGlue::transform__MatrixPath}, |
| 570 | {"nTransform", "(JJ)V", (void*)SkPathGlue::transform__Matrix}, |
| 571 | {"nOp", "(JJIJ)Z", (void*)SkPathGlue::op}, |
| 572 | {"nApproximate", "(JF)[F", (void*)SkPathGlue::approximate}, |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 573 | |
Chet Haase | 0834e9f | 2022-08-15 23:01:03 +0000 | [diff] [blame^] | 574 | // ------- @FastNative below here ---------------------- |
| 575 | {"nIsRect", "(JLandroid/graphics/RectF;)Z", (void*)SkPathGlue::isRect}, |
Chris Craik | 2414e1b | 2016-12-12 13:56:15 -0800 | [diff] [blame] | 576 | |
Chet Haase | 0834e9f | 2022-08-15 23:01:03 +0000 | [diff] [blame^] | 577 | // ------- @CriticalNative below here ------------------ |
| 578 | {"nGetGenerationID", "(J)I", (void*)SkPathGlue::getGenerationID}, |
| 579 | {"nIsInterpolatable", "(JJ)Z", (void*)SkPathGlue::isInterpolatable}, |
| 580 | {"nReset", "(J)V", (void*)SkPathGlue::reset}, |
| 581 | {"nRewind", "(J)V", (void*)SkPathGlue::rewind}, |
| 582 | {"nIsEmpty", "(J)Z", (void*)SkPathGlue::isEmpty}, |
| 583 | {"nIsConvex", "(J)Z", (void*)SkPathGlue::isConvex}, |
| 584 | {"nGetFillType", "(J)I", (void*)SkPathGlue::getFillType}, |
| 585 | {"nSetFillType", "(JI)V", (void*)SkPathGlue::setFillType}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 586 | }; |
| 587 | |
| 588 | int register_android_graphics_Path(JNIEnv* env) { |
Andreas Gampe | ed6b9df | 2014-11-20 22:02:20 -0800 | [diff] [blame] | 589 | return RegisterMethodsOrDie(env, "android/graphics/Path", methods, NELEM(methods)); |
Derek Sollenberger | 1ad545d | 2015-08-20 14:23:14 -0400 | [diff] [blame] | 590 | |
Mike Reed | 15760c9 | 2019-11-25 11:43:48 -0500 | [diff] [blame] | 591 | static_assert(0 == (int)SkPathDirection::kCW, "direction_mismatch"); |
| 592 | static_assert(1 == (int)SkPathDirection::kCCW, "direction_mismatch"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | } |