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