DisplayDevice.h revision 47e45405d1533aa73307014f7bf371e118695cf3
1/* 2 * Copyright (C) 2007 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#ifndef ANDROID_DISPLAY_DEVICE_H 18#define ANDROID_DISPLAY_DEVICE_H 19 20#include <stdlib.h> 21 22#include <ui/PixelFormat.h> 23#include <ui/Region.h> 24 25#include <EGL/egl.h> 26#include <EGL/eglext.h> 27 28#include <utils/Mutex.h> 29#include <utils/String8.h> 30#include <utils/Timers.h> 31 32#include <hardware/hwcomposer_defs.h> 33 34#include "Transform.h" 35 36struct ANativeWindow; 37 38namespace android { 39 40class DisplayInfo; 41class DisplaySurface; 42class IGraphicBufferProducer; 43class Layer; 44class SurfaceFlinger; 45class HWComposer; 46 47class DisplayDevice : public LightRefBase<DisplayDevice> 48{ 49public: 50 // region in layer-stack space 51 mutable Region dirtyRegion; 52 // region in screen space 53 mutable Region swapRegion; 54 // region in screen space 55 Region undefinedRegion; 56 57 enum DisplayType { 58 DISPLAY_ID_INVALID = -1, 59 DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY, 60 DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL, 61 DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL, 62 NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES, 63 }; 64 65 enum { 66 PARTIAL_UPDATES = 0x00020000, // video driver feature 67 SWAP_RECTANGLE = 0x00080000, 68 }; 69 70 enum { 71 NO_LAYER_STACK = 0xFFFFFFFF, 72 }; 73 74 DisplayDevice( 75 const sp<SurfaceFlinger>& flinger, 76 DisplayType type, 77 int32_t hwcId, // negative for non-HWC-composited displays 78 int format, 79 bool isSecure, 80 const wp<IBinder>& displayToken, 81 const sp<DisplaySurface>& displaySurface, 82 const sp<IGraphicBufferProducer>& producer, 83 EGLConfig config); 84 85 ~DisplayDevice(); 86 87 // whether this is a valid object. An invalid DisplayDevice is returned 88 // when an non existing id is requested 89 bool isValid() const; 90 91 // isSecure indicates whether this display can be trusted to display 92 // secure surfaces. 93 bool isSecure() const { return mIsSecure; } 94 95 // Flip the front and back buffers if the back buffer is "dirty". Might 96 // be instantaneous, might involve copying the frame buffer around. 97 void flip(const Region& dirty) const; 98 99 int getWidth() const; 100 int getHeight() const; 101 PixelFormat getFormat() const; 102 uint32_t getFlags() const; 103 104 EGLSurface getEGLSurface() const; 105 106 void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers); 107 const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const; 108 bool getSecureLayerVisible() const; 109 Region getDirtyRegion(bool repaintEverything) const; 110 111 void setLayerStack(uint32_t stack); 112 void setDisplaySize(const int newWidth, const int newHeight); 113 void setProjection(int orientation, const Rect& viewport, const Rect& frame); 114 115 int getOrientation() const { return mOrientation; } 116 uint32_t getOrientationTransform() const; 117 const Transform& getTransform() const { return mGlobalTransform; } 118 const Rect getViewport() const { return mViewport; } 119 const Rect getFrame() const { return mFrame; } 120 const Rect& getScissor() const { return mScissor; } 121 bool needsFiltering() const { return mNeedsFiltering; } 122 123 uint32_t getLayerStack() const { return mLayerStack; } 124 int32_t getDisplayType() const { return mType; } 125 int32_t getHwcDisplayId() const { return mHwcDisplayId; } 126 const wp<IBinder>& getDisplayToken() const { return mDisplayToken; } 127 128 // We pass in mustRecompose so we can keep VirtualDisplaySurface's state 129 // machine happy without actually queueing a buffer if nothing has changed 130 status_t beginFrame(bool mustRecompose) const; 131 status_t prepareFrame(const HWComposer& hwc) const; 132 133 void swapBuffers(HWComposer& hwc) const; 134 status_t compositionComplete() const; 135 136 // called after h/w composer has completed its set() call 137 void onSwapBuffersCompleted(HWComposer& hwc) const; 138 139 Rect getBounds() const { 140 return Rect(mDisplayWidth, mDisplayHeight); 141 } 142 inline Rect bounds() const { return getBounds(); } 143 144 void setDisplayName(const String8& displayName); 145 const String8& getDisplayName() const { return mDisplayName; } 146 147 EGLBoolean makeCurrent(EGLDisplay dpy, EGLContext ctx) const; 148 void setViewportAndProjection() const; 149 150 /* ------------------------------------------------------------------------ 151 * Display power mode management. 152 */ 153 int getPowerMode() const; 154 void setPowerMode(int mode); 155 bool isDisplayOn() const; 156 157 /* ------------------------------------------------------------------------ 158 * Display active config management. 159 */ 160 int getActiveConfig() const; 161 void setActiveConfig(int mode); 162 163 // release HWC resources (if any) for removable displays 164 void disconnect(HWComposer& hwc); 165 166 /* ------------------------------------------------------------------------ 167 * Debugging 168 */ 169 uint32_t getPageFlipCount() const; 170 void dump(String8& result) const; 171 172private: 173 /* 174 * Constants, set during initialization 175 */ 176 sp<SurfaceFlinger> mFlinger; 177 DisplayType mType; 178 int32_t mHwcDisplayId; 179 wp<IBinder> mDisplayToken; 180 181 // ANativeWindow this display is rendering into 182 sp<ANativeWindow> mNativeWindow; 183 sp<DisplaySurface> mDisplaySurface; 184 185 EGLConfig mConfig; 186 EGLDisplay mDisplay; 187 EGLSurface mSurface; 188 int mDisplayWidth; 189 int mDisplayHeight; 190 PixelFormat mFormat; 191 uint32_t mFlags; 192 mutable uint32_t mPageFlipCount; 193 String8 mDisplayName; 194 bool mIsSecure; 195 196 /* 197 * Can only accessed from the main thread, these members 198 * don't need synchronization. 199 */ 200 201 // list of visible layers on that display 202 Vector< sp<Layer> > mVisibleLayersSortedByZ; 203 204 // Whether we have a visible secure layer on this display 205 bool mSecureLayerVisible; 206 207 208 /* 209 * Transaction state 210 */ 211 static status_t orientationToTransfrom(int orientation, 212 int w, int h, Transform* tr); 213 214 uint32_t mLayerStack; 215 int mOrientation; 216 // user-provided visible area of the layer stack 217 Rect mViewport; 218 // user-provided rectangle where mViewport gets mapped to 219 Rect mFrame; 220 // pre-computed scissor to apply to the display 221 Rect mScissor; 222 Transform mGlobalTransform; 223 bool mNeedsFiltering; 224 // Current power mode 225 int mPowerMode; 226 // Current active config 227 int mActiveConfig; 228}; 229 230}; // namespace android 231 232#endif // ANDROID_DISPLAY_DEVICE_H 233