| 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 |  | 
| Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 17 | #pragma once | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 |  | 
|  | 19 | #include <stdint.h> | 
|  | 20 | #include <sys/types.h> | 
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 21 | #include <set> | 
| chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 22 | #include <unordered_map> | 
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 23 | #include <unordered_set> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 |  | 
| Mathias Agopian | dd3423c | 2009-09-23 15:44:05 -0700 | [diff] [blame] | 25 | #include <binder/IBinder.h> | 
|  | 26 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | #include <utils/RefBase.h> | 
| Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 28 | #include <utils/Singleton.h> | 
|  | 29 | #include <utils/SortedVector.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | #include <utils/threads.h> | 
|  | 31 |  | 
| Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 32 | #include <ui/ConfigStoreTypes.h> | 
| Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 33 | #include <ui/DisplayedFrameStats.h> | 
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 34 | #include <ui/FrameStats.h> | 
| Peiyong Lin | 9f03447 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 35 | #include <ui/GraphicTypes.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | #include <ui/PixelFormat.h> | 
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 37 | #include <ui/Rotation.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> | 
| Robert Carr | 866455f | 2019-04-02 16:28:26 -0700 | [diff] [blame] | 40 | #include <gui/ISurfaceComposer.h> | 
| Marissa Wall | 7a9b6ff | 2018-08-21 17:26:20 -0700 | [diff] [blame] | 41 | #include <gui/ITransactionCompletedListener.h> | 
|  | 42 | #include <gui/LayerState.h> | 
| Mathias Agopian | e3c697f | 2013-02-14 17:11:02 -0800 | [diff] [blame] | 43 | #include <gui/SurfaceControl.h> | 
| chaviw | 13fdc49 | 2017-06-27 12:40:18 -0700 | [diff] [blame] | 44 | #include <math/vec3.h> | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 45 |  | 
|  | 46 | namespace android { | 
|  | 47 |  | 
| Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 48 | class HdrCapabilities; | 
| Mathias Agopian | 41f673c | 2011-11-17 17:48:35 -0800 | [diff] [blame] | 49 | class ISurfaceComposerClient; | 
| Andy McFadden | 2adaf04 | 2012-12-18 09:49:45 -0800 | [diff] [blame] | 50 | class IGraphicBufferProducer; | 
| Kevin DuBois | 00c6683 | 2019-02-18 16:21:31 -0800 | [diff] [blame] | 51 | class IRegionSamplingListener; | 
| Mathias Agopian | a67932f | 2011-04-20 14:20:59 -0700 | [diff] [blame] | 52 | class Region; | 
| Mathias Agopian | b7e930d | 2010-06-01 15:12:58 -0700 | [diff] [blame] | 53 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 54 | struct SurfaceControlStats { | 
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 55 | SurfaceControlStats(const sp<SurfaceControl>& sc, nsecs_t latchTime, nsecs_t acquireTime, | 
|  | 56 | const sp<Fence>& presentFence, const sp<Fence>& prevReleaseFence, | 
|  | 57 | uint32_t hint, FrameEventHistoryStats eventStats) | 
| Valerie Hau | 32cdc1f | 2019-10-21 14:45:54 -0700 | [diff] [blame] | 58 | : surfaceControl(sc), | 
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 59 | latchTime(latchTime), | 
|  | 60 | acquireTime(acquireTime), | 
|  | 61 | presentFence(presentFence), | 
| Valerie Hau | 32cdc1f | 2019-10-21 14:45:54 -0700 | [diff] [blame] | 62 | previousReleaseFence(prevReleaseFence), | 
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 63 | transformHint(hint), | 
|  | 64 | frameEventStats(eventStats) {} | 
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 65 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 66 | sp<SurfaceControl> surfaceControl; | 
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 67 | nsecs_t latchTime = -1; | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 68 | nsecs_t acquireTime = -1; | 
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 69 | sp<Fence> presentFence; | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 70 | sp<Fence> previousReleaseFence; | 
| Valerie Hau | 32cdc1f | 2019-10-21 14:45:54 -0700 | [diff] [blame] | 71 | uint32_t transformHint = 0; | 
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 72 | FrameEventHistoryStats frameEventStats; | 
| Marissa Wall | 7a9b6ff | 2018-08-21 17:26:20 -0700 | [diff] [blame] | 73 | }; | 
|  | 74 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 75 | using TransactionCompletedCallbackTakesContext = | 
|  | 76 | std::function<void(void* /*context*/, nsecs_t /*latchTime*/, | 
|  | 77 | const sp<Fence>& /*presentFence*/, | 
|  | 78 | const std::vector<SurfaceControlStats>& /*stats*/)>; | 
|  | 79 | using TransactionCompletedCallback = | 
|  | 80 | std::function<void(nsecs_t /*latchTime*/, const sp<Fence>& /*presentFence*/, | 
|  | 81 | const std::vector<SurfaceControlStats>& /*stats*/)>; | 
|  | 82 |  | 
| Marissa Wall | 7a9b6ff | 2018-08-21 17:26:20 -0700 | [diff] [blame] | 83 | // --------------------------------------------------------------------------- | 
|  | 84 |  | 
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 85 | class SurfaceComposerClient : public RefBase | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 86 | { | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 87 | friend class Composer; | 
| Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 88 | public: | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | SurfaceComposerClient(); | 
| Jorim Jaggi | f3cf4bc | 2017-11-30 14:19:23 +0100 | [diff] [blame] | 90 | SurfaceComposerClient(const sp<ISurfaceComposerClient>& client); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | virtual     ~SurfaceComposerClient(); | 
|  | 92 |  | 
|  | 93 | // Always make sure we could initialize | 
|  | 94 | status_t    initCheck() const; | 
|  | 95 |  | 
|  | 96 | // Return the connection of this client | 
|  | 97 | sp<IBinder> connection() const; | 
| Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 98 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | // Forcibly remove connection before all references have gone away. | 
|  | 100 | void        dispose(); | 
|  | 101 |  | 
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 102 | // callback when the composer is dies | 
|  | 103 | status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient, | 
| Yi Kong | a03e044 | 2018-07-17 11:16:57 -0700 | [diff] [blame] | 104 | void* cookie = nullptr, uint32_t flags = 0); | 
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 105 |  | 
| Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 106 | // Get transactional state of given display. | 
|  | 107 | static status_t getDisplayState(const sp<IBinder>& display, ui::DisplayState*); | 
| Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 108 |  | 
| Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 109 | // Get immutable information about given physical display. | 
|  | 110 | static status_t getDisplayInfo(const sp<IBinder>& display, DisplayInfo*); | 
| Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 111 |  | 
| Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 112 | // Get configurations supported by given physical display. | 
|  | 113 | static status_t getDisplayConfigs(const sp<IBinder>& display, Vector<DisplayConfig>*); | 
|  | 114 |  | 
|  | 115 | // Get the ID of the active DisplayConfig, as getDisplayConfigs index. | 
| Dan Stoza | 7f7da32 | 2014-05-02 15:26:25 -0700 | [diff] [blame] | 116 | static int getActiveConfig(const sp<IBinder>& display); | 
|  | 117 |  | 
| Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 118 | // Shorthand for getDisplayConfigs element at getActiveConfig index. | 
|  | 119 | static status_t getActiveDisplayConfig(const sp<IBinder>& display, DisplayConfig*); | 
|  | 120 |  | 
| Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 121 | // Sets the refresh rate boundaries for the display. | 
| Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 122 | static status_t setDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken, | 
| Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 123 | int32_t defaultConfig, float primaryRefreshRateMin, | 
|  | 124 | float primaryRefreshRateMax, | 
|  | 125 | float appRequestRefreshRateMin, | 
|  | 126 | float appRequestRefreshRateMax); | 
|  | 127 | // Gets the refresh rate boundaries for the display. | 
| Ana Krulec | 234bb16 | 2019-11-10 22:55:55 +0100 | [diff] [blame] | 128 | static status_t getDesiredDisplayConfigSpecs(const sp<IBinder>& displayToken, | 
| Ana Krulec | ed3a8cc | 2019-11-14 00:55:07 +0100 | [diff] [blame] | 129 | int32_t* outDefaultConfig, | 
| Steven Thomas | f734df4 | 2020-04-13 21:09:28 -0700 | [diff] [blame] | 130 | float* outPrimaryRefreshRateMin, | 
|  | 131 | float* outPrimaryRefreshRateMax, | 
|  | 132 | float* outAppRequestRefreshRateMin, | 
|  | 133 | float* outAppRequestRefreshRateMax); | 
| Ana Krulec | 0782b88 | 2019-10-15 17:34:54 -0700 | [diff] [blame] | 134 |  | 
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 135 | // Gets the list of supported color modes for the given display | 
|  | 136 | static status_t getDisplayColorModes(const sp<IBinder>& display, | 
| Peiyong Lin | 9f03447 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 137 | Vector<ui::ColorMode>* outColorModes); | 
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 138 |  | 
| Daniel Solomon | 42d0456 | 2019-01-20 21:03:19 -0800 | [diff] [blame] | 139 | // Get the coordinates of the display's native color primaries | 
|  | 140 | static status_t getDisplayNativePrimaries(const sp<IBinder>& display, | 
|  | 141 | ui::DisplayPrimaries& outPrimaries); | 
|  | 142 |  | 
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 143 | // Gets the active color mode for the given display | 
| Peiyong Lin | 9f03447 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 144 | static ui::ColorMode getActiveColorMode(const sp<IBinder>& display); | 
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 145 |  | 
|  | 146 | // Sets the active color mode for the given display | 
| Peiyong Lin | 9f03447 | 2018-03-28 15:29:00 -0700 | [diff] [blame] | 147 | static status_t setActiveColorMode(const sp<IBinder>& display, | 
|  | 148 | ui::ColorMode colorMode); | 
| Michael Wright | 28f24d0 | 2016-07-12 13:30:53 -0700 | [diff] [blame] | 149 |  | 
| Galia Peycheva | 5492cb5 | 2019-10-30 14:13:16 +0100 | [diff] [blame] | 150 | // Reports whether the connected display supports Auto Low Latency Mode | 
|  | 151 | static bool getAutoLowLatencyModeSupport(const sp<IBinder>& display); | 
|  | 152 |  | 
|  | 153 | // Switches on/off Auto Low Latency Mode on the connected display. This should only be | 
|  | 154 | // called if the connected display supports Auto Low Latency Mode as reported by | 
|  | 155 | // #getAutoLowLatencyModeSupport | 
|  | 156 | static void setAutoLowLatencyMode(const sp<IBinder>& display, bool on); | 
|  | 157 |  | 
|  | 158 | // Reports whether the connected display supports Game content type | 
|  | 159 | static bool getGameContentTypeSupport(const sp<IBinder>& display); | 
|  | 160 |  | 
|  | 161 | // Turns Game mode on/off on the connected display. This should only be called | 
|  | 162 | // if the display supports Game content type, as reported by #getGameContentTypeSupport | 
|  | 163 | static void setGameContentType(const sp<IBinder>& display, bool on); | 
|  | 164 |  | 
| Prashant Malani | 2c9b11f | 2014-05-25 01:36:31 -0700 | [diff] [blame] | 165 | /* Triggers screen on/off or low power mode and waits for it to complete */ | 
|  | 166 | static void setDisplayPowerMode(const sp<IBinder>& display, int mode); | 
| Jeff Brown | 2a09bb3 | 2012-10-08 19:13:57 -0700 | [diff] [blame] | 167 |  | 
| Peiyong Lin | c678097 | 2018-10-28 15:24:08 -0700 | [diff] [blame] | 168 | /* Returns the composition preference of the default data space and default pixel format, | 
|  | 169 | * as well as the wide color gamut data space and wide color gamut pixel format. | 
|  | 170 | * If the wide color gamut data space is V0_SRGB, then it implies that the platform | 
|  | 171 | * has no wide color gamut support. | 
|  | 172 | */ | 
|  | 173 | static status_t getCompositionPreference(ui::Dataspace* defaultDataspace, | 
|  | 174 | ui::PixelFormat* defaultPixelFormat, | 
|  | 175 | ui::Dataspace* wideColorGamutDataspace, | 
|  | 176 | ui::PixelFormat* wideColorGamutPixelFormat); | 
| Peiyong Lin | 0256f72 | 2018-08-31 15:45:10 -0700 | [diff] [blame] | 177 |  | 
| Peiyong Lin | 08d1051 | 2019-01-16 13:27:35 -0800 | [diff] [blame] | 178 | /* | 
|  | 179 | * Gets whether SurfaceFlinger can support protected content in GPU composition. | 
|  | 180 | * Requires the ACCESS_SURFACE_FLINGER permission. | 
|  | 181 | */ | 
|  | 182 | static bool getProtectedContentSupport(); | 
|  | 183 |  | 
| Robert Carr | 6fb1a7e | 2018-12-11 12:07:25 -0800 | [diff] [blame] | 184 | /** | 
| Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 185 | * Uncaches a buffer in ISurfaceComposer. It must be uncached via a transaction so that it is | 
|  | 186 | * in order with other transactions that use buffers. | 
|  | 187 | */ | 
|  | 188 | static void doUncacheBufferTransaction(uint64_t cacheId); | 
|  | 189 |  | 
| Peiyong Lin | 4f3fddf | 2019-01-24 17:21:24 -0800 | [diff] [blame] | 190 | // Queries whether a given display is wide color display. | 
|  | 191 | static status_t isWideColorDisplay(const sp<IBinder>& display, bool* outIsWideColorDisplay); | 
|  | 192 |  | 
| Dan Gittik | 57e63c5 | 2019-01-18 16:37:54 +0000 | [diff] [blame] | 193 | /* | 
|  | 194 | * Returns whether brightness operations are supported on a display. | 
|  | 195 | * | 
|  | 196 | * displayToken | 
|  | 197 | *      The token of the display. | 
|  | 198 | * | 
|  | 199 | * Returns whether brightness operations are supported on a display or not. | 
|  | 200 | */ | 
|  | 201 | static bool getDisplayBrightnessSupport(const sp<IBinder>& displayToken); | 
|  | 202 |  | 
|  | 203 | /* | 
|  | 204 | * Sets the brightness of a display. | 
|  | 205 | * | 
|  | 206 | * displayToken | 
|  | 207 | *      The token of the display whose brightness is set. | 
|  | 208 | * brightness | 
|  | 209 | *      A number between 0.0 (minimum brightness) and 1.0 (maximum brightness), or -1.0f to | 
|  | 210 | *      turn the backlight off. | 
|  | 211 | * | 
|  | 212 | * Returns NO_ERROR upon success. Otherwise, | 
|  | 213 | *      NAME_NOT_FOUND    if the display handle is invalid, or | 
|  | 214 | *      BAD_VALUE         if the brightness value is invalid, or | 
|  | 215 | *      INVALID_OPERATION if brightness operaetions are not supported. | 
|  | 216 | */ | 
|  | 217 | static status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness); | 
|  | 218 |  | 
| Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 219 | /* | 
| Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 220 | * Sends a power boost to the composer. This function is asynchronous. | 
| Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 221 | * | 
| Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 222 | * boostId | 
|  | 223 | *      boost id according to android::hardware::power::Boost | 
| Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 224 | * | 
|  | 225 | * Returns NO_ERROR upon success. | 
|  | 226 | */ | 
| Lais Andrade | 3a6e47d | 2020-04-02 11:20:16 +0100 | [diff] [blame] | 227 | static status_t notifyPowerBoost(int32_t boostId); | 
| Ady Abraham | 8532d01 | 2019-05-08 14:50:56 -0700 | [diff] [blame] | 228 |  | 
| Vishnu Nair | b13bb95 | 2019-11-15 10:24:08 -0800 | [diff] [blame] | 229 | /* | 
|  | 230 | * Sets the global configuration for all the shadows drawn by SurfaceFlinger. Shadow follows | 
|  | 231 | * material design guidelines. | 
|  | 232 | * | 
|  | 233 | * ambientColor | 
|  | 234 | *      Color to the ambient shadow. The alpha is premultiplied. | 
|  | 235 | * | 
|  | 236 | * spotColor | 
|  | 237 | *      Color to the spot shadow. The alpha is premultiplied. The position of the spot shadow | 
|  | 238 | *      depends on the light position. | 
|  | 239 | * | 
|  | 240 | * lightPosY/lightPosZ | 
|  | 241 | *      Position of the light used to cast the spot shadow. The X value is always the display | 
|  | 242 | *      width / 2. | 
|  | 243 | * | 
|  | 244 | * lightRadius | 
|  | 245 | *      Radius of the light casting the shadow. | 
|  | 246 | */ | 
|  | 247 | static status_t setGlobalShadowSettings(const half4& ambientColor, const half4& spotColor, | 
|  | 248 | float lightPosY, float lightPosZ, float lightRadius); | 
|  | 249 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 250 | // ------------------------------------------------------------------------ | 
|  | 251 | // surface creation / destruction | 
|  | 252 |  | 
| Robert Carr | fb4d58b | 2019-01-15 09:21:27 -0800 | [diff] [blame] | 253 | static sp<SurfaceComposerClient> getDefault(); | 
|  | 254 |  | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | //! Create a surface | 
| Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 256 | sp<SurfaceControl> createSurface(const String8& name,              // name of the surface | 
|  | 257 | uint32_t w,                       // width in pixel | 
|  | 258 | uint32_t h,                       // height in pixel | 
|  | 259 | PixelFormat format,               // pixel-format desired | 
|  | 260 | uint32_t flags = 0,               // usage flags | 
|  | 261 | SurfaceControl* parent = nullptr, // parent | 
| Valerie Hau | 1acd696 | 2019-10-28 16:35:48 -0700 | [diff] [blame] | 262 | LayerMetadata metadata = LayerMetadata(), // metadata | 
|  | 263 | uint32_t* outTransformHint = nullptr); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 264 |  | 
| Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 265 | status_t createSurfaceChecked(const String8& name, // name of the surface | 
|  | 266 | uint32_t w,          // width in pixel | 
|  | 267 | uint32_t h,          // height in pixel | 
|  | 268 | PixelFormat format,  // pixel-format desired | 
|  | 269 | sp<SurfaceControl>* outSurface, | 
| Valerie Hau | 1acd696 | 2019-10-28 16:35:48 -0700 | [diff] [blame] | 270 | uint32_t flags = 0,                       // usage flags | 
|  | 271 | SurfaceControl* parent = nullptr,         // parent | 
|  | 272 | LayerMetadata metadata = LayerMetadata(), // metadata | 
|  | 273 | uint32_t* outTransformHint = nullptr); | 
| Marissa Wall | 35187b3 | 2019-01-08 10:08:52 -0800 | [diff] [blame] | 274 |  | 
|  | 275 | //! Create a surface | 
| Evan Rosky | 1f6d6d5 | 2018-12-06 10:47:26 -0800 | [diff] [blame] | 276 | sp<SurfaceControl> createWithSurfaceParent(const String8& name,       // name of the surface | 
|  | 277 | uint32_t w,                // width in pixel | 
|  | 278 | uint32_t h,                // height in pixel | 
|  | 279 | PixelFormat format,        // pixel-format desired | 
|  | 280 | uint32_t flags = 0,        // usage flags | 
|  | 281 | Surface* parent = nullptr, // parent | 
| Valerie Hau | 1acd696 | 2019-10-28 16:35:48 -0700 | [diff] [blame] | 282 | LayerMetadata metadata = LayerMetadata(), // metadata | 
|  | 283 | uint32_t* outTransformHint = nullptr); | 
| Robert Carr | 3b382ed | 2018-03-14 13:49:41 -0700 | [diff] [blame] | 284 |  | 
| chaviw | fe94a22 | 2019-08-21 13:52:59 -0700 | [diff] [blame] | 285 | // Creates a mirrored hierarchy for the mirrorFromSurface. This returns a SurfaceControl | 
|  | 286 | // which is a parent of the root of the mirrored hierarchy. | 
|  | 287 | // | 
|  | 288 | //  Real Hierarchy    Mirror | 
|  | 289 | //                      SC (value that's returned) | 
|  | 290 | //                      | | 
|  | 291 | //      A               A' | 
|  | 292 | //      |               | | 
|  | 293 | //      B               B' | 
|  | 294 | sp<SurfaceControl> mirrorSurface(SurfaceControl* mirrorFromSurface); | 
|  | 295 |  | 
| Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 296 | //! Create a virtual display | 
| Jamie Gennis | dd3cb84 | 2012-10-19 18:19:11 -0700 | [diff] [blame] | 297 | static sp<IBinder> createDisplay(const String8& displayName, bool secure); | 
| Mathias Agopian | 285dbde | 2010-03-01 16:09:43 -0800 | [diff] [blame] | 298 |  | 
| Jesse Hall | 6c913be | 2013-08-08 12:15:49 -0700 | [diff] [blame] | 299 | //! Destroy a virtual display | 
|  | 300 | static void destroyDisplay(const sp<IBinder>& display); | 
|  | 301 |  | 
| Dominik Laskowski | dcb38bb | 2019-01-25 02:35:50 -0800 | [diff] [blame] | 302 | //! Get stable IDs for connected physical displays | 
|  | 303 | static std::vector<PhysicalDisplayId> getPhysicalDisplayIds(); | 
|  | 304 | static std::optional<PhysicalDisplayId> getInternalDisplayId(); | 
|  | 305 |  | 
|  | 306 | //! Get token for a physical display given its stable ID | 
|  | 307 | static sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId); | 
|  | 308 | static sp<IBinder> getInternalDisplayToken(); | 
| Jeff Brown | 9d4e3d2 | 2012-08-24 20:00:51 -0700 | [diff] [blame] | 309 |  | 
| Sahil Dhanju | c1ba5c4 | 2016-06-07 20:09:20 -0700 | [diff] [blame] | 310 | static status_t enableVSyncInjections(bool enable); | 
|  | 311 |  | 
|  | 312 | static status_t injectVSync(nsecs_t when); | 
|  | 313 |  | 
| chaviw | 8e3fe5d | 2018-02-22 10:55:42 -0800 | [diff] [blame] | 314 | struct SCHash { | 
|  | 315 | std::size_t operator()(const sp<SurfaceControl>& sc) const { | 
|  | 316 | return std::hash<SurfaceControl *>{}(sc.get()); | 
|  | 317 | } | 
|  | 318 | }; | 
|  | 319 |  | 
| Vishnu Nair | f03652d | 2019-07-16 17:56:56 -0700 | [diff] [blame] | 320 | struct IBinderHash { | 
|  | 321 | std::size_t operator()(const sp<IBinder>& iBinder) const { | 
|  | 322 | return std::hash<IBinder*>{}(iBinder.get()); | 
|  | 323 | } | 
|  | 324 | }; | 
|  | 325 |  | 
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 326 | struct TCLHash { | 
|  | 327 | std::size_t operator()(const sp<ITransactionCompletedListener>& tcl) const { | 
|  | 328 | return std::hash<IBinder*>{}((tcl) ? IInterface::asBinder(tcl).get() : nullptr); | 
|  | 329 | } | 
|  | 330 | }; | 
|  | 331 |  | 
|  | 332 | struct CallbackInfo { | 
|  | 333 | // All the callbacks that have been requested for a TransactionCompletedListener in the | 
|  | 334 | // Transaction | 
|  | 335 | std::unordered_set<CallbackId> callbackIds; | 
|  | 336 | // All the SurfaceControls that have been modified in this TransactionCompletedListener's | 
|  | 337 | // process that require a callback if there is one or more callbackIds set. | 
|  | 338 | std::unordered_set<sp<SurfaceControl>, SCHash> surfaceControls; | 
|  | 339 | }; | 
|  | 340 |  | 
| Valerie Hau | 2b0cd8d | 2019-08-26 10:30:52 -0700 | [diff] [blame] | 341 | class Transaction : public Parcelable { | 
| Pablo Gamito | 7eb7ee7 | 2020-08-05 10:57:05 +0000 | [diff] [blame] | 342 | private: | 
|  | 343 | static std::atomic<uint32_t> idCounter; | 
|  | 344 | int64_t generateId(); | 
|  | 345 |  | 
| Valerie Hau | 9dab973 | 2019-08-20 09:29:25 -0700 | [diff] [blame] | 346 | protected: | 
| Vishnu Nair | f03652d | 2019-07-16 17:56:56 -0700 | [diff] [blame] | 347 | std::unordered_map<sp<IBinder>, ComposerState, IBinderHash> mComposerStates; | 
| Pablo Gamito | dbc3167 | 2020-09-01 18:28:58 +0000 | [diff] [blame] | 348 | SortedVector<DisplayState> mDisplayStates; | 
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 349 | std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash> | 
|  | 350 | mListenerCallbacks; | 
|  | 351 |  | 
| Pablo Gamito | 7eb7ee7 | 2020-08-05 10:57:05 +0000 | [diff] [blame] | 352 | uint64_t mId; | 
|  | 353 |  | 
| Ady Abraham | bf1349c | 2020-06-12 14:26:18 -0700 | [diff] [blame] | 354 | uint32_t mForceSynchronous = 0; | 
|  | 355 | uint32_t mTransactionNestCount = 0; | 
|  | 356 | bool mAnimation = false; | 
|  | 357 | bool mEarlyWakeup = false; | 
|  | 358 | bool mExplicitEarlyWakeupStart = false; | 
|  | 359 | bool mExplicitEarlyWakeupEnd = false; | 
| Jamie Gennis | 2d5e230 | 2012-10-15 18:24:43 -0700 | [diff] [blame] | 360 |  | 
| Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 361 | // Indicates that the Transaction contains a buffer that should be cached | 
|  | 362 | bool mContainsBuffer = false; | 
|  | 363 |  | 
| Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 364 | // mDesiredPresentTime is the time in nanoseconds that the client would like the transaction | 
|  | 365 | // to be presented. When it is not possible to present at exactly that time, it will be | 
|  | 366 | // presented after the time has passed. | 
|  | 367 | // | 
|  | 368 | // Desired present times that are more than 1 second in the future may be ignored. | 
|  | 369 | // When a desired present time has already passed, the transaction will be presented as soon | 
|  | 370 | // as possible. | 
|  | 371 | // | 
|  | 372 | // Transactions from the same process are presented in the same order that they are applied. | 
|  | 373 | // The desired present time does not affect this ordering. | 
|  | 374 | int64_t mDesiredPresentTime = -1; | 
|  | 375 |  | 
| Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 376 | // The vsync Id provided by Choreographer.getVsyncId | 
|  | 377 | int64_t mFrameTimelineVsyncId = ISurfaceComposer::INVALID_VSYNC_ID; | 
|  | 378 |  | 
| chaviw | 273171b | 2018-12-26 11:46:30 -0800 | [diff] [blame] | 379 | InputWindowCommands mInputWindowCommands; | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 380 | int mStatus = NO_ERROR; | 
|  | 381 |  | 
| Pablo Gamito | dbc3167 | 2020-09-01 18:28:58 +0000 | [diff] [blame] | 382 | layer_state_t* getLayerState(const sp<SurfaceControl>& sc); | 
| chaviw | 763ef57 | 2018-02-22 16:04:57 -0800 | [diff] [blame] | 383 | DisplayState& getDisplayState(const sp<IBinder>& token); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 384 |  | 
| Marissa Wall | 78b7220 | 2019-03-15 14:58:34 -0700 | [diff] [blame] | 385 | void cacheBuffers(); | 
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 386 | void registerSurfaceControlForCallback(const sp<SurfaceControl>& sc); | 
|  | 387 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 388 | public: | 
| Pablo Gamito | 7eb7ee7 | 2020-08-05 10:57:05 +0000 | [diff] [blame] | 389 | Transaction(); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 390 | virtual ~Transaction() = default; | 
|  | 391 | Transaction(Transaction const& other); | 
|  | 392 |  | 
| Vishnu Nair | 621102e | 2019-06-12 14:16:57 -0700 | [diff] [blame] | 393 | // Factory method that creates a new Transaction instance from the parcel. | 
|  | 394 | static std::unique_ptr<Transaction> createFromParcel(const Parcel* parcel); | 
|  | 395 |  | 
|  | 396 | status_t writeToParcel(Parcel* parcel) const override; | 
|  | 397 | status_t readFromParcel(const Parcel* parcel) override; | 
|  | 398 |  | 
| Vishnu Nair | fef244e | 2019-06-17 18:07:51 -0700 | [diff] [blame] | 399 | // Clears the contents of the transaction without applying it. | 
|  | 400 | void clear(); | 
|  | 401 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 402 | status_t apply(bool synchronous = false); | 
| Robert Carr | 2c5f6d2 | 2017-09-26 12:30:35 -0700 | [diff] [blame] | 403 | // Merge another transaction in to this one, clearing other | 
|  | 404 | // as if it had been applied. | 
|  | 405 | Transaction& merge(Transaction&& other); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 406 | Transaction& show(const sp<SurfaceControl>& sc); | 
|  | 407 | Transaction& hide(const sp<SurfaceControl>& sc); | 
|  | 408 | Transaction& setPosition(const sp<SurfaceControl>& sc, | 
|  | 409 | float x, float y); | 
|  | 410 | Transaction& setSize(const sp<SurfaceControl>& sc, | 
|  | 411 | uint32_t w, uint32_t h); | 
|  | 412 | Transaction& setLayer(const sp<SurfaceControl>& sc, | 
|  | 413 | int32_t z); | 
|  | 414 |  | 
|  | 415 | // Sets a Z order relative to the Surface specified by "relativeTo" but | 
|  | 416 | // without becoming a full child of the relative. Z-ordering works exactly | 
|  | 417 | // as if it were a child however. | 
|  | 418 | // | 
|  | 419 | // As a nod to sanity, only non-child surfaces may have a relative Z-order. | 
|  | 420 | // | 
|  | 421 | // This overrides any previous call and is overriden by any future calls | 
|  | 422 | // to setLayer. | 
|  | 423 | // | 
|  | 424 | // If the relative is removed, the Surface will have no layer and be | 
|  | 425 | // invisible, until the next time set(Relative)Layer is called. | 
|  | 426 | Transaction& setRelativeLayer(const sp<SurfaceControl>& sc, | 
| Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame^] | 427 | const sp<SurfaceControl>& relativeTo, int32_t z); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 428 | Transaction& setFlags(const sp<SurfaceControl>& sc, | 
|  | 429 | uint32_t flags, uint32_t mask); | 
|  | 430 | Transaction& setTransparentRegionHint(const sp<SurfaceControl>& sc, | 
|  | 431 | const Region& transparentRegion); | 
|  | 432 | Transaction& setAlpha(const sp<SurfaceControl>& sc, | 
|  | 433 | float alpha); | 
|  | 434 | Transaction& setMatrix(const sp<SurfaceControl>& sc, | 
|  | 435 | float dsdx, float dtdx, float dtdy, float dsdy); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 436 | Transaction& setCrop_legacy(const sp<SurfaceControl>& sc, const Rect& crop); | 
| Lucas Dupin | 1b6531c | 2018-07-05 17:18:21 -0700 | [diff] [blame] | 437 | Transaction& setCornerRadius(const sp<SurfaceControl>& sc, float cornerRadius); | 
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 438 | Transaction& setBackgroundBlurRadius(const sp<SurfaceControl>& sc, | 
|  | 439 | int backgroundBlurRadius); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 440 | Transaction& setLayerStack(const sp<SurfaceControl>& sc, uint32_t layerStack); | 
| Garfield Tan | 01a5613 | 2019-08-05 16:44:21 -0700 | [diff] [blame] | 441 | Transaction& setMetadata(const sp<SurfaceControl>& sc, uint32_t key, const Parcel& p); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 442 | // Defers applying any changes made in this transaction until the Layer | 
|  | 443 | // identified by handle reaches the given frameNumber. If the Layer identified | 
|  | 444 | // by handle is removed, then we will apply this transaction regardless of | 
|  | 445 | // what frame number has been reached. | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 446 | Transaction& deferTransactionUntil_legacy(const sp<SurfaceControl>& sc, | 
| Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame^] | 447 | const sp<SurfaceControl>& barrierSurfaceControl, | 
|  | 448 | uint64_t frameNumber); | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 449 | // 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] | 450 | // Surface instead of Handle. Useful for clients which may not have the | 
|  | 451 | // SurfaceControl for some of their Surfaces. Otherwise behaves identically. | 
| Marissa Wall | f58c14b | 2018-07-24 10:50:43 -0700 | [diff] [blame] | 452 | Transaction& deferTransactionUntil_legacy(const sp<SurfaceControl>& sc, | 
|  | 453 | const sp<Surface>& barrierSurface, | 
|  | 454 | uint64_t frameNumber); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 455 | // Reparents all children of this layer to the new parent handle. | 
|  | 456 | Transaction& reparentChildren(const sp<SurfaceControl>& sc, | 
| Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame^] | 457 | const sp<SurfaceControl>& newParent); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 458 |  | 
|  | 459 | /// Reparents the current layer to the new parent handle. The new parent must not be null. | 
|  | 460 | // This can be used instead of reparentChildren if the caller wants to | 
|  | 461 | // only re-parent a specific child. | 
| Pablo Gamito | 11dcc22 | 2020-09-12 15:49:39 +0000 | [diff] [blame^] | 462 | Transaction& reparent(const sp<SurfaceControl>& sc, const sp<SurfaceControl>& newParent); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 463 |  | 
|  | 464 | Transaction& setColor(const sp<SurfaceControl>& sc, const half3& color); | 
|  | 465 |  | 
| Valerie Hau | dd0b757 | 2019-01-29 14:59:27 -0800 | [diff] [blame] | 466 | // Sets the background color of a layer with the specified color, alpha, and dataspace | 
|  | 467 | Transaction& setBackgroundColor(const sp<SurfaceControl>& sc, const half3& color, | 
|  | 468 | float alpha, ui::Dataspace dataspace); | 
| Valerie Hau | ed54efa | 2019-01-11 20:03:14 -0800 | [diff] [blame] | 469 |  | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 470 | Transaction& setTransform(const sp<SurfaceControl>& sc, uint32_t transform); | 
|  | 471 | Transaction& setTransformToDisplayInverse(const sp<SurfaceControl>& sc, | 
|  | 472 | bool transformToDisplayInverse); | 
|  | 473 | Transaction& setCrop(const sp<SurfaceControl>& sc, const Rect& crop); | 
| Marissa Wall | 861616d | 2018-10-22 12:52:23 -0700 | [diff] [blame] | 474 | Transaction& setFrame(const sp<SurfaceControl>& sc, const Rect& frame); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 475 | Transaction& setBuffer(const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer); | 
| Marissa Wall | ebc2c05 | 2019-01-16 19:16:55 -0800 | [diff] [blame] | 476 | Transaction& setCachedBuffer(const sp<SurfaceControl>& sc, int32_t bufferId); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 477 | Transaction& setAcquireFence(const sp<SurfaceControl>& sc, const sp<Fence>& fence); | 
|  | 478 | Transaction& setDataspace(const sp<SurfaceControl>& sc, ui::Dataspace dataspace); | 
|  | 479 | Transaction& setHdrMetadata(const sp<SurfaceControl>& sc, const HdrMetadata& hdrMetadata); | 
|  | 480 | Transaction& setSurfaceDamageRegion(const sp<SurfaceControl>& sc, | 
|  | 481 | const Region& surfaceDamageRegion); | 
|  | 482 | Transaction& setApi(const sp<SurfaceControl>& sc, int32_t api); | 
|  | 483 | Transaction& setSidebandStream(const sp<SurfaceControl>& sc, | 
|  | 484 | const sp<NativeHandle>& sidebandStream); | 
| Marissa Wall | 17b4e45 | 2018-12-26 16:32:34 -0800 | [diff] [blame] | 485 | Transaction& setDesiredPresentTime(nsecs_t desiredPresentTime); | 
| Peiyong Lin | c502cb7 | 2019-03-01 15:00:23 -0800 | [diff] [blame] | 486 | Transaction& setColorSpaceAgnostic(const sp<SurfaceControl>& sc, const bool agnostic); | 
| Marissa Wall | 61c5862 | 2018-07-18 10:12:20 -0700 | [diff] [blame] | 487 |  | 
| Ana Krulec | c84d09b | 2019-11-02 23:10:29 +0100 | [diff] [blame] | 488 | // Sets information about the priority of the frame. | 
|  | 489 | Transaction& setFrameRateSelectionPriority(const sp<SurfaceControl>& sc, int32_t priority); | 
|  | 490 |  | 
| Marissa Wall | e2ffb42 | 2018-10-12 11:33:52 -0700 | [diff] [blame] | 491 | Transaction& addTransactionCompletedCallback( | 
|  | 492 | TransactionCompletedCallbackTakesContext callback, void* callbackContext); | 
| Marissa Wall | c837b5e | 2018-10-12 10:04:44 -0700 | [diff] [blame] | 493 |  | 
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 494 | // ONLY FOR BLAST ADAPTER | 
|  | 495 | Transaction& notifyProducerDisconnect(const sp<SurfaceControl>& sc); | 
| Vishnu Nair | 6b7c5c9 | 2020-09-29 17:27:05 -0700 | [diff] [blame] | 496 | // Set the framenumber generated by the graphics producer to mimic BufferQueue behaviour. | 
|  | 497 | Transaction& setFrameNumber(const sp<SurfaceControl>& sc, uint64_t frameNumber); | 
| Valerie Hau | 871d635 | 2020-01-29 08:44:02 -0800 | [diff] [blame] | 498 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 499 | // Detaches all child surfaces (and their children recursively) | 
|  | 500 | // from their SurfaceControl. | 
|  | 501 | // The child SurfaceControls will not throw exceptions or return errors, | 
|  | 502 | // but transactions will have no effect. | 
|  | 503 | // The child surfaces will continue to follow their parent surfaces, | 
|  | 504 | // and remain eligible for rendering, but their relative state will be | 
|  | 505 | // frozen. We use this in the WindowManager, in app shutdown/relaunch | 
|  | 506 | // scenarios, where the app would otherwise clean up its child Surfaces. | 
|  | 507 | // Sometimes the WindowManager needs to extend their lifetime slightly | 
|  | 508 | // in order to perform an exit animation or prevent flicker. | 
|  | 509 | Transaction& detachChildren(const sp<SurfaceControl>& sc); | 
|  | 510 | // Set an override scaling mode as documented in <system/window.h> | 
|  | 511 | // the override scaling mode will take precedence over any client | 
|  | 512 | // specified scaling mode. -1 will clear the override scaling mode. | 
|  | 513 | Transaction& setOverrideScalingMode(const sp<SurfaceControl>& sc, | 
|  | 514 | int32_t overrideScalingMode); | 
|  | 515 |  | 
| Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 516 | #ifndef NO_INPUT | 
|  | 517 | Transaction& setInputWindowInfo(const sp<SurfaceControl>& sc, const InputWindowInfo& info); | 
| Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 518 | Transaction& setFocusedWindow(const sp<IBinder>& token, const sp<IBinder>& focusedToken, | 
| Vishnu Nair | 958da93 | 2020-08-21 17:12:37 -0700 | [diff] [blame] | 519 | nsecs_t timestampNanos, int32_t displayId); | 
| Vishnu Nair | e798b47 | 2020-07-23 13:52:21 -0700 | [diff] [blame] | 520 | Transaction& setFocusedWindow(const FocusRequest& request); | 
| chaviw | a911b10 | 2019-02-14 10:18:33 -0800 | [diff] [blame] | 521 | Transaction& syncInputWindows(); | 
| Robert Carr | 2c358bf | 2018-08-08 15:58:15 -0700 | [diff] [blame] | 522 | #endif | 
|  | 523 |  | 
| Peiyong Lin | d378863 | 2018-09-18 16:01:31 -0700 | [diff] [blame] | 524 | // Set a color transform matrix on the given layer on the built-in display. | 
|  | 525 | Transaction& setColorTransform(const sp<SurfaceControl>& sc, const mat3& matrix, | 
|  | 526 | const vec3& translation); | 
|  | 527 |  | 
| Robert Carr | fb4d58b | 2019-01-15 09:21:27 -0800 | [diff] [blame] | 528 | Transaction& setGeometry(const sp<SurfaceControl>& sc, | 
|  | 529 | const Rect& source, const Rect& dst, int transform); | 
| Vishnu Nair | c97b8db | 2019-10-29 18:19:35 -0700 | [diff] [blame] | 530 | Transaction& setShadowRadius(const sp<SurfaceControl>& sc, float cornerRadius); | 
| Robert Carr | fb4d58b | 2019-01-15 09:21:27 -0800 | [diff] [blame] | 531 |  | 
| Steven Thomas | 62a4cf8 | 2020-01-31 12:04:03 -0800 | [diff] [blame] | 532 | Transaction& setFrameRate(const sp<SurfaceControl>& sc, float frameRate, | 
|  | 533 | int8_t compatibility); | 
| Steven Thomas | 3172e20 | 2020-01-06 19:25:30 -0800 | [diff] [blame] | 534 |  | 
| Vishnu Nair | 6213bd9 | 2020-05-08 17:42:25 -0700 | [diff] [blame] | 535 | // Set by window manager indicating the layer and all its children are | 
|  | 536 | // in a different orientation than the display. The hint suggests that | 
|  | 537 | // the graphic producers should receive a transform hint as if the | 
|  | 538 | // display was in this orientation. When the display changes to match | 
|  | 539 | // the layer orientation, the graphic producer may not need to allocate | 
|  | 540 | // a buffer of a different size. | 
|  | 541 | Transaction& setFixedTransformHint(const sp<SurfaceControl>& sc, int32_t transformHint); | 
|  | 542 |  | 
| Ady Abraham | 22c7b5c | 2020-09-22 19:33:40 -0700 | [diff] [blame] | 543 | // Sets the frame timeline vsync id received from choreographer that corresponds | 
|  | 544 | // to the transaction. | 
|  | 545 | Transaction& setFrameTimelineVsync(int64_t frameTimelineVsyncId); | 
|  | 546 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 547 | status_t setDisplaySurface(const sp<IBinder>& token, | 
|  | 548 | const sp<IGraphicBufferProducer>& bufferProducer); | 
|  | 549 |  | 
|  | 550 | void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack); | 
|  | 551 |  | 
|  | 552 | /* setDisplayProjection() defines the projection of layer stacks | 
|  | 553 | * to a given display. | 
|  | 554 | * | 
|  | 555 | * - orientation defines the display's orientation. | 
|  | 556 | * - layerStackRect defines which area of the window manager coordinate | 
|  | 557 | * space will be used. | 
|  | 558 | * - displayRect defines where on the display will layerStackRect be | 
|  | 559 | * mapped to. displayRect is specified post-orientation, that is | 
|  | 560 | * it uses the orientation seen by the end-user. | 
|  | 561 | */ | 
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 562 | void setDisplayProjection(const sp<IBinder>& token, ui::Rotation orientation, | 
|  | 563 | const Rect& layerStackRect, const Rect& displayRect); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 564 | void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height); | 
|  | 565 | void setAnimationTransaction(); | 
| Dan Stoza | 84d619e | 2018-03-28 17:07:36 -0700 | [diff] [blame] | 566 | void setEarlyWakeup(); | 
| Ady Abraham | bf1349c | 2020-06-12 14:26:18 -0700 | [diff] [blame] | 567 | void setExplicitEarlyWakeupStart(); | 
|  | 568 | void setExplicitEarlyWakeupEnd(); | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 569 | }; | 
| Robert Carr | 82364e3 | 2016-05-15 11:27:47 -0700 | [diff] [blame] | 570 |  | 
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 571 | status_t clearLayerFrameStats(const sp<IBinder>& token) const; | 
|  | 572 | status_t getLayerFrameStats(const sp<IBinder>& token, FrameStats* outStats) const; | 
| Svetoslav | d85084b | 2014-03-20 10:28:31 -0700 | [diff] [blame] | 573 | static status_t clearAnimationFrameStats(); | 
|  | 574 | static status_t getAnimationFrameStats(FrameStats* outStats); | 
|  | 575 |  | 
| Dan Stoza | c4f471e | 2016-03-24 09:31:08 -0700 | [diff] [blame] | 576 | static status_t getHdrCapabilities(const sp<IBinder>& display, | 
|  | 577 | HdrCapabilities* outCapabilities); | 
|  | 578 |  | 
| Dominik Laskowski | 718f960 | 2019-11-09 20:01:35 -0800 | [diff] [blame] | 579 | static void setDisplayProjection(const sp<IBinder>& token, ui::Rotation orientation, | 
|  | 580 | const Rect& layerStackRect, const Rect& displayRect); | 
| Mathias Agopian | e57f292 | 2012-08-09 16:29:12 -0700 | [diff] [blame] | 581 |  | 
| Robert Carr | 4cdc58f | 2017-08-23 14:22:20 -0700 | [diff] [blame] | 582 | inline sp<ISurfaceComposerClient> getClient() { return mClient; } | 
|  | 583 |  | 
| Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 584 | static status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display, | 
|  | 585 | ui::PixelFormat* outFormat, | 
|  | 586 | ui::Dataspace* outDataspace, | 
|  | 587 | uint8_t* outComponentMask); | 
| Kevin DuBois | 74e5377 | 2018-11-19 10:52:38 -0800 | [diff] [blame] | 588 | static status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable, | 
|  | 589 | uint8_t componentMask, uint64_t maxFrames); | 
| Kevin DuBois | 9c0a176 | 2018-10-16 13:32:31 -0700 | [diff] [blame] | 590 |  | 
| Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 591 | static status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames, | 
|  | 592 | uint64_t timestamp, DisplayedFrameStats* outStats); | 
| Kevin DuBois | 00c6683 | 2019-02-18 16:21:31 -0800 | [diff] [blame] | 593 | static status_t addRegionSamplingListener(const Rect& samplingArea, | 
|  | 594 | const sp<IBinder>& stopLayerHandle, | 
|  | 595 | const sp<IRegionSamplingListener>& listener); | 
|  | 596 | static status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener); | 
| Kevin DuBois | 1d4249a | 2018-08-29 10:45:14 -0700 | [diff] [blame] | 597 |  | 
| Mathias Agopian | 631f358 | 2010-05-25 17:51:34 -0700 | [diff] [blame] | 598 | private: | 
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 599 | virtual void onFirstRef(); | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 |  | 
| Mathias Agopian | 698c087 | 2011-06-28 19:09:31 -0700 | [diff] [blame] | 601 | mutable     Mutex                       mLock; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 602 | status_t                    mStatus; | 
| Mathias Agopian | 7e27f05 | 2010-05-28 14:22:23 -0700 | [diff] [blame] | 603 | sp<ISurfaceComposerClient>  mClient; | 
| The Android Open Source Project | edbf3b6 | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 604 | }; | 
|  | 605 |  | 
| Mathias Agopian | d4784a3 | 2010-05-27 19:41:15 -0700 | [diff] [blame] | 606 | // --------------------------------------------------------------------------- | 
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 607 |  | 
| Chavi Weingarten | 40482ff | 2017-11-30 01:51:40 +0000 | [diff] [blame] | 608 | class ScreenshotClient { | 
| Mathias Agopian | 2a9fc49 | 2013-03-01 13:42:57 -0800 | [diff] [blame] | 609 | public: | 
| chaviw | 690db38 | 2020-07-27 16:46:46 -0700 | [diff] [blame] | 610 | static status_t captureDisplay(const DisplayCaptureArgs& captureArgs, | 
| chaviw | e7b9f27 | 2020-08-18 16:08:59 -0700 | [diff] [blame] | 611 | const sp<IScreenCaptureListener>& captureListener); | 
| chaviw | 690db38 | 2020-07-27 16:46:46 -0700 | [diff] [blame] | 612 | static status_t captureDisplay(uint64_t displayOrLayerStack, | 
| chaviw | e7b9f27 | 2020-08-18 16:08:59 -0700 | [diff] [blame] | 613 | const sp<IScreenCaptureListener>& captureListener); | 
| chaviw | 26c5248 | 2020-07-28 16:25:52 -0700 | [diff] [blame] | 614 | static status_t captureLayers(const LayerCaptureArgs& captureArgs, | 
| chaviw | e7b9f27 | 2020-08-18 16:08:59 -0700 | [diff] [blame] | 615 | const sp<IScreenCaptureListener>& captureListener); | 
| Mathias Agopian | 74c40c0 | 2010-09-29 13:02:36 -0700 | [diff] [blame] | 616 | }; | 
|  | 617 |  | 
|  | 618 | // --------------------------------------------------------------------------- | 
| Marissa Wall | 7a9b6ff | 2018-08-21 17:26:20 -0700 | [diff] [blame] | 619 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 620 | class TransactionCompletedListener : public BnTransactionCompletedListener { | 
|  | 621 | TransactionCompletedListener(); | 
|  | 622 |  | 
|  | 623 | CallbackId getNextIdLocked() REQUIRES(mMutex); | 
|  | 624 |  | 
|  | 625 | std::mutex mMutex; | 
|  | 626 |  | 
|  | 627 | bool mListening GUARDED_BY(mMutex) = false; | 
|  | 628 |  | 
|  | 629 | CallbackId mCallbackIdCounter GUARDED_BY(mMutex) = 1; | 
|  | 630 |  | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 631 | struct CallbackTranslation { | 
|  | 632 | TransactionCompletedCallback callbackFunction; | 
| Vishnu Nair | f03652d | 2019-07-16 17:56:56 -0700 | [diff] [blame] | 633 | std::unordered_map<sp<IBinder>, sp<SurfaceControl>, SurfaceComposerClient::IBinderHash> | 
|  | 634 | surfaceControls; | 
| Marissa Wall | 80d94ad | 2019-01-18 16:04:36 -0800 | [diff] [blame] | 635 | }; | 
|  | 636 |  | 
|  | 637 | std::unordered_map<CallbackId, CallbackTranslation> mCallbacks GUARDED_BY(mMutex); | 
|  | 638 |  | 
|  | 639 | public: | 
|  | 640 | static sp<TransactionCompletedListener> getInstance(); | 
|  | 641 | static sp<ITransactionCompletedListener> getIInstance(); | 
|  | 642 |  | 
|  | 643 | void startListeningLocked() REQUIRES(mMutex); | 
|  | 644 |  | 
|  | 645 | CallbackId addCallbackFunction( | 
|  | 646 | const TransactionCompletedCallback& callbackFunction, | 
|  | 647 | const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>& | 
|  | 648 | surfaceControls); | 
|  | 649 |  | 
|  | 650 | void addSurfaceControlToCallbacks(const sp<SurfaceControl>& surfaceControl, | 
|  | 651 | const std::unordered_set<CallbackId>& callbackIds); | 
|  | 652 |  | 
|  | 653 | // Overrides BnTransactionCompletedListener's onTransactionCompleted | 
|  | 654 | void onTransactionCompleted(ListenerStats stats) override; | 
|  | 655 | }; | 
|  | 656 |  | 
| Dominik Laskowski | 3cb3d4e | 2019-11-21 11:14:45 -0800 | [diff] [blame] | 657 | } // namespace android |