The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 25 | #include <GLES/gl.h> |
| 26 | #include <GLES/glext.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | #include <EGL/egl.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 28 | #include <EGL/eglext.h> |
| 29 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 30 | #include "Transform.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 31 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | #include "DisplayHardware/DisplayHardwareBase.h" |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 33 | #include "DisplayHardware/HWComposer.h" |
| 34 | #include "DisplayHardware/PowerHAL.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | namespace android { |
| 37 | |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 38 | class FramebufferSurface; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 39 | class SurfaceTextureClient; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 41 | class DisplayHardware : |
| 42 | public DisplayHardwareBase, |
| 43 | public HWComposer::EventHandler |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | { |
| 45 | public: |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 46 | |
| 47 | class VSyncHandler : virtual public RefBase { |
| 48 | friend class DisplayHardware; |
| 49 | virtual void onVSyncReceived(int dpy, nsecs_t timestamp) = 0; |
| 50 | protected: |
| 51 | virtual ~VSyncHandler() {} |
| 52 | }; |
| 53 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | enum { |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 55 | PARTIAL_UPDATES = 0x00020000, // video driver feature |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 56 | SWAP_RECTANGLE = 0x00080000, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | DisplayHardware( |
| 60 | const sp<SurfaceFlinger>& flinger, |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 61 | int dpy, |
| 62 | const sp<SurfaceTextureClient>& surface, |
| 63 | EGLConfig config); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 65 | virtual ~DisplayHardware(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 66 | |
| 67 | void releaseScreen() const; |
| 68 | void acquireScreen() const; |
| 69 | |
| 70 | // Flip the front and back buffers if the back buffer is "dirty". Might |
| 71 | // be instantaneous, might involve copying the frame buffer around. |
| 72 | void flip(const Region& dirty) const; |
| 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; |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 82 | nsecs_t getRefreshPeriod() const; |
| 83 | nsecs_t getRefreshTimestamp() const; |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 84 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 85 | EGLSurface getEGLSurface() const; |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 86 | |
| 87 | void setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers); |
| 88 | Vector< sp<LayerBase> > getVisibleLayersSortedByZ() const; |
| 89 | bool getSecureLayerVisible() const; |
| 90 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 91 | status_t setOrientation(int orientation); |
| 92 | int getOrientation() const { return mOrientation; } |
| 93 | const Transform& getTransform() const { return mGlobalTransform; } |
| 94 | int getUserWidth() const { return mUserDisplayWidth; } |
| 95 | int getUserHeight() const { return mUserDisplayHeight; } |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 96 | |
| 97 | void setVSyncHandler(const sp<VSyncHandler>& handler); |
| 98 | |
Mathias Agopian | 03e4072 | 2012-04-26 16:11:59 -0700 | [diff] [blame] | 99 | enum { |
| 100 | EVENT_VSYNC = HWC_EVENT_VSYNC |
| 101 | }; |
| 102 | |
| 103 | void eventControl(int event, int enabled); |
| 104 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 105 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | uint32_t getPageFlipCount() const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | EGLDisplay getEGLDisplay() const { return mDisplay; } |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 108 | |
Erik Gilling | 1d21a9c | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 109 | void dump(String8& res) const; |
| 110 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 111 | // Hardware Composer |
| 112 | HWComposer& getHwComposer() const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 114 | status_t compositionComplete() const; |
| 115 | |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 116 | Rect getBounds() const { |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 117 | return Rect(mDisplayWidth, mDisplayHeight); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | } |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 119 | inline Rect bounds() const { return getBounds(); } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | |
| 121 | private: |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 122 | void init(EGLConfig config); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 123 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 124 | virtual void onVSyncReceived(int dpy, nsecs_t timestamp); |
| 125 | |
| 126 | /* |
| 127 | * Constants, set during initialization |
| 128 | */ |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 129 | sp<SurfaceFlinger> mFlinger; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 130 | int mDisplayId; |
| 131 | HWComposer* mHwc; |
| 132 | PowerHAL mPowerHAL; |
| 133 | // ANativeWindow this display is rendering into |
| 134 | sp<SurfaceTextureClient> mNativeWindow; |
| 135 | // set if mNativeWindow is a FramebufferSurface |
| 136 | sp<FramebufferSurface> mFramebufferSurface; |
| 137 | |
| 138 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | EGLDisplay mDisplay; |
| 140 | EGLSurface mSurface; |
| 141 | EGLContext mContext; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | float mDpiX; |
| 143 | float mDpiY; |
| 144 | float mRefreshRate; |
| 145 | float mDensity; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 146 | int mDisplayWidth; |
| 147 | int mDisplayHeight; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | PixelFormat mFormat; |
| 149 | uint32_t mFlags; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 150 | mutable uint32_t mPageFlipCount; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 151 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 152 | nsecs_t mRefreshPeriod; |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 153 | mutable nsecs_t mLastHwVSync; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 154 | |
Mathias Agopian | 03e4072 | 2012-04-26 16:11:59 -0700 | [diff] [blame] | 155 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 156 | /* |
| 157 | * Can only accessed from the main thread, these members |
| 158 | * don't need synchronization. |
| 159 | */ |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 160 | // list of visible layers on that display |
| 161 | Vector< sp<LayerBase> > mVisibleLayersSortedByZ; |
| 162 | // Whether we have a visible secure layer on this display |
| 163 | bool mSecureLayerVisible; |
| 164 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 165 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 166 | // this used to be in GraphicPlane |
| 167 | static status_t orientationToTransfrom(int orientation, int w, int h, |
| 168 | Transform* tr); |
| 169 | Transform mGlobalTransform; |
| 170 | Transform mDisplayTransform; |
| 171 | int mOrientation; |
| 172 | int mLogicalDisplayWidth; |
| 173 | int mLogicalDisplayHeight; |
| 174 | int mUserDisplayWidth; |
| 175 | int mUserDisplayHeight; |
| 176 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 177 | mutable Mutex mLock; |
| 178 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 179 | /* |
| 180 | * protected by mLock |
| 181 | */ |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 182 | wp<VSyncHandler> mVSyncHandler; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 183 | }; |
| 184 | |
| 185 | }; // namespace android |
| 186 | |
| 187 | #endif // ANDROID_DISPLAY_HARDWARE_H |