Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 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 <compositionengine/LayerFECompositionState.h> |
| 20 | #include <renderengine/LayerSettings.h> |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 21 | #include "DisplayHardware/ComposerHal.h" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 22 | #include "LayerHierarchy.h" |
| 23 | #include "RequestedLayerState.h" |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 24 | #include "Scheduler/LayerInfo.h" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 25 | #include "android-base/stringprintf.h" |
| 26 | |
| 27 | namespace android::surfaceflinger::frontend { |
| 28 | |
| 29 | struct RoundedCornerState { |
| 30 | RoundedCornerState() = default; |
| 31 | RoundedCornerState(const FloatRect& cropRect, const vec2& radius) |
| 32 | : cropRect(cropRect), radius(radius) {} |
| 33 | |
| 34 | // Rounded rectangle in local layer coordinate space. |
| 35 | FloatRect cropRect = FloatRect(); |
| 36 | // Radius of the rounded rectangle. |
| 37 | vec2 radius; |
| 38 | bool hasRoundedCorners() const { return radius.x > 0.0f && radius.y > 0.0f; } |
| 39 | bool operator==(RoundedCornerState const& rhs) const { |
| 40 | return cropRect == rhs.cropRect && radius == rhs.radius; |
| 41 | } |
| 42 | }; |
| 43 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 44 | struct ChildState { |
| 45 | bool hasValidFrameRate = false; |
| 46 | }; |
| 47 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 48 | // LayerSnapshot stores Layer state used by CompositionEngine and RenderEngine. Composition |
| 49 | // Engine uses a pointer to LayerSnapshot (as LayerFECompositionState*) and the LayerSettings |
| 50 | // passed to Render Engine are created using properties stored on this struct. |
| 51 | struct LayerSnapshot : public compositionengine::LayerFECompositionState { |
| 52 | LayerSnapshot() = default; |
| 53 | LayerSnapshot(const RequestedLayerState&, const LayerHierarchy::TraversalPath&); |
| 54 | |
| 55 | LayerHierarchy::TraversalPath path; |
| 56 | size_t globalZ = std::numeric_limits<ssize_t>::max(); |
| 57 | bool invalidTransform = false; |
| 58 | bool isHiddenByPolicyFromParent = false; |
| 59 | bool isHiddenByPolicyFromRelativeParent = false; |
| 60 | ftl::Flags<RequestedLayerState::Changes> changes; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 61 | uint64_t clientChanges = 0; |
Vishnu Nair | 93b8b79 | 2023-02-27 19:40:24 +0000 | [diff] [blame] | 62 | // Some consumers of this snapshot (input, layer traces) rely on each snapshot to be unique. |
| 63 | // For mirrored layers, snapshots will have the same sequence so this unique id provides |
| 64 | // an alternative identifier when needed. |
| 65 | uint32_t uniqueSequence; |
| 66 | // Layer id used to create this snapshot. Multiple snapshots will have the same sequence if they |
| 67 | // generated from the same layer, for example when mirroring. |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 68 | int32_t sequence; |
| 69 | std::string name; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 70 | std::string debugName; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 71 | uint32_t textureName; |
| 72 | bool contentOpaque; |
| 73 | bool layerOpaqueFlagSet; |
| 74 | RoundedCornerState roundedCorner; |
| 75 | FloatRect transformedBounds; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 76 | Rect transformedBoundsWithoutTransparentRegion; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 77 | renderengine::ShadowSettings shadowSettings; |
| 78 | bool premultipliedAlpha; |
| 79 | bool isHdrY410; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 80 | ui::Transform parentTransform; |
| 81 | Rect bufferSize; |
| 82 | Rect croppedBufferSize; |
| 83 | std::shared_ptr<renderengine::ExternalTexture> externalTexture; |
| 84 | gui::LayerMetadata layerMetadata; |
| 85 | gui::LayerMetadata relativeLayerMetadata; |
| 86 | bool hasReadyFrame; |
| 87 | ui::Transform localTransformInverse; |
| 88 | gui::WindowInfo inputInfo; |
| 89 | ui::Transform localTransform; |
| 90 | gui::DropInputMode dropInputMode; |
| 91 | bool isTrustedOverlay; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 92 | gui::GameMode gameMode; |
| 93 | scheduler::LayerInfo::FrameRate frameRate; |
| 94 | ui::Transform::RotationFlags fixedTransformHint; |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 95 | std::optional<ui::Transform::RotationFlags> transformHint; |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 96 | bool handleSkipScreenshotFlag = false; |
Vishnu Nair | 3d8565a | 2023-06-30 07:23:24 +0000 | [diff] [blame^] | 97 | int32_t frameRateSelectionPriority = -1; |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 98 | LayerHierarchy::TraversalPath mirrorRootPath; |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 99 | uint32_t touchCropId; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 100 | gui::Uid uid = gui::Uid::INVALID; |
| 101 | gui::Pid pid = gui::Pid::INVALID; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 102 | ChildState childState; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 103 | enum class Reachablilty : uint32_t { |
| 104 | // Can traverse the hierarchy from a root node and reach this snapshot |
| 105 | Reachable, |
| 106 | // Cannot traverse the hierarchy from a root node and reach this snapshot |
| 107 | Unreachable, |
| 108 | // Can only reach this node from a relative parent. This means the nodes parents are |
| 109 | // not reachable. |
| 110 | // See example scenario: |
| 111 | // ROOT |
| 112 | // ├── 1 |
| 113 | // │ ├── 11 |
| 114 | // │ │ └── 111 |
| 115 | // │ ├── 12 |
| 116 | // │ │ └ - 111 (relative) |
| 117 | // │ ├── 13 |
| 118 | // │ └── 14 |
| 119 | // │ └ * 12 (mirroring) |
| 120 | // └── 2 |
| 121 | // 111 will create two snapshots, first when visited from 1 -> 12 or 1 -> 11 and the |
| 122 | // second when visited from 1 -> 14 -> 12. Because its parent 11 doesn't exist in the |
| 123 | // mirrored hierarchy, the second snapshot will be marked as ReachableByRelativeParent. |
| 124 | // This snapshot doesn't have any valid properties because it cannot inherit from its |
| 125 | // parent. Therefore, snapshots that are not reachable will be ignored for composition |
| 126 | // and input. |
| 127 | ReachableByRelativeParent |
| 128 | }; |
| 129 | Reachablilty reachablilty; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 130 | |
| 131 | static bool isOpaqueFormat(PixelFormat format); |
| 132 | static bool isTransformValid(const ui::Transform& t); |
| 133 | |
| 134 | bool canReceiveInput() const; |
| 135 | bool drawShadows() const; |
| 136 | bool fillsColor() const; |
| 137 | bool getIsVisible() const; |
| 138 | bool hasBlur() const; |
| 139 | bool hasBufferOrSidebandStream() const; |
| 140 | bool hasEffect() const; |
| 141 | bool hasSomethingToDraw() const; |
| 142 | bool isContentOpaque() const; |
| 143 | bool isHiddenByPolicy() const; |
| 144 | std::string getDebugString() const; |
| 145 | std::string getIsVisibleReason() const; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 146 | bool hasInputInfo() const; |
Vishnu Nair | 781d725 | 2023-01-30 18:16:01 +0000 | [diff] [blame] | 147 | FloatRect sourceBounds() const; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 148 | Hwc2::IComposerClient::BlendMode getBlendMode(const RequestedLayerState& requested) const; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 149 | friend std::ostream& operator<<(std::ostream& os, const LayerSnapshot& obj); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 150 | void merge(const RequestedLayerState& requested, bool forceUpdate, bool displayChanges, |
| 151 | bool forceFullDamage, uint32_t displayRotationFlags); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | } // namespace android::surfaceflinger::frontend |