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 | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 29 | #include <binder/IServiceManager.h> |
Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 30 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 31 | #include <system/graphics.h> |
| 32 | |
Mathias Agopian | 076b1cc | 2009-04-10 14:24:30 -0700 | [diff] [blame] | 33 | #include <ui/DisplayInfo.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | |
Robert Carr | 673134e | 2017-01-09 19:48:38 -0800 | [diff] [blame] | 35 | #include <gui/BufferItemConsumer.h> |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 36 | #include <gui/CpuConsumer.h> |
Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 37 | #include <gui/IGraphicBufferProducer.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 38 | #include <gui/ISurfaceComposer.h> |
| 39 | #include <gui/ISurfaceComposerClient.h> |
Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 40 | #include <gui/Surface.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 41 | #include <gui/SurfaceComposerClient.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | |
Mathias Agopian | 41f673c | 2011-11-17 17:48:35 -0800 | [diff] [blame] | 43 | #include <private/gui/ComposerService.h> |
Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 44 | #include <private/gui/LayerState.h> |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 | |
| 46 | namespace android { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 47 | // --------------------------------------------------------------------------- |
| 48 | |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 49 | ANDROID_SINGLETON_STATIC_INSTANCE(ComposerService); |
| 50 | |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 51 | ComposerService::ComposerService() |
| 52 | : Singleton<ComposerService>() { |
Andy McFadden | 6652b3e | 2012-09-06 18:45:56 -0700 | [diff] [blame] | 53 | Mutex::Autolock _l(mLock); |
| 54 | connectLocked(); |
| 55 | } |
| 56 | |
| 57 | void ComposerService::connectLocked() { |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 58 | const String16 name("SurfaceFlinger"); |
| 59 | while (getService(name, &mComposerService) != NO_ERROR) { |
| 60 | usleep(250000); |
| 61 | } |
Andy McFadden | 6652b3e | 2012-09-06 18:45:56 -0700 | [diff] [blame] | 62 | assert(mComposerService != NULL); |
| 63 | |
| 64 | // Create the death listener. |
| 65 | class DeathObserver : public IBinder::DeathRecipient { |
| 66 | ComposerService& mComposerService; |
| 67 | virtual void binderDied(const wp<IBinder>& who) { |
| 68 | ALOGW("ComposerService remote (surfaceflinger) died [%p]", |
| 69 | who.unsafe_get()); |
| 70 | mComposerService.composerServiceDied(); |
| 71 | } |
| 72 | public: |
Chih-Hung Hsieh | e2347b7 | 2016-04-25 15:41:05 -0700 | [diff] [blame] | 73 | explicit DeathObserver(ComposerService& mgr) : mComposerService(mgr) { } |
Andy McFadden | 6652b3e | 2012-09-06 18:45:56 -0700 | [diff] [blame] | 74 | }; |
| 75 | |
| 76 | mDeathObserver = new DeathObserver(*const_cast<ComposerService*>(this)); |
Marco Nelissen | 2ea926b | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 77 | IInterface::asBinder(mComposerService)->linkToDeath(mDeathObserver); |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Andy McFadden | 6652b3e | 2012-09-06 18:45:56 -0700 | [diff] [blame] | 80 | /*static*/ sp<ISurfaceComposer> ComposerService::getComposerService() { |
| 81 | ComposerService& instance = ComposerService::getInstance(); |
| 82 | Mutex::Autolock _l(instance.mLock); |
| 83 | if (instance.mComposerService == NULL) { |
| 84 | ComposerService::getInstance().connectLocked(); |
| 85 | assert(instance.mComposerService != NULL); |
| 86 | ALOGD("ComposerService reconnected"); |
| 87 | } |
| 88 | return instance.mComposerService; |
| 89 | } |
| 90 | |
| 91 | void ComposerService::composerServiceDied() |
| 92 | { |
| 93 | Mutex::Autolock _l(mLock); |
| 94 | mComposerService = NULL; |
| 95 | mDeathObserver = NULL; |
Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 98 | // --------------------------------------------------------------------------- |
| 99 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 100 | static inline |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 101 | int compare_type(const ComposerState& lhs, const ComposerState& rhs) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 102 | if (lhs.client < rhs.client) return -1; |
| 103 | if (lhs.client > rhs.client) return 1; |
| 104 | if (lhs.state.surface < rhs.state.surface) return -1; |
| 105 | if (lhs.state.surface > rhs.state.surface) return 1; |
| 106 | return 0; |
| 107 | } |
| 108 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 109 | static inline |
| 110 | int compare_type(const DisplayState& lhs, const DisplayState& rhs) { |
| 111 | return compare_type(lhs.token, rhs.token); |
| 112 | } |
| 113 | |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 114 | class Composer : public Singleton<Composer> |
| 115 | { |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 116 | friend class Singleton<Composer>; |
| 117 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 118 | mutable Mutex mLock; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 119 | SortedVector<ComposerState> mComposerStates; |
| 120 | SortedVector<DisplayState > mDisplayStates; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 121 | uint32_t mForceSynchronous; |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 122 | uint32_t mTransactionNestCount; |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 123 | bool mAnimation; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 124 | |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 125 | Composer() : Singleton<Composer>(), |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 126 | mForceSynchronous(0), mTransactionNestCount(0), |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 127 | mAnimation(false) |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 128 | { } |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 129 | |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 130 | void openGlobalTransactionImpl(); |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 131 | void closeGlobalTransactionImpl(bool synchronous); |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 132 | void setAnimationTransactionImpl(); |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 133 | status_t enableVSyncInjectionsImpl(bool enable); |
| 134 | status_t injectVSyncImpl(nsecs_t when); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 135 | |
| 136 | layer_state_t* getLayerStateLocked( |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 137 | const sp<SurfaceComposerClient>& client, const sp<IBinder>& id); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 138 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 139 | DisplayState& getDisplayStateLocked(const sp<IBinder>& token); |
| 140 | |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 141 | public: |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 142 | sp<IBinder> createDisplay(const String8& displayName, bool secure); |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 143 | void destroyDisplay(const sp<IBinder>& display); |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 144 | sp<IBinder> getBuiltInDisplay(int32_t id); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 145 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 146 | status_t setPosition(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 41b6aab | 2011-08-30 18:51:54 -0700 | [diff] [blame] | 147 | float x, float y); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 148 | status_t setSize(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 149 | uint32_t w, uint32_t h); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 150 | status_t setLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 151 | int32_t z); |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 152 | status_t setRelativeLayer(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
| 153 | const sp<IBinder>& relativeTo, int32_t z); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 154 | status_t setFlags(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 155 | uint32_t flags, uint32_t mask); |
| 156 | status_t setTransparentRegionHint( |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 157 | const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 158 | const Region& transparentRegion); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 159 | status_t setAlpha(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 160 | float alpha); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 161 | status_t setMatrix(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Robert Carr | cb6e1e3 | 2017-02-21 19:48:26 -0800 | [diff] [blame] | 162 | float dsdx, float dtdx, float dtdy, float dsdy); |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 163 | status_t setOrientation(int orientation); |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 164 | status_t setCrop(const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 165 | const Rect& crop); |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 166 | status_t setFinalCrop(const sp<SurfaceComposerClient>& client, |
| 167 | const sp<IBinder>& id, const Rect& crop); |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 168 | status_t setLayerStack(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 169 | const sp<IBinder>& id, uint32_t layerStack); |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 170 | status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client, |
| 171 | const sp<IBinder>& id, const sp<IBinder>& handle, |
| 172 | uint64_t frameNumber); |
Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 173 | status_t deferTransactionUntil(const sp<SurfaceComposerClient>& client, |
| 174 | const sp<IBinder>& id, const sp<Surface>& barrierSurface, |
| 175 | uint64_t frameNumber); |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 176 | status_t reparentChildren(const sp<SurfaceComposerClient>& client, |
| 177 | const sp<IBinder>& id, |
| 178 | const sp<IBinder>& newParentHandle); |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame^] | 179 | status_t reparentChild(const sp<SurfaceComposerClient>& client, |
| 180 | const sp<IBinder>& id, const sp<IBinder>& newParentHandle, |
| 181 | const sp<IBinder>& childHandle); |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 182 | status_t detachChildren(const sp<SurfaceComposerClient>& client, |
| 183 | const sp<IBinder>& id); |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 184 | status_t setOverrideScalingMode(const sp<SurfaceComposerClient>& client, |
| 185 | const sp<IBinder>& id, int32_t overrideScalingMode); |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 186 | status_t setGeometryAppliesWithResize(const sp<SurfaceComposerClient>& client, |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 187 | const sp<IBinder>& id); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 188 | |
Pablo Ceballos | 1aad24c | 2016-08-04 10:24:22 -0700 | [diff] [blame] | 189 | status_t setDisplaySurface(const sp<IBinder>& token, |
| 190 | sp<IGraphicBufferProducer> bufferProducer); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 191 | void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack); |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 192 | void setDisplayProjection(const sp<IBinder>& token, |
| 193 | uint32_t orientation, |
| 194 | const Rect& layerStackRect, |
| 195 | const Rect& displayRect); |
Michael Wright | 1f6078a | 2014-06-26 16:01:02 -0700 | [diff] [blame] | 196 | void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 197 | |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 198 | static void setAnimationTransaction() { |
| 199 | Composer::getInstance().setAnimationTransactionImpl(); |
| 200 | } |
| 201 | |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 202 | static void openGlobalTransaction() { |
| 203 | Composer::getInstance().openGlobalTransactionImpl(); |
| 204 | } |
| 205 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 206 | static void closeGlobalTransaction(bool synchronous) { |
| 207 | Composer::getInstance().closeGlobalTransactionImpl(synchronous); |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 208 | } |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 209 | |
| 210 | static status_t enableVSyncInjections(bool enable) { |
| 211 | return Composer::getInstance().enableVSyncInjectionsImpl(enable); |
| 212 | } |
| 213 | |
| 214 | static status_t injectVSync(nsecs_t when) { |
| 215 | return Composer::getInstance().injectVSyncImpl(when); |
| 216 | } |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 217 | }; |
| 218 | |
| 219 | ANDROID_SINGLETON_STATIC_INSTANCE(Composer); |
| 220 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 221 | // --------------------------------------------------------------------------- |
| 222 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 223 | sp<IBinder> Composer::createDisplay(const String8& displayName, bool secure) { |
| 224 | return ComposerService::getComposerService()->createDisplay(displayName, |
| 225 | secure); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 228 | void Composer::destroyDisplay(const sp<IBinder>& display) { |
| 229 | return ComposerService::getComposerService()->destroyDisplay(display); |
| 230 | } |
| 231 | |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 232 | sp<IBinder> Composer::getBuiltInDisplay(int32_t id) { |
| 233 | return ComposerService::getComposerService()->getBuiltInDisplay(id); |
| 234 | } |
| 235 | |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 236 | void Composer::openGlobalTransactionImpl() { |
| 237 | { // scope for the lock |
| 238 | Mutex::Autolock _l(mLock); |
| 239 | mTransactionNestCount += 1; |
| 240 | } |
| 241 | } |
| 242 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 243 | void Composer::closeGlobalTransactionImpl(bool synchronous) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 244 | sp<ISurfaceComposer> sm(ComposerService::getComposerService()); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 245 | |
| 246 | Vector<ComposerState> transaction; |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 247 | Vector<DisplayState> displayTransaction; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 248 | uint32_t flags = 0; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 249 | |
| 250 | { // scope for the lock |
| 251 | Mutex::Autolock _l(mLock); |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 252 | mForceSynchronous |= synchronous; |
| 253 | if (!mTransactionNestCount) { |
| 254 | ALOGW("At least one call to closeGlobalTransaction() was not matched by a prior " |
| 255 | "call to openGlobalTransaction()."); |
| 256 | } else if (--mTransactionNestCount) { |
| 257 | return; |
| 258 | } |
| 259 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 260 | transaction = mComposerStates; |
| 261 | mComposerStates.clear(); |
Jamie Gennis | b8d69a5 | 2011-10-10 15:48:06 -0700 | [diff] [blame] | 262 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 263 | displayTransaction = mDisplayStates; |
| 264 | mDisplayStates.clear(); |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 265 | |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 266 | if (mForceSynchronous) { |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 267 | flags |= ISurfaceComposer::eSynchronous; |
| 268 | } |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 269 | if (mAnimation) { |
| 270 | flags |= ISurfaceComposer::eAnimation; |
| 271 | } |
| 272 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 273 | mForceSynchronous = false; |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 274 | mAnimation = false; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 275 | } |
| 276 | |
Mathias Agopian | 8b33f03 | 2012-07-24 20:43:54 -0700 | [diff] [blame] | 277 | sm->setTransactionState(transaction, displayTransaction, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 280 | status_t Composer::enableVSyncInjectionsImpl(bool enable) { |
| 281 | sp<ISurfaceComposer> sm(ComposerService::getComposerService()); |
| 282 | return sm->enableVSyncInjections(enable); |
| 283 | } |
| 284 | |
| 285 | status_t Composer::injectVSyncImpl(nsecs_t when) { |
| 286 | sp<ISurfaceComposer> sm(ComposerService::getComposerService()); |
| 287 | return sm->injectVSync(when); |
| 288 | } |
| 289 | |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 290 | void Composer::setAnimationTransactionImpl() { |
| 291 | Mutex::Autolock _l(mLock); |
| 292 | mAnimation = true; |
| 293 | } |
| 294 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 295 | layer_state_t* Composer::getLayerStateLocked( |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 296 | const sp<SurfaceComposerClient>& client, const sp<IBinder>& id) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 297 | |
| 298 | ComposerState s; |
| 299 | s.client = client->mClient; |
| 300 | s.state.surface = id; |
| 301 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 302 | ssize_t index = mComposerStates.indexOf(s); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 303 | if (index < 0) { |
| 304 | // 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] | 305 | index = mComposerStates.add(s); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 306 | } |
| 307 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 308 | ComposerState* const out = mComposerStates.editArray(); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 309 | return &(out[index].state); |
| 310 | } |
| 311 | |
| 312 | status_t Composer::setPosition(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 313 | const sp<IBinder>& id, float x, float y) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 314 | Mutex::Autolock _l(mLock); |
| 315 | layer_state_t* s = getLayerStateLocked(client, id); |
| 316 | if (!s) |
| 317 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 318 | s->what |= layer_state_t::ePositionChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 319 | s->x = x; |
| 320 | s->y = y; |
| 321 | return NO_ERROR; |
| 322 | } |
| 323 | |
| 324 | status_t Composer::setSize(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 325 | const sp<IBinder>& id, uint32_t w, uint32_t h) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 326 | Mutex::Autolock _l(mLock); |
| 327 | layer_state_t* s = getLayerStateLocked(client, id); |
| 328 | if (!s) |
| 329 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 330 | s->what |= layer_state_t::eSizeChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 331 | s->w = w; |
| 332 | s->h = h; |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 333 | |
Jorim Jaggi | 092123c | 2016-04-13 01:40:35 +0000 | [diff] [blame] | 334 | // Resizing a surface makes the transaction synchronous. |
| 335 | mForceSynchronous = true; |
| 336 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 337 | return NO_ERROR; |
| 338 | } |
| 339 | |
| 340 | status_t Composer::setLayer(const sp<SurfaceComposerClient>& client, |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 341 | const sp<IBinder>& id, int32_t z) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 342 | Mutex::Autolock _l(mLock); |
| 343 | layer_state_t* s = getLayerStateLocked(client, id); |
| 344 | if (!s) |
| 345 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 346 | s->what |= layer_state_t::eLayerChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 347 | s->z = z; |
| 348 | return NO_ERROR; |
| 349 | } |
| 350 | |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 351 | status_t Composer::setRelativeLayer(const sp<SurfaceComposerClient>& client, |
| 352 | const sp<IBinder>& id, const sp<IBinder>& relativeTo, |
| 353 | int32_t z) { |
| 354 | Mutex::Autolock _l(mLock); |
| 355 | layer_state_t* s = getLayerStateLocked(client, id); |
| 356 | if (!s) { |
| 357 | return BAD_INDEX; |
| 358 | } |
| 359 | s->what |= layer_state_t::eRelativeLayerChanged; |
| 360 | s->relativeLayerHandle = relativeTo; |
| 361 | s->z = z; |
| 362 | return NO_ERROR; |
| 363 | } |
| 364 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 365 | status_t Composer::setFlags(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 366 | const sp<IBinder>& id, uint32_t flags, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 367 | uint32_t mask) { |
| 368 | Mutex::Autolock _l(mLock); |
| 369 | layer_state_t* s = getLayerStateLocked(client, id); |
| 370 | if (!s) |
| 371 | return BAD_INDEX; |
Pablo Ceballos | 53390e1 | 2015-08-04 11:25:59 -0700 | [diff] [blame] | 372 | if ((mask & layer_state_t::eLayerOpaque) || |
| 373 | (mask & layer_state_t::eLayerHidden) || |
| 374 | (mask & layer_state_t::eLayerSecure)) { |
Dan Stoza | 2311608 | 2015-06-18 14:58:39 -0700 | [diff] [blame] | 375 | s->what |= layer_state_t::eFlagsChanged; |
Andy McFadden | 4125a4f | 2014-01-29 17:17:11 -0800 | [diff] [blame] | 376 | } |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 377 | s->flags &= ~mask; |
| 378 | s->flags |= (flags & mask); |
| 379 | s->mask |= mask; |
| 380 | return NO_ERROR; |
| 381 | } |
| 382 | |
| 383 | status_t Composer::setTransparentRegionHint( |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 384 | const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 385 | const Region& transparentRegion) { |
| 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::eTransparentRegionChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 391 | s->transparentRegion = transparentRegion; |
| 392 | return NO_ERROR; |
| 393 | } |
| 394 | |
| 395 | status_t Composer::setAlpha(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 396 | const sp<IBinder>& id, float alpha) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 397 | Mutex::Autolock _l(mLock); |
| 398 | layer_state_t* s = getLayerStateLocked(client, id); |
| 399 | if (!s) |
| 400 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 401 | s->what |= layer_state_t::eAlphaChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 402 | s->alpha = alpha; |
| 403 | return NO_ERROR; |
| 404 | } |
| 405 | |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 406 | status_t Composer::setLayerStack(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 407 | const sp<IBinder>& id, uint32_t layerStack) { |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 408 | Mutex::Autolock _l(mLock); |
| 409 | layer_state_t* s = getLayerStateLocked(client, id); |
| 410 | if (!s) |
| 411 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 412 | s->what |= layer_state_t::eLayerStackChanged; |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 413 | s->layerStack = layerStack; |
| 414 | return NO_ERROR; |
| 415 | } |
| 416 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 417 | status_t Composer::setMatrix(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 418 | const sp<IBinder>& id, float dsdx, float dtdx, |
Robert Carr | cb6e1e3 | 2017-02-21 19:48:26 -0800 | [diff] [blame] | 419 | float dtdy, float dsdy) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 420 | Mutex::Autolock _l(mLock); |
| 421 | layer_state_t* s = getLayerStateLocked(client, id); |
| 422 | if (!s) |
| 423 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 424 | s->what |= layer_state_t::eMatrixChanged; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 425 | layer_state_t::matrix22_t matrix; |
| 426 | matrix.dsdx = dsdx; |
| 427 | matrix.dtdx = dtdx; |
| 428 | matrix.dsdy = dsdy; |
| 429 | matrix.dtdy = dtdy; |
| 430 | s->matrix = matrix; |
| 431 | return NO_ERROR; |
| 432 | } |
| 433 | |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 434 | status_t Composer::setCrop(const sp<SurfaceComposerClient>& client, |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 435 | const sp<IBinder>& id, const Rect& crop) { |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 436 | Mutex::Autolock _l(mLock); |
| 437 | layer_state_t* s = getLayerStateLocked(client, id); |
| 438 | if (!s) |
| 439 | return BAD_INDEX; |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 440 | s->what |= layer_state_t::eCropChanged; |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 441 | s->crop = crop; |
| 442 | return NO_ERROR; |
| 443 | } |
| 444 | |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 445 | status_t Composer::setFinalCrop(const sp<SurfaceComposerClient>& client, |
| 446 | const sp<IBinder>& id, const Rect& crop) { |
| 447 | Mutex::Autolock _l(mLock); |
| 448 | layer_state_t* s = getLayerStateLocked(client, id); |
| 449 | if (!s) { |
| 450 | return BAD_INDEX; |
| 451 | } |
| 452 | s->what |= layer_state_t::eFinalCropChanged; |
| 453 | s->finalCrop = crop; |
| 454 | return NO_ERROR; |
| 455 | } |
| 456 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 457 | status_t Composer::deferTransactionUntil( |
| 458 | const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
| 459 | const sp<IBinder>& handle, uint64_t frameNumber) { |
| 460 | Mutex::Autolock lock(mLock); |
| 461 | layer_state_t* s = getLayerStateLocked(client, id); |
| 462 | if (!s) { |
| 463 | return BAD_INDEX; |
| 464 | } |
| 465 | s->what |= layer_state_t::eDeferTransaction; |
Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 466 | s->barrierHandle = handle; |
| 467 | s->frameNumber = frameNumber; |
| 468 | return NO_ERROR; |
| 469 | } |
| 470 | |
| 471 | status_t Composer::deferTransactionUntil( |
| 472 | const sp<SurfaceComposerClient>& client, const sp<IBinder>& id, |
| 473 | const sp<Surface>& barrierSurface, uint64_t frameNumber) { |
| 474 | Mutex::Autolock lock(mLock); |
| 475 | layer_state_t* s = getLayerStateLocked(client, id); |
| 476 | if (!s) { |
| 477 | return BAD_INDEX; |
| 478 | } |
| 479 | s->what |= layer_state_t::eDeferTransaction; |
| 480 | s->barrierGbp = barrierSurface->getIGraphicBufferProducer(); |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 481 | s->frameNumber = frameNumber; |
| 482 | return NO_ERROR; |
| 483 | } |
| 484 | |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 485 | status_t Composer::reparentChildren( |
| 486 | const sp<SurfaceComposerClient>& client, |
| 487 | const sp<IBinder>& id, |
| 488 | const sp<IBinder>& newParentHandle) { |
| 489 | Mutex::Autolock lock(mLock); |
| 490 | layer_state_t* s = getLayerStateLocked(client, id); |
| 491 | if (!s) { |
| 492 | return BAD_INDEX; |
| 493 | } |
| 494 | s->what |= layer_state_t::eReparentChildren; |
| 495 | s->reparentHandle = newParentHandle; |
| 496 | return NO_ERROR; |
| 497 | } |
| 498 | |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame^] | 499 | status_t Composer::reparentChild(const sp<SurfaceComposerClient>& client, |
| 500 | const sp<IBinder>& id, |
| 501 | const sp<IBinder>& newParentHandle, |
| 502 | const sp<IBinder>& childHandle) { |
| 503 | Mutex::Autolock lock(mLock); |
| 504 | layer_state_t* s = getLayerStateLocked(client, id); |
| 505 | if (!s) { |
| 506 | return BAD_INDEX; |
| 507 | } |
| 508 | s->what |= layer_state_t::eReparentChild; |
| 509 | s->parentHandleForChild = newParentHandle; |
| 510 | s->childHandle = childHandle; |
| 511 | return NO_ERROR; |
| 512 | } |
| 513 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 514 | status_t Composer::detachChildren( |
| 515 | const sp<SurfaceComposerClient>& client, |
| 516 | const sp<IBinder>& id) { |
| 517 | Mutex::Autolock lock(mLock); |
| 518 | layer_state_t* s = getLayerStateLocked(client, id); |
| 519 | if (!s) { |
| 520 | return BAD_INDEX; |
| 521 | } |
| 522 | s->what |= layer_state_t::eDetachChildren; |
| 523 | return NO_ERROR; |
| 524 | } |
| 525 | |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 526 | status_t Composer::setOverrideScalingMode( |
| 527 | const sp<SurfaceComposerClient>& client, |
| 528 | const sp<IBinder>& id, int32_t overrideScalingMode) { |
| 529 | Mutex::Autolock lock(mLock); |
| 530 | layer_state_t* s = getLayerStateLocked(client, id); |
| 531 | if (!s) { |
| 532 | return BAD_INDEX; |
| 533 | } |
| 534 | |
| 535 | switch (overrideScalingMode) { |
| 536 | case NATIVE_WINDOW_SCALING_MODE_FREEZE: |
| 537 | case NATIVE_WINDOW_SCALING_MODE_SCALE_TO_WINDOW: |
| 538 | case NATIVE_WINDOW_SCALING_MODE_SCALE_CROP: |
| 539 | case NATIVE_WINDOW_SCALING_MODE_NO_SCALE_CROP: |
| 540 | case -1: |
| 541 | break; |
| 542 | default: |
| 543 | ALOGE("unknown scaling mode: %d", |
| 544 | overrideScalingMode); |
| 545 | return BAD_VALUE; |
| 546 | } |
| 547 | |
| 548 | s->what |= layer_state_t::eOverrideScalingModeChanged; |
| 549 | s->overrideScalingMode = overrideScalingMode; |
| 550 | return NO_ERROR; |
| 551 | } |
| 552 | |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 553 | status_t Composer::setGeometryAppliesWithResize( |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 554 | const sp<SurfaceComposerClient>& client, |
| 555 | const sp<IBinder>& id) { |
| 556 | Mutex::Autolock lock(mLock); |
| 557 | layer_state_t* s = getLayerStateLocked(client, id); |
| 558 | if (!s) { |
| 559 | return BAD_INDEX; |
| 560 | } |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 561 | s->what |= layer_state_t::eGeometryAppliesWithResize; |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 562 | return NO_ERROR; |
| 563 | } |
| 564 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 565 | // --------------------------------------------------------------------------- |
| 566 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 567 | DisplayState& Composer::getDisplayStateLocked(const sp<IBinder>& token) { |
| 568 | DisplayState s; |
| 569 | s.token = token; |
| 570 | ssize_t index = mDisplayStates.indexOf(s); |
| 571 | if (index < 0) { |
| 572 | // we don't have it, add an initialized layer_state to our list |
| 573 | s.what = 0; |
| 574 | index = mDisplayStates.add(s); |
| 575 | } |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 576 | return mDisplayStates.editItemAt(static_cast<size_t>(index)); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Pablo Ceballos | 1aad24c | 2016-08-04 10:24:22 -0700 | [diff] [blame] | 579 | status_t Composer::setDisplaySurface(const sp<IBinder>& token, |
| 580 | sp<IGraphicBufferProducer> bufferProducer) { |
Pablo Ceballos | eddbef8 | 2016-09-01 11:21:21 -0700 | [diff] [blame] | 581 | if (bufferProducer.get() != nullptr) { |
| 582 | // Make sure that composition can never be stalled by a virtual display |
| 583 | // consumer that isn't processing buffers fast enough. |
| 584 | status_t err = bufferProducer->setAsyncMode(true); |
| 585 | if (err != NO_ERROR) { |
| 586 | ALOGE("Composer::setDisplaySurface Failed to enable async mode on the " |
| 587 | "BufferQueue. This BufferQueue cannot be used for virtual " |
| 588 | "display. (%d)", err); |
| 589 | return err; |
| 590 | } |
Pablo Ceballos | 1aad24c | 2016-08-04 10:24:22 -0700 | [diff] [blame] | 591 | } |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 592 | Mutex::Autolock _l(mLock); |
| 593 | DisplayState& s(getDisplayStateLocked(token)); |
Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 594 | s.surface = bufferProducer; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 595 | s.what |= DisplayState::eSurfaceChanged; |
Pablo Ceballos | 1aad24c | 2016-08-04 10:24:22 -0700 | [diff] [blame] | 596 | return NO_ERROR; |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 597 | } |
| 598 | |
| 599 | void Composer::setDisplayLayerStack(const sp<IBinder>& token, |
| 600 | uint32_t layerStack) { |
| 601 | Mutex::Autolock _l(mLock); |
| 602 | DisplayState& s(getDisplayStateLocked(token)); |
| 603 | s.layerStack = layerStack; |
| 604 | s.what |= DisplayState::eLayerStackChanged; |
| 605 | } |
| 606 | |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 607 | void Composer::setDisplayProjection(const sp<IBinder>& token, |
| 608 | uint32_t orientation, |
| 609 | const Rect& layerStackRect, |
| 610 | const Rect& displayRect) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 611 | Mutex::Autolock _l(mLock); |
| 612 | DisplayState& s(getDisplayStateLocked(token)); |
| 613 | s.orientation = orientation; |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 614 | s.viewport = layerStackRect; |
| 615 | s.frame = displayRect; |
| 616 | s.what |= DisplayState::eDisplayProjectionChanged; |
Jorim Jaggi | 092123c | 2016-04-13 01:40:35 +0000 | [diff] [blame] | 617 | mForceSynchronous = true; // TODO: do we actually still need this? |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 618 | } |
| 619 | |
Michael Wright | 1f6078a | 2014-06-26 16:01:02 -0700 | [diff] [blame] | 620 | void Composer::setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height) { |
| 621 | Mutex::Autolock _l(mLock); |
| 622 | DisplayState& s(getDisplayStateLocked(token)); |
| 623 | s.width = width; |
| 624 | s.height = height; |
| 625 | s.what |= DisplayState::eDisplaySizeChanged; |
| 626 | } |
| 627 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 628 | // --------------------------------------------------------------------------- |
| 629 | |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 630 | SurfaceComposerClient::SurfaceComposerClient() |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 631 | : mStatus(NO_INIT), mComposer(Composer::getInstance()) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 632 | { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | } |
| 634 | |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 635 | SurfaceComposerClient::SurfaceComposerClient(const sp<IGraphicBufferProducer>& root) |
| 636 | : mStatus(NO_INIT), mComposer(Composer::getInstance()), mParent(root) |
| 637 | { |
| 638 | } |
| 639 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 640 | void SurfaceComposerClient::onFirstRef() { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 641 | sp<ISurfaceComposer> sm(ComposerService::getComposerService()); |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 642 | if (sm != 0) { |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 643 | auto rootProducer = mParent.promote(); |
| 644 | sp<ISurfaceComposerClient> conn; |
| 645 | conn = (rootProducer != nullptr) ? sm->createScopedConnection(rootProducer) : |
| 646 | sm->createConnection(); |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 647 | if (conn != 0) { |
| 648 | mClient = conn; |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 649 | mStatus = NO_ERROR; |
| 650 | } |
| 651 | } |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 652 | } |
| 653 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 654 | SurfaceComposerClient::~SurfaceComposerClient() { |
Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 655 | dispose(); |
| 656 | } |
Mathias Agopian | dd3423c | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 657 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 658 | status_t SurfaceComposerClient::initCheck() const { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 659 | return mStatus; |
| 660 | } |
| 661 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 662 | sp<IBinder> SurfaceComposerClient::connection() const { |
Marco Nelissen | 2ea926b | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 663 | return IInterface::asBinder(mClient); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 664 | } |
| 665 | |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 666 | status_t SurfaceComposerClient::linkToComposerDeath( |
| 667 | const sp<IBinder::DeathRecipient>& recipient, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 668 | void* cookie, uint32_t flags) { |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 669 | sp<ISurfaceComposer> sm(ComposerService::getComposerService()); |
Marco Nelissen | 2ea926b | 2014-11-14 08:01:01 -0800 | [diff] [blame] | 670 | return IInterface::asBinder(sm)->linkToDeath(recipient, cookie, flags); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 671 | } |
| 672 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 673 | void SurfaceComposerClient::dispose() { |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 674 | // this can be called more than once. |
Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 675 | sp<ISurfaceComposerClient> client; |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 676 | Mutex::Autolock _lm(mLock); |
| 677 | if (mClient != 0) { |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 678 | client = mClient; // hold ref while lock is held |
| 679 | mClient.clear(); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 680 | } |
Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 681 | mStatus = NO_INIT; |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 682 | } |
| 683 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 684 | sp<SurfaceControl> SurfaceComposerClient::createSurface( |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 685 | const String8& name, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 686 | uint32_t w, |
| 687 | uint32_t h, |
| 688 | PixelFormat format, |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 689 | uint32_t flags, |
Albert Chaulk | 479c60c | 2017-01-27 14:21:34 -0500 | [diff] [blame] | 690 | SurfaceControl* parent, |
| 691 | uint32_t windowType, |
| 692 | uint32_t ownerUid) |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 693 | { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 694 | sp<SurfaceControl> sur; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 695 | if (mStatus == NO_ERROR) { |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 696 | sp<IBinder> handle; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 697 | sp<IBinder> parentHandle; |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 698 | sp<IGraphicBufferProducer> gbp; |
Robert Carr | 1f0a16a | 2016-10-24 16:27:39 -0700 | [diff] [blame] | 699 | |
| 700 | if (parent != nullptr) { |
| 701 | parentHandle = parent->getHandle(); |
| 702 | } |
| 703 | status_t err = mClient->createSurface(name, w, h, format, flags, parentHandle, |
Albert Chaulk | 479c60c | 2017-01-27 14:21:34 -0500 | [diff] [blame] | 704 | windowType, ownerUid, &handle, &gbp); |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 705 | ALOGE_IF(err, "SurfaceComposerClient::createSurface error %s", strerror(-err)); |
| 706 | if (err == NO_ERROR) { |
| 707 | sur = new SurfaceControl(this, handle, gbp); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 708 | } |
| 709 | } |
Mathias Agopian | 4d9b822 | 2013-03-12 17:11:48 -0700 | [diff] [blame] | 710 | return sur; |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 713 | sp<IBinder> SurfaceComposerClient::createDisplay(const String8& displayName, |
| 714 | bool secure) { |
| 715 | return Composer::getInstance().createDisplay(displayName, secure); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 716 | } |
| 717 | |
Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 718 | void SurfaceComposerClient::destroyDisplay(const sp<IBinder>& display) { |
| 719 | Composer::getInstance().destroyDisplay(display); |
| 720 | } |
| 721 | |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 722 | sp<IBinder> SurfaceComposerClient::getBuiltInDisplay(int32_t id) { |
| 723 | return Composer::getInstance().getBuiltInDisplay(id); |
| 724 | } |
| 725 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 726 | status_t SurfaceComposerClient::destroySurface(const sp<IBinder>& sid) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 727 | if (mStatus != NO_ERROR) |
| 728 | return mStatus; |
| 729 | status_t err = mClient->destroySurface(sid); |
| 730 | return err; |
| 731 | } |
| 732 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 733 | status_t SurfaceComposerClient::clearLayerFrameStats(const sp<IBinder>& token) const { |
| 734 | if (mStatus != NO_ERROR) { |
| 735 | return mStatus; |
| 736 | } |
| 737 | return mClient->clearLayerFrameStats(token); |
| 738 | } |
| 739 | |
| 740 | status_t SurfaceComposerClient::getLayerFrameStats(const sp<IBinder>& token, |
| 741 | FrameStats* outStats) const { |
| 742 | if (mStatus != NO_ERROR) { |
| 743 | return mStatus; |
| 744 | } |
| 745 | return mClient->getLayerFrameStats(token, outStats); |
| 746 | } |
| 747 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 748 | inline Composer& SurfaceComposerClient::getComposer() { |
| 749 | return mComposer; |
| 750 | } |
| 751 | |
| 752 | // ---------------------------------------------------------------------------- |
| 753 | |
| 754 | void SurfaceComposerClient::openGlobalTransaction() { |
Jeff Brown | f3f7db6 | 2012-08-31 02:18:38 -0700 | [diff] [blame] | 755 | Composer::openGlobalTransaction(); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 756 | } |
| 757 | |
Jamie Gennis | 2837839 | 2011-10-12 17:39:00 -0700 | [diff] [blame] | 758 | void SurfaceComposerClient::closeGlobalTransaction(bool synchronous) { |
| 759 | Composer::closeGlobalTransaction(synchronous); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 762 | void SurfaceComposerClient::setAnimationTransaction() { |
| 763 | Composer::setAnimationTransaction(); |
| 764 | } |
| 765 | |
Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 766 | status_t SurfaceComposerClient::enableVSyncInjections(bool enable) { |
| 767 | return Composer::enableVSyncInjections(enable); |
| 768 | } |
| 769 | |
| 770 | status_t SurfaceComposerClient::injectVSync(nsecs_t when) { |
| 771 | return Composer::injectVSync(when); |
| 772 | } |
| 773 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 774 | // ---------------------------------------------------------------------------- |
| 775 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 776 | status_t SurfaceComposerClient::setCrop(const sp<IBinder>& id, const Rect& crop) { |
Jamie Gennis | f15a83f | 2012-05-10 20:43:55 -0700 | [diff] [blame] | 777 | return getComposer().setCrop(this, id, crop); |
| 778 | } |
| 779 | |
Pablo Ceballos | acbe678 | 2016-03-04 17:54:21 +0000 | [diff] [blame] | 780 | status_t SurfaceComposerClient::setFinalCrop(const sp<IBinder>& id, |
| 781 | const Rect& crop) { |
| 782 | return getComposer().setFinalCrop(this, id, crop); |
| 783 | } |
| 784 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 785 | status_t SurfaceComposerClient::setPosition(const sp<IBinder>& id, float x, float y) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 786 | return getComposer().setPosition(this, id, x, y); |
| 787 | } |
| 788 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 789 | 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] | 790 | return getComposer().setSize(this, id, w, h); |
| 791 | } |
| 792 | |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 793 | status_t SurfaceComposerClient::setLayer(const sp<IBinder>& id, int32_t z) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 794 | return getComposer().setLayer(this, id, z); |
| 795 | } |
| 796 | |
Robert Carr | db66e62 | 2017-04-10 16:55:57 -0700 | [diff] [blame] | 797 | status_t SurfaceComposerClient::setRelativeLayer(const sp<IBinder>& id, |
| 798 | const sp<IBinder>& relativeTo, int32_t z) { |
| 799 | return getComposer().setRelativeLayer(this, id, relativeTo, z); |
| 800 | } |
| 801 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 802 | status_t SurfaceComposerClient::hide(const sp<IBinder>& id) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 803 | return getComposer().setFlags(this, id, |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 804 | layer_state_t::eLayerHidden, |
| 805 | layer_state_t::eLayerHidden); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 808 | status_t SurfaceComposerClient::show(const sp<IBinder>& id) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 809 | return getComposer().setFlags(this, id, |
| 810 | 0, |
Mathias Agopian | 3165cc2 | 2012-08-08 19:42:09 -0700 | [diff] [blame] | 811 | layer_state_t::eLayerHidden); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 812 | } |
| 813 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 814 | status_t SurfaceComposerClient::setFlags(const sp<IBinder>& id, uint32_t flags, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 815 | uint32_t mask) { |
| 816 | return getComposer().setFlags(this, id, flags, mask); |
| 817 | } |
| 818 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 819 | status_t SurfaceComposerClient::setTransparentRegionHint(const sp<IBinder>& id, |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 820 | const Region& transparentRegion) { |
| 821 | return getComposer().setTransparentRegionHint(this, id, transparentRegion); |
| 822 | } |
| 823 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 824 | status_t SurfaceComposerClient::setAlpha(const sp<IBinder>& id, float alpha) { |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 825 | return getComposer().setAlpha(this, id, alpha); |
| 826 | } |
| 827 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 828 | status_t SurfaceComposerClient::setLayerStack(const sp<IBinder>& id, uint32_t layerStack) { |
Mathias Agopian | 8785578 | 2012-07-24 21:41:09 -0700 | [diff] [blame] | 829 | return getComposer().setLayerStack(this, id, layerStack); |
| 830 | } |
| 831 | |
Mathias Agopian | ac9fa42 | 2013-02-11 16:40:36 -0800 | [diff] [blame] | 832 | status_t SurfaceComposerClient::setMatrix(const sp<IBinder>& id, float dsdx, float dtdx, |
Robert Carr | cb6e1e3 | 2017-02-21 19:48:26 -0800 | [diff] [blame] | 833 | float dtdy, float dsdy) { |
| 834 | return getComposer().setMatrix(this, id, dsdx, dtdx, dtdy, dsdy); |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Dan Stoza | 7dde599 | 2015-05-22 09:51:44 -0700 | [diff] [blame] | 837 | status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id, |
| 838 | const sp<IBinder>& handle, uint64_t frameNumber) { |
| 839 | return getComposer().deferTransactionUntil(this, id, handle, frameNumber); |
| 840 | } |
| 841 | |
Robert Carr | 0d48072 | 2017-01-10 16:42:54 -0800 | [diff] [blame] | 842 | status_t SurfaceComposerClient::deferTransactionUntil(const sp<IBinder>& id, |
| 843 | const sp<Surface>& barrierSurface, uint64_t frameNumber) { |
| 844 | return getComposer().deferTransactionUntil(this, id, barrierSurface, frameNumber); |
| 845 | } |
| 846 | |
Robert Carr | 1db73f6 | 2016-12-21 12:58:51 -0800 | [diff] [blame] | 847 | status_t SurfaceComposerClient::reparentChildren(const sp<IBinder>& id, |
| 848 | const sp<IBinder>& newParentHandle) { |
| 849 | return getComposer().reparentChildren(this, id, newParentHandle); |
| 850 | } |
| 851 | |
chaviw | 0617894 | 2017-07-27 10:25:59 -0700 | [diff] [blame^] | 852 | status_t SurfaceComposerClient::reparentChild(const sp<IBinder>& id, |
| 853 | const sp<IBinder>& newParentHandle, const sp<IBinder>& childHandle) { |
| 854 | return getComposer().reparentChild(this, id, newParentHandle, childHandle); |
| 855 | } |
| 856 | |
Robert Carr | 9524cb3 | 2017-02-13 11:32:32 -0800 | [diff] [blame] | 857 | status_t SurfaceComposerClient::detachChildren(const sp<IBinder>& id) { |
| 858 | return getComposer().detachChildren(this, id); |
| 859 | } |
| 860 | |
Robert Carr | c3574f7 | 2016-03-24 12:19:32 -0700 | [diff] [blame] | 861 | status_t SurfaceComposerClient::setOverrideScalingMode( |
| 862 | const sp<IBinder>& id, int32_t overrideScalingMode) { |
| 863 | return getComposer().setOverrideScalingMode( |
| 864 | this, id, overrideScalingMode); |
| 865 | } |
| 866 | |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 867 | status_t SurfaceComposerClient::setGeometryAppliesWithResize( |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 868 | const sp<IBinder>& id) { |
Robert Carr | 99e27f0 | 2016-06-16 15:18:02 -0700 | [diff] [blame] | 869 | return getComposer().setGeometryAppliesWithResize(this, id); |
Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 870 | } |
| 871 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 872 | // ---------------------------------------------------------------------------- |
| 873 | |
Pablo Ceballos | 1aad24c | 2016-08-04 10:24:22 -0700 | [diff] [blame] | 874 | status_t SurfaceComposerClient::setDisplaySurface(const sp<IBinder>& token, |
| 875 | sp<IGraphicBufferProducer> bufferProducer) { |
| 876 | return Composer::getInstance().setDisplaySurface(token, bufferProducer); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | void SurfaceComposerClient::setDisplayLayerStack(const sp<IBinder>& token, |
| 880 | uint32_t layerStack) { |
| 881 | Composer::getInstance().setDisplayLayerStack(token, layerStack); |
| 882 | } |
| 883 | |
Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 884 | void SurfaceComposerClient::setDisplayProjection(const sp<IBinder>& token, |
| 885 | uint32_t orientation, |
| 886 | const Rect& layerStackRect, |
| 887 | const Rect& displayRect) { |
| 888 | Composer::getInstance().setDisplayProjection(token, orientation, |
| 889 | layerStackRect, displayRect); |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 890 | } |
| 891 | |
Michael Wright | 1f6078a | 2014-06-26 16:01:02 -0700 | [diff] [blame] | 892 | void SurfaceComposerClient::setDisplaySize(const sp<IBinder>& token, |
| 893 | uint32_t width, uint32_t height) { |
| 894 | Composer::getInstance().setDisplaySize(token, width, height); |
| 895 | } |
| 896 | |
Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 897 | // ---------------------------------------------------------------------------- |
| 898 | |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 899 | status_t SurfaceComposerClient::getDisplayConfigs( |
| 900 | const sp<IBinder>& display, Vector<DisplayInfo>* configs) |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | { |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 902 | return ComposerService::getComposerService()->getDisplayConfigs(display, configs); |
| 903 | } |
| 904 | |
| 905 | status_t SurfaceComposerClient::getDisplayInfo(const sp<IBinder>& display, |
| 906 | DisplayInfo* info) { |
| 907 | Vector<DisplayInfo> configs; |
| 908 | status_t result = getDisplayConfigs(display, &configs); |
| 909 | if (result != NO_ERROR) { |
| 910 | return result; |
| 911 | } |
| 912 | |
| 913 | int activeId = getActiveConfig(display); |
| 914 | if (activeId < 0) { |
| 915 | ALOGE("No active configuration found"); |
| 916 | return NAME_NOT_FOUND; |
| 917 | } |
| 918 | |
Dan Stoza | d723bd7 | 2014-11-18 10:24:03 -0800 | [diff] [blame] | 919 | *info = configs[static_cast<size_t>(activeId)]; |
Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 920 | return NO_ERROR; |
| 921 | } |
| 922 | |
| 923 | int SurfaceComposerClient::getActiveConfig(const sp<IBinder>& display) { |
| 924 | return ComposerService::getComposerService()->getActiveConfig(display); |
| 925 | } |
| 926 | |
| 927 | status_t SurfaceComposerClient::setActiveConfig(const sp<IBinder>& display, int id) { |
| 928 | return ComposerService::getComposerService()->setActiveConfig(display, id); |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 929 | } |
| 930 | |
Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 931 | status_t SurfaceComposerClient::getDisplayColorModes(const sp<IBinder>& display, |
| 932 | Vector<android_color_mode_t>* outColorModes) { |
| 933 | return ComposerService::getComposerService()->getDisplayColorModes(display, outColorModes); |
| 934 | } |
| 935 | |
| 936 | android_color_mode_t SurfaceComposerClient::getActiveColorMode(const sp<IBinder>& display) { |
| 937 | return ComposerService::getComposerService()->getActiveColorMode(display); |
| 938 | } |
| 939 | |
| 940 | status_t SurfaceComposerClient::setActiveColorMode(const sp<IBinder>& display, |
| 941 | android_color_mode_t colorMode) { |
| 942 | return ComposerService::getComposerService()->setActiveColorMode(display, colorMode); |
| 943 | } |
| 944 | |
Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 945 | void SurfaceComposerClient::setDisplayPowerMode(const sp<IBinder>& token, |
| 946 | int mode) { |
| 947 | ComposerService::getComposerService()->setPowerMode(token, mode); |
Jeff Brown | 2a09bb3 | 2012-10-08 19:13:57 -0700 | [diff] [blame] | 948 | } |
| 949 | |
Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 950 | status_t SurfaceComposerClient::clearAnimationFrameStats() { |
| 951 | return ComposerService::getComposerService()->clearAnimationFrameStats(); |
| 952 | } |
| 953 | |
| 954 | status_t SurfaceComposerClient::getAnimationFrameStats(FrameStats* outStats) { |
| 955 | return ComposerService::getComposerService()->getAnimationFrameStats(outStats); |
| 956 | } |
| 957 | |
Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 958 | status_t SurfaceComposerClient::getHdrCapabilities(const sp<IBinder>& display, |
| 959 | HdrCapabilities* outCapabilities) { |
| 960 | return ComposerService::getComposerService()->getHdrCapabilities(display, |
| 961 | outCapabilities); |
| 962 | } |
| 963 | |
Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 964 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 965 | |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 966 | status_t ScreenshotClient::capture( |
| 967 | const sp<IBinder>& display, |
| 968 | const sp<IGraphicBufferProducer>& producer, |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 969 | Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 970 | int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform) { |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 971 | sp<ISurfaceComposer> s(ComposerService::getComposerService()); |
| 972 | if (s == NULL) return NO_INIT; |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 973 | return s->captureScreen(display, producer, sourceCrop, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 974 | reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform); |
Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 975 | } |
| 976 | |
Robert Carr | 673134e | 2017-01-09 19:48:38 -0800 | [diff] [blame] | 977 | status_t ScreenshotClient::captureToBuffer(const sp<IBinder>& display, |
| 978 | Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 979 | int32_t minLayerZ, int32_t maxLayerZ, bool useIdentityTransform, |
Robert Carr | 673134e | 2017-01-09 19:48:38 -0800 | [diff] [blame] | 980 | uint32_t rotation, |
| 981 | sp<GraphicBuffer>* outBuffer) { |
| 982 | sp<ISurfaceComposer> s(ComposerService::getComposerService()); |
| 983 | if (s == NULL) return NO_INIT; |
| 984 | |
| 985 | sp<IGraphicBufferConsumer> gbpConsumer; |
| 986 | sp<IGraphicBufferProducer> producer; |
| 987 | BufferQueue::createBufferQueue(&producer, &gbpConsumer); |
| 988 | sp<BufferItemConsumer> consumer(new BufferItemConsumer(gbpConsumer, |
| 989 | GRALLOC_USAGE_HW_TEXTURE | GRALLOC_USAGE_SW_READ_NEVER | GRALLOC_USAGE_SW_WRITE_NEVER, |
| 990 | 1, true)); |
| 991 | |
| 992 | status_t ret = s->captureScreen(display, producer, sourceCrop, reqWidth, reqHeight, |
| 993 | minLayerZ, maxLayerZ, useIdentityTransform, |
| 994 | static_cast<ISurfaceComposer::Rotation>(rotation)); |
| 995 | if (ret != NO_ERROR) { |
| 996 | return ret; |
| 997 | } |
| 998 | BufferItem b; |
| 999 | consumer->acquireBuffer(&b, 0, true); |
| 1000 | *outBuffer = b.mGraphicBuffer; |
| 1001 | return ret; |
| 1002 | } |
| 1003 | |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 1004 | ScreenshotClient::ScreenshotClient() |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 1005 | : mHaveBuffer(false) { |
| 1006 | memset(&mBuffer, 0, sizeof(mBuffer)); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 1007 | } |
| 1008 | |
Mathias Agopian | 8000d06 | 2013-03-26 18:15:35 -0700 | [diff] [blame] | 1009 | ScreenshotClient::~ScreenshotClient() { |
| 1010 | ScreenshotClient::release(); |
| 1011 | } |
| 1012 | |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 1013 | sp<CpuConsumer> ScreenshotClient::getCpuConsumer() const { |
| 1014 | if (mCpuConsumer == NULL) { |
Dan Stoza | 6d5a7bb | 2014-03-13 11:39:09 -0700 | [diff] [blame] | 1015 | sp<IGraphicBufferConsumer> consumer; |
| 1016 | BufferQueue::createBufferQueue(&mProducer, &consumer); |
| 1017 | mCpuConsumer = new CpuConsumer(consumer, 1); |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 1018 | mCpuConsumer->setName(String8("ScreenshotClient")); |
| 1019 | } |
| 1020 | return mCpuConsumer; |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 1021 | } |
| 1022 | |
Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 1023 | status_t ScreenshotClient::update(const sp<IBinder>& display, |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 1024 | Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 1025 | int32_t minLayerZ, int32_t maxLayerZ, |
Riley Andrews | d15ef27 | 2014-09-04 16:19:44 -0700 | [diff] [blame] | 1026 | bool useIdentityTransform, uint32_t rotation) { |
Mathias Agopian | bf2c6a6 | 2010-12-10 16:22:31 -0800 | [diff] [blame] | 1027 | sp<ISurfaceComposer> s(ComposerService::getComposerService()); |
| 1028 | if (s == NULL) return NO_INIT; |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 1029 | sp<CpuConsumer> cpuConsumer = getCpuConsumer(); |
| 1030 | |
| 1031 | if (mHaveBuffer) { |
| 1032 | mCpuConsumer->unlockBuffer(mBuffer); |
| 1033 | memset(&mBuffer, 0, sizeof(mBuffer)); |
| 1034 | mHaveBuffer = false; |
| 1035 | } |
| 1036 | |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 1037 | status_t err = s->captureScreen(display, mProducer, sourceCrop, |
Riley Andrews | d15ef27 | 2014-09-04 16:19:44 -0700 | [diff] [blame] | 1038 | reqWidth, reqHeight, minLayerZ, maxLayerZ, useIdentityTransform, |
| 1039 | static_cast<ISurfaceComposer::Rotation>(rotation)); |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 1040 | |
| 1041 | if (err == NO_ERROR) { |
| 1042 | err = mCpuConsumer->lockNextBuffer(&mBuffer); |
| 1043 | if (err == NO_ERROR) { |
| 1044 | mHaveBuffer = true; |
| 1045 | } |
| 1046 | } |
| 1047 | return err; |
| 1048 | } |
| 1049 | |
Riley Andrews | d15ef27 | 2014-09-04 16:19:44 -0700 | [diff] [blame] | 1050 | status_t ScreenshotClient::update(const sp<IBinder>& display, |
| 1051 | Rect sourceCrop, uint32_t reqWidth, uint32_t reqHeight, |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 1052 | int32_t minLayerZ, int32_t maxLayerZ, |
Riley Andrews | d15ef27 | 2014-09-04 16:19:44 -0700 | [diff] [blame] | 1053 | bool useIdentityTransform) { |
| 1054 | |
| 1055 | return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight, |
| 1056 | minLayerZ, maxLayerZ, useIdentityTransform, ISurfaceComposer::eRotateNone); |
| 1057 | } |
| 1058 | |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 1059 | status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 1060 | bool useIdentityTransform) { |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 1061 | return ScreenshotClient::update(display, sourceCrop, 0, 0, |
| 1062 | INT32_MIN, INT32_MAX, |
Riley Andrews | d15ef27 | 2014-09-04 16:19:44 -0700 | [diff] [blame] | 1063 | useIdentityTransform, ISurfaceComposer::eRotateNone); |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 1064 | } |
| 1065 | |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 1066 | status_t ScreenshotClient::update(const sp<IBinder>& display, Rect sourceCrop, |
Dan Stoza | c701401 | 2014-02-14 15:03:43 -0800 | [diff] [blame] | 1067 | uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform) { |
Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 1068 | return ScreenshotClient::update(display, sourceCrop, reqWidth, reqHeight, |
Robert Carr | ae06083 | 2016-11-28 10:51:00 -0800 | [diff] [blame] | 1069 | INT32_MIN, INT32_MAX, |
| 1070 | useIdentityTransform, ISurfaceComposer::eRotateNone); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | void ScreenshotClient::release() { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 1074 | if (mHaveBuffer) { |
| 1075 | mCpuConsumer->unlockBuffer(mBuffer); |
| 1076 | memset(&mBuffer, 0, sizeof(mBuffer)); |
| 1077 | mHaveBuffer = false; |
| 1078 | } |
| 1079 | mCpuConsumer.clear(); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 1080 | } |
| 1081 | |
| 1082 | void const* ScreenshotClient::getPixels() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 1083 | return mBuffer.data; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | uint32_t ScreenshotClient::getWidth() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 1087 | return mBuffer.width; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | uint32_t ScreenshotClient::getHeight() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 1091 | return mBuffer.height; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 1092 | } |
| 1093 | |
| 1094 | PixelFormat ScreenshotClient::getFormat() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 1095 | return mBuffer.format; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
| 1098 | uint32_t ScreenshotClient::getStride() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 1099 | return mBuffer.stride; |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 1100 | } |
| 1101 | |
| 1102 | size_t ScreenshotClient::getSize() const { |
Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 1103 | return mBuffer.stride * mBuffer.height * bytesPerPixel(mBuffer.format); |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 1104 | } |
| 1105 | |
Romain Guy | 88d37dd | 2017-05-26 17:57:05 -0700 | [diff] [blame] | 1106 | android_dataspace ScreenshotClient::getDataSpace() const { |
| 1107 | return mBuffer.dataSpace; |
| 1108 | } |
| 1109 | |
Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 1110 | // ---------------------------------------------------------------------------- |
The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1111 | }; // namespace android |