blob: 7f5c01cc8efc7eba827485637e355caf41e1e3e8 [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;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700370 sourceCrop =
371 FloatRect(0.f, 0.f,
372 static_cast<float>(outputDependentState.overrideInfo.buffer->getBuffer()
373 ->getWidth()),
374 static_cast<float>(outputDependentState.overrideInfo.buffer->getBuffer()
375 ->getHeight()));
Lloyd Piquef5275482019-01-29 18:42:42 -0800376 }
377
Dan Stoza6166c312021-01-15 16:34:05 -0800378 ALOGV("Writing display frame [%d, %d, %d, %d]", displayFrame.left, displayFrame.top,
379 displayFrame.right, displayFrame.bottom);
380
381 if (auto error = hwcLayer->setDisplayFrame(displayFrame); error != hal::Error::NONE) {
382 ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)",
383 getLayerFE().getDebugName(), displayFrame.left, displayFrame.top, displayFrame.right,
384 displayFrame.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
385 }
386
387 if (auto error = hwcLayer->setSourceCrop(sourceCrop); error != hal::Error::NONE) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800388 ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: "
389 "%s (%d)",
Dan Stoza6166c312021-01-15 16:34:05 -0800390 getLayerFE().getDebugName(), sourceCrop.left, sourceCrop.top, sourceCrop.right,
391 sourceCrop.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800392 }
393
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400394 if (auto error = hwcLayer->setZOrder(z); error != hal::Error::NONE) {
395 ALOGE("[%s] Failed to set Z %u: %s (%d)", getLayerFE().getDebugName(), z,
396 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800397 }
398
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700399 // Solid-color layers and overridden buffers should always use an identity transform.
400 const auto bufferTransform = (requestedCompositionType != hal::Composition::SOLID_COLOR &&
401 getState().overrideInfo.buffer == nullptr)
Lloyd Piquef5275482019-01-29 18:42:42 -0800402 ? outputDependentState.bufferTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700403 : static_cast<hal::Transform>(0);
404 if (auto error = hwcLayer->setTransform(static_cast<hal::Transform>(bufferTransform));
405 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700406 ALOGE("[%s] Failed to set transform %s: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800407 toString(outputDependentState.bufferTransform).c_str(), to_string(error).c_str(),
408 static_cast<int32_t>(error));
409 }
410}
411
412void OutputLayer::writeOutputIndependentGeometryStateToHWC(
Dan Stoza6166c312021-01-15 16:34:05 -0800413 HWC2::Layer* hwcLayer, const LayerFECompositionState& outputIndependentState,
414 bool skipLayer) {
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400415 // If there is a peekThroughLayer, then this layer has a hole in it. We need to use
416 // PREMULTIPLIED so it will peek through.
417 const auto& overrideInfo = getState().overrideInfo;
418 const auto blendMode = overrideInfo.buffer || overrideInfo.peekThroughLayer
Alec Mouriee69a592021-03-23 15:00:45 -0700419 ? hardware::graphics::composer::hal::BlendMode::PREMULTIPLIED
420 : outputIndependentState.blendMode;
421 if (auto error = hwcLayer->setBlendMode(blendMode); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700422 ALOGE("[%s] Failed to set blend mode %s: %s (%d)", getLayerFE().getDebugName(),
Alec Mouriee69a592021-03-23 15:00:45 -0700423 toString(blendMode).c_str(), to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800424 }
425
Alec Mouriee69a592021-03-23 15:00:45 -0700426 const float alpha = skipLayer
427 ? 0.0f
428 : (getState().overrideInfo.buffer ? 1.0f : outputIndependentState.alpha);
Dan Stoza6166c312021-01-15 16:34:05 -0800429 ALOGV("Writing alpha %f", alpha);
430
431 if (auto error = hwcLayer->setPlaneAlpha(alpha); error != hal::Error::NONE) {
432 ALOGE("[%s] Failed to set plane alpha %.3f: %s (%d)", getLayerFE().getDebugName(), alpha,
433 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800434 }
435
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800436 for (const auto& [name, entry] : outputIndependentState.metadata) {
437 if (auto error = hwcLayer->setLayerGenericMetadata(name, entry.mandatory, entry.value);
Peiyong Line9d809e2020-04-14 13:10:48 -0700438 error != hal::Error::NONE) {
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800439 ALOGE("[%s] Failed to set generic metadata %s %s (%d)", getLayerFE().getDebugName(),
440 name.c_str(), to_string(error).c_str(), static_cast<int32_t>(error));
441 }
442 }
Lloyd Piquef5275482019-01-29 18:42:42 -0800443}
444
445void OutputLayer::writeOutputDependentPerFrameStateToHWC(HWC2::Layer* hwcLayer) {
446 const auto& outputDependentState = getState();
447
Lloyd Piquea2468662019-03-07 21:31:06 -0800448 // TODO(lpique): b/121291683 outputSpaceVisibleRegion is output-dependent geometry
Lloyd Piquef5275482019-01-29 18:42:42 -0800449 // state and should not change every frame.
Alec Mouri464352b2021-03-24 16:33:21 -0700450 Region visibleRegion = outputDependentState.overrideInfo.buffer
451 ? Region(outputDependentState.overrideInfo.visibleRegion)
452 : outputDependentState.outputSpaceVisibleRegion;
453 if (auto error = hwcLayer->setVisibleRegion(visibleRegion); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700454 ALOGE("[%s] Failed to set visible region: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800455 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquea2468662019-03-07 21:31:06 -0800456 outputDependentState.outputSpaceVisibleRegion.dump(LOG_TAG);
Lloyd Piquef5275482019-01-29 18:42:42 -0800457 }
458
Alec Mourib7edfc22021-03-17 16:20:26 -0700459 const auto dataspace = outputDependentState.overrideInfo.buffer
460 ? outputDependentState.overrideInfo.dataspace
461 : outputDependentState.dataspace;
462
463 if (auto error = hwcLayer->setDataspace(dataspace); error != hal::Error::NONE) {
464 ALOGE("[%s] Failed to set dataspace %d: %s (%d)", getLayerFE().getDebugName(), dataspace,
465 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800466 }
467}
468
469void OutputLayer::writeOutputIndependentPerFrameStateToHWC(
470 HWC2::Layer* hwcLayer, const LayerFECompositionState& outputIndependentState) {
471 switch (auto error = hwcLayer->setColorTransform(outputIndependentState.colorTransform)) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700472 case hal::Error::NONE:
Lloyd Piquef5275482019-01-29 18:42:42 -0800473 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700474 case hal::Error::UNSUPPORTED:
Lloyd Piquef5275482019-01-29 18:42:42 -0800475 editState().forceClientComposition = true;
476 break;
477 default:
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700478 ALOGE("[%s] Failed to set color transform: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquea83776c2019-01-29 18:42:32 -0800479 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800480 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800481
Alec Mouri464352b2021-03-24 16:33:21 -0700482 const Region& surfaceDamage = getState().overrideInfo.buffer
483 ? getState().overrideInfo.damageRegion
484 : outputIndependentState.surfaceDamage;
485
486 if (auto error = hwcLayer->setSurfaceDamage(surfaceDamage); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700487 ALOGE("[%s] Failed to set surface damage: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800488 to_string(error).c_str(), static_cast<int32_t>(error));
489 outputIndependentState.surfaceDamage.dump(LOG_TAG);
490 }
491
492 // Content-specific per-frame state
493 switch (outputIndependentState.compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700494 case hal::Composition::SOLID_COLOR:
Lloyd Pique46b72df2019-10-29 13:19:27 -0700495 // For compatibility, should be written AFTER the composition type.
Lloyd Piquef5275482019-01-29 18:42:42 -0800496 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700497 case hal::Composition::SIDEBAND:
Lloyd Piquef5275482019-01-29 18:42:42 -0800498 writeSidebandStateToHWC(hwcLayer, outputIndependentState);
499 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700500 case hal::Composition::CURSOR:
501 case hal::Composition::DEVICE:
Lloyd Piquef5275482019-01-29 18:42:42 -0800502 writeBufferStateToHWC(hwcLayer, outputIndependentState);
503 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700504 case hal::Composition::INVALID:
505 case hal::Composition::CLIENT:
Lloyd Piquef5275482019-01-29 18:42:42 -0800506 // Ignored
507 break;
508 }
509}
510
511void OutputLayer::writeSolidColorStateToHWC(HWC2::Layer* hwcLayer,
512 const LayerFECompositionState& outputIndependentState) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700513 if (outputIndependentState.compositionType != hal::Composition::SOLID_COLOR) {
Lloyd Pique46b72df2019-10-29 13:19:27 -0700514 return;
515 }
516
Peiyong Line9d809e2020-04-14 13:10:48 -0700517 hal::Color color = {static_cast<uint8_t>(std::round(255.0f * outputIndependentState.color.r)),
518 static_cast<uint8_t>(std::round(255.0f * outputIndependentState.color.g)),
519 static_cast<uint8_t>(std::round(255.0f * outputIndependentState.color.b)),
520 255};
Lloyd Piquef5275482019-01-29 18:42:42 -0800521
Peiyong Line9d809e2020-04-14 13:10:48 -0700522 if (auto error = hwcLayer->setColor(color); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700523 ALOGE("[%s] Failed to set color: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800524 to_string(error).c_str(), static_cast<int32_t>(error));
525 }
526}
527
528void OutputLayer::writeSidebandStateToHWC(HWC2::Layer* hwcLayer,
529 const LayerFECompositionState& outputIndependentState) {
530 if (auto error = hwcLayer->setSidebandStream(outputIndependentState.sidebandStream->handle());
Peiyong Line9d809e2020-04-14 13:10:48 -0700531 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700532 ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800533 outputIndependentState.sidebandStream->handle(), to_string(error).c_str(),
534 static_cast<int32_t>(error));
535 }
536}
537
538void OutputLayer::writeBufferStateToHWC(HWC2::Layer* hwcLayer,
539 const LayerFECompositionState& outputIndependentState) {
540 auto supportedPerFrameMetadata =
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700541 getOutput().getDisplayColorProfile()->getSupportedPerFrameMetadata();
Lloyd Piquef5275482019-01-29 18:42:42 -0800542 if (auto error = hwcLayer->setPerFrameMetadata(supportedPerFrameMetadata,
543 outputIndependentState.hdrMetadata);
Peiyong Line9d809e2020-04-14 13:10:48 -0700544 error != hal::Error::NONE && error != hal::Error::UNSUPPORTED) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700545 ALOGE("[%s] Failed to set hdrMetadata: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800546 to_string(error).c_str(), static_cast<int32_t>(error));
547 }
548
Dan Stoza6166c312021-01-15 16:34:05 -0800549 sp<GraphicBuffer> buffer = outputIndependentState.buffer;
550 sp<Fence> acquireFence = outputIndependentState.acquireFence;
551 if (getState().overrideInfo.buffer != nullptr) {
Alec Mouria90a5702021-04-16 16:36:21 +0000552 buffer = getState().overrideInfo.buffer->getBuffer();
Dan Stoza6166c312021-01-15 16:34:05 -0800553 acquireFence = getState().overrideInfo.acquireFence;
554 }
555
556 ALOGV("Writing buffer %p", buffer.get());
557
Lloyd Piquef5275482019-01-29 18:42:42 -0800558 uint32_t hwcSlot = 0;
559 sp<GraphicBuffer> hwcBuffer;
560 // We need access to the output-dependent state for the buffer cache there,
561 // though otherwise the buffer is not output-dependent.
Dan Stoza6166c312021-01-15 16:34:05 -0800562 editState().hwc->hwcBufferCache.getHwcBuffer(outputIndependentState.bufferSlot, buffer,
563 &hwcSlot, &hwcBuffer);
Lloyd Piquef5275482019-01-29 18:42:42 -0800564
Dan Stoza6166c312021-01-15 16:34:05 -0800565 if (auto error = hwcLayer->setBuffer(hwcSlot, hwcBuffer, acquireFence);
Peiyong Line9d809e2020-04-14 13:10:48 -0700566 error != hal::Error::NONE) {
Dan Stoza6166c312021-01-15 16:34:05 -0800567 ALOGE("[%s] Failed to set buffer %p: %s (%d)", getLayerFE().getDebugName(), buffer->handle,
568 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800569 }
570}
571
Peiyong Line9d809e2020-04-14 13:10:48 -0700572void OutputLayer::writeCompositionTypeToHWC(HWC2::Layer* hwcLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400573 hal::Composition requestedCompositionType,
574 bool isPeekingThrough) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800575 auto& outputDependentState = editState();
576
577 // If we are forcing client composition, we need to tell the HWC
Leon Scroggins IIId305ef22021-04-06 09:53:26 -0400578 if (outputDependentState.forceClientComposition ||
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400579 (!isPeekingThrough && getLayerFE().hasRoundedCorners())) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700580 requestedCompositionType = hal::Composition::CLIENT;
Lloyd Piquef5275482019-01-29 18:42:42 -0800581 }
582
583 // Set the requested composition type with the HWC whenever it changes
584 if (outputDependentState.hwc->hwcCompositionType != requestedCompositionType) {
585 outputDependentState.hwc->hwcCompositionType = requestedCompositionType;
586
Peiyong Line9d809e2020-04-14 13:10:48 -0700587 if (auto error = hwcLayer->setCompositionType(requestedCompositionType);
588 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700589 ALOGE("[%s] Failed to set composition type %s: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800590 toString(requestedCompositionType).c_str(), to_string(error).c_str(),
Lloyd Piquea83776c2019-01-29 18:42:32 -0800591 static_cast<int32_t>(error));
592 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800593 }
594}
595
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800596void OutputLayer::writeCursorPositionToHWC() const {
597 // Skip doing this if there is no HWC interface
598 auto hwcLayer = getHwcLayer();
599 if (!hwcLayer) {
600 return;
601 }
602
Lloyd Piquede196652020-01-22 17:29:58 -0800603 const auto* layerFEState = getLayerFE().getCompositionState();
604 if (!layerFEState) {
605 return;
606 }
607
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700608 const auto& outputState = getOutput().getState();
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800609
Lloyd Piquede196652020-01-22 17:29:58 -0800610 Rect frame = layerFEState->cursorFrame;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200611 frame.intersect(outputState.layerStackSpace.content, &frame);
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800612 Rect position = outputState.transform.transform(frame);
613
614 if (auto error = hwcLayer->setCursorPosition(position.left, position.top);
Peiyong Line9d809e2020-04-14 13:10:48 -0700615 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700616 ALOGE("[%s] Failed to set cursor position to (%d, %d): %s (%d)",
617 getLayerFE().getDebugName(), position.left, position.top, to_string(error).c_str(),
618 static_cast<int32_t>(error));
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800619 }
620}
621
Lloyd Pique66d68602019-02-13 14:23:31 -0800622HWC2::Layer* OutputLayer::getHwcLayer() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700623 const auto& state = getState();
624 return state.hwc ? state.hwc->hwcLayer.get() : nullptr;
Lloyd Pique66d68602019-02-13 14:23:31 -0800625}
626
627bool OutputLayer::requiresClientComposition() 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::CLIENT;
Lloyd Pique66d68602019-02-13 14:23:31 -0800630}
631
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800632bool OutputLayer::isHardwareCursor() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700633 const auto& state = getState();
Peiyong Line9d809e2020-04-14 13:10:48 -0700634 return state.hwc && state.hwc->hwcCompositionType == hal::Composition::CURSOR;
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800635}
636
Peiyong Line9d809e2020-04-14 13:10:48 -0700637void OutputLayer::detectDisallowedCompositionTypeChange(hal::Composition from,
638 hal::Composition to) const {
Lloyd Pique66d68602019-02-13 14:23:31 -0800639 bool result = false;
640 switch (from) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700641 case hal::Composition::INVALID:
642 case hal::Composition::CLIENT:
Lloyd Pique66d68602019-02-13 14:23:31 -0800643 result = false;
644 break;
645
Peiyong Line9d809e2020-04-14 13:10:48 -0700646 case hal::Composition::DEVICE:
647 case hal::Composition::SOLID_COLOR:
648 result = (to == hal::Composition::CLIENT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800649 break;
650
Peiyong Line9d809e2020-04-14 13:10:48 -0700651 case hal::Composition::CURSOR:
652 case hal::Composition::SIDEBAND:
653 result = (to == hal::Composition::CLIENT || to == hal::Composition::DEVICE);
Lloyd Pique66d68602019-02-13 14:23:31 -0800654 break;
655 }
656
657 if (!result) {
658 ALOGE("[%s] Invalid device requested composition type change: %s (%d) --> %s (%d)",
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700659 getLayerFE().getDebugName(), toString(from).c_str(), static_cast<int>(from),
Lloyd Pique66d68602019-02-13 14:23:31 -0800660 toString(to).c_str(), static_cast<int>(to));
661 }
662}
663
Peiyong Line9d809e2020-04-14 13:10:48 -0700664void OutputLayer::applyDeviceCompositionTypeChange(hal::Composition compositionType) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700665 auto& state = editState();
666 LOG_FATAL_IF(!state.hwc);
667 auto& hwcState = *state.hwc;
Lloyd Pique66d68602019-02-13 14:23:31 -0800668
669 detectDisallowedCompositionTypeChange(hwcState.hwcCompositionType, compositionType);
670
671 hwcState.hwcCompositionType = compositionType;
672}
673
674void OutputLayer::prepareForDeviceLayerRequests() {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700675 auto& state = editState();
676 state.clearClientTarget = false;
Lloyd Pique66d68602019-02-13 14:23:31 -0800677}
678
Peiyong Line9d809e2020-04-14 13:10:48 -0700679void OutputLayer::applyDeviceLayerRequest(hal::LayerRequest request) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700680 auto& state = editState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800681 switch (request) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700682 case hal::LayerRequest::CLEAR_CLIENT_TARGET:
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700683 state.clearClientTarget = true;
Lloyd Pique66d68602019-02-13 14:23:31 -0800684 break;
685
686 default:
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700687 ALOGE("[%s] Unknown device layer request %s (%d)", getLayerFE().getDebugName(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800688 toString(request).c_str(), static_cast<int>(request));
689 break;
690 }
691}
692
Lloyd Pique688abd42019-02-15 15:42:24 -0800693bool OutputLayer::needsFiltering() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700694 const auto& state = getState();
695 const auto& displayFrame = state.displayFrame;
696 const auto& sourceCrop = state.sourceCrop;
Lloyd Pique688abd42019-02-15 15:42:24 -0800697 return sourceCrop.getHeight() != displayFrame.getHeight() ||
698 sourceCrop.getWidth() != displayFrame.getWidth();
699}
700
Dan Stoza6166c312021-01-15 16:34:05 -0800701std::vector<LayerFE::LayerSettings> OutputLayer::getOverrideCompositionList() const {
702 if (getState().overrideInfo.buffer == nullptr) {
703 return {};
704 }
705
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700706 // Compute the geometry boundaries in layer stack space: we need to transform from the
707 // framebuffer space of the override buffer to layer space.
708 const ProjectionSpace& layerSpace = getOutput().getState().layerStackSpace;
709 const ui::Transform transform = getState().overrideInfo.displaySpace.getTransform(layerSpace);
710 const Rect boundaries = transform.transform(getState().overrideInfo.displayFrame);
711
Dan Stoza6166c312021-01-15 16:34:05 -0800712 LayerFE::LayerSettings settings;
713 settings.geometry = renderengine::Geometry{
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700714 .boundaries = boundaries.toFloatRect(),
Dan Stoza6166c312021-01-15 16:34:05 -0800715 };
Alec Mouria90a5702021-04-16 16:36:21 +0000716 settings.bufferId = getState().overrideInfo.buffer->getBuffer()->getId();
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700717 settings.source = renderengine::PixelSource{
718 .buffer = renderengine::Buffer{
719 .buffer = getState().overrideInfo.buffer,
720 .fence = getState().overrideInfo.acquireFence,
721 // If the transform from layer space to display space contains a rotation, we
722 // need to undo the rotation in the texture transform
723 .textureTransform =
724 ui::Transform(transform.inverse().getOrientation(), 1, 1).asMatrix4(),
725 }};
Alec Mouri9c8fce02021-03-12 18:30:42 -0800726 settings.sourceDataspace = getState().overrideInfo.dataspace;
Dan Stoza6166c312021-01-15 16:34:05 -0800727 settings.alpha = 1.0f;
728
729 return {static_cast<LayerFE::LayerSettings>(settings)};
730}
731
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800732void OutputLayer::dump(std::string& out) const {
733 using android::base::StringAppendF;
734
Lloyd Piquede196652020-01-22 17:29:58 -0800735 StringAppendF(&out, " - Output Layer %p(%s)\n", this, getLayerFE().getDebugName());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700736 dumpState(out);
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800737}
738
Lloyd Piquecc01a452018-12-04 17:24:00 -0800739} // namespace impl
740} // namespace android::compositionengine