1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #ifndef ANDROID_GRAPHICS_REGION_H
17 #define ANDROID_GRAPHICS_REGION_H
18 
19 #include <cutils/compiler.h>
20 #include <android/rect.h>
21 #include <sys/cdefs.h>
22 #include <jni.h>
23 
24 __BEGIN_DECLS
25 
26 /**
27 * Opaque handle for a native graphics region iterator.
28 */
29 typedef struct ARegionIterator ARegionIterator;
30 
31 /**
32  * Returns a iterator for a Java android.graphics.Region
33  *
34  * @param env
35  * @param region
36  * @return ARegionIterator that must be closed and must not live longer than the life
37  *         of the jobject.  It returns nullptr if the region is not a valid object.
38  */
39 ANDROID_API ARegionIterator* ARegionIterator_acquireIterator(JNIEnv* env, jobject region);
40 
41 ANDROID_API void ARegionIterator_releaseIterator(ARegionIterator* iterator);
42 
43 ANDROID_API bool ARegionIterator_isComplex(ARegionIterator* iterator);
44 
45 ANDROID_API bool ARegionIterator_isDone(ARegionIterator* iterator);
46 
47 ANDROID_API void ARegionIterator_next(ARegionIterator* iterator);
48 
49 ANDROID_API ARect ARegionIterator_getRect(ARegionIterator* iterator);
50 
51 ANDROID_API ARect ARegionIterator_getTotalBounds(ARegionIterator* iterator);
52 
53 __END_DECLS
54 
55 #ifdef	__cplusplus
56 namespace android {
57 namespace graphics {
58     class RegionIterator {
59     public:
RegionIterator(JNIEnv * env,jobject region)60         RegionIterator(JNIEnv* env, jobject region)
61                 : mIterator(ARegionIterator_acquireIterator(env, region)) {}
~RegionIterator()62         ~RegionIterator() { ARegionIterator_releaseIterator(mIterator); }
63 
isValid()64         bool isValid() const { return mIterator != nullptr; }
isComplex()65         bool isComplex() { return ARegionIterator_isComplex(mIterator); }
isDone()66         bool isDone() { return ARegionIterator_isDone(mIterator); }
next()67         void next() { ARegionIterator_next(mIterator); }
getRect()68         ARect getRect() { return ARegionIterator_getRect(mIterator); }
getTotalBounds()69         ARect getTotalBounds() const { return ARegionIterator_getTotalBounds(mIterator); }
70     private:
71         ARegionIterator* mIterator;
72     };
73 }; // namespace graphics
74 }; // namespace android
75 
76 #endif // __cplusplus
77 #endif // ANDROID_GRAPHICS_REGION_H