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