Home | History | Annotate | Download | only in wm
      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 
     19 import android.os.RemoteCallbackList;
     20 import android.view.Display;
     21 import android.view.DisplayInfo;
     22 import android.view.IDisplayContentChangeListener;
     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 
     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     private final DisplayInfo mDisplayInfo = new DisplayInfo();
     70     private final Display mDisplay;
     71 
     72     // Accessed directly by all users.
     73     boolean layoutNeeded;
     74     int pendingLayoutChanges;
     75     final boolean isDefaultDisplay;
     76 
     77     /**
     78      * @param display May not be null.
     79      */
     80     DisplayContent(Display display) {
     81         mDisplay = display;
     82         mDisplayId = display.getDisplayId();
     83         display.getDisplayInfo(mDisplayInfo);
     84         isDefaultDisplay = mDisplayId == Display.DEFAULT_DISPLAY;
     85     }
     86 
     87     int getDisplayId() {
     88         return mDisplayId;
     89     }
     90 
     91     WindowList getWindowList() {
     92         return mWindows;
     93     }
     94 
     95     Display getDisplay() {
     96         return mDisplay;
     97     }
     98 
     99     DisplayInfo getDisplayInfo() {
    100         return mDisplayInfo;
    101     }
    102 
    103     public void updateDisplayInfo() {
    104         mDisplay.getDisplayInfo(mDisplayInfo);
    105     }
    106 
    107     public void dump(String prefix, PrintWriter pw) {
    108         pw.print(prefix); pw.print("Display: mDisplayId="); pw.println(mDisplayId);
    109         final String subPrefix = "  " + prefix;
    110         pw.print(subPrefix); pw.print("init="); pw.print(mInitialDisplayWidth); pw.print("x");
    111             pw.print(mInitialDisplayHeight); pw.print(" "); pw.print(mInitialDisplayDensity);
    112             pw.print("dpi");
    113             if (mInitialDisplayWidth != mBaseDisplayWidth
    114                     || mInitialDisplayHeight != mBaseDisplayHeight
    115                     || mInitialDisplayDensity != mBaseDisplayDensity) {
    116                 pw.print(" base=");
    117                 pw.print(mBaseDisplayWidth); pw.print("x"); pw.print(mBaseDisplayHeight);
    118                 pw.print(" "); pw.print(mBaseDisplayDensity); pw.print("dpi");
    119             }
    120             pw.print(" cur=");
    121             pw.print(mDisplayInfo.logicalWidth);
    122             pw.print("x"); pw.print(mDisplayInfo.logicalHeight);
    123             pw.print(" app=");
    124             pw.print(mDisplayInfo.appWidth);
    125             pw.print("x"); pw.print(mDisplayInfo.appHeight);
    126             pw.print(" rng="); pw.print(mDisplayInfo.smallestNominalAppWidth);
    127             pw.print("x"); pw.print(mDisplayInfo.smallestNominalAppHeight);
    128             pw.print("-"); pw.print(mDisplayInfo.largestNominalAppWidth);
    129             pw.print("x"); pw.println(mDisplayInfo.largestNominalAppHeight);
    130         pw.print(subPrefix); pw.print("layoutNeeded="); pw.print(layoutNeeded);
    131         if (mMagnificationSpec != null) {
    132             pw.print(" mMagnificationSpec="); pw.print(mMagnificationSpec);
    133         }
    134         pw.println();
    135     }
    136 }
    137