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.Display;
20import android.view.DisplayInfo;
21
22import java.io.PrintWriter;
23import java.util.ArrayList;
24
25class 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 */
35class 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
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;
57    int mInitialDisplayDensity = 0;
58    int mBaseDisplayWidth = 0;
59    int mBaseDisplayHeight = 0;
60    int mBaseDisplayDensity = 0;
61    private final DisplayInfo mDisplayInfo = new DisplayInfo();
62    private final Display mDisplay;
63
64    // Accessed directly by all users.
65    boolean layoutNeeded;
66    int pendingLayoutChanges;
67    final boolean isDefaultDisplay;
68
69    /**
70     * @param display May not be null.
71     */
72    DisplayContent(Display display) {
73        mDisplay = display;
74        mDisplayId = display.getDisplayId();
75        display.getDisplayInfo(mDisplayInfo);
76        isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY;
77    }
78
79    int getDisplayId() {
80        return mDisplayId;
81    }
82
83    WindowList getWindowList() {
84        return mWindows;
85    }
86
87    Display getDisplay() {
88        return mDisplay;
89    }
90
91    DisplayInfo getDisplayInfo() {
92        return mDisplayInfo;
93    }
94
95    public void updateDisplayInfo() {
96        mDisplay.getDisplayInfo(mDisplayInfo);
97    }
98
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);
122        pw.print(subPrefix); pw.print("layoutNeeded="); pw.print(layoutNeeded);
123        pw.println();
124    }
125}
126