blob: 5491d9af17d45803e2a45ecea90aec08dfc057f2 [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>
21#include "LayerHierarchy.h"
22#include "RequestedLayerState.h"
Vishnu Naircfb2d252023-01-19 04:44:02 +000023#include "Scheduler/LayerInfo.h"
Vishnu Nair8fc721b2022-12-22 20:06:32 +000024#include "android-base/stringprintf.h"
25
26namespace android::surfaceflinger::frontend {
27
28struct RoundedCornerState {
29 RoundedCornerState() = default;
30 RoundedCornerState(const FloatRect& cropRect, const vec2& radius)
31 : cropRect(cropRect), radius(radius) {}
32
33 // Rounded rectangle in local layer coordinate space.
34 FloatRect cropRect = FloatRect();
35 // Radius of the rounded rectangle.
36 vec2 radius;
37 bool hasRoundedCorners() const { return radius.x > 0.0f && radius.y > 0.0f; }
38 bool operator==(RoundedCornerState const& rhs) const {
39 return cropRect == rhs.cropRect && radius == rhs.radius;
40 }
41};
42
Vishnu Naircfb2d252023-01-19 04:44:02 +000043struct ChildState {
44 bool hasValidFrameRate = false;
45};
46
Vishnu Nair8fc721b2022-12-22 20:06:32 +000047// LayerSnapshot stores Layer state used by CompositionEngine and RenderEngine. Composition
48// Engine uses a pointer to LayerSnapshot (as LayerFECompositionState*) and the LayerSettings
49// passed to Render Engine are created using properties stored on this struct.
50struct LayerSnapshot : public compositionengine::LayerFECompositionState {
51 LayerSnapshot() = default;
52 LayerSnapshot(const RequestedLayerState&, const LayerHierarchy::TraversalPath&);
53
54 LayerHierarchy::TraversalPath path;
55 size_t globalZ = std::numeric_limits<ssize_t>::max();
56 bool invalidTransform = false;
57 bool isHiddenByPolicyFromParent = false;
58 bool isHiddenByPolicyFromRelativeParent = false;
59 ftl::Flags<RequestedLayerState::Changes> changes;
Vishnu Nair93b8b792023-02-27 19:40:24 +000060 // Some consumers of this snapshot (input, layer traces) rely on each snapshot to be unique.
61 // For mirrored layers, snapshots will have the same sequence so this unique id provides
62 // an alternative identifier when needed.
63 uint32_t uniqueSequence;
64 // Layer id used to create this snapshot. Multiple snapshots will have the same sequence if they
65 // generated from the same layer, for example when mirroring.
Vishnu Nair8fc721b2022-12-22 20:06:32 +000066 int32_t sequence;
67 std::string name;
68 uint32_t textureName;
69 bool contentOpaque;
70 bool layerOpaqueFlagSet;
71 RoundedCornerState roundedCorner;
72 FloatRect transformedBounds;
Vishnu Naircfb2d252023-01-19 04:44:02 +000073 Rect transformedBoundsWithoutTransparentRegion;
Vishnu Nair8fc721b2022-12-22 20:06:32 +000074 renderengine::ShadowSettings shadowSettings;
75 bool premultipliedAlpha;
76 bool isHdrY410;
Vishnu Nair8fc721b2022-12-22 20:06:32 +000077 ui::Transform parentTransform;
78 Rect bufferSize;
79 Rect croppedBufferSize;
80 std::shared_ptr<renderengine::ExternalTexture> externalTexture;
81 gui::LayerMetadata layerMetadata;
82 gui::LayerMetadata relativeLayerMetadata;
83 bool hasReadyFrame;
84 ui::Transform localTransformInverse;
85 gui::WindowInfo inputInfo;
86 ui::Transform localTransform;
87 gui::DropInputMode dropInputMode;
88 bool isTrustedOverlay;
Vishnu Naircfb2d252023-01-19 04:44:02 +000089 gui::GameMode gameMode;
90 scheduler::LayerInfo::FrameRate frameRate;
91 ui::Transform::RotationFlags fixedTransformHint;
Vishnu Nairb76d99a2023-03-19 18:22:31 -070092 std::optional<ui::Transform::RotationFlags> transformHint;
Vishnu Naira9c43762023-01-27 19:10:25 +000093 bool handleSkipScreenshotFlag = false;
Vishnu Nairef68d6d2023-02-28 06:18:27 +000094 int32_t frameRateSelectionPriority;
Vishnu Nair92990e22023-02-24 20:01:05 +000095 LayerHierarchy::TraversalPath mirrorRootPath;
Vishnu Nairfccd6362023-02-24 23:39:53 +000096 bool unreachable = true;
Vishnu Nair36d5f8e2023-03-19 13:31:35 -070097 uid_t uid;
98 pid_t pid;
Vishnu Naircfb2d252023-01-19 04:44:02 +000099 ChildState childState;
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000100
101 static bool isOpaqueFormat(PixelFormat format);
102 static bool isTransformValid(const ui::Transform& t);
103
104 bool canReceiveInput() const;
105 bool drawShadows() const;
106 bool fillsColor() const;
107 bool getIsVisible() const;
108 bool hasBlur() const;
109 bool hasBufferOrSidebandStream() const;
110 bool hasEffect() const;
111 bool hasSomethingToDraw() const;
112 bool isContentOpaque() const;
113 bool isHiddenByPolicy() const;
114 std::string getDebugString() const;
115 std::string getIsVisibleReason() const;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000116 bool hasInputInfo() const;
Vishnu Nair781d7252023-01-30 18:16:01 +0000117 FloatRect sourceBounds() const;
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000118};
119
120} // namespace android::surfaceflinger::frontend