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 | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 30 | #include "GLExtensions.h" |
| 31 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | #include "DisplayHardware/DisplayHardwareBase.h" |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 33 | #include "HWComposer.h" |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | namespace android { |
| 36 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 37 | class FramebufferNativeWindow; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 39 | class DisplayHardware : |
| 40 | public DisplayHardwareBase, |
| 41 | public HWComposer::EventHandler |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | { |
| 43 | public: |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 44 | |
| 45 | class VSyncHandler : virtual public RefBase { |
| 46 | friend class DisplayHardware; |
| 47 | virtual void onVSyncReceived(int dpy, nsecs_t timestamp) = 0; |
| 48 | protected: |
| 49 | virtual ~VSyncHandler() {} |
| 50 | }; |
| 51 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | enum { |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 53 | COPY_BITS_EXTENSION = 0x00000008, |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 54 | PARTIAL_UPDATES = 0x00020000, // video driver feature |
| 55 | SLOW_CONFIG = 0x00040000, // software |
| 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, |
| 61 | uint32_t displayIndex); |
| 62 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 63 | virtual ~DisplayHardware(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | |
| 65 | void releaseScreen() const; |
| 66 | void acquireScreen() const; |
| 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 | float getDpiX() const; |
| 73 | float getDpiY() const; |
| 74 | float getRefreshRate() const; |
| 75 | float getDensity() const; |
| 76 | int getWidth() const; |
| 77 | int getHeight() const; |
| 78 | PixelFormat getFormat() const; |
| 79 | uint32_t getFlags() const; |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 80 | uint32_t getMaxTextureSize() const; |
| 81 | uint32_t getMaxViewportDims() 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 | void makeCurrent() const; |
| 85 | |
| 86 | |
| 87 | void setVSyncHandler(const sp<VSyncHandler>& handler); |
| 88 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 89 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | uint32_t getPageFlipCount() const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | EGLDisplay getEGLDisplay() const { return mDisplay; } |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 92 | |
Erik Gilling | 1d21a9c | 2010-12-01 16:38:01 -0800 | [diff] [blame] | 93 | void dump(String8& res) const; |
| 94 | |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 95 | // Hardware Composer |
| 96 | HWComposer& getHwComposer() const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 98 | status_t compositionComplete() const; |
| 99 | |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 100 | Rect getBounds() const { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | return Rect(mWidth, mHeight); |
| 102 | } |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 103 | inline Rect bounds() const { return getBounds(); } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 104 | |
| 105 | private: |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 106 | virtual void onVSyncReceived(int dpy, nsecs_t timestamp); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | void init(uint32_t displayIndex) __attribute__((noinline)); |
| 108 | void fini() __attribute__((noinline)); |
| 109 | |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 110 | sp<SurfaceFlinger> mFlinger; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 111 | EGLDisplay mDisplay; |
| 112 | EGLSurface mSurface; |
| 113 | EGLContext mContext; |
| 114 | EGLConfig mConfig; |
| 115 | float mDpiX; |
| 116 | float mDpiY; |
| 117 | float mRefreshRate; |
| 118 | float mDensity; |
| 119 | int mWidth; |
| 120 | int mHeight; |
| 121 | PixelFormat mFormat; |
| 122 | uint32_t mFlags; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 123 | mutable uint32_t mPageFlipCount; |
Mathias Agopian | 3d64e73 | 2011-04-18 15:59:24 -0700 | [diff] [blame] | 124 | GLint mMaxViewportDims[2]; |
Mathias Agopian | ca99fb8 | 2010-04-14 16:43:44 -0700 | [diff] [blame] | 125 | GLint mMaxTextureSize; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 126 | |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 127 | nsecs_t mRefreshPeriod; |
Mathias Agopian | 82d7ab6 | 2012-01-19 18:34:40 -0800 | [diff] [blame] | 128 | mutable nsecs_t mLastHwVSync; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 129 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 130 | // constant once set |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 131 | HWComposer* mHwc; |
| 132 | |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 133 | mutable Mutex mLock; |
| 134 | |
| 135 | // protected by mLock |
| 136 | wp<VSyncHandler> mVSyncHandler; |
| 137 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 138 | sp<FramebufferNativeWindow> mNativeWindow; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | }; |
| 140 | |
| 141 | }; // namespace android |
| 142 | |
| 143 | #endif // ANDROID_DISPLAY_HARDWARE_H |