blob: 975764086ff2bdda9801e6da28b0a0d197cf521b [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;
60 int32_t sequence;
61 std::string name;
62 uint32_t textureName;
63 bool contentOpaque;
64 bool layerOpaqueFlagSet;
65 RoundedCornerState roundedCorner;
66 FloatRect transformedBounds;
Vishnu Naircfb2d252023-01-19 04:44:02 +000067 Rect transformedBoundsWithoutTransparentRegion;
Vishnu Nair8fc721b2022-12-22 20:06:32 +000068 renderengine::ShadowSettings shadowSettings;
69 bool premultipliedAlpha;
70 bool isHdrY410;
Vishnu Nair8fc721b2022-12-22 20:06:32 +000071 ui::Transform parentTransform;
72 Rect bufferSize;
73 Rect croppedBufferSize;
74 std::shared_ptr<renderengine::ExternalTexture> externalTexture;
75 gui::LayerMetadata layerMetadata;
76 gui::LayerMetadata relativeLayerMetadata;
77 bool hasReadyFrame;
78 ui::Transform localTransformInverse;
79 gui::WindowInfo inputInfo;
80 ui::Transform localTransform;
81 gui::DropInputMode dropInputMode;
82 bool isTrustedOverlay;
Vishnu Naircfb2d252023-01-19 04:44:02 +000083 gui::GameMode gameMode;
84 scheduler::LayerInfo::FrameRate frameRate;
85 ui::Transform::RotationFlags fixedTransformHint;
Vishnu Naira9c43762023-01-27 19:10:25 +000086 bool handleSkipScreenshotFlag = false;
Vishnu Nair92990e22023-02-24 20:01:05 +000087 LayerHierarchy::TraversalPath mirrorRootPath;
Vishnu Naircfb2d252023-01-19 04:44:02 +000088 ChildState childState;
Vishnu Nair8fc721b2022-12-22 20:06:32 +000089
90 static bool isOpaqueFormat(PixelFormat format);
91 static bool isTransformValid(const ui::Transform& t);
92
93 bool canReceiveInput() const;
94 bool drawShadows() const;
95 bool fillsColor() const;
96 bool getIsVisible() const;
97 bool hasBlur() const;
98 bool hasBufferOrSidebandStream() const;
99 bool hasEffect() const;
100 bool hasSomethingToDraw() const;
101 bool isContentOpaque() const;
102 bool isHiddenByPolicy() const;
103 std::string getDebugString() const;
104 std::string getIsVisibleReason() const;
Vishnu Naircfb2d252023-01-19 04:44:02 +0000105 bool hasInputInfo() const;
Vishnu Nair781d7252023-01-30 18:16:01 +0000106 FloatRect sourceBounds() const;
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000107};
108
109} // namespace android::surfaceflinger::frontend