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 | #define LOG_TAG "SurfaceComposerClient" |
| 18 | |
| 19 | #include <stdint.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | #include <sys/types.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | #include <utils/Errors.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 23 | #include <utils/Log.h> |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 24 | #include <utils/Singleton.h> |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 25 | #include <utils/SortedVector.h> |
| 26 | #include <utils/String8.h> |
| 27 | #include <utils/threads.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 29 | #include <binder/IMemory.h> |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 30 | #include <binder/IServiceManager.h> |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 31 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 32 | #include <ui/DisplayInfo.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 34 | #include <gui/ISurface.h> |
| 35 | #include <gui/ISurfaceComposer.h> |
| 36 | #include <gui/ISurfaceComposerClient.h> |
| 37 | #include <gui/SurfaceComposerClient.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | |
Mathias Agopian | 41f673c | 2011-11-17 17:48:35 -0800 | [diff] [blame] | 39 | #include <private/gui/ComposerService.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 40 | #include <private/gui/LayerState.h> |
| 41 | #include <private/gui/SharedBufferStack.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
| 43 | namespace android { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | // --------------------------------------------------------------------------- |
| 45 | |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 46 | ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService); |
| 47 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 48 | ComposerService::ComposerService() |
| 49 | : Singleton<ComposerService>() { |
| 50 | const String16 name("SurfaceFlinger"); |
| 51 | while (getService(name, &mComposerService) != NO_ERROR) { |
| 52 | usleep(250000); |
| 53 | } |
| 54 | mServerCblkMemory = mComposerService->getCblk(); |
| 55 | mServerCblk = static_cast<surface_flinger_cblk_t volatile *>( |
| 56 | mServerCblkMemory->getBase()); |
| 57 | } |
| 58 | |
| 59 | sp<ISurfaceComposer> ComposerService::getComposerService() { |
| 60 | return ComposerService::getInstance().mComposerService; |
| 61 | } |
| 62 | |
| 63 | surface_flinger_cblk_t const volatile * ComposerService::getControlBlock() { |
| 64 | return ComposerService::getInstance().mServerCblk; |
| 65 | } |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 66 | |
| 67 | static inline sp<ISurfaceComposer> getComposerService() { |
| 68 | return ComposerService::getComposerService(); |
| 69 | } |
| 70 | |
| 71 | static inline surface_flinger_cblk_t const volatile * get_cblk() { |
| 72 | return ComposerService::getControlBlock(); |
| 73 | } |
| 74 | |
| 75 | // --------------------------------------------------------------------------- |
| 76 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 77 | // NOTE: this is NOT a member function (it's a friend defined with its |
| 78 | // declaration). |
| 79 | static inline |
| 80 | int compare_type( const ComposerState& lhs, const ComposerState& rhs) { |
| 81 | if (lhs.client < rhs.client) return -1; |
| 82 | if (lhs.client > rhs.client) return 1; |
| 83 | if (lhs.state.surface < rhs.state.surface) return -1; |
| 84 | if (lhs.state.surface > rhs.state.surface) return 1; |
| 85 | return 0; |
| 86 | } |
| 87 | |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 88 | class Composer : public Singleton<Composer> |
| 89 | { |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 90 | friend class Singleton<Composer>; |
| 91 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 92 | mutable Mutex mLock; |
| 93 | SortedVector<ComposerState> mStates; |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 94 | int mOrientation; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 95 | uint32_t mForceSynchronous; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 96 | |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 97 | Composer() : Singleton<Composer>(), |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 98 | mOrientation(ISurfaceComposer::eOrientationUnchanged), |
| 99 | mForceSynchronous(0) |
| 100 | { } |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 101 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 102 | void closeGlobalTransactionImpl(bool synchronous); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 103 | |
| 104 | layer_state_t* getLayerStateLocked( |
| 105 | const sp<SurfaceComposerClient>& client, SurfaceID id); |
| 106 | |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 107 | public: |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 108 | |
| 109 | status_t setPosition(const sp<SurfaceComposerClient>& client, SurfaceID id, |
Mathias Agopian | 41b6aab | 2011-08-30 18:51:54 -0700 | [diff] [blame] | 110 | float x, float y); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 111 | status_t setSize(const sp<SurfaceComposerClient>& client, SurfaceID id, |
| 112 | uint32_t w, uint32_t h); |
| 113 | status_t setLayer(const sp<SurfaceComposerClient>& client, SurfaceID id, |
| 114 | int32_t z); |
| 115 | status_t setFlags(const sp<SurfaceComposerClient>& client, SurfaceID id, |
| 116 | uint32_t flags, uint32_t mask); |
| 117 | status_t setTransparentRegionHint( |
| 118 | const sp<SurfaceComposerClient>& client, SurfaceID id, |
| 119 | const Region& transparentRegion); |
| 120 | status_t setAlpha(const sp<SurfaceComposerClient>& client, SurfaceID id, |
| 121 | float alpha); |
| 122 | status_t setMatrix(const sp<SurfaceComposerClient>& client, SurfaceID id, |
| 123 | float dsdx, float dtdx, float dsdy, float dtdy); |
| 124 | status_t setFreezeTint( |
| 125 | const sp<SurfaceComposerClient>& client, SurfaceID id, |
| 126 | uint32_t tint); |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 127 | status_t setOrientation(int orientation); |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame^] | 128 | status_t setCrop(const sp<SurfaceComposerClient>& client, SurfaceID id, |
| 129 | const Rect& crop); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 130 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 131 | static void closeGlobalTransaction(bool synchronous) { |
| 132 | Composer::getInstance().closeGlobalTransactionImpl(synchronous); |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 133 | } |
| 134 | }; |
| 135 | |
| 136 | ANDROID_SINGLETON_STATIC_INSTANCE(Composer); |
| 137 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 138 | // --------------------------------------------------------------------------- |
| 139 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 140 | void Composer::closeGlobalTransactionImpl(bool synchronous) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 141 | sp<ISurfaceComposer> sm(getComposerService()); |
| 142 | |
| 143 | Vector<ComposerState> transaction; |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 144 | int orientation; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 145 | uint32_t flags = 0; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 146 | |
| 147 | { // scope for the lock |
| 148 | Mutex::Autolock _l(mLock); |
| 149 | transaction = mStates; |
| 150 | mStates.clear(); |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 151 | |
| 152 | orientation = mOrientation; |
| 153 | mOrientation = ISurfaceComposer::eOrientationUnchanged; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 154 | |
| 155 | if (synchronous || mForceSynchronous) { |
| 156 | flags |= ISurfaceComposer::eSynchronous; |
| 157 | } |
| 158 | mForceSynchronous = false; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 161 | sm->setTransactionState(transaction, orientation, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 164 | layer_state_t* Composer::getLayerStateLocked( |
| 165 | const sp<SurfaceComposerClient>& client, SurfaceID id) { |
| 166 | |
| 167 | ComposerState s; |
| 168 | s.client = client->mClient; |
| 169 | s.state.surface = id; |
| 170 | |
| 171 | ssize_t index = mStates.indexOf(s); |
| 172 | if (index < 0) { |
| 173 | // we don't have it, add an initialized layer_state to our list |
| 174 | index = mStates.add(s); |
| 175 | } |
| 176 | |
| 177 | ComposerState* const out = mStates.editArray(); |
| 178 | return &(out[index].state); |
| 179 | } |
| 180 | |
| 181 | status_t Composer::setPosition(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | 41b6aab | 2011-08-30 18:51:54 -0700 | [diff] [blame] | 182 | SurfaceID id, float x, float y) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 183 | Mutex::Autolock _l(mLock); |
| 184 | layer_state_t* s = getLayerStateLocked(client, id); |
| 185 | if (!s) |
| 186 | return BAD_INDEX; |
| 187 | s->what |= ISurfaceComposer::ePositionChanged; |
| 188 | s->x = x; |
| 189 | s->y = y; |
| 190 | return NO_ERROR; |
| 191 | } |
| 192 | |
| 193 | status_t Composer::setSize(const sp<SurfaceComposerClient>& client, |
| 194 | SurfaceID id, uint32_t w, uint32_t h) { |
| 195 | Mutex::Autolock _l(mLock); |
| 196 | layer_state_t* s = getLayerStateLocked(client, id); |
| 197 | if (!s) |
| 198 | return BAD_INDEX; |
| 199 | s->what |= ISurfaceComposer::eSizeChanged; |
| 200 | s->w = w; |
| 201 | s->h = h; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 202 | |
| 203 | // Resizing a surface makes the transaction synchronous. |
| 204 | mForceSynchronous = true; |
| 205 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 206 | return NO_ERROR; |
| 207 | } |
| 208 | |
| 209 | status_t Composer::setLayer(const sp<SurfaceComposerClient>& client, |
| 210 | SurfaceID id, int32_t z) { |
| 211 | Mutex::Autolock _l(mLock); |
| 212 | layer_state_t* s = getLayerStateLocked(client, id); |
| 213 | if (!s) |
| 214 | return BAD_INDEX; |
| 215 | s->what |= ISurfaceComposer::eLayerChanged; |
| 216 | s->z = z; |
| 217 | return NO_ERROR; |
| 218 | } |
| 219 | |
| 220 | status_t Composer::setFlags(const sp<SurfaceComposerClient>& client, |
| 221 | SurfaceID id, uint32_t flags, |
| 222 | uint32_t mask) { |
| 223 | Mutex::Autolock _l(mLock); |
| 224 | layer_state_t* s = getLayerStateLocked(client, id); |
| 225 | if (!s) |
| 226 | return BAD_INDEX; |
| 227 | s->what |= ISurfaceComposer::eVisibilityChanged; |
| 228 | s->flags &= ~mask; |
| 229 | s->flags |= (flags & mask); |
| 230 | s->mask |= mask; |
| 231 | return NO_ERROR; |
| 232 | } |
| 233 | |
| 234 | status_t Composer::setTransparentRegionHint( |
| 235 | const sp<SurfaceComposerClient>& client, SurfaceID id, |
| 236 | const Region& transparentRegion) { |
| 237 | Mutex::Autolock _l(mLock); |
| 238 | layer_state_t* s = getLayerStateLocked(client, id); |
| 239 | if (!s) |
| 240 | return BAD_INDEX; |
| 241 | s->what |= ISurfaceComposer::eTransparentRegionChanged; |
| 242 | s->transparentRegion = transparentRegion; |
| 243 | return NO_ERROR; |
| 244 | } |
| 245 | |
| 246 | status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client, |
| 247 | SurfaceID id, float alpha) { |
| 248 | Mutex::Autolock _l(mLock); |
| 249 | layer_state_t* s = getLayerStateLocked(client, id); |
| 250 | if (!s) |
| 251 | return BAD_INDEX; |
| 252 | s->what |= ISurfaceComposer::eAlphaChanged; |
| 253 | s->alpha = alpha; |
| 254 | return NO_ERROR; |
| 255 | } |
| 256 | |
| 257 | status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client, |
| 258 | SurfaceID id, float dsdx, float dtdx, |
| 259 | float dsdy, float dtdy) { |
| 260 | Mutex::Autolock _l(mLock); |
| 261 | layer_state_t* s = getLayerStateLocked(client, id); |
| 262 | if (!s) |
| 263 | return BAD_INDEX; |
| 264 | s->what |= ISurfaceComposer::eMatrixChanged; |
| 265 | layer_state_t::matrix22_t matrix; |
| 266 | matrix.dsdx = dsdx; |
| 267 | matrix.dtdx = dtdx; |
| 268 | matrix.dsdy = dsdy; |
| 269 | matrix.dtdy = dtdy; |
| 270 | s->matrix = matrix; |
| 271 | return NO_ERROR; |
| 272 | } |
| 273 | |
| 274 | status_t Composer::setFreezeTint(const sp<SurfaceComposerClient>& client, |
| 275 | SurfaceID id, uint32_t tint) { |
| 276 | Mutex::Autolock _l(mLock); |
| 277 | layer_state_t* s = getLayerStateLocked(client, id); |
| 278 | if (!s) |
| 279 | return BAD_INDEX; |
| 280 | s->what |= ISurfaceComposer::eFreezeTintChanged; |
| 281 | s->tint = tint; |
| 282 | return NO_ERROR; |
| 283 | } |
| 284 | |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 285 | status_t Composer::setOrientation(int orientation) { |
| 286 | Mutex::Autolock _l(mLock); |
| 287 | mOrientation = orientation; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 288 | |
| 289 | // Changing the orientation makes the transaction synchronous. |
| 290 | mForceSynchronous = true; |
| 291 | |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 292 | return NO_ERROR; |
| 293 | } |
| 294 | |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame^] | 295 | status_t Composer::setCrop(const sp<SurfaceComposerClient>& client, |
| 296 | SurfaceID id, const Rect& crop) { |
| 297 | Mutex::Autolock _l(mLock); |
| 298 | layer_state_t* s = getLayerStateLocked(client, id); |
| 299 | if (!s) |
| 300 | return BAD_INDEX; |
| 301 | s->what |= ISurfaceComposer::eCropChanged; |
| 302 | s->crop = crop; |
| 303 | return NO_ERROR; |
| 304 | } |
| 305 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 306 | // --------------------------------------------------------------------------- |
| 307 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | SurfaceComposerClient::SurfaceComposerClient() |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 309 | : mStatus(NO_INIT), mComposer(Composer::getInstance()) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 310 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | } |
| 312 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 313 | void SurfaceComposerClient::onFirstRef() { |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 314 | sp<ISurfaceComposer> sm(getComposerService()); |
| 315 | if (sm != 0) { |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 316 | sp<ISurfaceComposerClient> conn = sm->createConnection(); |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 317 | if (conn != 0) { |
| 318 | mClient = conn; |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 319 | mStatus = NO_ERROR; |
| 320 | } |
| 321 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 324 | SurfaceComposerClient::~SurfaceComposerClient() { |
Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 325 | dispose(); |
| 326 | } |
Mathias Agopian | dd3423c | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 327 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 328 | status_t SurfaceComposerClient::initCheck() const { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | return mStatus; |
| 330 | } |
| 331 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 332 | sp<IBinder> SurfaceComposerClient::connection() const { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 333 | return (mClient != 0) ? mClient->asBinder() : 0; |
| 334 | } |
| 335 | |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 336 | status_t SurfaceComposerClient::linkToComposerDeath( |
| 337 | const sp<IBinder::DeathRecipient>& recipient, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 338 | void* cookie, uint32_t flags) { |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 339 | sp<ISurfaceComposer> sm(getComposerService()); |
| 340 | return sm->asBinder()->linkToDeath(recipient, cookie, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 341 | } |
| 342 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 343 | void SurfaceComposerClient::dispose() { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | // this can be called more than once. |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 345 | sp<ISurfaceComposerClient> client; |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 346 | Mutex::Autolock _lm(mLock); |
| 347 | if (mClient != 0) { |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 348 | client = mClient; // hold ref while lock is held |
| 349 | mClient.clear(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 350 | } |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 351 | mStatus = NO_INIT; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 352 | } |
| 353 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 354 | sp<SurfaceControl> SurfaceComposerClient::createSurface( |
| 355 | DisplayID display, |
| 356 | uint32_t w, |
| 357 | uint32_t h, |
| 358 | PixelFormat format, |
| 359 | uint32_t flags) |
| 360 | { |
| 361 | String8 name; |
| 362 | const size_t SIZE = 128; |
| 363 | char buffer[SIZE]; |
| 364 | snprintf(buffer, SIZE, "<pid_%d>", getpid()); |
| 365 | name.append(buffer); |
| 366 | |
| 367 | return SurfaceComposerClient::createSurface(name, display, |
| 368 | w, h, format, flags); |
| 369 | } |
| 370 | |
| 371 | sp<SurfaceControl> SurfaceComposerClient::createSurface( |
| 372 | const String8& name, |
| 373 | DisplayID display, |
| 374 | uint32_t w, |
| 375 | uint32_t h, |
| 376 | PixelFormat format, |
| 377 | uint32_t flags) |
| 378 | { |
| 379 | sp<SurfaceControl> result; |
| 380 | if (mStatus == NO_ERROR) { |
| 381 | ISurfaceComposerClient::surface_data_t data; |
| 382 | sp<ISurface> surface = mClient->createSurface(&data, name, |
| 383 | display, w, h, format, flags); |
| 384 | if (surface != 0) { |
Mathias Agopian | c10d9d9 | 2011-07-20 16:46:11 -0700 | [diff] [blame] | 385 | result = new SurfaceControl(this, surface, data); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | return result; |
| 389 | } |
| 390 | |
| 391 | status_t SurfaceComposerClient::destroySurface(SurfaceID sid) { |
| 392 | if (mStatus != NO_ERROR) |
| 393 | return mStatus; |
| 394 | status_t err = mClient->destroySurface(sid); |
| 395 | return err; |
| 396 | } |
| 397 | |
| 398 | inline Composer& SurfaceComposerClient::getComposer() { |
| 399 | return mComposer; |
| 400 | } |
| 401 | |
| 402 | // ---------------------------------------------------------------------------- |
| 403 | |
| 404 | void SurfaceComposerClient::openGlobalTransaction() { |
| 405 | // Currently a no-op |
| 406 | } |
| 407 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 408 | void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) { |
| 409 | Composer::closeGlobalTransaction(synchronous); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | // ---------------------------------------------------------------------------- |
| 413 | |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame^] | 414 | status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) { |
| 415 | return getComposer().setCrop(this, id, crop); |
| 416 | } |
| 417 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 418 | status_t SurfaceComposerClient::setFreezeTint(SurfaceID id, uint32_t tint) { |
| 419 | return getComposer().setFreezeTint(this, id, tint); |
| 420 | } |
| 421 | |
Mathias Agopian | 41b6aab | 2011-08-30 18:51:54 -0700 | [diff] [blame] | 422 | status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 423 | return getComposer().setPosition(this, id, x, y); |
| 424 | } |
| 425 | |
| 426 | status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) { |
| 427 | return getComposer().setSize(this, id, w, h); |
| 428 | } |
| 429 | |
| 430 | status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) { |
| 431 | return getComposer().setLayer(this, id, z); |
| 432 | } |
| 433 | |
| 434 | status_t SurfaceComposerClient::hide(SurfaceID id) { |
| 435 | return getComposer().setFlags(this, id, |
| 436 | ISurfaceComposer::eLayerHidden, |
| 437 | ISurfaceComposer::eLayerHidden); |
| 438 | } |
| 439 | |
| 440 | status_t SurfaceComposerClient::show(SurfaceID id, int32_t) { |
| 441 | return getComposer().setFlags(this, id, |
| 442 | 0, |
| 443 | ISurfaceComposer::eLayerHidden); |
| 444 | } |
| 445 | |
| 446 | status_t SurfaceComposerClient::freeze(SurfaceID id) { |
| 447 | return getComposer().setFlags(this, id, |
| 448 | ISurfaceComposer::eLayerFrozen, |
| 449 | ISurfaceComposer::eLayerFrozen); |
| 450 | } |
| 451 | |
| 452 | status_t SurfaceComposerClient::unfreeze(SurfaceID id) { |
| 453 | return getComposer().setFlags(this, id, |
| 454 | 0, |
| 455 | ISurfaceComposer::eLayerFrozen); |
| 456 | } |
| 457 | |
| 458 | status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags, |
| 459 | uint32_t mask) { |
| 460 | return getComposer().setFlags(this, id, flags, mask); |
| 461 | } |
| 462 | |
| 463 | status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id, |
| 464 | const Region& transparentRegion) { |
| 465 | return getComposer().setTransparentRegionHint(this, id, transparentRegion); |
| 466 | } |
| 467 | |
| 468 | status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) { |
| 469 | return getComposer().setAlpha(this, id, alpha); |
| 470 | } |
| 471 | |
| 472 | status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx, |
| 473 | float dsdy, float dtdy) { |
| 474 | return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy); |
| 475 | } |
| 476 | |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 477 | status_t SurfaceComposerClient::setOrientation(DisplayID dpy, |
| 478 | int orientation, uint32_t flags) |
| 479 | { |
| 480 | return Composer::getInstance().setOrientation(orientation); |
| 481 | } |
| 482 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 483 | // ---------------------------------------------------------------------------- |
| 484 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 485 | status_t SurfaceComposerClient::getDisplayInfo( |
| 486 | DisplayID dpy, DisplayInfo* info) |
| 487 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 488 | if (uint32_t(dpy)>=NUM_DISPLAY_MAX) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 489 | return BAD_VALUE; |
| 490 | |
| 491 | volatile surface_flinger_cblk_t const * cblk = get_cblk(); |
| 492 | volatile display_cblk_t const * dcblk = cblk->displays + dpy; |
| 493 | |
| 494 | info->w = dcblk->w; |
| 495 | info->h = dcblk->h; |
| 496 | info->orientation = dcblk->orientation; |
| 497 | info->xdpi = dcblk->xdpi; |
| 498 | info->ydpi = dcblk->ydpi; |
| 499 | info->fps = dcblk->fps; |
| 500 | info->density = dcblk->density; |
| 501 | return getPixelFormatInfo(dcblk->format, &(info->pixelFormatInfo)); |
| 502 | } |
| 503 | |
| 504 | ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy) |
| 505 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 506 | if (uint32_t(dpy)>=NUM_DISPLAY_MAX) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 507 | return BAD_VALUE; |
| 508 | volatile surface_flinger_cblk_t const * cblk = get_cblk(); |
| 509 | volatile display_cblk_t const * dcblk = cblk->displays + dpy; |
| 510 | return dcblk->w; |
| 511 | } |
| 512 | |
| 513 | ssize_t SurfaceComposerClient::getDisplayHeight(DisplayID dpy) |
| 514 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 515 | if (uint32_t(dpy)>=NUM_DISPLAY_MAX) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | return BAD_VALUE; |
| 517 | volatile surface_flinger_cblk_t const * cblk = get_cblk(); |
| 518 | volatile display_cblk_t const * dcblk = cblk->displays + dpy; |
| 519 | return dcblk->h; |
| 520 | } |
| 521 | |
| 522 | ssize_t SurfaceComposerClient::getDisplayOrientation(DisplayID dpy) |
| 523 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 524 | if (uint32_t(dpy)>=NUM_DISPLAY_MAX) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 525 | return BAD_VALUE; |
| 526 | volatile surface_flinger_cblk_t const * cblk = get_cblk(); |
| 527 | volatile display_cblk_t const * dcblk = cblk->displays + dpy; |
| 528 | return dcblk->orientation; |
| 529 | } |
| 530 | |
| 531 | ssize_t SurfaceComposerClient::getNumberOfDisplays() |
| 532 | { |
| 533 | volatile surface_flinger_cblk_t const * cblk = get_cblk(); |
| 534 | uint32_t connected = cblk->connected; |
| 535 | int n = 0; |
| 536 | while (connected) { |
| 537 | if (connected&1) n++; |
| 538 | connected >>= 1; |
| 539 | } |
| 540 | return n; |
| 541 | } |
| 542 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 543 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 544 | |
| 545 | status_t SurfaceComposerClient::freezeDisplay(DisplayID dpy, uint32_t flags) |
| 546 | { |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 547 | // This has been made a no-op because it can cause Gralloc buffer deadlocks. |
| 548 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | status_t SurfaceComposerClient::unfreezeDisplay(DisplayID dpy, uint32_t flags) |
| 552 | { |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 553 | // This has been made a no-op because it can cause Gralloc buffer deadlocks. |
| 554 | return NO_ERROR; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | } |
| 556 | |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 557 | // ---------------------------------------------------------------------------- |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 558 | |
| 559 | ScreenshotClient::ScreenshotClient() |
| 560 | : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) { |
| 561 | } |
| 562 | |
| 563 | status_t ScreenshotClient::update() { |
| 564 | sp<ISurfaceComposer> s(ComposerService::getComposerService()); |
| 565 | if (s == NULL) return NO_INIT; |
| 566 | mHeap = 0; |
| 567 | return s->captureScreen(0, &mHeap, |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 568 | &mWidth, &mHeight, &mFormat, 0, 0, |
| 569 | 0, -1UL); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight) { |
| 573 | sp<ISurfaceComposer> s(ComposerService::getComposerService()); |
| 574 | if (s == NULL) return NO_INIT; |
| 575 | mHeap = 0; |
| 576 | return s->captureScreen(0, &mHeap, |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 577 | &mWidth, &mHeight, &mFormat, reqWidth, reqHeight, |
| 578 | 0, -1UL); |
| 579 | } |
| 580 | |
| 581 | status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight, |
| 582 | uint32_t minLayerZ, uint32_t maxLayerZ) { |
| 583 | sp<ISurfaceComposer> s(ComposerService::getComposerService()); |
| 584 | if (s == NULL) return NO_INIT; |
| 585 | mHeap = 0; |
| 586 | return s->captureScreen(0, &mHeap, |
| 587 | &mWidth, &mHeight, &mFormat, reqWidth, reqHeight, |
| 588 | minLayerZ, maxLayerZ); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 589 | } |
| 590 | |
| 591 | void ScreenshotClient::release() { |
| 592 | mHeap = 0; |
| 593 | } |
| 594 | |
| 595 | void const* ScreenshotClient::getPixels() const { |
| 596 | return mHeap->getBase(); |
| 597 | } |
| 598 | |
| 599 | uint32_t ScreenshotClient::getWidth() const { |
| 600 | return mWidth; |
| 601 | } |
| 602 | |
| 603 | uint32_t ScreenshotClient::getHeight() const { |
| 604 | return mHeight; |
| 605 | } |
| 606 | |
| 607 | PixelFormat ScreenshotClient::getFormat() const { |
| 608 | return mFormat; |
| 609 | } |
| 610 | |
| 611 | uint32_t ScreenshotClient::getStride() const { |
| 612 | return mWidth; |
| 613 | } |
| 614 | |
| 615 | size_t ScreenshotClient::getSize() const { |
| 616 | return mHeap->getSize(); |
| 617 | } |
| 618 | |
| 619 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 620 | }; // namespace android |