DisplayDevice.h revision 87baae104a3e4c2059990b01c393476065c558b0
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_HARDWARE_H 18#define ANDROID_DISPLAY_HARDWARE_H 19 20#include <stdlib.h> 21 22#include <ui/PixelFormat.h> 23#include <ui/Region.h> 24 25#include <GLES/gl.h> 26#include <GLES/glext.h> 27#include <EGL/egl.h> 28#include <EGL/eglext.h> 29 30#include <utils/Mutex.h> 31#include <utils/Timers.h> 32 33#include "Transform.h" 34 35#include "DisplayHardware/DisplayHardwareBase.h" 36 37namespace android { 38 39class DisplayInfo; 40class FramebufferSurface; 41class LayerBase; 42class SurfaceFlinger; 43class SurfaceTextureClient; 44 45class DisplayHardware : public DisplayHardwareBase 46{ 47public: 48 // region in layer-stack space 49 mutable Region dirtyRegion; 50 // region in screen space 51 mutable Region swapRegion; 52 // region in screen space 53 Region undefinedRegion; 54 55 enum { 56 PARTIAL_UPDATES = 0x00020000, // video driver feature 57 SWAP_RECTANGLE = 0x00080000, 58 }; 59 60 DisplayHardware( 61 const sp<SurfaceFlinger>& flinger, 62 int dpy, 63 const sp<SurfaceTextureClient>& surface, 64 EGLConfig config); 65 66 virtual ~DisplayHardware(); 67 68 // Flip the front and back buffers if the back buffer is "dirty". Might 69 // be instantaneous, might involve copying the frame buffer around. 70 void flip(const Region& dirty) const; 71 72 void onVSyncReceived(nsecs_t timestamp); 73 74 float getDpiX() const; 75 float getDpiY() const; 76 float getRefreshRate() const; 77 float getDensity() const; 78 int getWidth() const; 79 int getHeight() const; 80 PixelFormat getFormat() const; 81 uint32_t getFlags() const; 82 nsecs_t getRefreshPeriod() const; 83 nsecs_t getRefreshTimestamp() const; 84 status_t getInfo(DisplayInfo* info) const; 85 86 EGLSurface getEGLSurface() const; 87 88 void setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers); 89 Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const; 90 bool getSecureLayerVisible() const; 91 92 status_t setOrientation(int orientation); 93 int getOrientation() const { return mOrientation; } 94 const Transform& getTransform() const { return mGlobalTransform; } 95 uint32_t getLayerStack() const { return mLayerStack; } 96 97 98 uint32_t getPageFlipCount() const; 99 EGLDisplay getEGLDisplay() const { return mDisplay; } 100 101 void dump(String8& res) const; 102 103 status_t compositionComplete() const; 104 105 Rect getBounds() const { 106 return Rect(mDisplayWidth, mDisplayHeight); 107 } 108 inline Rect bounds() const { return getBounds(); } 109 110private: 111 void init(EGLConfig config); 112 113 /* 114 * Constants, set during initialization 115 */ 116 sp<SurfaceFlinger> mFlinger; 117 int mDisplayId; 118 // ANativeWindow this display is rendering into 119 sp<SurfaceTextureClient> mNativeWindow; 120 // set if mNativeWindow is a FramebufferSurface 121 sp<FramebufferSurface> mFramebufferSurface; 122 123 124 EGLDisplay mDisplay; 125 EGLSurface mSurface; 126 EGLContext mContext; 127 float mDpiX; 128 float mDpiY; 129 float mRefreshRate; 130 float mDensity; 131 int mDisplayWidth; 132 int mDisplayHeight; 133 PixelFormat mFormat; 134 uint32_t mFlags; 135 mutable uint32_t mPageFlipCount; 136 137 nsecs_t mRefreshPeriod; 138 139 /* 140 * Can only accessed from the main thread, these members 141 * don't need synchronization. 142 */ 143 // list of visible layers on that display 144 Vector< sp<LayerBase> > mVisibleLayersSortedByZ; 145 // Whether we have a visible secure layer on this display 146 bool mSecureLayerVisible; 147 148 149 // this used to be in GraphicPlane 150 static status_t orientationToTransfrom(int orientation, int w, int h, 151 Transform* tr); 152 Transform mGlobalTransform; 153 int mOrientation; 154 155 uint32_t mLayerStack; 156 157 158 /* 159 * protected by mLock 160 */ 161 mutable Mutex mLock; 162 mutable nsecs_t mLastHwVSync; 163}; 164 165}; // namespace android 166 167#endif // ANDROID_DISPLAY_HARDWARE_H 168