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