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