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