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 | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 34 | #include <gui/CpuConsumer.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 35 | #include <gui/IGraphicBufferProducer.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 36 | #include <gui/ISurfaceComposer.h> |
| 37 | #include <gui/ISurfaceComposerClient.h> |
| 38 | #include <gui/SurfaceComposerClient.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | |
Mathias Agopian | 41f673c | 2011-11-17 17:48:35 -0800 | [diff] [blame] | 40 | #include <private/gui/ComposerService.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 41 | #include <private/gui/LayerState.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
| 43 | namespace android { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | // --------------------------------------------------------------------------- |
| 45 | |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 46 | ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService); |
| 47 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 48 | ComposerService::ComposerService() |
| 49 | : Singleton<ComposerService>() { |
Andy McFadden | 6652b3e | 2012-09-06 18:45:56 -0700 | [diff] [blame] | 50 | Mutex::Autolock _l(mLock); |
| 51 | connectLocked(); |
| 52 | } |
| 53 | |
| 54 | void ComposerService::connectLocked() { |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 55 | const String16 name("SurfaceFlinger"); |
| 56 | while (getService(name, &mComposerService) != NO_ERROR) { |
| 57 | usleep(250000); |
| 58 | } |
Andy McFadden | 6652b3e | 2012-09-06 18:45:56 -0700 | [diff] [blame] | 59 | assert(mComposerService != NULL); |
| 60 | |
| 61 | // Create the death listener. |
| 62 | class DeathObserver : public IBinder::DeathRecipient { |
| 63 | ComposerService& mComposerService; |
| 64 | virtual void binderDied(const wp<IBinder>& who) { |
| 65 | ALOGW("ComposerService remote (surfaceflinger) died [%p]", |
| 66 | who.unsafe_get()); |
| 67 | mComposerService.composerServiceDied(); |
| 68 | } |
| 69 | public: |
| 70 | DeathObserver(ComposerService& mgr) : mComposerService(mgr) { } |
| 71 | }; |
| 72 | |
| 73 | mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this)); |
| 74 | mComposerService->asBinder()->linkToDeath(mDeathObserver); |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 75 | } |
| 76 | |
Andy McFadden | 6652b3e | 2012-09-06 18:45:56 -0700 | [diff] [blame] | 77 | /*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() { |
| 78 | ComposerService& instance = ComposerService::getInstance(); |
| 79 | Mutex::Autolock _l(instance.mLock); |
| 80 | if (instance.mComposerService == NULL) { |
| 81 | ComposerService::getInstance().connectLocked(); |
| 82 | assert(instance.mComposerService != NULL); |
| 83 | ALOGD("ComposerService reconnected"); |
| 84 | } |
| 85 | return instance.mComposerService; |
| 86 | } |
| 87 | |
| 88 | void ComposerService::composerServiceDied() |
| 89 | { |
| 90 | Mutex::Autolock _l(mLock); |
| 91 | mComposerService = NULL; |
| 92 | mDeathObserver = NULL; |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 93 | } |
| 94 | |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 95 | // --------------------------------------------------------------------------- |
| 96 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 97 | static inline |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 98 | int compare_type(const ComposerState& lhs, const ComposerState& rhs) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 99 | if (lhs.client < rhs.client) return -1; |
| 100 | if (lhs.client > rhs.client) return 1; |
| 101 | if (lhs.state.surface < rhs.state.surface) return -1; |
| 102 | if (lhs.state.surface > rhs.state.surface) return 1; |
| 103 | return 0; |
| 104 | } |
| 105 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 106 | static inline |
| 107 | int compare_type(const DisplayState& lhs, const DisplayState& rhs) { |
| 108 | return compare_type(lhs.token, rhs.token); |
| 109 | } |
| 110 | |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 111 | class Composer : public Singleton<Composer> |
| 112 | { |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 113 | friend class Singleton<Composer>; |
| 114 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 115 | mutable Mutex mLock; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 116 | SortedVector<ComposerState> mComposerStates; |
| 117 | SortedVector<DisplayState > mDisplayStates; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 118 | uint32_t mForceSynchronous; |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 119 | uint32_t mTransactionNestCount; |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 120 | bool mAnimation; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 121 | |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 122 | Composer() : Singleton<Composer>(), |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 123 | mForceSynchronous(0), mTransactionNestCount(0), |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 124 | mAnimation(false) |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 125 | { } |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 126 | |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 127 | void openGlobalTransactionImpl(); |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 128 | void closeGlobalTransactionImpl(bool synchronous); |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 129 | void setAnimationTransactionImpl(); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 130 | |
| 131 | layer_state_t* getLayerStateLocked( |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 132 | const sp<SurfaceComposerClient>& client, const sp<IBinder>& id); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 133 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 134 | DisplayState& getDisplayStateLocked(const sp<IBinder>& token); |
| 135 | |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 136 | public: |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 137 | sp<IBinder> createDisplay(const String8& displayName, bool secure); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 138 | void destroyDisplay(const sp<IBinder>& display); |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 139 | sp<IBinder> getBuiltInDisplay(int32_t id); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 140 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 141 | status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 41b6aab | 2011-08-30 18:51:54 -0700 | [diff] [blame] | 142 | float x, float y); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 143 | status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 144 | uint32_t w, uint32_t h); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 145 | status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 146 | int32_t z); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 147 | status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 148 | uint32_t flags, uint32_t mask); |
| 149 | status_t setTransparentRegionHint( |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 150 | const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 151 | const Region& transparentRegion); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 152 | status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 153 | float alpha); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 154 | status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 155 | float dsdx, float dtdx, float dsdy, float dtdy); |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 156 | status_t setOrientation(int orientation); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 157 | status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 158 | const Rect& crop); |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 159 | status_t setLayerStack(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 160 | const sp<IBinder>& id, uint32_t layerStack); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 161 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 162 | void setDisplaySurface(const sp<IBinder>& token, |
| 163 | const sp<IGraphicBufferProducer>& bufferProducer); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 164 | void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack); |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 165 | void setDisplayProjection(const sp<IBinder>& token, |
| 166 | uint32_t orientation, |
| 167 | const Rect& layerStackRect, |
| 168 | const Rect& displayRect); |
Michael Wright | 1f6078a | 2014-06-26 16:01:02 -0700 | [diff] [blame] | 169 | void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 170 | |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 171 | static void setAnimationTransaction() { |
| 172 | Composer::getInstance().setAnimationTransactionImpl(); |
| 173 | } |
| 174 | |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 175 | static void openGlobalTransaction() { |
| 176 | Composer::getInstance().openGlobalTransactionImpl(); |
| 177 | } |
| 178 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 179 | static void closeGlobalTransaction(bool synchronous) { |
| 180 | Composer::getInstance().closeGlobalTransactionImpl(synchronous); |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 181 | } |
| 182 | }; |
| 183 | |
| 184 | ANDROID_SINGLETON_STATIC_INSTANCE(Composer); |
| 185 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 186 | // --------------------------------------------------------------------------- |
| 187 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 188 | sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) { |
| 189 | return ComposerService::getComposerService()->createDisplay(displayName, |
| 190 | secure); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 193 | void Composer::destroyDisplay(const sp<IBinder>& display) { |
| 194 | return ComposerService::getComposerService()->destroyDisplay(display); |
| 195 | } |
| 196 | |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 197 | sp<IBinder> Composer::getBuiltInDisplay(int32_t id) { |
| 198 | return ComposerService::getComposerService()->getBuiltInDisplay(id); |
| 199 | } |
| 200 | |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 201 | void Composer::openGlobalTransactionImpl() { |
| 202 | { // scope for the lock |
| 203 | Mutex::Autolock _l(mLock); |
| 204 | mTransactionNestCount += 1; |
| 205 | } |
| 206 | } |
| 207 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 208 | void Composer::closeGlobalTransactionImpl(bool synchronous) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 209 | sp<ISurfaceComposer> sm(ComposerService::getComposerService()); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 210 | |
| 211 | Vector<ComposerState> transaction; |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 212 | Vector<DisplayState> displayTransaction; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 213 | uint32_t flags = 0; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 214 | |
| 215 | { // scope for the lock |
| 216 | Mutex::Autolock _l(mLock); |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 217 | mForceSynchronous |= synchronous; |
| 218 | if (!mTransactionNestCount) { |
| 219 | ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior " |
| 220 | "call to openGlobalTransaction()."); |
| 221 | } else if (--mTransactionNestCount) { |
| 222 | return; |
| 223 | } |
| 224 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 225 | transaction = mComposerStates; |
| 226 | mComposerStates.clear(); |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 227 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 228 | displayTransaction = mDisplayStates; |
| 229 | mDisplayStates.clear(); |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 230 | |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 231 | if (mForceSynchronous) { |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 232 | flags |= ISurfaceComposer::eSynchronous; |
| 233 | } |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 234 | if (mAnimation) { |
| 235 | flags |= ISurfaceComposer::eAnimation; |
| 236 | } |
| 237 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 238 | mForceSynchronous = false; |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 239 | mAnimation = false; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 242 | sm->setTransactionState(transaction, displayTransaction, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 245 | void Composer::setAnimationTransactionImpl() { |
| 246 | Mutex::Autolock _l(mLock); |
| 247 | mAnimation = true; |
| 248 | } |
| 249 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 250 | layer_state_t* Composer::getLayerStateLocked( |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 251 | const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 252 | |
| 253 | ComposerState s; |
| 254 | s.client = client->mClient; |
| 255 | s.state.surface = id; |
| 256 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 257 | ssize_t index = mComposerStates.indexOf(s); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 258 | if (index < 0) { |
| 259 | // we don't have it, add an initialized layer_state to our list |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 260 | index = mComposerStates.add(s); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 263 | ComposerState* const out = mComposerStates.editArray(); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 264 | return &(out[index].state); |
| 265 | } |
| 266 | |
| 267 | status_t Composer::setPosition(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 268 | const sp<IBinder>& id, float x, float y) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 269 | Mutex::Autolock _l(mLock); |
| 270 | layer_state_t* s = getLayerStateLocked(client, id); |
| 271 | if (!s) |
| 272 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 273 | s->what |= layer_state_t::ePositionChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 274 | s->x = x; |
| 275 | s->y = y; |
| 276 | return NO_ERROR; |
| 277 | } |
| 278 | |
| 279 | status_t Composer::setSize(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 280 | const sp<IBinder>& id, uint32_t w, uint32_t h) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 281 | Mutex::Autolock _l(mLock); |
| 282 | layer_state_t* s = getLayerStateLocked(client, id); |
| 283 | if (!s) |
| 284 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 285 | s->what |= layer_state_t::eSizeChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 286 | s->w = w; |
| 287 | s->h = h; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 288 | |
| 289 | // Resizing a surface makes the transaction synchronous. |
| 290 | mForceSynchronous = true; |
| 291 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 292 | return NO_ERROR; |
| 293 | } |
| 294 | |
| 295 | status_t Composer::setLayer(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 296 | const sp<IBinder>& id, int32_t z) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 297 | Mutex::Autolock _l(mLock); |
| 298 | layer_state_t* s = getLayerStateLocked(client, id); |
| 299 | if (!s) |
| 300 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 301 | s->what |= layer_state_t::eLayerChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 302 | s->z = z; |
| 303 | return NO_ERROR; |
| 304 | } |
| 305 | |
| 306 | status_t Composer::setFlags(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 307 | const sp<IBinder>& id, uint32_t flags, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 308 | uint32_t mask) { |
| 309 | Mutex::Autolock _l(mLock); |
| 310 | layer_state_t* s = getLayerStateLocked(client, id); |
| 311 | if (!s) |
| 312 | return BAD_INDEX; |
Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 313 | if (mask & layer_state_t::eLayerOpaque) { |
| 314 | s->what |= layer_state_t::eOpacityChanged; |
| 315 | } |
| 316 | if (mask & layer_state_t::eLayerHidden) { |
| 317 | s->what |= layer_state_t::eVisibilityChanged; |
| 318 | } |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 319 | s->flags &= ~mask; |
| 320 | s->flags |= (flags & mask); |
| 321 | s->mask |= mask; |
| 322 | return NO_ERROR; |
| 323 | } |
| 324 | |
| 325 | status_t Composer::setTransparentRegionHint( |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 326 | const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 327 | const Region& transparentRegion) { |
| 328 | Mutex::Autolock _l(mLock); |
| 329 | layer_state_t* s = getLayerStateLocked(client, id); |
| 330 | if (!s) |
| 331 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 332 | s->what |= layer_state_t::eTransparentRegionChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 333 | s->transparentRegion = transparentRegion; |
| 334 | return NO_ERROR; |
| 335 | } |
| 336 | |
| 337 | status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 338 | const sp<IBinder>& id, float alpha) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 339 | Mutex::Autolock _l(mLock); |
| 340 | layer_state_t* s = getLayerStateLocked(client, id); |
| 341 | if (!s) |
| 342 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 343 | s->what |= layer_state_t::eAlphaChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 344 | s->alpha = alpha; |
| 345 | return NO_ERROR; |
| 346 | } |
| 347 | |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 348 | status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 349 | const sp<IBinder>& id, uint32_t layerStack) { |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 350 | Mutex::Autolock _l(mLock); |
| 351 | layer_state_t* s = getLayerStateLocked(client, id); |
| 352 | if (!s) |
| 353 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 354 | s->what |= layer_state_t::eLayerStackChanged; |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 355 | s->layerStack = layerStack; |
| 356 | return NO_ERROR; |
| 357 | } |
| 358 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 359 | status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 360 | const sp<IBinder>& id, float dsdx, float dtdx, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 361 | float dsdy, float dtdy) { |
| 362 | Mutex::Autolock _l(mLock); |
| 363 | layer_state_t* s = getLayerStateLocked(client, id); |
| 364 | if (!s) |
| 365 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 366 | s->what |= layer_state_t::eMatrixChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 367 | layer_state_t::matrix22_t matrix; |
| 368 | matrix.dsdx = dsdx; |
| 369 | matrix.dtdx = dtdx; |
| 370 | matrix.dsdy = dsdy; |
| 371 | matrix.dtdy = dtdy; |
| 372 | s->matrix = matrix; |
| 373 | return NO_ERROR; |
| 374 | } |
| 375 | |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 376 | status_t Composer::setCrop(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 377 | const sp<IBinder>& id, const Rect& crop) { |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 378 | Mutex::Autolock _l(mLock); |
| 379 | layer_state_t* s = getLayerStateLocked(client, id); |
| 380 | if (!s) |
| 381 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 382 | s->what |= layer_state_t::eCropChanged; |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 383 | s->crop = crop; |
| 384 | return NO_ERROR; |
| 385 | } |
| 386 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 387 | // --------------------------------------------------------------------------- |
| 388 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 389 | DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) { |
| 390 | DisplayState s; |
| 391 | s.token = token; |
| 392 | ssize_t index = mDisplayStates.indexOf(s); |
| 393 | if (index < 0) { |
| 394 | // we don't have it, add an initialized layer_state to our list |
| 395 | s.what = 0; |
| 396 | index = mDisplayStates.add(s); |
| 397 | } |
| 398 | return mDisplayStates.editItemAt(index); |
| 399 | } |
| 400 | |
| 401 | void Composer::setDisplaySurface(const sp<IBinder>& token, |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 402 | const sp<IGraphicBufferProducer>& bufferProducer) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 403 | Mutex::Autolock _l(mLock); |
| 404 | DisplayState& s(getDisplayStateLocked(token)); |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 405 | s.surface = bufferProducer; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 406 | s.what |= DisplayState::eSurfaceChanged; |
| 407 | } |
| 408 | |
| 409 | void Composer::setDisplayLayerStack(const sp<IBinder>& token, |
| 410 | uint32_t layerStack) { |
| 411 | Mutex::Autolock _l(mLock); |
| 412 | DisplayState& s(getDisplayStateLocked(token)); |
| 413 | s.layerStack = layerStack; |
| 414 | s.what |= DisplayState::eLayerStackChanged; |
| 415 | } |
| 416 | |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 417 | void Composer::setDisplayProjection(const sp<IBinder>& token, |
| 418 | uint32_t orientation, |
| 419 | const Rect& layerStackRect, |
| 420 | const Rect& displayRect) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 421 | Mutex::Autolock _l(mLock); |
| 422 | DisplayState& s(getDisplayStateLocked(token)); |
| 423 | s.orientation = orientation; |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 424 | s.viewport = layerStackRect; |
| 425 | s.frame = displayRect; |
| 426 | s.what |= DisplayState::eDisplayProjectionChanged; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 427 | mForceSynchronous = true; // TODO: do we actually still need this? |
| 428 | } |
| 429 | |
Michael Wright | 1f6078a | 2014-06-26 16:01:02 -0700 | [diff] [blame] | 430 | void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) { |
| 431 | Mutex::Autolock _l(mLock); |
| 432 | DisplayState& s(getDisplayStateLocked(token)); |
| 433 | s.width = width; |
| 434 | s.height = height; |
| 435 | s.what |= DisplayState::eDisplaySizeChanged; |
| 436 | } |
| 437 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 438 | // --------------------------------------------------------------------------- |
| 439 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 440 | SurfaceComposerClient::SurfaceComposerClient() |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 441 | : mStatus(NO_INIT), mComposer(Composer::getInstance()) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 442 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | } |
| 444 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 445 | void SurfaceComposerClient::onFirstRef() { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 446 | sp<ISurfaceComposer> sm(ComposerService::getComposerService()); |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 447 | if (sm != 0) { |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 448 | sp<ISurfaceComposerClient> conn = sm->createConnection(); |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 449 | if (conn != 0) { |
| 450 | mClient = conn; |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 451 | mStatus = NO_ERROR; |
| 452 | } |
| 453 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 454 | } |
| 455 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 456 | SurfaceComposerClient::~SurfaceComposerClient() { |
Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 457 | dispose(); |
| 458 | } |
Mathias Agopian | dd3423c | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 459 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 460 | status_t SurfaceComposerClient::initCheck() const { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 461 | return mStatus; |
| 462 | } |
| 463 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 464 | sp<IBinder> SurfaceComposerClient::connection() const { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 465 | return (mClient != 0) ? mClient->asBinder() : 0; |
| 466 | } |
| 467 | |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 468 | status_t SurfaceComposerClient::linkToComposerDeath( |
| 469 | const sp<IBinder::DeathRecipient>& recipient, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 470 | void* cookie, uint32_t flags) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 471 | sp<ISurfaceComposer> sm(ComposerService::getComposerService()); |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 472 | return sm->asBinder()->linkToDeath(recipient, cookie, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 473 | } |
| 474 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 475 | void SurfaceComposerClient::dispose() { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 476 | // this can be called more than once. |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 477 | sp<ISurfaceComposerClient> client; |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 478 | Mutex::Autolock _lm(mLock); |
| 479 | if (mClient != 0) { |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 480 | client = mClient; // hold ref while lock is held |
| 481 | mClient.clear(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 482 | } |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 483 | mStatus = NO_INIT; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 484 | } |
| 485 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 486 | sp<SurfaceControl> SurfaceComposerClient::createSurface( |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 487 | const String8& name, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 488 | uint32_t w, |
| 489 | uint32_t h, |
| 490 | PixelFormat format, |
| 491 | uint32_t flags) |
| 492 | { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 493 | sp<SurfaceControl> sur; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 494 | if (mStatus == NO_ERROR) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 495 | sp<IBinder> handle; |
| 496 | sp<IGraphicBufferProducer> gbp; |
| 497 | status_t err = mClient->createSurface(name, w, h, format, flags, |
| 498 | &handle, &gbp); |
| 499 | ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err)); |
| 500 | if (err == NO_ERROR) { |
| 501 | sur = new SurfaceControl(this, handle, gbp); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 502 | } |
| 503 | } |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 504 | return sur; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 507 | sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, |
| 508 | bool secure) { |
| 509 | return Composer::getInstance().createDisplay(displayName, secure); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 510 | } |
| 511 | |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 512 | void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) { |
| 513 | Composer::getInstance().destroyDisplay(display); |
| 514 | } |
| 515 | |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 516 | sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) { |
| 517 | return Composer::getInstance().getBuiltInDisplay(id); |
| 518 | } |
| 519 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 520 | status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 521 | if (mStatus != NO_ERROR) |
| 522 | return mStatus; |
| 523 | status_t err = mClient->destroySurface(sid); |
| 524 | return err; |
| 525 | } |
| 526 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 527 | status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const { |
| 528 | if (mStatus != NO_ERROR) { |
| 529 | return mStatus; |
| 530 | } |
| 531 | return mClient->clearLayerFrameStats(token); |
| 532 | } |
| 533 | |
| 534 | status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token, |
| 535 | FrameStats* outStats) const { |
| 536 | if (mStatus != NO_ERROR) { |
| 537 | return mStatus; |
| 538 | } |
| 539 | return mClient->getLayerFrameStats(token, outStats); |
| 540 | } |
| 541 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 542 | inline Composer& SurfaceComposerClient::getComposer() { |
| 543 | return mComposer; |
| 544 | } |
| 545 | |
| 546 | // ---------------------------------------------------------------------------- |
| 547 | |
| 548 | void SurfaceComposerClient::openGlobalTransaction() { |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 549 | Composer::openGlobalTransaction(); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 550 | } |
| 551 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 552 | void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) { |
| 553 | Composer::closeGlobalTransaction(synchronous); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 554 | } |
| 555 | |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 556 | void SurfaceComposerClient::setAnimationTransaction() { |
| 557 | Composer::setAnimationTransaction(); |
| 558 | } |
| 559 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 560 | // ---------------------------------------------------------------------------- |
| 561 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 562 | status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) { |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 563 | return getComposer().setCrop(this, id, crop); |
| 564 | } |
| 565 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 566 | status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 567 | return getComposer().setPosition(this, id, x, y); |
| 568 | } |
| 569 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 570 | status_t SurfaceComposerClient::setSize(const sp<IBinder>& id, uint32_t w, uint32_t h) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 571 | return getComposer().setSize(this, id, w, h); |
| 572 | } |
| 573 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 574 | status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, int32_t z) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 575 | return getComposer().setLayer(this, id, z); |
| 576 | } |
| 577 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 578 | status_t SurfaceComposerClient::hide(const sp<IBinder>& id) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 579 | return getComposer().setFlags(this, id, |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 580 | layer_state_t::eLayerHidden, |
| 581 | layer_state_t::eLayerHidden); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 582 | } |
| 583 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 584 | status_t SurfaceComposerClient::show(const sp<IBinder>& id) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 585 | return getComposer().setFlags(this, id, |
| 586 | 0, |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 587 | layer_state_t::eLayerHidden); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 590 | status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 591 | uint32_t mask) { |
| 592 | return getComposer().setFlags(this, id, flags, mask); |
| 593 | } |
| 594 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 595 | status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 596 | const Region& transparentRegion) { |
| 597 | return getComposer().setTransparentRegionHint(this, id, transparentRegion); |
| 598 | } |
| 599 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 600 | status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 601 | return getComposer().setAlpha(this, id, alpha); |
| 602 | } |
| 603 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 604 | status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) { |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 605 | return getComposer().setLayerStack(this, id, layerStack); |
| 606 | } |
| 607 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 608 | status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 609 | float dsdy, float dtdy) { |
| 610 | return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy); |
| 611 | } |
| 612 | |
| 613 | // ---------------------------------------------------------------------------- |
| 614 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 615 | void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token, |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 616 | const sp<IGraphicBufferProducer>& bufferProducer) { |
| 617 | Composer::getInstance().setDisplaySurface(token, bufferProducer); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token, |
| 621 | uint32_t layerStack) { |
| 622 | Composer::getInstance().setDisplayLayerStack(token, layerStack); |
| 623 | } |
| 624 | |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 625 | void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token, |
| 626 | uint32_t orientation, |
| 627 | const Rect& layerStackRect, |
| 628 | const Rect& displayRect) { |
| 629 | Composer::getInstance().setDisplayProjection(token, orientation, |
| 630 | layerStackRect, displayRect); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 631 | } |
| 632 | |
Michael Wright | 1f6078a | 2014-06-26 16:01:02 -0700 | [diff] [blame] | 633 | void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token, |
| 634 | uint32_t width, uint32_t height) { |
| 635 | Composer::getInstance().setDisplaySize(token, width, height); |
| 636 | } |
| 637 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 638 | // ---------------------------------------------------------------------------- |
| 639 | |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 640 | status_t SurfaceComposerClient::getDisplayConfigs( |
| 641 | const sp<IBinder>& display, Vector<DisplayInfo>* configs) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 642 | { |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 643 | return ComposerService::getComposerService()->getDisplayConfigs(display, configs); |
| 644 | } |
| 645 | |
| 646 | status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display, |
| 647 | DisplayInfo* info) { |
| 648 | Vector<DisplayInfo> configs; |
| 649 | status_t result = getDisplayConfigs(display, &configs); |
| 650 | if (result != NO_ERROR) { |
| 651 | return result; |
| 652 | } |
| 653 | |
| 654 | int activeId = getActiveConfig(display); |
| 655 | if (activeId < 0) { |
| 656 | ALOGE("No active configuration found"); |
| 657 | return NAME_NOT_FOUND; |
| 658 | } |
| 659 | |
| 660 | *info = configs[activeId]; |
| 661 | return NO_ERROR; |
| 662 | } |
| 663 | |
| 664 | int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) { |
| 665 | return ComposerService::getComposerService()->getActiveConfig(display); |
| 666 | } |
| 667 | |
| 668 | status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) { |
| 669 | return ComposerService::getComposerService()->setActiveConfig(display, id); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 670 | } |
| 671 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 672 | void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token, |
| 673 | int mode) { |
| 674 | ComposerService::getComposerService()->setPowerMode(token, mode); |
Jeff Brown | 2a09bb3 | 2012-10-08 19:13:57 -0700 | [diff] [blame] | 675 | } |
| 676 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 677 | status_t SurfaceComposerClient::clearAnimationFrameStats() { |
| 678 | return ComposerService::getComposerService()->clearAnimationFrameStats(); |
| 679 | } |
| 680 | |
| 681 | status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) { |
| 682 | return ComposerService::getComposerService()->getAnimationFrameStats(outStats); |
| 683 | } |
| 684 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 685 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 686 | |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 687 | status_t ScreenshotClient::capture( |
| 688 | const sp<IBinder>& display, |
| 689 | const sp<IGraphicBufferProducer>& producer, |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 690 | Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 691 | uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) { |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 692 | sp<ISurfaceComposer> s(ComposerService::getComposerService()); |
| 693 | if (s == NULL) return NO_INIT; |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 694 | return s->captureScreen(display, producer, sourceCrop, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 695 | reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 696 | } |
| 697 | |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 698 | ScreenshotClient::ScreenshotClient() |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 699 | : mHaveBuffer(false) { |
| 700 | memset(&mBuffer, 0, sizeof(mBuffer)); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 701 | } |
| 702 | |
Mathias Agopian | 8000d06 | 2013-03-26 18:15:35 -0700 | [diff] [blame] | 703 | ScreenshotClient::~ScreenshotClient() { |
| 704 | ScreenshotClient::release(); |
| 705 | } |
| 706 | |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 707 | sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const { |
| 708 | if (mCpuConsumer == NULL) { |
Dan Stoza | 6d5a7bb | 2014-03-13 11:39:09 -0700 | [diff] [blame] | 709 | sp<IGraphicBufferConsumer> consumer; |
| 710 | BufferQueue::createBufferQueue(&mProducer, &consumer); |
| 711 | mCpuConsumer = new CpuConsumer(consumer, 1); |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 712 | mCpuConsumer->setName(String8("ScreenshotClient")); |
| 713 | } |
| 714 | return mCpuConsumer; |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 715 | } |
| 716 | |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 717 | status_t ScreenshotClient::update(const sp<IBinder>& display, |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 718 | Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 719 | uint32_t minLayerZ, uint32_t maxLayerZ, |
| 720 | bool useIdentityTransform) { |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 721 | sp<ISurfaceComposer> s(ComposerService::getComposerService()); |
| 722 | if (s == NULL) return NO_INIT; |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 723 | sp<CpuConsumer> cpuConsumer = getCpuConsumer(); |
| 724 | |
| 725 | if (mHaveBuffer) { |
| 726 | mCpuConsumer->unlockBuffer(mBuffer); |
| 727 | memset(&mBuffer, 0, sizeof(mBuffer)); |
| 728 | mHaveBuffer = false; |
| 729 | } |
| 730 | |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 731 | status_t err = s->captureScreen(display, mProducer, sourceCrop, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 732 | reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform); |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 733 | |
| 734 | if (err == NO_ERROR) { |
| 735 | err = mCpuConsumer->lockNextBuffer(&mBuffer); |
| 736 | if (err == NO_ERROR) { |
| 737 | mHaveBuffer = true; |
| 738 | } |
| 739 | } |
| 740 | return err; |
| 741 | } |
| 742 | |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 743 | status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 744 | bool useIdentityTransform) { |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 745 | return ScreenshotClient::update(display, sourceCrop, 0, 0, 0, -1UL, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 746 | useIdentityTransform); |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 749 | status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 750 | uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) { |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 751 | return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight, |
| 752 | 0, -1UL, useIdentityTransform); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 753 | } |
| 754 | |
| 755 | void ScreenshotClient::release() { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 756 | if (mHaveBuffer) { |
| 757 | mCpuConsumer->unlockBuffer(mBuffer); |
| 758 | memset(&mBuffer, 0, sizeof(mBuffer)); |
| 759 | mHaveBuffer = false; |
| 760 | } |
| 761 | mCpuConsumer.clear(); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 762 | } |
| 763 | |
| 764 | void const* ScreenshotClient::getPixels() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 765 | return mBuffer.data; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 766 | } |
| 767 | |
| 768 | uint32_t ScreenshotClient::getWidth() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 769 | return mBuffer.width; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | uint32_t ScreenshotClient::getHeight() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 773 | return mBuffer.height; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 774 | } |
| 775 | |
| 776 | PixelFormat ScreenshotClient::getFormat() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 777 | return mBuffer.format; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | uint32_t ScreenshotClient::getStride() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 781 | return mBuffer.stride; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 782 | } |
| 783 | |
| 784 | size_t ScreenshotClient::getSize() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 785 | return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 786 | } |
| 787 | |
| 788 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 789 | }; // namespace android |