blob: d14bd3ae8b6e8bd3f82a0bf7d9d004b843bea845 [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"
23#include "android-base/stringprintf.h"
24
25namespace android::surfaceflinger::frontend {
26
27struct RoundedCornerState {
28 RoundedCornerState() = default;
29 RoundedCornerState(const FloatRect& cropRect, const vec2& radius)
30 : cropRect(cropRect), radius(radius) {}
31
32 // Rounded rectangle in local layer coordinate space.
33 FloatRect cropRect = FloatRect();
34 // Radius of the rounded rectangle.
35 vec2 radius;
36 bool hasRoundedCorners() const { return radius.x > 0.0f && radius.y > 0.0f; }
37 bool operator==(RoundedCornerState const& rhs) const {
38 return cropRect == rhs.cropRect && radius == rhs.radius;
39 }
40};
41
42// LayerSnapshot stores Layer state used by CompositionEngine and RenderEngine. Composition
43// Engine uses a pointer to LayerSnapshot (as LayerFECompositionState*) and the LayerSettings
44// passed to Render Engine are created using properties stored on this struct.
45struct LayerSnapshot : public compositionengine::LayerFECompositionState {
46 LayerSnapshot() = default;
47 LayerSnapshot(const RequestedLayerState&, const LayerHierarchy::TraversalPath&);
48
49 LayerHierarchy::TraversalPath path;
50 size_t globalZ = std::numeric_limits<ssize_t>::max();
51 bool invalidTransform = false;
52 bool isHiddenByPolicyFromParent = false;
53 bool isHiddenByPolicyFromRelativeParent = false;
54 ftl::Flags<RequestedLayerState::Changes> changes;
55 int32_t sequence;
56 std::string name;
57 uint32_t textureName;
58 bool contentOpaque;
59 bool layerOpaqueFlagSet;
60 RoundedCornerState roundedCorner;
61 FloatRect transformedBounds;
62 renderengine::ShadowSettings shadowSettings;
63 bool premultipliedAlpha;
64 bool isHdrY410;
65 bool bufferNeedsFiltering;
66 ui::Transform parentTransform;
67 Rect bufferSize;
68 Rect croppedBufferSize;
69 std::shared_ptr<renderengine::ExternalTexture> externalTexture;
70 gui::LayerMetadata layerMetadata;
71 gui::LayerMetadata relativeLayerMetadata;
72 bool hasReadyFrame;
73 ui::Transform localTransformInverse;
74 gui::WindowInfo inputInfo;
75 ui::Transform localTransform;
76 gui::DropInputMode dropInputMode;
77 bool isTrustedOverlay;
78
79 static bool isOpaqueFormat(PixelFormat format);
80 static bool isTransformValid(const ui::Transform& t);
81
82 bool canReceiveInput() const;
83 bool drawShadows() const;
84 bool fillsColor() const;
85 bool getIsVisible() const;
86 bool hasBlur() const;
87 bool hasBufferOrSidebandStream() const;
88 bool hasEffect() const;
89 bool hasSomethingToDraw() const;
90 bool isContentOpaque() const;
91 bool isHiddenByPolicy() const;
92 std::string getDebugString() const;
93 std::string getIsVisibleReason() const;
94};
95
96} // namespace android::surfaceflinger::frontend