blob: b8df3ed7489f115a295fc353ac42cb1b2669b676 [file] [log] [blame]
Vishnu Nair8fc721b2022-12-22 20:06:32 +00001/*
2 * Copyright 2022 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#pragma once
18
19#include <compositionengine/LayerFECompositionState.h>
20#include <renderengine/LayerSettings.h>
Vishnu Naira02943f2023-06-03 13:44:46 -070021#include "DisplayHardware/ComposerHal.h"
Vishnu Nair8fc721b2022-12-22 20:06:32 +000022#include "LayerHierarchy.h"
23#include "RequestedLayerState.h"
Vishnu Naircfb2d252023-01-19 04:44:02 +000024#include "Scheduler/LayerInfo.h"
Vishnu Nair8fc721b2022-12-22 20:06:32 +000025#include "android-base/stringprintf.h"
26
27namespace android::surfaceflinger::frontend {
28
29struct RoundedCornerState {
30 RoundedCornerState() = default;
31 RoundedCornerState(const FloatRect& cropRect, const vec2& radius)
32 : cropRect(cropRect), radius(radius) {}
33
34 // Rounded rectangle in local layer coordinate space.
35 FloatRect cropRect = FloatRect();
36 // Radius of the rounded rectangle.
37 vec2 radius;
38 bool hasRoundedCorners() const { return radius.x > 0.0f && radius.y > 0.0f; }
39 bool operator==(RoundedCornerState const& rhs) const {
40 return cropRect == rhs.cropRect && radius == rhs.radius;
41 }
42};
43
44// LayerSnapshot stores Layer state used by CompositionEngine and RenderEngine. Composition
45// Engine uses a pointer to LayerSnapshot (as LayerFECompositionState*) and the LayerSettings
46// passed to Render Engine are created using properties stored on this struct.
47struct LayerSnapshot : public compositionengine::LayerFECompositionState {
48 LayerSnapshot() = default;
49 LayerSnapshot(const RequestedLayerState&, const LayerHierarchy::TraversalPath&);
50
51 LayerHierarchy::TraversalPath path;
52 size_t globalZ = std::numeric_limits<ssize_t>::max();
53 bool invalidTransform = false;
54 bool isHiddenByPolicyFromParent = false;
55 bool isHiddenByPolicyFromRelativeParent = false;
56 ftl::Flags<RequestedLayerState::Changes> changes;
Vishnu Naira02943f2023-06-03 13:44:46 -070057 uint64_t clientChanges = 0;
Vishnu Nair93b8b792023-02-27 19:40:24 +000058 // Some consumers of this snapshot (input, layer traces) rely on each snapshot to be unique.
59 // For mirrored layers, snapshots will have the same sequence so this unique id provides
60 // an alternative identifier when needed.
61 uint32_t uniqueSequence;
62 // Layer id used to create this snapshot. Multiple snapshots will have the same sequence if they
63 // generated from the same layer, for example when mirroring.
Vishnu Nair8fc721b2022-12-22 20:06:32 +000064 int32_t sequence;
65 std::string name;
Vishnu Nair3cc15a42023-06-30 06:20:22 +000066 std::string debugName;
Vishnu Nair8fc721b2022-12-22 20:06:32 +000067 bool contentOpaque;
68 bool layerOpaqueFlagSet;
69 RoundedCornerState roundedCorner;
70 FloatRect transformedBounds;
Vishnu Naircfb2d252023-01-19 04:44:02 +000071 Rect transformedBoundsWithoutTransparentRegion;
Vishnu Nair8fc721b2022-12-22 20:06:32 +000072 bool premultipliedAlpha;
Vishnu Nair8fc721b2022-12-22 20:06:32 +000073 ui::Transform parentTransform;
74 Rect bufferSize;
Vishnu Naira9123c82024-10-03 03:56:44 +000075 FloatRect croppedBufferSize;
Vishnu Nair8fc721b2022-12-22 20:06:32 +000076 std::shared_ptr<renderengine::ExternalTexture> externalTexture;
77 gui::LayerMetadata layerMetadata;
78 gui::LayerMetadata relativeLayerMetadata;
Vishnu Nair6f209e22023-08-04 16:33:23 +000079 bool hasReadyFrame; // used in post composition to check if there is another frame ready
Vishnu Naira4b3a102024-11-05 05:26:38 +000080 bool autoRefresh;
Vishnu Nair8fc721b2022-12-22 20:06:32 +000081 ui::Transform localTransformInverse;
82 gui::WindowInfo inputInfo;
83 ui::Transform localTransform;
Vishnu Nair491827d2024-04-29 23:43:26 +000084 // set to true if this snapshot will ignore local transforms. Used when the snapshot
85 // is a mirror root
86 bool ignoreLocalTransform;
Vishnu Nair8fc721b2022-12-22 20:06:32 +000087 gui::DropInputMode dropInputMode;
Vishnu Nair9e0017e2024-05-22 19:02:44 +000088 gui::TrustedOverlay trustedOverlay;
Vishnu Naircfb2d252023-01-19 04:44:02 +000089 gui::GameMode gameMode;
90 scheduler::LayerInfo::FrameRate frameRate;
Vishnu Nair30515cb2023-10-19 21:54:08 -070091 scheduler::LayerInfo::FrameRate inheritedFrameRate;
Rachel Lee58cc90d2023-09-05 18:50:20 -070092 scheduler::LayerInfo::FrameRateSelectionStrategy frameRateSelectionStrategy;
Vishnu Nair80e8cfe2023-09-29 17:03:45 -070093 scheduler::FrameRateCompatibility defaultFrameRateCompatibility =
94 scheduler::FrameRateCompatibility::Default;
Vishnu Naircfb2d252023-01-19 04:44:02 +000095 ui::Transform::RotationFlags fixedTransformHint;
Vishnu Nairb76d99a2023-03-19 18:22:31 -070096 std::optional<ui::Transform::RotationFlags> transformHint;
Vishnu Naira9c43762023-01-27 19:10:25 +000097 bool handleSkipScreenshotFlag = false;
Vishnu Nair3d8565a2023-06-30 07:23:24 +000098 int32_t frameRateSelectionPriority = -1;
Vishnu Nair92990e22023-02-24 20:01:05 +000099 LayerHierarchy::TraversalPath mirrorRootPath;
Vishnu Nair29354ec2023-03-28 18:51:28 -0700100 uint32_t touchCropId;
Vishnu Naira02943f2023-06-03 13:44:46 -0700101 gui::Uid uid = gui::Uid::INVALID;
102 gui::Pid pid = gui::Pid::INVALID;
Vishnu Naira02943f2023-06-03 13:44:46 -0700103 enum class Reachablilty : uint32_t {
104 // Can traverse the hierarchy from a root node and reach this snapshot
105 Reachable,
106 // Cannot traverse the hierarchy from a root node and reach this snapshot
107 Unreachable,
108 // Can only reach this node from a relative parent. This means the nodes parents are
109 // not reachable.
110 // See example scenario:
111 // ROOT
112 // ├── 1
113 // │ ├── 11
114 // │ │ └── 111
115 // │ ├── 12
116 // │ │ └ - 111 (relative)
117 // │ ├── 13
118 // │ └── 14
119 // │ └ * 12 (mirroring)
120 // └── 2
121 // 111 will create two snapshots, first when visited from 1 -> 12 or 1 -> 11 and the
122 // second when visited from 1 -> 14 -> 12. Because its parent 11 doesn't exist in the
123 // mirrored hierarchy, the second snapshot will be marked as ReachableByRelativeParent.
124 // This snapshot doesn't have any valid properties because it cannot inherit from its
125 // parent. Therefore, snapshots that are not reachable will be ignored for composition
126 // and input.
127 ReachableByRelativeParent
128 };
129 Reachablilty reachablilty;
Arthur Hung69f95222023-10-04 07:39:02 +0000130 // True when the surfaceDamage is recognized as a small area update.
131 bool isSmallDirty = false;
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000132
133 static bool isOpaqueFormat(PixelFormat format);
134 static bool isTransformValid(const ui::Transform& t);
135
136 bool canReceiveInput() const;
137 bool drawShadows() const;
138 bool fillsColor() const;
139 bool getIsVisible() const;
140 bool hasBlur() const;
141 bool hasBufferOrSidebandStream() const;
142 bool hasEffect() const;
143 bool hasSomethingToDraw() const;
144 bool isContentOpaque() const;
145 bool isHiddenByPolicy() const;
146 std::string getDebugString() const;
147 std::string getIsVisibleReason() const;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000148 bool hasInputInfo() const;
Vishnu Nair781d7252023-01-30 18:16:01 +0000149 FloatRect sourceBounds() const;
Alec Mouri89f5d4e2023-10-20 17:12:49 +0000150 bool isFrontBuffered() const;
Vishnu Naira02943f2023-06-03 13:44:46 -0700151 Hwc2::IComposerClient::BlendMode getBlendMode(const RequestedLayerState& requested) const;
Vishnu Nair3cc15a42023-06-30 06:20:22 +0000152 friend std::ostream& operator<<(std::ostream& os, const LayerSnapshot& obj);
Vishnu Naira02943f2023-06-03 13:44:46 -0700153 void merge(const RequestedLayerState& requested, bool forceUpdate, bool displayChanges,
154 bool forceFullDamage, uint32_t displayRotationFlags);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000155};
156
157} // namespace android::surfaceflinger::frontend