DisplayDevice.h revision b7a0549c983bef103ce07eb3af5905febc6e538e
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 bool lastCompositionHadVisibleLayers; 57 58 enum DisplayType { 59 DISPLAY_ID_INVALID = -1, 60 DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY, 61 DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL, 62 DISPLAY_VIRTUAL = HWC_DISPLAY_VIRTUAL, 63 NUM_BUILTIN_DISPLAY_TYPES = HWC_NUM_PHYSICAL_DISPLAY_TYPES, 64 }; 65 66 enum { 67 PARTIAL_UPDATES = 0x00020000, // video driver feature 68 SWAP_RECTANGLE = 0x00080000, 69 }; 70 71 enum { 72 NO_LAYER_STACK = 0xFFFFFFFF, 73 }; 74 75 DisplayDevice( 76 const sp<SurfaceFlinger>& flinger, 77 DisplayType type, 78 int32_t hwcId, // negative for non-HWC-composited displays 79 int format, 80 bool isSecure, 81 const wp<IBinder>& displayToken, 82 const sp<DisplaySurface>& displaySurface, 83 const sp<IGraphicBufferProducer>& producer, 84 EGLConfig config); 85 86 ~DisplayDevice(); 87 88 // whether this is a valid object. An invalid DisplayDevice is returned 89 // when an non existing id is requested 90 bool isValid() const; 91 92 // isSecure indicates whether this display can be trusted to display 93 // secure surfaces. 94 bool isSecure() const { return mIsSecure; } 95 96 // Flip the front and back buffers if the back buffer is "dirty". Might 97 // be instantaneous, might involve copying the frame buffer around. 98 void flip(const Region& dirty) const; 99 100 int getWidth() const; 101 int getHeight() const; 102 PixelFormat getFormat() const; 103 uint32_t getFlags() const; 104 105 EGLSurface getEGLSurface() const; 106 107 void setVisibleLayersSortedByZ(const Vector< sp<Layer> >& layers); 108 const Vector< sp<Layer> >& getVisibleLayersSortedByZ() const; 109 bool getSecureLayerVisible() const; 110 Region getDirtyRegion(bool repaintEverything) const; 111 112 void setLayerStack(uint32_t stack); 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 * blank / unblank management 152 */ 153 void releaseScreen() const; 154 void acquireScreen() const; 155 bool isScreenAcquired() const; 156 bool canDraw() const; 157 158 // release HWC resources (if any) for removable displays 159 void disconnect(HWComposer& hwc); 160 161 /* ------------------------------------------------------------------------ 162 * Debugging 163 */ 164 uint32_t getPageFlipCount() const; 165 void dump(String8& result) const; 166 167private: 168 /* 169 * Constants, set during initialization 170 */ 171 sp<SurfaceFlinger> mFlinger; 172 DisplayType mType; 173 int32_t mHwcDisplayId; 174 wp<IBinder> mDisplayToken; 175 176 // ANativeWindow this display is rendering into 177 sp<ANativeWindow> mNativeWindow; 178 sp<DisplaySurface> mDisplaySurface; 179 180 EGLDisplay mDisplay; 181 EGLSurface mSurface; 182 int mDisplayWidth; 183 int mDisplayHeight; 184 PixelFormat mFormat; 185 uint32_t mFlags; 186 mutable uint32_t mPageFlipCount; 187 String8 mDisplayName; 188 bool mIsSecure; 189 190 /* 191 * Can only accessed from the main thread, these members 192 * don't need synchronization. 193 */ 194 195 // list of visible layers on that display 196 Vector< sp<Layer> > mVisibleLayersSortedByZ; 197 198 // Whether we have a visible secure layer on this display 199 bool mSecureLayerVisible; 200 201 // Whether the screen is blanked; 202 mutable int mScreenAcquired; 203 204 205 /* 206 * Transaction state 207 */ 208 static status_t orientationToTransfrom(int orientation, 209 int w, int h, Transform* tr); 210 211 uint32_t mLayerStack; 212 int mOrientation; 213 // user-provided visible area of the layer stack 214 Rect mViewport; 215 // user-provided rectangle where mViewport gets mapped to 216 Rect mFrame; 217 // pre-computed scissor to apply to the display 218 Rect mScissor; 219 Transform mGlobalTransform; 220 bool mNeedsFiltering; 221}; 222 223}; // namespace android 224 225#endif // ANDROID_DISPLAY_DEVICE_H 226