Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +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 <aidl/android/hardware/graphics/composer3/Composition.h> |
| 20 | #include <ftl/flags.h> |
| 21 | #include <gui/LayerState.h> |
| 22 | #include <renderengine/ExternalTexture.h> |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 23 | #include "Scheduler/LayerInfo.h" |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 24 | |
| 25 | #include "LayerCreationArgs.h" |
| 26 | #include "TransactionState.h" |
| 27 | |
| 28 | namespace android::surfaceflinger::frontend { |
Ady Abraham | 6846ade | 2024-05-20 21:58:27 +0000 | [diff] [blame] | 29 | using namespace ftl::flag_operators; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 30 | |
| 31 | // Stores client requested states for a layer. |
| 32 | // This struct does not store any other states or states pertaining to |
| 33 | // other layers. Links to other layers that are part of the client |
| 34 | // requested state such as parent are translated to layer id so |
| 35 | // we can avoid extending the lifetime of layer handles. |
| 36 | struct RequestedLayerState : layer_state_t { |
| 37 | // Changes in state after merging with new state. This includes additional state |
| 38 | // changes found in layer_state_t::what. |
| 39 | enum class Changes : uint32_t { |
| 40 | Created = 1u << 0, |
| 41 | Destroyed = 1u << 1, |
| 42 | Hierarchy = 1u << 2, |
| 43 | Geometry = 1u << 3, |
| 44 | Content = 1u << 4, |
| 45 | Input = 1u << 5, |
| 46 | Z = 1u << 6, |
| 47 | Mirror = 1u << 7, |
| 48 | Parent = 1u << 8, |
| 49 | RelativeParent = 1u << 9, |
| 50 | Metadata = 1u << 10, |
| 51 | Visibility = 1u << 11, |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 52 | AffectsChildren = 1u << 12, |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 53 | FrameRate = 1u << 13, |
| 54 | VisibleRegion = 1u << 14, |
| 55 | Buffer = 1u << 15, |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 56 | SidebandStream = 1u << 16, |
Vishnu Nair | ef68d6d | 2023-02-28 06:18:27 +0000 | [diff] [blame] | 57 | Animation = 1u << 17, |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 58 | BufferSize = 1u << 18, |
| 59 | GameMode = 1u << 19, |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 60 | BufferUsageFlags = 1u << 20, |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 61 | }; |
Ady Abraham | 6846ade | 2024-05-20 21:58:27 +0000 | [diff] [blame] | 62 | |
| 63 | static constexpr ftl::Flags<Changes> kMustComposite = Changes::Created | Changes::Destroyed | |
| 64 | Changes::Hierarchy | Changes::Geometry | Changes::Content | Changes::Input | |
| 65 | Changes::Z | Changes::Mirror | Changes::Parent | Changes::RelativeParent | |
| 66 | Changes::Metadata | Changes::Visibility | Changes::VisibleRegion | Changes::Buffer | |
| 67 | Changes::SidebandStream | Changes::Animation | Changes::BufferSize | Changes::GameMode | |
| 68 | Changes::BufferUsageFlags; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 69 | static Rect reduce(const Rect& win, const Region& exclude); |
| 70 | RequestedLayerState(const LayerCreationArgs&); |
| 71 | void merge(const ResolvedComposerState&); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 72 | void clearChanges(); |
| 73 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 74 | // Currently we only care about the primary display |
| 75 | ui::Transform getTransform(uint32_t displayRotationFlags) const; |
| 76 | ui::Size getUnrotatedBufferSize(uint32_t displayRotationFlags) const; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 77 | bool canBeDestroyed() const; |
| 78 | bool isRoot() const; |
| 79 | bool isHiddenByPolicy() const; |
| 80 | half4 getColor() const; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 81 | Rect getBufferSize(uint32_t displayRotationFlags) const; |
Vishnu Nair | a9123c8 | 2024-10-03 03:56:44 +0000 | [diff] [blame] | 82 | FloatRect getCroppedBufferSize(const Rect& bufferSize) const; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 83 | Rect getBufferCrop() const; |
| 84 | std::string getDebugString() const; |
| 85 | std::string getDebugStringShort() const; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 86 | friend std::ostream& operator<<(std::ostream& os, const RequestedLayerState& obj); |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 87 | aidl::android::hardware::graphics::composer3::Composition getCompositionType() const; |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 88 | bool hasValidRelativeParent() const; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 89 | bool hasInputInfo() const; |
Wenhui Yang | ab89d81 | 2024-09-11 23:21:38 +0000 | [diff] [blame] | 90 | bool needsInputInfo() const; |
Wenhui Yang | 4fafc90 | 2024-12-19 20:19:28 +0000 | [diff] [blame^] | 91 | bool hasBufferOrSidebandStream() const; |
| 92 | bool fillsColor() const; |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 93 | bool hasBlur() const; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 94 | bool hasFrameUpdate() const; |
| 95 | bool hasReadyFrame() const; |
| 96 | bool hasSidebandStreamFrame() const; |
Vishnu Nair | 7ee4f46 | 2023-04-19 09:54:09 -0700 | [diff] [blame] | 97 | bool willReleaseBufferOnLatch() const; |
Vishnu Nair | 4d9cef9 | 2023-06-24 22:34:41 +0000 | [diff] [blame] | 98 | bool backpressureEnabled() const; |
| 99 | bool isSimpleBufferUpdate(const layer_state_t&) const; |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 100 | bool isProtected() const; |
Vishnu Nair | 854ce1c | 2023-08-19 15:00:13 -0700 | [diff] [blame] | 101 | bool hasSomethingToDraw() const; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 102 | |
| 103 | // Layer serial number. This gives layers an explicit ordering, so we |
| 104 | // have a stable sort order when their layer stack and Z-order are |
| 105 | // the same. |
| 106 | const uint32_t id; |
| 107 | const std::string name; |
Vishnu Nair | 04f8969 | 2022-11-16 23:21:05 +0000 | [diff] [blame] | 108 | bool canBeRoot = false; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 109 | const uint32_t layerCreationFlags; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 110 | // The owner of the layer. If created from a non system process, it will be the calling uid. |
| 111 | // If created from a system process, the value can be passed in. |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 112 | const gui::Uid ownerUid; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 113 | // The owner pid of the layer. If created from a non system process, it will be the calling pid. |
| 114 | // If created from a system process, the value can be passed in. |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 115 | const gui::Pid ownerPid; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 116 | bool dataspaceRequested; |
| 117 | bool hasColorTransform; |
| 118 | bool premultipliedAlpha{true}; |
| 119 | // This layer can be a cursor on some displays. |
| 120 | bool potentialCursor{false}; |
| 121 | bool protectedByApp{false}; // application requires protected path to external sink |
| 122 | ui::Transform requestedTransform; |
| 123 | std::shared_ptr<FenceTime> acquireFenceTime; |
| 124 | std::shared_ptr<renderengine::ExternalTexture> externalTexture; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 125 | gui::GameMode gameMode; |
| 126 | scheduler::LayerInfo::FrameRate requestedFrameRate; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 127 | uint32_t parentId = UNASSIGNED_LAYER_ID; |
| 128 | uint32_t relativeParentId = UNASSIGNED_LAYER_ID; |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 129 | uint32_t layerIdToMirror = UNASSIGNED_LAYER_ID; |
Vishnu Nair | 1391de2 | 2023-03-05 19:56:14 -0800 | [diff] [blame] | 130 | ui::LayerStack layerStackToMirror = ui::INVALID_LAYER_STACK; |
| 131 | uint32_t touchCropId = UNASSIGNED_LAYER_ID; |
| 132 | uint32_t bgColorLayerId = UNASSIGNED_LAYER_ID; |
Vishnu Nair | 6322121 | 2023-04-06 15:17:37 -0700 | [diff] [blame] | 133 | uint64_t barrierFrameNumber = 0; |
| 134 | uint32_t barrierProducerId = 0; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 135 | std::string debugName; |
Melody Hsu | 1635578 | 2024-10-09 08:56:28 +0000 | [diff] [blame] | 136 | std::atomic<int32_t>* pendingBuffers = 0; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 137 | |
| 138 | // book keeping states |
| 139 | bool handleAlive = true; |
| 140 | bool isRelativeOf = false; |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 141 | std::vector<uint32_t> mirrorIds{}; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 142 | ftl::Flags<RequestedLayerState::Changes> changes; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 143 | bool bgColorLayer = false; |
Vishnu Nair | dc4d31b | 2022-11-17 03:20:58 +0000 | [diff] [blame] | 144 | }; |
| 145 | |
| 146 | } // namespace android::surfaceflinger::frontend |