• 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/LayerStack.h>
26 #include <ui/Rect.h>
27 #include <ui/Region.h>
28 #include <ui/Transform.h>
29 
30 // TODO(b/129481165): remove the #pragma below and fix conversion issues
31 #pragma clang diagnostic push
32 #pragma clang diagnostic ignored "-Wconversion"
33 #pragma clang diagnostic ignored "-Wextra"
34 
35 #include <gui/BufferQueue.h>
36 #include <ui/GraphicBuffer.h>
37 #include <ui/GraphicTypes.h>
38 #include <ui/StretchEffect.h>
39 
40 #include "DisplayHardware/Hal.h"
41 
42 #include <aidl/android/hardware/graphics/composer3/Composition.h>
43 
44 // TODO(b/129481165): remove the #pragma below and fix conversion issues
45 #pragma clang diagnostic pop // ignored "-Wconversion -Wextra"
46 
47 namespace android::compositionengine {
48 
49 namespace hal = android::hardware::graphics::composer::hal;
50 
51 // More complex metadata for this layer
52 struct 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;
61 
62     struct Hasher {
operatorGenericLayerMetadataEntry::Hasher63         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     };
71 };
72 
73 inline 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.
PrintTo(const GenericLayerMetadataEntry & v,::std::ostream * os)78 inline void PrintTo(const GenericLayerMetadataEntry& v, ::std::ostream* os) {
79     *os << v.dumpAsString();
80 }
81 
82 using GenericLayerMetadataMap = std::unordered_map<std::string, GenericLayerMetadataEntry>;
83 
84 /*
85  * Used by LayerFE::getCompositionState
86  * Note that fields that affect HW composer state may need to be mirrored into
87  * android::compositionengine::impl::planner::LayerState
88  */
89 struct LayerFECompositionState {
90     // If set to true, forces client composition on all output layers until
91     // the next geometry change.
92     bool forceClientComposition{false};
93 
94     // TODO(b/121291683): Reorganize and rename the contents of this structure
95 
96     /*
97      * Visibility state
98      */
99 
100     // The filter that determines which outputs include this layer
101     ui::LayerFilter outputFilter;
102 
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 
115     // Background blur in pixels
116     int backgroundBlurRadius{0};
117 
118     // 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
129     hal::BlendMode blendMode{hal::BlendMode::INVALID};
130 
131     // The bounds of the layer in layer local coordinates
132     FloatRect geomLayerBounds;
133 
134     // length of the shadow in screen space
135     float shadowRadius{0.f};
136 
137     // List of regions that require blur
138     std::vector<BlurRegion> blurRegions;
139 
140     StretchEffect stretchEffect;
141 
142     /*
143      * Geometry state
144      */
145 
146     bool isSecure{false};
147     bool geomUsesSourceCrop{false};
148     bool geomBufferUsesDisplayInverseTransform{false};
149     uint32_t geomBufferTransform{0};
150     Rect geomBufferSize;
151     Rect geomContentCrop;
152     Rect geomCrop;
153 
154     GenericLayerMetadataMap metadata;
155 
156     /*
157      * Per-frame content
158      */
159 
160     // The type of composition for this layer
161     aidl::android::hardware::graphics::composer3::Composition compositionType{
162             aidl::android::hardware::graphics::composer3::Composition::INVALID};
163 
164     // The buffer and related state
165     sp<GraphicBuffer> buffer;
166     int bufferSlot{BufferQueue::INVALID_BUFFER_SLOT};
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     virtual ~LayerFECompositionState();
214 
215     // Debugging
216     virtual void dump(std::string& out) const;
217 };
218 
219 } // namespace android::compositionengine
220