• 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/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/ShadowSettings.h>
30 #include <ui/Transform.h>
31 
32 // TODO(b/129481165): remove the #pragma below and fix conversion issues
33 #pragma clang diagnostic push
34 #pragma clang diagnostic ignored "-Wconversion"
35 #pragma clang diagnostic ignored "-Wextra"
36 
37 #include <gui/BufferQueue.h>
38 #include <ui/GraphicBuffer.h>
39 #include <ui/GraphicTypes.h>
40 #include <ui/StretchEffect.h>
41 
42 #include "DisplayHardware/Hal.h"
43 
44 #include <aidl/android/hardware/graphics/composer3/Composition.h>
45 
46 // TODO(b/129481165): remove the #pragma below and fix conversion issues
47 #pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
48 
49 namespace android::compositionengine {
50 
51 namespace hal = android::hardware::graphics::composer::hal;
52 
53 // More complex metadata for this layer
54 struct GenericLayerMetadataEntry {
55     // True if the metadata may affect the composed result.
56     // See setLayerGenericMetadata in IComposerClient.hal
57     bool mandatory;
58 
59     // Byte blob or parcel
60     std::vector<uint8_t> value;
61 
62     std::string dumpAsString() const;
63 
64     struct Hasher {
operatorGenericLayerMetadataEntry::Hasher65         size_t operator()(const GenericLayerMetadataEntry& entry) const {
66             size_t hash = 0;
67             for (const auto value : entry.value) {
68                 hashCombineSingleHashed(hash, value);
69             }
70             return hash;
71         }
72     };
73 };
74 
75 inline bool operator==(const GenericLayerMetadataEntry& lhs, const GenericLayerMetadataEntry& rhs) {
76     return lhs.mandatory == rhs.mandatory && lhs.value == rhs.value;
77 }
78 
79 // Defining PrintTo helps with Google Tests.
PrintTo(const GenericLayerMetadataEntry & v,::std::ostream * os)80 inline void PrintTo(const GenericLayerMetadataEntry& v, ::std::ostream* os) {
81     *os << v.dumpAsString();
82 }
83 
84 using GenericLayerMetadataMap = std::unordered_map<std::string, GenericLayerMetadataEntry>;
85 
86 /*
87  * Used by LayerFE::getCompositionState
88  * Note that fields that affect HW composer state may need to be mirrored into
89  * android::compositionengine::impl::planner::LayerState
90  */
91 struct LayerFECompositionState {
92     // If set to true, forces client composition on all output layers until
93     // the next geometry change.
94     bool forceClientComposition{false};
95 
96     // TODO(b/121291683): Reorganize and rename the contents of this structure
97 
98     /*
99      * Visibility state
100      */
101 
102     // The filter that determines which outputs include this layer
103     ui::LayerFilter outputFilter;
104 
105     // If false, this layer should not be considered visible
106     bool isVisible{true};
107 
108     // True if the layer is completely opaque
109     bool isOpaque{true};
110 
111     // If true, invalidates the entire visible region
112     bool contentDirty{false};
113 
114     // The alpha value for this layer
115     float alpha{1.f};
116 
117     // Background blur in pixels
118     int backgroundBlurRadius{0};
119 
120     // The transform from layer local coordinates to composition coordinates
121     ui::Transform geomLayerTransform;
122 
123     // The inverse of the layer transform
124     ui::Transform geomInverseLayerTransform;
125 
126     // The hint from the layer producer as to what portion of the layer is
127     // transparent.
128     Region transparentRegionHint;
129 
130     // The blend mode for this layer
131     hal::BlendMode blendMode{hal::BlendMode::INVALID};
132 
133     // The bounds of the layer in layer local coordinates
134     FloatRect geomLayerBounds;
135 
136     ShadowSettings shadowSettings;
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