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 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 17 | #ifndef ANDROID_DISPLAY_DEVICE_H |
| 18 | #define ANDROID_DISPLAY_DEVICE_H |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | |
| 20 | #include <stdlib.h> |
| 21 | |
| 22 | #include <ui/PixelFormat.h> |
| 23 | #include <ui/Region.h> |
| 24 | |
| 25 | #include <EGL/egl.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 26 | #include <EGL/eglext.h> |
| 27 | |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 28 | #include <utils/Mutex.h> |
| 29 | #include <utils/Timers.h> |
| 30 | |
Mathias Agopian | f435863 | 2012-08-22 17:16:19 -0700 | [diff] [blame] | 31 | #include <hardware/hwcomposer_defs.h> |
| 32 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 33 | #include "Transform.h" |
Mathias Agopian | 1f7bec6 | 2010-06-25 18:02:21 -0700 | [diff] [blame] | 34 | |
Mathias Agopian | d8552d7 | 2012-08-04 21:39:11 -0700 | [diff] [blame] | 35 | struct ANativeWindow; |
| 36 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | namespace android { |
| 38 | |
Mathias Agopian | c666cae | 2012-07-25 18:56:13 -0700 | [diff] [blame] | 39 | class DisplayInfo; |
Mathias Agopian | 3e87601 | 2012-06-07 17:52:54 -0700 | [diff] [blame] | 40 | class FramebufferSurface; |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 41 | class LayerBase; |
| 42 | class SurfaceFlinger; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | |
Mathias Agopian | 028a757 | 2012-08-05 01:23:51 -0700 | [diff] [blame] | 44 | class DisplayDevice : public LightRefBase<DisplayDevice> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | { |
| 46 | public: |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 47 | // region in layer-stack space |
| 48 | mutable Region dirtyRegion; |
| 49 | // region in screen space |
| 50 | mutable Region swapRegion; |
| 51 | // region in screen space |
| 52 | Region undefinedRegion; |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 53 | |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 54 | enum DisplayType { |
| 55 | DISPLAY_ID_INVALID = -1, |
| 56 | DISPLAY_PRIMARY = HWC_DISPLAY_PRIMARY, |
| 57 | DISPLAY_EXTERNAL = HWC_DISPLAY_EXTERNAL, |
| 58 | NUM_DISPLAY_TYPES = HWC_NUM_DISPLAY_TYPES, |
| 59 | DISPLAY_VIRTUAL = HWC_NUM_DISPLAY_TYPES |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | enum { |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 63 | PARTIAL_UPDATES = 0x00020000, // video driver feature |
| 64 | SWAP_RECTANGLE = 0x00080000, |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 65 | }; |
| 66 | |
Mathias Agopian | 0f2f5ff | 2012-07-31 23:09:07 -0700 | [diff] [blame] | 67 | DisplayDevice( |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | const sp<SurfaceFlinger>& flinger, |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 69 | DisplayType type, const wp<IBinder>& displayToken, |
Jamie Gennis | 1a4d883 | 2012-08-02 20:11:05 -0700 | [diff] [blame] | 70 | const sp<ANativeWindow>& nativeWindow, |
| 71 | const sp<FramebufferSurface>& framebufferSurface, |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 72 | EGLConfig config); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 73 | |
Mathias Agopian | 028a757 | 2012-08-05 01:23:51 -0700 | [diff] [blame] | 74 | ~DisplayDevice(); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 75 | |
| 76 | // whether this is a valid object. An invalid DisplayDevice is returned |
| 77 | // when an non existing id is requested |
| 78 | bool isValid() const; |
| 79 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | // Flip the front and back buffers if the back buffer is "dirty". Might |
| 81 | // be instantaneous, might involve copying the frame buffer around. |
| 82 | void flip(const Region& dirty) const; |
| 83 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | int getWidth() const; |
| 85 | int getHeight() const; |
| 86 | PixelFormat getFormat() const; |
| 87 | uint32_t getFlags() const; |
Mathias Agopian | 3eb38cb | 2012-04-03 22:09:52 -0700 | [diff] [blame] | 88 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 89 | EGLSurface getEGLSurface() const; |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 90 | |
| 91 | void setVisibleLayersSortedByZ(const Vector< sp<LayerBase> >& layers); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 92 | const Vector< sp<LayerBase> >& getVisibleLayersSortedByZ() const; |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 93 | bool getSecureLayerVisible() const; |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 94 | Region getDirtyRegion(bool repaintEverything) const; |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 95 | |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 96 | void setLayerStack(uint32_t stack); |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame^] | 97 | void setOrientation(int orientation); |
| 98 | void setViewport(const Rect& viewport); |
| 99 | void setFrame(const Rect& frame); |
Mathias Agopian | 28947d7 | 2012-08-08 18:51:15 -0700 | [diff] [blame] | 100 | |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 101 | int getOrientation() const { return mOrientation; } |
| 102 | const Transform& getTransform() const { return mGlobalTransform; } |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame^] | 103 | const Rect& getViewport() const { return mViewport; } |
| 104 | const Rect& getFrame() const { return mFrame; } |
| 105 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 106 | uint32_t getLayerStack() const { return mLayerStack; } |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 107 | int32_t getDisplayType() const { return mType; } |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 108 | int32_t getHwcDisplayId() const { return mHwcDisplayId; } |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 109 | const wp<IBinder>& getDisplayToken() const { return mDisplayToken; } |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 110 | |
Mathias Agopian | 74faca2 | 2009-09-17 16:18:16 -0700 | [diff] [blame] | 111 | status_t compositionComplete() const; |
| 112 | |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 113 | Rect getBounds() const { |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 114 | return Rect(mDisplayWidth, mDisplayHeight); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 115 | } |
Mathias Agopian | 9c6e297 | 2011-09-20 17:21:56 -0700 | [diff] [blame] | 116 | inline Rect bounds() const { return getBounds(); } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame^] | 118 | static EGLBoolean makeCurrent(EGLDisplay dpy, |
| 119 | const sp<const DisplayDevice>& hw, EGLContext ctx); |
Mathias Agopian | 52bbb1a | 2012-07-31 19:01:53 -0700 | [diff] [blame] | 120 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 121 | /* ------------------------------------------------------------------------ |
| 122 | * blank / unplank management |
| 123 | */ |
| 124 | void releaseScreen() const; |
| 125 | void acquireScreen() const; |
| 126 | bool isScreenAcquired() const; |
| 127 | bool canDraw() const; |
| 128 | |
| 129 | /* ------------------------------------------------------------------------ |
| 130 | * Debugging |
| 131 | */ |
| 132 | uint32_t getPageFlipCount() const; |
| 133 | void dump(String8& res) const; |
| 134 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 135 | private: |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 136 | void init(EGLConfig config); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 138 | /* |
| 139 | * Constants, set during initialization |
| 140 | */ |
Mathias Agopian | c7d14e2 | 2011-08-01 16:32:21 -0700 | [diff] [blame] | 141 | sp<SurfaceFlinger> mFlinger; |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 142 | DisplayType mType; |
Mathias Agopian | e60b068 | 2012-08-21 23:34:09 -0700 | [diff] [blame] | 143 | int32_t mHwcDisplayId; |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 144 | wp<IBinder> mDisplayToken; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 145 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 146 | // ANativeWindow this display is rendering into |
Mathias Agopian | d8552d7 | 2012-08-04 21:39:11 -0700 | [diff] [blame] | 147 | sp<ANativeWindow> mNativeWindow; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 148 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 149 | // set if mNativeWindow is a FramebufferSurface |
| 150 | sp<FramebufferSurface> mFramebufferSurface; |
| 151 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | EGLDisplay mDisplay; |
| 153 | EGLSurface mSurface; |
| 154 | EGLContext mContext; |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 155 | int mDisplayWidth; |
| 156 | int mDisplayHeight; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 157 | PixelFormat mFormat; |
| 158 | uint32_t mFlags; |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 159 | mutable uint32_t mPageFlipCount; |
Mathias Agopian | 03e4072 | 2012-04-26 16:11:59 -0700 | [diff] [blame] | 160 | |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 161 | /* |
| 162 | * Can only accessed from the main thread, these members |
| 163 | * don't need synchronization. |
| 164 | */ |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 165 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 166 | // list of visible layers on that display |
| 167 | Vector< sp<LayerBase> > mVisibleLayersSortedByZ; |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 168 | |
Mathias Agopian | 3b1d2b6 | 2012-07-11 13:48:17 -0700 | [diff] [blame] | 169 | // Whether we have a visible secure layer on this display |
| 170 | bool mSecureLayerVisible; |
| 171 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 172 | // Whether the screen is blanked; |
| 173 | mutable int mScreenAcquired; |
Mathias Agopian | a350ff9 | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 174 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 175 | |
| 176 | /* |
| 177 | * Transaction state |
| 178 | */ |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame^] | 179 | static status_t orientationToTransfrom(int orientation, |
| 180 | int w, int h, Transform* tr); |
| 181 | |
| 182 | void updateGeometryTransform(); |
| 183 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 184 | uint32_t mLayerStack; |
Mathias Agopian | da8d0a5 | 2012-09-04 15:05:38 -0700 | [diff] [blame^] | 185 | int mOrientation; |
| 186 | Rect mViewport; |
| 187 | Rect mFrame; |
| 188 | Transform mGlobalTransform; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 189 | }; |
| 190 | |
| 191 | }; // namespace android |
| 192 | |
Mathias Agopian | d3ee231 | 2012-08-02 14:01:42 -0700 | [diff] [blame] | 193 | #endif // ANDROID_DISPLAY_DEVICE_H |