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 "DisplayHardware/ComposerHal.h" 22 #include "LayerHierarchy.h" 23 #include "RequestedLayerState.h" 24 #include "Scheduler/LayerInfo.h" 25 #include "android-base/stringprintf.h" 26 27 namespace android::surfaceflinger::frontend { 28 29 struct RoundedCornerState { 30 RoundedCornerState() = default; RoundedCornerStateRoundedCornerState31 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; hasRoundedCornersRoundedCornerState38 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 44 struct ChildState { 45 bool hasValidFrameRate = false; 46 }; 47 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; 61 uint64_t clientChanges = 0; 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. 68 int32_t sequence; 69 std::string name; 70 uint32_t textureName; 71 bool contentOpaque; 72 bool layerOpaqueFlagSet; 73 RoundedCornerState roundedCorner; 74 FloatRect transformedBounds; 75 Rect transformedBoundsWithoutTransparentRegion; 76 renderengine::ShadowSettings shadowSettings; 77 bool premultipliedAlpha; 78 bool isHdrY410; 79 ui::Transform parentTransform; 80 Rect bufferSize; 81 Rect croppedBufferSize; 82 std::shared_ptr<renderengine::ExternalTexture> externalTexture; 83 gui::LayerMetadata layerMetadata; 84 gui::LayerMetadata relativeLayerMetadata; 85 bool hasReadyFrame; 86 ui::Transform localTransformInverse; 87 gui::WindowInfo inputInfo; 88 ui::Transform localTransform; 89 gui::DropInputMode dropInputMode; 90 bool isTrustedOverlay; 91 gui::GameMode gameMode; 92 scheduler::LayerInfo::FrameRate frameRate; 93 ui::Transform::RotationFlags fixedTransformHint; 94 std::optional<ui::Transform::RotationFlags> transformHint; 95 bool handleSkipScreenshotFlag = false; 96 int32_t frameRateSelectionPriority; 97 LayerHierarchy::TraversalPath mirrorRootPath; 98 uint32_t touchCropId; 99 gui::Uid uid = gui::Uid::INVALID; 100 gui::Pid pid = gui::Pid::INVALID; 101 ChildState childState; 102 enum class Reachablilty : uint32_t { 103 // Can traverse the hierarchy from a root node and reach this snapshot 104 Reachable, 105 // Cannot traverse the hierarchy from a root node and reach this snapshot 106 Unreachable, 107 // Can only reach this node from a relative parent. This means the nodes parents are 108 // not reachable. 109 // See example scenario: 110 // ROOT 111 // ├── 1 112 // │ ├── 11 113 // │ │ └── 111 114 // │ ├── 12 115 // │ │ └ - 111 (relative) 116 // │ ├── 13 117 // │ └── 14 118 // │ └ * 12 (mirroring) 119 // └── 2 120 // 111 will create two snapshots, first when visited from 1 -> 12 or 1 -> 11 and the 121 // second when visited from 1 -> 14 -> 12. Because its parent 11 doesn't exist in the 122 // mirrored hierarchy, the second snapshot will be marked as ReachableByRelativeParent. 123 // This snapshot doesn't have any valid properties because it cannot inherit from its 124 // parent. Therefore, snapshots that are not reachable will be ignored for composition 125 // and input. 126 ReachableByRelativeParent 127 }; 128 Reachablilty reachablilty; 129 130 static bool isOpaqueFormat(PixelFormat format); 131 static bool isTransformValid(const ui::Transform& t); 132 133 bool canReceiveInput() const; 134 bool drawShadows() const; 135 bool fillsColor() const; 136 bool getIsVisible() const; 137 bool hasBlur() const; 138 bool hasBufferOrSidebandStream() const; 139 bool hasEffect() const; 140 bool hasSomethingToDraw() const; 141 bool isContentOpaque() const; 142 bool isHiddenByPolicy() const; 143 std::string getDebugString() const; 144 std::string getIsVisibleReason() const; 145 bool hasInputInfo() const; 146 FloatRect sourceBounds() const; 147 Hwc2::IComposerClient::BlendMode getBlendMode(const RequestedLayerState& requested) const; 148 149 void merge(const RequestedLayerState& requested, bool forceUpdate, bool displayChanges, 150 bool forceFullDamage, uint32_t displayRotationFlags); 151 }; 152 153 } // namespace android::surfaceflinger::frontend 154