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