blob: c21e7d19609664851fdcb279f3863efef043fa29 [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 */
Brian Lindahl1a4ffd82024-10-30 11:00:37 -060016
Alec Mourid1bf1b52021-05-05 18:44:58 -070017#include <DisplayHardware/Hal.h>
Lloyd Pique37c2c9b2018-12-04 17:25:10 -080018#include <android-base/stringprintf.h>
Lloyd Piquef5275482019-01-29 18:42:42 -080019#include <compositionengine/DisplayColorProfile.h>
Lloyd Pique9755fb72019-03-26 14:44:40 -070020#include <compositionengine/LayerFECompositionState.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080021#include <compositionengine/Output.h>
Pierre-Hugues Husson17486262020-05-25 10:12:24 +000022#include <compositionengine/UdfpsExtension.h>
Alec Mourie7cc1c22021-04-27 15:23:26 -070023#include <compositionengine/impl/HwcBufferCache.h>
Lloyd Piquea83776c2019-01-29 18:42:32 -080024#include <compositionengine/impl/OutputCompositionState.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080025#include <compositionengine/impl/OutputLayer.h>
Lloyd Piquea83776c2019-01-29 18:42:32 -080026#include <compositionengine/impl/OutputLayerCompositionState.h>
Brian Lindahl1a4ffd82024-10-30 11:00:37 -060027#include <ui/FloatRect.h>
28#include <ui/HdrRenderTypeUtils.h>
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -040029#include <cstdint>
Alec Mouri8face532024-11-09 22:15:32 +000030#include <limits>
Alec Mouricdf6cbc2021-11-01 17:21:15 -070031#include "system/graphics-base-v1.0.h"
32
Brian Lindahl1a4ffd82024-10-30 11:00:37 -060033#include <com_android_graphics_libgui_flags.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080034
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080035// TODO(b/129481165): remove the #pragma below and fix conversion issues
36#pragma clang diagnostic push
37#pragma clang diagnostic ignored "-Wconversion"
38
Lloyd Pique07e33212018-12-18 16:33:37 -080039#include "DisplayHardware/HWComposer.h"
40
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080041// TODO(b/129481165): remove the #pragma below and fix conversion issues
42#pragma clang diagnostic pop // ignored "-Wconversion"
43
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050044using aidl::android::hardware::graphics::composer3::Composition;
Sally Qi0abc4a52024-09-26 16:13:06 -070045using aidl::android::hardware::graphics::composer3::Luts;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -050046
Lloyd Piquecc01a452018-12-04 17:24:00 -080047namespace android::compositionengine {
48
49OutputLayer::~OutputLayer() = default;
50
51namespace impl {
52
Lloyd Piquea83776c2019-01-29 18:42:32 -080053namespace {
54
55FloatRect reduce(const FloatRect& win, const Region& exclude) {
56 if (CC_LIKELY(exclude.isEmpty())) {
57 return win;
58 }
59 // Convert through Rect (by rounding) for lack of FloatRegion
60 return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect();
61}
62
63} // namespace
64
Lloyd Piquede196652020-01-22 17:29:58 -080065std::unique_ptr<OutputLayer> createOutputLayer(const compositionengine::Output& output,
66 const sp<compositionengine::LayerFE>& layerFE) {
67 return createOutputLayerTemplated<OutputLayer>(output, layerFE);
Lloyd Piquecc01a452018-12-04 17:24:00 -080068}
69
Lloyd Piquecc01a452018-12-04 17:24:00 -080070OutputLayer::~OutputLayer() = default;
71
Lloyd Piquedf336d92019-03-07 21:38:42 -080072void OutputLayer::setHwcLayer(std::shared_ptr<HWC2::Layer> hwcLayer) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070073 auto& state = editState();
Lloyd Piquedf336d92019-03-07 21:38:42 -080074 if (hwcLayer) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070075 state.hwc.emplace(std::move(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -080076 } else {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070077 state.hwc.reset();
Lloyd Pique07e33212018-12-18 16:33:37 -080078 }
Lloyd Pique07e33212018-12-18 16:33:37 -080079}
80
Lloyd Piquea83776c2019-01-29 18:42:32 -080081Rect OutputLayer::calculateInitialCrop() const {
Lloyd Piquede196652020-01-22 17:29:58 -080082 const auto& layerState = *getLayerFE().getCompositionState();
Lloyd Piquea83776c2019-01-29 18:42:32 -080083
84 // apply the projection's clipping to the window crop in
85 // layerstack space, and convert-back to layer space.
86 // if there are no window scaling involved, this operation will map to full
87 // pixels in the buffer.
88
89 FloatRect activeCropFloat =
Lloyd Piquec6687342019-03-07 21:34:57 -080090 reduce(layerState.geomLayerBounds, layerState.transparentRegionHint);
Lloyd Piquea83776c2019-01-29 18:42:32 -080091
Angel Aguayob084e0c2021-08-04 23:27:28 +000092 const Rect& viewport = getOutput().getState().layerStackSpace.getContent();
Lloyd Piquea83776c2019-01-29 18:42:32 -080093 const ui::Transform& layerTransform = layerState.geomLayerTransform;
94 const ui::Transform& inverseLayerTransform = layerState.geomInverseLayerTransform;
95 // Transform to screen space.
96 activeCropFloat = layerTransform.transform(activeCropFloat);
97 activeCropFloat = activeCropFloat.intersect(viewport.toFloatRect());
98 // Back to layer space to work with the content crop.
99 activeCropFloat = inverseLayerTransform.transform(activeCropFloat);
100
101 // This needs to be here as transform.transform(Rect) computes the
102 // transformed rect and then takes the bounding box of the result before
103 // returning. This means
104 // transform.inverse().transform(transform.transform(Rect)) != Rect
105 // in which case we need to make sure the final rect is clipped to the
106 // display bounds.
107 Rect activeCrop{activeCropFloat};
108 if (!activeCrop.intersect(layerState.geomBufferSize, &activeCrop)) {
109 activeCrop.clear();
110 }
111 return activeCrop;
112}
113
ramindani2c043be2022-04-19 20:11:10 +0000114FloatRect OutputLayer::calculateOutputSourceCrop(uint32_t internalDisplayRotationFlags) const {
Lloyd Piquede196652020-01-22 17:29:58 -0800115 const auto& layerState = *getLayerFE().getCompositionState();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800116
117 if (!layerState.geomUsesSourceCrop) {
118 return {};
119 }
120
121 // the content crop is the area of the content that gets scaled to the
122 // layer's size. This is in buffer space.
123 FloatRect crop = layerState.geomContentCrop.toFloatRect();
124
125 // In addition there is a WM-specified crop we pull from our drawing state.
126 Rect activeCrop = calculateInitialCrop();
127 const Rect& bufferSize = layerState.geomBufferSize;
128
129 int winWidth = bufferSize.getWidth();
130 int winHeight = bufferSize.getHeight();
131
132 // The bufferSize for buffer state layers can be unbounded ([0, 0, -1, -1])
133 // if display frame hasn't been set and the parent is an unbounded layer.
134 if (winWidth < 0 && winHeight < 0) {
135 return crop;
136 }
137
138 // Transform the window crop to match the buffer coordinate system,
139 // which means using the inverse of the current transform set on the
140 // SurfaceFlingerConsumer.
141 uint32_t invTransform = layerState.geomBufferTransform;
142 if (layerState.geomBufferUsesDisplayInverseTransform) {
143 /*
144 * the code below applies the primary display's inverse transform to the
145 * buffer
146 */
ramindani2c043be2022-04-19 20:11:10 +0000147 uint32_t invTransformOrient = internalDisplayRotationFlags;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800148 // calculate the inverse transform
149 if (invTransformOrient & HAL_TRANSFORM_ROT_90) {
150 invTransformOrient ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H;
151 }
152 // and apply to the current transform
153 invTransform =
154 (ui::Transform(invTransformOrient) * ui::Transform(invTransform)).getOrientation();
155 }
156
157 if (invTransform & HAL_TRANSFORM_ROT_90) {
158 // If the activeCrop has been rotate the ends are rotated but not
159 // the space itself so when transforming ends back we can't rely on
160 // a modification of the axes of rotation. To account for this we
161 // need to reorient the inverse rotation in terms of the current
162 // axes of rotation.
Marin Shalamanovcfeebd42020-05-15 15:23:49 +0200163 bool isHFlipped = (invTransform & HAL_TRANSFORM_FLIP_H) != 0;
164 bool isVFlipped = (invTransform & HAL_TRANSFORM_FLIP_V) != 0;
165 if (isHFlipped == isVFlipped) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800166 invTransform ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H;
167 }
168 std::swap(winWidth, winHeight);
169 }
170 const Rect winCrop =
171 activeCrop.transform(invTransform, bufferSize.getWidth(), bufferSize.getHeight());
172
173 // below, crop is intersected with winCrop expressed in crop's coordinate space
Marin Shalamanovcfeebd42020-05-15 15:23:49 +0200174 const float xScale = crop.getWidth() / float(winWidth);
175 const float yScale = crop.getHeight() / float(winHeight);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800176
Marin Shalamanovcfeebd42020-05-15 15:23:49 +0200177 const float insetLeft = winCrop.left * xScale;
178 const float insetTop = winCrop.top * yScale;
179 const float insetRight = (winWidth - winCrop.right) * xScale;
180 const float insetBottom = (winHeight - winCrop.bottom) * yScale;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800181
Marin Shalamanovcfeebd42020-05-15 15:23:49 +0200182 crop.left += insetLeft;
183 crop.top += insetTop;
184 crop.right -= insetRight;
185 crop.bottom -= insetBottom;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800186
187 return crop;
188}
189
190Rect OutputLayer::calculateOutputDisplayFrame() const {
Lloyd Piquede196652020-01-22 17:29:58 -0800191 const auto& layerState = *getLayerFE().getCompositionState();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700192 const auto& outputState = getOutput().getState();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800193
Vishnu Naira9123c82024-10-03 03:56:44 +0000194 // Convert from layer space to layerStackSpace
Lloyd Piquea83776c2019-01-29 18:42:32 -0800195 // apply the layer's transform, followed by the display's global transform
196 // here we're guaranteed that the layer's transform preserves rects
Lloyd Piquea83776c2019-01-29 18:42:32 -0800197 const ui::Transform& layerTransform = layerState.geomLayerTransform;
Vishnu Naira9123c82024-10-03 03:56:44 +0000198 Region activeTransparentRegion = layerTransform.transform(layerState.transparentRegionHint);
199 if (!layerState.geomCrop.isEmpty() && layerState.geomBufferSize.isValid()) {
200 FloatRect activeCrop = layerTransform.transform(layerState.geomCrop);
201 activeCrop = activeCrop.intersect(outputState.layerStackSpace.getContent().toFloatRect());
202 const FloatRect& bufferSize =
203 layerTransform.transform(layerState.geomBufferSize.toFloatRect());
204 activeCrop = activeCrop.intersect(bufferSize);
205
Lloyd Piquea83776c2019-01-29 18:42:32 -0800206 // mark regions outside the crop as transparent
Vishnu Naira9123c82024-10-03 03:56:44 +0000207 Rect topRegion = Rect(layerTransform.transform(
208 FloatRect(0, 0, layerState.geomBufferSize.getWidth(), layerState.geomCrop.top)));
209 Rect bottomRegion = Rect(layerTransform.transform(
210 FloatRect(0, layerState.geomCrop.bottom, layerState.geomBufferSize.getWidth(),
211 layerState.geomBufferSize.getHeight())));
212 Rect leftRegion = Rect(layerTransform.transform(FloatRect(0, layerState.geomCrop.top,
213 layerState.geomCrop.left,
214 layerState.geomCrop.bottom)));
215 Rect rightRegion = Rect(layerTransform.transform(
216 FloatRect(layerState.geomCrop.right, layerState.geomCrop.top,
217 layerState.geomBufferSize.getWidth(), layerState.geomCrop.bottom)));
218
219 activeTransparentRegion.orSelf(topRegion);
220 activeTransparentRegion.orSelf(bottomRegion);
221 activeTransparentRegion.orSelf(leftRegion);
222 activeTransparentRegion.orSelf(rightRegion);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800223 }
224
225 // reduce uses a FloatRect to provide more accuracy during the
226 // transformation. We then round upon constructing 'frame'.
Leon Scroggins IIId394d3c2021-06-24 11:30:32 -0400227 FloatRect geomLayerBounds = layerState.geomLayerBounds;
228
229 // Some HWCs may clip client composited input to its displayFrame. Make sure
230 // that this does not cut off the shadow.
Vishnu Naird9e4f462023-10-06 04:05:45 +0000231 if (layerState.forceClientComposition && layerState.shadowSettings.length > 0.0f) {
Alec Mourida128512024-09-28 23:46:58 +0000232 // RenderEngine currently blurs shadows to smooth out edges, so outset by
233 // 2x the length instead of 1x to compensate
234 const auto outset = layerState.shadowSettings.length * 2;
Leon Scroggins IIId394d3c2021-06-24 11:30:32 -0400235 geomLayerBounds.left -= outset;
236 geomLayerBounds.top -= outset;
237 geomLayerBounds.right += outset;
238 geomLayerBounds.bottom += outset;
239 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800240
Vishnu Naira9123c82024-10-03 03:56:44 +0000241 geomLayerBounds = layerTransform.transform(geomLayerBounds);
242 FloatRect frame = reduce(geomLayerBounds, activeTransparentRegion);
243 frame = frame.intersect(outputState.layerStackSpace.getContent().toFloatRect());
244
245 // convert from layerStackSpace to displaySpace
246 const ui::Transform displayTransform{outputState.transform};
247 return Rect(displayTransform.transform(frame));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800248}
249
Snild Dolkow9e217d62020-04-22 15:53:42 +0200250uint32_t OutputLayer::calculateOutputRelativeBufferTransform(
251 uint32_t internalDisplayRotationFlags) const {
Lloyd Piquede196652020-01-22 17:29:58 -0800252 const auto& layerState = *getLayerFE().getCompositionState();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700253 const auto& outputState = getOutput().getState();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800254
255 /*
256 * Transformations are applied in this order:
257 * 1) buffer orientation/flip/mirror
258 * 2) state transformation (window manager)
259 * 3) layer orientation (screen orientation)
260 * (NOTE: the matrices are multiplied in reverse order)
261 */
262 const ui::Transform& layerTransform = layerState.geomLayerTransform;
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700263 const ui::Transform displayTransform{outputState.transform};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800264 const ui::Transform bufferTransform{layerState.geomBufferTransform};
265 ui::Transform transform(displayTransform * layerTransform * bufferTransform);
266
267 if (layerState.geomBufferUsesDisplayInverseTransform) {
268 /*
Snild Dolkow9e217d62020-04-22 15:53:42 +0200269 * We must apply the internal display's inverse transform to the buffer
270 * transform, and not the one for the output this layer is on.
Lloyd Piquea83776c2019-01-29 18:42:32 -0800271 */
Snild Dolkow9e217d62020-04-22 15:53:42 +0200272 uint32_t invTransform = internalDisplayRotationFlags;
273
Lloyd Piquea83776c2019-01-29 18:42:32 -0800274 // calculate the inverse transform
275 if (invTransform & HAL_TRANSFORM_ROT_90) {
276 invTransform ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H;
277 }
278
279 /*
280 * Here we cancel out the orientation component of the WM transform.
281 * The scaling and translate components are already included in our bounds
282 * computation so it's enough to just omit it in the composition.
283 * See comment in BufferLayer::prepareClientLayer with ref to b/36727915 for why.
284 */
Lloyd Pique546a2452019-03-18 20:53:27 +0000285 transform = ui::Transform(invTransform) * displayTransform * bufferTransform;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800286 }
287
288 // this gives us only the "orientation" component of the transform
289 return transform.getOrientation();
Snild Dolkow9e217d62020-04-22 15:53:42 +0200290}
Lloyd Piquea83776c2019-01-29 18:42:32 -0800291
Sally Qi0abc4a52024-09-26 16:13:06 -0700292void OutputLayer::updateLuts(
Sally Qief006582024-10-11 13:23:09 -0700293 const LayerFECompositionState& layerFEState,
Sally Qi0abc4a52024-09-26 16:13:06 -0700294 const std::optional<std::vector<std::optional<LutProperties>>>& properties) {
Sally Qief006582024-10-11 13:23:09 -0700295 auto& luts = layerFEState.luts;
296 if (!luts) {
297 return;
298 }
299
Sally Qi0abc4a52024-09-26 16:13:06 -0700300 auto& state = editState();
301
302 if (!properties) {
303 // GPU composition if no Hwc Luts
304 state.forceClientComposition = true;
305 return;
306 }
307
308 std::vector<LutProperties> hwcLutProperties;
309 for (auto& p : *properties) {
310 if (p) {
311 hwcLutProperties.emplace_back(*p);
312 }
313 }
314
Sally Qief006582024-10-11 13:23:09 -0700315 for (const auto& inputLut : luts->lutProperties) {
Sally Qi0abc4a52024-09-26 16:13:06 -0700316 bool foundInHwcLuts = false;
317 for (const auto& hwcLut : hwcLutProperties) {
318 if (static_cast<int32_t>(hwcLut.dimension) ==
319 static_cast<int32_t>(inputLut.dimension) &&
320 hwcLut.size == inputLut.size &&
321 std::find(hwcLut.samplingKeys.begin(), hwcLut.samplingKeys.end(),
322 static_cast<LutProperties::SamplingKey>(inputLut.samplingKey)) !=
323 hwcLut.samplingKeys.end()) {
324 foundInHwcLuts = true;
325 break;
326 }
327 }
Sally Qief006582024-10-11 13:23:09 -0700328 // if any lut properties of luts can not be found in hwcLutProperties,
Sally Qi0abc4a52024-09-26 16:13:06 -0700329 // GPU composition instead
330 if (!foundInHwcLuts) {
331 state.forceClientComposition = true;
332 return;
333 }
334 }
335}
336
Snild Dolkow9e217d62020-04-22 15:53:42 +0200337void OutputLayer::updateCompositionState(
338 bool includeGeometry, bool forceClientComposition,
Sally Qi0abc4a52024-09-26 16:13:06 -0700339 ui::Transform::RotationFlags internalDisplayRotationFlags,
340 const std::optional<std::vector<std::optional<LutProperties>>> properties) {
Lloyd Piquede196652020-01-22 17:29:58 -0800341 const auto* layerFEState = getLayerFE().getCompositionState();
342 if (!layerFEState) {
343 return;
344 }
345
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700346 const auto& outputState = getOutput().getState();
347 const auto& profile = *getOutput().getDisplayColorProfile();
348 auto& state = editState();
Lloyd Piquef5275482019-01-29 18:42:42 -0800349
Lloyd Piquea83776c2019-01-29 18:42:32 -0800350 if (includeGeometry) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700351 // Clear the forceClientComposition flag before it is set for any
352 // reason. Note that since it can be set by some checks below when
353 // updating the geometry state, we only clear it when updating the
354 // geometry since those conditions for forcing client composition won't
355 // go away otherwise.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700356 state.forceClientComposition = false;
Lloyd Piquefe671022019-09-24 10:43:03 -0700357
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700358 state.displayFrame = calculateOutputDisplayFrame();
ramindani2c043be2022-04-19 20:11:10 +0000359 state.sourceCrop = calculateOutputSourceCrop(internalDisplayRotationFlags);
Snild Dolkow9e217d62020-04-22 15:53:42 +0200360 state.bufferTransform = static_cast<Hwc2::Transform>(
361 calculateOutputRelativeBufferTransform(internalDisplayRotationFlags));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800362
Lloyd Piquede196652020-01-22 17:29:58 -0800363 if ((layerFEState->isSecure && !outputState.isSecure) ||
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700364 (state.bufferTransform & ui::Transform::ROT_INVALID)) {
365 state.forceClientComposition = true;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800366 }
367 }
Lloyd Piquef5275482019-01-29 18:42:42 -0800368
Sally Qif6918d42023-08-07 15:28:30 -0700369 auto pixelFormat = layerFEState->buffer ? std::make_optional(static_cast<ui::PixelFormat>(
370 layerFEState->buffer->getPixelFormat()))
371 : std::nullopt;
372
373 auto hdrRenderType =
374 getHdrRenderType(outputState.dataspace, pixelFormat, layerFEState->desiredHdrSdrRatio);
375
Lloyd Piquef5275482019-01-29 18:42:42 -0800376 // Determine the output dependent dataspace for this layer. If it is
377 // colorspace agnostic, it just uses the dataspace chosen for the output to
378 // avoid the need for color conversion.
Alec Mouri88790f32023-07-21 01:25:14 +0000379 // For now, also respect the colorspace agnostic flag if we're drawing to HDR, to avoid drastic
380 // luminance shift. TODO(b/292162273): we should check if that's true though.
Sally Qif6918d42023-08-07 15:28:30 -0700381 state.dataspace = layerFEState->isColorspaceAgnostic && hdrRenderType == HdrRenderType::SDR
Alec Mouri88790f32023-07-21 01:25:14 +0000382 ? outputState.dataspace
Lloyd Piquede196652020-01-22 17:29:58 -0800383 : layerFEState->dataspace;
Lloyd Piquef5275482019-01-29 18:42:42 -0800384
Alec Mouridda07d92022-04-25 22:39:25 +0000385 // Override the dataspace transfer from 170M to sRGB if the device configuration requests this.
386 // We do this here instead of in buffer info so that dumpsys can still report layers that are
387 // using the 170M transfer. Also we only do this if the colorspace is not agnostic for the
388 // layer, in case the color profile uses a 170M transfer function.
389 if (outputState.treat170mAsSrgb && !layerFEState->isColorspaceAgnostic &&
390 (state.dataspace & HAL_DATASPACE_TRANSFER_MASK) == HAL_DATASPACE_TRANSFER_SMPTE_170M) {
391 state.dataspace = static_cast<ui::Dataspace>(
392 (state.dataspace & HAL_DATASPACE_STANDARD_MASK) |
393 (state.dataspace & HAL_DATASPACE_RANGE_MASK) | HAL_DATASPACE_TRANSFER_SRGB);
394 }
395
Sally Qi8f9ed652023-08-17 15:30:29 -0700396 // re-get HdrRenderType after the dataspace gets changed.
397 hdrRenderType =
398 getHdrRenderType(state.dataspace, pixelFormat, layerFEState->desiredHdrSdrRatio);
399
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700400 // For hdr content, treat the white point as the display brightness - HDR content should not be
401 // boosted or dimmed.
Sally Qi81d95e62022-03-21 19:41:33 -0700402 // If the layer explicitly requests to disable dimming, then don't dim either.
Alec Mouri8face532024-11-09 22:15:32 +0000403 if (getOutput().getState().displayBrightnessNits == getOutput().getState().sdrWhitePointNits ||
404 getOutput().getState().displayBrightnessNits <= 0.f || !layerFEState->dimmingEnabled) {
Alec Mouri6da0e272022-02-07 12:45:57 -0800405 state.dimmingRatio = 1.f;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700406 state.whitePointNits = getOutput().getState().displayBrightnessNits;
Alec Mouri8face532024-11-09 22:15:32 +0000407 } else if (hdrRenderType == HdrRenderType::GENERIC_HDR) {
408 float deviceHeadroom = getOutput().getState().displayBrightnessNits /
409 getOutput().getState().sdrWhitePointNits;
410 float idealizedMaxHeadroom = deviceHeadroom;
411
412 if (FlagManager::getInstance().begone_bright_hlg()) {
413 idealizedMaxHeadroom =
414 std::min(idealizedMaxHeadroom, getIdealizedMaxHeadroom(state.dataspace));
415 }
416
417 state.dimmingRatio = std::min(idealizedMaxHeadroom / deviceHeadroom, 1.0f);
418 state.whitePointNits = getOutput().getState().displayBrightnessNits * state.dimmingRatio;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700419 } else {
John Reck68796592023-01-25 13:47:12 -0500420 float layerBrightnessNits = getOutput().getState().sdrWhitePointNits;
421 // RANGE_EXTENDED can "self-promote" to HDR, but is still rendered for a particular
422 // range that we may need to re-adjust to the current display conditions
Sally Qif6918d42023-08-07 15:28:30 -0700423 if (hdrRenderType == HdrRenderType::DISPLAY_HDR) {
Sally Qi963049b2023-03-23 14:06:21 -0700424 layerBrightnessNits *= layerFEState->currentHdrSdrRatio;
John Reck68796592023-01-25 13:47:12 -0500425 }
426 state.dimmingRatio =
427 std::clamp(layerBrightnessNits / getOutput().getState().displayBrightnessNits, 0.f,
428 1.f);
429 state.whitePointNits = layerBrightnessNits;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700430 }
431
Sally Qief006582024-10-11 13:23:09 -0700432 updateLuts(*layerFEState, properties);
Sally Qi0abc4a52024-09-26 16:13:06 -0700433
Lloyd Piquef5275482019-01-29 18:42:42 -0800434 // These are evaluated every frame as they can potentially change at any
435 // time.
Lloyd Piquede196652020-01-22 17:29:58 -0800436 if (layerFEState->forceClientComposition || !profile.isDataspaceSupported(state.dataspace) ||
Lloyd Pique7a234912019-10-03 11:54:27 -0700437 forceClientComposition) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700438 state.forceClientComposition = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800439 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800440}
441
Brian Lindahl1a4ffd82024-10-30 11:00:37 -0600442void OutputLayer::commitPictureProfileToCompositionState() {
443 if (!com_android_graphics_libgui_flags_apply_picture_profiles()) {
444 return;
445 }
446 const auto* layerState = getLayerFE().getCompositionState();
447 if (layerState) {
Brian Lindahlf5fdff82024-11-01 09:28:47 -0600448 editState().pictureProfileHandle = layerState->pictureProfileHandle;
Brian Lindahl1a4ffd82024-10-30 11:00:37 -0600449 }
450}
451
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400452void OutputLayer::writeStateToHWC(bool includeGeometry, bool skipLayer, uint32_t z,
453 bool zIsOverridden, bool isPeekingThrough) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700454 const auto& state = getState();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800455 // Skip doing this if there is no HWC interface
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700456 if (!state.hwc) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800457 return;
458 }
459
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700460 auto& hwcLayer = (*state.hwc).hwcLayer;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800461 if (!hwcLayer) {
462 ALOGE("[%s] failed to write composition state to HWC -- no hwcLayer for output %s",
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700463 getLayerFE().getDebugName(), getOutput().getName().c_str());
Lloyd Piquea83776c2019-01-29 18:42:32 -0800464 return;
465 }
466
Lloyd Piquede196652020-01-22 17:29:58 -0800467 const auto* outputIndependentState = getLayerFE().getCompositionState();
468 if (!outputIndependentState) {
469 return;
470 }
471
472 auto requestedCompositionType = outputIndependentState->compositionType;
Lloyd Piquef5275482019-01-29 18:42:42 -0800473
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500474 if (requestedCompositionType == Composition::SOLID_COLOR && state.overrideInfo.buffer) {
475 requestedCompositionType = Composition::DEVICE;
Alec Mouri028676a2021-12-02 15:01:48 -0800476 }
477
Yichi Chen413d46a2021-04-07 21:42:09 +0800478 // TODO(b/181172795): We now update geometry for all flattened layers. We should update it
479 // only when the geometry actually changes
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400480 const bool isOverridden =
481 state.overrideInfo.buffer != nullptr || isPeekingThrough || zIsOverridden;
Yichi Chen413d46a2021-04-07 21:42:09 +0800482 const bool prevOverridden = state.hwc->stateOverridden;
483 if (isOverridden || prevOverridden || skipLayer || includeGeometry) {
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400484 writeOutputDependentGeometryStateToHWC(hwcLayer.get(), requestedCompositionType, z);
Dan Stoza6166c312021-01-15 16:34:05 -0800485 writeOutputIndependentGeometryStateToHWC(hwcLayer.get(), *outputIndependentState,
486 skipLayer);
Lloyd Piquef5275482019-01-29 18:42:42 -0800487 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800488
Lloyd Piquef5275482019-01-29 18:42:42 -0800489 writeOutputDependentPerFrameStateToHWC(hwcLayer.get());
Alec Mouri028676a2021-12-02 15:01:48 -0800490 writeOutputIndependentPerFrameStateToHWC(hwcLayer.get(), *outputIndependentState,
491 requestedCompositionType, skipLayer);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800492
Alec Mourid1bf1b52021-05-05 18:44:58 -0700493 writeCompositionTypeToHWC(hwcLayer.get(), requestedCompositionType, isPeekingThrough,
494 skipLayer);
Lloyd Pique46b72df2019-10-29 13:19:27 -0700495
Sally Qi0abc4a52024-09-26 16:13:06 -0700496 writeLutToHWC(hwcLayer.get(), *outputIndependentState);
497
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500498 if (requestedCompositionType == Composition::SOLID_COLOR) {
Alec Mouri028676a2021-12-02 15:01:48 -0800499 writeSolidColorStateToHWC(hwcLayer.get(), *outputIndependentState);
500 }
Yichi Chen413d46a2021-04-07 21:42:09 +0800501
502 editState().hwc->stateOverridden = isOverridden;
Alec Mourid1bf1b52021-05-05 18:44:58 -0700503 editState().hwc->layerSkipped = skipLayer;
Lloyd Piquef5275482019-01-29 18:42:42 -0800504}
Lloyd Piquea83776c2019-01-29 18:42:32 -0800505
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400506void OutputLayer::writeOutputDependentGeometryStateToHWC(HWC2::Layer* hwcLayer,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500507 Composition requestedCompositionType,
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400508 uint32_t z) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800509 const auto& outputDependentState = getState();
510
Dan Stoza6166c312021-01-15 16:34:05 -0800511 Rect displayFrame = outputDependentState.displayFrame;
512 FloatRect sourceCrop = outputDependentState.sourceCrop;
Huihong Luoa5825112021-03-24 12:28:29 -0700513
Alec Mouri464352b2021-03-24 16:33:21 -0700514 if (outputDependentState.overrideInfo.buffer != nullptr) {
Dan Stoza6166c312021-01-15 16:34:05 -0800515 displayFrame = outputDependentState.overrideInfo.displayFrame;
Wiwit Rifa'i50abed02022-05-24 02:24:33 +0000516 sourceCrop =
517 FloatRect(0.f, 0.f,
518 static_cast<float>(outputDependentState.overrideInfo.buffer->getBuffer()
519 ->getWidth()),
520 static_cast<float>(outputDependentState.overrideInfo.buffer->getBuffer()
521 ->getHeight()));
Lloyd Piquef5275482019-01-29 18:42:42 -0800522 }
523
Dan Stoza6166c312021-01-15 16:34:05 -0800524 ALOGV("Writing display frame [%d, %d, %d, %d]", displayFrame.left, displayFrame.top,
525 displayFrame.right, displayFrame.bottom);
526
527 if (auto error = hwcLayer->setDisplayFrame(displayFrame); error != hal::Error::NONE) {
528 ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)",
529 getLayerFE().getDebugName(), displayFrame.left, displayFrame.top, displayFrame.right,
530 displayFrame.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
531 }
532
533 if (auto error = hwcLayer->setSourceCrop(sourceCrop); error != hal::Error::NONE) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800534 ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: "
535 "%s (%d)",
Dan Stoza6166c312021-01-15 16:34:05 -0800536 getLayerFE().getDebugName(), sourceCrop.left, sourceCrop.top, sourceCrop.right,
537 sourceCrop.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800538 }
539
Pierre-Hugues Husson17486262020-05-25 10:12:24 +0000540 uint32_t z_udfps = z;
541 if ((strncmp(getLayerFE().getDebugName(), UDFPS_LAYER_NAME, strlen(UDFPS_LAYER_NAME)) == 0) ||
542 (strncmp(getLayerFE().getDebugName(), UDFPS_BIOMETRIC_PROMPT_LAYER_NAME,
543 strlen(UDFPS_BIOMETRIC_PROMPT_LAYER_NAME)) == 0)) {
544 z_udfps = getUdfpsZOrder(z, false);
545 } else if (strncmp(getLayerFE().getDebugName(), UDFPS_TOUCHED_LAYER_NAME,
546 strlen(UDFPS_TOUCHED_LAYER_NAME)) == 0) {
547 z_udfps = getUdfpsZOrder(z, true);
548 }
549
550 if (auto error = hwcLayer->setZOrder(z_udfps); error != hal::Error::NONE) {
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400551 ALOGE("[%s] Failed to set Z %u: %s (%d)", getLayerFE().getDebugName(), z,
552 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800553 }
554
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700555 // Solid-color layers and overridden buffers should always use an identity transform.
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500556 const auto bufferTransform = (requestedCompositionType != Composition::SOLID_COLOR &&
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700557 getState().overrideInfo.buffer == nullptr)
Lloyd Piquef5275482019-01-29 18:42:42 -0800558 ? outputDependentState.bufferTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700559 : static_cast<hal::Transform>(0);
560 if (auto error = hwcLayer->setTransform(static_cast<hal::Transform>(bufferTransform));
561 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700562 ALOGE("[%s] Failed to set transform %s: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800563 toString(outputDependentState.bufferTransform).c_str(), to_string(error).c_str(),
564 static_cast<int32_t>(error));
565 }
566}
567
568void OutputLayer::writeOutputIndependentGeometryStateToHWC(
Dan Stoza6166c312021-01-15 16:34:05 -0800569 HWC2::Layer* hwcLayer, const LayerFECompositionState& outputIndependentState,
570 bool skipLayer) {
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400571 // If there is a peekThroughLayer, then this layer has a hole in it. We need to use
572 // PREMULTIPLIED so it will peek through.
573 const auto& overrideInfo = getState().overrideInfo;
574 const auto blendMode = overrideInfo.buffer || overrideInfo.peekThroughLayer
Alec Mouriee69a592021-03-23 15:00:45 -0700575 ? hardware::graphics::composer::hal::BlendMode::PREMULTIPLIED
576 : outputIndependentState.blendMode;
577 if (auto error = hwcLayer->setBlendMode(blendMode); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700578 ALOGE("[%s] Failed to set blend mode %s: %s (%d)", getLayerFE().getDebugName(),
Alec Mouriee69a592021-03-23 15:00:45 -0700579 toString(blendMode).c_str(), to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800580 }
581
Alec Mouriee69a592021-03-23 15:00:45 -0700582 const float alpha = skipLayer
583 ? 0.0f
584 : (getState().overrideInfo.buffer ? 1.0f : outputIndependentState.alpha);
Dan Stoza6166c312021-01-15 16:34:05 -0800585 ALOGV("Writing alpha %f", alpha);
586
587 if (auto error = hwcLayer->setPlaneAlpha(alpha); error != hal::Error::NONE) {
588 ALOGE("[%s] Failed to set plane alpha %.3f: %s (%d)", getLayerFE().getDebugName(), alpha,
589 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800590 }
591
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800592 for (const auto& [name, entry] : outputIndependentState.metadata) {
593 if (auto error = hwcLayer->setLayerGenericMetadata(name, entry.mandatory, entry.value);
Peiyong Line9d809e2020-04-14 13:10:48 -0700594 error != hal::Error::NONE) {
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800595 ALOGE("[%s] Failed to set generic metadata %s %s (%d)", getLayerFE().getDebugName(),
596 name.c_str(), to_string(error).c_str(), static_cast<int32_t>(error));
597 }
598 }
Lloyd Piquef5275482019-01-29 18:42:42 -0800599}
600
Sally Qi0abc4a52024-09-26 16:13:06 -0700601void OutputLayer::writeLutToHWC(HWC2::Layer* hwcLayer,
602 const LayerFECompositionState& outputIndependentState) {
Sally Qif5f380b2024-11-26 18:16:10 +0000603 if (!outputIndependentState.luts) {
604 return;
Sally Qi36349ac2024-11-25 08:00:26 +0000605 }
Sally Qif5f380b2024-11-26 18:16:10 +0000606 auto& lutFileDescriptor = outputIndependentState.luts->getLutFileDescriptor();
607 auto lutOffsets = outputIndependentState.luts->offsets;
608 auto& lutProperties = outputIndependentState.luts->lutProperties;
609
610 std::vector<LutProperties> aidlProperties;
611 aidlProperties.reserve(lutProperties.size());
612 for (size_t i = 0; i < lutOffsets.size(); i++) {
613 LutProperties properties;
614 properties.dimension = static_cast<LutProperties::Dimension>(lutProperties[i].dimension);
615 properties.size = lutProperties[i].size;
616 properties.samplingKeys = {
617 static_cast<LutProperties::SamplingKey>(lutProperties[i].samplingKey)};
618 aidlProperties.emplace_back(properties);
619 }
620
621 Luts luts;
622 luts.pfd = ndk::ScopedFileDescriptor(dup(lutFileDescriptor.get()));
623 luts.offsets = lutOffsets;
624 luts.lutProperties = std::move(aidlProperties);
Sally Qi0abc4a52024-09-26 16:13:06 -0700625
626 switch (auto error = hwcLayer->setLuts(luts)) {
627 case hal::Error::NONE:
628 break;
629 default:
630 ALOGE("[%s] Failed to set Luts: %s (%d)", getLayerFE().getDebugName(),
631 to_string(error).c_str(), static_cast<int32_t>(error));
632 }
633}
634
Lloyd Piquef5275482019-01-29 18:42:42 -0800635void OutputLayer::writeOutputDependentPerFrameStateToHWC(HWC2::Layer* hwcLayer) {
636 const auto& outputDependentState = getState();
637
Lloyd Piquea2468662019-03-07 21:31:06 -0800638 // TODO(lpique): b/121291683 outputSpaceVisibleRegion is output-dependent geometry
Lloyd Piquef5275482019-01-29 18:42:42 -0800639 // state and should not change every frame.
Alec Mouri464352b2021-03-24 16:33:21 -0700640 Region visibleRegion = outputDependentState.overrideInfo.buffer
641 ? Region(outputDependentState.overrideInfo.visibleRegion)
642 : outputDependentState.outputSpaceVisibleRegion;
643 if (auto error = hwcLayer->setVisibleRegion(visibleRegion); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700644 ALOGE("[%s] Failed to set visible region: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800645 to_string(error).c_str(), static_cast<int32_t>(error));
Leon Scroggins IIIf2b8ec42022-01-05 13:23:36 -0500646 visibleRegion.dump(LOG_TAG);
Lloyd Piquef5275482019-01-29 18:42:42 -0800647 }
648
Leon Scroggins III9a0afda2022-01-11 16:53:09 -0500649 if (auto error =
650 hwcLayer->setBlockingRegion(outputDependentState.outputSpaceBlockingRegionHint);
651 error != hal::Error::NONE) {
652 ALOGE("[%s] Failed to set blocking region: %s (%d)", getLayerFE().getDebugName(),
653 to_string(error).c_str(), static_cast<int32_t>(error));
654 outputDependentState.outputSpaceBlockingRegionHint.dump(LOG_TAG);
655 }
656
Alec Mourib7edfc22021-03-17 16:20:26 -0700657 const auto dataspace = outputDependentState.overrideInfo.buffer
658 ? outputDependentState.overrideInfo.dataspace
659 : outputDependentState.dataspace;
660
661 if (auto error = hwcLayer->setDataspace(dataspace); error != hal::Error::NONE) {
662 ALOGE("[%s] Failed to set dataspace %d: %s (%d)", getLayerFE().getDebugName(), dataspace,
663 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800664 }
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700665
Alec Mourie8dd3562022-02-11 14:18:57 -0800666 // Cached layers are not dimmed, which means that composer should attempt to dim.
667 // Note that if the dimming ratio is large, then this may cause the cached layer
668 // to kick back into GPU composition :(
669 // Also note that this assumes that there are no HDR layers that are able to be cached.
670 // Otherwise, this could cause HDR layers to be dimmed twice.
671 const auto dimmingRatio = outputDependentState.overrideInfo.buffer
672 ? (getOutput().getState().displayBrightnessNits != 0.f
673 ? std::clamp(getOutput().getState().sdrWhitePointNits /
674 getOutput().getState().displayBrightnessNits,
675 0.f, 1.f)
676 : 1.f)
677 : outputDependentState.dimmingRatio;
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700678
Alec Mouri6da0e272022-02-07 12:45:57 -0800679 if (auto error = hwcLayer->setBrightness(dimmingRatio); error != hal::Error::NONE) {
680 ALOGE("[%s] Failed to set brightness %f: %s (%d)", getLayerFE().getDebugName(),
681 dimmingRatio, to_string(error).c_str(), static_cast<int32_t>(error));
Alec Mouricdf6cbc2021-11-01 17:21:15 -0700682 }
Brian Lindahl1a4ffd82024-10-30 11:00:37 -0600683
684 if (com_android_graphics_libgui_flags_apply_picture_profiles() &&
685 outputDependentState.pictureProfileHandle) {
686 if (auto error =
687 hwcLayer->setPictureProfileHandle(outputDependentState.pictureProfileHandle);
688 error != hal::Error::NONE) {
689 ALOGE("[%s] Failed to set picture profile handle: %s (%d)", getLayerFE().getDebugName(),
690 toString(outputDependentState.pictureProfileHandle).c_str(),
691 static_cast<int32_t>(error));
692 }
693 // Reset the picture profile state, as it needs to be re-committed on each present cycle
694 // when Output decides that the limited picture-processing hardware should be used by this
695 // layer.
696 editState().pictureProfileHandle = PictureProfileHandle::NONE;
697 }
Lloyd Piquef5275482019-01-29 18:42:42 -0800698}
699
700void OutputLayer::writeOutputIndependentPerFrameStateToHWC(
Alec Mouri96ca45c2021-06-09 17:32:26 -0700701 HWC2::Layer* hwcLayer, const LayerFECompositionState& outputIndependentState,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500702 Composition compositionType, bool skipLayer) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800703 switch (auto error = hwcLayer->setColorTransform(outputIndependentState.colorTransform)) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700704 case hal::Error::NONE:
Lloyd Piquef5275482019-01-29 18:42:42 -0800705 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700706 case hal::Error::UNSUPPORTED:
Lloyd Piquef5275482019-01-29 18:42:42 -0800707 editState().forceClientComposition = true;
708 break;
709 default:
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700710 ALOGE("[%s] Failed to set color transform: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquea83776c2019-01-29 18:42:32 -0800711 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800712 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800713
Alec Mouri464352b2021-03-24 16:33:21 -0700714 const Region& surfaceDamage = getState().overrideInfo.buffer
715 ? getState().overrideInfo.damageRegion
Alec Mourid1bf1b52021-05-05 18:44:58 -0700716 : (getState().hwc->stateOverridden ? Region::INVALID_REGION
717 : outputIndependentState.surfaceDamage);
Alec Mouri464352b2021-03-24 16:33:21 -0700718
719 if (auto error = hwcLayer->setSurfaceDamage(surfaceDamage); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700720 ALOGE("[%s] Failed to set surface damage: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800721 to_string(error).c_str(), static_cast<int32_t>(error));
722 outputIndependentState.surfaceDamage.dump(LOG_TAG);
723 }
724
725 // Content-specific per-frame state
Alec Mouri028676a2021-12-02 15:01:48 -0800726 switch (compositionType) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500727 case Composition::SOLID_COLOR:
Lloyd Pique46b72df2019-10-29 13:19:27 -0700728 // For compatibility, should be written AFTER the composition type.
Lloyd Piquef5275482019-01-29 18:42:42 -0800729 break;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500730 case Composition::SIDEBAND:
Lloyd Piquef5275482019-01-29 18:42:42 -0800731 writeSidebandStateToHWC(hwcLayer, outputIndependentState);
732 break;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500733 case Composition::CURSOR:
734 case Composition::DEVICE:
Leon Scroggins III09c25412021-12-02 14:49:56 -0500735 case Composition::DISPLAY_DECORATION:
ramindanic1945cb2023-02-03 13:28:15 -0800736 case Composition::REFRESH_RATE_INDICATOR:
Alec Mouri96ca45c2021-06-09 17:32:26 -0700737 writeBufferStateToHWC(hwcLayer, outputIndependentState, skipLayer);
Lloyd Piquef5275482019-01-29 18:42:42 -0800738 break;
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500739 case Composition::INVALID:
740 case Composition::CLIENT:
Lloyd Piquef5275482019-01-29 18:42:42 -0800741 // Ignored
742 break;
743 }
744}
745
746void OutputLayer::writeSolidColorStateToHWC(HWC2::Layer* hwcLayer,
747 const LayerFECompositionState& outputIndependentState) {
Ady Abraham6e60b142022-01-06 18:10:35 -0800748 aidl::android::hardware::graphics::composer3::Color color = {outputIndependentState.color.r,
749 outputIndependentState.color.g,
750 outputIndependentState.color.b,
751 1.0f};
Lloyd Piquef5275482019-01-29 18:42:42 -0800752
Peiyong Line9d809e2020-04-14 13:10:48 -0700753 if (auto error = hwcLayer->setColor(color); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700754 ALOGE("[%s] Failed to set color: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800755 to_string(error).c_str(), static_cast<int32_t>(error));
756 }
757}
758
759void OutputLayer::writeSidebandStateToHWC(HWC2::Layer* hwcLayer,
760 const LayerFECompositionState& outputIndependentState) {
761 if (auto error = hwcLayer->setSidebandStream(outputIndependentState.sidebandStream->handle());
Peiyong Line9d809e2020-04-14 13:10:48 -0700762 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700763 ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800764 outputIndependentState.sidebandStream->handle(), to_string(error).c_str(),
765 static_cast<int32_t>(error));
766 }
767}
768
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700769void OutputLayer::uncacheBuffers(const std::vector<uint64_t>& bufferIdsToUncache) {
Brian Lindahl439afad2022-11-14 11:16:55 -0700770 auto& state = editState();
771 // Skip doing this if there is no HWC interface
772 if (!state.hwc) {
773 return;
774 }
775
Brian Lindahl3e1e1e62022-12-21 14:28:58 -0700776 // Uncache the active buffer last so that it's the first buffer to be purged from the cache
777 // next time a buffer is sent to this layer.
778 bool uncacheActiveBuffer = false;
779
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700780 std::vector<uint32_t> slotsToClear;
781 for (uint64_t bufferId : bufferIdsToUncache) {
Brian Lindahl3e1e1e62022-12-21 14:28:58 -0700782 if (bufferId == state.hwc->activeBufferId) {
783 uncacheActiveBuffer = true;
784 } else {
785 uint32_t slot = state.hwc->hwcBufferCache.uncache(bufferId);
786 if (slot != UINT32_MAX) {
787 slotsToClear.push_back(slot);
788 }
Brian Lindahl90553da2022-12-06 13:36:30 -0700789 }
Brian Lindahl439afad2022-11-14 11:16:55 -0700790 }
Brian Lindahl3e1e1e62022-12-21 14:28:58 -0700791 if (uncacheActiveBuffer) {
792 slotsToClear.push_back(state.hwc->hwcBufferCache.uncache(state.hwc->activeBufferId));
793 }
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700794
795 hal::Error error =
796 state.hwc->hwcLayer->setBufferSlotsToClear(slotsToClear, state.hwc->activeBufferSlot);
797 if (error != hal::Error::NONE) {
798 ALOGE("[%s] Failed to clear buffer slots: %s (%d)", getLayerFE().getDebugName(),
799 to_string(error).c_str(), static_cast<int32_t>(error));
800 }
Brian Lindahl439afad2022-11-14 11:16:55 -0700801}
802
Brian Lindahl1a4ffd82024-10-30 11:00:37 -0600803int64_t OutputLayer::getPictureProfilePriority() const {
804 const auto* layerState = getLayerFE().getCompositionState();
805 return layerState ? layerState->pictureProfilePriority : 0;
806}
807
808const PictureProfileHandle& OutputLayer::getPictureProfileHandle() const {
809 const auto* layerState = getLayerFE().getCompositionState();
810 return layerState ? layerState->pictureProfileHandle : PictureProfileHandle::NONE;
811}
812
Lloyd Piquef5275482019-01-29 18:42:42 -0800813void OutputLayer::writeBufferStateToHWC(HWC2::Layer* hwcLayer,
Alec Mouri96ca45c2021-06-09 17:32:26 -0700814 const LayerFECompositionState& outputIndependentState,
815 bool skipLayer) {
Huihong Luo5e161962023-08-18 14:26:32 -0700816 if (skipLayer && outputIndependentState.buffer == nullptr) {
817 return;
818 }
Lloyd Piquef5275482019-01-29 18:42:42 -0800819 auto supportedPerFrameMetadata =
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700820 getOutput().getDisplayColorProfile()->getSupportedPerFrameMetadata();
Lloyd Piquef5275482019-01-29 18:42:42 -0800821 if (auto error = hwcLayer->setPerFrameMetadata(supportedPerFrameMetadata,
822 outputIndependentState.hdrMetadata);
Peiyong Line9d809e2020-04-14 13:10:48 -0700823 error != hal::Error::NONE && error != hal::Error::UNSUPPORTED) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700824 ALOGE("[%s] Failed to set hdrMetadata: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800825 to_string(error).c_str(), static_cast<int32_t>(error));
826 }
827
Brian Lindahl439afad2022-11-14 11:16:55 -0700828 HwcSlotAndBuffer hwcSlotAndBuffer;
829 sp<Fence> hwcFence;
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700830 {
831 // Editing the state only because we update the HWC buffer cache and active buffer.
832 auto& state = editState();
833 // Override buffers use a special cache slot so that they don't evict client buffers.
834 if (state.overrideInfo.buffer != nullptr && !skipLayer) {
835 hwcSlotAndBuffer = state.hwc->hwcBufferCache.getOverrideHwcSlotAndBuffer(
836 state.overrideInfo.buffer->getBuffer());
837 hwcFence = state.overrideInfo.acquireFence;
Brian Lindahl3e1e1e62022-12-21 14:28:58 -0700838 // Keep track of the active buffer ID so when it's discarded we uncache it last so its
839 // slot will be used first, allowing the memory to be freed as soon as possible.
840 state.hwc->activeBufferId = state.overrideInfo.buffer->getBuffer()->getId();
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700841 } else {
842 hwcSlotAndBuffer =
843 state.hwc->hwcBufferCache.getHwcSlotAndBuffer(outputIndependentState.buffer);
844 hwcFence = outputIndependentState.acquireFence;
Brian Lindahl3e1e1e62022-12-21 14:28:58 -0700845 // Keep track of the active buffer ID so when it's discarded we uncache it last so its
846 // slot will be used first, allowing the memory to be freed as soon as possible.
847 state.hwc->activeBufferId = outputIndependentState.buffer->getId();
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700848 }
Brian Lindahlb158a5c2022-12-15 15:21:13 -0700849 // Keep track of the active buffer slot, so we can restore it after clearing other buffer
850 // slots.
Brian Lindahl3e1e1e62022-12-21 14:28:58 -0700851 state.hwc->activeBufferSlot = hwcSlotAndBuffer.slot;
Dan Stoza6166c312021-01-15 16:34:05 -0800852 }
853
Brian Lindahl439afad2022-11-14 11:16:55 -0700854 if (auto error = hwcLayer->setBuffer(hwcSlotAndBuffer.slot, hwcSlotAndBuffer.buffer, hwcFence);
Peiyong Line9d809e2020-04-14 13:10:48 -0700855 error != hal::Error::NONE) {
Brian Lindahl439afad2022-11-14 11:16:55 -0700856 ALOGE("[%s] Failed to set buffer %p: %s (%d)", getLayerFE().getDebugName(),
857 hwcSlotAndBuffer.buffer->handle, to_string(error).c_str(),
858 static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800859 }
860}
861
Peiyong Line9d809e2020-04-14 13:10:48 -0700862void OutputLayer::writeCompositionTypeToHWC(HWC2::Layer* hwcLayer,
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500863 Composition requestedCompositionType,
Alec Mourid1bf1b52021-05-05 18:44:58 -0700864 bool isPeekingThrough, bool skipLayer) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800865 auto& outputDependentState = editState();
866
Alec Mourid1bf1b52021-05-05 18:44:58 -0700867 if (isClientCompositionForced(isPeekingThrough)) {
868 // If we are forcing client composition, we need to tell the HWC
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500869 requestedCompositionType = Composition::CLIENT;
Lloyd Piquef5275482019-01-29 18:42:42 -0800870 }
871
872 // Set the requested composition type with the HWC whenever it changes
Alec Mourid1bf1b52021-05-05 18:44:58 -0700873 // We also resend the composition type when this layer was previously skipped, to ensure that
874 // the composition type is up-to-date.
875 if (outputDependentState.hwc->hwcCompositionType != requestedCompositionType ||
876 (outputDependentState.hwc->layerSkipped && !skipLayer)) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800877 outputDependentState.hwc->hwcCompositionType = requestedCompositionType;
878
Peiyong Line9d809e2020-04-14 13:10:48 -0700879 if (auto error = hwcLayer->setCompositionType(requestedCompositionType);
880 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700881 ALOGE("[%s] Failed to set composition type %s: %s (%d)", getLayerFE().getDebugName(),
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500882 to_string(requestedCompositionType).c_str(), to_string(error).c_str(),
Lloyd Piquea83776c2019-01-29 18:42:32 -0800883 static_cast<int32_t>(error));
884 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800885 }
886}
887
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800888void OutputLayer::writeCursorPositionToHWC() const {
889 // Skip doing this if there is no HWC interface
890 auto hwcLayer = getHwcLayer();
891 if (!hwcLayer) {
892 return;
893 }
894
Brian Lindahl1a4ffd82024-10-30 11:00:37 -0600895 const auto* layerState = getLayerFE().getCompositionState();
896 if (!layerState) {
Lloyd Piquede196652020-01-22 17:29:58 -0800897 return;
898 }
899
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700900 const auto& outputState = getOutput().getState();
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800901
Brian Lindahl1a4ffd82024-10-30 11:00:37 -0600902 Rect frame = layerState->cursorFrame;
Angel Aguayob084e0c2021-08-04 23:27:28 +0000903 frame.intersect(outputState.layerStackSpace.getContent(), &frame);
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800904 Rect position = outputState.transform.transform(frame);
905
906 if (auto error = hwcLayer->setCursorPosition(position.left, position.top);
Peiyong Line9d809e2020-04-14 13:10:48 -0700907 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700908 ALOGE("[%s] Failed to set cursor position to (%d, %d): %s (%d)",
909 getLayerFE().getDebugName(), position.left, position.top, to_string(error).c_str(),
910 static_cast<int32_t>(error));
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800911 }
912}
913
Lloyd Pique66d68602019-02-13 14:23:31 -0800914HWC2::Layer* OutputLayer::getHwcLayer() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700915 const auto& state = getState();
916 return state.hwc ? state.hwc->hwcLayer.get() : nullptr;
Lloyd Pique66d68602019-02-13 14:23:31 -0800917}
918
919bool OutputLayer::requiresClientComposition() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700920 const auto& state = getState();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500921 return !state.hwc || state.hwc->hwcCompositionType == Composition::CLIENT;
Lloyd Pique66d68602019-02-13 14:23:31 -0800922}
923
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800924bool OutputLayer::isHardwareCursor() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700925 const auto& state = getState();
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500926 return state.hwc && state.hwc->hwcCompositionType == Composition::CURSOR;
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800927}
928
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500929void OutputLayer::detectDisallowedCompositionTypeChange(Composition from, Composition to) const {
Lloyd Pique66d68602019-02-13 14:23:31 -0800930 bool result = false;
931 switch (from) {
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500932 case Composition::INVALID:
933 case Composition::CLIENT:
Lloyd Pique66d68602019-02-13 14:23:31 -0800934 result = false;
935 break;
936
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500937 case Composition::DEVICE:
938 case Composition::SOLID_COLOR:
939 result = (to == Composition::CLIENT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800940 break;
941
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500942 case Composition::CURSOR:
943 case Composition::SIDEBAND:
Leon Scroggins7fd536f2021-12-28 14:43:12 +0000944 case Composition::DISPLAY_DECORATION:
ramindanic1945cb2023-02-03 13:28:15 -0800945 case Composition::REFRESH_RATE_INDICATOR:
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500946 result = (to == Composition::CLIENT || to == Composition::DEVICE);
Lloyd Pique66d68602019-02-13 14:23:31 -0800947 break;
948 }
949
950 if (!result) {
951 ALOGE("[%s] Invalid device requested composition type change: %s (%d) --> %s (%d)",
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500952 getLayerFE().getDebugName(), to_string(from).c_str(), static_cast<int>(from),
953 to_string(to).c_str(), static_cast<int>(to));
Lloyd Pique66d68602019-02-13 14:23:31 -0800954 }
955}
956
Alec Mourid1bf1b52021-05-05 18:44:58 -0700957bool OutputLayer::isClientCompositionForced(bool isPeekingThrough) const {
958 return getState().forceClientComposition ||
959 (!isPeekingThrough && getLayerFE().hasRoundedCorners());
960}
961
Leon Scroggins III2e1aa182021-12-01 17:33:12 -0500962void OutputLayer::applyDeviceCompositionTypeChange(Composition compositionType) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700963 auto& state = editState();
964 LOG_FATAL_IF(!state.hwc);
965 auto& hwcState = *state.hwc;
Lloyd Pique66d68602019-02-13 14:23:31 -0800966
Alec Mourid1bf1b52021-05-05 18:44:58 -0700967 // Only detected disallowed changes if this was not a skip layer, because the
968 // validated composition type may be arbitrary (usually DEVICE, to reflect that there were
969 // fewer GPU layers)
970 if (!hwcState.layerSkipped) {
971 detectDisallowedCompositionTypeChange(hwcState.hwcCompositionType, compositionType);
972 }
Lloyd Pique66d68602019-02-13 14:23:31 -0800973
974 hwcState.hwcCompositionType = compositionType;
975}
976
977void OutputLayer::prepareForDeviceLayerRequests() {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700978 auto& state = editState();
979 state.clearClientTarget = false;
Lloyd Pique66d68602019-02-13 14:23:31 -0800980}
981
Peiyong Line9d809e2020-04-14 13:10:48 -0700982void OutputLayer::applyDeviceLayerRequest(hal::LayerRequest request) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700983 auto& state = editState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800984 switch (request) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700985 case hal::LayerRequest::CLEAR_CLIENT_TARGET:
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700986 state.clearClientTarget = true;
Lloyd Pique66d68602019-02-13 14:23:31 -0800987 break;
988
989 default:
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700990 ALOGE("[%s] Unknown device layer request %s (%d)", getLayerFE().getDebugName(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800991 toString(request).c_str(), static_cast<int>(request));
992 break;
993 }
994}
995
Sally Qi0abc4a52024-09-26 16:13:06 -0700996void OutputLayer::applyDeviceLayerLut(
997 ndk::ScopedFileDescriptor lutFileDescriptor,
998 std::vector<std::pair<int, LutProperties>> lutOffsetsAndProperties) {
999 auto& state = editState();
1000 LOG_FATAL_IF(!state.hwc);
1001 auto& hwcState = *state.hwc;
1002 std::vector<int32_t> offsets;
1003 std::vector<int32_t> dimensions;
1004 std::vector<int32_t> sizes;
1005 std::vector<int32_t> samplingKeys;
1006 for (const auto& [offset, properties] : lutOffsetsAndProperties) {
1007 // The Lut(s) that comes back through CommandResultPayload should be
1008 // only one sampling key.
1009 if (properties.samplingKeys.size() == 1) {
1010 offsets.emplace_back(offset);
1011 dimensions.emplace_back(static_cast<int32_t>(properties.dimension));
1012 sizes.emplace_back(static_cast<int32_t>(properties.size));
1013 samplingKeys.emplace_back(static_cast<int32_t>(properties.samplingKeys[0]));
1014 }
1015 }
1016 hwcState.luts = std::make_shared<gui::DisplayLuts>(base::unique_fd(lutFileDescriptor.release()),
1017 std::move(offsets), std::move(dimensions),
1018 std::move(sizes), std::move(samplingKeys));
Sally Qi95f669a2024-08-27 11:31:42 -07001019}
1020
Lloyd Pique688abd42019-02-15 15:42:24 -08001021bool OutputLayer::needsFiltering() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07001022 const auto& state = getState();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07001023 const auto& sourceCrop = state.sourceCrop;
Alec Mourib6d78932023-09-20 16:05:42 +00001024 auto displayFrameWidth = static_cast<float>(state.displayFrame.getWidth());
1025 auto displayFrameHeight = static_cast<float>(state.displayFrame.getHeight());
1026
1027 if (state.bufferTransform & HAL_TRANSFORM_ROT_90) {
1028 std::swap(displayFrameWidth, displayFrameHeight);
1029 }
1030
1031 return sourceCrop.getHeight() != displayFrameHeight ||
1032 sourceCrop.getWidth() != displayFrameWidth;
Lloyd Pique688abd42019-02-15 15:42:24 -08001033}
1034
Patrick Williams16d8b2c2022-08-08 17:29:05 +00001035std::optional<LayerFE::LayerSettings> OutputLayer::getOverrideCompositionSettings() const {
Dan Stoza6166c312021-01-15 16:34:05 -08001036 if (getState().overrideInfo.buffer == nullptr) {
1037 return {};
1038 }
1039
Alec Mouri7be6c0a2021-03-19 15:22:01 -07001040 // Compute the geometry boundaries in layer stack space: we need to transform from the
1041 // framebuffer space of the override buffer to layer space.
1042 const ProjectionSpace& layerSpace = getOutput().getState().layerStackSpace;
1043 const ui::Transform transform = getState().overrideInfo.displaySpace.getTransform(layerSpace);
Wiwit Rifa'i50abed02022-05-24 02:24:33 +00001044 const Rect boundaries = transform.transform(getState().overrideInfo.displayFrame);
Alec Mouri7be6c0a2021-03-19 15:22:01 -07001045
Dan Stoza6166c312021-01-15 16:34:05 -08001046 LayerFE::LayerSettings settings;
1047 settings.geometry = renderengine::Geometry{
Alec Mouri7be6c0a2021-03-19 15:22:01 -07001048 .boundaries = boundaries.toFloatRect(),
Dan Stoza6166c312021-01-15 16:34:05 -08001049 };
Alec Mouria90a5702021-04-16 16:36:21 +00001050 settings.bufferId = getState().overrideInfo.buffer->getBuffer()->getId();
Alec Mouri7be6c0a2021-03-19 15:22:01 -07001051 settings.source = renderengine::PixelSource{
1052 .buffer = renderengine::Buffer{
1053 .buffer = getState().overrideInfo.buffer,
1054 .fence = getState().overrideInfo.acquireFence,
1055 // If the transform from layer space to display space contains a rotation, we
1056 // need to undo the rotation in the texture transform
1057 .textureTransform =
1058 ui::Transform(transform.inverse().getOrientation(), 1, 1).asMatrix4(),
1059 }};
Alec Mouri9c8fce02021-03-12 18:30:42 -08001060 settings.sourceDataspace = getState().overrideInfo.dataspace;
Dan Stoza6166c312021-01-15 16:34:05 -08001061 settings.alpha = 1.0f;
Alec Mourie8dd3562022-02-11 14:18:57 -08001062 settings.whitePointNits = getOutput().getState().sdrWhitePointNits;
Dan Stoza6166c312021-01-15 16:34:05 -08001063
Patrick Williams16d8b2c2022-08-08 17:29:05 +00001064 return settings;
Dan Stoza6166c312021-01-15 16:34:05 -08001065}
1066
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001067void OutputLayer::dump(std::string& out) const {
1068 using android::base::StringAppendF;
1069
Lloyd Piquede196652020-01-22 17:29:58 -08001070 StringAppendF(&out, " - Output Layer %p(%s)\n", this, getLayerFE().getDebugName());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -07001071 dumpState(out);
Lloyd Pique37c2c9b2018-12-04 17:25:10 -08001072}
1073
Lloyd Piquecc01a452018-12-04 17:24:00 -08001074} // namespace impl
1075} // namespace android::compositionengine