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> |
| 21 | #include "LayerHierarchy.h" |
| 22 | #include "RequestedLayerState.h" |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 23 | #include "Scheduler/LayerInfo.h" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 24 | #include "android-base/stringprintf.h" |
| 25 | |
| 26 | namespace android::surfaceflinger::frontend { |
| 27 | |
| 28 | struct 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 Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 43 | struct ChildState { |
| 44 | bool hasValidFrameRate = false; |
| 45 | }; |
| 46 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 47 | // 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. |
| 50 | struct 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 Nair | 93b8b79 | 2023-02-27 19:40:24 +0000 | [diff] [blame] | 60 | // 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 Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 66 | int32_t sequence; |
| 67 | std::string name; |
| 68 | uint32_t textureName; |
| 69 | bool contentOpaque; |
| 70 | bool layerOpaqueFlagSet; |
| 71 | RoundedCornerState roundedCorner; |
| 72 | FloatRect transformedBounds; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 73 | Rect transformedBoundsWithoutTransparentRegion; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 74 | renderengine::ShadowSettings shadowSettings; |
| 75 | bool premultipliedAlpha; |
| 76 | bool isHdrY410; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 77 | 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 Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 89 | gui::GameMode gameMode; |
| 90 | scheduler::LayerInfo::FrameRate frameRate; |
| 91 | ui::Transform::RotationFlags fixedTransformHint; |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame^] | 92 | std::optional<ui::Transform::RotationFlags> transformHint; |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 93 | bool handleSkipScreenshotFlag = false; |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 94 | int32_t frameRateSelectionPriority; |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 95 | LayerHierarchy::TraversalPath mirrorRootPath; |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 96 | bool unreachable = true; |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 97 | uid_t uid; |
| 98 | pid_t pid; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 99 | ChildState childState; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 100 | |
| 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 Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 116 | bool hasInputInfo() const; |
Vishnu Nair | 781d725 | 2023-01-30 18:16:01 +0000 | [diff] [blame] | 117 | FloatRect sourceBounds() const; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 118 | }; |
| 119 | |
| 120 | } // namespace android::surfaceflinger::frontend |