| 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 | |
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 17 | #ifndef ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H |
| 18 | #define ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | |
| 20 | #include <stdint.h> |
| 21 | #include <sys/types.h> |
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 22 | #include <set> |
| chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 23 | #include <unordered_map> |
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 24 | #include <unordered_set> |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | |
| Mathias Agopian | dd3423c | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 26 | #include <binder/IBinder.h> |
| 27 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | #include <utils/RefBase.h> |
| Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 29 | #include <utils/Singleton.h> |
| 30 | #include <utils/SortedVector.h> |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | #include <utils/threads.h> |
| 32 | |
| Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 33 | #include <ui/ConfigStoreTypes.h> |
| Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 34 | #include <ui/DisplayedFrameStats.h> |
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 35 | #include <ui/FrameStats.h> |
| Peiyong Lin | 9f03447 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 36 | #include <ui/GraphicTypes.h> |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | #include <ui/PixelFormat.h> |
| Mathias Agopian | 9cce325 | 2010-02-09 17:46:37 -0800 | [diff] [blame] | 38 | |
| Mathias Agopian | abe815d | 2013-03-19 22:22:21 -0700 | [diff] [blame] | 39 | #include <gui/CpuConsumer.h> |
| Marissa Wall | 7a9b6ff | 2018-08-21 17:26:20 -0700 | [diff] [blame] | 40 | #include <gui/ITransactionCompletedListener.h> |
| 41 | #include <gui/LayerState.h> |
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 42 | #include <gui/SurfaceControl.h> |
| chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 43 | #include <math/vec3.h> |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | |
| 45 | namespace android { |
| 46 | |
| 47 | // --------------------------------------------------------------------------- |
| 48 | |
| Colin Cross | a2362b4 | 2016-09-26 13:48:25 -0700 | [diff] [blame] | 49 | struct DisplayInfo; |
| Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 50 | class HdrCapabilities; |
| Mathias Agopian | 41f673c | 2011-11-17 17:48:35 -0800 | [diff] [blame] | 51 | class ISurfaceComposerClient; |
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 52 | class IGraphicBufferProducer; |
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 53 | class Region; |
| Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 54 | |
| 55 | // --------------------------------------------------------------------------- |
| 56 | |
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 57 | struct SurfaceControlStats { |
| 58 | SurfaceControlStats(const sp<SurfaceControl>& sc, nsecs_t time, |
| 59 | const sp<Fence>& prevReleaseFence) |
| 60 | : surfaceControl(sc), acquireTime(time), previousReleaseFence(prevReleaseFence) {} |
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 61 | |
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 62 | sp<SurfaceControl> surfaceControl; |
| 63 | nsecs_t acquireTime = -1; |
| 64 | sp<Fence> previousReleaseFence; |
| Marissa Wall | 7a9b6ff | 2018-08-21 17:26:20 -0700 | [diff] [blame] | 65 | }; |
| 66 | |
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 67 | using TransactionCompletedCallbackTakesContext = |
| 68 | std::function<void(void* /*context*/, nsecs_t /*latchTime*/, |
| 69 | const sp<Fence>& /*presentFence*/, |
| 70 | const std::vector<SurfaceControlStats>& /*stats*/)>; |
| 71 | using TransactionCompletedCallback = |
| 72 | std::function<void(nsecs_t /*latchTime*/, const sp<Fence>& /*presentFence*/, |
| 73 | const std::vector<SurfaceControlStats>& /*stats*/)>; |
| 74 | |
| Marissa Wall | 7a9b6ff | 2018-08-21 17:26:20 -0700 | [diff] [blame] | 75 | // --------------------------------------------------------------------------- |
| 76 | |
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 77 | class SurfaceComposerClient : public RefBase |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | { |
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 79 | friend class Composer; |
| Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 80 | public: |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | SurfaceComposerClient(); |
| Jorim Jaggi | f3cf4bc | 2017-11-30 14:19:23 +0100 | [diff] [blame] | 82 | SurfaceComposerClient(const sp<ISurfaceComposerClient>& client); |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 83 | virtual ~SurfaceComposerClient(); |
| 84 | |
| 85 | // Always make sure we could initialize |
| 86 | status_t initCheck() const; |
| 87 | |
| 88 | // Return the connection of this client |
| 89 | sp<IBinder> connection() const; |
| Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 90 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | // Forcibly remove connection before all references have gone away. |
| 92 | void dispose(); |
| 93 | |
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 94 | // callback when the composer is dies |
| 95 | status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient, |
| Yi Kong | a03e044 | 2018-07-17 11:16:57 -0700 | [diff] [blame] | 96 | void* cookie = nullptr, uint32_t flags = 0); |
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 97 | |
| Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 98 | // Get a list of supported configurations for a given display |
| 99 | static status_t getDisplayConfigs(const sp<IBinder>& display, |
| 100 | Vector<DisplayInfo>* configs); |
| 101 | |
| 102 | // Get the DisplayInfo for the currently-active configuration |
| 103 | static status_t getDisplayInfo(const sp<IBinder>& display, |
| 104 | DisplayInfo* info); |
| 105 | |
| 106 | // Get the index of the current active configuration (relative to the list |
| 107 | // returned by getDisplayInfo) |
| 108 | static int getActiveConfig(const sp<IBinder>& display); |
| 109 | |
| 110 | // Set a new active configuration using an index relative to the list |
| 111 | // returned by getDisplayInfo |
| 112 | static status_t setActiveConfig(const sp<IBinder>& display, int id); |
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 113 | |
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 114 | // Gets the list of supported color modes for the given display |
| 115 | static status_t getDisplayColorModes(const sp<IBinder>& display, |
| Peiyong Lin | 9f03447 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 116 | Vector<ui::ColorMode>* outColorModes); |
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 117 | |
| Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 118 | // Get the coordinates of the display's native color primaries |
| 119 | static status_t getDisplayNativePrimaries(const sp<IBinder>& display, |
| 120 | ui::DisplayPrimaries& outPrimaries); |
| 121 | |
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 122 | // Gets the active color mode for the given display |
| Peiyong Lin | 9f03447 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 123 | static ui::ColorMode getActiveColorMode(const sp<IBinder>& display); |
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 124 | |
| 125 | // Sets the active color mode for the given display |
| Peiyong Lin | 9f03447 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 126 | static status_t setActiveColorMode(const sp<IBinder>& display, |
| 127 | ui::ColorMode colorMode); |
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 128 | |
| Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 129 | /* Triggers screen on/off or low power mode and waits for it to complete */ |
| 130 | static void setDisplayPowerMode(const sp<IBinder>& display, int mode); |
| Jeff Brown | 2a09bb3 | 2012-10-08 19:13:57 -0700 | [diff] [blame] | 131 | |
| Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 132 | /* Returns the composition preference of the default data space and default pixel format, |
| 133 | * as well as the wide color gamut data space and wide color gamut pixel format. |
| 134 | * If the wide color gamut data space is V0_SRGB, then it implies that the platform |
| 135 | * has no wide color gamut support. |
| 136 | */ |
| 137 | static status_t getCompositionPreference(ui::Dataspace* defaultDataspace, |
| 138 | ui::PixelFormat* defaultPixelFormat, |
| 139 | ui::Dataspace* wideColorGamutDataspace, |
| 140 | ui::PixelFormat* wideColorGamutPixelFormat); |
| Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 141 | |
| Peiyong Lin | 08d1051 | 2019-01-16 13:27:35 -0800 | [diff] [blame] | 142 | /* |
| 143 | * Gets whether SurfaceFlinger can support protected content in GPU composition. |
| 144 | * Requires the ACCESS_SURFACE_FLINGER permission. |
| 145 | */ |
| 146 | static bool getProtectedContentSupport(); |
| 147 | |
| Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 148 | /** |
| 149 | * Called from SurfaceControl d'tor to 'destroy' the surface (or rather, reparent it |
| 150 | * to null), but without needing an sp<SurfaceControl> to avoid infinite ressurection. |
| 151 | */ |
| 152 | static void doDropReferenceTransaction(const sp<IBinder>& handle, |
| 153 | const sp<ISurfaceComposerClient>& client); |
| 154 | |
| Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 155 | // Queries whether a given display is wide color display. |
| 156 | static status_t isWideColorDisplay(const sp<IBinder>& display, bool* outIsWideColorDisplay); |
| 157 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 158 | // ------------------------------------------------------------------------ |
| 159 | // surface creation / destruction |
| 160 | |
| Robert Carr | fb4d58b | 2019-01-15 09:21:27 -0800 | [diff] [blame] | 161 | static sp<SurfaceComposerClient> getDefault(); |
| 162 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 163 | //! Create a surface |
| Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 164 | sp<SurfaceControl> createSurface(const String8& name, // name of the surface |
| 165 | uint32_t w, // width in pixel |
| 166 | uint32_t h, // height in pixel |
| 167 | PixelFormat format, // pixel-format desired |
| 168 | uint32_t flags = 0, // usage flags |
| 169 | SurfaceControl* parent = nullptr, // parent |
| 170 | LayerMetadata metadata = LayerMetadata() // metadata |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 171 | ); |
| 172 | |
| Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 173 | status_t createSurfaceChecked(const String8& name, // name of the surface |
| 174 | uint32_t w, // width in pixel |
| 175 | uint32_t h, // height in pixel |
| 176 | PixelFormat format, // pixel-format desired |
| 177 | sp<SurfaceControl>* outSurface, |
| 178 | uint32_t flags = 0, // usage flags |
| 179 | SurfaceControl* parent = nullptr, // parent |
| 180 | LayerMetadata metadata = LayerMetadata() // metadata |
| Marissa Wall | 35187b3 | 2019-01-08 10:08:52 -0800 | [diff] [blame] | 181 | ); |
| 182 | |
| 183 | //! Create a surface |
| Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 184 | sp<SurfaceControl> createWithSurfaceParent(const String8& name, // name of the surface |
| 185 | uint32_t w, // width in pixel |
| 186 | uint32_t h, // height in pixel |
| 187 | PixelFormat format, // pixel-format desired |
| 188 | uint32_t flags = 0, // usage flags |
| 189 | Surface* parent = nullptr, // parent |
| 190 | LayerMetadata metadata = LayerMetadata() // metadata |
| Robert Carr | 3b382ed | 2018-03-14 13:49:41 -0700 | [diff] [blame] | 191 | ); |
| 192 | |
| Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 193 | //! Create a virtual display |
| Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 194 | static sp<IBinder> createDisplay(const String8& displayName, bool secure); |
| Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 195 | |
| Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 196 | //! Destroy a virtual display |
| 197 | static void destroyDisplay(const sp<IBinder>& display); |
| 198 | |
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 199 | //! Get stable IDs for connected physical displays |
| 200 | static std::vector<PhysicalDisplayId> getPhysicalDisplayIds(); |
| 201 | static std::optional<PhysicalDisplayId> getInternalDisplayId(); |
| 202 | |
| 203 | //! Get token for a physical display given its stable ID |
| 204 | static sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId); |
| 205 | static sp<IBinder> getInternalDisplayToken(); |
| Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 206 | |
| Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 207 | static status_t enableVSyncInjections(bool enable); |
| 208 | |
| 209 | static status_t injectVSync(nsecs_t when); |
| 210 | |
| chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 211 | struct SCHash { |
| 212 | std::size_t operator()(const sp<SurfaceControl>& sc) const { |
| 213 | return std::hash<SurfaceControl *>{}(sc.get()); |
| 214 | } |
| 215 | }; |
| 216 | |
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 217 | struct TCLHash { |
| 218 | std::size_t operator()(const sp<ITransactionCompletedListener>& tcl) const { |
| 219 | return std::hash<IBinder*>{}((tcl) ? IInterface::asBinder(tcl).get() : nullptr); |
| 220 | } |
| 221 | }; |
| 222 | |
| 223 | struct CallbackInfo { |
| 224 | // All the callbacks that have been requested for a TransactionCompletedListener in the |
| 225 | // Transaction |
| 226 | std::unordered_set<CallbackId> callbackIds; |
| 227 | // All the SurfaceControls that have been modified in this TransactionCompletedListener's |
| 228 | // process that require a callback if there is one or more callbackIds set. |
| 229 | std::unordered_set<sp<SurfaceControl>, SCHash> surfaceControls; |
| 230 | }; |
| 231 | |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 232 | class Transaction { |
| chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 233 | std::unordered_map<sp<SurfaceControl>, ComposerState, SCHash> mComposerStates; |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 234 | SortedVector<DisplayState > mDisplayStates; |
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 235 | std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> |
| 236 | mListenerCallbacks; |
| 237 | |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 238 | uint32_t mForceSynchronous = 0; |
| 239 | uint32_t mTransactionNestCount = 0; |
| 240 | bool mAnimation = false; |
| Dan Stoza | 84d619e | 2018-03-28 17:07:36 -0700 | [diff] [blame] | 241 | bool mEarlyWakeup = false; |
| Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 242 | |
| Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 243 | // mDesiredPresentTime is the time in nanoseconds that the client would like the transaction |
| 244 | // to be presented. When it is not possible to present at exactly that time, it will be |
| 245 | // presented after the time has passed. |
| 246 | // |
| 247 | // Desired present times that are more than 1 second in the future may be ignored. |
| 248 | // When a desired present time has already passed, the transaction will be presented as soon |
| 249 | // as possible. |
| 250 | // |
| 251 | // Transactions from the same process are presented in the same order that they are applied. |
| 252 | // The desired present time does not affect this ordering. |
| 253 | int64_t mDesiredPresentTime = -1; |
| 254 | |
| chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 255 | InputWindowCommands mInputWindowCommands; |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 256 | int mStatus = NO_ERROR; |
| 257 | |
| chaviw | 763ef57 | 2018-02-22 16:04:57 -0800 | [diff] [blame] | 258 | layer_state_t* getLayerState(const sp<SurfaceControl>& sc); |
| 259 | DisplayState& getDisplayState(const sp<IBinder>& token); |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 260 | |
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 261 | void registerSurfaceControlForCallback(const sp<SurfaceControl>& sc); |
| 262 | |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 263 | public: |
| 264 | Transaction() = default; |
| 265 | virtual ~Transaction() = default; |
| 266 | Transaction(Transaction const& other); |
| 267 | |
| 268 | status_t apply(bool synchronous = false); |
| Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 269 | // Merge another transaction in to this one, clearing other |
| 270 | // as if it had been applied. |
| 271 | Transaction& merge(Transaction&& other); |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 272 | Transaction& show(const sp<SurfaceControl>& sc); |
| 273 | Transaction& hide(const sp<SurfaceControl>& sc); |
| 274 | Transaction& setPosition(const sp<SurfaceControl>& sc, |
| 275 | float x, float y); |
| 276 | Transaction& setSize(const sp<SurfaceControl>& sc, |
| 277 | uint32_t w, uint32_t h); |
| 278 | Transaction& setLayer(const sp<SurfaceControl>& sc, |
| 279 | int32_t z); |
| 280 | |
| 281 | // Sets a Z order relative to the Surface specified by "relativeTo" but |
| 282 | // without becoming a full child of the relative. Z-ordering works exactly |
| 283 | // as if it were a child however. |
| 284 | // |
| 285 | // As a nod to sanity, only non-child surfaces may have a relative Z-order. |
| 286 | // |
| 287 | // This overrides any previous call and is overriden by any future calls |
| 288 | // to setLayer. |
| 289 | // |
| 290 | // If the relative is removed, the Surface will have no layer and be |
| 291 | // invisible, until the next time set(Relative)Layer is called. |
| 292 | Transaction& setRelativeLayer(const sp<SurfaceControl>& sc, |
| 293 | const sp<IBinder>& relativeTo, int32_t z); |
| 294 | Transaction& setFlags(const sp<SurfaceControl>& sc, |
| 295 | uint32_t flags, uint32_t mask); |
| 296 | Transaction& setTransparentRegionHint(const sp<SurfaceControl>& sc, |
| 297 | const Region& transparentRegion); |
| 298 | Transaction& setAlpha(const sp<SurfaceControl>& sc, |
| 299 | float alpha); |
| 300 | Transaction& setMatrix(const sp<SurfaceControl>& sc, |
| 301 | float dsdx, float dtdx, float dtdy, float dsdy); |
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 302 | Transaction& setCrop_legacy(const sp<SurfaceControl>& sc, const Rect& crop); |
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 303 | Transaction& setCornerRadius(const sp<SurfaceControl>& sc, float cornerRadius); |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 304 | Transaction& setLayerStack(const sp<SurfaceControl>& sc, uint32_t layerStack); |
| Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 305 | Transaction& setMetadata(const sp<SurfaceControl>& sc, uint32_t key, |
| 306 | std::vector<uint8_t> data); |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 307 | // Defers applying any changes made in this transaction until the Layer |
| 308 | // identified by handle reaches the given frameNumber. If the Layer identified |
| 309 | // by handle is removed, then we will apply this transaction regardless of |
| 310 | // what frame number has been reached. |
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 311 | Transaction& deferTransactionUntil_legacy(const sp<SurfaceControl>& sc, |
| 312 | const sp<IBinder>& handle, uint64_t frameNumber); |
| 313 | // A variant of deferTransactionUntil_legacy which identifies the Layer we wait for by |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 314 | // Surface instead of Handle. Useful for clients which may not have the |
| 315 | // SurfaceControl for some of their Surfaces. Otherwise behaves identically. |
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 316 | Transaction& deferTransactionUntil_legacy(const sp<SurfaceControl>& sc, |
| 317 | const sp<Surface>& barrierSurface, |
| 318 | uint64_t frameNumber); |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 319 | // Reparents all children of this layer to the new parent handle. |
| 320 | Transaction& reparentChildren(const sp<SurfaceControl>& sc, |
| 321 | const sp<IBinder>& newParentHandle); |
| 322 | |
| 323 | /// Reparents the current layer to the new parent handle. The new parent must not be null. |
| 324 | // This can be used instead of reparentChildren if the caller wants to |
| 325 | // only re-parent a specific child. |
| 326 | Transaction& reparent(const sp<SurfaceControl>& sc, |
| 327 | const sp<IBinder>& newParentHandle); |
| 328 | |
| 329 | Transaction& setColor(const sp<SurfaceControl>& sc, const half3& color); |
| 330 | |
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 331 | // Sets the background color of a layer with the specified color, alpha, and dataspace |
| 332 | Transaction& setBackgroundColor(const sp<SurfaceControl>& sc, const half3& color, |
| 333 | float alpha, ui::Dataspace dataspace); |
| Valerie Hau | ed54efa | 2019-01-11 20:03:14 -0800 | [diff] [blame] | 334 | |
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 335 | Transaction& setTransform(const sp<SurfaceControl>& sc, uint32_t transform); |
| 336 | Transaction& setTransformToDisplayInverse(const sp<SurfaceControl>& sc, |
| 337 | bool transformToDisplayInverse); |
| 338 | Transaction& setCrop(const sp<SurfaceControl>& sc, const Rect& crop); |
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 339 | Transaction& setFrame(const sp<SurfaceControl>& sc, const Rect& frame); |
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 340 | Transaction& setBuffer(const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer); |
| Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 341 | Transaction& setCachedBuffer(const sp<SurfaceControl>& sc, int32_t bufferId); |
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 342 | Transaction& setAcquireFence(const sp<SurfaceControl>& sc, const sp<Fence>& fence); |
| 343 | Transaction& setDataspace(const sp<SurfaceControl>& sc, ui::Dataspace dataspace); |
| 344 | Transaction& setHdrMetadata(const sp<SurfaceControl>& sc, const HdrMetadata& hdrMetadata); |
| 345 | Transaction& setSurfaceDamageRegion(const sp<SurfaceControl>& sc, |
| 346 | const Region& surfaceDamageRegion); |
| 347 | Transaction& setApi(const sp<SurfaceControl>& sc, int32_t api); |
| 348 | Transaction& setSidebandStream(const sp<SurfaceControl>& sc, |
| 349 | const sp<NativeHandle>& sidebandStream); |
| Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 350 | Transaction& setDesiredPresentTime(nsecs_t desiredPresentTime); |
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 351 | |
| Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 352 | Transaction& addTransactionCompletedCallback( |
| 353 | TransactionCompletedCallbackTakesContext callback, void* callbackContext); |
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 354 | |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 355 | // Detaches all child surfaces (and their children recursively) |
| 356 | // from their SurfaceControl. |
| 357 | // The child SurfaceControls will not throw exceptions or return errors, |
| 358 | // but transactions will have no effect. |
| 359 | // The child surfaces will continue to follow their parent surfaces, |
| 360 | // and remain eligible for rendering, but their relative state will be |
| 361 | // frozen. We use this in the WindowManager, in app shutdown/relaunch |
| 362 | // scenarios, where the app would otherwise clean up its child Surfaces. |
| 363 | // Sometimes the WindowManager needs to extend their lifetime slightly |
| 364 | // in order to perform an exit animation or prevent flicker. |
| 365 | Transaction& detachChildren(const sp<SurfaceControl>& sc); |
| 366 | // Set an override scaling mode as documented in <system/window.h> |
| 367 | // the override scaling mode will take precedence over any client |
| 368 | // specified scaling mode. -1 will clear the override scaling mode. |
| 369 | Transaction& setOverrideScalingMode(const sp<SurfaceControl>& sc, |
| 370 | int32_t overrideScalingMode); |
| 371 | |
| 372 | // If the size changes in this transaction, all geometry updates specified |
| 373 | // in this transaction will not complete until a buffer of the new size |
| 374 | // arrives. As some elements normally apply immediately, this enables |
| 375 | // freezing the total geometry of a surface until a resize is completed. |
| 376 | Transaction& setGeometryAppliesWithResize(const sp<SurfaceControl>& sc); |
| 377 | |
| Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 378 | #ifndef NO_INPUT |
| 379 | Transaction& setInputWindowInfo(const sp<SurfaceControl>& sc, const InputWindowInfo& info); |
| chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 380 | Transaction& transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken); |
| Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 381 | #endif |
| 382 | |
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 383 | // Set a color transform matrix on the given layer on the built-in display. |
| 384 | Transaction& setColorTransform(const sp<SurfaceControl>& sc, const mat3& matrix, |
| 385 | const vec3& translation); |
| 386 | |
| Robert Carr | fb4d58b | 2019-01-15 09:21:27 -0800 | [diff] [blame] | 387 | Transaction& setGeometry(const sp<SurfaceControl>& sc, |
| 388 | const Rect& source, const Rect& dst, int transform); |
| 389 | |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 390 | status_t setDisplaySurface(const sp<IBinder>& token, |
| 391 | const sp<IGraphicBufferProducer>& bufferProducer); |
| 392 | |
| 393 | void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack); |
| 394 | |
| 395 | /* setDisplayProjection() defines the projection of layer stacks |
| 396 | * to a given display. |
| 397 | * |
| 398 | * - orientation defines the display's orientation. |
| 399 | * - layerStackRect defines which area of the window manager coordinate |
| 400 | * space will be used. |
| 401 | * - displayRect defines where on the display will layerStackRect be |
| 402 | * mapped to. displayRect is specified post-orientation, that is |
| 403 | * it uses the orientation seen by the end-user. |
| 404 | */ |
| 405 | void setDisplayProjection(const sp<IBinder>& token, |
| 406 | uint32_t orientation, |
| 407 | const Rect& layerStackRect, |
| 408 | const Rect& displayRect); |
| 409 | void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height); |
| 410 | void setAnimationTransaction(); |
| Dan Stoza | 84d619e | 2018-03-28 17:07:36 -0700 | [diff] [blame] | 411 | void setEarlyWakeup(); |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 412 | }; |
| Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 413 | |
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 414 | status_t clearLayerFrameStats(const sp<IBinder>& token) const; |
| 415 | status_t getLayerFrameStats(const sp<IBinder>& token, FrameStats* outStats) const; |
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 416 | static status_t clearAnimationFrameStats(); |
| 417 | static status_t getAnimationFrameStats(FrameStats* outStats); |
| 418 | |
| Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 419 | static status_t getHdrCapabilities(const sp<IBinder>& display, |
| 420 | HdrCapabilities* outCapabilities); |
| 421 | |
| Mathias Agopian | 00e8c7a | 2012-09-04 19:30:46 -0700 | [diff] [blame] | 422 | static void setDisplayProjection(const sp<IBinder>& token, |
| 423 | uint32_t orientation, |
| 424 | const Rect& layerStackRect, |
| 425 | const Rect& displayRect); |
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 426 | |
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 427 | inline sp<ISurfaceComposerClient> getClient() { return mClient; } |
| 428 | |
| Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 429 | static status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display, |
| 430 | ui::PixelFormat* outFormat, |
| 431 | ui::Dataspace* outDataspace, |
| 432 | uint8_t* outComponentMask); |
| Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 433 | static status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable, |
| 434 | uint8_t componentMask, uint64_t maxFrames); |
| Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 435 | |
| Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 436 | static status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames, |
| 437 | uint64_t timestamp, DisplayedFrameStats* outStats); |
| 438 | |
| Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 439 | private: |
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 440 | virtual void onFirstRef(); |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 441 | |
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 442 | mutable Mutex mLock; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 443 | status_t mStatus; |
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 444 | sp<ISurfaceComposerClient> mClient; |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 445 | }; |
| 446 | |
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 447 | // --------------------------------------------------------------------------- |
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 448 | |
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 449 | class ScreenshotClient { |
| Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 450 | public: |
| Dan Stoza | c187900 | 2014-05-22 15:59:05 -0700 | [diff] [blame] | 451 | // if cropping isn't required, callers may pass in a default Rect, e.g.: |
| 452 | // capture(display, producer, Rect(), reqWidth, ...); |
| Peiyong Lin | 0e003c9 | 2018-09-17 11:09:51 -0700 | [diff] [blame] | 453 | static status_t capture(const sp<IBinder>& display, const ui::Dataspace reqDataSpace, |
| 454 | const ui::PixelFormat reqPixelFormat, Rect sourceCrop, |
| 455 | uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform, |
| 456 | uint32_t rotation, sp<GraphicBuffer>* outBuffer); |
| 457 | static status_t captureLayers(const sp<IBinder>& layerHandle, const ui::Dataspace reqDataSpace, |
| 458 | const ui::PixelFormat reqPixelFormat, Rect sourceCrop, |
| 459 | float frameScale, sp<GraphicBuffer>* outBuffer); |
| 460 | static status_t captureChildLayers(const sp<IBinder>& layerHandle, |
| 461 | const ui::Dataspace reqDataSpace, |
| 462 | const ui::PixelFormat reqPixelFormat, Rect sourceCrop, |
| Robert Carr | 578038f | 2018-03-09 12:25:24 -0800 | [diff] [blame] | 463 | float frameScale, sp<GraphicBuffer>* outBuffer); |
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 464 | }; |
| 465 | |
| 466 | // --------------------------------------------------------------------------- |
| Marissa Wall | 7a9b6ff | 2018-08-21 17:26:20 -0700 | [diff] [blame] | 467 | |
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 468 | class TransactionCompletedListener : public BnTransactionCompletedListener { |
| 469 | TransactionCompletedListener(); |
| 470 | |
| 471 | CallbackId getNextIdLocked() REQUIRES(mMutex); |
| 472 | |
| 473 | std::mutex mMutex; |
| 474 | |
| 475 | bool mListening GUARDED_BY(mMutex) = false; |
| 476 | |
| 477 | CallbackId mCallbackIdCounter GUARDED_BY(mMutex) = 1; |
| 478 | |
| 479 | struct IBinderHash { |
| 480 | std::size_t operator()(const sp<IBinder>& iBinder) const { |
| 481 | return std::hash<IBinder*>{}(iBinder.get()); |
| 482 | } |
| 483 | }; |
| 484 | |
| 485 | struct CallbackTranslation { |
| 486 | TransactionCompletedCallback callbackFunction; |
| 487 | std::unordered_map<sp<IBinder>, sp<SurfaceControl>, IBinderHash> surfaceControls; |
| 488 | }; |
| 489 | |
| 490 | std::unordered_map<CallbackId, CallbackTranslation> mCallbacks GUARDED_BY(mMutex); |
| 491 | |
| 492 | public: |
| 493 | static sp<TransactionCompletedListener> getInstance(); |
| 494 | static sp<ITransactionCompletedListener> getIInstance(); |
| 495 | |
| 496 | void startListeningLocked() REQUIRES(mMutex); |
| 497 | |
| 498 | CallbackId addCallbackFunction( |
| 499 | const TransactionCompletedCallback& callbackFunction, |
| 500 | const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>& |
| 501 | surfaceControls); |
| 502 | |
| 503 | void addSurfaceControlToCallbacks(const sp<SurfaceControl>& surfaceControl, |
| 504 | const std::unordered_set<CallbackId>& callbackIds); |
| 505 | |
| 506 | // Overrides BnTransactionCompletedListener's onTransactionCompleted |
| 507 | void onTransactionCompleted(ListenerStats stats) override; |
| 508 | }; |
| 509 | |
| 510 | // --------------------------------------------------------------------------- |
| 511 | |
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 512 | }; // namespace android |
| 513 | |
| Mathias Agopian | 90ac799 | 2012-02-25 18:48:35 -0800 | [diff] [blame] | 514 | #endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H |