blob: 7e763fcd54bc4491d8622687118f3c7139c97546 [file] [log] [blame]
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -08001/*
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 Agopian90ac7992012-02-25 18:48:35 -080017#ifndef ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
18#define ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080019
20#include <stdint.h>
21#include <sys/types.h>
Marissa Wallc837b5e2018-10-12 10:04:44 -070022#include <set>
chaviw8e3fe5d2018-02-22 10:55:42 -080023#include <unordered_map>
Marissa Wallc837b5e2018-10-12 10:04:44 -070024#include <unordered_set>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080025
Mathias Agopiandd3423c2009-09-23 15:44:05 -070026#include <binder/IBinder.h>
27
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080028#include <utils/RefBase.h>
Mathias Agopianb7e930d2010-06-01 15:12:58 -070029#include <utils/Singleton.h>
30#include <utils/SortedVector.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080031#include <utils/threads.h>
32
Daniel Solomon42d04562019-01-20 21:03:19 -080033#include <ui/ConfigStoreTypes.h>
Kevin DuBois1d4249a2018-08-29 10:45:14 -070034#include <ui/DisplayedFrameStats.h>
Svetoslavd85084b2014-03-20 10:28:31 -070035#include <ui/FrameStats.h>
Peiyong Lin9f034472018-03-28 15:29:00 -070036#include <ui/GraphicTypes.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080037#include <ui/PixelFormat.h>
Mathias Agopian9cce3252010-02-09 17:46:37 -080038
Mathias Agopianabe815d2013-03-19 22:22:21 -070039#include <gui/CpuConsumer.h>
Marissa Wall7a9b6ff2018-08-21 17:26:20 -070040#include <gui/ITransactionCompletedListener.h>
41#include <gui/LayerState.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080042#include <gui/SurfaceControl.h>
chaviw13fdc492017-06-27 12:40:18 -070043#include <math/vec3.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080044
45namespace android {
46
47// ---------------------------------------------------------------------------
48
Colin Crossa2362b42016-09-26 13:48:25 -070049struct DisplayInfo;
Dan Stozac4f471e2016-03-24 09:31:08 -070050class HdrCapabilities;
Mathias Agopian41f673c2011-11-17 17:48:35 -080051class ISurfaceComposerClient;
Andy McFadden2adaf042012-12-18 09:49:45 -080052class IGraphicBufferProducer;
Mathias Agopiana67932f2011-04-20 14:20:59 -070053class Region;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070054
55// ---------------------------------------------------------------------------
56
Marissa Wall80d94ad2019-01-18 16:04:36 -080057struct SurfaceControlStats {
58 SurfaceControlStats(const sp<SurfaceControl>& sc, nsecs_t time,
59 const sp<Fence>& prevReleaseFence)
60 : surfaceControl(sc), acquireTime(time), previousReleaseFence(prevReleaseFence) {}
Marissa Wallc837b5e2018-10-12 10:04:44 -070061
Marissa Wall80d94ad2019-01-18 16:04:36 -080062 sp<SurfaceControl> surfaceControl;
63 nsecs_t acquireTime = -1;
64 sp<Fence> previousReleaseFence;
Marissa Wall7a9b6ff2018-08-21 17:26:20 -070065};
66
Marissa Wall80d94ad2019-01-18 16:04:36 -080067using TransactionCompletedCallbackTakesContext =
68 std::function<void(void* /*context*/, nsecs_t /*latchTime*/,
69 const sp<Fence>& /*presentFence*/,
70 const std::vector<SurfaceControlStats>& /*stats*/)>;
71using TransactionCompletedCallback =
72 std::function<void(nsecs_t /*latchTime*/, const sp<Fence>& /*presentFence*/,
73 const std::vector<SurfaceControlStats>& /*stats*/)>;
74
Marissa Wall7a9b6ff2018-08-21 17:26:20 -070075// ---------------------------------------------------------------------------
76
Mathias Agopiand4784a32010-05-27 19:41:15 -070077class SurfaceComposerClient : public RefBase
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080078{
Mathias Agopian698c0872011-06-28 19:09:31 -070079 friend class Composer;
Jesse Hall6c913be2013-08-08 12:15:49 -070080public:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080081 SurfaceComposerClient();
Jorim Jaggif3cf4bc2017-11-30 14:19:23 +010082 SurfaceComposerClient(const sp<ISurfaceComposerClient>& client);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083 virtual ~SurfaceComposerClient();
84
85 // Always make sure we could initialize
86 status_t initCheck() const;
87
88 // Return the connection of this client
89 sp<IBinder> connection() const;
Jesse Hall6c913be2013-08-08 12:15:49 -070090
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080091 // Forcibly remove connection before all references have gone away.
92 void dispose();
93
Mathias Agopiane57f2922012-08-09 16:29:12 -070094 // callback when the composer is dies
95 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
Yi Konga03e0442018-07-17 11:16:57 -070096 void* cookie = nullptr, uint32_t flags = 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -070097
Dan Stoza7f7da322014-05-02 15:26:25 -070098 // Get a list of supported configurations for a given display
99 static status_t getDisplayConfigs(const sp<IBinder>& display,
100 Vector<DisplayInfo>* configs);
101
102 // Get the DisplayInfo for the currently-active configuration
103 static status_t getDisplayInfo(const sp<IBinder>& display,
104 DisplayInfo* info);
105
106 // Get the index of the current active configuration (relative to the list
107 // returned by getDisplayInfo)
108 static int getActiveConfig(const sp<IBinder>& display);
109
110 // Set a new active configuration using an index relative to the list
111 // returned by getDisplayInfo
112 static status_t setActiveConfig(const sp<IBinder>& display, int id);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700113
Ady Abraham838de062019-02-04 10:24:03 -0800114 // Sets the allowed display configurations to be used.
115 // The allowedConfigs in a vector of indexes corresponding to the configurations
116 // returned from getDisplayConfigs().
117 static status_t setAllowedDisplayConfigs(const sp<IBinder>& displayToken,
118 const std::vector<int32_t>& allowedConfigs);
119
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800120 // Returns the allowed display configurations currently set.
121 // The allowedConfigs in a vector of indexes corresponding to the configurations
122 // returned from getDisplayConfigs().
123 static status_t getAllowedDisplayConfigs(const sp<IBinder>& displayToken,
124 std::vector<int32_t>* outAllowedConfigs);
125
Michael Wright28f24d02016-07-12 13:30:53 -0700126 // Gets the list of supported color modes for the given display
127 static status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lin9f034472018-03-28 15:29:00 -0700128 Vector<ui::ColorMode>* outColorModes);
Michael Wright28f24d02016-07-12 13:30:53 -0700129
Daniel Solomon42d04562019-01-20 21:03:19 -0800130 // Get the coordinates of the display's native color primaries
131 static status_t getDisplayNativePrimaries(const sp<IBinder>& display,
132 ui::DisplayPrimaries& outPrimaries);
133
Michael Wright28f24d02016-07-12 13:30:53 -0700134 // Gets the active color mode for the given display
Peiyong Lin9f034472018-03-28 15:29:00 -0700135 static ui::ColorMode getActiveColorMode(const sp<IBinder>& display);
Michael Wright28f24d02016-07-12 13:30:53 -0700136
137 // Sets the active color mode for the given display
Peiyong Lin9f034472018-03-28 15:29:00 -0700138 static status_t setActiveColorMode(const sp<IBinder>& display,
139 ui::ColorMode colorMode);
Michael Wright28f24d02016-07-12 13:30:53 -0700140
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700141 /* Triggers screen on/off or low power mode and waits for it to complete */
142 static void setDisplayPowerMode(const sp<IBinder>& display, int mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700143
Peiyong Linc6780972018-10-28 15:24:08 -0700144 /* Returns the composition preference of the default data space and default pixel format,
145 * as well as the wide color gamut data space and wide color gamut pixel format.
146 * If the wide color gamut data space is V0_SRGB, then it implies that the platform
147 * has no wide color gamut support.
148 */
149 static status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
150 ui::PixelFormat* defaultPixelFormat,
151 ui::Dataspace* wideColorGamutDataspace,
152 ui::PixelFormat* wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -0700153
Peiyong Lin08d10512019-01-16 13:27:35 -0800154 /*
155 * Gets whether SurfaceFlinger can support protected content in GPU composition.
156 * Requires the ACCESS_SURFACE_FLINGER permission.
157 */
158 static bool getProtectedContentSupport();
159
Robert Carr6fb1a7e2018-12-11 12:07:25 -0800160 /**
161 * Called from SurfaceControl d'tor to 'destroy' the surface (or rather, reparent it
162 * to null), but without needing an sp<SurfaceControl> to avoid infinite ressurection.
163 */
164 static void doDropReferenceTransaction(const sp<IBinder>& handle,
165 const sp<ISurfaceComposerClient>& client);
166
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800167 // Queries whether a given display is wide color display.
168 static status_t isWideColorDisplay(const sp<IBinder>& display, bool* outIsWideColorDisplay);
169
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800170 // ------------------------------------------------------------------------
171 // surface creation / destruction
172
Robert Carrfb4d58b2019-01-15 09:21:27 -0800173 static sp<SurfaceComposerClient> getDefault();
174
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800175 //! Create a surface
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800176 sp<SurfaceControl> createSurface(const String8& name, // name of the surface
177 uint32_t w, // width in pixel
178 uint32_t h, // height in pixel
179 PixelFormat format, // pixel-format desired
180 uint32_t flags = 0, // usage flags
181 SurfaceControl* parent = nullptr, // parent
182 LayerMetadata metadata = LayerMetadata() // metadata
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800183 );
184
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800185 status_t createSurfaceChecked(const String8& name, // name of the surface
186 uint32_t w, // width in pixel
187 uint32_t h, // height in pixel
188 PixelFormat format, // pixel-format desired
189 sp<SurfaceControl>* outSurface,
190 uint32_t flags = 0, // usage flags
191 SurfaceControl* parent = nullptr, // parent
192 LayerMetadata metadata = LayerMetadata() // metadata
Marissa Wall35187b32019-01-08 10:08:52 -0800193 );
194
195 //! Create a surface
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800196 sp<SurfaceControl> createWithSurfaceParent(const String8& name, // name of the surface
197 uint32_t w, // width in pixel
198 uint32_t h, // height in pixel
199 PixelFormat format, // pixel-format desired
200 uint32_t flags = 0, // usage flags
201 Surface* parent = nullptr, // parent
202 LayerMetadata metadata = LayerMetadata() // metadata
Robert Carr3b382ed2018-03-14 13:49:41 -0700203 );
204
Jesse Hall6c913be2013-08-08 12:15:49 -0700205 //! Create a virtual display
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700206 static sp<IBinder> createDisplay(const String8& displayName, bool secure);
Mathias Agopian285dbde2010-03-01 16:09:43 -0800207
Jesse Hall6c913be2013-08-08 12:15:49 -0700208 //! Destroy a virtual display
209 static void destroyDisplay(const sp<IBinder>& display);
210
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800211 //! Get stable IDs for connected physical displays
212 static std::vector<PhysicalDisplayId> getPhysicalDisplayIds();
213 static std::optional<PhysicalDisplayId> getInternalDisplayId();
214
215 //! Get token for a physical display given its stable ID
216 static sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId);
217 static sp<IBinder> getInternalDisplayToken();
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700218
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700219 static status_t enableVSyncInjections(bool enable);
220
221 static status_t injectVSync(nsecs_t when);
222
chaviw8e3fe5d2018-02-22 10:55:42 -0800223 struct SCHash {
224 std::size_t operator()(const sp<SurfaceControl>& sc) const {
225 return std::hash<SurfaceControl *>{}(sc.get());
226 }
227 };
228
Marissa Wallc837b5e2018-10-12 10:04:44 -0700229 struct TCLHash {
230 std::size_t operator()(const sp<ITransactionCompletedListener>& tcl) const {
231 return std::hash<IBinder*>{}((tcl) ? IInterface::asBinder(tcl).get() : nullptr);
232 }
233 };
234
235 struct CallbackInfo {
236 // All the callbacks that have been requested for a TransactionCompletedListener in the
237 // Transaction
238 std::unordered_set<CallbackId> callbackIds;
239 // All the SurfaceControls that have been modified in this TransactionCompletedListener's
240 // process that require a callback if there is one or more callbackIds set.
241 std::unordered_set<sp<SurfaceControl>, SCHash> surfaceControls;
242 };
243
Robert Carr4cdc58f2017-08-23 14:22:20 -0700244 class Transaction {
chaviw8e3fe5d2018-02-22 10:55:42 -0800245 std::unordered_map<sp<SurfaceControl>, ComposerState, SCHash> mComposerStates;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700246 SortedVector<DisplayState > mDisplayStates;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700247 std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash>
248 mListenerCallbacks;
249
Robert Carr4cdc58f2017-08-23 14:22:20 -0700250 uint32_t mForceSynchronous = 0;
251 uint32_t mTransactionNestCount = 0;
252 bool mAnimation = false;
Dan Stoza84d619e2018-03-28 17:07:36 -0700253 bool mEarlyWakeup = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700254
Marissa Wall17b4e452018-12-26 16:32:34 -0800255 // mDesiredPresentTime is the time in nanoseconds that the client would like the transaction
256 // to be presented. When it is not possible to present at exactly that time, it will be
257 // presented after the time has passed.
258 //
259 // Desired present times that are more than 1 second in the future may be ignored.
260 // When a desired present time has already passed, the transaction will be presented as soon
261 // as possible.
262 //
263 // Transactions from the same process are presented in the same order that they are applied.
264 // The desired present time does not affect this ordering.
265 int64_t mDesiredPresentTime = -1;
266
chaviw273171b2018-12-26 11:46:30 -0800267 InputWindowCommands mInputWindowCommands;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700268 int mStatus = NO_ERROR;
269
chaviw763ef572018-02-22 16:04:57 -0800270 layer_state_t* getLayerState(const sp<SurfaceControl>& sc);
271 DisplayState& getDisplayState(const sp<IBinder>& token);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700272
Marissa Wallc837b5e2018-10-12 10:04:44 -0700273 void registerSurfaceControlForCallback(const sp<SurfaceControl>& sc);
274
Robert Carr4cdc58f2017-08-23 14:22:20 -0700275 public:
276 Transaction() = default;
277 virtual ~Transaction() = default;
278 Transaction(Transaction const& other);
279
280 status_t apply(bool synchronous = false);
Robert Carr2c5f6d22017-09-26 12:30:35 -0700281 // Merge another transaction in to this one, clearing other
282 // as if it had been applied.
283 Transaction& merge(Transaction&& other);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700284 Transaction& show(const sp<SurfaceControl>& sc);
285 Transaction& hide(const sp<SurfaceControl>& sc);
286 Transaction& setPosition(const sp<SurfaceControl>& sc,
287 float x, float y);
288 Transaction& setSize(const sp<SurfaceControl>& sc,
289 uint32_t w, uint32_t h);
290 Transaction& setLayer(const sp<SurfaceControl>& sc,
291 int32_t z);
292
293 // Sets a Z order relative to the Surface specified by "relativeTo" but
294 // without becoming a full child of the relative. Z-ordering works exactly
295 // as if it were a child however.
296 //
297 // As a nod to sanity, only non-child surfaces may have a relative Z-order.
298 //
299 // This overrides any previous call and is overriden by any future calls
300 // to setLayer.
301 //
302 // If the relative is removed, the Surface will have no layer and be
303 // invisible, until the next time set(Relative)Layer is called.
304 Transaction& setRelativeLayer(const sp<SurfaceControl>& sc,
305 const sp<IBinder>& relativeTo, int32_t z);
306 Transaction& setFlags(const sp<SurfaceControl>& sc,
307 uint32_t flags, uint32_t mask);
308 Transaction& setTransparentRegionHint(const sp<SurfaceControl>& sc,
309 const Region& transparentRegion);
310 Transaction& setAlpha(const sp<SurfaceControl>& sc,
311 float alpha);
312 Transaction& setMatrix(const sp<SurfaceControl>& sc,
313 float dsdx, float dtdx, float dtdy, float dsdy);
Marissa Wallf58c14b2018-07-24 10:50:43 -0700314 Transaction& setCrop_legacy(const sp<SurfaceControl>& sc, const Rect& crop);
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700315 Transaction& setCornerRadius(const sp<SurfaceControl>& sc, float cornerRadius);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700316 Transaction& setLayerStack(const sp<SurfaceControl>& sc, uint32_t layerStack);
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800317 Transaction& setMetadata(const sp<SurfaceControl>& sc, uint32_t key,
318 std::vector<uint8_t> data);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700319 // Defers applying any changes made in this transaction until the Layer
320 // identified by handle reaches the given frameNumber. If the Layer identified
321 // by handle is removed, then we will apply this transaction regardless of
322 // what frame number has been reached.
Marissa Wallf58c14b2018-07-24 10:50:43 -0700323 Transaction& deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
324 const sp<IBinder>& handle, uint64_t frameNumber);
325 // A variant of deferTransactionUntil_legacy which identifies the Layer we wait for by
Robert Carr4cdc58f2017-08-23 14:22:20 -0700326 // Surface instead of Handle. Useful for clients which may not have the
327 // SurfaceControl for some of their Surfaces. Otherwise behaves identically.
Marissa Wallf58c14b2018-07-24 10:50:43 -0700328 Transaction& deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
329 const sp<Surface>& barrierSurface,
330 uint64_t frameNumber);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700331 // Reparents all children of this layer to the new parent handle.
332 Transaction& reparentChildren(const sp<SurfaceControl>& sc,
333 const sp<IBinder>& newParentHandle);
334
335 /// Reparents the current layer to the new parent handle. The new parent must not be null.
336 // This can be used instead of reparentChildren if the caller wants to
337 // only re-parent a specific child.
338 Transaction& reparent(const sp<SurfaceControl>& sc,
339 const sp<IBinder>& newParentHandle);
340
341 Transaction& setColor(const sp<SurfaceControl>& sc, const half3& color);
342
Valerie Haudd0b7572019-01-29 14:59:27 -0800343 // Sets the background color of a layer with the specified color, alpha, and dataspace
344 Transaction& setBackgroundColor(const sp<SurfaceControl>& sc, const half3& color,
345 float alpha, ui::Dataspace dataspace);
Valerie Haued54efa2019-01-11 20:03:14 -0800346
Marissa Wall61c58622018-07-18 10:12:20 -0700347 Transaction& setTransform(const sp<SurfaceControl>& sc, uint32_t transform);
348 Transaction& setTransformToDisplayInverse(const sp<SurfaceControl>& sc,
349 bool transformToDisplayInverse);
350 Transaction& setCrop(const sp<SurfaceControl>& sc, const Rect& crop);
Marissa Wall861616d2018-10-22 12:52:23 -0700351 Transaction& setFrame(const sp<SurfaceControl>& sc, const Rect& frame);
Marissa Wall61c58622018-07-18 10:12:20 -0700352 Transaction& setBuffer(const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer);
Marissa Wallebc2c052019-01-16 19:16:55 -0800353 Transaction& setCachedBuffer(const sp<SurfaceControl>& sc, int32_t bufferId);
Marissa Wall61c58622018-07-18 10:12:20 -0700354 Transaction& setAcquireFence(const sp<SurfaceControl>& sc, const sp<Fence>& fence);
355 Transaction& setDataspace(const sp<SurfaceControl>& sc, ui::Dataspace dataspace);
356 Transaction& setHdrMetadata(const sp<SurfaceControl>& sc, const HdrMetadata& hdrMetadata);
357 Transaction& setSurfaceDamageRegion(const sp<SurfaceControl>& sc,
358 const Region& surfaceDamageRegion);
359 Transaction& setApi(const sp<SurfaceControl>& sc, int32_t api);
360 Transaction& setSidebandStream(const sp<SurfaceControl>& sc,
361 const sp<NativeHandle>& sidebandStream);
Marissa Wall17b4e452018-12-26 16:32:34 -0800362 Transaction& setDesiredPresentTime(nsecs_t desiredPresentTime);
Marissa Wall61c58622018-07-18 10:12:20 -0700363
Marissa Walle2ffb422018-10-12 11:33:52 -0700364 Transaction& addTransactionCompletedCallback(
365 TransactionCompletedCallbackTakesContext callback, void* callbackContext);
Marissa Wallc837b5e2018-10-12 10:04:44 -0700366
Robert Carr4cdc58f2017-08-23 14:22:20 -0700367 // Detaches all child surfaces (and their children recursively)
368 // from their SurfaceControl.
369 // The child SurfaceControls will not throw exceptions or return errors,
370 // but transactions will have no effect.
371 // The child surfaces will continue to follow their parent surfaces,
372 // and remain eligible for rendering, but their relative state will be
373 // frozen. We use this in the WindowManager, in app shutdown/relaunch
374 // scenarios, where the app would otherwise clean up its child Surfaces.
375 // Sometimes the WindowManager needs to extend their lifetime slightly
376 // in order to perform an exit animation or prevent flicker.
377 Transaction& detachChildren(const sp<SurfaceControl>& sc);
378 // Set an override scaling mode as documented in <system/window.h>
379 // the override scaling mode will take precedence over any client
380 // specified scaling mode. -1 will clear the override scaling mode.
381 Transaction& setOverrideScalingMode(const sp<SurfaceControl>& sc,
382 int32_t overrideScalingMode);
383
384 // If the size changes in this transaction, all geometry updates specified
385 // in this transaction will not complete until a buffer of the new size
386 // arrives. As some elements normally apply immediately, this enables
387 // freezing the total geometry of a surface until a resize is completed.
388 Transaction& setGeometryAppliesWithResize(const sp<SurfaceControl>& sc);
389
Robert Carr2c358bf2018-08-08 15:58:15 -0700390#ifndef NO_INPUT
391 Transaction& setInputWindowInfo(const sp<SurfaceControl>& sc, const InputWindowInfo& info);
chaviw273171b2018-12-26 11:46:30 -0800392 Transaction& transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken);
chaviwa911b102019-02-14 10:18:33 -0800393 Transaction& syncInputWindows();
Robert Carr2c358bf2018-08-08 15:58:15 -0700394#endif
395
Peiyong Lind3788632018-09-18 16:01:31 -0700396 // Set a color transform matrix on the given layer on the built-in display.
397 Transaction& setColorTransform(const sp<SurfaceControl>& sc, const mat3& matrix,
398 const vec3& translation);
399
Robert Carrfb4d58b2019-01-15 09:21:27 -0800400 Transaction& setGeometry(const sp<SurfaceControl>& sc,
401 const Rect& source, const Rect& dst, int transform);
402
Robert Carr4cdc58f2017-08-23 14:22:20 -0700403 status_t setDisplaySurface(const sp<IBinder>& token,
404 const sp<IGraphicBufferProducer>& bufferProducer);
405
406 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
407
408 /* setDisplayProjection() defines the projection of layer stacks
409 * to a given display.
410 *
411 * - orientation defines the display's orientation.
412 * - layerStackRect defines which area of the window manager coordinate
413 * space will be used.
414 * - displayRect defines where on the display will layerStackRect be
415 * mapped to. displayRect is specified post-orientation, that is
416 * it uses the orientation seen by the end-user.
417 */
418 void setDisplayProjection(const sp<IBinder>& token,
419 uint32_t orientation,
420 const Rect& layerStackRect,
421 const Rect& displayRect);
422 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
423 void setAnimationTransaction();
Dan Stoza84d619e2018-03-28 17:07:36 -0700424 void setEarlyWakeup();
Robert Carr4cdc58f2017-08-23 14:22:20 -0700425 };
Robert Carr82364e32016-05-15 11:27:47 -0700426
Svetoslavd85084b2014-03-20 10:28:31 -0700427 status_t clearLayerFrameStats(const sp<IBinder>& token) const;
428 status_t getLayerFrameStats(const sp<IBinder>& token, FrameStats* outStats) const;
Svetoslavd85084b2014-03-20 10:28:31 -0700429 static status_t clearAnimationFrameStats();
430 static status_t getAnimationFrameStats(FrameStats* outStats);
431
Dan Stozac4f471e2016-03-24 09:31:08 -0700432 static status_t getHdrCapabilities(const sp<IBinder>& display,
433 HdrCapabilities* outCapabilities);
434
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700435 static void setDisplayProjection(const sp<IBinder>& token,
436 uint32_t orientation,
437 const Rect& layerStackRect,
438 const Rect& displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700439
Robert Carr4cdc58f2017-08-23 14:22:20 -0700440 inline sp<ISurfaceComposerClient> getClient() { return mClient; }
441
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700442 static status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
443 ui::PixelFormat* outFormat,
444 ui::Dataspace* outDataspace,
445 uint8_t* outComponentMask);
Kevin DuBois74e53772018-11-19 10:52:38 -0800446 static status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
447 uint8_t componentMask, uint64_t maxFrames);
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700448
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700449 static status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
450 uint64_t timestamp, DisplayedFrameStats* outStats);
451
Mathias Agopian631f3582010-05-25 17:51:34 -0700452private:
Mathias Agopiand4784a32010-05-27 19:41:15 -0700453 virtual void onFirstRef();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800454
Mathias Agopian698c0872011-06-28 19:09:31 -0700455 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800456 status_t mStatus;
Mathias Agopian7e27f052010-05-28 14:22:23 -0700457 sp<ISurfaceComposerClient> mClient;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800458};
459
Mathias Agopiand4784a32010-05-27 19:41:15 -0700460// ---------------------------------------------------------------------------
Mathias Agopian74c40c02010-09-29 13:02:36 -0700461
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000462class ScreenshotClient {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800463public:
Dan Stozac1879002014-05-22 15:59:05 -0700464 // if cropping isn't required, callers may pass in a default Rect, e.g.:
465 // capture(display, producer, Rect(), reqWidth, ...);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700466 static status_t capture(const sp<IBinder>& display, const ui::Dataspace reqDataSpace,
467 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
468 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
469 uint32_t rotation, sp<GraphicBuffer>* outBuffer);
470 static status_t captureLayers(const sp<IBinder>& layerHandle, const ui::Dataspace reqDataSpace,
471 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
472 float frameScale, sp<GraphicBuffer>* outBuffer);
473 static status_t captureChildLayers(const sp<IBinder>& layerHandle,
474 const ui::Dataspace reqDataSpace,
475 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
Robert Carr578038f2018-03-09 12:25:24 -0800476 float frameScale, sp<GraphicBuffer>* outBuffer);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700477};
478
479// ---------------------------------------------------------------------------
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700480
Marissa Wall80d94ad2019-01-18 16:04:36 -0800481class TransactionCompletedListener : public BnTransactionCompletedListener {
482 TransactionCompletedListener();
483
484 CallbackId getNextIdLocked() REQUIRES(mMutex);
485
486 std::mutex mMutex;
487
488 bool mListening GUARDED_BY(mMutex) = false;
489
490 CallbackId mCallbackIdCounter GUARDED_BY(mMutex) = 1;
491
492 struct IBinderHash {
493 std::size_t operator()(const sp<IBinder>& iBinder) const {
494 return std::hash<IBinder*>{}(iBinder.get());
495 }
496 };
497
498 struct CallbackTranslation {
499 TransactionCompletedCallback callbackFunction;
500 std::unordered_map<sp<IBinder>, sp<SurfaceControl>, IBinderHash> surfaceControls;
501 };
502
503 std::unordered_map<CallbackId, CallbackTranslation> mCallbacks GUARDED_BY(mMutex);
504
505public:
506 static sp<TransactionCompletedListener> getInstance();
507 static sp<ITransactionCompletedListener> getIInstance();
508
509 void startListeningLocked() REQUIRES(mMutex);
510
511 CallbackId addCallbackFunction(
512 const TransactionCompletedCallback& callbackFunction,
513 const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>&
514 surfaceControls);
515
516 void addSurfaceControlToCallbacks(const sp<SurfaceControl>& surfaceControl,
517 const std::unordered_set<CallbackId>& callbackIds);
518
519 // Overrides BnTransactionCompletedListener's onTransactionCompleted
520 void onTransactionCompleted(ListenerStats stats) override;
521};
522
523// ---------------------------------------------------------------------------
524
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800525}; // namespace android
526
Mathias Agopian90ac7992012-02-25 18:48:35 -0800527#endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H