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