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