DisplayContent.java revision 1cf70bbf96930662cab0e699d70b62865766ff52
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.os.RemoteCallbackList; 20import android.view.Display; 21import android.view.DisplayInfo; 22import android.view.IDisplayContentChangeListener; 23 24import java.io.PrintWriter; 25import java.util.ArrayList; 26 27class 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 */ 37class 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 46 // Specification for magnifying the display content. 47 MagnificationSpec mMagnificationSpec; 48 49 // Callback for observing content changes on a display. 50 RemoteCallbackList<IDisplayContentChangeListener> mDisplayContentChangeListeners; 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; 65 int mInitialDisplayDensity = 0; 66 int mBaseDisplayWidth = 0; 67 int mBaseDisplayHeight = 0; 68 int mBaseDisplayDensity = 0; 69 final DisplayInfo mDisplayInfo = new DisplayInfo(); 70 final Display mDisplay; 71 72 // Accessed directly by all users. 73 boolean layoutNeeded; 74 int pendingLayoutChanges; 75 final boolean isDefaultDisplay; 76 77 DisplayContent(Display display) { 78 mDisplay = display; 79 mDisplayId = display.getDisplayId(); 80 display.getDisplayInfo(mDisplayInfo); 81 isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY; 82 } 83 84 int getDisplayId() { 85 return mDisplayId; 86 } 87 88 WindowList getWindowList() { 89 return mWindows; 90 } 91 92 Display getDisplay() { 93 return mDisplay; 94 } 95 96 DisplayInfo getDisplayInfo() { 97 // TODO: Add a listener for changes to Display and update mDisplayInfo when appropriate. 98 return mDisplayInfo; 99 } 100 101 public void dump(PrintWriter pw) { 102 pw.print(" Display: mDisplayId="); pw.println(mDisplayId); 103 pw.print(" init="); pw.print(mInitialDisplayWidth); pw.print("x"); 104 pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity); 105 pw.print("dpi"); 106 if (mInitialDisplayWidth != mBaseDisplayWidth 107 || mInitialDisplayHeight != mBaseDisplayHeight 108 || mInitialDisplayDensity != mBaseDisplayDensity) { 109 pw.print(" base="); 110 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight); 111 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi"); 112 } 113 pw.print(" cur="); 114 pw.print(mDisplayInfo.logicalWidth); 115 pw.print("x"); pw.print(mDisplayInfo.logicalHeight); 116 pw.print(" app="); 117 pw.print(mDisplayInfo.appWidth); 118 pw.print("x"); pw.print(mDisplayInfo.appHeight); 119 pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth); 120 pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight); 121 pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth); 122 pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight); 123 pw.print(" layoutNeeded="); pw.println(layoutNeeded); 124 pw.print("magnificationSpec="); pw.println(mMagnificationSpec.toString()); 125 pw.println(); 126 } 127} 128