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