1 /*
2 * Copyright (C) 2008 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
17 #ifndef ANDROID_SF_LAYER_STATE_H
18 #define ANDROID_SF_LAYER_STATE_H
19
20 #include <stdint.h>
21 #include <sys/types.h>
22 #include <span>
23
24 #include <android/gui/BorderSettings.h>
25 #include <android/gui/DisplayCaptureArgs.h>
26 #include <android/gui/IWindowInfosReportedListener.h>
27 #include <android/gui/LayerCaptureArgs.h>
28 #include <android/gui/TrustedPresentationThresholds.h>
29 #include <android/native_window.h>
30 #include <gui/DisplayLuts.h>
31 #include <gui/IGraphicBufferProducer.h>
32 #include <gui/ITransactionCompletedListener.h>
33 #include <math/mat4.h>
34
35 #include <android/gui/DropInputMode.h>
36 #include <android/gui/EdgeExtensionParameters.h>
37 #include <android/gui/FocusRequest.h>
38 #include <android/gui/TrustedOverlay.h>
39
40 #include <ftl/flags.h>
41 #include <gui/BufferReleaseChannel.h>
42 #include <gui/ISurfaceComposer.h>
43 #include <gui/LayerMetadata.h>
44 #include <gui/SpHash.h>
45 #include <gui/SurfaceControl.h>
46 #include <gui/WindowInfo.h>
47 #include <math/vec3.h>
48 #include <ui/BlurRegion.h>
49 #include <ui/GraphicTypes.h>
50 #include <ui/LayerStack.h>
51 #include <ui/PictureProfileHandle.h>
52 #include <ui/Rect.h>
53 #include <ui/Region.h>
54 #include <ui/Rotation.h>
55 #include <ui/StretchEffect.h>
56 #include <ui/Transform.h>
57 #include <utils/Errors.h>
58
59 namespace android {
60
61 class Parcel;
62
63 using gui::ISurfaceComposerClient;
64 using gui::LayerMetadata;
65
66 using gui::TrustedPresentationThresholds;
67
68 struct client_cache_t {
69 wp<IBinder> token = nullptr;
70 uint64_t id;
71
72 bool operator==(const client_cache_t& other) const { return id == other.id; }
73 bool operator!=(const client_cache_t&) const = default;
74
isValidclient_cache_t75 bool isValid() const { return token != nullptr; }
76 };
77
78 class TrustedPresentationListener : public Parcelable {
79 public:
80 struct State {
81 sp<ITransactionCompletedListener> callbackInterface;
82 int callbackId = -1;
83 bool operator==(const State&) const = default;
84 bool operator!=(const State&) const = default;
85 };
86
invoke(bool presentedWithinThresholds)87 void invoke(bool presentedWithinThresholds) {
88 mState.callbackInterface->onTrustedPresentationChanged(mState.callbackId,
89 presentedWithinThresholds);
90 }
configure(State && state)91 void configure(State&& state) { mState = std::move(state); }
getCallback()92 const sp<ITransactionCompletedListener>& getCallback() { return mState.callbackInterface; }
clear()93 void clear() {
94 mState.callbackInterface = nullptr;
95 mState.callbackId = -1;
96 }
97
98 status_t writeToParcel(Parcel* parcel) const;
99 status_t readFromParcel(const Parcel* parcel);
100
101 bool operator==(const TrustedPresentationListener& rhs) const { return mState == rhs.mState; }
102 bool operator!=(const TrustedPresentationListener&) const = default;
103
104 private:
105 State mState;
106 };
107
108 class BufferData : public Parcelable {
109 public:
110 virtual ~BufferData() = default;
hasBuffer()111 virtual bool hasBuffer() const { return buffer != nullptr; }
hasSameBuffer(const BufferData & other)112 virtual bool hasSameBuffer(const BufferData& other) const {
113 return buffer == other.buffer && frameNumber == other.frameNumber;
114 }
getWidth()115 virtual uint32_t getWidth() const { return buffer->getWidth(); }
getHeight()116 virtual uint32_t getHeight() const { return buffer->getHeight(); }
getBounds()117 Rect getBounds() const {
118 return {0, 0, static_cast<int32_t>(getWidth()), static_cast<int32_t>(getHeight())};
119 }
getId()120 virtual uint64_t getId() const { return buffer->getId(); }
getPixelFormat()121 virtual PixelFormat getPixelFormat() const { return buffer->getPixelFormat(); }
getUsage()122 virtual uint64_t getUsage() const { return buffer->getUsage(); }
123
124 enum class BufferDataChange : uint32_t {
125 fenceChanged = 0x01,
126 frameNumberChanged = 0x02,
127 cachedBufferChanged = 0x04,
128 };
129
130 sp<GraphicBuffer> buffer;
131 sp<Fence> acquireFence;
132
133 // Used by BlastBufferQueue to forward the framenumber generated by the
134 // graphics producer.
135 uint64_t frameNumber = 0;
136 bool hasBarrier = false;
137 uint64_t barrierFrameNumber = 0;
138 uint32_t producerId = 0;
139
140 // Listens to when the buffer is safe to be released. This is used for blast
141 // layers only. The callback includes a release fence as well as the graphic
142 // buffer id to identify the buffer.
143 sp<ITransactionCompletedListener> releaseBufferListener = nullptr;
144
145 // Stores which endpoint the release information should be sent to. We don't want to send the
146 // releaseCallbackId and release fence to all listeners so we store which listener the setBuffer
147 // was called with.
148 sp<IBinder> releaseBufferEndpoint;
149
150 ftl::Flags<BufferDataChange> flags;
151
152 client_cache_t cachedBuffer;
153
154 nsecs_t dequeueTime;
155
156 // Generates the release callback id based on the buffer id and frame number.
157 // This is used as an identifier when release callbacks are invoked.
158 ReleaseCallbackId generateReleaseCallbackId() const;
159
160 status_t writeToParcel(Parcel* parcel) const override;
161 status_t readFromParcel(const Parcel* parcel) override;
162 };
163
164 /*
165 * Used to communicate layer information between SurfaceFlinger and its clients.
166 */
167 struct layer_state_t {
168 enum Permission {
169 ACCESS_SURFACE_FLINGER = 0x1,
170 ROTATE_SURFACE_FLINGER = 0x2,
171 INTERNAL_SYSTEM_WINDOW = 0x4,
172 };
173
174 enum {
175 eLayerHidden = 0x01, // SURFACE_HIDDEN in SurfaceControl.java
176 eLayerOpaque = 0x02, // SURFACE_OPAQUE
177 eLayerSkipScreenshot = 0x40, // SKIP_SCREENSHOT
178 eLayerSecure = 0x80, // SECURE
179 // Queue up layer buffers instead of dropping the oldest buffer when this flag is
180 // set. This blocks the client until all the buffers have been presented. If the buffers
181 // have presentation timestamps, then we may drop buffers.
182 eEnableBackpressure = 0x100, // ENABLE_BACKPRESSURE
183 eLayerIsDisplayDecoration = 0x200, // DISPLAY_DECORATION
184 // Ignore any destination frame set on the layer. This is used when the buffer scaling mode
185 // is freeze and the destination frame is applied asynchronously with the buffer submission.
186 // This is needed to maintain compatibility for SurfaceView scaling behavior.
187 // See SurfaceView scaling behavior for more details.
188 eIgnoreDestinationFrame = 0x400,
189 eLayerIsRefreshRateIndicator = 0x800, // REFRESH_RATE_INDICATOR
190 // Sets a property on this layer indicating that its visible region should be considered
191 // when computing TrustedPresentation Thresholds.
192 eCanOccludePresentation = 0x1000,
193 // Indicates that the SurfaceControl should recover from buffer stuffing when
194 // possible. This is the case when the SurfaceControl is the root SurfaceControl
195 // owned by ViewRootImpl.
196 eRecoverableFromBufferStuffing = 0x2000,
197 };
198
199 enum {
200 ePositionChanged = 0x00000001,
201 eLayerChanged = 0x00000002,
202 eTrustedPresentationInfoChanged = 0x00000004,
203 eAlphaChanged = 0x00000008,
204 eMatrixChanged = 0x00000010,
205 eTransparentRegionChanged = 0x00000020,
206 eFlagsChanged = 0x00000040,
207 eLayerStackChanged = 0x00000080,
208 eFlushJankData = 0x00000100,
209 eCachingHintChanged = 0x00000200,
210 eDimmingEnabledChanged = 0x00000400,
211 eShadowRadiusChanged = 0x00000800,
212 eLutsChanged = 0x00001000,
213 eBufferCropChanged = 0x00002000,
214 eRelativeLayerChanged = 0x00004000,
215 eReparent = 0x00008000,
216 eColorChanged = 0x00010000,
217 eFrameRateCategoryChanged = 0x00020000,
218 eBufferTransformChanged = 0x00040000,
219 eTransformToDisplayInverseChanged = 0x00080000,
220 eCropChanged = 0x00100000,
221 eBufferChanged = 0x00200000,
222 eDefaultFrameRateCompatibilityChanged = 0x00400000,
223 eDataspaceChanged = 0x00800000,
224 eHdrMetadataChanged = 0x01000000,
225 eSurfaceDamageRegionChanged = 0x02000000,
226 eApiChanged = 0x04000000,
227 eSidebandStreamChanged = 0x08000000,
228 eColorTransformChanged = 0x10000000,
229 eHasListenerCallbacksChanged = 0x20000000,
230 eInputInfoChanged = 0x40000000,
231 eCornerRadiusChanged = 0x80000000,
232 eDestinationFrameChanged = 0x1'00000000,
233 eFrameRateSelectionStrategyChanged = 0x2'00000000,
234 eBackgroundColorChanged = 0x4'00000000,
235 eMetadataChanged = 0x8'00000000,
236 eColorSpaceAgnosticChanged = 0x10'00000000,
237 eFrameRateSelectionPriority = 0x20'00000000,
238 eFrameRateChanged = 0x40'00000000,
239 eBackgroundBlurRadiusChanged = 0x80'00000000,
240 eProducerDisconnect = 0x100'00000000,
241 eFixedTransformHintChanged = 0x200'00000000,
242 eDesiredHdrHeadroomChanged = 0x400'00000000,
243 eBlurRegionsChanged = 0x800'00000000,
244 eAutoRefreshChanged = 0x1000'00000000,
245 eStretchChanged = 0x2000'00000000,
246 eTrustedOverlayChanged = 0x4000'00000000,
247 eDropInputModeChanged = 0x8000'00000000,
248 eExtendedRangeBrightnessChanged = 0x10000'00000000,
249 eEdgeExtensionChanged = 0x20000'00000000,
250 eBufferReleaseChannelChanged = 0x40000'00000000,
251 ePictureProfileHandleChanged = 0x80000'00000000,
252 eAppContentPriorityChanged = 0x100000'00000000,
253 eClientDrawnCornerRadiusChanged = 0x200000'00000000,
254 eBorderSettingsChanged = 0x400000'00000000,
255 };
256
257 layer_state_t();
258
259 void merge(const layer_state_t& other);
260 status_t write(Parcel& output) const;
261 status_t read(const Parcel& input);
262 // Compares two layer_state_t structs and returns a set of change flags describing all the
263 // states that are different.
264 uint64_t diff(const layer_state_t& other) const;
265 bool hasBufferChanges() const;
266
267 // Layer hierarchy updates.
268 static constexpr uint64_t HIERARCHY_CHANGES = layer_state_t::eLayerChanged |
269 layer_state_t::eRelativeLayerChanged | layer_state_t::eReparent |
270 layer_state_t::eLayerStackChanged;
271
272 // Geometry updates.
273 static constexpr uint64_t GEOMETRY_CHANGES = layer_state_t::eBufferCropChanged |
274 layer_state_t::eBufferTransformChanged | layer_state_t::eCornerRadiusChanged |
275 layer_state_t::eClientDrawnCornerRadiusChanged | layer_state_t::eCropChanged |
276 layer_state_t::eDestinationFrameChanged | layer_state_t::eMatrixChanged |
277 layer_state_t::ePositionChanged | layer_state_t::eTransformToDisplayInverseChanged |
278 layer_state_t::eTransparentRegionChanged | layer_state_t::eEdgeExtensionChanged;
279
280 // Buffer and related updates.
281 static constexpr uint64_t BUFFER_CHANGES = layer_state_t::eApiChanged |
282 layer_state_t::eBufferChanged | layer_state_t::eBufferCropChanged |
283 layer_state_t::eBufferTransformChanged | layer_state_t::eDataspaceChanged |
284 layer_state_t::eSidebandStreamChanged | layer_state_t::eSurfaceDamageRegionChanged |
285 layer_state_t::eTransformToDisplayInverseChanged |
286 layer_state_t::eTransparentRegionChanged |
287 layer_state_t::eExtendedRangeBrightnessChanged |
288 layer_state_t::eDesiredHdrHeadroomChanged | layer_state_t::eLutsChanged;
289
290 // Content updates.
291 static constexpr uint64_t CONTENT_CHANGES = layer_state_t::BUFFER_CHANGES |
292 layer_state_t::eAlphaChanged | layer_state_t::eAutoRefreshChanged |
293 layer_state_t::eBackgroundBlurRadiusChanged | layer_state_t::eBackgroundColorChanged |
294 layer_state_t::eBlurRegionsChanged | layer_state_t::eColorChanged |
295 layer_state_t::eColorSpaceAgnosticChanged | layer_state_t::eColorTransformChanged |
296 layer_state_t::eCornerRadiusChanged | layer_state_t::eDimmingEnabledChanged |
297 layer_state_t::eHdrMetadataChanged | layer_state_t::eShadowRadiusChanged |
298 layer_state_t::eStretchChanged | layer_state_t::ePictureProfileHandleChanged |
299 layer_state_t::eAppContentPriorityChanged | layer_state_t::eBorderSettingsChanged;
300
301 // Changes which invalidates the layer's visible region in CE.
302 static constexpr uint64_t CONTENT_DIRTY = layer_state_t::CONTENT_CHANGES |
303 layer_state_t::GEOMETRY_CHANGES | layer_state_t::HIERARCHY_CHANGES;
304
305 // Changes affecting child states.
306 static constexpr uint64_t AFFECTS_CHILDREN = layer_state_t::GEOMETRY_CHANGES |
307 layer_state_t::HIERARCHY_CHANGES | layer_state_t::eAlphaChanged |
308 layer_state_t::eBackgroundBlurRadiusChanged | layer_state_t::eBlurRegionsChanged |
309 layer_state_t::eColorTransformChanged | layer_state_t::eCornerRadiusChanged |
310 layer_state_t::eFlagsChanged | layer_state_t::eTrustedOverlayChanged |
311 layer_state_t::eFrameRateChanged | layer_state_t::eFrameRateCategoryChanged |
312 layer_state_t::eFrameRateSelectionStrategyChanged |
313 layer_state_t::eFrameRateSelectionPriority | layer_state_t::eFixedTransformHintChanged;
314
315 // Changes affecting data sent to input.
316 static constexpr uint64_t INPUT_CHANGES = layer_state_t::eAlphaChanged |
317 layer_state_t::eInputInfoChanged | layer_state_t::eDropInputModeChanged |
318 layer_state_t::eTrustedOverlayChanged | layer_state_t::eLayerStackChanged;
319
320 // Changes that affect the visible region on a display.
321 static constexpr uint64_t VISIBLE_REGION_CHANGES = layer_state_t::GEOMETRY_CHANGES |
322 layer_state_t::HIERARCHY_CHANGES | layer_state_t::eAlphaChanged;
323
324 // Changes that force GPU composition.
325 static constexpr uint64_t COMPOSITION_EFFECTS = layer_state_t::eBackgroundBlurRadiusChanged |
326 layer_state_t::eBlurRegionsChanged | layer_state_t::eCornerRadiusChanged |
327 layer_state_t::eShadowRadiusChanged | layer_state_t::eStretchChanged |
328 layer_state_t::eBorderSettingsChanged;
329
330 bool hasValidBuffer() const;
331 void sanitize(int32_t permissions);
332
333 void updateTransparentRegion(const Region& transparentRegion);
getTransparentRegionlayer_state_t334 const Region& getTransparentRegion() const { return mNotDefCmpState.transparentRegion; }
335 void updateSurfaceDamageRegion(const Region& surfaceDamageRegion);
getSurfaceDamageRegionlayer_state_t336 const Region& getSurfaceDamageRegion() const { return mNotDefCmpState.surfaceDamageRegion; }
337 // Do not update state flags. Used to set up test state.
setSurfaceDamageRegionlayer_state_t338 void setSurfaceDamageRegion(Region&& surfaceDamageRegion) {
339 mNotDefCmpState.surfaceDamageRegion = std::move(surfaceDamageRegion);
340 }
341 void updateRelativeLayer(const sp<SurfaceControl>& relativeTo, int32_t z);
342 void updateParentLayer(const sp<SurfaceControl>& newParent);
343 void updateInputWindowInfo(sp<gui::WindowInfoHandle>&& info);
getWindowInfolayer_state_t344 const gui::WindowInfo& getWindowInfo() const {
345 return *mNotDefCmpState.windowInfoHandle->getInfo();
346 }
editWindowInfolayer_state_t347 gui::WindowInfo* editWindowInfo() { return mNotDefCmpState.windowInfoHandle->editInfo(); }
348
getParentSurfaceControlForChildlayer_state_t349 const sp<SurfaceControl>& getParentSurfaceControlForChild() const {
350 return mNotDefCmpState.parentSurfaceControlForChild;
351 }
getRelativeLayerSurfaceControllayer_state_t352 const sp<SurfaceControl>& getRelativeLayerSurfaceControl() const {
353 return mNotDefCmpState.relativeLayerSurfaceControl;
354 }
355
356 bool operator==(const layer_state_t&) const = default;
357 bool operator!=(const layer_state_t&) const = default;
358
359 struct matrix22_t {
360 float dsdx{0};
361 float dtdx{0};
362 float dtdy{0};
363 float dsdy{0};
364 status_t write(Parcel& output) const;
365 status_t read(const Parcel& input);
366 inline bool operator==(const matrix22_t& other) const {
367 return std::tie(dsdx, dtdx, dtdy, dsdy) ==
368 std::tie(other.dsdx, other.dtdx, other.dtdy, other.dsdy);
369 }
370 inline bool operator!=(const matrix22_t& other) const { return !(*this == other); }
371 };
372 sp<IBinder> surface;
373 int32_t layerId;
374 uint64_t what;
375 float x;
376 float y;
377 int32_t z;
378 ui::LayerStack layerStack = ui::DEFAULT_LAYER_STACK;
379 uint32_t flags;
380 uint32_t mask;
381 uint8_t reserved;
382 matrix22_t matrix;
383 float cornerRadius;
384 float clientDrawnCornerRadius;
385 uint32_t backgroundBlurRadius;
386
387 half4 color;
388
389 // non POD must be last. see write/read
390 uint32_t bufferTransform;
391 bool transformToDisplayInverse;
392 FloatRect crop;
393 std::shared_ptr<BufferData> bufferData = nullptr;
394 ui::Dataspace dataspace;
395 HdrMetadata hdrMetadata;
396 int32_t api;
397 sp<NativeHandle> sidebandStream;
398 mat4 colorTransform;
399 std::vector<BlurRegion> blurRegions;
400
401 LayerMetadata metadata;
402
403 // The following refer to the alpha, and dataspace, respectively of
404 // the background color layer
405 half4 bgColor;
406 ui::Dataspace bgColorDataspace;
407
408 // A color space agnostic layer means the color of this layer can be
409 // interpreted in any color space.
410 bool colorSpaceAgnostic;
411
412 std::vector<ListenerCallbacks> listeners;
413
414 // Draws a shadow around the surface.
415 float shadowRadius;
416
417 // Draws an outline around the layer.
418 gui::BorderSettings borderSettings;
419
420 // Priority of the layer assigned by Window Manager.
421 int32_t frameRateSelectionPriority;
422
423 // Layer frame rate and compatibility. See ANativeWindow_setFrameRate().
424 float frameRate;
425 int8_t frameRateCompatibility;
426 int8_t changeFrameRateStrategy;
427
428 // Default frame rate compatibility used to set the layer refresh rate votetype.
429 int8_t defaultFrameRateCompatibility;
430
431 // Frame rate category to suggest what frame rate range a surface should run.
432 int8_t frameRateCategory;
433 bool frameRateCategorySmoothSwitchOnly;
434
435 // Strategy of the layer for frame rate selection.
436 int8_t frameRateSelectionStrategy;
437
438 // Set by window manager indicating the layer and all its children are
439 // in a different orientation than the display. The hint suggests that
440 // the graphic producers should receive a transform hint as if the
441 // display was in this orientation. When the display changes to match
442 // the layer orientation, the graphic producer may not need to allocate
443 // a buffer of a different size. -1 means the transform hint is not set,
444 // otherwise the value will be a valid ui::Rotation.
445 ui::Transform::RotationFlags fixedTransformHint;
446
447 // Indicates that the consumer should acquire the next frame as soon as it
448 // can and not wait for a frame to become available. This is only relevant
449 // in shared buffer mode.
450 bool autoRefresh;
451
452 // An inherited state that indicates that this surface control and its children
453 // should be trusted for input occlusion detection purposes
454 gui::TrustedOverlay trustedOverlay;
455
456 // Stretch effect to be applied to this layer
457 StretchEffect stretchEffect;
458
459 // Edge extension effect to be applied to this layer
460 gui::EdgeExtensionParameters edgeExtensionParameters;
461
462 Rect bufferCrop;
463 Rect destinationFrame;
464
465 // Force inputflinger to drop all input events for the layer and its children.
466 gui::DropInputMode dropInputMode;
467
468 bool dimmingEnabled;
469 float currentHdrSdrRatio = 1.f;
470 float desiredHdrSdrRatio = 1.f;
471
472 // Enhance the quality of the buffer contents by configurating a picture processing pipeline
473 // with values as specified by this picture profile.
474 PictureProfileHandle pictureProfileHandle{PictureProfileHandle::NONE};
475
476 // A value indicating the significance of the layer's content to the app's desired user
477 // experience. A higher value will result in more likelihood of getting access to limited
478 // resources, such as picture processing hardware.
479 int32_t appContentPriority = 0;
480
481 gui::CachingHint cachingHint = gui::CachingHint::Enabled;
482
483 TrustedPresentationThresholds trustedPresentationThresholds;
484 TrustedPresentationListener trustedPresentationListener;
485
486 std::shared_ptr<gui::BufferReleaseChannel::ProducerEndpoint> bufferReleaseChannel;
487
488 std::shared_ptr<gui::DisplayLuts> luts;
489
490 protected:
491 struct NotDefaultComparableState {
492 Region transparentRegion;
493 Region surfaceDamageRegion;
494 sp<gui::WindowInfoHandle> windowInfoHandle = sp<gui::WindowInfoHandle>::make();
495 sp<SurfaceControl> relativeLayerSurfaceControl;
496 sp<SurfaceControl> parentSurfaceControlForChild;
497
498 bool operator==(const NotDefaultComparableState& rhs) const;
499 bool operator!=(const NotDefaultComparableState& rhs) const = default;
500 } mNotDefCmpState;
501 };
502
503 class ComposerState {
504 public:
505 layer_state_t state;
506 status_t write(Parcel& output) const;
507 status_t read(const Parcel& input);
508
509 bool operator==(const ComposerState&) const = default;
510 bool operator!=(const ComposerState&) const = default;
511 };
512
513 struct DisplayState {
514 enum : uint32_t {
515 eSurfaceChanged = 0x01,
516 eLayerStackChanged = 0x02,
517 eDisplayProjectionChanged = 0x04,
518 eDisplaySizeChanged = 0x08,
519 eFlagsChanged = 0x10,
520
521 eAllChanged = ~0u
522 };
523
524 // Not for direct use. Prefer constructor below for new displays.
525 DisplayState();
526
DisplayStateDisplayState527 DisplayState(sp<IBinder> token, ui::LayerStack layerStack)
528 : what(eAllChanged),
529 token(std::move(token)),
530 layerStack(layerStack),
531 layerStackSpaceRect(Rect::INVALID_RECT),
532 orientedDisplaySpaceRect(Rect::INVALID_RECT) {}
533
534 void merge(const DisplayState& other);
535 void sanitize(int32_t permissions);
536
537 uint32_t what = 0;
538 uint32_t flags = 0;
539 sp<IBinder> token;
540
541 ui::LayerStack layerStack = ui::DEFAULT_LAYER_STACK;
542
543 // These states define how layers are projected onto the physical or virtual display.
544 //
545 // Layers are first clipped to `layerStackSpaceRect'. They are then translated and
546 // scaled from `layerStackSpaceRect' to `orientedDisplaySpaceRect'. Finally, they are rotated
547 // according to `orientation', `width', and `height'.
548 //
549 // For example, assume layerStackSpaceRect is Rect(0, 0, 200, 100), orientedDisplaySpaceRect is
550 // Rect(20, 10, 420, 210), and the size of the display is WxH. When orientation is 0, layers
551 // will be scaled by a factor of 2 and translated by (20, 10). When orientation is 1, layers
552 // will be additionally rotated by 90 degrees around the origin clockwise and translated by (W,
553 // 0).
554 //
555 // Rect::INVALID_RECT sizes the space to the active resolution of the physical display, or the
556 // default dimensions of the virtual display surface.
557 //
558 ui::Rotation orientation = ui::ROTATION_0;
559 Rect layerStackSpaceRect = Rect::EMPTY_RECT;
560 Rect orientedDisplaySpaceRect = Rect::EMPTY_RECT;
561
562 // For physical displays, this is the resolution, which must match the active display mode. To
563 // change the resolution, the client must first call SurfaceControl.setDesiredDisplayModeSpecs
564 // with the new DesiredDisplayModeSpecs#defaultMode, then commit the matching width and height.
565 //
566 // For virtual displays, this is an optional resolution that overrides its default dimensions.
567 //
568 uint32_t width = 0;
569 uint32_t height = 0;
570
571 // For virtual displays, this is the sink surface into which the virtual display is rendered.
572 sp<IGraphicBufferProducer> surface;
573
574 status_t write(Parcel& output) const;
575 status_t read(const Parcel& input);
576
577 bool operator==(const DisplayState&) const = default;
578 bool operator!=(const DisplayState&) const = default;
579 };
580
581 struct InputWindowCommands {
582 using Listener = gui::IWindowInfosReportedListener;
583 using ListenerSet = std::unordered_set<sp<Listener>, SpHash<Listener>>;
584 // Merges the passed in commands and returns true if there were any changes.
585 bool merge(const InputWindowCommands& other);
586 bool empty() const;
587 void clear();
addFocusRequestInputWindowCommands588 void addFocusRequest(const gui::FocusRequest& request) { focusRequests.push_back(request); }
addWindowInfosReportedListenerInputWindowCommands589 void addWindowInfosReportedListener(const sp<Listener>& listener) {
590 windowInfosReportedListeners.insert(listener);
591 }
releaseListenersInputWindowCommands592 ListenerSet&& releaseListeners() { return std::move(windowInfosReportedListeners); }
593
594 status_t write(Parcel& output) const;
595 status_t read(const Parcel& input);
596
getFocusRequestsInputWindowCommands597 std::span<const gui::FocusRequest> getFocusRequests() const { return focusRequests; }
getListenersInputWindowCommands598 const ListenerSet& getListeners() const { return windowInfosReportedListeners; }
599 bool operator==(const InputWindowCommands&) const = default;
600 bool operator!=(const InputWindowCommands&) const = default;
601
602 private:
603 std::vector<gui::FocusRequest> focusRequests;
604 ListenerSet windowInfosReportedListeners;
605 };
606
compare_type(const ComposerState & lhs,const ComposerState & rhs)607 static inline int compare_type(const ComposerState& lhs, const ComposerState& rhs) {
608 if (lhs.state.surface < rhs.state.surface) return -1;
609 if (lhs.state.surface > rhs.state.surface) return 1;
610 return 0;
611 }
612
compare_type(const DisplayState & lhs,const DisplayState & rhs)613 static inline int compare_type(const DisplayState& lhs, const DisplayState& rhs) {
614 return compare_type(lhs.token, rhs.token);
615 }
616
617 }; // namespace android
618
619 #endif // ANDROID_SF_LAYER_STATE_H
620