blob: 15287e2cb6fbf81505335b855fc6b6d3b545bb98 [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>
Robert Carr866455f2019-04-02 16:28:26 -070040#include <gui/ISurfaceComposer.h>
Marissa Wall7a9b6ff2018-08-21 17:26:20 -070041#include <gui/ITransactionCompletedListener.h>
42#include <gui/LayerState.h>
Mathias Agopiane3c697f2013-02-14 17:11:02 -080043#include <gui/SurfaceControl.h>
chaviw13fdc492017-06-27 12:40:18 -070044#include <math/vec3.h>
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080045
46namespace android {
47
48// ---------------------------------------------------------------------------
49
Colin Crossa2362b42016-09-26 13:48:25 -070050struct DisplayInfo;
Dan Stozac4f471e2016-03-24 09:31:08 -070051class HdrCapabilities;
Mathias Agopian41f673c2011-11-17 17:48:35 -080052class ISurfaceComposerClient;
Andy McFadden2adaf042012-12-18 09:49:45 -080053class IGraphicBufferProducer;
Kevin DuBois00c66832019-02-18 16:21:31 -080054class IRegionSamplingListener;
Mathias Agopiana67932f2011-04-20 14:20:59 -070055class Region;
Mathias Agopianb7e930d2010-06-01 15:12:58 -070056
57// ---------------------------------------------------------------------------
58
Marissa Wall80d94ad2019-01-18 16:04:36 -080059struct SurfaceControlStats {
60 SurfaceControlStats(const sp<SurfaceControl>& sc, nsecs_t time,
61 const sp<Fence>& prevReleaseFence)
62 : surfaceControl(sc), acquireTime(time), previousReleaseFence(prevReleaseFence) {}
Marissa Wallc837b5e2018-10-12 10:04:44 -070063
Marissa Wall80d94ad2019-01-18 16:04:36 -080064 sp<SurfaceControl> surfaceControl;
65 nsecs_t acquireTime = -1;
66 sp<Fence> previousReleaseFence;
Marissa Wall7a9b6ff2018-08-21 17:26:20 -070067};
68
Marissa Wall80d94ad2019-01-18 16:04:36 -080069using TransactionCompletedCallbackTakesContext =
70 std::function<void(void* /*context*/, nsecs_t /*latchTime*/,
71 const sp<Fence>& /*presentFence*/,
72 const std::vector<SurfaceControlStats>& /*stats*/)>;
73using TransactionCompletedCallback =
74 std::function<void(nsecs_t /*latchTime*/, const sp<Fence>& /*presentFence*/,
75 const std::vector<SurfaceControlStats>& /*stats*/)>;
76
Marissa Wall7a9b6ff2018-08-21 17:26:20 -070077// ---------------------------------------------------------------------------
78
Mathias Agopiand4784a32010-05-27 19:41:15 -070079class SurfaceComposerClient : public RefBase
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080080{
Mathias Agopian698c0872011-06-28 19:09:31 -070081 friend class Composer;
Jesse Hall6c913be2013-08-08 12:15:49 -070082public:
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080083 SurfaceComposerClient();
Jorim Jaggif3cf4bc2017-11-30 14:19:23 +010084 SurfaceComposerClient(const sp<ISurfaceComposerClient>& client);
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080085 virtual ~SurfaceComposerClient();
86
87 // Always make sure we could initialize
88 status_t initCheck() const;
89
90 // Return the connection of this client
91 sp<IBinder> connection() const;
Jesse Hall6c913be2013-08-08 12:15:49 -070092
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -080093 // Forcibly remove connection before all references have gone away.
94 void dispose();
95
Mathias Agopiane57f2922012-08-09 16:29:12 -070096 // callback when the composer is dies
97 status_t linkToComposerDeath(const sp<IBinder::DeathRecipient>& recipient,
Yi Konga03e0442018-07-17 11:16:57 -070098 void* cookie = nullptr, uint32_t flags = 0);
Mathias Agopiane57f2922012-08-09 16:29:12 -070099
Dan Stoza7f7da322014-05-02 15:26:25 -0700100 // Get a list of supported configurations for a given display
101 static status_t getDisplayConfigs(const sp<IBinder>& display,
102 Vector<DisplayInfo>* configs);
103
104 // Get the DisplayInfo for the currently-active configuration
105 static status_t getDisplayInfo(const sp<IBinder>& display,
106 DisplayInfo* info);
107
108 // Get the index of the current active configuration (relative to the list
109 // returned by getDisplayInfo)
110 static int getActiveConfig(const sp<IBinder>& display);
111
112 // Set a new active configuration using an index relative to the list
113 // returned by getDisplayInfo
114 static status_t setActiveConfig(const sp<IBinder>& display, int id);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700115
Ady Abraham838de062019-02-04 10:24:03 -0800116 // Sets the allowed display configurations to be used.
117 // The allowedConfigs in a vector of indexes corresponding to the configurations
118 // returned from getDisplayConfigs().
119 static status_t setAllowedDisplayConfigs(const sp<IBinder>& displayToken,
120 const std::vector<int32_t>& allowedConfigs);
121
Ady Abrahamd9b3ea62019-02-26 14:08:03 -0800122 // Returns the allowed display configurations currently set.
123 // The allowedConfigs in a vector of indexes corresponding to the configurations
124 // returned from getDisplayConfigs().
125 static status_t getAllowedDisplayConfigs(const sp<IBinder>& displayToken,
126 std::vector<int32_t>* outAllowedConfigs);
127
Michael Wright28f24d02016-07-12 13:30:53 -0700128 // Gets the list of supported color modes for the given display
129 static status_t getDisplayColorModes(const sp<IBinder>& display,
Peiyong Lin9f034472018-03-28 15:29:00 -0700130 Vector<ui::ColorMode>* outColorModes);
Michael Wright28f24d02016-07-12 13:30:53 -0700131
Daniel Solomon42d04562019-01-20 21:03:19 -0800132 // Get the coordinates of the display's native color primaries
133 static status_t getDisplayNativePrimaries(const sp<IBinder>& display,
134 ui::DisplayPrimaries& outPrimaries);
135
Michael Wright28f24d02016-07-12 13:30:53 -0700136 // Gets the active color mode for the given display
Peiyong Lin9f034472018-03-28 15:29:00 -0700137 static ui::ColorMode getActiveColorMode(const sp<IBinder>& display);
Michael Wright28f24d02016-07-12 13:30:53 -0700138
139 // Sets the active color mode for the given display
Peiyong Lin9f034472018-03-28 15:29:00 -0700140 static status_t setActiveColorMode(const sp<IBinder>& display,
141 ui::ColorMode colorMode);
Michael Wright28f24d02016-07-12 13:30:53 -0700142
Prashant Malani2c9b11f2014-05-25 01:36:31 -0700143 /* Triggers screen on/off or low power mode and waits for it to complete */
144 static void setDisplayPowerMode(const sp<IBinder>& display, int mode);
Jeff Brown2a09bb32012-10-08 19:13:57 -0700145
Peiyong Linc6780972018-10-28 15:24:08 -0700146 /* Returns the composition preference of the default data space and default pixel format,
147 * as well as the wide color gamut data space and wide color gamut pixel format.
148 * If the wide color gamut data space is V0_SRGB, then it implies that the platform
149 * has no wide color gamut support.
150 */
151 static status_t getCompositionPreference(ui::Dataspace* defaultDataspace,
152 ui::PixelFormat* defaultPixelFormat,
153 ui::Dataspace* wideColorGamutDataspace,
154 ui::PixelFormat* wideColorGamutPixelFormat);
Peiyong Lin0256f722018-08-31 15:45:10 -0700155
Peiyong Lin08d10512019-01-16 13:27:35 -0800156 /*
157 * Gets whether SurfaceFlinger can support protected content in GPU composition.
158 * Requires the ACCESS_SURFACE_FLINGER permission.
159 */
160 static bool getProtectedContentSupport();
161
Robert Carr6fb1a7e2018-12-11 12:07:25 -0800162 /**
163 * Called from SurfaceControl d'tor to 'destroy' the surface (or rather, reparent it
164 * to null), but without needing an sp<SurfaceControl> to avoid infinite ressurection.
165 */
Vishnu Nairf03652d2019-07-16 17:56:56 -0700166 static void doDropReferenceTransaction(const sp<IBinder>& handle);
Robert Carr6fb1a7e2018-12-11 12:07:25 -0800167
Marissa Wall78b72202019-03-15 14:58:34 -0700168 /**
169 * Uncaches a buffer in ISurfaceComposer. It must be uncached via a transaction so that it is
170 * in order with other transactions that use buffers.
171 */
172 static void doUncacheBufferTransaction(uint64_t cacheId);
173
Peiyong Lin4f3fddf2019-01-24 17:21:24 -0800174 // Queries whether a given display is wide color display.
175 static status_t isWideColorDisplay(const sp<IBinder>& display, bool* outIsWideColorDisplay);
176
Dan Gittik57e63c52019-01-18 16:37:54 +0000177 /*
178 * Returns whether brightness operations are supported on a display.
179 *
180 * displayToken
181 * The token of the display.
182 *
183 * Returns whether brightness operations are supported on a display or not.
184 */
185 static bool getDisplayBrightnessSupport(const sp<IBinder>& displayToken);
186
187 /*
188 * Sets the brightness of a display.
189 *
190 * displayToken
191 * The token of the display whose brightness is set.
192 * brightness
193 * A number between 0.0 (minimum brightness) and 1.0 (maximum brightness), or -1.0f to
194 * turn the backlight off.
195 *
196 * Returns NO_ERROR upon success. Otherwise,
197 * NAME_NOT_FOUND if the display handle is invalid, or
198 * BAD_VALUE if the brightness value is invalid, or
199 * INVALID_OPERATION if brightness operaetions are not supported.
200 */
201 static status_t setDisplayBrightness(const sp<IBinder>& displayToken, float brightness);
202
Ady Abraham8532d012019-05-08 14:50:56 -0700203 /*
204 * Sends a power hint to the composer. This function is asynchronous.
205 *
206 * hintId
207 * hint id according to android::hardware::power::V1_0::PowerHint
208 *
209 * Returns NO_ERROR upon success.
210 */
211 static status_t notifyPowerHint(int32_t hintId);
212
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800213 // ------------------------------------------------------------------------
214 // surface creation / destruction
215
Robert Carrfb4d58b2019-01-15 09:21:27 -0800216 static sp<SurfaceComposerClient> getDefault();
217
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800218 //! Create a surface
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800219 sp<SurfaceControl> createSurface(const String8& name, // name of the surface
220 uint32_t w, // width in pixel
221 uint32_t h, // height in pixel
222 PixelFormat format, // pixel-format desired
223 uint32_t flags = 0, // usage flags
224 SurfaceControl* parent = nullptr, // parent
225 LayerMetadata metadata = LayerMetadata() // metadata
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800226 );
227
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800228 status_t createSurfaceChecked(const String8& name, // name of the surface
229 uint32_t w, // width in pixel
230 uint32_t h, // height in pixel
231 PixelFormat format, // pixel-format desired
232 sp<SurfaceControl>* outSurface,
233 uint32_t flags = 0, // usage flags
234 SurfaceControl* parent = nullptr, // parent
235 LayerMetadata metadata = LayerMetadata() // metadata
Marissa Wall35187b32019-01-08 10:08:52 -0800236 );
237
238 //! Create a surface
Evan Rosky1f6d6d52018-12-06 10:47:26 -0800239 sp<SurfaceControl> createWithSurfaceParent(const String8& name, // name of the surface
240 uint32_t w, // width in pixel
241 uint32_t h, // height in pixel
242 PixelFormat format, // pixel-format desired
243 uint32_t flags = 0, // usage flags
244 Surface* parent = nullptr, // parent
245 LayerMetadata metadata = LayerMetadata() // metadata
Robert Carr3b382ed2018-03-14 13:49:41 -0700246 );
247
Jesse Hall6c913be2013-08-08 12:15:49 -0700248 //! Create a virtual display
Jamie Gennisdd3cb842012-10-19 18:19:11 -0700249 static sp<IBinder> createDisplay(const String8& displayName, bool secure);
Mathias Agopian285dbde2010-03-01 16:09:43 -0800250
Jesse Hall6c913be2013-08-08 12:15:49 -0700251 //! Destroy a virtual display
252 static void destroyDisplay(const sp<IBinder>& display);
253
Dominik Laskowskidcb38bb2019-01-25 02:35:50 -0800254 //! Get stable IDs for connected physical displays
255 static std::vector<PhysicalDisplayId> getPhysicalDisplayIds();
256 static std::optional<PhysicalDisplayId> getInternalDisplayId();
257
258 //! Get token for a physical display given its stable ID
259 static sp<IBinder> getPhysicalDisplayToken(PhysicalDisplayId displayId);
260 static sp<IBinder> getInternalDisplayToken();
Jeff Brown9d4e3d22012-08-24 20:00:51 -0700261
Sahil Dhanjuc1ba5c42016-06-07 20:09:20 -0700262 static status_t enableVSyncInjections(bool enable);
263
264 static status_t injectVSync(nsecs_t when);
265
chaviw8e3fe5d2018-02-22 10:55:42 -0800266 struct SCHash {
267 std::size_t operator()(const sp<SurfaceControl>& sc) const {
268 return std::hash<SurfaceControl *>{}(sc.get());
269 }
270 };
271
Vishnu Nairf03652d2019-07-16 17:56:56 -0700272 struct IBinderHash {
273 std::size_t operator()(const sp<IBinder>& iBinder) const {
274 return std::hash<IBinder*>{}(iBinder.get());
275 }
276 };
277
Marissa Wallc837b5e2018-10-12 10:04:44 -0700278 struct TCLHash {
279 std::size_t operator()(const sp<ITransactionCompletedListener>& tcl) const {
280 return std::hash<IBinder*>{}((tcl) ? IInterface::asBinder(tcl).get() : nullptr);
281 }
282 };
283
284 struct CallbackInfo {
285 // All the callbacks that have been requested for a TransactionCompletedListener in the
286 // Transaction
287 std::unordered_set<CallbackId> callbackIds;
288 // All the SurfaceControls that have been modified in this TransactionCompletedListener's
289 // process that require a callback if there is one or more callbackIds set.
290 std::unordered_set<sp<SurfaceControl>, SCHash> surfaceControls;
291 };
292
Valerie Hau2b0cd8d2019-08-26 10:30:52 -0700293 class Transaction : public Parcelable {
Valerie Hau9dab9732019-08-20 09:29:25 -0700294 protected:
Vishnu Nairf03652d2019-07-16 17:56:56 -0700295 std::unordered_map<sp<IBinder>, ComposerState, IBinderHash> mComposerStates;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700296 SortedVector<DisplayState > mDisplayStates;
Marissa Wallc837b5e2018-10-12 10:04:44 -0700297 std::unordered_map<sp<ITransactionCompletedListener>, CallbackInfo, TCLHash>
298 mListenerCallbacks;
299
Robert Carr4cdc58f2017-08-23 14:22:20 -0700300 uint32_t mForceSynchronous = 0;
301 uint32_t mTransactionNestCount = 0;
302 bool mAnimation = false;
Dan Stoza84d619e2018-03-28 17:07:36 -0700303 bool mEarlyWakeup = false;
Jamie Gennis2d5e2302012-10-15 18:24:43 -0700304
Marissa Wall78b72202019-03-15 14:58:34 -0700305 // Indicates that the Transaction contains a buffer that should be cached
306 bool mContainsBuffer = false;
307
Marissa Wall17b4e452018-12-26 16:32:34 -0800308 // mDesiredPresentTime is the time in nanoseconds that the client would like the transaction
309 // to be presented. When it is not possible to present at exactly that time, it will be
310 // presented after the time has passed.
311 //
312 // Desired present times that are more than 1 second in the future may be ignored.
313 // When a desired present time has already passed, the transaction will be presented as soon
314 // as possible.
315 //
316 // Transactions from the same process are presented in the same order that they are applied.
317 // The desired present time does not affect this ordering.
318 int64_t mDesiredPresentTime = -1;
319
chaviw273171b2018-12-26 11:46:30 -0800320 InputWindowCommands mInputWindowCommands;
Robert Carr4cdc58f2017-08-23 14:22:20 -0700321 int mStatus = NO_ERROR;
322
Vishnu Nairf03652d2019-07-16 17:56:56 -0700323 layer_state_t* getLayerState(const sp<IBinder>& surfaceHandle);
324 layer_state_t* getLayerState(const sp<SurfaceControl>& sc) {
325 return getLayerState(sc->getHandle());
326 }
chaviw763ef572018-02-22 16:04:57 -0800327 DisplayState& getDisplayState(const sp<IBinder>& token);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700328
Marissa Wall78b72202019-03-15 14:58:34 -0700329 void cacheBuffers();
Marissa Wallc837b5e2018-10-12 10:04:44 -0700330 void registerSurfaceControlForCallback(const sp<SurfaceControl>& sc);
331
Robert Carr4cdc58f2017-08-23 14:22:20 -0700332 public:
333 Transaction() = default;
334 virtual ~Transaction() = default;
335 Transaction(Transaction const& other);
336
Vishnu Nair621102e2019-06-12 14:16:57 -0700337 // Factory method that creates a new Transaction instance from the parcel.
338 static std::unique_ptr<Transaction> createFromParcel(const Parcel* parcel);
339
340 status_t writeToParcel(Parcel* parcel) const override;
341 status_t readFromParcel(const Parcel* parcel) override;
342
Vishnu Nairfef244e2019-06-17 18:07:51 -0700343 // Clears the contents of the transaction without applying it.
344 void clear();
345
Robert Carr4cdc58f2017-08-23 14:22:20 -0700346 status_t apply(bool synchronous = false);
Robert Carr2c5f6d22017-09-26 12:30:35 -0700347 // Merge another transaction in to this one, clearing other
348 // as if it had been applied.
349 Transaction& merge(Transaction&& other);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700350 Transaction& show(const sp<SurfaceControl>& sc);
351 Transaction& hide(const sp<SurfaceControl>& sc);
352 Transaction& setPosition(const sp<SurfaceControl>& sc,
353 float x, float y);
354 Transaction& setSize(const sp<SurfaceControl>& sc,
355 uint32_t w, uint32_t h);
356 Transaction& setLayer(const sp<SurfaceControl>& sc,
357 int32_t z);
358
359 // Sets a Z order relative to the Surface specified by "relativeTo" but
360 // without becoming a full child of the relative. Z-ordering works exactly
361 // as if it were a child however.
362 //
363 // As a nod to sanity, only non-child surfaces may have a relative Z-order.
364 //
365 // This overrides any previous call and is overriden by any future calls
366 // to setLayer.
367 //
368 // If the relative is removed, the Surface will have no layer and be
369 // invisible, until the next time set(Relative)Layer is called.
370 Transaction& setRelativeLayer(const sp<SurfaceControl>& sc,
371 const sp<IBinder>& relativeTo, int32_t z);
372 Transaction& setFlags(const sp<SurfaceControl>& sc,
373 uint32_t flags, uint32_t mask);
374 Transaction& setTransparentRegionHint(const sp<SurfaceControl>& sc,
375 const Region& transparentRegion);
376 Transaction& setAlpha(const sp<SurfaceControl>& sc,
377 float alpha);
378 Transaction& setMatrix(const sp<SurfaceControl>& sc,
379 float dsdx, float dtdx, float dtdy, float dsdy);
Marissa Wallf58c14b2018-07-24 10:50:43 -0700380 Transaction& setCrop_legacy(const sp<SurfaceControl>& sc, const Rect& crop);
Lucas Dupin1b6531c2018-07-05 17:18:21 -0700381 Transaction& setCornerRadius(const sp<SurfaceControl>& sc, float cornerRadius);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700382 Transaction& setLayerStack(const sp<SurfaceControl>& sc, uint32_t layerStack);
Garfield Tan01a56132019-08-05 16:44:21 -0700383 Transaction& setMetadata(const sp<SurfaceControl>& sc, uint32_t key, const Parcel& p);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700384 // Defers applying any changes made in this transaction until the Layer
385 // identified by handle reaches the given frameNumber. If the Layer identified
386 // by handle is removed, then we will apply this transaction regardless of
387 // what frame number has been reached.
Marissa Wallf58c14b2018-07-24 10:50:43 -0700388 Transaction& deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
389 const sp<IBinder>& handle, uint64_t frameNumber);
390 // A variant of deferTransactionUntil_legacy which identifies the Layer we wait for by
Robert Carr4cdc58f2017-08-23 14:22:20 -0700391 // Surface instead of Handle. Useful for clients which may not have the
392 // SurfaceControl for some of their Surfaces. Otherwise behaves identically.
Marissa Wallf58c14b2018-07-24 10:50:43 -0700393 Transaction& deferTransactionUntil_legacy(const sp<SurfaceControl>& sc,
394 const sp<Surface>& barrierSurface,
395 uint64_t frameNumber);
Robert Carr4cdc58f2017-08-23 14:22:20 -0700396 // Reparents all children of this layer to the new parent handle.
397 Transaction& reparentChildren(const sp<SurfaceControl>& sc,
398 const sp<IBinder>& newParentHandle);
399
400 /// Reparents the current layer to the new parent handle. The new parent must not be null.
401 // This can be used instead of reparentChildren if the caller wants to
402 // only re-parent a specific child.
403 Transaction& reparent(const sp<SurfaceControl>& sc,
404 const sp<IBinder>& newParentHandle);
405
406 Transaction& setColor(const sp<SurfaceControl>& sc, const half3& color);
407
Valerie Haudd0b7572019-01-29 14:59:27 -0800408 // Sets the background color of a layer with the specified color, alpha, and dataspace
409 Transaction& setBackgroundColor(const sp<SurfaceControl>& sc, const half3& color,
410 float alpha, ui::Dataspace dataspace);
Valerie Haued54efa2019-01-11 20:03:14 -0800411
Marissa Wall61c58622018-07-18 10:12:20 -0700412 Transaction& setTransform(const sp<SurfaceControl>& sc, uint32_t transform);
413 Transaction& setTransformToDisplayInverse(const sp<SurfaceControl>& sc,
414 bool transformToDisplayInverse);
415 Transaction& setCrop(const sp<SurfaceControl>& sc, const Rect& crop);
Marissa Wall861616d2018-10-22 12:52:23 -0700416 Transaction& setFrame(const sp<SurfaceControl>& sc, const Rect& frame);
Marissa Wall61c58622018-07-18 10:12:20 -0700417 Transaction& setBuffer(const sp<SurfaceControl>& sc, const sp<GraphicBuffer>& buffer);
Marissa Wallebc2c052019-01-16 19:16:55 -0800418 Transaction& setCachedBuffer(const sp<SurfaceControl>& sc, int32_t bufferId);
Marissa Wall61c58622018-07-18 10:12:20 -0700419 Transaction& setAcquireFence(const sp<SurfaceControl>& sc, const sp<Fence>& fence);
420 Transaction& setDataspace(const sp<SurfaceControl>& sc, ui::Dataspace dataspace);
421 Transaction& setHdrMetadata(const sp<SurfaceControl>& sc, const HdrMetadata& hdrMetadata);
422 Transaction& setSurfaceDamageRegion(const sp<SurfaceControl>& sc,
423 const Region& surfaceDamageRegion);
424 Transaction& setApi(const sp<SurfaceControl>& sc, int32_t api);
425 Transaction& setSidebandStream(const sp<SurfaceControl>& sc,
426 const sp<NativeHandle>& sidebandStream);
Marissa Wall17b4e452018-12-26 16:32:34 -0800427 Transaction& setDesiredPresentTime(nsecs_t desiredPresentTime);
Peiyong Linc502cb72019-03-01 15:00:23 -0800428 Transaction& setColorSpaceAgnostic(const sp<SurfaceControl>& sc, const bool agnostic);
Marissa Wall61c58622018-07-18 10:12:20 -0700429
Marissa Walle2ffb422018-10-12 11:33:52 -0700430 Transaction& addTransactionCompletedCallback(
431 TransactionCompletedCallbackTakesContext callback, void* callbackContext);
Marissa Wallc837b5e2018-10-12 10:04:44 -0700432
Robert Carr4cdc58f2017-08-23 14:22:20 -0700433 // Detaches all child surfaces (and their children recursively)
434 // from their SurfaceControl.
435 // The child SurfaceControls will not throw exceptions or return errors,
436 // but transactions will have no effect.
437 // The child surfaces will continue to follow their parent surfaces,
438 // and remain eligible for rendering, but their relative state will be
439 // frozen. We use this in the WindowManager, in app shutdown/relaunch
440 // scenarios, where the app would otherwise clean up its child Surfaces.
441 // Sometimes the WindowManager needs to extend their lifetime slightly
442 // in order to perform an exit animation or prevent flicker.
443 Transaction& detachChildren(const sp<SurfaceControl>& sc);
444 // Set an override scaling mode as documented in <system/window.h>
445 // the override scaling mode will take precedence over any client
446 // specified scaling mode. -1 will clear the override scaling mode.
447 Transaction& setOverrideScalingMode(const sp<SurfaceControl>& sc,
448 int32_t overrideScalingMode);
449
Robert Carr2c358bf2018-08-08 15:58:15 -0700450#ifndef NO_INPUT
451 Transaction& setInputWindowInfo(const sp<SurfaceControl>& sc, const InputWindowInfo& info);
chaviw273171b2018-12-26 11:46:30 -0800452 Transaction& transferTouchFocus(const sp<IBinder>& fromToken, const sp<IBinder>& toToken);
chaviwa911b102019-02-14 10:18:33 -0800453 Transaction& syncInputWindows();
Robert Carr2c358bf2018-08-08 15:58:15 -0700454#endif
455
Peiyong Lind3788632018-09-18 16:01:31 -0700456 // Set a color transform matrix on the given layer on the built-in display.
457 Transaction& setColorTransform(const sp<SurfaceControl>& sc, const mat3& matrix,
458 const vec3& translation);
459
Robert Carrfb4d58b2019-01-15 09:21:27 -0800460 Transaction& setGeometry(const sp<SurfaceControl>& sc,
461 const Rect& source, const Rect& dst, int transform);
462
Robert Carr4cdc58f2017-08-23 14:22:20 -0700463 status_t setDisplaySurface(const sp<IBinder>& token,
464 const sp<IGraphicBufferProducer>& bufferProducer);
465
466 void setDisplayLayerStack(const sp<IBinder>& token, uint32_t layerStack);
467
468 /* setDisplayProjection() defines the projection of layer stacks
469 * to a given display.
470 *
471 * - orientation defines the display's orientation.
472 * - layerStackRect defines which area of the window manager coordinate
473 * space will be used.
474 * - displayRect defines where on the display will layerStackRect be
475 * mapped to. displayRect is specified post-orientation, that is
476 * it uses the orientation seen by the end-user.
477 */
478 void setDisplayProjection(const sp<IBinder>& token,
479 uint32_t orientation,
480 const Rect& layerStackRect,
481 const Rect& displayRect);
482 void setDisplaySize(const sp<IBinder>& token, uint32_t width, uint32_t height);
483 void setAnimationTransaction();
Dan Stoza84d619e2018-03-28 17:07:36 -0700484 void setEarlyWakeup();
Robert Carr4cdc58f2017-08-23 14:22:20 -0700485 };
Robert Carr82364e32016-05-15 11:27:47 -0700486
Svetoslavd85084b2014-03-20 10:28:31 -0700487 status_t clearLayerFrameStats(const sp<IBinder>& token) const;
488 status_t getLayerFrameStats(const sp<IBinder>& token, FrameStats* outStats) const;
Svetoslavd85084b2014-03-20 10:28:31 -0700489 static status_t clearAnimationFrameStats();
490 static status_t getAnimationFrameStats(FrameStats* outStats);
491
Dan Stozac4f471e2016-03-24 09:31:08 -0700492 static status_t getHdrCapabilities(const sp<IBinder>& display,
493 HdrCapabilities* outCapabilities);
494
Mathias Agopian00e8c7a2012-09-04 19:30:46 -0700495 static void setDisplayProjection(const sp<IBinder>& token,
496 uint32_t orientation,
497 const Rect& layerStackRect,
498 const Rect& displayRect);
Mathias Agopiane57f2922012-08-09 16:29:12 -0700499
Robert Carr4cdc58f2017-08-23 14:22:20 -0700500 inline sp<ISurfaceComposerClient> getClient() { return mClient; }
501
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700502 static status_t getDisplayedContentSamplingAttributes(const sp<IBinder>& display,
503 ui::PixelFormat* outFormat,
504 ui::Dataspace* outDataspace,
505 uint8_t* outComponentMask);
Kevin DuBois74e53772018-11-19 10:52:38 -0800506 static status_t setDisplayContentSamplingEnabled(const sp<IBinder>& display, bool enable,
507 uint8_t componentMask, uint64_t maxFrames);
Kevin DuBois9c0a1762018-10-16 13:32:31 -0700508
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700509 static status_t getDisplayedContentSample(const sp<IBinder>& display, uint64_t maxFrames,
510 uint64_t timestamp, DisplayedFrameStats* outStats);
Kevin DuBois00c66832019-02-18 16:21:31 -0800511 static status_t addRegionSamplingListener(const Rect& samplingArea,
512 const sp<IBinder>& stopLayerHandle,
513 const sp<IRegionSamplingListener>& listener);
514 static status_t removeRegionSamplingListener(const sp<IRegionSamplingListener>& listener);
Kevin DuBois1d4249a2018-08-29 10:45:14 -0700515
Mathias Agopian631f3582010-05-25 17:51:34 -0700516private:
Mathias Agopiand4784a32010-05-27 19:41:15 -0700517 virtual void onFirstRef();
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800518
Mathias Agopian698c0872011-06-28 19:09:31 -0700519 mutable Mutex mLock;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800520 status_t mStatus;
Mathias Agopian7e27f052010-05-28 14:22:23 -0700521 sp<ISurfaceComposerClient> mClient;
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800522};
523
Mathias Agopiand4784a32010-05-27 19:41:15 -0700524// ---------------------------------------------------------------------------
Mathias Agopian74c40c02010-09-29 13:02:36 -0700525
Chavi Weingarten40482ff2017-11-30 01:51:40 +0000526class ScreenshotClient {
Mathias Agopian2a9fc492013-03-01 13:42:57 -0800527public:
Dan Stozac1879002014-05-22 15:59:05 -0700528 // if cropping isn't required, callers may pass in a default Rect, e.g.:
529 // capture(display, producer, Rect(), reqWidth, ...);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700530 static status_t capture(const sp<IBinder>& display, const ui::Dataspace reqDataSpace,
531 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
532 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
Robert Carr108b2c72019-04-02 16:32:58 -0700533 uint32_t rotation, bool captureSecureLayers,
534 sp<GraphicBuffer>* outBuffer, bool& outCapturedSecureLayers);
Robert Carrfa8855f2019-02-19 10:05:00 -0800535 static status_t capture(const sp<IBinder>& display, const ui::Dataspace reqDataSpace,
536 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
537 uint32_t reqWidth, uint32_t reqHeight, bool useIdentityTransform,
Peiyong Lin0e003c92018-09-17 11:09:51 -0700538 uint32_t rotation, sp<GraphicBuffer>* outBuffer);
chaviw93df2ea2019-04-30 16:45:12 -0700539 static status_t capture(uint64_t displayOrLayerStack, ui::Dataspace* outDataspace,
540 sp<GraphicBuffer>* outBuffer);
Peiyong Lin0e003c92018-09-17 11:09:51 -0700541 static status_t captureLayers(const sp<IBinder>& layerHandle, const ui::Dataspace reqDataSpace,
542 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
543 float frameScale, sp<GraphicBuffer>* outBuffer);
Robert Carr866455f2019-04-02 16:28:26 -0700544 static status_t captureChildLayers(
545 const sp<IBinder>& layerHandle, const ui::Dataspace reqDataSpace,
546 const ui::PixelFormat reqPixelFormat, Rect sourceCrop,
547 const std::unordered_set<sp<IBinder>, ISurfaceComposer::SpHash<IBinder>>&
548 excludeHandles,
549 float frameScale, sp<GraphicBuffer>* outBuffer);
Mathias Agopian74c40c02010-09-29 13:02:36 -0700550};
551
552// ---------------------------------------------------------------------------
Marissa Wall7a9b6ff2018-08-21 17:26:20 -0700553
Marissa Wall80d94ad2019-01-18 16:04:36 -0800554class TransactionCompletedListener : public BnTransactionCompletedListener {
555 TransactionCompletedListener();
556
557 CallbackId getNextIdLocked() REQUIRES(mMutex);
558
559 std::mutex mMutex;
560
561 bool mListening GUARDED_BY(mMutex) = false;
562
563 CallbackId mCallbackIdCounter GUARDED_BY(mMutex) = 1;
564
Marissa Wall80d94ad2019-01-18 16:04:36 -0800565 struct CallbackTranslation {
566 TransactionCompletedCallback callbackFunction;
Vishnu Nairf03652d2019-07-16 17:56:56 -0700567 std::unordered_map<sp<IBinder>, sp<SurfaceControl>, SurfaceComposerClient::IBinderHash>
568 surfaceControls;
Marissa Wall80d94ad2019-01-18 16:04:36 -0800569 };
570
571 std::unordered_map<CallbackId, CallbackTranslation> mCallbacks GUARDED_BY(mMutex);
572
573public:
574 static sp<TransactionCompletedListener> getInstance();
575 static sp<ITransactionCompletedListener> getIInstance();
576
577 void startListeningLocked() REQUIRES(mMutex);
578
579 CallbackId addCallbackFunction(
580 const TransactionCompletedCallback& callbackFunction,
581 const std::unordered_set<sp<SurfaceControl>, SurfaceComposerClient::SCHash>&
582 surfaceControls);
583
584 void addSurfaceControlToCallbacks(const sp<SurfaceControl>& surfaceControl,
585 const std::unordered_set<CallbackId>& callbackIds);
586
587 // Overrides BnTransactionCompletedListener's onTransactionCompleted
588 void onTransactionCompleted(ListenerStats stats) override;
589};
590
591// ---------------------------------------------------------------------------
592
The Android Open Source Projectedbf3b62009-03-03 19:31:44 -0800593}; // namespace android
594
Mathias Agopian90ac7992012-02-25 18:48:35 -0800595#endif // ANDROID_GUI_SURFACE_COMPOSER_CLIENT_H