• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
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 <PowerAdvisor/Workload.h>
20 #include <compositionengine/LayerFECompositionState.h>
21 #include <renderengine/LayerSettings.h>
22 #include "DisplayHardware/ComposerHal.h"
23 #include "LayerHierarchy.h"
24 #include "RequestedLayerState.h"
25 #include "Scheduler/LayerInfo.h"
26 #include "android-base/stringprintf.h"
27 #include "compositionengine/LayerFE.h"
28 
29 namespace android::surfaceflinger::frontend {
30 
31 struct RoundedCornerState {
32     RoundedCornerState() = default;
33 
34     // Rounded rectangle in local layer coordinate space.
35     FloatRect cropRect = FloatRect();
36     // Radius of the rounded rectangle for composition
37     vec2 radius;
38     // Requested radius of the rounded rectangle
39     vec2 requestedRadius;
40     // Radius drawn by client for the rounded rectangle
41     vec2 clientDrawnRadius;
hasClientDrawnRadiusRoundedCornerState42     bool hasClientDrawnRadius() const {
43         return clientDrawnRadius.x > 0.0f && clientDrawnRadius.y > 0.0f;
44     }
hasRequestedRadiusRoundedCornerState45     bool hasRequestedRadius() const { return requestedRadius.x > 0.0f && requestedRadius.y > 0.0f; }
hasRoundedCornersRoundedCornerState46     bool hasRoundedCorners() const { return radius.x > 0.0f && radius.y > 0.0f; }
47     bool operator==(RoundedCornerState const& rhs) const {
48         return cropRect == rhs.cropRect && radius == rhs.radius &&
49                 clientDrawnRadius == rhs.clientDrawnRadius;
50     }
51 };
52 
53 // LayerSnapshot stores Layer state used by CompositionEngine and RenderEngine. Composition
54 // Engine uses a pointer to LayerSnapshot (as LayerFECompositionState*) and the LayerSettings
55 // passed to Render Engine are created using properties stored on this struct.
56 struct LayerSnapshot : public compositionengine::LayerFECompositionState {
57     LayerSnapshot() = default;
58     LayerSnapshot(const RequestedLayerState&, const LayerHierarchy::TraversalPath&);
59 
60     LayerHierarchy::TraversalPath path;
61     size_t globalZ = std::numeric_limits<ssize_t>::max();
62     bool invalidTransform = false;
63     bool isHiddenByPolicyFromParent = false;
64     bool isHiddenByPolicyFromRelativeParent = false;
65     ftl::Flags<RequestedLayerState::Changes> changes;
66     uint64_t clientChanges = 0;
67     // Some consumers of this snapshot (input, layer traces) rely on each snapshot to be unique.
68     // For mirrored layers, snapshots will have the same sequence so this unique id provides
69     // an alternative identifier when needed.
70     uint32_t uniqueSequence;
71     // Layer id used to create this snapshot. Multiple snapshots will have the same sequence if they
72     // generated from the same layer, for example when mirroring.
73     int32_t sequence;
74     std::string name;
75     std::string debugName;
76     bool contentOpaque;
77     bool layerOpaqueFlagSet;
78     RoundedCornerState roundedCorner;
79     FloatRect transformedBounds;
80     Rect transformedBoundsWithoutTransparentRegion;
81     bool premultipliedAlpha;
82     ui::Transform parentTransform;
83     Rect bufferSize;
84     FloatRect croppedBufferSize;
85     std::shared_ptr<renderengine::ExternalTexture> externalTexture;
86     gui::LayerMetadata layerMetadata;
87     gui::LayerMetadata relativeLayerMetadata;
88     bool hasReadyFrame; // used in post composition to check if there is another frame ready
89     bool autoRefresh;
90     ui::Transform localTransformInverse;
91     gui::WindowInfo inputInfo;
92     ui::Transform localTransform;
93     // set to true if this snapshot will ignore local transforms. Used when the snapshot
94     // is a mirror root
95     bool ignoreLocalTransform;
96     gui::DropInputMode dropInputMode;
97     gui::TrustedOverlay trustedOverlay;
98     gui::GameMode gameMode;
99     scheduler::LayerInfo::FrameRate frameRate;
100     scheduler::LayerInfo::FrameRate inheritedFrameRate;
101     scheduler::LayerInfo::FrameRateSelectionStrategy frameRateSelectionStrategy;
102     scheduler::FrameRateCompatibility defaultFrameRateCompatibility =
103             scheduler::FrameRateCompatibility::Default;
104     ui::Transform::RotationFlags fixedTransformHint;
105     std::optional<ui::Transform::RotationFlags> transformHint;
106     bool handleSkipScreenshotFlag = false;
107     int32_t frameRateSelectionPriority = -1;
108     LayerHierarchy::TraversalPath mirrorRootPath;
109     uint32_t touchCropId;
110     gui::Uid uid = gui::Uid::INVALID;
111     gui::Pid pid = gui::Pid::INVALID;
112     enum class Reachablilty : uint32_t {
113         // Can traverse the hierarchy from a root node and reach this snapshot
114         Reachable,
115         // Cannot traverse the hierarchy from a root node and reach this snapshot
116         Unreachable,
117         // Can only reach this node from a relative parent. This means the nodes parents are
118         // not reachable.
119         // See example scenario:
120         // ROOT
121         // ├── 1
122         // │   ├── 11
123         // │   │   └── 111
124         // │   ├── 12
125         // │   │   └ - 111 (relative)
126         // │   ├── 13
127         // │   └── 14
128         // │       └ * 12 (mirroring)
129         // └── 2
130         // 111 will create two snapshots, first when visited from 1 -> 12 or 1 -> 11 and the
131         // second when visited from 1 -> 14 -> 12. Because its parent 11 doesn't exist in the
132         // mirrored hierarchy, the second snapshot will be marked as ReachableByRelativeParent.
133         // This snapshot doesn't have any valid properties because it cannot inherit from its
134         // parent. Therefore, snapshots that are not reachable will be ignored for composition
135         // and input.
136         ReachableByRelativeParent
137     };
138     Reachablilty reachablilty;
139     // True when the surfaceDamage is recognized as a small area update.
140     bool isSmallDirty = false;
141 
142     static bool isOpaqueFormat(PixelFormat format);
143     static bool isTransformValid(const ui::Transform& t);
144 
145     bool canReceiveInput() const;
146     bool drawShadows() const;
147     bool fillsColor() const;
148     bool getIsVisible() const;
149     bool hasBlur() const;
150     bool hasBufferOrSidebandStream() const;
151     bool hasEffect() const;
152     bool hasOutline() const;
153     bool hasSomethingToDraw() const;
154     bool isContentOpaque() const;
155     bool isHiddenByPolicy() const;
156     std::string getDebugString() const;
157     std::string getIsVisibleReason() const;
158     bool hasInputInfo() const;
159     FloatRect sourceBounds() const;
160     bool isFrontBuffered() const;
161     Hwc2::IComposerClient::BlendMode getBlendMode(const RequestedLayerState& requested) const;
162     friend std::ostream& operator<<(std::ostream& os, const LayerSnapshot& obj);
163     void merge(const RequestedLayerState& requested, bool forceUpdate, bool displayChanges,
164                bool forceFullDamage, uint32_t displayRotationFlags);
165     // Returns a char summarizing the composition request
166     // This function tries to maintain parity with planner::Plan chars.
167     char classifyCompositionForDebug(
168             const compositionengine::LayerFE::HwcLayerDebugState& hwcState) const;
169 };
170 
171 } // namespace android::surfaceflinger::frontend
172