DisplayContent.java revision 4f67ba6ba4e861b287a3ff0323c107aa77f66264
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 17package com.android.server.wm; 18 19import android.view.DisplayInfo; 20 21import com.android.server.display.DisplayManagerService; 22 23import java.io.PrintWriter; 24import java.util.ArrayList; 25 26class 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 */ 36class DisplayContent { 37 38 /** Unique identifier of this stack. */ 39 private final int mDisplayId; 40 41 /** Z-ordered (bottom-most first) list of all Window objects. Assigned to an element 42 * from mDisplayWindows; */ 43 private WindowList mWindows = new WindowList(); 44 45 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; 59 int mBaseDisplayWidth = 0; 60 int mBaseDisplayHeight = 0; 61 final DisplayManagerService mDisplayManager; 62 final DisplayInfo mDisplayInfo = new DisplayInfo(); 63 64 DisplayContent(DisplayManagerService displayManager, final int displayId) { 65 mDisplayManager = displayManager; 66 mDisplayId = displayId; 67 displayManager.getDisplayInfo(displayId, mDisplayInfo); 68 } 69 70 int getDisplayId() { 71 return mDisplayId; 72 } 73 74 WindowList getWindowList() { 75 return mWindows; 76 } 77 78 DisplayInfo getDisplayInfo() { 79 return mDisplayInfo; 80 } 81 82 public void dump(PrintWriter pw) { 83 pw.print(" Display: mDisplayId="); pw.println(mDisplayId); 84 pw.print(" init="); pw.print(mInitialDisplayWidth); pw.print("x"); 85 pw.print(mInitialDisplayHeight); 86 if (mInitialDisplayWidth != mBaseDisplayWidth 87 || mInitialDisplayHeight != mBaseDisplayHeight) { 88 pw.print(" base="); 89 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); 90 } 91 if (mInitialDisplayWidth != mDisplayInfo.logicalWidth 92 || mInitialDisplayHeight != mDisplayInfo.logicalHeight) { 93 pw.print(" init="); pw.print(mInitialDisplayWidth); 94 pw.print("x"); pw.print(mInitialDisplayHeight); 95 } 96 pw.print(" cur="); 97 pw.print(mDisplayInfo.logicalWidth); 98 pw.print("x"); pw.print(mDisplayInfo.logicalHeight); 99 pw.print(" app="); 100 pw.print(mDisplayInfo.appWidth); 101 pw.print("x"); pw.print(mDisplayInfo.appHeight); 102 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); 103 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); 104 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); 105 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); 106 pw.println(); 107 } 108} 109