blob: 0a4ab67f033da079ff7c4014f90b53b51161a33c [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/**
24 * A holder that contains a collection of rectangular areas identified by int id. Each individual
25 * region can be updated separately.
26 */
27class TapExcludeRegionHolder {
28 private SparseArray<Rect> mTapExcludeRects = new SparseArray<>();
29
30 /** Update the specified region with provided position and size. */
31 void updateRegion(int regionId, int left, int top, int width, int height) {
32 if (width <= 0 || height <= 0) {
33 // A region became empty - remove it.
34 mTapExcludeRects.remove(regionId);
35 return;
36 }
37
38 Rect region = mTapExcludeRects.get(regionId);
39 if (region == null) {
40 region = new Rect();
41 }
42 region.set(left, top, left + width, top + height);
43 mTapExcludeRects.put(regionId, region);
44 }
45
46 /**
47 * Union the provided region with current region formed by this container.
48 */
49 void amendRegion(Region region, Rect boundingRegion) {
50 for (int i = mTapExcludeRects.size() - 1; i>= 0 ; --i) {
51 final Rect rect = mTapExcludeRects.valueAt(i);
Tiger Huang04dc4cc2019-01-17 18:41:41 +080052 if (boundingRegion != null) {
53 rect.intersect(boundingRegion);
54 }
Andrii Kulian4b6599e2018-01-15 17:24:08 -080055 region.union(rect);
56 }
57 }
58}