DisplayDevice.java revision d728bf514f257670fcb9aa22c6eaf97626072c93
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.display; 18 19import android.graphics.Rect; 20import android.os.IBinder; 21import android.view.Surface; 22 23import java.io.PrintWriter; 24 25/** 26 * Represents a physical display device such as the built-in display 27 * an external monitor, or a WiFi display. 28 * <p> 29 * Display devices are guarded by the {@link DisplayManagerService.SyncRoot} lock. 30 * </p> 31 */ 32abstract class DisplayDevice { 33 private final DisplayAdapter mDisplayAdapter; 34 private final IBinder mDisplayToken; 35 36 // The display device does not manage these properties itself, they are set by 37 // the display manager service. The display device shouldn't really be looking at these. 38 private int mCurrentLayerStack = -1; 39 private int mCurrentOrientation = -1; 40 private Rect mCurrentLayerStackRect; 41 private Rect mCurrentDisplayRect; 42 43 // The display device owns its surface, but it should only set it 44 // within a transaction from performTraversalInTransactionLocked. 45 private Surface mCurrentSurface; 46 47 public DisplayDevice(DisplayAdapter displayAdapter, IBinder displayToken) { 48 mDisplayAdapter = displayAdapter; 49 mDisplayToken = displayToken; 50 } 51 52 /** 53 * Gets the display adapter that owns the display device. 54 * 55 * @return The display adapter. 56 */ 57 public final DisplayAdapter getAdapterLocked() { 58 return mDisplayAdapter; 59 } 60 61 /** 62 * Gets the Surface Flinger display token for this display. 63 * 64 * @return The display token, or null if the display is not being managed 65 * by Surface Flinger. 66 */ 67 public final IBinder getDisplayTokenLocked() { 68 return mDisplayToken; 69 } 70 71 /** 72 * Gets the name of the display device. 73 * 74 * @return The display device name. 75 */ 76 public final String getNameLocked() { 77 return getDisplayDeviceInfoLocked().name; 78 } 79 80 /** 81 * Gets information about the display device. 82 * 83 * The information returned should not change between calls unless the display 84 * adapter sent a {@link DisplayAdapter#DISPLAY_DEVICE_EVENT_CHANGED} event and 85 * {@link #applyPendingDisplayDeviceInfoChangesLocked()} has been called to apply 86 * the pending changes. 87 * 88 * @return The display device info, which should be treated as immutable by the caller. 89 * The display device should allocate a new display device info object whenever 90 * the data changes. 91 */ 92 public abstract DisplayDeviceInfo getDisplayDeviceInfoLocked(); 93 94 /** 95 * Applies any pending changes to the observable state of the display device 96 * if the display adapter sent a {@link DisplayAdapter#DISPLAY_DEVICE_EVENT_CHANGED} event. 97 */ 98 public void applyPendingDisplayDeviceInfoChangesLocked() { 99 } 100 101 /** 102 * Gives the display device a chance to update its properties while in a transaction. 103 */ 104 public void performTraversalInTransactionLocked() { 105 } 106 107 /** 108 * Sets the display layer stack while in a transaction. 109 */ 110 public final void setLayerStackInTransactionLocked(int layerStack) { 111 if (mCurrentLayerStack != layerStack) { 112 mCurrentLayerStack = layerStack; 113 Surface.setDisplayLayerStack(mDisplayToken, layerStack); 114 } 115 } 116 117 /** 118 * Sets the display projection while in a transaction. 119 * 120 * @param orientation defines the display's orientation 121 * @param layerStackRect defines which area of the window manager coordinate 122 * space will be used 123 * @param displayRect defines where on the display will layerStackRect be 124 * mapped to. displayRect is specified post-orientation, that is 125 * it uses the orientation seen by the end-user 126 */ 127 public final void setProjectionInTransactionLocked(int orientation, 128 Rect layerStackRect, Rect displayRect) { 129 if (mCurrentOrientation != orientation 130 || mCurrentLayerStackRect == null 131 || !mCurrentLayerStackRect.equals(layerStackRect) 132 || mCurrentDisplayRect == null 133 || !mCurrentDisplayRect.equals(displayRect)) { 134 mCurrentOrientation = orientation; 135 136 if (mCurrentLayerStackRect == null) { 137 mCurrentLayerStackRect = new Rect(); 138 } 139 mCurrentLayerStackRect.set(layerStackRect); 140 141 if (mCurrentDisplayRect == null) { 142 mCurrentDisplayRect = new Rect(); 143 } 144 mCurrentDisplayRect.set(displayRect); 145 146 Surface.setDisplayProjection(mDisplayToken, 147 orientation, layerStackRect, displayRect); 148 } 149 } 150 151 /** 152 * Sets the display surface while in a transaction. 153 */ 154 public final void setSurfaceInTransactionLocked(Surface surface) { 155 if (mCurrentSurface != surface) { 156 mCurrentSurface = surface; 157 Surface.setDisplaySurface(mDisplayToken, surface); 158 } 159 } 160 161 /** 162 * Populates the specified viewport object with orientation, 163 * physical and logical rects based on the display's current projection. 164 */ 165 public final void populateViewportLocked(DisplayViewport viewport) { 166 viewport.orientation = mCurrentOrientation; 167 168 if (mCurrentLayerStackRect != null) { 169 viewport.logicalFrame.set(mCurrentLayerStackRect); 170 } else { 171 viewport.logicalFrame.setEmpty(); 172 } 173 174 if (mCurrentDisplayRect != null) { 175 viewport.physicalFrame.set(mCurrentDisplayRect); 176 } else { 177 viewport.physicalFrame.setEmpty(); 178 } 179 } 180 181 /** 182 * Dumps the local state of the display device. 183 * Does not need to dump the display device info because that is already dumped elsewhere. 184 */ 185 public void dumpLocked(PrintWriter pw) { 186 pw.println("mAdapter=" + mDisplayAdapter.getName()); 187 pw.println("mDisplayToken=" + mDisplayToken); 188 pw.println("mCurrentLayerStack=" + mCurrentLayerStack); 189 pw.println("mCurrentOrientation=" + mCurrentOrientation); 190 pw.println("mCurrentLayerStackRect=" + mCurrentLayerStackRect); 191 pw.println("mCurrentDisplayRect=" + mCurrentDisplayRect); 192 pw.println("mCurrentSurface=" + mCurrentSurface); 193 } 194} 195