blob: d3e2c253a97b2a3a4d88729434e9f0cf33031fe3 [file] [log] [blame]
Lloyd Piquecc01a452018-12-04 17:24:00 -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
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080017#include <android-base/stringprintf.h>
Lloyd Piquef5275482019-01-29 18:42:42 -080018#include <compositionengine/DisplayColorProfile.h>
Lloyd Pique9755fb72019-03-26 14:44:40 -070019#include <compositionengine/LayerFECompositionState.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080020#include <compositionengine/Output.h>
Lloyd Piquea83776c2019-01-29 18:42:32 -080021#include <compositionengine/impl/OutputCompositionState.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080022#include <compositionengine/impl/OutputLayer.h>
Lloyd Piquea83776c2019-01-29 18:42:32 -080023#include <compositionengine/impl/OutputLayerCompositionState.h>
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -040024#include <cstdint>
Lloyd Piquecc01a452018-12-04 17:24:00 -080025
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080026// TODO(b/129481165): remove the #pragma below and fix conversion issues
27#pragma clang diagnostic push
28#pragma clang diagnostic ignored "-Wconversion"
29
Lloyd Pique07e33212018-12-18 16:33:37 -080030#include "DisplayHardware/HWComposer.h"
31
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080032// TODO(b/129481165): remove the #pragma below and fix conversion issues
33#pragma clang diagnostic pop // ignored "-Wconversion"
34
Lloyd Piquecc01a452018-12-04 17:24:00 -080035namespace android::compositionengine {
36
37OutputLayer::~OutputLayer() = default;
38
39namespace impl {
40
Lloyd Piquea83776c2019-01-29 18:42:32 -080041namespace {
42
43FloatRect reduce(const FloatRect& win, const Region& exclude) {
44 if (CC_LIKELY(exclude.isEmpty())) {
45 return win;
46 }
47 // Convert through Rect (by rounding) for lack of FloatRegion
48 return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect();
49}
50
51} // namespace
52
Lloyd Piquede196652020-01-22 17:29:58 -080053std::unique_ptr<OutputLayer> createOutputLayer(const compositionengine::Output& output,
54 const sp<compositionengine::LayerFE>& layerFE) {
55 return createOutputLayerTemplated<OutputLayer>(output, layerFE);
Lloyd Piquecc01a452018-12-04 17:24:00 -080056}
57
Lloyd Piquecc01a452018-12-04 17:24:00 -080058OutputLayer::~OutputLayer() = default;
59
Lloyd Piquedf336d92019-03-07 21:38:42 -080060void OutputLayer::setHwcLayer(std::shared_ptr<HWC2::Layer> hwcLayer) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070061 auto& state = editState();
Lloyd Piquedf336d92019-03-07 21:38:42 -080062 if (hwcLayer) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070063 state.hwc.emplace(std::move(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -080064 } else {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070065 state.hwc.reset();
Lloyd Pique07e33212018-12-18 16:33:37 -080066 }
Lloyd Pique07e33212018-12-18 16:33:37 -080067}
68
Lloyd Piquea83776c2019-01-29 18:42:32 -080069Rect OutputLayer::calculateInitialCrop() const {
Lloyd Piquede196652020-01-22 17:29:58 -080070 const auto& layerState = *getLayerFE().getCompositionState();
Lloyd Piquea83776c2019-01-29 18:42:32 -080071
72 // apply the projection's clipping to the window crop in
73 // layerstack space, and convert-back to layer space.
74 // if there are no window scaling involved, this operation will map to full
75 // pixels in the buffer.
76
77 FloatRect activeCropFloat =
Lloyd Piquec6687342019-03-07 21:34:57 -080078 reduce(layerState.geomLayerBounds, layerState.transparentRegionHint);
Lloyd Piquea83776c2019-01-29 18:42:32 -080079
Marin Shalamanov6ad317c2020-07-29 23:34:07 +020080 const Rect& viewport = getOutput().getState().layerStackSpace.content;
Lloyd Piquea83776c2019-01-29 18:42:32 -080081 const ui::Transform& layerTransform = layerState.geomLayerTransform;
82 const ui::Transform& inverseLayerTransform = layerState.geomInverseLayerTransform;
83 // Transform to screen space.
84 activeCropFloat = layerTransform.transform(activeCropFloat);
85 activeCropFloat = activeCropFloat.intersect(viewport.toFloatRect());
86 // Back to layer space to work with the content crop.
87 activeCropFloat = inverseLayerTransform.transform(activeCropFloat);
88
89 // This needs to be here as transform.transform(Rect) computes the
90 // transformed rect and then takes the bounding box of the result before
91 // returning. This means
92 // transform.inverse().transform(transform.transform(Rect)) != Rect
93 // in which case we need to make sure the final rect is clipped to the
94 // display bounds.
95 Rect activeCrop{activeCropFloat};
96 if (!activeCrop.intersect(layerState.geomBufferSize, &activeCrop)) {
97 activeCrop.clear();
98 }
99 return activeCrop;
100}
101
102FloatRect OutputLayer::calculateOutputSourceCrop() const {
Lloyd Piquede196652020-01-22 17:29:58 -0800103 const auto& layerState = *getLayerFE().getCompositionState();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700104 const auto& outputState = getOutput().getState();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800105
106 if (!layerState.geomUsesSourceCrop) {
107 return {};
108 }
109
110 // the content crop is the area of the content that gets scaled to the
111 // layer's size. This is in buffer space.
112 FloatRect crop = layerState.geomContentCrop.toFloatRect();
113
114 // In addition there is a WM-specified crop we pull from our drawing state.
115 Rect activeCrop = calculateInitialCrop();
116 const Rect& bufferSize = layerState.geomBufferSize;
117
118 int winWidth = bufferSize.getWidth();
119 int winHeight = bufferSize.getHeight();
120
121 // The bufferSize for buffer state layers can be unbounded ([0, 0, -1, -1])
122 // if display frame hasn't been set and the parent is an unbounded layer.
123 if (winWidth < 0 && winHeight < 0) {
124 return crop;
125 }
126
127 // Transform the window crop to match the buffer coordinate system,
128 // which means using the inverse of the current transform set on the
129 // SurfaceFlingerConsumer.
130 uint32_t invTransform = layerState.geomBufferTransform;
131 if (layerState.geomBufferUsesDisplayInverseTransform) {
132 /*
133 * the code below applies the primary display's inverse transform to the
134 * buffer
135 */
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200136 uint32_t invTransformOrient =
137 ui::Transform::toRotationFlags(outputState.displaySpace.orientation);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800138 // calculate the inverse transform
139 if (invTransformOrient & HAL_TRANSFORM_ROT_90) {
140 invTransformOrient ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H;
141 }
142 // and apply to the current transform
143 invTransform =
144 (ui::Transform(invTransformOrient) * ui::Transform(invTransform)).getOrientation();
145 }
146
147 if (invTransform & HAL_TRANSFORM_ROT_90) {
148 // If the activeCrop has been rotate the ends are rotated but not
149 // the space itself so when transforming ends back we can't rely on
150 // a modification of the axes of rotation. To account for this we
151 // need to reorient the inverse rotation in terms of the current
152 // axes of rotation.
Marin Shalamanovcfeebd42020-05-15 15:23:49 +0200153 bool isHFlipped = (invTransform & HAL_TRANSFORM_FLIP_H) != 0;
154 bool isVFlipped = (invTransform & HAL_TRANSFORM_FLIP_V) != 0;
155 if (isHFlipped == isVFlipped) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800156 invTransform ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H;
157 }
158 std::swap(winWidth, winHeight);
159 }
160 const Rect winCrop =
161 activeCrop.transform(invTransform, bufferSize.getWidth(), bufferSize.getHeight());
162
163 // below, crop is intersected with winCrop expressed in crop's coordinate space
Marin Shalamanovcfeebd42020-05-15 15:23:49 +0200164 const float xScale = crop.getWidth() / float(winWidth);
165 const float yScale = crop.getHeight() / float(winHeight);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800166
Marin Shalamanovcfeebd42020-05-15 15:23:49 +0200167 const float insetLeft = winCrop.left * xScale;
168 const float insetTop = winCrop.top * yScale;
169 const float insetRight = (winWidth - winCrop.right) * xScale;
170 const float insetBottom = (winHeight - winCrop.bottom) * yScale;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800171
Marin Shalamanovcfeebd42020-05-15 15:23:49 +0200172 crop.left += insetLeft;
173 crop.top += insetTop;
174 crop.right -= insetRight;
175 crop.bottom -= insetBottom;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800176
177 return crop;
178}
179
180Rect OutputLayer::calculateOutputDisplayFrame() const {
Lloyd Piquede196652020-01-22 17:29:58 -0800181 const auto& layerState = *getLayerFE().getCompositionState();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700182 const auto& outputState = getOutput().getState();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800183
184 // apply the layer's transform, followed by the display's global transform
185 // here we're guaranteed that the layer's transform preserves rects
Lloyd Piquec6687342019-03-07 21:34:57 -0800186 Region activeTransparentRegion = layerState.transparentRegionHint;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800187 const ui::Transform& layerTransform = layerState.geomLayerTransform;
188 const ui::Transform& inverseLayerTransform = layerState.geomInverseLayerTransform;
189 const Rect& bufferSize = layerState.geomBufferSize;
190 Rect activeCrop = layerState.geomCrop;
191 if (!activeCrop.isEmpty() && bufferSize.isValid()) {
192 activeCrop = layerTransform.transform(activeCrop);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200193 if (!activeCrop.intersect(outputState.layerStackSpace.content, &activeCrop)) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800194 activeCrop.clear();
195 }
196 activeCrop = inverseLayerTransform.transform(activeCrop, true);
197 // This needs to be here as transform.transform(Rect) computes the
198 // transformed rect and then takes the bounding box of the result before
199 // returning. This means
200 // transform.inverse().transform(transform.transform(Rect)) != Rect
201 // in which case we need to make sure the final rect is clipped to the
202 // display bounds.
203 if (!activeCrop.intersect(bufferSize, &activeCrop)) {
204 activeCrop.clear();
205 }
206 // mark regions outside the crop as transparent
207 activeTransparentRegion.orSelf(Rect(0, 0, bufferSize.getWidth(), activeCrop.top));
208 activeTransparentRegion.orSelf(
209 Rect(0, activeCrop.bottom, bufferSize.getWidth(), bufferSize.getHeight()));
210 activeTransparentRegion.orSelf(Rect(0, activeCrop.top, activeCrop.left, activeCrop.bottom));
211 activeTransparentRegion.orSelf(
212 Rect(activeCrop.right, activeCrop.top, bufferSize.getWidth(), activeCrop.bottom));
213 }
214
215 // reduce uses a FloatRect to provide more accuracy during the
216 // transformation. We then round upon constructing 'frame'.
217 Rect frame{
218 layerTransform.transform(reduce(layerState.geomLayerBounds, activeTransparentRegion))};
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200219 if (!frame.intersect(outputState.layerStackSpace.content, &frame)) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800220 frame.clear();
221 }
222 const ui::Transform displayTransform{outputState.transform};
223
224 return displayTransform.transform(frame);
225}
226
Snild Dolkow9e217d62020-04-22 15:53:42 +0200227uint32_t OutputLayer::calculateOutputRelativeBufferTransform(
228 uint32_t internalDisplayRotationFlags) const {
Lloyd Piquede196652020-01-22 17:29:58 -0800229 const auto& layerState = *getLayerFE().getCompositionState();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700230 const auto& outputState = getOutput().getState();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800231
232 /*
233 * Transformations are applied in this order:
234 * 1) buffer orientation/flip/mirror
235 * 2) state transformation (window manager)
236 * 3) layer orientation (screen orientation)
237 * (NOTE: the matrices are multiplied in reverse order)
238 */
239 const ui::Transform& layerTransform = layerState.geomLayerTransform;
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700240 const ui::Transform displayTransform{outputState.transform};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800241 const ui::Transform bufferTransform{layerState.geomBufferTransform};
242 ui::Transform transform(displayTransform * layerTransform * bufferTransform);
243
244 if (layerState.geomBufferUsesDisplayInverseTransform) {
245 /*
Snild Dolkow9e217d62020-04-22 15:53:42 +0200246 * We must apply the internal display's inverse transform to the buffer
247 * transform, and not the one for the output this layer is on.
Lloyd Piquea83776c2019-01-29 18:42:32 -0800248 */
Snild Dolkow9e217d62020-04-22 15:53:42 +0200249 uint32_t invTransform = internalDisplayRotationFlags;
250
Lloyd Piquea83776c2019-01-29 18:42:32 -0800251 // calculate the inverse transform
252 if (invTransform & HAL_TRANSFORM_ROT_90) {
253 invTransform ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H;
254 }
255
256 /*
257 * Here we cancel out the orientation component of the WM transform.
258 * The scaling and translate components are already included in our bounds
259 * computation so it's enough to just omit it in the composition.
260 * See comment in BufferLayer::prepareClientLayer with ref to b/36727915 for why.
261 */
Lloyd Pique546a2452019-03-18 20:53:27 +0000262 transform = ui::Transform(invTransform) * displayTransform * bufferTransform;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800263 }
264
265 // this gives us only the "orientation" component of the transform
266 return transform.getOrientation();
Snild Dolkow9e217d62020-04-22 15:53:42 +0200267}
Lloyd Piquea83776c2019-01-29 18:42:32 -0800268
Snild Dolkow9e217d62020-04-22 15:53:42 +0200269void OutputLayer::updateCompositionState(
270 bool includeGeometry, bool forceClientComposition,
271 ui::Transform::RotationFlags internalDisplayRotationFlags) {
Lloyd Piquede196652020-01-22 17:29:58 -0800272 const auto* layerFEState = getLayerFE().getCompositionState();
273 if (!layerFEState) {
274 return;
275 }
276
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700277 const auto& outputState = getOutput().getState();
278 const auto& profile = *getOutput().getDisplayColorProfile();
279 auto& state = editState();
Lloyd Piquef5275482019-01-29 18:42:42 -0800280
Lloyd Piquea83776c2019-01-29 18:42:32 -0800281 if (includeGeometry) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700282 // Clear the forceClientComposition flag before it is set for any
283 // reason. Note that since it can be set by some checks below when
284 // updating the geometry state, we only clear it when updating the
285 // geometry since those conditions for forcing client composition won't
286 // go away otherwise.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700287 state.forceClientComposition = false;
Lloyd Piquefe671022019-09-24 10:43:03 -0700288
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700289 state.displayFrame = calculateOutputDisplayFrame();
290 state.sourceCrop = calculateOutputSourceCrop();
Snild Dolkow9e217d62020-04-22 15:53:42 +0200291 state.bufferTransform = static_cast<Hwc2::Transform>(
292 calculateOutputRelativeBufferTransform(internalDisplayRotationFlags));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800293
Lloyd Piquede196652020-01-22 17:29:58 -0800294 if ((layerFEState->isSecure && !outputState.isSecure) ||
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700295 (state.bufferTransform & ui::Transform::ROT_INVALID)) {
296 state.forceClientComposition = true;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800297 }
298 }
Lloyd Piquef5275482019-01-29 18:42:42 -0800299
300 // Determine the output dependent dataspace for this layer. If it is
301 // colorspace agnostic, it just uses the dataspace chosen for the output to
302 // avoid the need for color conversion.
Lloyd Piquede196652020-01-22 17:29:58 -0800303 state.dataspace = layerFEState->isColorspaceAgnostic &&
Lloyd Piquef5275482019-01-29 18:42:42 -0800304 outputState.targetDataspace != ui::Dataspace::UNKNOWN
305 ? outputState.targetDataspace
Lloyd Piquede196652020-01-22 17:29:58 -0800306 : layerFEState->dataspace;
Lloyd Piquef5275482019-01-29 18:42:42 -0800307
Lloyd Piquef5275482019-01-29 18:42:42 -0800308 // These are evaluated every frame as they can potentially change at any
309 // time.
Lloyd Piquede196652020-01-22 17:29:58 -0800310 if (layerFEState->forceClientComposition || !profile.isDataspaceSupported(state.dataspace) ||
Lloyd Pique7a234912019-10-03 11:54:27 -0700311 forceClientComposition) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700312 state.forceClientComposition = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800313 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800314}
315
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400316void OutputLayer::writeStateToHWC(bool includeGeometry, bool skipLayer, uint32_t z,
317 bool zIsOverridden, bool isPeekingThrough) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700318 const auto& state = getState();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800319 // Skip doing this if there is no HWC interface
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700320 if (!state.hwc) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800321 return;
322 }
323
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700324 auto& hwcLayer = (*state.hwc).hwcLayer;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800325 if (!hwcLayer) {
326 ALOGE("[%s] failed to write composition state to HWC -- no hwcLayer for output %s",
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700327 getLayerFE().getDebugName(), getOutput().getName().c_str());
Lloyd Piquea83776c2019-01-29 18:42:32 -0800328 return;
329 }
330
Lloyd Piquede196652020-01-22 17:29:58 -0800331 const auto* outputIndependentState = getLayerFE().getCompositionState();
332 if (!outputIndependentState) {
333 return;
334 }
335
336 auto requestedCompositionType = outputIndependentState->compositionType;
Lloyd Piquef5275482019-01-29 18:42:42 -0800337
Yichi Chen413d46a2021-04-07 21:42:09 +0800338 // TODO(b/181172795): We now update geometry for all flattened layers. We should update it
339 // only when the geometry actually changes
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400340 const bool isOverridden =
341 state.overrideInfo.buffer != nullptr || isPeekingThrough || zIsOverridden;
Yichi Chen413d46a2021-04-07 21:42:09 +0800342 const bool prevOverridden = state.hwc->stateOverridden;
343 if (isOverridden || prevOverridden || skipLayer || includeGeometry) {
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400344 writeOutputDependentGeometryStateToHWC(hwcLayer.get(), requestedCompositionType, z);
Dan Stoza6166c312021-01-15 16:34:05 -0800345 writeOutputIndependentGeometryStateToHWC(hwcLayer.get(), *outputIndependentState,
346 skipLayer);
Lloyd Piquef5275482019-01-29 18:42:42 -0800347 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800348
Lloyd Piquef5275482019-01-29 18:42:42 -0800349 writeOutputDependentPerFrameStateToHWC(hwcLayer.get());
Lloyd Piquede196652020-01-22 17:29:58 -0800350 writeOutputIndependentPerFrameStateToHWC(hwcLayer.get(), *outputIndependentState);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800351
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400352 writeCompositionTypeToHWC(hwcLayer.get(), requestedCompositionType, isPeekingThrough);
Lloyd Pique46b72df2019-10-29 13:19:27 -0700353
354 // Always set the layer color after setting the composition type.
Lloyd Piquede196652020-01-22 17:29:58 -0800355 writeSolidColorStateToHWC(hwcLayer.get(), *outputIndependentState);
Yichi Chen413d46a2021-04-07 21:42:09 +0800356
357 editState().hwc->stateOverridden = isOverridden;
Lloyd Piquef5275482019-01-29 18:42:42 -0800358}
Lloyd Piquea83776c2019-01-29 18:42:32 -0800359
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400360void OutputLayer::writeOutputDependentGeometryStateToHWC(HWC2::Layer* hwcLayer,
361 hal::Composition requestedCompositionType,
362 uint32_t z) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800363 const auto& outputDependentState = getState();
364
Dan Stoza6166c312021-01-15 16:34:05 -0800365 Rect displayFrame = outputDependentState.displayFrame;
366 FloatRect sourceCrop = outputDependentState.sourceCrop;
Huihong Luoa5825112021-03-24 12:28:29 -0700367
Alec Mouri464352b2021-03-24 16:33:21 -0700368 if (outputDependentState.overrideInfo.buffer != nullptr) {
Dan Stoza6166c312021-01-15 16:34:05 -0800369 displayFrame = outputDependentState.overrideInfo.displayFrame;
370 sourceCrop = displayFrame.toFloatRect();
Lloyd Piquef5275482019-01-29 18:42:42 -0800371 }
372
Dan Stoza6166c312021-01-15 16:34:05 -0800373 ALOGV("Writing display frame [%d, %d, %d, %d]", displayFrame.left, displayFrame.top,
374 displayFrame.right, displayFrame.bottom);
375
376 if (auto error = hwcLayer->setDisplayFrame(displayFrame); error != hal::Error::NONE) {
377 ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)",
378 getLayerFE().getDebugName(), displayFrame.left, displayFrame.top, displayFrame.right,
379 displayFrame.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
380 }
381
382 if (auto error = hwcLayer->setSourceCrop(sourceCrop); error != hal::Error::NONE) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800383 ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: "
384 "%s (%d)",
Dan Stoza6166c312021-01-15 16:34:05 -0800385 getLayerFE().getDebugName(), sourceCrop.left, sourceCrop.top, sourceCrop.right,
386 sourceCrop.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800387 }
388
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400389 if (auto error = hwcLayer->setZOrder(z); error != hal::Error::NONE) {
390 ALOGE("[%s] Failed to set Z %u: %s (%d)", getLayerFE().getDebugName(), z,
391 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800392 }
393
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700394 // Solid-color layers and overridden buffers should always use an identity transform.
395 const auto bufferTransform = (requestedCompositionType != hal::Composition::SOLID_COLOR &&
396 getState().overrideInfo.buffer == nullptr)
Lloyd Piquef5275482019-01-29 18:42:42 -0800397 ? outputDependentState.bufferTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700398 : static_cast<hal::Transform>(0);
399 if (auto error = hwcLayer->setTransform(static_cast<hal::Transform>(bufferTransform));
400 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700401 ALOGE("[%s] Failed to set transform %s: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800402 toString(outputDependentState.bufferTransform).c_str(), to_string(error).c_str(),
403 static_cast<int32_t>(error));
404 }
405}
406
407void OutputLayer::writeOutputIndependentGeometryStateToHWC(
Dan Stoza6166c312021-01-15 16:34:05 -0800408 HWC2::Layer* hwcLayer, const LayerFECompositionState& outputIndependentState,
409 bool skipLayer) {
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400410 // If there is a peekThroughLayer, then this layer has a hole in it. We need to use
411 // PREMULTIPLIED so it will peek through.
412 const auto& overrideInfo = getState().overrideInfo;
413 const auto blendMode = overrideInfo.buffer || overrideInfo.peekThroughLayer
Alec Mouriee69a592021-03-23 15:00:45 -0700414 ? hardware::graphics::composer::hal::BlendMode::PREMULTIPLIED
415 : outputIndependentState.blendMode;
416 if (auto error = hwcLayer->setBlendMode(blendMode); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700417 ALOGE("[%s] Failed to set blend mode %s: %s (%d)", getLayerFE().getDebugName(),
Alec Mouriee69a592021-03-23 15:00:45 -0700418 toString(blendMode).c_str(), to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800419 }
420
Alec Mouriee69a592021-03-23 15:00:45 -0700421 const float alpha = skipLayer
422 ? 0.0f
423 : (getState().overrideInfo.buffer ? 1.0f : outputIndependentState.alpha);
Dan Stoza6166c312021-01-15 16:34:05 -0800424 ALOGV("Writing alpha %f", alpha);
425
426 if (auto error = hwcLayer->setPlaneAlpha(alpha); error != hal::Error::NONE) {
427 ALOGE("[%s] Failed to set plane alpha %.3f: %s (%d)", getLayerFE().getDebugName(), alpha,
428 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800429 }
430
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800431 for (const auto& [name, entry] : outputIndependentState.metadata) {
432 if (auto error = hwcLayer->setLayerGenericMetadata(name, entry.mandatory, entry.value);
Peiyong Line9d809e2020-04-14 13:10:48 -0700433 error != hal::Error::NONE) {
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800434 ALOGE("[%s] Failed to set generic metadata %s %s (%d)", getLayerFE().getDebugName(),
435 name.c_str(), to_string(error).c_str(), static_cast<int32_t>(error));
436 }
437 }
Lloyd Piquef5275482019-01-29 18:42:42 -0800438}
439
440void OutputLayer::writeOutputDependentPerFrameStateToHWC(HWC2::Layer* hwcLayer) {
441 const auto& outputDependentState = getState();
442
Lloyd Piquea2468662019-03-07 21:31:06 -0800443 // TODO(lpique): b/121291683 outputSpaceVisibleRegion is output-dependent geometry
Lloyd Piquef5275482019-01-29 18:42:42 -0800444 // state and should not change every frame.
Alec Mouri464352b2021-03-24 16:33:21 -0700445 Region visibleRegion = outputDependentState.overrideInfo.buffer
446 ? Region(outputDependentState.overrideInfo.visibleRegion)
447 : outputDependentState.outputSpaceVisibleRegion;
448 if (auto error = hwcLayer->setVisibleRegion(visibleRegion); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700449 ALOGE("[%s] Failed to set visible region: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800450 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquea2468662019-03-07 21:31:06 -0800451 outputDependentState.outputSpaceVisibleRegion.dump(LOG_TAG);
Lloyd Piquef5275482019-01-29 18:42:42 -0800452 }
453
Alec Mourib7edfc22021-03-17 16:20:26 -0700454 const auto dataspace = outputDependentState.overrideInfo.buffer
455 ? outputDependentState.overrideInfo.dataspace
456 : outputDependentState.dataspace;
457
458 if (auto error = hwcLayer->setDataspace(dataspace); error != hal::Error::NONE) {
459 ALOGE("[%s] Failed to set dataspace %d: %s (%d)", getLayerFE().getDebugName(), dataspace,
460 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800461 }
462}
463
464void OutputLayer::writeOutputIndependentPerFrameStateToHWC(
465 HWC2::Layer* hwcLayer, const LayerFECompositionState& outputIndependentState) {
466 switch (auto error = hwcLayer->setColorTransform(outputIndependentState.colorTransform)) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700467 case hal::Error::NONE:
Lloyd Piquef5275482019-01-29 18:42:42 -0800468 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700469 case hal::Error::UNSUPPORTED:
Lloyd Piquef5275482019-01-29 18:42:42 -0800470 editState().forceClientComposition = true;
471 break;
472 default:
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700473 ALOGE("[%s] Failed to set color transform: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquea83776c2019-01-29 18:42:32 -0800474 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800475 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800476
Alec Mouri464352b2021-03-24 16:33:21 -0700477 const Region& surfaceDamage = getState().overrideInfo.buffer
478 ? getState().overrideInfo.damageRegion
479 : outputIndependentState.surfaceDamage;
480
481 if (auto error = hwcLayer->setSurfaceDamage(surfaceDamage); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700482 ALOGE("[%s] Failed to set surface damage: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800483 to_string(error).c_str(), static_cast<int32_t>(error));
484 outputIndependentState.surfaceDamage.dump(LOG_TAG);
485 }
486
487 // Content-specific per-frame state
488 switch (outputIndependentState.compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700489 case hal::Composition::SOLID_COLOR:
Lloyd Pique46b72df2019-10-29 13:19:27 -0700490 // For compatibility, should be written AFTER the composition type.
Lloyd Piquef5275482019-01-29 18:42:42 -0800491 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700492 case hal::Composition::SIDEBAND:
Lloyd Piquef5275482019-01-29 18:42:42 -0800493 writeSidebandStateToHWC(hwcLayer, outputIndependentState);
494 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700495 case hal::Composition::CURSOR:
496 case hal::Composition::DEVICE:
Lloyd Piquef5275482019-01-29 18:42:42 -0800497 writeBufferStateToHWC(hwcLayer, outputIndependentState);
498 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700499 case hal::Composition::INVALID:
500 case hal::Composition::CLIENT:
Lloyd Piquef5275482019-01-29 18:42:42 -0800501 // Ignored
502 break;
503 }
504}
505
506void OutputLayer::writeSolidColorStateToHWC(HWC2::Layer* hwcLayer,
507 const LayerFECompositionState& outputIndependentState) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700508 if (outputIndependentState.compositionType != hal::Composition::SOLID_COLOR) {
Lloyd Pique46b72df2019-10-29 13:19:27 -0700509 return;
510 }
511
Peiyong Line9d809e2020-04-14 13:10:48 -0700512 hal::Color color = {static_cast<uint8_t>(std::round(255.0f * outputIndependentState.color.r)),
513 static_cast<uint8_t>(std::round(255.0f * outputIndependentState.color.g)),
514 static_cast<uint8_t>(std::round(255.0f * outputIndependentState.color.b)),
515 255};
Lloyd Piquef5275482019-01-29 18:42:42 -0800516
Peiyong Line9d809e2020-04-14 13:10:48 -0700517 if (auto error = hwcLayer->setColor(color); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700518 ALOGE("[%s] Failed to set color: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800519 to_string(error).c_str(), static_cast<int32_t>(error));
520 }
521}
522
523void OutputLayer::writeSidebandStateToHWC(HWC2::Layer* hwcLayer,
524 const LayerFECompositionState& outputIndependentState) {
525 if (auto error = hwcLayer->setSidebandStream(outputIndependentState.sidebandStream->handle());
Peiyong Line9d809e2020-04-14 13:10:48 -0700526 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700527 ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800528 outputIndependentState.sidebandStream->handle(), to_string(error).c_str(),
529 static_cast<int32_t>(error));
530 }
531}
532
533void OutputLayer::writeBufferStateToHWC(HWC2::Layer* hwcLayer,
534 const LayerFECompositionState& outputIndependentState) {
535 auto supportedPerFrameMetadata =
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700536 getOutput().getDisplayColorProfile()->getSupportedPerFrameMetadata();
Lloyd Piquef5275482019-01-29 18:42:42 -0800537 if (auto error = hwcLayer->setPerFrameMetadata(supportedPerFrameMetadata,
538 outputIndependentState.hdrMetadata);
Peiyong Line9d809e2020-04-14 13:10:48 -0700539 error != hal::Error::NONE && error != hal::Error::UNSUPPORTED) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700540 ALOGE("[%s] Failed to set hdrMetadata: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800541 to_string(error).c_str(), static_cast<int32_t>(error));
542 }
543
Dan Stoza6166c312021-01-15 16:34:05 -0800544 sp<GraphicBuffer> buffer = outputIndependentState.buffer;
545 sp<Fence> acquireFence = outputIndependentState.acquireFence;
546 if (getState().overrideInfo.buffer != nullptr) {
Alec Mouria90a5702021-04-16 16:36:21 +0000547 buffer = getState().overrideInfo.buffer->getBuffer();
Dan Stoza6166c312021-01-15 16:34:05 -0800548 acquireFence = getState().overrideInfo.acquireFence;
549 }
550
551 ALOGV("Writing buffer %p", buffer.get());
552
Lloyd Piquef5275482019-01-29 18:42:42 -0800553 uint32_t hwcSlot = 0;
554 sp<GraphicBuffer> hwcBuffer;
555 // We need access to the output-dependent state for the buffer cache there,
556 // though otherwise the buffer is not output-dependent.
Dan Stoza6166c312021-01-15 16:34:05 -0800557 editState().hwc->hwcBufferCache.getHwcBuffer(outputIndependentState.bufferSlot, buffer,
558 &hwcSlot, &hwcBuffer);
Lloyd Piquef5275482019-01-29 18:42:42 -0800559
Dan Stoza6166c312021-01-15 16:34:05 -0800560 if (auto error = hwcLayer->setBuffer(hwcSlot, hwcBuffer, acquireFence);
Peiyong Line9d809e2020-04-14 13:10:48 -0700561 error != hal::Error::NONE) {
Dan Stoza6166c312021-01-15 16:34:05 -0800562 ALOGE("[%s] Failed to set buffer %p: %s (%d)", getLayerFE().getDebugName(), buffer->handle,
563 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800564 }
565}
566
Peiyong Line9d809e2020-04-14 13:10:48 -0700567void OutputLayer::writeCompositionTypeToHWC(HWC2::Layer* hwcLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400568 hal::Composition requestedCompositionType,
569 bool isPeekingThrough) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800570 auto& outputDependentState = editState();
571
572 // If we are forcing client composition, we need to tell the HWC
Leon Scroggins IIId305ef22021-04-06 09:53:26 -0400573 if (outputDependentState.forceClientComposition ||
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400574 (!isPeekingThrough && getLayerFE().hasRoundedCorners())) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700575 requestedCompositionType = hal::Composition::CLIENT;
Lloyd Piquef5275482019-01-29 18:42:42 -0800576 }
577
578 // Set the requested composition type with the HWC whenever it changes
579 if (outputDependentState.hwc->hwcCompositionType != requestedCompositionType) {
580 outputDependentState.hwc->hwcCompositionType = requestedCompositionType;
581
Peiyong Line9d809e2020-04-14 13:10:48 -0700582 if (auto error = hwcLayer->setCompositionType(requestedCompositionType);
583 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700584 ALOGE("[%s] Failed to set composition type %s: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800585 toString(requestedCompositionType).c_str(), to_string(error).c_str(),
Lloyd Piquea83776c2019-01-29 18:42:32 -0800586 static_cast<int32_t>(error));
587 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800588 }
589}
590
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800591void OutputLayer::writeCursorPositionToHWC() const {
592 // Skip doing this if there is no HWC interface
593 auto hwcLayer = getHwcLayer();
594 if (!hwcLayer) {
595 return;
596 }
597
Lloyd Piquede196652020-01-22 17:29:58 -0800598 const auto* layerFEState = getLayerFE().getCompositionState();
599 if (!layerFEState) {
600 return;
601 }
602
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700603 const auto& outputState = getOutput().getState();
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800604
Lloyd Piquede196652020-01-22 17:29:58 -0800605 Rect frame = layerFEState->cursorFrame;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200606 frame.intersect(outputState.layerStackSpace.content, &frame);
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800607 Rect position = outputState.transform.transform(frame);
608
609 if (auto error = hwcLayer->setCursorPosition(position.left, position.top);
Peiyong Line9d809e2020-04-14 13:10:48 -0700610 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700611 ALOGE("[%s] Failed to set cursor position to (%d, %d): %s (%d)",
612 getLayerFE().getDebugName(), position.left, position.top, to_string(error).c_str(),
613 static_cast<int32_t>(error));
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800614 }
615}
616
Lloyd Pique66d68602019-02-13 14:23:31 -0800617HWC2::Layer* OutputLayer::getHwcLayer() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700618 const auto& state = getState();
619 return state.hwc ? state.hwc->hwcLayer.get() : nullptr;
Lloyd Pique66d68602019-02-13 14:23:31 -0800620}
621
622bool OutputLayer::requiresClientComposition() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700623 const auto& state = getState();
Peiyong Line9d809e2020-04-14 13:10:48 -0700624 return !state.hwc || state.hwc->hwcCompositionType == hal::Composition::CLIENT;
Lloyd Pique66d68602019-02-13 14:23:31 -0800625}
626
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800627bool OutputLayer::isHardwareCursor() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700628 const auto& state = getState();
Peiyong Line9d809e2020-04-14 13:10:48 -0700629 return state.hwc && state.hwc->hwcCompositionType == hal::Composition::CURSOR;
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800630}
631
Peiyong Line9d809e2020-04-14 13:10:48 -0700632void OutputLayer::detectDisallowedCompositionTypeChange(hal::Composition from,
633 hal::Composition to) const {
Lloyd Pique66d68602019-02-13 14:23:31 -0800634 bool result = false;
635 switch (from) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700636 case hal::Composition::INVALID:
637 case hal::Composition::CLIENT:
Lloyd Pique66d68602019-02-13 14:23:31 -0800638 result = false;
639 break;
640
Peiyong Line9d809e2020-04-14 13:10:48 -0700641 case hal::Composition::DEVICE:
642 case hal::Composition::SOLID_COLOR:
643 result = (to == hal::Composition::CLIENT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800644 break;
645
Peiyong Line9d809e2020-04-14 13:10:48 -0700646 case hal::Composition::CURSOR:
647 case hal::Composition::SIDEBAND:
648 result = (to == hal::Composition::CLIENT || to == hal::Composition::DEVICE);
Lloyd Pique66d68602019-02-13 14:23:31 -0800649 break;
650 }
651
652 if (!result) {
653 ALOGE("[%s] Invalid device requested composition type change: %s (%d) --> %s (%d)",
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700654 getLayerFE().getDebugName(), toString(from).c_str(), static_cast<int>(from),
Lloyd Pique66d68602019-02-13 14:23:31 -0800655 toString(to).c_str(), static_cast<int>(to));
656 }
657}
658
Peiyong Line9d809e2020-04-14 13:10:48 -0700659void OutputLayer::applyDeviceCompositionTypeChange(hal::Composition compositionType) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700660 auto& state = editState();
661 LOG_FATAL_IF(!state.hwc);
662 auto& hwcState = *state.hwc;
Lloyd Pique66d68602019-02-13 14:23:31 -0800663
664 detectDisallowedCompositionTypeChange(hwcState.hwcCompositionType, compositionType);
665
666 hwcState.hwcCompositionType = compositionType;
667}
668
669void OutputLayer::prepareForDeviceLayerRequests() {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700670 auto& state = editState();
671 state.clearClientTarget = false;
Lloyd Pique66d68602019-02-13 14:23:31 -0800672}
673
Peiyong Line9d809e2020-04-14 13:10:48 -0700674void OutputLayer::applyDeviceLayerRequest(hal::LayerRequest request) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700675 auto& state = editState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800676 switch (request) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700677 case hal::LayerRequest::CLEAR_CLIENT_TARGET:
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700678 state.clearClientTarget = true;
Lloyd Pique66d68602019-02-13 14:23:31 -0800679 break;
680
681 default:
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700682 ALOGE("[%s] Unknown device layer request %s (%d)", getLayerFE().getDebugName(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800683 toString(request).c_str(), static_cast<int>(request));
684 break;
685 }
686}
687
Lloyd Pique688abd42019-02-15 15:42:24 -0800688bool OutputLayer::needsFiltering() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700689 const auto& state = getState();
690 const auto& displayFrame = state.displayFrame;
691 const auto& sourceCrop = state.sourceCrop;
Lloyd Pique688abd42019-02-15 15:42:24 -0800692 return sourceCrop.getHeight() != displayFrame.getHeight() ||
693 sourceCrop.getWidth() != displayFrame.getWidth();
694}
695
Dan Stoza6166c312021-01-15 16:34:05 -0800696std::vector<LayerFE::LayerSettings> OutputLayer::getOverrideCompositionList() const {
697 if (getState().overrideInfo.buffer == nullptr) {
698 return {};
699 }
700
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700701 // Compute the geometry boundaries in layer stack space: we need to transform from the
702 // framebuffer space of the override buffer to layer space.
703 const ProjectionSpace& layerSpace = getOutput().getState().layerStackSpace;
704 const ui::Transform transform = getState().overrideInfo.displaySpace.getTransform(layerSpace);
705 const Rect boundaries = transform.transform(getState().overrideInfo.displayFrame);
706
Dan Stoza6166c312021-01-15 16:34:05 -0800707 LayerFE::LayerSettings settings;
708 settings.geometry = renderengine::Geometry{
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700709 .boundaries = boundaries.toFloatRect(),
Dan Stoza6166c312021-01-15 16:34:05 -0800710 };
Alec Mouria90a5702021-04-16 16:36:21 +0000711 settings.bufferId = getState().overrideInfo.buffer->getBuffer()->getId();
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700712 settings.source = renderengine::PixelSource{
713 .buffer = renderengine::Buffer{
714 .buffer = getState().overrideInfo.buffer,
715 .fence = getState().overrideInfo.acquireFence,
716 // If the transform from layer space to display space contains a rotation, we
717 // need to undo the rotation in the texture transform
718 .textureTransform =
719 ui::Transform(transform.inverse().getOrientation(), 1, 1).asMatrix4(),
720 }};
Alec Mouri9c8fce02021-03-12 18:30:42 -0800721 settings.sourceDataspace = getState().overrideInfo.dataspace;
Dan Stoza6166c312021-01-15 16:34:05 -0800722 settings.alpha = 1.0f;
723
724 return {static_cast<LayerFE::LayerSettings>(settings)};
725}
726
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800727void OutputLayer::dump(std::string& out) const {
728 using android::base::StringAppendF;
729
Lloyd Piquede196652020-01-22 17:29:58 -0800730 StringAppendF(&out, " - Output Layer %p(%s)\n", this, getLayerFE().getDebugName());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700731 dumpState(out);
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800732}
733
Lloyd Piquecc01a452018-12-04 17:24:00 -0800734} // namespace impl
735} // namespace android::compositionengine