blob: d8ce629153708126ff404dcb818e324601d29362 [file] [log] [blame]
Lloyd Pique0b785d82018-12-04 17:25:27 -08001/*
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
Lloyd Pique0b785d82018-12-04 17:25:27 -080021#include <gui/HdrMetadata.h>
22#include <math/mat4.h>
23#include <ui/FloatRect.h>
Lloyd Pique0b785d82018-12-04 17:25:27 -080024#include <ui/Rect.h>
25#include <ui/Region.h>
26#include <ui/Transform.h>
27
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080028// TODO(b/129481165): remove the #pragma below and fix conversion issues
29#pragma clang diagnostic push
30#pragma clang diagnostic ignored "-Wconversion"
31
32#include <gui/BufferQueue.h>
33#include <ui/GraphicBuffer.h>
34#include <ui/GraphicTypes.h>
35
Lloyd Pique0b785d82018-12-04 17:25:27 -080036#include "DisplayHardware/ComposerHal.h"
37
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080038// TODO(b/129481165): remove the #pragma below and fix conversion issues
39#pragma clang diagnostic pop // ignored "-Wconversion"
40
Lloyd Pique0b785d82018-12-04 17:25:27 -080041namespace android::compositionengine {
42
Lloyd Pique8d9f8362020-02-11 19:13:09 -080043// More complex metadata for this layer
44struct GenericLayerMetadataEntry {
45 // True if the metadata may affect the composed result.
46 // See setLayerGenericMetadata in IComposerClient.hal
47 bool mandatory;
48
49 // Byte blob or parcel
50 std::vector<uint8_t> value;
51
52 std::string dumpAsString() const;
53};
54
55inline bool operator==(const GenericLayerMetadataEntry& lhs, const GenericLayerMetadataEntry& rhs) {
56 return lhs.mandatory == rhs.mandatory && lhs.value == rhs.value;
57}
58
59// Defining PrintTo helps with Google Tests.
60inline void PrintTo(const GenericLayerMetadataEntry& v, ::std::ostream* os) {
61 *os << v.dumpAsString();
62}
63
64using GenericLayerMetadataMap = std::unordered_map<std::string, GenericLayerMetadataEntry>;
65
Lloyd Pique0b785d82018-12-04 17:25:27 -080066/*
67 * Used by LayerFE::getCompositionState
68 */
69struct LayerFECompositionState {
Lloyd Piquef5275482019-01-29 18:42:42 -080070 // If set to true, forces client composition on all output layers until
71 // the next geometry change.
72 bool forceClientComposition{false};
Lloyd Pique07e33212018-12-18 16:33:37 -080073
Lloyd Piquec6687342019-03-07 21:34:57 -080074 // TODO(b/121291683): Reorganize and rename the contents of this structure
75
76 /*
77 * Visibility state
78 */
79 // the layer stack this layer belongs to
80 std::optional<uint32_t> layerStackId;
81
82 // If true, this layer should be only visible on the internal display
83 bool internalOnly{false};
84
85 // If false, this layer should not be considered visible
86 bool isVisible{true};
87
88 // True if the layer is completely opaque
89 bool isOpaque{true};
90
91 // If true, invalidates the entire visible region
92 bool contentDirty{false};
93
94 // The alpha value for this layer
95 float alpha{1.f};
96
Lucas Dupin19c8f0e2019-11-25 17:55:44 -080097 // Background blur in pixels
98 int backgroundBlurRadius{0};
99
Lloyd Piquec6687342019-03-07 21:34:57 -0800100 // The transform from layer local coordinates to composition coordinates
101 ui::Transform geomLayerTransform;
102
103 // The inverse of the layer transform
104 ui::Transform geomInverseLayerTransform;
105
106 // The hint from the layer producer as to what portion of the layer is
107 // transparent.
108 Region transparentRegionHint;
109
110 // The blend mode for this layer
111 Hwc2::IComposerClient::BlendMode blendMode{Hwc2::IComposerClient::BlendMode::INVALID};
112
113 // The bounds of the layer in layer local coordinates
114 FloatRect geomLayerBounds;
115
Vishnu Naira483b4a2019-12-12 15:07:52 -0800116 // length of the shadow in screen space
117 float shadowRadius;
118
Lloyd Pique0b785d82018-12-04 17:25:27 -0800119 /*
Lloyd Piquea83776c2019-01-29 18:42:32 -0800120 * Geometry state
121 */
122
123 bool isSecure{false};
124 bool geomUsesSourceCrop{false};
125 bool geomBufferUsesDisplayInverseTransform{false};
126 uint32_t geomBufferTransform{0};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800127 Rect geomBufferSize;
128 Rect geomContentCrop;
129 Rect geomCrop;
Lloyd Pique0b785d82018-12-04 17:25:27 -0800130
131 /*
132 * Extra metadata
133 */
134
135 // The type for this layer
136 int type{0};
137
138 // The appId for this layer
139 int appId{0};
140
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800141 GenericLayerMetadataMap metadata;
142
Lloyd Pique0b785d82018-12-04 17:25:27 -0800143 /*
144 * Per-frame content
145 */
146
147 // The type of composition for this layer
148 Hwc2::IComposerClient::Composition compositionType{Hwc2::IComposerClient::Composition::INVALID};
149
150 // The buffer and related state
151 sp<GraphicBuffer> buffer;
152 int bufferSlot{BufferQueue::INVALID_BUFFER_SLOT};
153 sp<Fence> acquireFence;
154 Region surfaceDamage;
155
156 // The handle to use for a sideband stream for this layer
157 sp<NativeHandle> sidebandStream;
158
159 // The color for this layer
Lloyd Piquef5275482019-01-29 18:42:42 -0800160 half4 color;
Lloyd Pique0b785d82018-12-04 17:25:27 -0800161
162 /*
163 * Per-frame presentation state
164 */
165
Lloyd Piquef5275482019-01-29 18:42:42 -0800166 // If true, this layer will use the dataspace chosen for the output and
167 // ignore the dataspace value just below
168 bool isColorspaceAgnostic{false};
169
Lloyd Pique0b785d82018-12-04 17:25:27 -0800170 // The dataspace for this layer
171 ui::Dataspace dataspace{ui::Dataspace::UNKNOWN};
172
173 // The metadata for this layer
174 HdrMetadata hdrMetadata;
175
176 // The color transform
177 mat4 colorTransform;
Lloyd Piquef5275482019-01-29 18:42:42 -0800178 bool colorTransformIsIdentity{true};
Lloyd Pique688abd42019-02-15 15:42:24 -0800179
Lloyd Pique688abd42019-02-15 15:42:24 -0800180 // True if the layer has protected content
181 bool hasProtectedContent{false};
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800182
183 /*
184 * Cursor state
185 */
186
187 // The output-independent frame for the cursor
188 Rect cursorFrame;
Lloyd Pique9755fb72019-03-26 14:44:40 -0700189
Lloyd Piquede196652020-01-22 17:29:58 -0800190 virtual ~LayerFECompositionState();
191
Lloyd Pique9755fb72019-03-26 14:44:40 -0700192 // Debugging
Lloyd Piquede196652020-01-22 17:29:58 -0800193 virtual void dump(std::string& out) const;
Lloyd Pique0b785d82018-12-04 17:25:27 -0800194};
195
196} // namespace android::compositionengine