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
17 #include "android/graphics/region.h"
18
19 #include "GraphicsJNI.h"
20
21 #include <SkRegion.h>
22
ARegionIter_to_SkRegionIter(ARegionIterator * iterator)23 static inline SkRegion::Iterator* ARegionIter_to_SkRegionIter(ARegionIterator* iterator) {
24 return reinterpret_cast<SkRegion::Iterator*>(iterator);
25 }
26
SkRegionIter_to_ARegionIter(SkRegion::Iterator * iterator)27 static inline ARegionIterator* SkRegionIter_to_ARegionIter(SkRegion::Iterator* iterator) {
28 return reinterpret_cast<ARegionIterator*>(iterator);
29 }
30
ARegionIterator_acquireIterator(JNIEnv * env,jobject regionObj)31 ARegionIterator* ARegionIterator_acquireIterator(JNIEnv* env, jobject regionObj) {
32 SkRegion* region = GraphicsJNI::getNativeRegion(env, regionObj);
33 return (!region) ? nullptr : SkRegionIter_to_ARegionIter(new SkRegion::Iterator(*region));
34 }
35
ARegionIterator_releaseIterator(ARegionIterator * iterator)36 void ARegionIterator_releaseIterator(ARegionIterator* iterator) {
37 delete ARegionIter_to_SkRegionIter(iterator);
38 }
39
ARegionIterator_isComplex(ARegionIterator * iterator)40 bool ARegionIterator_isComplex(ARegionIterator* iterator) {
41 return ARegionIter_to_SkRegionIter(iterator)->rgn()->isComplex();
42 }
43
ARegionIterator_isDone(ARegionIterator * iterator)44 bool ARegionIterator_isDone(ARegionIterator* iterator) {
45 return ARegionIter_to_SkRegionIter(iterator)->done();
46 }
47
ARegionIterator_next(ARegionIterator * iterator)48 void ARegionIterator_next(ARegionIterator* iterator) {
49 ARegionIter_to_SkRegionIter(iterator)->next();
50 }
51
ARegionIterator_getRect(ARegionIterator * iterator)52 ARect ARegionIterator_getRect(ARegionIterator* iterator) {
53 const SkIRect& rect = ARegionIter_to_SkRegionIter(iterator)->rect();
54 return { rect.fLeft, rect.fTop, rect.fRight, rect.fBottom };
55 }
56
ARegionIterator_getTotalBounds(ARegionIterator * iterator)57 ARect ARegionIterator_getTotalBounds(ARegionIterator* iterator) {
58 const SkIRect& bounds = ARegionIter_to_SkRegionIter(iterator)->rgn()->getBounds();
59 return { bounds.fLeft, bounds.fTop, bounds.fRight, bounds.fBottom };
60 }
61