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)); |
Marco Nelissen | 2ea926b | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 74 | IInterface::asBinder(mComposerService)->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, |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 146 | uint32_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); |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 159 | status_t setFinalCrop(const sp<SurfaceComposerClient>& client, |
| 160 | const sp<IBinder>& id, const Rect& crop); |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 161 | status_t setLayerStack(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 162 | const sp<IBinder>& id, uint32_t layerStack); |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 163 | status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client, |
| 164 | const sp<IBinder>& id, const sp<IBinder>& handle, |
| 165 | uint64_t frameNumber); |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 166 | status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client, |
| 167 | const sp<IBinder>& id, int32_t overrideScalingMode); |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 168 | status_t setPositionAppliesWithResize(const sp<SurfaceComposerClient>& client, |
| 169 | const sp<IBinder>& id); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 170 | |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 171 | void setDisplaySurface(const sp<IBinder>& token, |
| 172 | const sp<IGraphicBufferProducer>& bufferProducer); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 173 | void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack); |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 174 | void setDisplayProjection(const sp<IBinder>& token, |
| 175 | uint32_t orientation, |
| 176 | const Rect& layerStackRect, |
| 177 | const Rect& displayRect); |
Michael Wright | 1f6078a | 2014-06-26 16:01:02 -0700 | [diff] [blame] | 178 | void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 179 | |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 180 | static void setAnimationTransaction() { |
| 181 | Composer::getInstance().setAnimationTransactionImpl(); |
| 182 | } |
| 183 | |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 184 | static void openGlobalTransaction() { |
| 185 | Composer::getInstance().openGlobalTransactionImpl(); |
| 186 | } |
| 187 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 188 | static void closeGlobalTransaction(bool synchronous) { |
| 189 | Composer::getInstance().closeGlobalTransactionImpl(synchronous); |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 190 | } |
| 191 | }; |
| 192 | |
| 193 | ANDROID_SINGLETON_STATIC_INSTANCE(Composer); |
| 194 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 195 | // --------------------------------------------------------------------------- |
| 196 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 197 | sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) { |
| 198 | return ComposerService::getComposerService()->createDisplay(displayName, |
| 199 | secure); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 200 | } |
| 201 | |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 202 | void Composer::destroyDisplay(const sp<IBinder>& display) { |
| 203 | return ComposerService::getComposerService()->destroyDisplay(display); |
| 204 | } |
| 205 | |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 206 | sp<IBinder> Composer::getBuiltInDisplay(int32_t id) { |
| 207 | return ComposerService::getComposerService()->getBuiltInDisplay(id); |
| 208 | } |
| 209 | |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 210 | void Composer::openGlobalTransactionImpl() { |
| 211 | { // scope for the lock |
| 212 | Mutex::Autolock _l(mLock); |
| 213 | mTransactionNestCount += 1; |
| 214 | } |
| 215 | } |
| 216 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 217 | void Composer::closeGlobalTransactionImpl(bool synchronous) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 218 | sp<ISurfaceComposer> sm(ComposerService::getComposerService()); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 219 | |
| 220 | Vector<ComposerState> transaction; |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 221 | Vector<DisplayState> displayTransaction; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 222 | uint32_t flags = 0; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 223 | |
| 224 | { // scope for the lock |
| 225 | Mutex::Autolock _l(mLock); |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 226 | mForceSynchronous |= synchronous; |
| 227 | if (!mTransactionNestCount) { |
| 228 | ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior " |
| 229 | "call to openGlobalTransaction()."); |
| 230 | } else if (--mTransactionNestCount) { |
| 231 | return; |
| 232 | } |
| 233 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 234 | transaction = mComposerStates; |
| 235 | mComposerStates.clear(); |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 236 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 237 | displayTransaction = mDisplayStates; |
| 238 | mDisplayStates.clear(); |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 239 | |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 240 | if (mForceSynchronous) { |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 241 | flags |= ISurfaceComposer::eSynchronous; |
| 242 | } |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 243 | if (mAnimation) { |
| 244 | flags |= ISurfaceComposer::eAnimation; |
| 245 | } |
| 246 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 247 | mForceSynchronous = false; |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 248 | mAnimation = false; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 251 | sm->setTransactionState(transaction, displayTransaction, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | } |
| 253 | |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 254 | void Composer::setAnimationTransactionImpl() { |
| 255 | Mutex::Autolock _l(mLock); |
| 256 | mAnimation = true; |
| 257 | } |
| 258 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 259 | layer_state_t* Composer::getLayerStateLocked( |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 260 | const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 261 | |
| 262 | ComposerState s; |
| 263 | s.client = client->mClient; |
| 264 | s.state.surface = id; |
| 265 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 266 | ssize_t index = mComposerStates.indexOf(s); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 267 | if (index < 0) { |
| 268 | // 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] | 269 | index = mComposerStates.add(s); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 272 | ComposerState* const out = mComposerStates.editArray(); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 273 | return &(out[index].state); |
| 274 | } |
| 275 | |
| 276 | status_t Composer::setPosition(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 277 | const sp<IBinder>& id, float x, float y) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 278 | Mutex::Autolock _l(mLock); |
| 279 | layer_state_t* s = getLayerStateLocked(client, id); |
| 280 | if (!s) |
| 281 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 282 | s->what |= layer_state_t::ePositionChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 283 | s->x = x; |
| 284 | s->y = y; |
| 285 | return NO_ERROR; |
| 286 | } |
| 287 | |
| 288 | status_t Composer::setSize(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 289 | const sp<IBinder>& id, uint32_t w, uint32_t h) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 290 | Mutex::Autolock _l(mLock); |
| 291 | layer_state_t* s = getLayerStateLocked(client, id); |
| 292 | if (!s) |
| 293 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 294 | s->what |= layer_state_t::eSizeChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 295 | s->w = w; |
| 296 | s->h = h; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 297 | |
Jorim Jaggi | 092123c | 2016-04-13 01:40:35 +0000 | [diff] [blame] | 298 | // Resizing a surface makes the transaction synchronous. |
| 299 | mForceSynchronous = true; |
| 300 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 301 | return NO_ERROR; |
| 302 | } |
| 303 | |
| 304 | status_t Composer::setLayer(const sp<SurfaceComposerClient>& client, |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 305 | const sp<IBinder>& id, uint32_t z) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 306 | Mutex::Autolock _l(mLock); |
| 307 | layer_state_t* s = getLayerStateLocked(client, id); |
| 308 | if (!s) |
| 309 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 310 | s->what |= layer_state_t::eLayerChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 311 | s->z = z; |
| 312 | return NO_ERROR; |
| 313 | } |
| 314 | |
| 315 | status_t Composer::setFlags(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 316 | const sp<IBinder>& id, uint32_t flags, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 317 | uint32_t mask) { |
| 318 | Mutex::Autolock _l(mLock); |
| 319 | layer_state_t* s = getLayerStateLocked(client, id); |
| 320 | if (!s) |
| 321 | return BAD_INDEX; |
Pablo Ceballos | 53390e1 | 2015-08-04 11:25:59 -0700 | [diff] [blame] | 322 | if ((mask & layer_state_t::eLayerOpaque) || |
| 323 | (mask & layer_state_t::eLayerHidden) || |
| 324 | (mask & layer_state_t::eLayerSecure)) { |
Dan Stoza | 2311608 | 2015-06-18 14:58:39 -0700 | [diff] [blame] | 325 | s->what |= layer_state_t::eFlagsChanged; |
Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 326 | } |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 327 | s->flags &= ~mask; |
| 328 | s->flags |= (flags & mask); |
| 329 | s->mask |= mask; |
| 330 | return NO_ERROR; |
| 331 | } |
| 332 | |
| 333 | status_t Composer::setTransparentRegionHint( |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 334 | const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 335 | const Region& transparentRegion) { |
| 336 | Mutex::Autolock _l(mLock); |
| 337 | layer_state_t* s = getLayerStateLocked(client, id); |
| 338 | if (!s) |
| 339 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 340 | s->what |= layer_state_t::eTransparentRegionChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 341 | s->transparentRegion = transparentRegion; |
| 342 | return NO_ERROR; |
| 343 | } |
| 344 | |
| 345 | status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 346 | const sp<IBinder>& id, float alpha) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 347 | Mutex::Autolock _l(mLock); |
| 348 | layer_state_t* s = getLayerStateLocked(client, id); |
| 349 | if (!s) |
| 350 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 351 | s->what |= layer_state_t::eAlphaChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 352 | s->alpha = alpha; |
| 353 | return NO_ERROR; |
| 354 | } |
| 355 | |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 356 | status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 357 | const sp<IBinder>& id, uint32_t layerStack) { |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 358 | Mutex::Autolock _l(mLock); |
| 359 | layer_state_t* s = getLayerStateLocked(client, id); |
| 360 | if (!s) |
| 361 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 362 | s->what |= layer_state_t::eLayerStackChanged; |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 363 | s->layerStack = layerStack; |
| 364 | return NO_ERROR; |
| 365 | } |
| 366 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 367 | status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 368 | const sp<IBinder>& id, float dsdx, float dtdx, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 369 | float dsdy, float dtdy) { |
| 370 | Mutex::Autolock _l(mLock); |
| 371 | layer_state_t* s = getLayerStateLocked(client, id); |
| 372 | if (!s) |
| 373 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 374 | s->what |= layer_state_t::eMatrixChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 375 | layer_state_t::matrix22_t matrix; |
| 376 | matrix.dsdx = dsdx; |
| 377 | matrix.dtdx = dtdx; |
| 378 | matrix.dsdy = dsdy; |
| 379 | matrix.dtdy = dtdy; |
| 380 | s->matrix = matrix; |
| 381 | return NO_ERROR; |
| 382 | } |
| 383 | |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 384 | status_t Composer::setCrop(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 385 | const sp<IBinder>& id, const Rect& crop) { |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 386 | Mutex::Autolock _l(mLock); |
| 387 | layer_state_t* s = getLayerStateLocked(client, id); |
| 388 | if (!s) |
| 389 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 390 | s->what |= layer_state_t::eCropChanged; |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 391 | s->crop = crop; |
| 392 | return NO_ERROR; |
| 393 | } |
| 394 | |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 395 | status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client, |
| 396 | const sp<IBinder>& id, const Rect& crop) { |
| 397 | Mutex::Autolock _l(mLock); |
| 398 | layer_state_t* s = getLayerStateLocked(client, id); |
| 399 | if (!s) { |
| 400 | return BAD_INDEX; |
| 401 | } |
| 402 | s->what |= layer_state_t::eFinalCropChanged; |
| 403 | s->finalCrop = crop; |
| 404 | return NO_ERROR; |
| 405 | } |
| 406 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 407 | status_t Composer::deferTransactionUntil( |
| 408 | const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
| 409 | const sp<IBinder>& handle, uint64_t frameNumber) { |
| 410 | Mutex::Autolock lock(mLock); |
| 411 | layer_state_t* s = getLayerStateLocked(client, id); |
| 412 | if (!s) { |
| 413 | return BAD_INDEX; |
| 414 | } |
| 415 | s->what |= layer_state_t::eDeferTransaction; |
| 416 | s->handle = handle; |
| 417 | s->frameNumber = frameNumber; |
| 418 | return NO_ERROR; |
| 419 | } |
| 420 | |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 421 | status_t Composer::setOverrideScalingMode( |
| 422 | const sp<SurfaceComposerClient>& client, |
| 423 | const sp<IBinder>& id, int32_t overrideScalingMode) { |
| 424 | Mutex::Autolock lock(mLock); |
| 425 | layer_state_t* s = getLayerStateLocked(client, id); |
| 426 | if (!s) { |
| 427 | return BAD_INDEX; |
| 428 | } |
| 429 | |
| 430 | switch (overrideScalingMode) { |
| 431 | case NATIVE_WINDOW_SCALING_MODE_FREEZE: |
| 432 | case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW: |
| 433 | case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP: |
| 434 | case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP: |
| 435 | case -1: |
| 436 | break; |
| 437 | default: |
| 438 | ALOGE("unknown scaling mode: %d", |
| 439 | overrideScalingMode); |
| 440 | return BAD_VALUE; |
| 441 | } |
| 442 | |
| 443 | s->what |= layer_state_t::eOverrideScalingModeChanged; |
| 444 | s->overrideScalingMode = overrideScalingMode; |
| 445 | return NO_ERROR; |
| 446 | } |
| 447 | |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 448 | status_t Composer::setPositionAppliesWithResize( |
| 449 | const sp<SurfaceComposerClient>& client, |
| 450 | const sp<IBinder>& id) { |
| 451 | Mutex::Autolock lock(mLock); |
| 452 | layer_state_t* s = getLayerStateLocked(client, id); |
| 453 | if (!s) { |
| 454 | return BAD_INDEX; |
| 455 | } |
| 456 | s->what |= layer_state_t::ePositionAppliesWithResize; |
| 457 | return NO_ERROR; |
| 458 | } |
| 459 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 460 | // --------------------------------------------------------------------------- |
| 461 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 462 | DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) { |
| 463 | DisplayState s; |
| 464 | s.token = token; |
| 465 | ssize_t index = mDisplayStates.indexOf(s); |
| 466 | if (index < 0) { |
| 467 | // we don't have it, add an initialized layer_state to our list |
| 468 | s.what = 0; |
| 469 | index = mDisplayStates.add(s); |
| 470 | } |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 471 | return mDisplayStates.editItemAt(static_cast<size_t>(index)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 472 | } |
| 473 | |
| 474 | void Composer::setDisplaySurface(const sp<IBinder>& token, |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 475 | const sp<IGraphicBufferProducer>& bufferProducer) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 476 | Mutex::Autolock _l(mLock); |
| 477 | DisplayState& s(getDisplayStateLocked(token)); |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 478 | s.surface = bufferProducer; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 479 | s.what |= DisplayState::eSurfaceChanged; |
| 480 | } |
| 481 | |
| 482 | void Composer::setDisplayLayerStack(const sp<IBinder>& token, |
| 483 | uint32_t layerStack) { |
| 484 | Mutex::Autolock _l(mLock); |
| 485 | DisplayState& s(getDisplayStateLocked(token)); |
| 486 | s.layerStack = layerStack; |
| 487 | s.what |= DisplayState::eLayerStackChanged; |
| 488 | } |
| 489 | |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 490 | void Composer::setDisplayProjection(const sp<IBinder>& token, |
| 491 | uint32_t orientation, |
| 492 | const Rect& layerStackRect, |
| 493 | const Rect& displayRect) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 494 | Mutex::Autolock _l(mLock); |
| 495 | DisplayState& s(getDisplayStateLocked(token)); |
| 496 | s.orientation = orientation; |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 497 | s.viewport = layerStackRect; |
| 498 | s.frame = displayRect; |
| 499 | s.what |= DisplayState::eDisplayProjectionChanged; |
Jorim Jaggi | 092123c | 2016-04-13 01:40:35 +0000 | [diff] [blame] | 500 | mForceSynchronous = true; // TODO: do we actually still need this? |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 501 | } |
| 502 | |
Michael Wright | 1f6078a | 2014-06-26 16:01:02 -0700 | [diff] [blame] | 503 | void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) { |
| 504 | Mutex::Autolock _l(mLock); |
| 505 | DisplayState& s(getDisplayStateLocked(token)); |
| 506 | s.width = width; |
| 507 | s.height = height; |
| 508 | s.what |= DisplayState::eDisplaySizeChanged; |
| 509 | } |
| 510 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 511 | // --------------------------------------------------------------------------- |
| 512 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 513 | SurfaceComposerClient::SurfaceComposerClient() |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 514 | : mStatus(NO_INIT), mComposer(Composer::getInstance()) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 515 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 516 | } |
| 517 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 518 | void SurfaceComposerClient::onFirstRef() { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 519 | sp<ISurfaceComposer> sm(ComposerService::getComposerService()); |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 520 | if (sm != 0) { |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 521 | sp<ISurfaceComposerClient> conn = sm->createConnection(); |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 522 | if (conn != 0) { |
| 523 | mClient = conn; |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 524 | mStatus = NO_ERROR; |
| 525 | } |
| 526 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 527 | } |
| 528 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 529 | SurfaceComposerClient::~SurfaceComposerClient() { |
Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 530 | dispose(); |
| 531 | } |
Mathias Agopian | dd3423c | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 532 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 533 | status_t SurfaceComposerClient::initCheck() const { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 534 | return mStatus; |
| 535 | } |
| 536 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 537 | sp<IBinder> SurfaceComposerClient::connection() const { |
Marco Nelissen | 2ea926b | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 538 | return IInterface::asBinder(mClient); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 539 | } |
| 540 | |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 541 | status_t SurfaceComposerClient::linkToComposerDeath( |
| 542 | const sp<IBinder::DeathRecipient>& recipient, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 543 | void* cookie, uint32_t flags) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 544 | sp<ISurfaceComposer> sm(ComposerService::getComposerService()); |
Marco Nelissen | 2ea926b | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 545 | return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 546 | } |
| 547 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 548 | void SurfaceComposerClient::dispose() { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 549 | // this can be called more than once. |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 550 | sp<ISurfaceComposerClient> client; |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 551 | Mutex::Autolock _lm(mLock); |
| 552 | if (mClient != 0) { |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 553 | client = mClient; // hold ref while lock is held |
| 554 | mClient.clear(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 555 | } |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 556 | mStatus = NO_INIT; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 557 | } |
| 558 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 559 | sp<SurfaceControl> SurfaceComposerClient::createSurface( |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 560 | const String8& name, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 561 | uint32_t w, |
| 562 | uint32_t h, |
| 563 | PixelFormat format, |
| 564 | uint32_t flags) |
| 565 | { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 566 | sp<SurfaceControl> sur; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 567 | if (mStatus == NO_ERROR) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 568 | sp<IBinder> handle; |
| 569 | sp<IGraphicBufferProducer> gbp; |
| 570 | status_t err = mClient->createSurface(name, w, h, format, flags, |
| 571 | &handle, &gbp); |
| 572 | ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err)); |
| 573 | if (err == NO_ERROR) { |
| 574 | sur = new SurfaceControl(this, handle, gbp); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 575 | } |
| 576 | } |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 577 | return sur; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 578 | } |
| 579 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 580 | sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, |
| 581 | bool secure) { |
| 582 | return Composer::getInstance().createDisplay(displayName, secure); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 585 | void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) { |
| 586 | Composer::getInstance().destroyDisplay(display); |
| 587 | } |
| 588 | |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 589 | sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) { |
| 590 | return Composer::getInstance().getBuiltInDisplay(id); |
| 591 | } |
| 592 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 593 | status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 594 | if (mStatus != NO_ERROR) |
| 595 | return mStatus; |
| 596 | status_t err = mClient->destroySurface(sid); |
| 597 | return err; |
| 598 | } |
| 599 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 600 | status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const { |
| 601 | if (mStatus != NO_ERROR) { |
| 602 | return mStatus; |
| 603 | } |
| 604 | return mClient->clearLayerFrameStats(token); |
| 605 | } |
| 606 | |
| 607 | status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token, |
| 608 | FrameStats* outStats) const { |
| 609 | if (mStatus != NO_ERROR) { |
| 610 | return mStatus; |
| 611 | } |
| 612 | return mClient->getLayerFrameStats(token, outStats); |
| 613 | } |
| 614 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 615 | inline Composer& SurfaceComposerClient::getComposer() { |
| 616 | return mComposer; |
| 617 | } |
| 618 | |
| 619 | // ---------------------------------------------------------------------------- |
| 620 | |
| 621 | void SurfaceComposerClient::openGlobalTransaction() { |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 622 | Composer::openGlobalTransaction(); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 623 | } |
| 624 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 625 | void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) { |
| 626 | Composer::closeGlobalTransaction(synchronous); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 627 | } |
| 628 | |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 629 | void SurfaceComposerClient::setAnimationTransaction() { |
| 630 | Composer::setAnimationTransaction(); |
| 631 | } |
| 632 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 633 | // ---------------------------------------------------------------------------- |
| 634 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 635 | status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) { |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 636 | return getComposer().setCrop(this, id, crop); |
| 637 | } |
| 638 | |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 639 | status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id, |
| 640 | const Rect& crop) { |
| 641 | return getComposer().setFinalCrop(this, id, crop); |
| 642 | } |
| 643 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 644 | status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 645 | return getComposer().setPosition(this, id, x, y); |
| 646 | } |
| 647 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 648 | 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] | 649 | return getComposer().setSize(this, id, w, h); |
| 650 | } |
| 651 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 652 | status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, uint32_t z) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 653 | return getComposer().setLayer(this, id, z); |
| 654 | } |
| 655 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 656 | status_t SurfaceComposerClient::hide(const sp<IBinder>& id) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 657 | return getComposer().setFlags(this, id, |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 658 | layer_state_t::eLayerHidden, |
| 659 | layer_state_t::eLayerHidden); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 662 | status_t SurfaceComposerClient::show(const sp<IBinder>& id) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 663 | return getComposer().setFlags(this, id, |
| 664 | 0, |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 665 | layer_state_t::eLayerHidden); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 666 | } |
| 667 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 668 | status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 669 | uint32_t mask) { |
| 670 | return getComposer().setFlags(this, id, flags, mask); |
| 671 | } |
| 672 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 673 | status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 674 | const Region& transparentRegion) { |
| 675 | return getComposer().setTransparentRegionHint(this, id, transparentRegion); |
| 676 | } |
| 677 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 678 | status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 679 | return getComposer().setAlpha(this, id, alpha); |
| 680 | } |
| 681 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 682 | status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) { |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 683 | return getComposer().setLayerStack(this, id, layerStack); |
| 684 | } |
| 685 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 686 | status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 687 | float dsdy, float dtdy) { |
| 688 | return getComposer().setMatrix(this, id, dsdx, dtdx, dsdy, dtdy); |
| 689 | } |
| 690 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 691 | status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id, |
| 692 | const sp<IBinder>& handle, uint64_t frameNumber) { |
| 693 | return getComposer().deferTransactionUntil(this, id, handle, frameNumber); |
| 694 | } |
| 695 | |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 696 | status_t SurfaceComposerClient::setOverrideScalingMode( |
| 697 | const sp<IBinder>& id, int32_t overrideScalingMode) { |
| 698 | return getComposer().setOverrideScalingMode( |
| 699 | this, id, overrideScalingMode); |
| 700 | } |
| 701 | |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 702 | status_t SurfaceComposerClient::setPositionAppliesWithResize( |
| 703 | const sp<IBinder>& id) { |
| 704 | return getComposer().setPositionAppliesWithResize(this, id); |
| 705 | } |
| 706 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 707 | // ---------------------------------------------------------------------------- |
| 708 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 709 | void SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token, |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 710 | const sp<IGraphicBufferProducer>& bufferProducer) { |
| 711 | Composer::getInstance().setDisplaySurface(token, bufferProducer); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 712 | } |
| 713 | |
| 714 | void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token, |
| 715 | uint32_t layerStack) { |
| 716 | Composer::getInstance().setDisplayLayerStack(token, layerStack); |
| 717 | } |
| 718 | |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 719 | void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token, |
| 720 | uint32_t orientation, |
| 721 | const Rect& layerStackRect, |
| 722 | const Rect& displayRect) { |
| 723 | Composer::getInstance().setDisplayProjection(token, orientation, |
| 724 | layerStackRect, displayRect); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Michael Wright | 1f6078a | 2014-06-26 16:01:02 -0700 | [diff] [blame] | 727 | void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token, |
| 728 | uint32_t width, uint32_t height) { |
| 729 | Composer::getInstance().setDisplaySize(token, width, height); |
| 730 | } |
| 731 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 732 | // ---------------------------------------------------------------------------- |
| 733 | |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 734 | status_t SurfaceComposerClient::getDisplayConfigs( |
| 735 | const sp<IBinder>& display, Vector<DisplayInfo>* configs) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 736 | { |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 737 | return ComposerService::getComposerService()->getDisplayConfigs(display, configs); |
| 738 | } |
| 739 | |
| 740 | status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display, |
| 741 | DisplayInfo* info) { |
| 742 | Vector<DisplayInfo> configs; |
| 743 | status_t result = getDisplayConfigs(display, &configs); |
| 744 | if (result != NO_ERROR) { |
| 745 | return result; |
| 746 | } |
| 747 | |
| 748 | int activeId = getActiveConfig(display); |
| 749 | if (activeId < 0) { |
| 750 | ALOGE("No active configuration found"); |
| 751 | return NAME_NOT_FOUND; |
| 752 | } |
| 753 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 754 | *info = configs[static_cast<size_t>(activeId)]; |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 755 | return NO_ERROR; |
| 756 | } |
| 757 | |
| 758 | int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) { |
| 759 | return ComposerService::getComposerService()->getActiveConfig(display); |
| 760 | } |
| 761 | |
| 762 | status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) { |
| 763 | return ComposerService::getComposerService()->setActiveConfig(display, id); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 764 | } |
| 765 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 766 | void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token, |
| 767 | int mode) { |
| 768 | ComposerService::getComposerService()->setPowerMode(token, mode); |
Jeff Brown | 2a09bb3 | 2012-10-08 19:13:57 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 771 | status_t SurfaceComposerClient::clearAnimationFrameStats() { |
| 772 | return ComposerService::getComposerService()->clearAnimationFrameStats(); |
| 773 | } |
| 774 | |
| 775 | status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) { |
| 776 | return ComposerService::getComposerService()->getAnimationFrameStats(outStats); |
| 777 | } |
| 778 | |
Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 779 | status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display, |
| 780 | HdrCapabilities* outCapabilities) { |
| 781 | return ComposerService::getComposerService()->getHdrCapabilities(display, |
| 782 | outCapabilities); |
| 783 | } |
| 784 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 785 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 786 | |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 787 | status_t ScreenshotClient::capture( |
| 788 | const sp<IBinder>& display, |
| 789 | const sp<IGraphicBufferProducer>& producer, |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 790 | Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 791 | uint32_t minLayerZ, uint32_t maxLayerZ, bool useIdentityTransform) { |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 792 | sp<ISurfaceComposer> s(ComposerService::getComposerService()); |
| 793 | if (s == NULL) return NO_INIT; |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 794 | return s->captureScreen(display, producer, sourceCrop, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 795 | reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 796 | } |
| 797 | |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 798 | ScreenshotClient::ScreenshotClient() |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 799 | : mHaveBuffer(false) { |
| 800 | memset(&mBuffer, 0, sizeof(mBuffer)); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Mathias Agopian | 8000d06 | 2013-03-26 18:15:35 -0700 | [diff] [blame] | 803 | ScreenshotClient::~ScreenshotClient() { |
| 804 | ScreenshotClient::release(); |
| 805 | } |
| 806 | |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 807 | sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const { |
| 808 | if (mCpuConsumer == NULL) { |
Dan Stoza | 6d5a7bb | 2014-03-13 11:39:09 -0700 | [diff] [blame] | 809 | sp<IGraphicBufferConsumer> consumer; |
| 810 | BufferQueue::createBufferQueue(&mProducer, &consumer); |
| 811 | mCpuConsumer = new CpuConsumer(consumer, 1); |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 812 | mCpuConsumer->setName(String8("ScreenshotClient")); |
| 813 | } |
| 814 | return mCpuConsumer; |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 815 | } |
| 816 | |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 817 | status_t ScreenshotClient::update(const sp<IBinder>& display, |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 818 | Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 819 | uint32_t minLayerZ, uint32_t maxLayerZ, |
Riley Andrews | d15ef27 | 2014-09-04 16:19:44 -0700 | [diff] [blame] | 820 | bool useIdentityTransform, uint32_t rotation) { |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 821 | sp<ISurfaceComposer> s(ComposerService::getComposerService()); |
| 822 | if (s == NULL) return NO_INIT; |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 823 | sp<CpuConsumer> cpuConsumer = getCpuConsumer(); |
| 824 | |
| 825 | if (mHaveBuffer) { |
| 826 | mCpuConsumer->unlockBuffer(mBuffer); |
| 827 | memset(&mBuffer, 0, sizeof(mBuffer)); |
| 828 | mHaveBuffer = false; |
| 829 | } |
| 830 | |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 831 | status_t err = s->captureScreen(display, mProducer, sourceCrop, |
Riley Andrews | d15ef27 | 2014-09-04 16:19:44 -0700 | [diff] [blame] | 832 | reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform, |
| 833 | static_cast<ISurfaceComposer::Rotation>(rotation)); |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 834 | |
| 835 | if (err == NO_ERROR) { |
| 836 | err = mCpuConsumer->lockNextBuffer(&mBuffer); |
| 837 | if (err == NO_ERROR) { |
| 838 | mHaveBuffer = true; |
| 839 | } |
| 840 | } |
| 841 | return err; |
| 842 | } |
| 843 | |
Riley Andrews | d15ef27 | 2014-09-04 16:19:44 -0700 | [diff] [blame] | 844 | status_t ScreenshotClient::update(const sp<IBinder>& display, |
| 845 | Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, |
| 846 | uint32_t minLayerZ, uint32_t maxLayerZ, |
| 847 | bool useIdentityTransform) { |
| 848 | |
| 849 | return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight, |
| 850 | minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone); |
| 851 | } |
| 852 | |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 853 | status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 854 | bool useIdentityTransform) { |
Dan Stoza | f10c46e | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 855 | return ScreenshotClient::update(display, sourceCrop, 0, 0, 0, -1U, |
Riley Andrews | d15ef27 | 2014-09-04 16:19:44 -0700 | [diff] [blame] | 856 | useIdentityTransform, ISurfaceComposer::eRotateNone); |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 857 | } |
| 858 | |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 859 | status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 860 | uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) { |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 861 | return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight, |
Dan Stoza | f10c46e | 2014-11-11 10:32:31 -0800 | [diff] [blame] | 862 | 0, -1U, useIdentityTransform, ISurfaceComposer::eRotateNone); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | void ScreenshotClient::release() { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 866 | if (mHaveBuffer) { |
| 867 | mCpuConsumer->unlockBuffer(mBuffer); |
| 868 | memset(&mBuffer, 0, sizeof(mBuffer)); |
| 869 | mHaveBuffer = false; |
| 870 | } |
| 871 | mCpuConsumer.clear(); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | void const* ScreenshotClient::getPixels() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 875 | return mBuffer.data; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 876 | } |
| 877 | |
| 878 | uint32_t ScreenshotClient::getWidth() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 879 | return mBuffer.width; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 880 | } |
| 881 | |
| 882 | uint32_t ScreenshotClient::getHeight() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 883 | return mBuffer.height; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 884 | } |
| 885 | |
| 886 | PixelFormat ScreenshotClient::getFormat() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 887 | return mBuffer.format; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 888 | } |
| 889 | |
| 890 | uint32_t ScreenshotClient::getStride() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 891 | return mBuffer.stride; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | size_t ScreenshotClient::getSize() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 895 | return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 896 | } |
| 897 | |
| 898 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 899 | }; // namespace android |