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_SURFACE_FLINGER_H |
| 18 | #define ANDROID_SURFACE_FLINGER_H |
| 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| 22 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 23 | #include <EGL/egl.h> |
| 24 | #include <GLES/gl.h> |
| 25 | |
Glenn Kasten | 99ed224 | 2011-12-15 09:51:17 -0800 | [diff] [blame] | 26 | #include <cutils/compiler.h> |
| 27 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <utils/Atomic.h> |
| 29 | #include <utils/Errors.h> |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 30 | #include <utils/KeyedVector.h> |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 31 | #include <utils/RefBase.h> |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 32 | #include <utils/SortedVector.h> |
| 33 | #include <utils/threads.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
Mathias Agopian | a1e6bc8 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 35 | #include <binder/BinderService.h> |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 36 | #include <binder/IMemory.h> |
Mathias Agopian | 375f563 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 37 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | #include <ui/PixelFormat.h> |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 39 | |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 40 | #include <gui/ISurfaceComposer.h> |
| 41 | #include <gui/ISurfaceComposerClient.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 43 | #include <hardware/hwcomposer_defs.h> |
| 44 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 45 | #include <private/gui/LayerState.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 46 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 47 | #include "Barrier.h" |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 48 | #include "MessageQueue.h" |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 49 | #include "DisplayDevice.h" |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 50 | |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 51 | #include "DisplayHardware/HWComposer.h" |
| 52 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | namespace android { |
| 54 | |
| 55 | // --------------------------------------------------------------------------- |
| 56 | |
| 57 | class Client; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 58 | class DisplayEventConnection; |
| 59 | class EventThread; |
Mathias Agopian | f33e4b6 | 2012-09-20 16:54:14 -0700 | [diff] [blame] | 60 | class IGraphicBufferAlloc; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 61 | class Layer; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 62 | class LayerBase; |
| 63 | class LayerBaseClient; |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 64 | class LayerDim; |
Mathias Agopian | 118d024 | 2011-10-13 16:02:48 -0700 | [diff] [blame] | 65 | class LayerScreenshot; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 66 | class SurfaceTextureClient; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 68 | // --------------------------------------------------------------------------- |
| 69 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | enum { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 71 | eTransactionNeeded = 0x01, |
| 72 | eTraversalNeeded = 0x02, |
| 73 | eDisplayTransactionNeeded = 0x04, |
| 74 | eTransactionMask = 0x07 |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | }; |
| 76 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 77 | class SurfaceFlinger : public BinderService<SurfaceFlinger>, |
| 78 | public BnSurfaceComposer, |
| 79 | private IBinder::DeathRecipient, |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 80 | private Thread, |
| 81 | private HWComposer::EventHandler |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | { |
| 83 | public: |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 84 | static char const* getServiceName() { |
| 85 | return "SurfaceFlinger"; |
| 86 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 88 | SurfaceFlinger(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 90 | enum { |
| 91 | EVENT_VSYNC = HWC_EVENT_VSYNC |
| 92 | }; |
| 93 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 94 | // post an asynchronous message to the main thread |
| 95 | status_t postMessageAsync(const sp<MessageBase>& msg, nsecs_t reltime = 0, |
| 96 | uint32_t flags = 0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 98 | // post a synchronous message to the main thread |
| 99 | status_t postMessageSync(const sp<MessageBase>& msg, nsecs_t reltime = 0, |
| 100 | uint32_t flags = 0); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 102 | // force full composition on all displays |
| 103 | void repaintEverything(); |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 104 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 105 | // renders content on given display to a texture. thread-safe version. |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 106 | status_t renderScreenToTexture(uint32_t layerStack, GLuint* textureName, |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 107 | GLfloat* uOut, GLfloat* vOut); |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 108 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 109 | // renders content on given display to a texture, w/o acquiring main lock |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 110 | status_t renderScreenToTextureLocked(uint32_t layerStack, GLuint* textureName, |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 111 | GLfloat* uOut, GLfloat* vOut); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 112 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 113 | // returns the default Display |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 114 | sp<const DisplayDevice> getDefaultDisplayDevice() const { |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 115 | return getDisplayDevice(mDefaultDisplays[DisplayDevice::DISPLAY_PRIMARY]); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 116 | } |
Mathias Agopian | b60314a | 2012-04-10 22:09:54 -0700 | [diff] [blame] | 117 | |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 118 | // utility function to delete a texture on the main thread |
| 119 | void deleteTextureAsync(GLuint texture); |
| 120 | |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 121 | // allocate a h/w composer display id |
| 122 | int32_t allocateHwcDisplayId(DisplayDevice::DisplayType type); |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 123 | |
| 124 | // enable/disable h/w composer event |
| 125 | // TODO: this should be made accessible only to EventThread |
| 126 | void eventControl(int event, int enabled); |
| 127 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 128 | // called on the main thread by MessageQueue when an internal message |
| 129 | // is received |
| 130 | // TODO: this should be made accessible only to MessageQueue |
| 131 | void onMessageReceived(int32_t what); |
Mathias Agopian | 3094df3 | 2012-06-18 18:06:45 -0700 | [diff] [blame] | 132 | |
Mathias Agopian | 1f339ff | 2011-07-01 17:08:43 -0700 | [diff] [blame] | 133 | private: |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 134 | friend class Client; |
Mathias Agopian | d0566bc | 2011-11-17 17:49:17 -0800 | [diff] [blame] | 135 | friend class DisplayEventConnection; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 136 | friend class LayerBase; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | friend class LayerBaseClient; |
| 138 | friend class Layer; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 139 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 140 | // We're reference counted, never destroy SurfaceFlinger directly |
| 141 | virtual ~SurfaceFlinger(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 142 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 143 | /* ------------------------------------------------------------------------ |
| 144 | * Internal data structures |
| 145 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 147 | class LayerVector : public SortedVector<sp<LayerBase> > { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | public: |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 149 | LayerVector(); |
| 150 | LayerVector(const LayerVector& rhs); |
| 151 | virtual int do_compare(const void* lhs, const void* rhs) const; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | }; |
| 153 | |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 154 | struct DisplayDeviceState { |
| 155 | DisplayDeviceState(); |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 156 | DisplayDeviceState(DisplayDevice::DisplayType type); |
| 157 | bool isValid() const { return type >= 0; } |
| 158 | bool isMainDisplay() const { return type == DisplayDevice::DISPLAY_PRIMARY; } |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 159 | bool isVirtualDisplay() const { return type >= DisplayDevice::DISPLAY_VIRTUAL; } |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 160 | DisplayDevice::DisplayType type; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 161 | sp<ISurfaceTexture> surface; |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 162 | uint32_t layerStack; |
| 163 | Rect viewport; |
| 164 | Rect frame; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 165 | uint8_t orientation; |
Andy McFadden | 8dfa92f | 2012-09-17 18:27:17 -0700 | [diff] [blame] | 166 | String8 displayName; |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 167 | }; |
| 168 | |
| 169 | struct State { |
| 170 | LayerVector layersSortedByZ; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 171 | DefaultKeyedVector< wp<IBinder>, DisplayDeviceState> displays; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | }; |
| 173 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 174 | /* ------------------------------------------------------------------------ |
| 175 | * IBinder interface |
| 176 | */ |
| 177 | virtual status_t onTransact(uint32_t code, const Parcel& data, |
| 178 | Parcel* reply, uint32_t flags); |
| 179 | virtual status_t dump(int fd, const Vector<String16>& args); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 181 | /* ------------------------------------------------------------------------ |
| 182 | * ISurfaceComposer interface |
| 183 | */ |
| 184 | virtual sp<ISurfaceComposerClient> createConnection(); |
| 185 | virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc(); |
Andy McFadden | 8dfa92f | 2012-09-17 18:27:17 -0700 | [diff] [blame] | 186 | virtual sp<IBinder> createDisplay(const String8& displayName); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 187 | virtual sp<IBinder> getBuiltInDisplay(int32_t id); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 188 | virtual void setTransactionState(const Vector<ComposerState>& state, |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 189 | const Vector<DisplayState>& displays, uint32_t flags); |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 190 | virtual void bootFinished(); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 191 | virtual bool authenticateSurfaceTexture( |
| 192 | const sp<ISurfaceTexture>& surface) const; |
| 193 | virtual sp<IDisplayEventConnection> createDisplayEventConnection(); |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 194 | virtual status_t captureScreen(const sp<IBinder>& display, sp<IMemoryHeap>* heap, |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 195 | uint32_t* width, uint32_t* height, PixelFormat* format, |
| 196 | uint32_t reqWidth, uint32_t reqHeight, uint32_t minLayerZ, |
| 197 | uint32_t maxLayerZ); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 198 | // called when screen needs to turn off |
| 199 | virtual void blank(); |
| 200 | // called when screen is turning back on |
| 201 | virtual void unblank(); |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 202 | virtual status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo* info); |
| 203 | virtual void connectDisplay(const sp<ISurfaceTexture>& display); |
Mathias Agopian | 1b03149 | 2012-06-20 17:51:20 -0700 | [diff] [blame] | 204 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 205 | /* ------------------------------------------------------------------------ |
| 206 | * DeathRecipient interface |
| 207 | */ |
| 208 | virtual void binderDied(const wp<IBinder>& who); |
Mathias Agopian | 99ce5cd | 2012-01-31 18:24:27 -0800 | [diff] [blame] | 209 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 210 | /* ------------------------------------------------------------------------ |
| 211 | * Thread interface |
| 212 | */ |
| 213 | virtual bool threadLoop(); |
| 214 | virtual status_t readyToRun(); |
| 215 | virtual void onFirstRef(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 216 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 217 | /* ------------------------------------------------------------------------ |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 218 | * HWComposer::EventHandler interface |
| 219 | */ |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 220 | virtual void onVSyncReceived(int type, nsecs_t timestamp); |
Mathias Agopian | 148994e | 2012-09-19 17:31:36 -0700 | [diff] [blame^] | 221 | virtual void onHotplugReceived(int disp, bool connected); |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 222 | |
| 223 | /* ------------------------------------------------------------------------ |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 224 | * Message handling |
| 225 | */ |
| 226 | void waitForEvent(); |
| 227 | void signalTransaction(); |
| 228 | void signalLayerUpdate(); |
| 229 | void signalRefresh(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 230 | |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 231 | // called on the main thread in response to initializeDisplays() |
| 232 | void onInitializeDisplays(); |
| 233 | // called on the main thread in response to blank() |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 234 | void onScreenReleased(const sp<const DisplayDevice>& hw); |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 235 | // called on the main thread in response to unblank() |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 236 | void onScreenAcquired(const sp<const DisplayDevice>& hw); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 238 | void handleMessageTransaction(); |
| 239 | void handleMessageInvalidate(); |
| 240 | void handleMessageRefresh(); |
Mathias Agopian | 4fec873 | 2012-06-29 14:12:52 -0700 | [diff] [blame] | 241 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 242 | void handleTransaction(uint32_t transactionFlags); |
| 243 | void handleTransactionLocked(uint32_t transactionFlags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 244 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 245 | /* handlePageFilp: this is were we latch a new buffer |
| 246 | * if available and compute the dirty region. |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 247 | */ |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 248 | void handlePageFlip(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 249 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 250 | /* ------------------------------------------------------------------------ |
| 251 | * Transactions |
| 252 | */ |
| 253 | uint32_t getTransactionFlags(uint32_t flags); |
| 254 | uint32_t peekTransactionFlags(uint32_t flags); |
| 255 | uint32_t setTransactionFlags(uint32_t flags); |
| 256 | void commitTransaction(); |
| 257 | uint32_t setClientStateLocked(const sp<Client>& client, |
| 258 | const layer_state_t& s); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 259 | uint32_t setDisplayStateLocked(const DisplayState& s); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 260 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 261 | /* ------------------------------------------------------------------------ |
| 262 | * Layer management |
| 263 | */ |
| 264 | sp<ISurface> createLayer(ISurfaceComposerClient::surface_data_t* params, |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 265 | const String8& name, const sp<Client>& client, |
| 266 | uint32_t w, uint32_t h, PixelFormat format, uint32_t flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 267 | |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 268 | sp<Layer> createNormalLayer(const sp<Client>& client, |
| 269 | uint32_t w, uint32_t h, uint32_t flags, PixelFormat& format); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 270 | |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 271 | sp<LayerDim> createDimLayer(const sp<Client>& client, |
| 272 | uint32_t w, uint32_t h, uint32_t flags); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 273 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 274 | sp<LayerScreenshot> createScreenshotLayer(const sp<Client>& client, |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 275 | uint32_t w, uint32_t h, uint32_t flags); |
Mathias Agopian | 59119e6 | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 276 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 277 | // called in response to the window-manager calling |
| 278 | // ISurfaceComposerClient::destroySurface() |
| 279 | // The specified layer is first placed in a purgatory list |
| 280 | // until all references from the client are released. |
| 281 | status_t onLayerRemoved(const sp<Client>& client, SurfaceID sid); |
Mathias Agopian | b9494d5 | 2012-04-18 02:28:45 -0700 | [diff] [blame] | 282 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 283 | // called when all clients have released all their references to |
| 284 | // this layer meaning it is entirely safe to destroy all |
| 285 | // resources associated to this layer. |
| 286 | status_t onLayerDestroyed(const wp<LayerBaseClient>& layer); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 287 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 288 | // remove a layer from SurfaceFlinger immediately |
| 289 | status_t removeLayer(const sp<LayerBase>& layer); |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 290 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 291 | // add a layer to SurfaceFlinger |
| 292 | ssize_t addClientLayer(const sp<Client>& client, |
| 293 | const sp<LayerBaseClient>& lbc); |
Mathias Agopian | a67e418 | 2012-06-19 17:26:12 -0700 | [diff] [blame] | 294 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 295 | status_t removeLayer_l(const sp<LayerBase>& layer); |
| 296 | status_t purgatorizeLayer_l(const sp<LayerBase>& layer); |
Mathias Agopian | f1d8e87 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 297 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 298 | /* ------------------------------------------------------------------------ |
| 299 | * Boot animation, on/off animations and screen capture |
| 300 | */ |
Mathias Agopian | bb64124 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 301 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 302 | void startBootAnim(); |
Mathias Agopian | 96f0819 | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 303 | |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 304 | status_t captureScreenImplLocked(const sp<IBinder>& display, sp<IMemoryHeap>* heap, |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 305 | uint32_t* width, uint32_t* height, PixelFormat* format, |
| 306 | uint32_t reqWidth, uint32_t reqHeight, uint32_t minLayerZ, |
| 307 | uint32_t maxLayerZ); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 309 | /* ------------------------------------------------------------------------ |
| 310 | * EGL |
| 311 | */ |
| 312 | static status_t selectConfigForPixelFormat(EGLDisplay dpy, |
| 313 | EGLint const* attrs, PixelFormat format, EGLConfig* outConfig); |
| 314 | static EGLConfig selectEGLConfig(EGLDisplay disp, EGLint visualId); |
| 315 | static EGLContext createGLContext(EGLDisplay disp, EGLConfig config); |
Mathias Agopian | cde87a3 | 2012-09-13 14:09:01 -0700 | [diff] [blame] | 316 | void initializeGL(EGLDisplay display); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 317 | uint32_t getMaxTextureSize() const; |
| 318 | uint32_t getMaxViewportDims() const; |
Mathias Agopian | a491260 | 2012-07-12 14:25:33 -0700 | [diff] [blame] | 319 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 320 | /* ------------------------------------------------------------------------ |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 321 | * Display and layer stack management |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 322 | */ |
Andy McFadden | 13a082e | 2012-08-24 10:16:42 -0700 | [diff] [blame] | 323 | // called when starting, or restarting after system_server death |
| 324 | void initializeDisplays(); |
| 325 | |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 326 | sp<const DisplayDevice> getDisplayDevice(const wp<IBinder>& dpy) const { |
Mathias Agopian | 92a979a | 2012-08-02 18:32:23 -0700 | [diff] [blame] | 327 | return mDisplays.valueFor(dpy); |
| 328 | } |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 329 | const sp<DisplayDevice>& getDisplayDevice(const wp<IBinder>& dpy) { |
Mathias Agopian | 4297734 | 2012-08-05 00:40:46 -0700 | [diff] [blame] | 330 | return mDisplays.valueFor(dpy); |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 331 | } |
Mathias Agopian | 99b4984 | 2011-06-27 16:05:52 -0700 | [diff] [blame] | 332 | |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 333 | // mark a region of a layer stack dirty. this updates the dirty |
| 334 | // region of all screens presenting this layer stack. |
| 335 | void invalidateLayerStack(uint32_t layerStack, const Region& dirty); |
| 336 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 337 | /* ------------------------------------------------------------------------ |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 338 | * H/W composer |
| 339 | */ |
| 340 | |
| 341 | HWComposer& getHwComposer() const { return *mHwc; } |
| 342 | |
Mathias Agopian | 888c822 | 2012-08-04 21:10:38 -0700 | [diff] [blame] | 343 | /* ------------------------------------------------------------------------ |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 344 | * Compositing |
| 345 | */ |
| 346 | void invalidateHwcGeometry(); |
Mathias Agopian | ce3a0a5 | 2012-09-12 15:34:57 -0700 | [diff] [blame] | 347 | static void computeVisibleRegions( |
| 348 | const LayerVector& currentLayers, uint32_t layerStack, |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 349 | Region& dirtyRegion, Region& opaqueRegion); |
Mathias Agopian | cd60f99 | 2012-08-16 16:28:27 -0700 | [diff] [blame] | 350 | |
| 351 | void preComposition(); |
| 352 | void postComposition(); |
| 353 | void rebuildLayerStacks(); |
| 354 | void setUpHWComposer(); |
| 355 | void doComposition(); |
| 356 | void doDebugFlashRegions(); |
| 357 | void doDisplayComposition(const sp<const DisplayDevice>& hw, |
| 358 | const Region& dirtyRegion); |
| 359 | void doComposeSurfaces(const sp<const DisplayDevice>& hw, |
| 360 | const Region& dirty); |
| 361 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 362 | void postFramebuffer(); |
Mathias Agopian | 55801e4 | 2012-08-27 18:54:24 -0700 | [diff] [blame] | 363 | void drawWormhole(const sp<const DisplayDevice>& hw, |
| 364 | const Region& region) const; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 365 | GLuint getProtectedTexName() const { |
| 366 | return mProtectedTexName; |
| 367 | } |
Mathias Agopian | 4da7519 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 368 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 369 | /* ------------------------------------------------------------------------ |
Jamie Gennis | 0bceb84 | 2012-08-23 20:19:38 -0700 | [diff] [blame] | 370 | * Display management |
| 371 | */ |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 372 | |
Jamie Gennis | 0bceb84 | 2012-08-23 20:19:38 -0700 | [diff] [blame] | 373 | |
| 374 | /* ------------------------------------------------------------------------ |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 375 | * Debugging & dumpsys |
| 376 | */ |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 377 | void listLayersLocked(const Vector<String16>& args, size_t& index, |
| 378 | String8& result, char* buffer, size_t SIZE) const; |
| 379 | void dumpStatsLocked(const Vector<String16>& args, size_t& index, |
| 380 | String8& result, char* buffer, size_t SIZE) const; |
| 381 | void clearStatsLocked(const Vector<String16>& args, size_t& index, |
| 382 | String8& result, char* buffer, size_t SIZE) const; |
| 383 | void dumpAllLocked(String8& result, char* buffer, size_t SIZE) const; |
Keun young Park | 63f165f | 2012-08-31 10:53:36 -0700 | [diff] [blame] | 384 | bool startDdmConnection(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 386 | /* ------------------------------------------------------------------------ |
| 387 | * Attributes |
| 388 | */ |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 390 | // access must be protected by mStateLock |
| 391 | mutable Mutex mStateLock; |
| 392 | State mCurrentState; |
| 393 | volatile int32_t mTransactionFlags; |
| 394 | Condition mTransactionCV; |
| 395 | SortedVector<sp<LayerBase> > mLayerPurgatory; |
| 396 | bool mTransationPending; |
| 397 | Vector<sp<LayerBase> > mLayersPendingRemoval; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 398 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 399 | // protected by mStateLock (but we could use another lock) |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 400 | bool mLayersRemoved; |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 401 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 402 | // access must be protected by mInvalidateLock |
Mathias Agopian | 87baae1 | 2012-07-31 12:38:26 -0700 | [diff] [blame] | 403 | volatile int32_t mRepaintEverything; |
Mathias Agopian | ca4d360 | 2011-05-19 15:38:14 -0700 | [diff] [blame] | 404 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 405 | // constant members (no synchronization needed for access) |
Mathias Agopian | 8630320 | 2012-07-24 22:46:10 -0700 | [diff] [blame] | 406 | HWComposer* mHwc; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 407 | GLuint mProtectedTexName; |
| 408 | nsecs_t mBootTime; |
| 409 | sp<EventThread> mEventThread; |
| 410 | GLint mMaxViewportDims[2]; |
| 411 | GLint mMaxTextureSize; |
| 412 | EGLContext mEGLContext; |
| 413 | EGLConfig mEGLConfig; |
Jesse Hall | 34a09ba | 2012-07-29 22:35:34 -0700 | [diff] [blame] | 414 | EGLDisplay mEGLDisplay; |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 415 | sp<IBinder> mDefaultDisplays[DisplayDevice::NUM_DISPLAY_TYPES]; |
Mathias Agopian | 3094df3 | 2012-06-18 18:06:45 -0700 | [diff] [blame] | 416 | |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 417 | // Can only accessed from the main thread, these members |
| 418 | // don't need synchronization |
| 419 | State mDrawingState; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 420 | bool mVisibleRegionsDirty; |
| 421 | bool mHwWorkListDirty; |
Mathias Agopian | 3ee454a | 2012-08-27 16:28:24 -0700 | [diff] [blame] | 422 | DefaultKeyedVector< wp<IBinder>, sp<DisplayDevice> > mDisplays; |
Mathias Agopian | 921e6ac | 2012-07-23 23:11:29 -0700 | [diff] [blame] | 423 | |
| 424 | // don't use a lock for these, we don't care |
| 425 | int mDebugRegion; |
| 426 | int mDebugDDMS; |
| 427 | int mDebugDisableHWC; |
| 428 | int mDebugDisableTransformHint; |
| 429 | volatile nsecs_t mDebugInSwapBuffers; |
| 430 | nsecs_t mLastSwapBufferTime; |
| 431 | volatile nsecs_t mDebugInTransaction; |
| 432 | nsecs_t mLastTransactionTime; |
| 433 | bool mBootFinished; |
| 434 | |
| 435 | // these are thread safe |
| 436 | mutable MessageQueue mEventQueue; |
| 437 | mutable Barrier mReadyToRunBarrier; |
| 438 | |
| 439 | // protected by mDestroyedLayerLock; |
| 440 | mutable Mutex mDestroyedLayerLock; |
| 441 | Vector<LayerBase const *> mDestroyedLayers; |
| 442 | |
| 443 | /* ------------------------------------------------------------------------ |
| 444 | * Feature prototyping |
| 445 | */ |
| 446 | |
Mathias Agopian | 5f20e2d | 2012-08-10 18:50:38 -0700 | [diff] [blame] | 447 | sp<IBinder> mExtDisplayToken; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 448 | }; |
| 449 | |
| 450 | // --------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | }; // namespace android |
| 452 | |
| 453 | #endif // ANDROID_SURFACE_FLINGER_H |