1 /* 2 * Copyright (C) 2020 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 package com.android.server.display; 18 19 import java.util.ArrayList; 20 import java.util.List; 21 22 /** 23 * Represents a collection of {@link LogicalDisplay}s which act in unison for certain behaviors and 24 * operations; particularly display-state. 25 * 26 * @hide 27 */ 28 public class DisplayGroup { 29 30 private final List<LogicalDisplay> mDisplays = new ArrayList<>(); 31 private final int mGroupId; 32 33 private int mChangeCount; 34 DisplayGroup(int groupId)35 DisplayGroup(int groupId) { 36 mGroupId = groupId; 37 } 38 39 /** Returns the identifier for the Group. */ getGroupId()40 int getGroupId() { 41 return mGroupId; 42 } 43 44 /** 45 * Adds the provided {@code display} to the Group 46 * 47 * @param display the {@link LogicalDisplay} to add to the Group 48 */ addDisplayLocked(LogicalDisplay display)49 void addDisplayLocked(LogicalDisplay display) { 50 if (!containsLocked(display)) { 51 mChangeCount++; 52 mDisplays.add(display); 53 } 54 } 55 containsLocked(LogicalDisplay display)56 boolean containsLocked(LogicalDisplay display) { 57 return mDisplays.contains(display); 58 } 59 60 /** 61 * Removes the provided {@code display} from the Group. 62 * 63 * @param display The {@link LogicalDisplay} to remove from the Group. 64 * @return {@code true} if the {@code display} was removed; otherwise {@code false} 65 */ removeDisplayLocked(LogicalDisplay display)66 boolean removeDisplayLocked(LogicalDisplay display) { 67 mChangeCount++; 68 return mDisplays.remove(display); 69 } 70 71 /** Returns {@code true} if there are no {@link LogicalDisplay LogicalDisplays} in the Group. */ isEmptyLocked()72 boolean isEmptyLocked() { 73 return mDisplays.isEmpty(); 74 } 75 76 /** Returns a count of the changes made to this display group. */ getChangeCountLocked()77 int getChangeCountLocked() { 78 return mChangeCount; 79 } 80 81 /** Returns the number of {@link LogicalDisplay LogicalDisplays} in the Group. */ getSizeLocked()82 int getSizeLocked() { 83 return mDisplays.size(); 84 } 85 86 /** Returns the ID of the {@link LogicalDisplay} at the provided {@code index}. */ getIdLocked(int index)87 int getIdLocked(int index) { 88 return mDisplays.get(index).getDisplayIdLocked(); 89 } 90 } 91