| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 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 <cstdint> |
| 20 | |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 21 | #include <gui/HdrMetadata.h> |
| 22 | #include <math/mat4.h> |
| Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 23 | #include <ui/BlurRegion.h> |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 24 | #include <ui/FloatRect.h> |
| Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 25 | #include <ui/LayerStack.h> |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 26 | #include <ui/Rect.h> |
| 27 | #include <ui/Region.h> |
| 28 | #include <ui/Transform.h> |
| 29 | |
| Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 30 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 31 | #pragma clang diagnostic push |
| 32 | #pragma clang diagnostic ignored "-Wconversion" |
| Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 33 | #pragma clang diagnostic ignored "-Wextra" |
| Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 34 | |
| 35 | #include <gui/BufferQueue.h> |
| 36 | #include <ui/GraphicBuffer.h> |
| 37 | #include <ui/GraphicTypes.h> |
| John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 38 | #include <ui/StretchEffect.h> |
| Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 39 | |
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 40 | #include "DisplayHardware/Hal.h" |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 41 | |
| Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 42 | #include <aidl/android/hardware/graphics/composer3/Composition.h> |
| 43 | |
| Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 44 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| Marin Shalamanov | bed7fd3 | 2020-12-21 20:02:20 +0100 | [diff] [blame] | 45 | #pragma clang diagnostic pop // ignored "-Wconversion -Wextra" |
| Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 46 | |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 47 | namespace android::compositionengine { |
| 48 | |
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 49 | namespace hal = android::hardware::graphics::composer::hal; |
| 50 | |
| Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 51 | // More complex metadata for this layer |
| 52 | struct GenericLayerMetadataEntry { |
| 53 | // True if the metadata may affect the composed result. |
| 54 | // See setLayerGenericMetadata in IComposerClient.hal |
| 55 | bool mandatory; |
| 56 | |
| 57 | // Byte blob or parcel |
| 58 | std::vector<uint8_t> value; |
| 59 | |
| 60 | std::string dumpAsString() const; |
| Alec Mouri | 69114c7 | 2021-03-19 19:31:29 -0700 | [diff] [blame] | 61 | |
| 62 | struct Hasher { |
| 63 | size_t operator()(const GenericLayerMetadataEntry& entry) const { |
| 64 | size_t hash = 0; |
| 65 | for (const auto value : entry.value) { |
| 66 | hashCombineSingleHashed(hash, value); |
| 67 | } |
| 68 | return hash; |
| 69 | } |
| 70 | }; |
| Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 71 | }; |
| 72 | |
| 73 | inline bool operator==(const GenericLayerMetadataEntry& lhs, const GenericLayerMetadataEntry& rhs) { |
| 74 | return lhs.mandatory == rhs.mandatory && lhs.value == rhs.value; |
| 75 | } |
| 76 | |
| 77 | // Defining PrintTo helps with Google Tests. |
| 78 | inline void PrintTo(const GenericLayerMetadataEntry& v, ::std::ostream* os) { |
| 79 | *os << v.dumpAsString(); |
| 80 | } |
| 81 | |
| 82 | using GenericLayerMetadataMap = std::unordered_map<std::string, GenericLayerMetadataEntry>; |
| 83 | |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 84 | /* |
| 85 | * Used by LayerFE::getCompositionState |
| Alec Mouri | 69114c7 | 2021-03-19 19:31:29 -0700 | [diff] [blame] | 86 | * Note that fields that affect HW composer state may need to be mirrored into |
| 87 | * android::compositionengine::impl::planner::LayerState |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 88 | */ |
| 89 | struct LayerFECompositionState { |
| Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 90 | // If set to true, forces client composition on all output layers until |
| 91 | // the next geometry change. |
| 92 | bool forceClientComposition{false}; |
| Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 93 | |
| Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 94 | // TODO(b/121291683): Reorganize and rename the contents of this structure |
| 95 | |
| 96 | /* |
| 97 | * Visibility state |
| 98 | */ |
| Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 99 | |
| Dominik Laskowski | 29fa146 | 2021-04-27 15:51:50 -0700 | [diff] [blame] | 100 | // The filter that determines which outputs include this layer |
| 101 | ui::LayerFilter outputFilter; |
| Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 102 | |
| 103 | // If false, this layer should not be considered visible |
| 104 | bool isVisible{true}; |
| 105 | |
| 106 | // True if the layer is completely opaque |
| 107 | bool isOpaque{true}; |
| 108 | |
| 109 | // If true, invalidates the entire visible region |
| 110 | bool contentDirty{false}; |
| 111 | |
| 112 | // The alpha value for this layer |
| 113 | float alpha{1.f}; |
| 114 | |
| Lucas Dupin | 19c8f0e | 2019-11-25 17:55:44 -0800 | [diff] [blame] | 115 | // Background blur in pixels |
| 116 | int backgroundBlurRadius{0}; |
| 117 | |
| Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 118 | // The transform from layer local coordinates to composition coordinates |
| 119 | ui::Transform geomLayerTransform; |
| 120 | |
| 121 | // The inverse of the layer transform |
| 122 | ui::Transform geomInverseLayerTransform; |
| 123 | |
| 124 | // The hint from the layer producer as to what portion of the layer is |
| 125 | // transparent. |
| 126 | Region transparentRegionHint; |
| 127 | |
| 128 | // The blend mode for this layer |
| Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 129 | hal::BlendMode blendMode{hal::BlendMode::INVALID}; |
| Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 130 | |
| 131 | // The bounds of the layer in layer local coordinates |
| 132 | FloatRect geomLayerBounds; |
| 133 | |
| Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 134 | // length of the shadow in screen space |
| Lloyd Pique | 5d4e24e | 2020-08-19 20:02:44 -0700 | [diff] [blame] | 135 | float shadowRadius{0.f}; |
| Vishnu Nair | a483b4a | 2019-12-12 15:07:52 -0800 | [diff] [blame] | 136 | |
| Lucas Dupin | c3800b8 | 2020-10-02 16:24:48 -0700 | [diff] [blame] | 137 | // List of regions that require blur |
| 138 | std::vector<BlurRegion> blurRegions; |
| 139 | |
| John Reck | cdb4ed7 | 2021-02-04 13:39:33 -0500 | [diff] [blame] | 140 | StretchEffect stretchEffect; |
| 141 | |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 142 | /* |
| Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 143 | * Geometry state |
| 144 | */ |
| 145 | |
| 146 | bool isSecure{false}; |
| 147 | bool geomUsesSourceCrop{false}; |
| 148 | bool geomBufferUsesDisplayInverseTransform{false}; |
| 149 | uint32_t geomBufferTransform{0}; |
| Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 150 | Rect geomBufferSize; |
| 151 | Rect geomContentCrop; |
| 152 | Rect geomCrop; |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 153 | |
| Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 154 | GenericLayerMetadataMap metadata; |
| 155 | |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 156 | /* |
| 157 | * Per-frame content |
| 158 | */ |
| 159 | |
| 160 | // The type of composition for this layer |
| Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 161 | aidl::android::hardware::graphics::composer3::Composition compositionType{ |
| 162 | aidl::android::hardware::graphics::composer3::Composition::INVALID}; |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 163 | |
| 164 | // The buffer and related state |
| 165 | sp<GraphicBuffer> buffer; |
| Alec Mouri | 2b1212b | 2021-12-09 12:02:39 -0800 | [diff] [blame] | 166 | sp<Fence> acquireFence = Fence::NO_FENCE; |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 167 | Region surfaceDamage; |
| John Reck | bb40968 | 2022-03-04 16:03:37 -0500 | [diff] [blame] | 168 | uint64_t frameNumber = 0; |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 169 | |
| 170 | // The handle to use for a sideband stream for this layer |
| 171 | sp<NativeHandle> sidebandStream; |
| baocheng sun | 9691b9c | 2021-08-03 19:27:06 +0800 | [diff] [blame] | 172 | // If true, this sideband layer has a frame update |
| 173 | bool sidebandStreamHasFrame{false}; |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 174 | |
| 175 | // The color for this layer |
| Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 176 | half4 color; |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 177 | |
| 178 | /* |
| 179 | * Per-frame presentation state |
| 180 | */ |
| 181 | |
| Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 182 | // If true, this layer will use the dataspace chosen for the output and |
| 183 | // ignore the dataspace value just below |
| 184 | bool isColorspaceAgnostic{false}; |
| 185 | |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 186 | // The dataspace for this layer |
| 187 | ui::Dataspace dataspace{ui::Dataspace::UNKNOWN}; |
| 188 | |
| 189 | // The metadata for this layer |
| 190 | HdrMetadata hdrMetadata; |
| 191 | |
| 192 | // The color transform |
| 193 | mat4 colorTransform; |
| Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 194 | bool colorTransformIsIdentity{true}; |
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 195 | |
| Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 196 | // True if the layer has protected content |
| 197 | bool hasProtectedContent{false}; |
| Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 198 | |
| 199 | /* |
| 200 | * Cursor state |
| 201 | */ |
| 202 | |
| 203 | // The output-independent frame for the cursor |
| 204 | Rect cursorFrame; |
| Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 205 | |
| Nathaniel Nifong | 1303d91 | 2021-10-06 09:41:24 -0400 | [diff] [blame] | 206 | // framerate of the layer as measured by LayerHistory |
| 207 | float fps; |
| 208 | |
| Sally Qi | 421ffb0 | 2022-03-21 19:41:33 -0700 | [diff] [blame] | 209 | // The dimming flag |
| 210 | bool dimmingEnabled{true}; |
| 211 | |
| John Reck | 6879659 | 2023-01-25 13:47:12 -0500 | [diff] [blame] | 212 | float currentSdrHdrRatio = 1.f; |
| 213 | float desiredSdrHdrRatio = 1.f; |
| 214 | |
| Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 215 | virtual ~LayerFECompositionState(); |
| 216 | |
| Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 217 | // Debugging |
| Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 218 | virtual void dump(std::string& out) const; |
| Lloyd Pique | 0b785d8 | 2018-12-04 17:25:27 -0800 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | } // namespace android::compositionengine |