• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 android.util.IndentingPrintWriter;
20 
21 import java.util.ArrayList;
22 import java.util.List;
23 
24 /**
25  * Represents a collection of {@link LogicalDisplay}s which act in unison for certain behaviors and
26  * operations; particularly display-state.
27  *
28  * @hide
29  */
30 public class DisplayGroup {
31 
32     private final List<LogicalDisplay> mDisplays = new ArrayList<>();
33     private final int mGroupId;
34 
35     private int mChangeCount;
36 
DisplayGroup(int groupId)37     DisplayGroup(int groupId) {
38         mGroupId = groupId;
39     }
40 
41     /** Returns the identifier for the Group. */
getGroupId()42     int getGroupId() {
43         return mGroupId;
44     }
45 
46     /**
47      * Adds the provided {@code display} to the Group
48      *
49      * @param display the {@link LogicalDisplay} to add to the Group
50      */
addDisplayLocked(LogicalDisplay display)51     void addDisplayLocked(LogicalDisplay display) {
52         if (!containsLocked(display)) {
53             mChangeCount++;
54             mDisplays.add(display);
55         }
56     }
57 
containsLocked(LogicalDisplay display)58     boolean containsLocked(LogicalDisplay display) {
59         return mDisplays.contains(display);
60     }
61 
62     /**
63      * Removes the provided {@code display} from the Group.
64      *
65      * @param display The {@link LogicalDisplay} to remove from the Group.
66      * @return {@code true} if the {@code display} was removed; otherwise {@code false}
67      */
removeDisplayLocked(LogicalDisplay display)68     boolean removeDisplayLocked(LogicalDisplay display) {
69         mChangeCount++;
70         return mDisplays.remove(display);
71     }
72 
73     /** Returns {@code true} if there are no {@link LogicalDisplay LogicalDisplays} in the Group. */
isEmptyLocked()74     boolean isEmptyLocked() {
75         return mDisplays.isEmpty();
76     }
77 
78     /** Returns a count of the changes made to this display group. */
getChangeCountLocked()79     int getChangeCountLocked() {
80         return mChangeCount;
81     }
82 
83     /** Returns the number of {@link LogicalDisplay LogicalDisplays} in the Group. */
getSizeLocked()84     int getSizeLocked() {
85         return mDisplays.size();
86     }
87 
88     /** Returns the ID of the {@link LogicalDisplay} at the provided {@code index}. */
getIdLocked(int index)89     int getIdLocked(int index) {
90         return mDisplays.get(index).getDisplayIdLocked();
91     }
92 
93     /** Returns the IDs of the {@link LogicalDisplay}s belonging to the DisplayGroup. */
getIdsLocked()94     int[] getIdsLocked() {
95         final int numDisplays = mDisplays.size();
96         final int[] displayIds = new int[numDisplays];
97         for (int i = 0; i < numDisplays; i++) {
98             displayIds[i] = mDisplays.get(i).getDisplayIdLocked();
99         }
100         return displayIds;
101     }
102 
103     /** Dumps information about the DisplayGroup. */
dumpLocked(IndentingPrintWriter ipw)104     void dumpLocked(IndentingPrintWriter ipw) {
105         final int numDisplays = mDisplays.size();
106         for (int i = 0; i < numDisplays; i++) {
107             LogicalDisplay logicalDisplay = mDisplays.get(i);
108             ipw.println("Display " + logicalDisplay.getDisplayIdLocked() + " "
109                     + logicalDisplay.getPrimaryDisplayDeviceLocked());
110         }
111     }
112 }
113