Loading core/jni/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -339,6 +339,8 @@ cc_library_static { cppflags: ["-Wno-conversion-null"], srcs: [ "android/graphics/apex/android_region.cpp", "android_graphics_Canvas.cpp", "android_graphics_ColorSpace.cpp", "android_graphics_drawable_AnimatedVectorDrawable.cpp", Loading core/jni/android/graphics/Region.cpp +0 −4 Original line number Diff line number Diff line Loading @@ -360,8 +360,4 @@ int register_android_graphics_Region(JNIEnv* env) NELEM(gRegionIterMethods)); } SkRegion* android_graphics_Region_getSkRegion(JNIEnv* env, jobject regionObj) { return GetSkRegion(env, regionObj); } } // namespace android core/jni/android/graphics/Region.hdeleted 100644 → 0 +0 −30 Original line number Diff line number Diff line /* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _ANDROID_GRAPHICS_REGION_H_ #define _ANDROID_GRAPHICS_REGION_H_ #include "jni.h" #include "SkRegion.h" namespace android { /* Gets the underlying SkRegion from a Region object. */ extern SkRegion* android_graphics_Region_getSkRegion(JNIEnv* env, jobject regionObj); } // namespace android #endif // _ANDROID_GRAPHICS_REGION_H_ core/jni/android/graphics/apex/android_region.cpp 0 → 100644 +60 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "android/graphics/region.h" #include "GraphicsJNI.h" #include <SkRegion.h> static inline SkRegion::Iterator* ARegionIter_to_SkRegionIter(ARegionIterator* iterator) { return reinterpret_cast<SkRegion::Iterator*>(iterator); } static inline ARegionIterator* SkRegionIter_to_ARegionIter(SkRegion::Iterator* iterator) { return reinterpret_cast<ARegionIterator*>(iterator); } ARegionIterator* ARegionIterator_acquireIterator(JNIEnv* env, jobject regionObj) { SkRegion* region = GraphicsJNI::getNativeRegion(env, regionObj); return (!region) ? nullptr : SkRegionIter_to_ARegionIter(new SkRegion::Iterator(*region)); } void ARegionIterator_releaseIterator(ARegionIterator* iterator) { delete ARegionIter_to_SkRegionIter(iterator); } bool ARegionIterator_isComplex(ARegionIterator* iterator) { return ARegionIter_to_SkRegionIter(iterator)->rgn()->isComplex(); } bool ARegionIterator_isDone(ARegionIterator* iterator) { return ARegionIter_to_SkRegionIter(iterator)->done(); } void ARegionIterator_next(ARegionIterator* iterator) { ARegionIter_to_SkRegionIter(iterator)->next(); } ARect ARegionIterator_getRect(ARegionIterator* iterator) { const SkIRect& rect = ARegionIter_to_SkRegionIter(iterator)->rect(); return { rect.fLeft, rect.fTop, rect.fRight, rect.fBottom }; } ARect ARegionIterator_getTotalBounds(ARegionIterator* iterator) { const SkIRect& bounds = ARegionIter_to_SkRegionIter(iterator)->rgn()->getBounds(); return { bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom }; } core/jni/android/graphics/apex/include/android/graphics/region.h 0 → 100644 +76 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ANDROID_GRAPHICS_REGION_H #define ANDROID_GRAPHICS_REGION_H #include <android/rect.h> #include <sys/cdefs.h> #include <jni.h> __BEGIN_DECLS /** * Opaque handle for a native graphics region iterator. */ typedef struct ARegionIterator ARegionIterator; /** * Returns a iterator for a Java android.graphics.Region * * @param env * @param region * @return ARegionIterator that must be closed and must not live longer than the life * of the jobject. It returns nullptr if the region is not a valid object. */ ARegionIterator* ARegionIterator_acquireIterator(JNIEnv* env, jobject region); void ARegionIterator_releaseIterator(ARegionIterator* iterator); bool ARegionIterator_isComplex(ARegionIterator* iterator); bool ARegionIterator_isDone(ARegionIterator* iterator); void ARegionIterator_next(ARegionIterator* iterator); ARect ARegionIterator_getRect(ARegionIterator* iterator); ARect ARegionIterator_getTotalBounds(ARegionIterator* iterator); __END_DECLS #ifdef __cplusplus namespace android { namespace graphics { class RegionIterator { public: RegionIterator(JNIEnv* env, jobject region) : mIterator(ARegionIterator_acquireIterator(env, region)) {} ~RegionIterator() { ARegionIterator_releaseIterator(mIterator); } bool isValid() const { return mIterator != nullptr; } bool isComplex() { return ARegionIterator_isComplex(mIterator); } bool isDone() { return ARegionIterator_isDone(mIterator); } void next() { ARegionIterator_next(mIterator); } ARect getRect() { return ARegionIterator_getRect(mIterator); } ARect getTotalBounds() const { return ARegionIterator_getTotalBounds(mIterator); } private: ARegionIterator* mIterator; }; }; // namespace graphics }; // namespace android #endif // __cplusplus #endif // ANDROID_GRAPHICS_REGION_H No newline at end of file Loading
core/jni/Android.bp +2 −0 Original line number Diff line number Diff line Loading @@ -339,6 +339,8 @@ cc_library_static { cppflags: ["-Wno-conversion-null"], srcs: [ "android/graphics/apex/android_region.cpp", "android_graphics_Canvas.cpp", "android_graphics_ColorSpace.cpp", "android_graphics_drawable_AnimatedVectorDrawable.cpp", Loading
core/jni/android/graphics/Region.cpp +0 −4 Original line number Diff line number Diff line Loading @@ -360,8 +360,4 @@ int register_android_graphics_Region(JNIEnv* env) NELEM(gRegionIterMethods)); } SkRegion* android_graphics_Region_getSkRegion(JNIEnv* env, jobject regionObj) { return GetSkRegion(env, regionObj); } } // namespace android
core/jni/android/graphics/Region.hdeleted 100644 → 0 +0 −30 Original line number Diff line number Diff line /* * Copyright (C) 2011 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef _ANDROID_GRAPHICS_REGION_H_ #define _ANDROID_GRAPHICS_REGION_H_ #include "jni.h" #include "SkRegion.h" namespace android { /* Gets the underlying SkRegion from a Region object. */ extern SkRegion* android_graphics_Region_getSkRegion(JNIEnv* env, jobject regionObj); } // namespace android #endif // _ANDROID_GRAPHICS_REGION_H_
core/jni/android/graphics/apex/android_region.cpp 0 → 100644 +60 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "android/graphics/region.h" #include "GraphicsJNI.h" #include <SkRegion.h> static inline SkRegion::Iterator* ARegionIter_to_SkRegionIter(ARegionIterator* iterator) { return reinterpret_cast<SkRegion::Iterator*>(iterator); } static inline ARegionIterator* SkRegionIter_to_ARegionIter(SkRegion::Iterator* iterator) { return reinterpret_cast<ARegionIterator*>(iterator); } ARegionIterator* ARegionIterator_acquireIterator(JNIEnv* env, jobject regionObj) { SkRegion* region = GraphicsJNI::getNativeRegion(env, regionObj); return (!region) ? nullptr : SkRegionIter_to_ARegionIter(new SkRegion::Iterator(*region)); } void ARegionIterator_releaseIterator(ARegionIterator* iterator) { delete ARegionIter_to_SkRegionIter(iterator); } bool ARegionIterator_isComplex(ARegionIterator* iterator) { return ARegionIter_to_SkRegionIter(iterator)->rgn()->isComplex(); } bool ARegionIterator_isDone(ARegionIterator* iterator) { return ARegionIter_to_SkRegionIter(iterator)->done(); } void ARegionIterator_next(ARegionIterator* iterator) { ARegionIter_to_SkRegionIter(iterator)->next(); } ARect ARegionIterator_getRect(ARegionIterator* iterator) { const SkIRect& rect = ARegionIter_to_SkRegionIter(iterator)->rect(); return { rect.fLeft, rect.fTop, rect.fRight, rect.fBottom }; } ARect ARegionIterator_getTotalBounds(ARegionIterator* iterator) { const SkIRect& bounds = ARegionIter_to_SkRegionIter(iterator)->rgn()->getBounds(); return { bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom }; }
core/jni/android/graphics/apex/include/android/graphics/region.h 0 → 100644 +76 −0 Original line number Diff line number Diff line /* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef ANDROID_GRAPHICS_REGION_H #define ANDROID_GRAPHICS_REGION_H #include <android/rect.h> #include <sys/cdefs.h> #include <jni.h> __BEGIN_DECLS /** * Opaque handle for a native graphics region iterator. */ typedef struct ARegionIterator ARegionIterator; /** * Returns a iterator for a Java android.graphics.Region * * @param env * @param region * @return ARegionIterator that must be closed and must not live longer than the life * of the jobject. It returns nullptr if the region is not a valid object. */ ARegionIterator* ARegionIterator_acquireIterator(JNIEnv* env, jobject region); void ARegionIterator_releaseIterator(ARegionIterator* iterator); bool ARegionIterator_isComplex(ARegionIterator* iterator); bool ARegionIterator_isDone(ARegionIterator* iterator); void ARegionIterator_next(ARegionIterator* iterator); ARect ARegionIterator_getRect(ARegionIterator* iterator); ARect ARegionIterator_getTotalBounds(ARegionIterator* iterator); __END_DECLS #ifdef __cplusplus namespace android { namespace graphics { class RegionIterator { public: RegionIterator(JNIEnv* env, jobject region) : mIterator(ARegionIterator_acquireIterator(env, region)) {} ~RegionIterator() { ARegionIterator_releaseIterator(mIterator); } bool isValid() const { return mIterator != nullptr; } bool isComplex() { return ARegionIterator_isComplex(mIterator); } bool isDone() { return ARegionIterator_isDone(mIterator); } void next() { ARegionIterator_next(mIterator); } ARect getRect() { return ARegionIterator_getRect(mIterator); } ARect getTotalBounds() const { return ARegionIterator_getTotalBounds(mIterator); } private: ARegionIterator* mIterator; }; }; // namespace graphics }; // namespace android #endif // __cplusplus #endif // ANDROID_GRAPHICS_REGION_H No newline at end of file