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