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 | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 19 | import android.view.Display; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 20 | import android.view.DisplayInfo; |
| 21 | |
| 22 | import java.io.PrintWriter; |
| 23 | import java.util.ArrayList; |
| 24 | |
| 25 | class DisplayContentList extends ArrayList<DisplayContent> { |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Utility class for keeping track of the WindowStates and other pertinent contents of a |
| 30 | * particular Display. |
| 31 | * |
| 32 | * IMPORTANT: No method from this class should ever be used without holding |
| 33 | * WindowManagerService.mWindowMap. |
| 34 | */ |
| 35 | class DisplayContent { |
| 36 | |
| 37 | /** Unique identifier of this stack. */ |
| 38 | private final int mDisplayId; |
| 39 | |
| 40 | /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element |
| 41 | * from mDisplayWindows; */ |
| 42 | private WindowList mWindows = new WindowList(); |
| 43 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 44 | // This protects the following display size properties, so that |
| 45 | // getDisplaySize() doesn't need to acquire the global lock. This is |
| 46 | // needed because the window manager sometimes needs to use ActivityThread |
| 47 | // while it has its global state locked (for example to load animation |
| 48 | // resources), but the ActivityThread also needs get the current display |
| 49 | // size sometimes when it has its package lock held. |
| 50 | // |
| 51 | // These will only be modified with both mWindowMap and mDisplaySizeLock |
| 52 | // held (in that order) so the window manager doesn't need to acquire this |
| 53 | // lock when needing these values in its normal operation. |
| 54 | final Object mDisplaySizeLock = new Object(); |
| 55 | int mInitialDisplayWidth = 0; |
| 56 | int mInitialDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 57 | int mInitialDisplayDensity = 0; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 58 | int mBaseDisplayWidth = 0; |
| 59 | int mBaseDisplayHeight = 0; |
Dianne Hackborn | dde331c | 2012-08-03 14:01:57 -0700 | [diff] [blame] | 60 | int mBaseDisplayDensity = 0; |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 61 | private final DisplayInfo mDisplayInfo = new DisplayInfo(); |
| 62 | private final Display mDisplay; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 63 | |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 64 | // Accessed directly by all users. |
| 65 | boolean layoutNeeded; |
Craig Mautner | 76a7165 | 2012-09-03 23:23:58 -0700 | [diff] [blame] | 66 | int pendingLayoutChanges; |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 67 | final boolean isDefaultDisplay; |
Craig Mautner | 3983419 | 2012-09-02 07:47:24 -0700 | [diff] [blame] | 68 | |
Craig Mautner | 2d5618c | 2012-10-18 13:55:47 -0700 | [diff] [blame] | 69 | /** |
| 70 | * @param display May not be null. |
| 71 | */ |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 72 | DisplayContent(Display display) { |
| 73 | mDisplay = display; |
| 74 | mDisplayId = display.getDisplayId(); |
| 75 | display.getDisplayInfo(mDisplayInfo); |
Craig Mautner | 69b0818 | 2012-09-05 13:07:13 -0700 | [diff] [blame] | 76 | isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY; |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | int getDisplayId() { |
| 80 | return mDisplayId; |
| 81 | } |
| 82 | |
| 83 | WindowList getWindowList() { |
| 84 | return mWindows; |
| 85 | } |
| 86 | |
Craig Mautner | b47bbc3 | 2012-08-22 17:41:48 -0700 | [diff] [blame] | 87 | Display getDisplay() { |
| 88 | return mDisplay; |
| 89 | } |
| 90 | |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 91 | DisplayInfo getDisplayInfo() { |
| 92 | return mDisplayInfo; |
| 93 | } |
| 94 | |
Craig Mautner | 722285e | 2012-09-07 13:55:58 -0700 | [diff] [blame] | 95 | public void updateDisplayInfo() { |
| 96 | mDisplay.getDisplayInfo(mDisplayInfo); |
| 97 | } |
| 98 | |
Craig Mautner | a91f9e2 | 2012-09-14 16:22:08 -0700 | [diff] [blame] | 99 | public void dump(String prefix, PrintWriter pw) { |
| 100 | pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId); |
| 101 | final String subPrefix = " " + prefix; |
| 102 | pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x"); |
| 103 | pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); |
| 104 | pw.print("dpi"); |
| 105 | if (mInitialDisplayWidth != mBaseDisplayWidth |
| 106 | || mInitialDisplayHeight != mBaseDisplayHeight |
| 107 | || mInitialDisplayDensity != mBaseDisplayDensity) { |
| 108 | pw.print(" base="); |
| 109 | pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); |
| 110 | pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); |
| 111 | } |
| 112 | pw.print(" cur="); |
| 113 | pw.print(mDisplayInfo.logicalWidth); |
| 114 | pw.print("x"); pw.print(mDisplayInfo.logicalHeight); |
| 115 | pw.print(" app="); |
| 116 | pw.print(mDisplayInfo.appWidth); |
| 117 | pw.print("x"); pw.print(mDisplayInfo.appHeight); |
| 118 | pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); |
| 119 | pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); |
| 120 | pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); |
| 121 | pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); |
Craig Mautner | 2ad9207 | 2013-02-25 16:19:24 -0800 | [diff] [blame] | 122 | pw.print(subPrefix); pw.print("layoutNeeded="); pw.print(layoutNeeded); |
Craig Mautner | 59c0097 | 2012-07-30 12:10:24 -0700 | [diff] [blame] | 123 | pw.println(); |
| 124 | } |
| 125 | } |