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