blob: 22f529b28b8ed29c29ed9fa0cef26179f6f17217 [file] [log] [blame]
Andrii Kulian4b6599e2018-01-15 17:24:08 -08001/*
2 * Copyright 2018 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
17package com.android.server.wm;
18
19import android.graphics.Rect;
20import android.graphics.Region;
21import android.util.SparseArray;
22
23/**
Tiger Huang2b210c22019-03-18 21:21:26 +080024 * A holder that contains a collection of regions identified by int id. Each individual region can
25 * be updated separately.
Andrii Kulian4b6599e2018-01-15 17:24:08 -080026 */
27class TapExcludeRegionHolder {
Tiger Huang2b210c22019-03-18 21:21:26 +080028 private SparseArray<Region> mTapExcludeRegions = new SparseArray<>();
Andrii Kulian4b6599e2018-01-15 17:24:08 -080029
30 /** Update the specified region with provided position and size. */
Tiger Huang2b210c22019-03-18 21:21:26 +080031 void updateRegion(int regionId, Region region) {
32 // Remove the previous one because there is a new one incoming.
33 mTapExcludeRegions.remove(regionId);
34
35 if (region == null || region.isEmpty()) {
36 // The incoming region is invalid. Don't use it.
Andrii Kulian4b6599e2018-01-15 17:24:08 -080037 return;
38 }
39
Tiger Huang2b210c22019-03-18 21:21:26 +080040 mTapExcludeRegions.put(regionId, region);
Andrii Kulian4b6599e2018-01-15 17:24:08 -080041 }
42
43 /**
44 * Union the provided region with current region formed by this container.
45 */
Tiger Huang2b210c22019-03-18 21:21:26 +080046 void amendRegion(Region region, Rect bounds) {
47 for (int i = mTapExcludeRegions.size() - 1; i >= 0; --i) {
48 final Region r = mTapExcludeRegions.valueAt(i);
49 if (bounds != null) {
50 r.op(bounds, Region.Op.INTERSECT);
Tiger Huang04dc4cc2019-01-17 18:41:41 +080051 }
Tiger Huang2b210c22019-03-18 21:21:26 +080052 region.op(r, Region.Op.UNION);
Andrii Kulian4b6599e2018-01-15 17:24:08 -080053 }
54 }
55}