| Chet Haase | 0834e9f | 2022-08-15 23:01:03 +0000 | [diff] [blame] | 1 | /* libs/android_runtime/android/graphics/PathMeasure.cpp | 
|  | 2 | ** | 
|  | 3 | ** Copyright 2007, 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 <log/log.h> | 
|  | 19 |  | 
|  | 20 | #include "GraphicsJNI.h" | 
|  | 21 | #include "SkPath.h" | 
|  | 22 | #include "SkPoint.h" | 
|  | 23 |  | 
|  | 24 | namespace android { | 
|  | 25 |  | 
|  | 26 | class SkPathIteratorGlue { | 
|  | 27 | public: | 
|  | 28 | static void finalizer(SkPath::RawIter* obj) { delete obj; } | 
|  | 29 |  | 
|  | 30 | static jlong getFinalizer(JNIEnv* env, jclass clazz) { | 
|  | 31 | return static_cast<jlong>(reinterpret_cast<uintptr_t>(&finalizer)); | 
|  | 32 | } | 
|  | 33 |  | 
|  | 34 | static jlong create(JNIEnv* env, jobject clazz, jlong pathHandle) { | 
|  | 35 | const SkPath* path = reinterpret_cast<SkPath*>(pathHandle); | 
|  | 36 | return reinterpret_cast<jlong>(new SkPath::RawIter(*path)); | 
|  | 37 | } | 
|  | 38 |  | 
|  | 39 | // ---------------- @CriticalNative ------------------------- | 
|  | 40 |  | 
|  | 41 | static jint peek(CRITICAL_JNI_PARAMS_COMMA jlong iteratorHandle) { | 
|  | 42 | SkPath::RawIter* iterator = reinterpret_cast<SkPath::RawIter*>(iteratorHandle); | 
|  | 43 | return iterator->peek(); | 
|  | 44 | } | 
|  | 45 |  | 
|  | 46 | static jint next(CRITICAL_JNI_PARAMS_COMMA jlong iteratorHandle, jlong pointsArray) { | 
|  | 47 | static_assert(SkPath::kMove_Verb == 0, "SkPath::Verb unexpected index"); | 
|  | 48 | static_assert(SkPath::kLine_Verb == 1, "SkPath::Verb unexpected index"); | 
|  | 49 | static_assert(SkPath::kQuad_Verb == 2, "SkPath::Verb unexpected index"); | 
|  | 50 | static_assert(SkPath::kConic_Verb == 3, "SkPath::Verb unexpected index"); | 
|  | 51 | static_assert(SkPath::kCubic_Verb == 4, "SkPath::Verb unexpected index"); | 
|  | 52 | static_assert(SkPath::kClose_Verb == 5, "SkPath::Verb unexpected index"); | 
|  | 53 | static_assert(SkPath::kDone_Verb == 6, "SkPath::Verb unexpected index"); | 
|  | 54 |  | 
|  | 55 | SkPath::RawIter* iterator = reinterpret_cast<SkPath::RawIter*>(iteratorHandle); | 
|  | 56 | float* points = reinterpret_cast<float*>(pointsArray); | 
|  | 57 | SkPath::Verb verb = | 
|  | 58 | static_cast<SkPath::Verb>(iterator->next(reinterpret_cast<SkPoint*>(points))); | 
|  | 59 | if (verb == SkPath::kConic_Verb) { | 
|  | 60 | float weight = iterator->conicWeight(); | 
|  | 61 | points[6] = weight; | 
|  | 62 | } | 
|  | 63 | return static_cast<int>(verb); | 
|  | 64 | } | 
|  | 65 | }; | 
|  | 66 |  | 
|  | 67 | static const JNINativeMethod methods[] = { | 
|  | 68 | {"nCreate", "(J)J", (void*)SkPathIteratorGlue::create}, | 
|  | 69 | {"nGetFinalizer", "()J", (void*)SkPathIteratorGlue::getFinalizer}, | 
|  | 70 |  | 
|  | 71 | // ------- @CriticalNative below here ------------------ | 
|  | 72 |  | 
|  | 73 | {"nPeek", "(J)I", (void*)SkPathIteratorGlue::peek}, | 
|  | 74 | {"nNext", "(JJ)I", (void*)SkPathIteratorGlue::next}, | 
|  | 75 | }; | 
|  | 76 |  | 
|  | 77 | int register_android_graphics_PathIterator(JNIEnv* env) { | 
|  | 78 | return RegisterMethodsOrDie(env, "android/graphics/PathIterator", methods, NELEM(methods)); | 
|  | 79 | } | 
|  | 80 |  | 
|  | 81 | }  // namespace android |