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