Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 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.wm; |
| 18 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 19 | import android.graphics.Rect; |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 20 | import android.view.Display; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 21 | import android.view.DisplayInfo; |
| 22 | |
| 23 | import java.io.PrintWriter; |
| 24 | import java.util.ArrayList; |
| 25 | |
| 26 | class DisplayContentList extends ArrayList<DisplayContent> { |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * Utility class for keeping track of the WindowStates and other pertinent contents of a |
| 31 | * particular Display. |
| 32 | * |
| 33 | * IMPORTANT: No method from this class should ever be used without holding |
| 34 | * WindowManagerService.mWindowMap. |
| 35 | */ |
| 36 | class DisplayContent { |
Craig Mautner | 496bdbb | 2013-02-14 09:32:55 -0800 | [diff] [blame] | 37 | // private final static String TAG = "DisplayContent"; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 38 | |
| 39 | /** Unique identifier of this stack. */ |
| 40 | private final int mDisplayId; |
| 41 | |
| 42 | /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element |
| 43 | * from mDisplayWindows; */ |
| 44 | private WindowList mWindows = new WindowList(); |
| 45 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 46 | // This protects the following display size properties, so that |
| 47 | // getDisplaySize() doesn't need to acquire the global lock. This is |
| 48 | // needed because the window manager sometimes needs to use ActivityThread |
| 49 | // while it has its global state locked (for example to load animation |
| 50 | // resources), but the ActivityThread also needs get the current display |
| 51 | // size sometimes when it has its package lock held. |
| 52 | // |
| 53 | // These will only be modified with both mWindowMap and mDisplaySizeLock |
| 54 | // held (in that order) so the window manager doesn't need to acquire this |
| 55 | // lock when needing these values in its normal operation. |
| 56 | final Object mDisplaySizeLock = new Object(); |
| 57 | int mInitialDisplayWidth = 0; |
| 58 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 59 | int mInitialDisplayDensity = 0; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 60 | int mBaseDisplayWidth = 0; |
| 61 | int mBaseDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 62 | int mBaseDisplayDensity = 0; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 63 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
| 64 | private final Display mDisplay; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 65 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 66 | // Accessed directly by all users. |
| 67 | boolean layoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 68 | int pendingLayoutChanges; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 69 | final boolean isDefaultDisplay; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 70 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 71 | /** |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 72 | * Window tokens that are in the process of exiting, but still |
| 73 | * on screen for animations. |
| 74 | */ |
| 75 | final ArrayList<WindowToken> mExitingTokens = new ArrayList<WindowToken>(); |
| 76 | |
| 77 | /** |
| 78 | * Application tokens that are in the process of exiting, but still |
| 79 | * on screen for animations. |
| 80 | */ |
| 81 | final AppTokenList mExitingAppTokens = new AppTokenList(); |
| 82 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 83 | ArrayList<StackBox> mStackBoxes = new ArrayList<StackBox>(); |
| 84 | |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 85 | /** |
| 86 | * Sorted most recent at top, oldest at [0]. |
| 87 | */ |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 88 | ArrayList<Task> mTasks = new ArrayList<Task>(); |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 89 | |
| 90 | /** |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 91 | * @param display May not be null. |
| 92 | */ |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 93 | DisplayContent(Display display) { |
| 94 | mDisplay = display; |
| 95 | mDisplayId = display.getDisplayId(); |
| 96 | display.getDisplayInfo(mDisplayInfo); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 97 | isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | int getDisplayId() { |
| 101 | return mDisplayId; |
| 102 | } |
| 103 | |
| 104 | WindowList getWindowList() { |
| 105 | return mWindows; |
| 106 | } |
| 107 | |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 108 | Display getDisplay() { |
| 109 | return mDisplay; |
| 110 | } |
| 111 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 112 | DisplayInfo getDisplayInfo() { |
| 113 | return mDisplayInfo; |
| 114 | } |
| 115 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 116 | ArrayList<Task> getTasks() { |
| 117 | return mTasks; |
| 118 | } |
| 119 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 120 | public void updateDisplayInfo() { |
| 121 | mDisplay.getDisplayInfo(mDisplayInfo); |
| 122 | } |
| 123 | |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 124 | int numTokens() { |
| 125 | int count = 0; |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 126 | for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 127 | count += mTasks.get(taskNdx).mAppTokens.size(); |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 128 | } |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 129 | return count; |
Craig Mautner | 05d6272ba | 2013-02-11 09:39:27 -0800 | [diff] [blame] | 130 | } |
| 131 | |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 132 | TaskStack createStack(int stackId, int relativeStackId, int position, float weight) { |
| 133 | TaskStack newStack = null; |
| 134 | if (mStackBoxes.isEmpty()) { |
| 135 | StackBox newBox = new StackBox(this, new Rect(0, 0, mDisplayInfo.logicalWidth, |
| 136 | mDisplayInfo.logicalHeight)); |
| 137 | mStackBoxes.add(newBox); |
| 138 | newStack = new TaskStack(stackId, newBox); |
| 139 | newBox.mStack = newStack; |
| 140 | } else { |
| 141 | int stackBoxNdx; |
| 142 | for (stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) { |
| 143 | final StackBox box = mStackBoxes.get(stackBoxNdx); |
| 144 | if (position == StackBox.TASK_STACK_GOES_OVER |
| 145 | || position == StackBox.TASK_STACK_GOES_UNDER) { |
| 146 | // Position indicates a new box is added at top level only. |
| 147 | final TaskStack stack = box.mStack; |
| 148 | if (stack != null && stack.mStackId == relativeStackId) { |
| 149 | final int offset = position == StackBox.TASK_STACK_GOES_OVER ? 1 : 0; |
| 150 | StackBox newBox = new StackBox(this, box.mBounds); |
| 151 | newStack = new TaskStack(stackId, newBox); |
| 152 | newBox.mStack = newStack; |
| 153 | mStackBoxes.add(stackBoxNdx + offset, newBox); |
| 154 | break; |
| 155 | } |
| 156 | } else { |
| 157 | // Remaining position values indicate a box must be split. |
| 158 | newStack = box.split(stackId, relativeStackId, position, weight); |
| 159 | if (newStack != null) { |
| 160 | break; |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | if (stackBoxNdx >= 0) { |
| 165 | throw new IllegalArgumentException("createStack: stackId " + stackId + " not found."); |
| 166 | } |
| 167 | } |
| 168 | return newStack; |
| 169 | } |
| 170 | |
| 171 | boolean addTaskToStack(Task task, int stackId, boolean toTop) { |
| 172 | int stackBoxNdx; |
| 173 | for (stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) { |
| 174 | final StackBox box = mStackBoxes.get(stackBoxNdx); |
| 175 | if (box.addTaskToStack(task, stackId, toTop)) { |
| 176 | layoutNeeded = true; |
| 177 | break; |
| 178 | } |
| 179 | } |
| 180 | return false; |
| 181 | } |
| 182 | |
| 183 | boolean resizeStack(int stackId, float weight) { |
| 184 | int stackBoxNdx; |
| 185 | for (stackBoxNdx = mStackBoxes.size() - 1; stackBoxNdx >= 0; --stackBoxNdx) { |
| 186 | final StackBox box = mStackBoxes.get(stackBoxNdx); |
| 187 | if (box.resize(stackId, weight)) { |
| 188 | return true; |
| 189 | } |
| 190 | } |
| 191 | return false; |
| 192 | } |
| 193 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 194 | public void dump(String prefix, PrintWriter pw) { |
| 195 | pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId); |
| 196 | final String subPrefix = " " + prefix; |
| 197 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
| 198 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 199 | pw.print("dpi"); |
| 200 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 201 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 202 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 203 | pw.print(" base="); |
| 204 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 205 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 206 | } |
| 207 | pw.print(" cur="); |
| 208 | pw.print(mDisplayInfo.logicalWidth); |
| 209 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 210 | pw.print(" app="); |
| 211 | pw.print(mDisplayInfo.appWidth); |
| 212 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 213 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 214 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 215 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 216 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
Dianne Hackborn | c652de8 | 2013-02-15 16:32:56 -0800 | [diff] [blame] | 217 | pw.print(subPrefix); pw.print("layoutNeeded="); pw.println(layoutNeeded); |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 218 | int ndx = numTokens(); |
| 219 | if (ndx > 0) { |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 220 | pw.println(); |
| 221 | pw.println(" Application tokens in Z order:"); |
Craig Mautner | c00204b | 2013-03-05 15:02:14 -0800 | [diff] [blame] | 222 | for (int taskNdx = mTasks.size() - 1; taskNdx >= 0; --taskNdx) { |
| 223 | AppTokenList tokens = mTasks.get(taskNdx).mAppTokens; |
Craig Mautner | f81b9087 | 2013-02-26 13:02:43 -0800 | [diff] [blame] | 224 | for (int tokenNdx = tokens.size() - 1; tokenNdx >= 0; --tokenNdx) { |
| 225 | final AppWindowToken wtoken = tokens.get(tokenNdx); |
| 226 | pw.print(" App #"); pw.print(ndx--); |
| 227 | pw.print(' '); pw.print(wtoken); pw.println(":"); |
| 228 | wtoken.dump(pw, " "); |
| 229 | } |
Craig Mautner | b1fd65c0 | 2013-02-05 13:34:57 -0800 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | if (mExitingTokens.size() > 0) { |
| 233 | pw.println(); |
| 234 | pw.println(" Exiting tokens:"); |
| 235 | for (int i=mExitingTokens.size()-1; i>=0; i--) { |
| 236 | WindowToken token = mExitingTokens.get(i); |
| 237 | pw.print(" Exiting #"); pw.print(i); |
| 238 | pw.print(' '); pw.print(token); |
| 239 | pw.println(':'); |
| 240 | token.dump(pw, " "); |
| 241 | } |
| 242 | } |
| 243 | if (mExitingAppTokens.size() > 0) { |
| 244 | pw.println(); |
| 245 | pw.println(" Exiting application tokens:"); |
| 246 | for (int i=mExitingAppTokens.size()-1; i>=0; i--) { |
| 247 | WindowToken token = mExitingAppTokens.get(i); |
| 248 | pw.print(" Exiting App #"); pw.print(i); |
| 249 | pw.print(' '); pw.print(token); |
| 250 | pw.println(':'); |
| 251 | token.dump(pw, " "); |
| 252 | } |
| 253 | } |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 254 | pw.println(); |
| 255 | } |
| 256 | } |