xref: /aosp_15_r20/frameworks/native/services/surfaceflinger/FrontEnd/LayerSnapshot.h (revision 38e8c45f13ce32b0dcecb25141ffecaf386fa17f)
1*38e8c45fSAndroid Build Coastguard Worker /*
2*38e8c45fSAndroid Build Coastguard Worker  * Copyright 2022 The Android Open Source Project
3*38e8c45fSAndroid Build Coastguard Worker  *
4*38e8c45fSAndroid Build Coastguard Worker  * Licensed under the Apache License, Version 2.0 (the "License");
5*38e8c45fSAndroid Build Coastguard Worker  * you may not use this file except in compliance with the License.
6*38e8c45fSAndroid Build Coastguard Worker  * You may obtain a copy of the License at
7*38e8c45fSAndroid Build Coastguard Worker  *
8*38e8c45fSAndroid Build Coastguard Worker  *      http://www.apache.org/licenses/LICENSE-2.0
9*38e8c45fSAndroid Build Coastguard Worker  *
10*38e8c45fSAndroid Build Coastguard Worker  * Unless required by applicable law or agreed to in writing, software
11*38e8c45fSAndroid Build Coastguard Worker  * distributed under the License is distributed on an "AS IS" BASIS,
12*38e8c45fSAndroid Build Coastguard Worker  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*38e8c45fSAndroid Build Coastguard Worker  * See the License for the specific language governing permissions and
14*38e8c45fSAndroid Build Coastguard Worker  * limitations under the License.
15*38e8c45fSAndroid Build Coastguard Worker  */
16*38e8c45fSAndroid Build Coastguard Worker 
17*38e8c45fSAndroid Build Coastguard Worker #pragma once
18*38e8c45fSAndroid Build Coastguard Worker 
19*38e8c45fSAndroid Build Coastguard Worker #include <compositionengine/LayerFECompositionState.h>
20*38e8c45fSAndroid Build Coastguard Worker #include <renderengine/LayerSettings.h>
21*38e8c45fSAndroid Build Coastguard Worker #include "DisplayHardware/ComposerHal.h"
22*38e8c45fSAndroid Build Coastguard Worker #include "LayerHierarchy.h"
23*38e8c45fSAndroid Build Coastguard Worker #include "RequestedLayerState.h"
24*38e8c45fSAndroid Build Coastguard Worker #include "Scheduler/LayerInfo.h"
25*38e8c45fSAndroid Build Coastguard Worker #include "android-base/stringprintf.h"
26*38e8c45fSAndroid Build Coastguard Worker 
27*38e8c45fSAndroid Build Coastguard Worker namespace android::surfaceflinger::frontend {
28*38e8c45fSAndroid Build Coastguard Worker 
29*38e8c45fSAndroid Build Coastguard Worker struct RoundedCornerState {
30*38e8c45fSAndroid Build Coastguard Worker     RoundedCornerState() = default;
RoundedCornerStateRoundedCornerState31*38e8c45fSAndroid Build Coastguard Worker     RoundedCornerState(const FloatRect& cropRect, const vec2& radius)
32*38e8c45fSAndroid Build Coastguard Worker           : cropRect(cropRect), radius(radius) {}
33*38e8c45fSAndroid Build Coastguard Worker 
34*38e8c45fSAndroid Build Coastguard Worker     // Rounded rectangle in local layer coordinate space.
35*38e8c45fSAndroid Build Coastguard Worker     FloatRect cropRect = FloatRect();
36*38e8c45fSAndroid Build Coastguard Worker     // Radius of the rounded rectangle.
37*38e8c45fSAndroid Build Coastguard Worker     vec2 radius;
hasRoundedCornersRoundedCornerState38*38e8c45fSAndroid Build Coastguard Worker     bool hasRoundedCorners() const { return radius.x > 0.0f && radius.y > 0.0f; }
39*38e8c45fSAndroid Build Coastguard Worker     bool operator==(RoundedCornerState const& rhs) const {
40*38e8c45fSAndroid Build Coastguard Worker         return cropRect == rhs.cropRect && radius == rhs.radius;
41*38e8c45fSAndroid Build Coastguard Worker     }
42*38e8c45fSAndroid Build Coastguard Worker };
43*38e8c45fSAndroid Build Coastguard Worker 
44*38e8c45fSAndroid Build Coastguard Worker // LayerSnapshot stores Layer state used by CompositionEngine and RenderEngine. Composition
45*38e8c45fSAndroid Build Coastguard Worker // Engine uses a pointer to LayerSnapshot (as LayerFECompositionState*) and the LayerSettings
46*38e8c45fSAndroid Build Coastguard Worker // passed to Render Engine are created using properties stored on this struct.
47*38e8c45fSAndroid Build Coastguard Worker struct LayerSnapshot : public compositionengine::LayerFECompositionState {
48*38e8c45fSAndroid Build Coastguard Worker     LayerSnapshot() = default;
49*38e8c45fSAndroid Build Coastguard Worker     LayerSnapshot(const RequestedLayerState&, const LayerHierarchy::TraversalPath&);
50*38e8c45fSAndroid Build Coastguard Worker 
51*38e8c45fSAndroid Build Coastguard Worker     LayerHierarchy::TraversalPath path;
52*38e8c45fSAndroid Build Coastguard Worker     size_t globalZ = std::numeric_limits<ssize_t>::max();
53*38e8c45fSAndroid Build Coastguard Worker     bool invalidTransform = false;
54*38e8c45fSAndroid Build Coastguard Worker     bool isHiddenByPolicyFromParent = false;
55*38e8c45fSAndroid Build Coastguard Worker     bool isHiddenByPolicyFromRelativeParent = false;
56*38e8c45fSAndroid Build Coastguard Worker     ftl::Flags<RequestedLayerState::Changes> changes;
57*38e8c45fSAndroid Build Coastguard Worker     uint64_t clientChanges = 0;
58*38e8c45fSAndroid Build Coastguard Worker     // Some consumers of this snapshot (input, layer traces) rely on each snapshot to be unique.
59*38e8c45fSAndroid Build Coastguard Worker     // For mirrored layers, snapshots will have the same sequence so this unique id provides
60*38e8c45fSAndroid Build Coastguard Worker     // an alternative identifier when needed.
61*38e8c45fSAndroid Build Coastguard Worker     uint32_t uniqueSequence;
62*38e8c45fSAndroid Build Coastguard Worker     // Layer id used to create this snapshot. Multiple snapshots will have the same sequence if they
63*38e8c45fSAndroid Build Coastguard Worker     // generated from the same layer, for example when mirroring.
64*38e8c45fSAndroid Build Coastguard Worker     int32_t sequence;
65*38e8c45fSAndroid Build Coastguard Worker     std::string name;
66*38e8c45fSAndroid Build Coastguard Worker     std::string debugName;
67*38e8c45fSAndroid Build Coastguard Worker     bool contentOpaque;
68*38e8c45fSAndroid Build Coastguard Worker     bool layerOpaqueFlagSet;
69*38e8c45fSAndroid Build Coastguard Worker     RoundedCornerState roundedCorner;
70*38e8c45fSAndroid Build Coastguard Worker     FloatRect transformedBounds;
71*38e8c45fSAndroid Build Coastguard Worker     Rect transformedBoundsWithoutTransparentRegion;
72*38e8c45fSAndroid Build Coastguard Worker     bool premultipliedAlpha;
73*38e8c45fSAndroid Build Coastguard Worker     ui::Transform parentTransform;
74*38e8c45fSAndroid Build Coastguard Worker     Rect bufferSize;
75*38e8c45fSAndroid Build Coastguard Worker     FloatRect croppedBufferSize;
76*38e8c45fSAndroid Build Coastguard Worker     std::shared_ptr<renderengine::ExternalTexture> externalTexture;
77*38e8c45fSAndroid Build Coastguard Worker     gui::LayerMetadata layerMetadata;
78*38e8c45fSAndroid Build Coastguard Worker     gui::LayerMetadata relativeLayerMetadata;
79*38e8c45fSAndroid Build Coastguard Worker     bool hasReadyFrame; // used in post composition to check if there is another frame ready
80*38e8c45fSAndroid Build Coastguard Worker     bool autoRefresh;
81*38e8c45fSAndroid Build Coastguard Worker     ui::Transform localTransformInverse;
82*38e8c45fSAndroid Build Coastguard Worker     gui::WindowInfo inputInfo;
83*38e8c45fSAndroid Build Coastguard Worker     ui::Transform localTransform;
84*38e8c45fSAndroid Build Coastguard Worker     // set to true if this snapshot will ignore local transforms. Used when the snapshot
85*38e8c45fSAndroid Build Coastguard Worker     // is a mirror root
86*38e8c45fSAndroid Build Coastguard Worker     bool ignoreLocalTransform;
87*38e8c45fSAndroid Build Coastguard Worker     gui::DropInputMode dropInputMode;
88*38e8c45fSAndroid Build Coastguard Worker     gui::TrustedOverlay trustedOverlay;
89*38e8c45fSAndroid Build Coastguard Worker     gui::GameMode gameMode;
90*38e8c45fSAndroid Build Coastguard Worker     scheduler::LayerInfo::FrameRate frameRate;
91*38e8c45fSAndroid Build Coastguard Worker     scheduler::LayerInfo::FrameRate inheritedFrameRate;
92*38e8c45fSAndroid Build Coastguard Worker     scheduler::LayerInfo::FrameRateSelectionStrategy frameRateSelectionStrategy;
93*38e8c45fSAndroid Build Coastguard Worker     scheduler::FrameRateCompatibility defaultFrameRateCompatibility =
94*38e8c45fSAndroid Build Coastguard Worker             scheduler::FrameRateCompatibility::Default;
95*38e8c45fSAndroid Build Coastguard Worker     ui::Transform::RotationFlags fixedTransformHint;
96*38e8c45fSAndroid Build Coastguard Worker     std::optional<ui::Transform::RotationFlags> transformHint;
97*38e8c45fSAndroid Build Coastguard Worker     bool handleSkipScreenshotFlag = false;
98*38e8c45fSAndroid Build Coastguard Worker     int32_t frameRateSelectionPriority = -1;
99*38e8c45fSAndroid Build Coastguard Worker     LayerHierarchy::TraversalPath mirrorRootPath;
100*38e8c45fSAndroid Build Coastguard Worker     uint32_t touchCropId;
101*38e8c45fSAndroid Build Coastguard Worker     gui::Uid uid = gui::Uid::INVALID;
102*38e8c45fSAndroid Build Coastguard Worker     gui::Pid pid = gui::Pid::INVALID;
103*38e8c45fSAndroid Build Coastguard Worker     enum class Reachablilty : uint32_t {
104*38e8c45fSAndroid Build Coastguard Worker         // Can traverse the hierarchy from a root node and reach this snapshot
105*38e8c45fSAndroid Build Coastguard Worker         Reachable,
106*38e8c45fSAndroid Build Coastguard Worker         // Cannot traverse the hierarchy from a root node and reach this snapshot
107*38e8c45fSAndroid Build Coastguard Worker         Unreachable,
108*38e8c45fSAndroid Build Coastguard Worker         // Can only reach this node from a relative parent. This means the nodes parents are
109*38e8c45fSAndroid Build Coastguard Worker         // not reachable.
110*38e8c45fSAndroid Build Coastguard Worker         // See example scenario:
111*38e8c45fSAndroid Build Coastguard Worker         // ROOT
112*38e8c45fSAndroid Build Coastguard Worker         // ├── 1
113*38e8c45fSAndroid Build Coastguard Worker         // │   ├── 11
114*38e8c45fSAndroid Build Coastguard Worker         // │   │   └── 111
115*38e8c45fSAndroid Build Coastguard Worker         // │   ├── 12
116*38e8c45fSAndroid Build Coastguard Worker         // │   │   └ - 111 (relative)
117*38e8c45fSAndroid Build Coastguard Worker         // │   ├── 13
118*38e8c45fSAndroid Build Coastguard Worker         // │   └── 14
119*38e8c45fSAndroid Build Coastguard Worker         // │       └ * 12 (mirroring)
120*38e8c45fSAndroid Build Coastguard Worker         // └── 2
121*38e8c45fSAndroid Build Coastguard Worker         // 111 will create two snapshots, first when visited from 1 -> 12 or 1 -> 11 and the
122*38e8c45fSAndroid Build Coastguard Worker         // second when visited from 1 -> 14 -> 12. Because its parent 11 doesn't exist in the
123*38e8c45fSAndroid Build Coastguard Worker         // mirrored hierarchy, the second snapshot will be marked as ReachableByRelativeParent.
124*38e8c45fSAndroid Build Coastguard Worker         // This snapshot doesn't have any valid properties because it cannot inherit from its
125*38e8c45fSAndroid Build Coastguard Worker         // parent. Therefore, snapshots that are not reachable will be ignored for composition
126*38e8c45fSAndroid Build Coastguard Worker         // and input.
127*38e8c45fSAndroid Build Coastguard Worker         ReachableByRelativeParent
128*38e8c45fSAndroid Build Coastguard Worker     };
129*38e8c45fSAndroid Build Coastguard Worker     Reachablilty reachablilty;
130*38e8c45fSAndroid Build Coastguard Worker     // True when the surfaceDamage is recognized as a small area update.
131*38e8c45fSAndroid Build Coastguard Worker     bool isSmallDirty = false;
132*38e8c45fSAndroid Build Coastguard Worker 
133*38e8c45fSAndroid Build Coastguard Worker     static bool isOpaqueFormat(PixelFormat format);
134*38e8c45fSAndroid Build Coastguard Worker     static bool isTransformValid(const ui::Transform& t);
135*38e8c45fSAndroid Build Coastguard Worker 
136*38e8c45fSAndroid Build Coastguard Worker     bool canReceiveInput() const;
137*38e8c45fSAndroid Build Coastguard Worker     bool drawShadows() const;
138*38e8c45fSAndroid Build Coastguard Worker     bool fillsColor() const;
139*38e8c45fSAndroid Build Coastguard Worker     bool getIsVisible() const;
140*38e8c45fSAndroid Build Coastguard Worker     bool hasBlur() const;
141*38e8c45fSAndroid Build Coastguard Worker     bool hasBufferOrSidebandStream() const;
142*38e8c45fSAndroid Build Coastguard Worker     bool hasEffect() const;
143*38e8c45fSAndroid Build Coastguard Worker     bool hasSomethingToDraw() const;
144*38e8c45fSAndroid Build Coastguard Worker     bool isContentOpaque() const;
145*38e8c45fSAndroid Build Coastguard Worker     bool isHiddenByPolicy() const;
146*38e8c45fSAndroid Build Coastguard Worker     std::string getDebugString() const;
147*38e8c45fSAndroid Build Coastguard Worker     std::string getIsVisibleReason() const;
148*38e8c45fSAndroid Build Coastguard Worker     bool hasInputInfo() const;
149*38e8c45fSAndroid Build Coastguard Worker     FloatRect sourceBounds() const;
150*38e8c45fSAndroid Build Coastguard Worker     bool isFrontBuffered() const;
151*38e8c45fSAndroid Build Coastguard Worker     Hwc2::IComposerClient::BlendMode getBlendMode(const RequestedLayerState& requested) const;
152*38e8c45fSAndroid Build Coastguard Worker     friend std::ostream& operator<<(std::ostream& os, const LayerSnapshot& obj);
153*38e8c45fSAndroid Build Coastguard Worker     void merge(const RequestedLayerState& requested, bool forceUpdate, bool displayChanges,
154*38e8c45fSAndroid Build Coastguard Worker                bool forceFullDamage, uint32_t displayRotationFlags);
155*38e8c45fSAndroid Build Coastguard Worker };
156*38e8c45fSAndroid Build Coastguard Worker 
157*38e8c45fSAndroid Build Coastguard Worker } // namespace android::surfaceflinger::frontend
158