The Android Open Source Project | 9066cfe | 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 | |
| 23 | #include <utils/SortedVector.h> |
| 24 | #include <utils/KeyedVector.h> |
| 25 | #include <utils/threads.h> |
| 26 | #include <utils/Atomic.h> |
| 27 | #include <utils/Errors.h> |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 28 | #include <utils/RefBase.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 29 | |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 30 | #include <binder/IMemory.h> |
Mathias Agopian | 151e859 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 31 | #include <binder/Permission.h> |
Mathias Agopian | 2465168 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 32 | #include <binder/BinderService.h> |
Mathias Agopian | 151e859 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 33 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | #include <ui/PixelFormat.h> |
Mathias Agopian | 000479f | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 35 | #include <surfaceflinger/ISurfaceComposer.h> |
Mathias Agopian | 770492c | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 36 | #include <surfaceflinger/ISurfaceComposerClient.h> |
Jamie Gennis | f7acf16 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 37 | #include <surfaceflinger/IGraphicBufferAlloc.h> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
| 39 | #include "Barrier.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 40 | #include "Layer.h" |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | |
Mathias Agopian | 6ead5d9 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 42 | #include "MessageQueue.h" |
| 43 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | namespace android { |
| 45 | |
| 46 | // --------------------------------------------------------------------------- |
| 47 | |
| 48 | class Client; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | class DisplayHardware; |
| 50 | class FreezeLock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | class Layer; |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 52 | class LayerDim; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 53 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | #define LIKELY( exp ) (__builtin_expect( (exp) != 0, true )) |
| 55 | #define UNLIKELY( exp ) (__builtin_expect( (exp) != 0, false )) |
| 56 | |
| 57 | // --------------------------------------------------------------------------- |
| 58 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 59 | class Client : public BnSurfaceComposerClient |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 60 | { |
| 61 | public: |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 62 | Client(const sp<SurfaceFlinger>& flinger); |
| 63 | ~Client(); |
| 64 | |
| 65 | status_t initCheck() const; |
| 66 | |
| 67 | // protected by SurfaceFlinger::mStateLock |
| 68 | ssize_t attachLayer(const sp<LayerBaseClient>& layer); |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 69 | void detachLayer(const LayerBaseClient* layer); |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 70 | sp<LayerBaseClient> getLayerUser(int32_t i) const; |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 71 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | private: |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 73 | |
| 74 | // ISurfaceComposerClient interface |
| 75 | virtual sp<IMemoryHeap> getControlBlock() const; |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 76 | virtual ssize_t getTokenForSurface(const sp<ISurface>& sur) const; |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 77 | virtual sp<ISurface> createSurface( |
| 78 | surface_data_t* params, int pid, const String8& name, |
| 79 | DisplayID display, uint32_t w, uint32_t h,PixelFormat format, |
| 80 | uint32_t flags); |
| 81 | virtual status_t destroySurface(SurfaceID surfaceId); |
| 82 | virtual status_t setState(int32_t count, const layer_state_t* states); |
| 83 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 84 | DefaultKeyedVector< size_t, wp<LayerBaseClient> > mLayers; |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 85 | sp<SurfaceFlinger> mFlinger; |
| 86 | int32_t mNameGenerator; |
| 87 | }; |
| 88 | |
| 89 | class UserClient : public BnSurfaceComposerClient |
| 90 | { |
| 91 | public: |
| 92 | // pointer to this client's control block |
| 93 | SharedClient* ctrlblk; |
| 94 | |
| 95 | public: |
| 96 | UserClient(const sp<SurfaceFlinger>& flinger); |
| 97 | ~UserClient(); |
| 98 | |
| 99 | status_t initCheck() const; |
| 100 | |
| 101 | // protected by SurfaceFlinger::mStateLock |
| 102 | void detachLayer(const Layer* layer); |
| 103 | |
| 104 | private: |
| 105 | |
| 106 | // ISurfaceComposerClient interface |
| 107 | virtual sp<IMemoryHeap> getControlBlock() const; |
| 108 | virtual ssize_t getTokenForSurface(const sp<ISurface>& sur) const; |
| 109 | virtual sp<ISurface> createSurface( |
| 110 | surface_data_t* params, int pid, const String8& name, |
| 111 | DisplayID display, uint32_t w, uint32_t h,PixelFormat format, |
| 112 | uint32_t flags); |
| 113 | virtual status_t destroySurface(SurfaceID surfaceId); |
| 114 | virtual status_t setState(int32_t count, const layer_state_t* states); |
| 115 | |
| 116 | // atomic-ops |
| 117 | mutable volatile int32_t mBitmap; |
| 118 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 119 | sp<IMemoryHeap> mCblkHeap; |
| 120 | sp<SurfaceFlinger> mFlinger; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | }; |
| 122 | |
Jamie Gennis | f7acf16 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 123 | class GraphicBufferAlloc : public BnGraphicBufferAlloc |
| 124 | { |
| 125 | public: |
| 126 | GraphicBufferAlloc(); |
| 127 | virtual ~GraphicBufferAlloc(); |
| 128 | |
| 129 | virtual sp<GraphicBuffer> createGraphicBuffer(uint32_t w, uint32_t h, |
| 130 | PixelFormat format, uint32_t usage); |
| 131 | virtual void freeAllGraphicBuffersExcept(int bufIdx); |
| 132 | |
| 133 | private: |
| 134 | Vector<sp<GraphicBuffer> > mBuffers; |
| 135 | Mutex mLock; |
| 136 | }; |
| 137 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | // --------------------------------------------------------------------------- |
| 139 | |
| 140 | class GraphicPlane |
| 141 | { |
| 142 | public: |
| 143 | static status_t orientationToTransfrom(int orientation, int w, int h, |
| 144 | Transform* tr); |
| 145 | |
| 146 | GraphicPlane(); |
| 147 | ~GraphicPlane(); |
| 148 | |
| 149 | bool initialized() const; |
| 150 | |
| 151 | void setDisplayHardware(DisplayHardware *); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | status_t setOrientation(int orientation); |
Mathias Agopian | 3552f53 | 2009-03-27 17:58:20 -0700 | [diff] [blame] | 153 | int getOrientation() const { return mOrientation; } |
Mathias Agopian | 66c77a5 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 154 | int getWidth() const; |
| 155 | int getHeight() const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 156 | |
| 157 | const DisplayHardware& displayHardware() const; |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 158 | DisplayHardware& editDisplayHardware(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 159 | const Transform& transform() const; |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 160 | EGLDisplay getEGLDisplay() const; |
| 161 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | private: |
| 163 | GraphicPlane(const GraphicPlane&); |
| 164 | GraphicPlane operator = (const GraphicPlane&); |
| 165 | |
| 166 | DisplayHardware* mHw; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | Transform mGlobalTransform; |
Mathias Agopian | 66c77a5 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 168 | Transform mDisplayTransform; |
Mathias Agopian | 3552f53 | 2009-03-27 17:58:20 -0700 | [diff] [blame] | 169 | int mOrientation; |
Mathias Agopian | 66c77a5 | 2010-02-08 15:49:35 -0800 | [diff] [blame] | 170 | float mDisplayWidth; |
| 171 | float mDisplayHeight; |
| 172 | int mWidth; |
| 173 | int mHeight; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 174 | }; |
| 175 | |
| 176 | // --------------------------------------------------------------------------- |
| 177 | |
| 178 | enum { |
| 179 | eTransactionNeeded = 0x01, |
| 180 | eTraversalNeeded = 0x02 |
| 181 | }; |
| 182 | |
Mathias Agopian | 2465168 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 183 | class SurfaceFlinger : |
| 184 | public BinderService<SurfaceFlinger>, |
| 185 | public BnSurfaceComposer, |
| 186 | protected Thread |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 187 | { |
| 188 | public: |
Mathias Agopian | 2465168 | 2010-07-14 18:41:18 -0700 | [diff] [blame] | 189 | static char const* getServiceName() { return "SurfaceFlinger"; } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | |
| 191 | SurfaceFlinger(); |
| 192 | virtual ~SurfaceFlinger(); |
| 193 | void init(); |
| 194 | |
| 195 | virtual status_t onTransact( |
| 196 | uint32_t code, const Parcel& data, Parcel* reply, uint32_t flags); |
| 197 | |
| 198 | virtual status_t dump(int fd, const Vector<String16>& args); |
| 199 | |
| 200 | // ISurfaceComposer interface |
Mathias Agopian | 770492c | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 201 | virtual sp<ISurfaceComposerClient> createConnection(); |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 202 | virtual sp<ISurfaceComposerClient> createClientConnection(); |
Jamie Gennis | f7acf16 | 2011-01-12 18:30:40 -0800 | [diff] [blame] | 203 | virtual sp<IGraphicBufferAlloc> createGraphicBufferAlloc(); |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 204 | virtual sp<IMemoryHeap> getCblk() const; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 205 | virtual void bootFinished(); |
| 206 | virtual void openGlobalTransaction(); |
| 207 | virtual void closeGlobalTransaction(); |
| 208 | virtual status_t freezeDisplay(DisplayID dpy, uint32_t flags); |
| 209 | virtual status_t unfreezeDisplay(DisplayID dpy, uint32_t flags); |
Mathias Agopian | eb0c86e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 210 | virtual int setOrientation(DisplayID dpy, int orientation, uint32_t flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 211 | virtual void signal() const; |
Mathias Agopian | 3dd25a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 212 | |
| 213 | virtual status_t captureScreen(DisplayID dpy, |
| 214 | sp<IMemoryHeap>* heap, |
| 215 | uint32_t* width, uint32_t* height, |
| 216 | PixelFormat* format, uint32_t reqWidth, uint32_t reqHeight, |
| 217 | uint32_t minLayerZ, uint32_t maxLayerZ); |
| 218 | |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 219 | virtual status_t turnElectronBeamOff(int32_t mode); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 220 | virtual status_t turnElectronBeamOn(int32_t mode); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | |
| 222 | void screenReleased(DisplayID dpy); |
| 223 | void screenAcquired(DisplayID dpy); |
| 224 | |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 225 | status_t removeLayer(const sp<LayerBase>& layer); |
| 226 | status_t addLayer(const sp<LayerBase>& layer); |
| 227 | status_t invalidateLayerVisibility(const sp<LayerBase>& layer); |
Mathias Agopian | fb4dcb1 | 2011-01-13 17:53:01 -0800 | [diff] [blame] | 228 | void invalidateHwcGeometry(); |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 229 | |
| 230 | sp<Layer> getLayer(const sp<ISurface>& sur) const; |
| 231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | private: |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 233 | friend class Client; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | friend class LayerBase; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | friend class LayerBaseClient; |
Mathias Agopian | 94aadce | 2009-07-06 19:04:03 -0700 | [diff] [blame] | 236 | friend class LayerBaseClient::Surface; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 237 | friend class Layer; |
Mathias Agopian | 9cc8852 | 2009-06-18 18:48:39 -0700 | [diff] [blame] | 238 | friend class LayerDim; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 240 | sp<ISurface> createSurface(const sp<Client>& client, |
| 241 | int pid, const String8& name, |
Mathias Agopian | 770492c | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 242 | ISurfaceComposerClient::surface_data_t* params, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | DisplayID display, uint32_t w, uint32_t h, PixelFormat format, |
| 244 | uint32_t flags); |
| 245 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 246 | sp<Layer> createNormalSurface( |
Mathias Agopian | 6edf5af | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 247 | const sp<Client>& client, DisplayID display, |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 248 | uint32_t w, uint32_t h, uint32_t flags, |
Mathias Agopian | 18b6b49 | 2009-08-19 17:46:26 -0700 | [diff] [blame] | 249 | PixelFormat& format); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 251 | sp<LayerDim> createDimSurface( |
Mathias Agopian | 6edf5af | 2009-06-19 17:00:27 -0700 | [diff] [blame] | 252 | const sp<Client>& client, DisplayID display, |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 253 | uint32_t w, uint32_t h, uint32_t flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 254 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 255 | status_t removeSurface(const sp<Client>& client, SurfaceID sid); |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 256 | status_t destroySurface(const sp<LayerBaseClient>& layer); |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 257 | status_t setClientState(const sp<Client>& client, |
| 258 | int32_t count, const layer_state_t* states); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | |
Mathias Agopian | 1efba9a | 2010-08-10 18:09:09 -0700 | [diff] [blame] | 260 | class LayerVector : public SortedVector< sp<LayerBase> > { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 261 | public: |
Mathias Agopian | 1efba9a | 2010-08-10 18:09:09 -0700 | [diff] [blame] | 262 | LayerVector() { } |
| 263 | LayerVector(const LayerVector& rhs) : SortedVector< sp<LayerBase> >(rhs) { } |
| 264 | virtual int do_compare(const void* lhs, const void* rhs) const { |
| 265 | const sp<LayerBase>& l(*reinterpret_cast<const sp<LayerBase>*>(lhs)); |
| 266 | const sp<LayerBase>& r(*reinterpret_cast<const sp<LayerBase>*>(rhs)); |
| 267 | // sort layers by Z order |
| 268 | uint32_t lz = l->currentState().z; |
| 269 | uint32_t rz = r->currentState().z; |
| 270 | // then by sequence, so we get a stable ordering |
| 271 | return (lz != rz) ? (lz - rz) : (l->sequence - r->sequence); |
| 272 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 273 | }; |
| 274 | |
| 275 | struct State { |
| 276 | State() { |
| 277 | orientation = ISurfaceComposer::eOrientationDefault; |
| 278 | freezeDisplay = 0; |
| 279 | } |
| 280 | LayerVector layersSortedByZ; |
| 281 | uint8_t orientation; |
Mathias Agopian | eb0c86e | 2009-03-27 18:11:38 -0700 | [diff] [blame] | 282 | uint8_t orientationType; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 283 | uint8_t freezeDisplay; |
| 284 | }; |
| 285 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 286 | virtual bool threadLoop(); |
| 287 | virtual status_t readyToRun(); |
| 288 | virtual void onFirstRef(); |
| 289 | |
Andy McFadden | 08c19be | 2009-10-29 10:19:34 -0700 | [diff] [blame] | 290 | public: // hack to work around gcc 4.0.3 bug |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | const GraphicPlane& graphicPlane(int dpy) const; |
| 292 | GraphicPlane& graphicPlane(int dpy); |
Andy McFadden | 08c19be | 2009-10-29 10:19:34 -0700 | [diff] [blame] | 293 | private: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 294 | |
| 295 | void waitForEvent(); |
Andy McFadden | fa0a4bd | 2009-09-21 14:33:20 -0700 | [diff] [blame] | 296 | public: // hack to work around gcc 4.0.3 bug |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | void signalEvent(); |
Andy McFadden | fa0a4bd | 2009-09-21 14:33:20 -0700 | [diff] [blame] | 298 | private: |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | void handleConsoleEvents(); |
| 300 | void handleTransaction(uint32_t transactionFlags); |
Mathias Agopian | 2d5ee25 | 2009-06-04 18:46:21 -0700 | [diff] [blame] | 301 | void handleTransactionLocked( |
| 302 | uint32_t transactionFlags, |
| 303 | Vector< sp<LayerBase> >& ditchedLayers); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 304 | |
| 305 | void computeVisibleRegions( |
| 306 | LayerVector& currentLayers, |
| 307 | Region& dirtyRegion, |
| 308 | Region& wormholeRegion); |
| 309 | |
| 310 | void handlePageFlip(); |
| 311 | bool lockPageFlip(const LayerVector& currentLayers); |
| 312 | void unlockPageFlip(const LayerVector& currentLayers); |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 313 | void handleWorkList(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | void handleRepaint(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 315 | void postFramebuffer(); |
| 316 | void composeSurfaces(const Region& dirty); |
| 317 | void unlockClients(); |
| 318 | |
| 319 | |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 320 | ssize_t addClientLayer(const sp<Client>& client, |
| 321 | const sp<LayerBaseClient>& lbc); |
Mathias Agopian | 1473f46 | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 322 | status_t addLayer_l(const sp<LayerBase>& layer); |
| 323 | status_t removeLayer_l(const sp<LayerBase>& layer); |
Mathias Agopian | 6cf0db2 | 2009-04-17 19:36:26 -0700 | [diff] [blame] | 324 | status_t purgatorizeLayer_l(const sp<LayerBase>& layer); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | |
| 326 | uint32_t getTransactionFlags(uint32_t flags); |
Mathias Agopian | 898c4c9 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 327 | uint32_t setTransactionFlags(uint32_t flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | void commitTransaction(); |
| 329 | |
| 330 | |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 331 | status_t captureScreenImplLocked(DisplayID dpy, |
| 332 | sp<IMemoryHeap>* heap, |
| 333 | uint32_t* width, uint32_t* height, PixelFormat* format, |
Mathias Agopian | 3dd25a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 334 | uint32_t reqWidth, uint32_t reqHeight, |
| 335 | uint32_t minLayerZ, uint32_t maxLayerZ); |
Mathias Agopian | 38ed2e3 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 336 | |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 337 | status_t turnElectronBeamOffImplLocked(int32_t mode); |
| 338 | status_t turnElectronBeamOnImplLocked(int32_t mode); |
Mathias Agopian | 2d2b803 | 2010-10-12 16:05:48 -0700 | [diff] [blame] | 339 | status_t electronBeamOffAnimationImplLocked(); |
| 340 | status_t electronBeamOnAnimationImplLocked(); |
| 341 | status_t renderScreenToTextureLocked(DisplayID dpy, |
| 342 | GLuint* textureName, GLfloat* uOut, GLfloat* vOut); |
Mathias Agopian | aab758e | 2010-10-11 12:37:43 -0700 | [diff] [blame] | 343 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | friend class FreezeLock; |
| 345 | sp<FreezeLock> getFreezeLock() const; |
Mathias Agopian | 0e44976 | 2009-12-01 17:23:28 -0800 | [diff] [blame] | 346 | inline void incFreezeCount() { |
| 347 | if (mFreezeCount == 0) |
| 348 | mFreezeDisplayTime = 0; |
| 349 | mFreezeCount++; |
| 350 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | inline void decFreezeCount() { if (mFreezeCount > 0) mFreezeCount--; } |
| 352 | inline bool hasFreezeRequest() const { return mFreezeDisplay; } |
| 353 | inline bool isFrozen() const { |
Mathias Agopian | 6950e42 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 354 | return (mFreezeDisplay || mFreezeCount>0) && mBootFinished; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | |
| 358 | void debugFlashRegions(); |
| 359 | void debugShowFPS() const; |
| 360 | void drawWormhole() const; |
| 361 | |
Mathias Agopian | 6ead5d9 | 2009-04-20 19:39:12 -0700 | [diff] [blame] | 362 | |
| 363 | mutable MessageQueue mEventQueue; |
Mathias Agopian | 898c4c9 | 2010-05-18 17:06:55 -0700 | [diff] [blame] | 364 | |
| 365 | status_t postMessageAsync(const sp<MessageBase>& msg, |
| 366 | nsecs_t reltime=0, uint32_t flags = 0); |
| 367 | |
| 368 | status_t postMessageSync(const sp<MessageBase>& msg, |
| 369 | nsecs_t reltime=0, uint32_t flags = 0); |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 370 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 371 | // access must be protected by mStateLock |
| 372 | mutable Mutex mStateLock; |
| 373 | State mCurrentState; |
| 374 | State mDrawingState; |
| 375 | volatile int32_t mTransactionFlags; |
| 376 | volatile int32_t mTransactionCount; |
| 377 | Condition mTransactionCV; |
Mathias Agopian | f4dfe1b | 2011-01-14 17:37:42 -0800 | [diff] [blame] | 378 | SortedVector< sp<LayerBase> > mLayerPurgatory; |
Mathias Agopian | 9779b22 | 2009-09-07 16:32:45 -0700 | [diff] [blame] | 379 | bool mResizeTransationPending; |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 380 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 381 | // protected by mStateLock (but we could use another lock) |
Mathias Agopian | 593c05c | 2010-06-02 23:28:45 -0700 | [diff] [blame] | 382 | GraphicPlane mGraphicPlanes[1]; |
| 383 | bool mLayersRemoved; |
Mathias Agopian | 7623da4 | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 384 | DefaultKeyedVector< wp<IBinder>, wp<Layer> > mLayerMap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 385 | |
| 386 | // constant members (no synchronization needed for access) |
Mathias Agopian | d763b5d | 2009-07-02 18:11:53 -0700 | [diff] [blame] | 387 | sp<IMemoryHeap> mServerHeap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 388 | surface_flinger_cblk_t* mServerCblk; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 389 | GLuint mWormholeTexName; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 390 | nsecs_t mBootTime; |
Mathias Agopian | 151e859 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 391 | Permission mHardwareTest; |
| 392 | Permission mAccessSurfaceFlinger; |
Mathias Agopian | ca5edbe | 2010-09-24 11:26:58 -0700 | [diff] [blame] | 393 | Permission mReadFramebuffer; |
Mathias Agopian | 151e859 | 2009-06-15 18:24:59 -0700 | [diff] [blame] | 394 | Permission mDump; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 395 | |
| 396 | // Can only accessed from the main thread, these members |
| 397 | // don't need synchronization |
| 398 | Region mDirtyRegion; |
Mathias Agopian | 12cedff | 2009-07-28 10:57:27 -0700 | [diff] [blame] | 399 | Region mDirtyRegionRemovedLayer; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 400 | Region mInvalidRegion; |
| 401 | Region mWormholeRegion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | bool mVisibleRegionsDirty; |
Mathias Agopian | e0d5f5b | 2010-08-10 17:14:02 -0700 | [diff] [blame] | 403 | bool mHwWorkListDirty; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 404 | bool mDeferReleaseConsole; |
| 405 | bool mFreezeDisplay; |
Mathias Agopian | d4e03f3 | 2010-10-14 14:54:06 -0700 | [diff] [blame] | 406 | int32_t mElectronBeamAnimationMode; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 407 | int32_t mFreezeCount; |
| 408 | nsecs_t mFreezeDisplayTime; |
Mathias Agopian | ff1d410 | 2010-08-10 17:19:56 -0700 | [diff] [blame] | 409 | Vector< sp<LayerBase> > mVisibleLayersSortedByZ; |
| 410 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 411 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 412 | // don't use a lock for these, we don't care |
| 413 | int mDebugRegion; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 414 | int mDebugBackground; |
Mathias Agopian | 6a96924 | 2010-09-22 18:58:01 -0700 | [diff] [blame] | 415 | int mDebugDisableHWC; |
Mathias Agopian | a8d4917 | 2009-08-26 16:36:26 -0700 | [diff] [blame] | 416 | volatile nsecs_t mDebugInSwapBuffers; |
| 417 | nsecs_t mLastSwapBufferTime; |
| 418 | volatile nsecs_t mDebugInTransaction; |
| 419 | nsecs_t mLastTransactionTime; |
Mathias Agopian | 6950e42 | 2009-10-05 17:07:12 -0700 | [diff] [blame] | 420 | bool mBootFinished; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 421 | |
| 422 | // these are thread safe |
| 423 | mutable Barrier mReadyToRunBarrier; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 424 | |
| 425 | // atomic variables |
| 426 | enum { |
| 427 | eConsoleReleased = 1, |
| 428 | eConsoleAcquired = 2 |
| 429 | }; |
| 430 | volatile int32_t mConsoleSignals; |
| 431 | |
| 432 | // only written in the main thread, only read in other threads |
| 433 | volatile int32_t mSecureFrameBuffer; |
| 434 | }; |
| 435 | |
| 436 | // --------------------------------------------------------------------------- |
| 437 | |
| 438 | class FreezeLock : public LightRefBase<FreezeLock> { |
| 439 | SurfaceFlinger* mFlinger; |
| 440 | public: |
| 441 | FreezeLock(SurfaceFlinger* flinger) |
| 442 | : mFlinger(flinger) { |
| 443 | mFlinger->incFreezeCount(); |
| 444 | } |
| 445 | ~FreezeLock() { |
| 446 | mFlinger->decFreezeCount(); |
| 447 | } |
| 448 | }; |
| 449 | |
| 450 | // --------------------------------------------------------------------------- |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 451 | }; // namespace android |
| 452 | |
| 453 | #endif // ANDROID_SURFACE_FLINGER_H |