blob: 2030e7e6986185ab4ed2a0fa9f47fa5225fcc167 [file] [log] [blame]
Derek Sollenberger40d78132019-08-12 11:06:08 -04001/*
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
23static inline SkRegion::Iterator* ARegionIter_to_SkRegionIter(ARegionIterator* iterator) {
24 return reinterpret_cast<SkRegion::Iterator*>(iterator);
25}
26
27static inline ARegionIterator* SkRegionIter_to_ARegionIter(SkRegion::Iterator* iterator) {
28 return reinterpret_cast<ARegionIterator*>(iterator);
29}
30
31ARegionIterator* 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
36void ARegionIterator_releaseIterator(ARegionIterator* iterator) {
37 delete ARegionIter_to_SkRegionIter(iterator);
38}
39
40bool ARegionIterator_isComplex(ARegionIterator* iterator) {
41 return ARegionIter_to_SkRegionIter(iterator)->rgn()->isComplex();
42}
43
44bool ARegionIterator_isDone(ARegionIterator* iterator) {
45 return ARegionIter_to_SkRegionIter(iterator)->done();
46}
47
48void ARegionIterator_next(ARegionIterator* iterator) {
49 ARegionIter_to_SkRegionIter(iterator)->next();
50}
51
52ARect 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
57ARect 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}