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); |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 124 | status_t setOrientation(int orientation); |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 125 | status_t setCrop(const sp<SurfaceComposerClient>& client, SurfaceID id, |
| 126 | const Rect& crop); |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 127 | status_t setLayerStack(const sp<SurfaceComposerClient>& client, |
| 128 | SurfaceID id, uint32_t layerStack); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 129 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 130 | static void closeGlobalTransaction(bool synchronous) { |
| 131 | Composer::getInstance().closeGlobalTransactionImpl(synchronous); |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 132 | } |
| 133 | }; |
| 134 | |
| 135 | ANDROID_SINGLETON_STATIC_INSTANCE(Composer); |
| 136 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 137 | // --------------------------------------------------------------------------- |
| 138 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 139 | void Composer::closeGlobalTransactionImpl(bool synchronous) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 140 | sp<ISurfaceComposer> sm(getComposerService()); |
| 141 | |
| 142 | Vector<ComposerState> transaction; |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 143 | Vector<DisplayState> displayTransaction; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 144 | uint32_t flags = 0; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 145 | |
| 146 | { // scope for the lock |
| 147 | Mutex::Autolock _l(mLock); |
| 148 | transaction = mStates; |
| 149 | mStates.clear(); |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 150 | |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 151 | // FIXME: this should be the displays transaction state here |
| 152 | DisplayState item; |
| 153 | item.orientation = mOrientation; |
| 154 | displayTransaction.add(item); |
| 155 | |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 156 | mOrientation = ISurfaceComposer::eOrientationUnchanged; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 157 | |
| 158 | if (synchronous || mForceSynchronous) { |
| 159 | flags |= ISurfaceComposer::eSynchronous; |
| 160 | } |
| 161 | mForceSynchronous = false; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 164 | sm->setTransactionState(transaction, displayTransaction, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 165 | } |
| 166 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 167 | layer_state_t* Composer::getLayerStateLocked( |
| 168 | const sp<SurfaceComposerClient>& client, SurfaceID id) { |
| 169 | |
| 170 | ComposerState s; |
| 171 | s.client = client->mClient; |
| 172 | s.state.surface = id; |
| 173 | |
| 174 | ssize_t index = mStates.indexOf(s); |
| 175 | if (index < 0) { |
| 176 | // we don't have it, add an initialized layer_state to our list |
| 177 | index = mStates.add(s); |
| 178 | } |
| 179 | |
| 180 | ComposerState* const out = mStates.editArray(); |
| 181 | return &(out[index].state); |
| 182 | } |
| 183 | |
| 184 | status_t Composer::setPosition(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | 41b6aab | 2011-08-30 18:51:54 -0700 | [diff] [blame] | 185 | SurfaceID id, float x, float y) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 186 | Mutex::Autolock _l(mLock); |
| 187 | layer_state_t* s = getLayerStateLocked(client, id); |
| 188 | if (!s) |
| 189 | return BAD_INDEX; |
| 190 | s->what |= ISurfaceComposer::ePositionChanged; |
| 191 | s->x = x; |
| 192 | s->y = y; |
| 193 | return NO_ERROR; |
| 194 | } |
| 195 | |
| 196 | status_t Composer::setSize(const sp<SurfaceComposerClient>& client, |
| 197 | SurfaceID id, uint32_t w, uint32_t h) { |
| 198 | Mutex::Autolock _l(mLock); |
| 199 | layer_state_t* s = getLayerStateLocked(client, id); |
| 200 | if (!s) |
| 201 | return BAD_INDEX; |
| 202 | s->what |= ISurfaceComposer::eSizeChanged; |
| 203 | s->w = w; |
| 204 | s->h = h; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 205 | |
| 206 | // Resizing a surface makes the transaction synchronous. |
| 207 | mForceSynchronous = true; |
| 208 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 209 | return NO_ERROR; |
| 210 | } |
| 211 | |
| 212 | status_t Composer::setLayer(const sp<SurfaceComposerClient>& client, |
| 213 | SurfaceID id, int32_t z) { |
| 214 | Mutex::Autolock _l(mLock); |
| 215 | layer_state_t* s = getLayerStateLocked(client, id); |
| 216 | if (!s) |
| 217 | return BAD_INDEX; |
| 218 | s->what |= ISurfaceComposer::eLayerChanged; |
| 219 | s->z = z; |
| 220 | return NO_ERROR; |
| 221 | } |
| 222 | |
| 223 | status_t Composer::setFlags(const sp<SurfaceComposerClient>& client, |
| 224 | SurfaceID id, uint32_t flags, |
| 225 | uint32_t mask) { |
| 226 | Mutex::Autolock _l(mLock); |
| 227 | layer_state_t* s = getLayerStateLocked(client, id); |
| 228 | if (!s) |
| 229 | return BAD_INDEX; |
| 230 | s->what |= ISurfaceComposer::eVisibilityChanged; |
| 231 | s->flags &= ~mask; |
| 232 | s->flags |= (flags & mask); |
| 233 | s->mask |= mask; |
| 234 | return NO_ERROR; |
| 235 | } |
| 236 | |
| 237 | status_t Composer::setTransparentRegionHint( |
| 238 | const sp<SurfaceComposerClient>& client, SurfaceID id, |
| 239 | const Region& transparentRegion) { |
| 240 | Mutex::Autolock _l(mLock); |
| 241 | layer_state_t* s = getLayerStateLocked(client, id); |
| 242 | if (!s) |
| 243 | return BAD_INDEX; |
| 244 | s->what |= ISurfaceComposer::eTransparentRegionChanged; |
| 245 | s->transparentRegion = transparentRegion; |
| 246 | return NO_ERROR; |
| 247 | } |
| 248 | |
| 249 | status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client, |
| 250 | SurfaceID id, float alpha) { |
| 251 | Mutex::Autolock _l(mLock); |
| 252 | layer_state_t* s = getLayerStateLocked(client, id); |
| 253 | if (!s) |
| 254 | return BAD_INDEX; |
| 255 | s->what |= ISurfaceComposer::eAlphaChanged; |
| 256 | s->alpha = alpha; |
| 257 | return NO_ERROR; |
| 258 | } |
| 259 | |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 260 | status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client, |
| 261 | SurfaceID id, uint32_t layerStack) { |
| 262 | Mutex::Autolock _l(mLock); |
| 263 | layer_state_t* s = getLayerStateLocked(client, id); |
| 264 | if (!s) |
| 265 | return BAD_INDEX; |
| 266 | s->what |= ISurfaceComposer::eLayerStackChanged; |
| 267 | s->layerStack = layerStack; |
| 268 | return NO_ERROR; |
| 269 | } |
| 270 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 271 | status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client, |
| 272 | SurfaceID id, float dsdx, float dtdx, |
| 273 | float dsdy, float dtdy) { |
| 274 | Mutex::Autolock _l(mLock); |
| 275 | layer_state_t* s = getLayerStateLocked(client, id); |
| 276 | if (!s) |
| 277 | return BAD_INDEX; |
| 278 | s->what |= ISurfaceComposer::eMatrixChanged; |
| 279 | layer_state_t::matrix22_t matrix; |
| 280 | matrix.dsdx = dsdx; |
| 281 | matrix.dtdx = dtdx; |
| 282 | matrix.dsdy = dsdy; |
| 283 | matrix.dtdy = dtdy; |
| 284 | s->matrix = matrix; |
| 285 | return NO_ERROR; |
| 286 | } |
| 287 | |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 288 | status_t Composer::setOrientation(int orientation) { |
| 289 | Mutex::Autolock _l(mLock); |
| 290 | mOrientation = orientation; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 291 | |
| 292 | // Changing the orientation makes the transaction synchronous. |
| 293 | mForceSynchronous = true; |
| 294 | |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 295 | return NO_ERROR; |
| 296 | } |
| 297 | |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 298 | status_t Composer::setCrop(const sp<SurfaceComposerClient>& client, |
| 299 | SurfaceID id, const Rect& crop) { |
| 300 | Mutex::Autolock _l(mLock); |
| 301 | layer_state_t* s = getLayerStateLocked(client, id); |
| 302 | if (!s) |
| 303 | return BAD_INDEX; |
| 304 | s->what |= ISurfaceComposer::eCropChanged; |
| 305 | s->crop = crop; |
| 306 | return NO_ERROR; |
| 307 | } |
| 308 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 309 | // --------------------------------------------------------------------------- |
| 310 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 311 | SurfaceComposerClient::SurfaceComposerClient() |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 312 | : mStatus(NO_INIT), mComposer(Composer::getInstance()) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 314 | } |
| 315 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 316 | void SurfaceComposerClient::onFirstRef() { |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 317 | sp<ISurfaceComposer> sm(getComposerService()); |
| 318 | if (sm != 0) { |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 319 | sp<ISurfaceComposerClient> conn = sm->createConnection(); |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 320 | if (conn != 0) { |
| 321 | mClient = conn; |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 322 | mStatus = NO_ERROR; |
| 323 | } |
| 324 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 325 | } |
| 326 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 327 | SurfaceComposerClient::~SurfaceComposerClient() { |
Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 328 | dispose(); |
| 329 | } |
Mathias Agopian | dd3423c | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 330 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 331 | status_t SurfaceComposerClient::initCheck() const { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | return mStatus; |
| 333 | } |
| 334 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 335 | sp<IBinder> SurfaceComposerClient::connection() const { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 336 | return (mClient != 0) ? mClient->asBinder() : 0; |
| 337 | } |
| 338 | |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 339 | status_t SurfaceComposerClient::linkToComposerDeath( |
| 340 | const sp<IBinder::DeathRecipient>& recipient, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 341 | void* cookie, uint32_t flags) { |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 342 | sp<ISurfaceComposer> sm(getComposerService()); |
| 343 | return sm->asBinder()->linkToDeath(recipient, cookie, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 344 | } |
| 345 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 346 | void SurfaceComposerClient::dispose() { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | // this can be called more than once. |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 348 | sp<ISurfaceComposerClient> client; |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 349 | Mutex::Autolock _lm(mLock); |
| 350 | if (mClient != 0) { |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 351 | client = mClient; // hold ref while lock is held |
| 352 | mClient.clear(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 353 | } |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 354 | mStatus = NO_INIT; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 355 | } |
| 356 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 357 | sp<SurfaceControl> SurfaceComposerClient::createSurface( |
| 358 | DisplayID display, |
| 359 | uint32_t w, |
| 360 | uint32_t h, |
| 361 | PixelFormat format, |
| 362 | uint32_t flags) |
| 363 | { |
| 364 | String8 name; |
| 365 | const size_t SIZE = 128; |
| 366 | char buffer[SIZE]; |
| 367 | snprintf(buffer, SIZE, "<pid_%d>", getpid()); |
| 368 | name.append(buffer); |
| 369 | |
| 370 | return SurfaceComposerClient::createSurface(name, display, |
| 371 | w, h, format, flags); |
| 372 | } |
| 373 | |
| 374 | sp<SurfaceControl> SurfaceComposerClient::createSurface( |
| 375 | const String8& name, |
| 376 | DisplayID display, |
| 377 | uint32_t w, |
| 378 | uint32_t h, |
| 379 | PixelFormat format, |
| 380 | uint32_t flags) |
| 381 | { |
| 382 | sp<SurfaceControl> result; |
| 383 | if (mStatus == NO_ERROR) { |
| 384 | ISurfaceComposerClient::surface_data_t data; |
| 385 | sp<ISurface> surface = mClient->createSurface(&data, name, |
| 386 | display, w, h, format, flags); |
| 387 | if (surface != 0) { |
Mathias Agopian | c10d9d9 | 2011-07-20 16:46:11 -0700 | [diff] [blame] | 388 | result = new SurfaceControl(this, surface, data); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 389 | } |
| 390 | } |
| 391 | return result; |
| 392 | } |
| 393 | |
| 394 | status_t SurfaceComposerClient::destroySurface(SurfaceID sid) { |
| 395 | if (mStatus != NO_ERROR) |
| 396 | return mStatus; |
| 397 | status_t err = mClient->destroySurface(sid); |
| 398 | return err; |
| 399 | } |
| 400 | |
| 401 | inline Composer& SurfaceComposerClient::getComposer() { |
| 402 | return mComposer; |
| 403 | } |
| 404 | |
| 405 | // ---------------------------------------------------------------------------- |
| 406 | |
| 407 | void SurfaceComposerClient::openGlobalTransaction() { |
| 408 | // Currently a no-op |
| 409 | } |
| 410 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 411 | void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) { |
| 412 | Composer::closeGlobalTransaction(synchronous); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | // ---------------------------------------------------------------------------- |
| 416 | |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 417 | status_t SurfaceComposerClient::setCrop(SurfaceID id, const Rect& crop) { |
| 418 | return getComposer().setCrop(this, id, crop); |
| 419 | } |
| 420 | |
Mathias Agopian | 41b6aab | 2011-08-30 18:51:54 -0700 | [diff] [blame] | 421 | status_t SurfaceComposerClient::setPosition(SurfaceID id, float x, float y) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 422 | return getComposer().setPosition(this, id, x, y); |
| 423 | } |
| 424 | |
| 425 | status_t SurfaceComposerClient::setSize(SurfaceID id, uint32_t w, uint32_t h) { |
| 426 | return getComposer().setSize(this, id, w, h); |
| 427 | } |
| 428 | |
| 429 | status_t SurfaceComposerClient::setLayer(SurfaceID id, int32_t z) { |
| 430 | return getComposer().setLayer(this, id, z); |
| 431 | } |
| 432 | |
| 433 | status_t SurfaceComposerClient::hide(SurfaceID id) { |
| 434 | return getComposer().setFlags(this, id, |
| 435 | ISurfaceComposer::eLayerHidden, |
| 436 | ISurfaceComposer::eLayerHidden); |
| 437 | } |
| 438 | |
| 439 | status_t SurfaceComposerClient::show(SurfaceID id, int32_t) { |
| 440 | return getComposer().setFlags(this, id, |
| 441 | 0, |
| 442 | ISurfaceComposer::eLayerHidden); |
| 443 | } |
| 444 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 445 | status_t SurfaceComposerClient::setFlags(SurfaceID id, uint32_t flags, |
| 446 | uint32_t mask) { |
| 447 | return getComposer().setFlags(this, id, flags, mask); |
| 448 | } |
| 449 | |
| 450 | status_t SurfaceComposerClient::setTransparentRegionHint(SurfaceID id, |
| 451 | const Region& transparentRegion) { |
| 452 | return getComposer().setTransparentRegionHint(this, id, transparentRegion); |
| 453 | } |
| 454 | |
| 455 | status_t SurfaceComposerClient::setAlpha(SurfaceID id, float alpha) { |
| 456 | return getComposer().setAlpha(this, id, alpha); |
| 457 | } |
| 458 | |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 459 | status_t SurfaceComposerClient::setLayerStack(SurfaceID id, uint32_t layerStack) { |
| 460 | return getComposer().setLayerStack(this, id, layerStack); |
| 461 | } |
| 462 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 463 | status_t SurfaceComposerClient::setMatrix(SurfaceID id, float dsdx, float dtdx, |
| 464 | float dsdy, float dtdy) { |
| 465 | return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy); |
| 466 | } |
| 467 | |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 468 | status_t SurfaceComposerClient::setOrientation(DisplayID dpy, |
| 469 | int orientation, uint32_t flags) |
| 470 | { |
| 471 | return Composer::getInstance().setOrientation(orientation); |
| 472 | } |
| 473 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 474 | // ---------------------------------------------------------------------------- |
| 475 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | status_t SurfaceComposerClient::getDisplayInfo( |
| 477 | DisplayID dpy, DisplayInfo* info) |
| 478 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 479 | if (uint32_t(dpy)>=NUM_DISPLAY_MAX) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 480 | return BAD_VALUE; |
| 481 | |
| 482 | volatile surface_flinger_cblk_t const * cblk = get_cblk(); |
| 483 | volatile display_cblk_t const * dcblk = cblk->displays + dpy; |
| 484 | |
| 485 | info->w = dcblk->w; |
| 486 | info->h = dcblk->h; |
| 487 | info->orientation = dcblk->orientation; |
| 488 | info->xdpi = dcblk->xdpi; |
| 489 | info->ydpi = dcblk->ydpi; |
| 490 | info->fps = dcblk->fps; |
| 491 | info->density = dcblk->density; |
| 492 | return getPixelFormatInfo(dcblk->format, &(info->pixelFormatInfo)); |
| 493 | } |
| 494 | |
| 495 | ssize_t SurfaceComposerClient::getDisplayWidth(DisplayID dpy) |
| 496 | { |
Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 497 | if (uint32_t(dpy)>=NUM_DISPLAY_MAX) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | return BAD_VALUE; |
| 499 | volatile surface_flinger_cblk_t const * cblk = get_cblk(); |
| 500 | volatile display_cblk_t const * dcblk = cblk->displays + dpy; |
| 501 | return dcblk->w; |
| 502 | } |
| 503 | |
| 504 | ssize_t SurfaceComposerClient::getDisplayHeight(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->h; |
| 511 | } |
| 512 | |
| 513 | ssize_t SurfaceComposerClient::getDisplayOrientation(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->orientation; |
| 520 | } |
| 521 | |
| 522 | ssize_t SurfaceComposerClient::getNumberOfDisplays() |
| 523 | { |
| 524 | volatile surface_flinger_cblk_t const * cblk = get_cblk(); |
| 525 | uint32_t connected = cblk->connected; |
| 526 | int n = 0; |
| 527 | while (connected) { |
| 528 | if (connected&1) n++; |
| 529 | connected >>= 1; |
| 530 | } |
| 531 | return n; |
| 532 | } |
| 533 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 534 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 535 | |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 536 | ScreenshotClient::ScreenshotClient() |
| 537 | : mWidth(0), mHeight(0), mFormat(PIXEL_FORMAT_NONE) { |
| 538 | } |
| 539 | |
| 540 | status_t ScreenshotClient::update() { |
| 541 | sp<ISurfaceComposer> s(ComposerService::getComposerService()); |
| 542 | if (s == NULL) return NO_INIT; |
| 543 | mHeap = 0; |
| 544 | return s->captureScreen(0, &mHeap, |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 545 | &mWidth, &mHeight, &mFormat, 0, 0, |
| 546 | 0, -1UL); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight) { |
| 550 | sp<ISurfaceComposer> s(ComposerService::getComposerService()); |
| 551 | if (s == NULL) return NO_INIT; |
| 552 | mHeap = 0; |
| 553 | return s->captureScreen(0, &mHeap, |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 554 | &mWidth, &mHeight, &mFormat, reqWidth, reqHeight, |
| 555 | 0, -1UL); |
| 556 | } |
| 557 | |
| 558 | status_t ScreenshotClient::update(uint32_t reqWidth, uint32_t reqHeight, |
| 559 | uint32_t minLayerZ, uint32_t maxLayerZ) { |
| 560 | sp<ISurfaceComposer> s(ComposerService::getComposerService()); |
| 561 | if (s == NULL) return NO_INIT; |
| 562 | mHeap = 0; |
| 563 | return s->captureScreen(0, &mHeap, |
| 564 | &mWidth, &mHeight, &mFormat, reqWidth, reqHeight, |
| 565 | minLayerZ, maxLayerZ); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 566 | } |
| 567 | |
| 568 | void ScreenshotClient::release() { |
| 569 | mHeap = 0; |
| 570 | } |
| 571 | |
| 572 | void const* ScreenshotClient::getPixels() const { |
| 573 | return mHeap->getBase(); |
| 574 | } |
| 575 | |
| 576 | uint32_t ScreenshotClient::getWidth() const { |
| 577 | return mWidth; |
| 578 | } |
| 579 | |
| 580 | uint32_t ScreenshotClient::getHeight() const { |
| 581 | return mHeight; |
| 582 | } |
| 583 | |
| 584 | PixelFormat ScreenshotClient::getFormat() const { |
| 585 | return mFormat; |
| 586 | } |
| 587 | |
| 588 | uint32_t ScreenshotClient::getStride() const { |
| 589 | return mWidth; |
| 590 | } |
| 591 | |
| 592 | size_t ScreenshotClient::getSize() const { |
| 593 | return mHeap->getSize(); |
| 594 | } |
| 595 | |
| 596 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | }; // namespace android |