blob: 5bb249719ea76f7ee9e42b8b42473a3a63bebb07 [file] [log] [blame]
Lloyd Pique0b785d82018-12-04 17:25:27 -08001/*
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 Pique0b785d82018-12-04 17:25:27 -080021#include <gui/HdrMetadata.h>
22#include <math/mat4.h>
Lucas Dupinc3800b82020-10-02 16:24:48 -070023#include <ui/BlurRegion.h>
Lloyd Pique0b785d82018-12-04 17:25:27 -080024#include <ui/FloatRect.h>
Dominik Laskowski29fa1462021-04-27 15:51:50 -070025#include <ui/LayerStack.h>
Lloyd Pique0b785d82018-12-04 17:25:27 -080026#include <ui/Rect.h>
27#include <ui/Region.h>
28#include <ui/Transform.h>
29
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080030// TODO(b/129481165): remove the #pragma below and fix conversion issues
31#pragma clang diagnostic push
32#pragma clang diagnostic ignored "-Wconversion"
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010033#pragma clang diagnostic ignored "-Wextra"
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080034
35#include <gui/BufferQueue.h>
36#include <ui/GraphicBuffer.h>
37#include <ui/GraphicTypes.h>
John Reckcdb4ed72021-02-04 13:39:33 -050038#include <ui/StretchEffect.h>
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080039
Peiyong Line9d809e2020-04-14 13:10:48 -070040#include "DisplayHardware/Hal.h"
Lloyd Pique0b785d82018-12-04 17:25:27 -080041
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050042#include <aidl/android/hardware/graphics/composer3/Composition.h>
43
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080044// TODO(b/129481165): remove the #pragma below and fix conversion issues
Marin Shalamanovbed7fd32020-12-21 20:02:20 +010045#pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080046
Lloyd Pique0b785d82018-12-04 17:25:27 -080047namespace android::compositionengine {
48
Peiyong Line9d809e2020-04-14 13:10:48 -070049namespace hal = android::hardware::graphics::composer::hal;
50
Lloyd Pique8d9f8362020-02-11 19:13:09 -080051// More complex metadata for this layer
52struct 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 Mouri69114c72021-03-19 19:31:29 -070061
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 Pique8d9f8362020-02-11 19:13:09 -080071};
72
73inline 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.
78inline void PrintTo(const GenericLayerMetadataEntry& v, ::std::ostream* os) {
79 *os << v.dumpAsString();
80}
81
82using GenericLayerMetadataMap = std::unordered_map<std::string, GenericLayerMetadataEntry>;
83
Lloyd Pique0b785d82018-12-04 17:25:27 -080084/*
85 * Used by LayerFE::getCompositionState
Alec Mouri69114c72021-03-19 19:31:29 -070086 * Note that fields that affect HW composer state may need to be mirrored into
87 * android::compositionengine::impl::planner::LayerState
Lloyd Pique0b785d82018-12-04 17:25:27 -080088 */
89struct LayerFECompositionState {
Lloyd Piquef5275482019-01-29 18:42:42 -080090 // If set to true, forces client composition on all output layers until
91 // the next geometry change.
92 bool forceClientComposition{false};
Lloyd Pique07e33212018-12-18 16:33:37 -080093
Lloyd Piquec6687342019-03-07 21:34:57 -080094 // TODO(b/121291683): Reorganize and rename the contents of this structure
95
96 /*
97 * Visibility state
98 */
Lloyd Piquec6687342019-03-07 21:34:57 -080099
Dominik Laskowski29fa1462021-04-27 15:51:50 -0700100 // The filter that determines which outputs include this layer
101 ui::LayerFilter outputFilter;
Lloyd Piquec6687342019-03-07 21:34:57 -0800102
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 Dupin19c8f0e2019-11-25 17:55:44 -0800115 // Background blur in pixels
116 int backgroundBlurRadius{0};
117
Lloyd Piquec6687342019-03-07 21:34:57 -0800118 // 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 Line9d809e2020-04-14 13:10:48 -0700129 hal::BlendMode blendMode{hal::BlendMode::INVALID};
Lloyd Piquec6687342019-03-07 21:34:57 -0800130
131 // The bounds of the layer in layer local coordinates
132 FloatRect geomLayerBounds;
133
Vishnu Naira483b4a2019-12-12 15:07:52 -0800134 // length of the shadow in screen space
Lloyd Pique5d4e24e2020-08-19 20:02:44 -0700135 float shadowRadius{0.f};
Vishnu Naira483b4a2019-12-12 15:07:52 -0800136
Lucas Dupinc3800b82020-10-02 16:24:48 -0700137 // List of regions that require blur
138 std::vector<BlurRegion> blurRegions;
139
John Reckcdb4ed72021-02-04 13:39:33 -0500140 StretchEffect stretchEffect;
141
Lloyd Pique0b785d82018-12-04 17:25:27 -0800142 /*
Lloyd Piquea83776c2019-01-29 18:42:32 -0800143 * Geometry state
144 */
145
146 bool isSecure{false};
147 bool geomUsesSourceCrop{false};
148 bool geomBufferUsesDisplayInverseTransform{false};
149 uint32_t geomBufferTransform{0};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800150 Rect geomBufferSize;
151 Rect geomContentCrop;
152 Rect geomCrop;
Lloyd Pique0b785d82018-12-04 17:25:27 -0800153
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800154 GenericLayerMetadataMap metadata;
155
Lloyd Pique0b785d82018-12-04 17:25:27 -0800156 /*
157 * Per-frame content
158 */
159
160 // The type of composition for this layer
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500161 aidl::android::hardware::graphics::composer3::Composition compositionType{
162 aidl::android::hardware::graphics::composer3::Composition::INVALID};
Lloyd Pique0b785d82018-12-04 17:25:27 -0800163
164 // The buffer and related state
165 sp<GraphicBuffer> buffer;
Alec Mouri2b1212b2021-12-09 12:02:39 -0800166 sp<Fence> acquireFence = Fence::NO_FENCE;
Lloyd Pique0b785d82018-12-04 17:25:27 -0800167 Region surfaceDamage;
John Reckbb409682022-03-04 16:03:37 -0500168 uint64_t frameNumber = 0;
Lloyd Pique0b785d82018-12-04 17:25:27 -0800169
170 // The handle to use for a sideband stream for this layer
171 sp<NativeHandle> sidebandStream;
baocheng sun9691b9c2021-08-03 19:27:06 +0800172 // If true, this sideband layer has a frame update
173 bool sidebandStreamHasFrame{false};
Lloyd Pique0b785d82018-12-04 17:25:27 -0800174
175 // The color for this layer
Lloyd Piquef5275482019-01-29 18:42:42 -0800176 half4 color;
Lloyd Pique0b785d82018-12-04 17:25:27 -0800177
178 /*
179 * Per-frame presentation state
180 */
181
Lloyd Piquef5275482019-01-29 18:42:42 -0800182 // 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 Pique0b785d82018-12-04 17:25:27 -0800186 // 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 Piquef5275482019-01-29 18:42:42 -0800194 bool colorTransformIsIdentity{true};
Lloyd Pique688abd42019-02-15 15:42:24 -0800195
Lloyd Pique688abd42019-02-15 15:42:24 -0800196 // True if the layer has protected content
197 bool hasProtectedContent{false};
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800198
199 /*
200 * Cursor state
201 */
202
203 // The output-independent frame for the cursor
204 Rect cursorFrame;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700205
Nathaniel Nifong1303d912021-10-06 09:41:24 -0400206 // framerate of the layer as measured by LayerHistory
207 float fps;
208
Sally Qi421ffb02022-03-21 19:41:33 -0700209 // The dimming flag
210 bool dimmingEnabled{true};
211
John Reck68796592023-01-25 13:47:12 -0500212 float currentSdrHdrRatio = 1.f;
213 float desiredSdrHdrRatio = 1.f;
214
Lloyd Piquede196652020-01-22 17:29:58 -0800215 virtual ~LayerFECompositionState();
216
Lloyd Pique9755fb72019-03-26 14:44:40 -0700217 // Debugging
Lloyd Piquede196652020-01-22 17:29:58 -0800218 virtual void dump(std::string& out) const;
Lloyd Pique0b785d82018-12-04 17:25:27 -0800219};
220
221} // namespace android::compositionengine