DisplayContent.java revision dde331cebd87982faded6818ad5f9927ff994c96
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 mInitialDisplayDensity = 0;
60    int mBaseDisplayWidth = 0;
61    int mBaseDisplayHeight = 0;
62    int mBaseDisplayDensity = 0;
63    final DisplayManagerService mDisplayManager;
64    final DisplayInfo mDisplayInfo = new DisplayInfo();
65
66    DisplayContent(DisplayManagerService displayManager, final int displayId) {
67        mDisplayManager = displayManager;
68        mDisplayId = displayId;
69        displayManager.getDisplayInfo(displayId, mDisplayInfo);
70    }
71
72    int getDisplayId() {
73        return mDisplayId;
74    }
75
76    WindowList getWindowList() {
77        return mWindows;
78    }
79
80    DisplayInfo getDisplayInfo() {
81        return mDisplayInfo;
82    }
83
84    public void dump(PrintWriter pw) {
85        pw.print("  Display: mDisplayId="); pw.println(mDisplayId);
86        pw.print("  init="); pw.print(mInitialDisplayWidth); pw.print("x");
87        pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
88        pw.print("dpi");
89        if (mInitialDisplayWidth != mBaseDisplayWidth
90                || mInitialDisplayHeight != mBaseDisplayHeight
91                || mInitialDisplayDensity != mBaseDisplayDensity) {
92            pw.print(" base=");
93            pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
94            pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
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