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