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