blob: 01da0703474a2a5aa1ae0d18dd5861e873bbccd2 [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>
Alec Mourie7cc1c22021-04-27 15:23:26 -070021#include <compositionengine/impl/HwcBufferCache.h>
Lloyd Piquea83776c2019-01-29 18:42:32 -080022#include <compositionengine/impl/OutputCompositionState.h>
Lloyd Piquecc01a452018-12-04 17:24:00 -080023#include <compositionengine/impl/OutputLayer.h>
Lloyd Piquea83776c2019-01-29 18:42:32 -080024#include <compositionengine/impl/OutputLayerCompositionState.h>
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -040025#include <cstdint>
Lloyd Piquecc01a452018-12-04 17:24:00 -080026
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080027// TODO(b/129481165): remove the #pragma below and fix conversion issues
28#pragma clang diagnostic push
29#pragma clang diagnostic ignored "-Wconversion"
30
Lloyd Pique07e33212018-12-18 16:33:37 -080031#include "DisplayHardware/HWComposer.h"
32
Lloyd Pique3b5a69e2020-01-16 17:51:01 -080033// TODO(b/129481165): remove the #pragma below and fix conversion issues
34#pragma clang diagnostic pop // ignored "-Wconversion"
35
Lloyd Piquecc01a452018-12-04 17:24:00 -080036namespace android::compositionengine {
37
38OutputLayer::~OutputLayer() = default;
39
40namespace impl {
41
Lloyd Piquea83776c2019-01-29 18:42:32 -080042namespace {
43
44FloatRect reduce(const FloatRect& win, const Region& exclude) {
45 if (CC_LIKELY(exclude.isEmpty())) {
46 return win;
47 }
48 // Convert through Rect (by rounding) for lack of FloatRegion
49 return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect();
50}
51
52} // namespace
53
Lloyd Piquede196652020-01-22 17:29:58 -080054std::unique_ptr<OutputLayer> createOutputLayer(const compositionengine::Output& output,
55 const sp<compositionengine::LayerFE>& layerFE) {
56 return createOutputLayerTemplated<OutputLayer>(output, layerFE);
Lloyd Piquecc01a452018-12-04 17:24:00 -080057}
58
Lloyd Piquecc01a452018-12-04 17:24:00 -080059OutputLayer::~OutputLayer() = default;
60
Lloyd Piquedf336d92019-03-07 21:38:42 -080061void OutputLayer::setHwcLayer(std::shared_ptr<HWC2::Layer> hwcLayer) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070062 auto& state = editState();
Lloyd Piquedf336d92019-03-07 21:38:42 -080063 if (hwcLayer) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070064 state.hwc.emplace(std::move(hwcLayer));
Lloyd Piquedf336d92019-03-07 21:38:42 -080065 } else {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -070066 state.hwc.reset();
Lloyd Pique07e33212018-12-18 16:33:37 -080067 }
Lloyd Pique07e33212018-12-18 16:33:37 -080068}
69
Lloyd Piquea83776c2019-01-29 18:42:32 -080070Rect OutputLayer::calculateInitialCrop() const {
Lloyd Piquede196652020-01-22 17:29:58 -080071 const auto& layerState = *getLayerFE().getCompositionState();
Lloyd Piquea83776c2019-01-29 18:42:32 -080072
73 // apply the projection's clipping to the window crop in
74 // layerstack space, and convert-back to layer space.
75 // if there are no window scaling involved, this operation will map to full
76 // pixels in the buffer.
77
78 FloatRect activeCropFloat =
Lloyd Piquec6687342019-03-07 21:34:57 -080079 reduce(layerState.geomLayerBounds, layerState.transparentRegionHint);
Lloyd Piquea83776c2019-01-29 18:42:32 -080080
Marin Shalamanov6ad317c2020-07-29 23:34:07 +020081 const Rect& viewport = getOutput().getState().layerStackSpace.content;
Lloyd Piquea83776c2019-01-29 18:42:32 -080082 const ui::Transform& layerTransform = layerState.geomLayerTransform;
83 const ui::Transform& inverseLayerTransform = layerState.geomInverseLayerTransform;
84 // Transform to screen space.
85 activeCropFloat = layerTransform.transform(activeCropFloat);
86 activeCropFloat = activeCropFloat.intersect(viewport.toFloatRect());
87 // Back to layer space to work with the content crop.
88 activeCropFloat = inverseLayerTransform.transform(activeCropFloat);
89
90 // This needs to be here as transform.transform(Rect) computes the
91 // transformed rect and then takes the bounding box of the result before
92 // returning. This means
93 // transform.inverse().transform(transform.transform(Rect)) != Rect
94 // in which case we need to make sure the final rect is clipped to the
95 // display bounds.
96 Rect activeCrop{activeCropFloat};
97 if (!activeCrop.intersect(layerState.geomBufferSize, &activeCrop)) {
98 activeCrop.clear();
99 }
100 return activeCrop;
101}
102
103FloatRect OutputLayer::calculateOutputSourceCrop() const {
Lloyd Piquede196652020-01-22 17:29:58 -0800104 const auto& layerState = *getLayerFE().getCompositionState();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700105 const auto& outputState = getOutput().getState();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800106
107 if (!layerState.geomUsesSourceCrop) {
108 return {};
109 }
110
111 // the content crop is the area of the content that gets scaled to the
112 // layer's size. This is in buffer space.
113 FloatRect crop = layerState.geomContentCrop.toFloatRect();
114
115 // In addition there is a WM-specified crop we pull from our drawing state.
116 Rect activeCrop = calculateInitialCrop();
117 const Rect& bufferSize = layerState.geomBufferSize;
118
119 int winWidth = bufferSize.getWidth();
120 int winHeight = bufferSize.getHeight();
121
122 // The bufferSize for buffer state layers can be unbounded ([0, 0, -1, -1])
123 // if display frame hasn't been set and the parent is an unbounded layer.
124 if (winWidth < 0 && winHeight < 0) {
125 return crop;
126 }
127
128 // Transform the window crop to match the buffer coordinate system,
129 // which means using the inverse of the current transform set on the
130 // SurfaceFlingerConsumer.
131 uint32_t invTransform = layerState.geomBufferTransform;
132 if (layerState.geomBufferUsesDisplayInverseTransform) {
133 /*
134 * the code below applies the primary display's inverse transform to the
135 * buffer
136 */
Marin Shalamanov68933fb2020-09-10 17:58:12 +0200137 uint32_t invTransformOrient =
138 ui::Transform::toRotationFlags(outputState.displaySpace.orientation);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800139 // calculate the inverse transform
140 if (invTransformOrient & HAL_TRANSFORM_ROT_90) {
141 invTransformOrient ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H;
142 }
143 // and apply to the current transform
144 invTransform =
145 (ui::Transform(invTransformOrient) * ui::Transform(invTransform)).getOrientation();
146 }
147
148 if (invTransform & HAL_TRANSFORM_ROT_90) {
149 // If the activeCrop has been rotate the ends are rotated but not
150 // the space itself so when transforming ends back we can't rely on
151 // a modification of the axes of rotation. To account for this we
152 // need to reorient the inverse rotation in terms of the current
153 // axes of rotation.
Marin Shalamanovcfeebd42020-05-15 15:23:49 +0200154 bool isHFlipped = (invTransform & HAL_TRANSFORM_FLIP_H) != 0;
155 bool isVFlipped = (invTransform & HAL_TRANSFORM_FLIP_V) != 0;
156 if (isHFlipped == isVFlipped) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800157 invTransform ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H;
158 }
159 std::swap(winWidth, winHeight);
160 }
161 const Rect winCrop =
162 activeCrop.transform(invTransform, bufferSize.getWidth(), bufferSize.getHeight());
163
164 // below, crop is intersected with winCrop expressed in crop's coordinate space
Marin Shalamanovcfeebd42020-05-15 15:23:49 +0200165 const float xScale = crop.getWidth() / float(winWidth);
166 const float yScale = crop.getHeight() / float(winHeight);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800167
Marin Shalamanovcfeebd42020-05-15 15:23:49 +0200168 const float insetLeft = winCrop.left * xScale;
169 const float insetTop = winCrop.top * yScale;
170 const float insetRight = (winWidth - winCrop.right) * xScale;
171 const float insetBottom = (winHeight - winCrop.bottom) * yScale;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800172
Marin Shalamanovcfeebd42020-05-15 15:23:49 +0200173 crop.left += insetLeft;
174 crop.top += insetTop;
175 crop.right -= insetRight;
176 crop.bottom -= insetBottom;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800177
178 return crop;
179}
180
181Rect OutputLayer::calculateOutputDisplayFrame() const {
Lloyd Piquede196652020-01-22 17:29:58 -0800182 const auto& layerState = *getLayerFE().getCompositionState();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700183 const auto& outputState = getOutput().getState();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800184
185 // apply the layer's transform, followed by the display's global transform
186 // here we're guaranteed that the layer's transform preserves rects
Lloyd Piquec6687342019-03-07 21:34:57 -0800187 Region activeTransparentRegion = layerState.transparentRegionHint;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800188 const ui::Transform& layerTransform = layerState.geomLayerTransform;
189 const ui::Transform& inverseLayerTransform = layerState.geomInverseLayerTransform;
190 const Rect& bufferSize = layerState.geomBufferSize;
191 Rect activeCrop = layerState.geomCrop;
192 if (!activeCrop.isEmpty() && bufferSize.isValid()) {
193 activeCrop = layerTransform.transform(activeCrop);
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200194 if (!activeCrop.intersect(outputState.layerStackSpace.content, &activeCrop)) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800195 activeCrop.clear();
196 }
197 activeCrop = inverseLayerTransform.transform(activeCrop, true);
198 // This needs to be here as transform.transform(Rect) computes the
199 // transformed rect and then takes the bounding box of the result before
200 // returning. This means
201 // transform.inverse().transform(transform.transform(Rect)) != Rect
202 // in which case we need to make sure the final rect is clipped to the
203 // display bounds.
204 if (!activeCrop.intersect(bufferSize, &activeCrop)) {
205 activeCrop.clear();
206 }
207 // mark regions outside the crop as transparent
208 activeTransparentRegion.orSelf(Rect(0, 0, bufferSize.getWidth(), activeCrop.top));
209 activeTransparentRegion.orSelf(
210 Rect(0, activeCrop.bottom, bufferSize.getWidth(), bufferSize.getHeight()));
211 activeTransparentRegion.orSelf(Rect(0, activeCrop.top, activeCrop.left, activeCrop.bottom));
212 activeTransparentRegion.orSelf(
213 Rect(activeCrop.right, activeCrop.top, bufferSize.getWidth(), activeCrop.bottom));
214 }
215
216 // reduce uses a FloatRect to provide more accuracy during the
217 // transformation. We then round upon constructing 'frame'.
218 Rect frame{
219 layerTransform.transform(reduce(layerState.geomLayerBounds, activeTransparentRegion))};
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200220 if (!frame.intersect(outputState.layerStackSpace.content, &frame)) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800221 frame.clear();
222 }
223 const ui::Transform displayTransform{outputState.transform};
224
225 return displayTransform.transform(frame);
226}
227
Snild Dolkow9e217d62020-04-22 15:53:42 +0200228uint32_t OutputLayer::calculateOutputRelativeBufferTransform(
229 uint32_t internalDisplayRotationFlags) const {
Lloyd Piquede196652020-01-22 17:29:58 -0800230 const auto& layerState = *getLayerFE().getCompositionState();
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700231 const auto& outputState = getOutput().getState();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800232
233 /*
234 * Transformations are applied in this order:
235 * 1) buffer orientation/flip/mirror
236 * 2) state transformation (window manager)
237 * 3) layer orientation (screen orientation)
238 * (NOTE: the matrices are multiplied in reverse order)
239 */
240 const ui::Transform& layerTransform = layerState.geomLayerTransform;
Rashed Abdel-Tawab6643cd82019-10-29 10:01:56 -0700241 const ui::Transform displayTransform{outputState.transform};
Lloyd Piquea83776c2019-01-29 18:42:32 -0800242 const ui::Transform bufferTransform{layerState.geomBufferTransform};
243 ui::Transform transform(displayTransform * layerTransform * bufferTransform);
244
245 if (layerState.geomBufferUsesDisplayInverseTransform) {
246 /*
Snild Dolkow9e217d62020-04-22 15:53:42 +0200247 * We must apply the internal display's inverse transform to the buffer
248 * transform, and not the one for the output this layer is on.
Lloyd Piquea83776c2019-01-29 18:42:32 -0800249 */
Snild Dolkow9e217d62020-04-22 15:53:42 +0200250 uint32_t invTransform = internalDisplayRotationFlags;
251
Lloyd Piquea83776c2019-01-29 18:42:32 -0800252 // calculate the inverse transform
253 if (invTransform & HAL_TRANSFORM_ROT_90) {
254 invTransform ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H;
255 }
256
257 /*
258 * Here we cancel out the orientation component of the WM transform.
259 * The scaling and translate components are already included in our bounds
260 * computation so it's enough to just omit it in the composition.
261 * See comment in BufferLayer::prepareClientLayer with ref to b/36727915 for why.
262 */
Lloyd Pique546a2452019-03-18 20:53:27 +0000263 transform = ui::Transform(invTransform) * displayTransform * bufferTransform;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800264 }
265
266 // this gives us only the "orientation" component of the transform
267 return transform.getOrientation();
Snild Dolkow9e217d62020-04-22 15:53:42 +0200268}
Lloyd Piquea83776c2019-01-29 18:42:32 -0800269
Snild Dolkow9e217d62020-04-22 15:53:42 +0200270void OutputLayer::updateCompositionState(
271 bool includeGeometry, bool forceClientComposition,
272 ui::Transform::RotationFlags internalDisplayRotationFlags) {
Lloyd Piquede196652020-01-22 17:29:58 -0800273 const auto* layerFEState = getLayerFE().getCompositionState();
274 if (!layerFEState) {
275 return;
276 }
277
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700278 const auto& outputState = getOutput().getState();
279 const auto& profile = *getOutput().getDisplayColorProfile();
280 auto& state = editState();
Lloyd Piquef5275482019-01-29 18:42:42 -0800281
Lloyd Piquea83776c2019-01-29 18:42:32 -0800282 if (includeGeometry) {
Lloyd Piquefe671022019-09-24 10:43:03 -0700283 // Clear the forceClientComposition flag before it is set for any
284 // reason. Note that since it can be set by some checks below when
285 // updating the geometry state, we only clear it when updating the
286 // geometry since those conditions for forcing client composition won't
287 // go away otherwise.
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700288 state.forceClientComposition = false;
Lloyd Piquefe671022019-09-24 10:43:03 -0700289
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700290 state.displayFrame = calculateOutputDisplayFrame();
291 state.sourceCrop = calculateOutputSourceCrop();
Snild Dolkow9e217d62020-04-22 15:53:42 +0200292 state.bufferTransform = static_cast<Hwc2::Transform>(
293 calculateOutputRelativeBufferTransform(internalDisplayRotationFlags));
Lloyd Piquea83776c2019-01-29 18:42:32 -0800294
Lloyd Piquede196652020-01-22 17:29:58 -0800295 if ((layerFEState->isSecure && !outputState.isSecure) ||
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700296 (state.bufferTransform & ui::Transform::ROT_INVALID)) {
297 state.forceClientComposition = true;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800298 }
299 }
Lloyd Piquef5275482019-01-29 18:42:42 -0800300
301 // Determine the output dependent dataspace for this layer. If it is
302 // colorspace agnostic, it just uses the dataspace chosen for the output to
303 // avoid the need for color conversion.
Lloyd Piquede196652020-01-22 17:29:58 -0800304 state.dataspace = layerFEState->isColorspaceAgnostic &&
Lloyd Piquef5275482019-01-29 18:42:42 -0800305 outputState.targetDataspace != ui::Dataspace::UNKNOWN
306 ? outputState.targetDataspace
Lloyd Piquede196652020-01-22 17:29:58 -0800307 : layerFEState->dataspace;
Lloyd Piquef5275482019-01-29 18:42:42 -0800308
Lloyd Piquef5275482019-01-29 18:42:42 -0800309 // These are evaluated every frame as they can potentially change at any
310 // time.
Lloyd Piquede196652020-01-22 17:29:58 -0800311 if (layerFEState->forceClientComposition || !profile.isDataspaceSupported(state.dataspace) ||
Lloyd Pique7a234912019-10-03 11:54:27 -0700312 forceClientComposition) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700313 state.forceClientComposition = true;
Lloyd Piquef5275482019-01-29 18:42:42 -0800314 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800315}
316
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400317void OutputLayer::writeStateToHWC(bool includeGeometry, bool skipLayer, uint32_t z,
318 bool zIsOverridden, bool isPeekingThrough) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700319 const auto& state = getState();
Lloyd Piquea83776c2019-01-29 18:42:32 -0800320 // Skip doing this if there is no HWC interface
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700321 if (!state.hwc) {
Lloyd Piquea83776c2019-01-29 18:42:32 -0800322 return;
323 }
324
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700325 auto& hwcLayer = (*state.hwc).hwcLayer;
Lloyd Piquea83776c2019-01-29 18:42:32 -0800326 if (!hwcLayer) {
327 ALOGE("[%s] failed to write composition state to HWC -- no hwcLayer for output %s",
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700328 getLayerFE().getDebugName(), getOutput().getName().c_str());
Lloyd Piquea83776c2019-01-29 18:42:32 -0800329 return;
330 }
331
Lloyd Piquede196652020-01-22 17:29:58 -0800332 const auto* outputIndependentState = getLayerFE().getCompositionState();
333 if (!outputIndependentState) {
334 return;
335 }
336
337 auto requestedCompositionType = outputIndependentState->compositionType;
Lloyd Piquef5275482019-01-29 18:42:42 -0800338
Yichi Chen413d46a2021-04-07 21:42:09 +0800339 // TODO(b/181172795): We now update geometry for all flattened layers. We should update it
340 // only when the geometry actually changes
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400341 const bool isOverridden =
342 state.overrideInfo.buffer != nullptr || isPeekingThrough || zIsOverridden;
Yichi Chen413d46a2021-04-07 21:42:09 +0800343 const bool prevOverridden = state.hwc->stateOverridden;
344 if (isOverridden || prevOverridden || skipLayer || includeGeometry) {
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400345 writeOutputDependentGeometryStateToHWC(hwcLayer.get(), requestedCompositionType, z);
Dan Stoza6166c312021-01-15 16:34:05 -0800346 writeOutputIndependentGeometryStateToHWC(hwcLayer.get(), *outputIndependentState,
347 skipLayer);
Lloyd Piquef5275482019-01-29 18:42:42 -0800348 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800349
Lloyd Piquef5275482019-01-29 18:42:42 -0800350 writeOutputDependentPerFrameStateToHWC(hwcLayer.get());
Lloyd Piquede196652020-01-22 17:29:58 -0800351 writeOutputIndependentPerFrameStateToHWC(hwcLayer.get(), *outputIndependentState);
Lloyd Piquea83776c2019-01-29 18:42:32 -0800352
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400353 writeCompositionTypeToHWC(hwcLayer.get(), requestedCompositionType, isPeekingThrough);
Lloyd Pique46b72df2019-10-29 13:19:27 -0700354
355 // Always set the layer color after setting the composition type.
Lloyd Piquede196652020-01-22 17:29:58 -0800356 writeSolidColorStateToHWC(hwcLayer.get(), *outputIndependentState);
Yichi Chen413d46a2021-04-07 21:42:09 +0800357
358 editState().hwc->stateOverridden = isOverridden;
Lloyd Piquef5275482019-01-29 18:42:42 -0800359}
Lloyd Piquea83776c2019-01-29 18:42:32 -0800360
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400361void OutputLayer::writeOutputDependentGeometryStateToHWC(HWC2::Layer* hwcLayer,
362 hal::Composition requestedCompositionType,
363 uint32_t z) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800364 const auto& outputDependentState = getState();
365
Dan Stoza6166c312021-01-15 16:34:05 -0800366 Rect displayFrame = outputDependentState.displayFrame;
367 FloatRect sourceCrop = outputDependentState.sourceCrop;
Huihong Luoa5825112021-03-24 12:28:29 -0700368
Alec Mouri464352b2021-03-24 16:33:21 -0700369 if (outputDependentState.overrideInfo.buffer != nullptr) {
Dan Stoza6166c312021-01-15 16:34:05 -0800370 displayFrame = outputDependentState.overrideInfo.displayFrame;
Alec Mouri03bf0ff2021-04-19 14:17:31 -0700371 sourceCrop =
372 FloatRect(0.f, 0.f,
373 static_cast<float>(outputDependentState.overrideInfo.buffer->getBuffer()
374 ->getWidth()),
375 static_cast<float>(outputDependentState.overrideInfo.buffer->getBuffer()
376 ->getHeight()));
Lloyd Piquef5275482019-01-29 18:42:42 -0800377 }
378
Dan Stoza6166c312021-01-15 16:34:05 -0800379 ALOGV("Writing display frame [%d, %d, %d, %d]", displayFrame.left, displayFrame.top,
380 displayFrame.right, displayFrame.bottom);
381
382 if (auto error = hwcLayer->setDisplayFrame(displayFrame); error != hal::Error::NONE) {
383 ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)",
384 getLayerFE().getDebugName(), displayFrame.left, displayFrame.top, displayFrame.right,
385 displayFrame.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
386 }
387
388 if (auto error = hwcLayer->setSourceCrop(sourceCrop); error != hal::Error::NONE) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800389 ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: "
390 "%s (%d)",
Dan Stoza6166c312021-01-15 16:34:05 -0800391 getLayerFE().getDebugName(), sourceCrop.left, sourceCrop.top, sourceCrop.right,
392 sourceCrop.bottom, to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800393 }
394
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400395 if (auto error = hwcLayer->setZOrder(z); error != hal::Error::NONE) {
396 ALOGE("[%s] Failed to set Z %u: %s (%d)", getLayerFE().getDebugName(), z,
397 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800398 }
399
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700400 // Solid-color layers and overridden buffers should always use an identity transform.
401 const auto bufferTransform = (requestedCompositionType != hal::Composition::SOLID_COLOR &&
402 getState().overrideInfo.buffer == nullptr)
Lloyd Piquef5275482019-01-29 18:42:42 -0800403 ? outputDependentState.bufferTransform
Peiyong Line9d809e2020-04-14 13:10:48 -0700404 : static_cast<hal::Transform>(0);
405 if (auto error = hwcLayer->setTransform(static_cast<hal::Transform>(bufferTransform));
406 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700407 ALOGE("[%s] Failed to set transform %s: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800408 toString(outputDependentState.bufferTransform).c_str(), to_string(error).c_str(),
409 static_cast<int32_t>(error));
410 }
411}
412
413void OutputLayer::writeOutputIndependentGeometryStateToHWC(
Dan Stoza6166c312021-01-15 16:34:05 -0800414 HWC2::Layer* hwcLayer, const LayerFECompositionState& outputIndependentState,
415 bool skipLayer) {
Leon Scroggins IIIe2ee0402021-04-02 16:59:37 -0400416 // If there is a peekThroughLayer, then this layer has a hole in it. We need to use
417 // PREMULTIPLIED so it will peek through.
418 const auto& overrideInfo = getState().overrideInfo;
419 const auto blendMode = overrideInfo.buffer || overrideInfo.peekThroughLayer
Alec Mouriee69a592021-03-23 15:00:45 -0700420 ? hardware::graphics::composer::hal::BlendMode::PREMULTIPLIED
421 : outputIndependentState.blendMode;
422 if (auto error = hwcLayer->setBlendMode(blendMode); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700423 ALOGE("[%s] Failed to set blend mode %s: %s (%d)", getLayerFE().getDebugName(),
Alec Mouriee69a592021-03-23 15:00:45 -0700424 toString(blendMode).c_str(), to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800425 }
426
Alec Mouriee69a592021-03-23 15:00:45 -0700427 const float alpha = skipLayer
428 ? 0.0f
429 : (getState().overrideInfo.buffer ? 1.0f : outputIndependentState.alpha);
Dan Stoza6166c312021-01-15 16:34:05 -0800430 ALOGV("Writing alpha %f", alpha);
431
432 if (auto error = hwcLayer->setPlaneAlpha(alpha); error != hal::Error::NONE) {
433 ALOGE("[%s] Failed to set plane alpha %.3f: %s (%d)", getLayerFE().getDebugName(), alpha,
434 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800435 }
436
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800437 for (const auto& [name, entry] : outputIndependentState.metadata) {
438 if (auto error = hwcLayer->setLayerGenericMetadata(name, entry.mandatory, entry.value);
Peiyong Line9d809e2020-04-14 13:10:48 -0700439 error != hal::Error::NONE) {
Lloyd Pique8d9f8362020-02-11 19:13:09 -0800440 ALOGE("[%s] Failed to set generic metadata %s %s (%d)", getLayerFE().getDebugName(),
441 name.c_str(), to_string(error).c_str(), static_cast<int32_t>(error));
442 }
443 }
Lloyd Piquef5275482019-01-29 18:42:42 -0800444}
445
446void OutputLayer::writeOutputDependentPerFrameStateToHWC(HWC2::Layer* hwcLayer) {
447 const auto& outputDependentState = getState();
448
Lloyd Piquea2468662019-03-07 21:31:06 -0800449 // TODO(lpique): b/121291683 outputSpaceVisibleRegion is output-dependent geometry
Lloyd Piquef5275482019-01-29 18:42:42 -0800450 // state and should not change every frame.
Alec Mouri464352b2021-03-24 16:33:21 -0700451 Region visibleRegion = outputDependentState.overrideInfo.buffer
452 ? Region(outputDependentState.overrideInfo.visibleRegion)
453 : outputDependentState.outputSpaceVisibleRegion;
454 if (auto error = hwcLayer->setVisibleRegion(visibleRegion); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700455 ALOGE("[%s] Failed to set visible region: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800456 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquea2468662019-03-07 21:31:06 -0800457 outputDependentState.outputSpaceVisibleRegion.dump(LOG_TAG);
Lloyd Piquef5275482019-01-29 18:42:42 -0800458 }
459
Alec Mourib7edfc22021-03-17 16:20:26 -0700460 const auto dataspace = outputDependentState.overrideInfo.buffer
461 ? outputDependentState.overrideInfo.dataspace
462 : outputDependentState.dataspace;
463
464 if (auto error = hwcLayer->setDataspace(dataspace); error != hal::Error::NONE) {
465 ALOGE("[%s] Failed to set dataspace %d: %s (%d)", getLayerFE().getDebugName(), dataspace,
466 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800467 }
468}
469
470void OutputLayer::writeOutputIndependentPerFrameStateToHWC(
471 HWC2::Layer* hwcLayer, const LayerFECompositionState& outputIndependentState) {
472 switch (auto error = hwcLayer->setColorTransform(outputIndependentState.colorTransform)) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700473 case hal::Error::NONE:
Lloyd Piquef5275482019-01-29 18:42:42 -0800474 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700475 case hal::Error::UNSUPPORTED:
Lloyd Piquef5275482019-01-29 18:42:42 -0800476 editState().forceClientComposition = true;
477 break;
478 default:
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700479 ALOGE("[%s] Failed to set color transform: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquea83776c2019-01-29 18:42:32 -0800480 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800481 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800482
Alec Mouri464352b2021-03-24 16:33:21 -0700483 const Region& surfaceDamage = getState().overrideInfo.buffer
484 ? getState().overrideInfo.damageRegion
485 : outputIndependentState.surfaceDamage;
486
487 if (auto error = hwcLayer->setSurfaceDamage(surfaceDamage); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700488 ALOGE("[%s] Failed to set surface damage: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800489 to_string(error).c_str(), static_cast<int32_t>(error));
490 outputIndependentState.surfaceDamage.dump(LOG_TAG);
491 }
492
493 // Content-specific per-frame state
494 switch (outputIndependentState.compositionType) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700495 case hal::Composition::SOLID_COLOR:
Lloyd Pique46b72df2019-10-29 13:19:27 -0700496 // For compatibility, should be written AFTER the composition type.
Lloyd Piquef5275482019-01-29 18:42:42 -0800497 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700498 case hal::Composition::SIDEBAND:
Lloyd Piquef5275482019-01-29 18:42:42 -0800499 writeSidebandStateToHWC(hwcLayer, outputIndependentState);
500 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700501 case hal::Composition::CURSOR:
502 case hal::Composition::DEVICE:
Lloyd Piquef5275482019-01-29 18:42:42 -0800503 writeBufferStateToHWC(hwcLayer, outputIndependentState);
504 break;
Peiyong Line9d809e2020-04-14 13:10:48 -0700505 case hal::Composition::INVALID:
506 case hal::Composition::CLIENT:
Lloyd Piquef5275482019-01-29 18:42:42 -0800507 // Ignored
508 break;
509 }
510}
511
512void OutputLayer::writeSolidColorStateToHWC(HWC2::Layer* hwcLayer,
513 const LayerFECompositionState& outputIndependentState) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700514 if (outputIndependentState.compositionType != hal::Composition::SOLID_COLOR) {
Lloyd Pique46b72df2019-10-29 13:19:27 -0700515 return;
516 }
517
Peiyong Line9d809e2020-04-14 13:10:48 -0700518 hal::Color color = {static_cast<uint8_t>(std::round(255.0f * outputIndependentState.color.r)),
519 static_cast<uint8_t>(std::round(255.0f * outputIndependentState.color.g)),
520 static_cast<uint8_t>(std::round(255.0f * outputIndependentState.color.b)),
521 255};
Lloyd Piquef5275482019-01-29 18:42:42 -0800522
Peiyong Line9d809e2020-04-14 13:10:48 -0700523 if (auto error = hwcLayer->setColor(color); error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700524 ALOGE("[%s] Failed to set color: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800525 to_string(error).c_str(), static_cast<int32_t>(error));
526 }
527}
528
529void OutputLayer::writeSidebandStateToHWC(HWC2::Layer* hwcLayer,
530 const LayerFECompositionState& outputIndependentState) {
531 if (auto error = hwcLayer->setSidebandStream(outputIndependentState.sidebandStream->handle());
Peiyong Line9d809e2020-04-14 13:10:48 -0700532 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700533 ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800534 outputIndependentState.sidebandStream->handle(), to_string(error).c_str(),
535 static_cast<int32_t>(error));
536 }
537}
538
539void OutputLayer::writeBufferStateToHWC(HWC2::Layer* hwcLayer,
540 const LayerFECompositionState& outputIndependentState) {
541 auto supportedPerFrameMetadata =
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700542 getOutput().getDisplayColorProfile()->getSupportedPerFrameMetadata();
Lloyd Piquef5275482019-01-29 18:42:42 -0800543 if (auto error = hwcLayer->setPerFrameMetadata(supportedPerFrameMetadata,
544 outputIndependentState.hdrMetadata);
Peiyong Line9d809e2020-04-14 13:10:48 -0700545 error != hal::Error::NONE && error != hal::Error::UNSUPPORTED) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700546 ALOGE("[%s] Failed to set hdrMetadata: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800547 to_string(error).c_str(), static_cast<int32_t>(error));
548 }
549
Dan Stoza6166c312021-01-15 16:34:05 -0800550 sp<GraphicBuffer> buffer = outputIndependentState.buffer;
551 sp<Fence> acquireFence = outputIndependentState.acquireFence;
Alec Mourie7cc1c22021-04-27 15:23:26 -0700552 int slot = outputIndependentState.bufferSlot;
Dan Stoza6166c312021-01-15 16:34:05 -0800553 if (getState().overrideInfo.buffer != nullptr) {
Alec Mouria90a5702021-04-16 16:36:21 +0000554 buffer = getState().overrideInfo.buffer->getBuffer();
Dan Stoza6166c312021-01-15 16:34:05 -0800555 acquireFence = getState().overrideInfo.acquireFence;
Alec Mourie7cc1c22021-04-27 15:23:26 -0700556 slot = HwcBufferCache::FLATTENER_CACHING_SLOT;
Dan Stoza6166c312021-01-15 16:34:05 -0800557 }
558
559 ALOGV("Writing buffer %p", buffer.get());
560
Lloyd Piquef5275482019-01-29 18:42:42 -0800561 uint32_t hwcSlot = 0;
562 sp<GraphicBuffer> hwcBuffer;
563 // We need access to the output-dependent state for the buffer cache there,
564 // though otherwise the buffer is not output-dependent.
Alec Mourie7cc1c22021-04-27 15:23:26 -0700565 editState().hwc->hwcBufferCache.getHwcBuffer(slot, buffer, &hwcSlot, &hwcBuffer);
Lloyd Piquef5275482019-01-29 18:42:42 -0800566
Dan Stoza6166c312021-01-15 16:34:05 -0800567 if (auto error = hwcLayer->setBuffer(hwcSlot, hwcBuffer, acquireFence);
Peiyong Line9d809e2020-04-14 13:10:48 -0700568 error != hal::Error::NONE) {
Dan Stoza6166c312021-01-15 16:34:05 -0800569 ALOGE("[%s] Failed to set buffer %p: %s (%d)", getLayerFE().getDebugName(), buffer->handle,
570 to_string(error).c_str(), static_cast<int32_t>(error));
Lloyd Piquef5275482019-01-29 18:42:42 -0800571 }
572}
573
Peiyong Line9d809e2020-04-14 13:10:48 -0700574void OutputLayer::writeCompositionTypeToHWC(HWC2::Layer* hwcLayer,
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400575 hal::Composition requestedCompositionType,
576 bool isPeekingThrough) {
Lloyd Piquef5275482019-01-29 18:42:42 -0800577 auto& outputDependentState = editState();
578
579 // If we are forcing client composition, we need to tell the HWC
Leon Scroggins IIId305ef22021-04-06 09:53:26 -0400580 if (outputDependentState.forceClientComposition ||
Leon Scroggins III9aa25c22021-04-15 15:30:19 -0400581 (!isPeekingThrough && getLayerFE().hasRoundedCorners())) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700582 requestedCompositionType = hal::Composition::CLIENT;
Lloyd Piquef5275482019-01-29 18:42:42 -0800583 }
584
585 // Set the requested composition type with the HWC whenever it changes
586 if (outputDependentState.hwc->hwcCompositionType != requestedCompositionType) {
587 outputDependentState.hwc->hwcCompositionType = requestedCompositionType;
588
Peiyong Line9d809e2020-04-14 13:10:48 -0700589 if (auto error = hwcLayer->setCompositionType(requestedCompositionType);
590 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700591 ALOGE("[%s] Failed to set composition type %s: %s (%d)", getLayerFE().getDebugName(),
Lloyd Piquef5275482019-01-29 18:42:42 -0800592 toString(requestedCompositionType).c_str(), to_string(error).c_str(),
Lloyd Piquea83776c2019-01-29 18:42:32 -0800593 static_cast<int32_t>(error));
594 }
Lloyd Piquea83776c2019-01-29 18:42:32 -0800595 }
596}
597
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800598void OutputLayer::writeCursorPositionToHWC() const {
599 // Skip doing this if there is no HWC interface
600 auto hwcLayer = getHwcLayer();
601 if (!hwcLayer) {
602 return;
603 }
604
Lloyd Piquede196652020-01-22 17:29:58 -0800605 const auto* layerFEState = getLayerFE().getCompositionState();
606 if (!layerFEState) {
607 return;
608 }
609
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700610 const auto& outputState = getOutput().getState();
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800611
Lloyd Piquede196652020-01-22 17:29:58 -0800612 Rect frame = layerFEState->cursorFrame;
Marin Shalamanov6ad317c2020-07-29 23:34:07 +0200613 frame.intersect(outputState.layerStackSpace.content, &frame);
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800614 Rect position = outputState.transform.transform(frame);
615
616 if (auto error = hwcLayer->setCursorPosition(position.left, position.top);
Peiyong Line9d809e2020-04-14 13:10:48 -0700617 error != hal::Error::NONE) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700618 ALOGE("[%s] Failed to set cursor position to (%d, %d): %s (%d)",
619 getLayerFE().getDebugName(), position.left, position.top, to_string(error).c_str(),
620 static_cast<int32_t>(error));
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800621 }
622}
623
Lloyd Pique66d68602019-02-13 14:23:31 -0800624HWC2::Layer* OutputLayer::getHwcLayer() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700625 const auto& state = getState();
626 return state.hwc ? state.hwc->hwcLayer.get() : nullptr;
Lloyd Pique66d68602019-02-13 14:23:31 -0800627}
628
629bool OutputLayer::requiresClientComposition() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700630 const auto& state = getState();
Peiyong Line9d809e2020-04-14 13:10:48 -0700631 return !state.hwc || state.hwc->hwcCompositionType == hal::Composition::CLIENT;
Lloyd Pique66d68602019-02-13 14:23:31 -0800632}
633
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800634bool OutputLayer::isHardwareCursor() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700635 const auto& state = getState();
Peiyong Line9d809e2020-04-14 13:10:48 -0700636 return state.hwc && state.hwc->hwcCompositionType == hal::Composition::CURSOR;
Lloyd Piquec7b0c752019-03-07 20:59:59 -0800637}
638
Peiyong Line9d809e2020-04-14 13:10:48 -0700639void OutputLayer::detectDisallowedCompositionTypeChange(hal::Composition from,
640 hal::Composition to) const {
Lloyd Pique66d68602019-02-13 14:23:31 -0800641 bool result = false;
642 switch (from) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700643 case hal::Composition::INVALID:
644 case hal::Composition::CLIENT:
Lloyd Pique66d68602019-02-13 14:23:31 -0800645 result = false;
646 break;
647
Peiyong Line9d809e2020-04-14 13:10:48 -0700648 case hal::Composition::DEVICE:
649 case hal::Composition::SOLID_COLOR:
650 result = (to == hal::Composition::CLIENT);
Lloyd Pique66d68602019-02-13 14:23:31 -0800651 break;
652
Peiyong Line9d809e2020-04-14 13:10:48 -0700653 case hal::Composition::CURSOR:
654 case hal::Composition::SIDEBAND:
655 result = (to == hal::Composition::CLIENT || to == hal::Composition::DEVICE);
Lloyd Pique66d68602019-02-13 14:23:31 -0800656 break;
657 }
658
659 if (!result) {
660 ALOGE("[%s] Invalid device requested composition type change: %s (%d) --> %s (%d)",
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700661 getLayerFE().getDebugName(), toString(from).c_str(), static_cast<int>(from),
Lloyd Pique66d68602019-02-13 14:23:31 -0800662 toString(to).c_str(), static_cast<int>(to));
663 }
664}
665
Peiyong Line9d809e2020-04-14 13:10:48 -0700666void OutputLayer::applyDeviceCompositionTypeChange(hal::Composition compositionType) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700667 auto& state = editState();
668 LOG_FATAL_IF(!state.hwc);
669 auto& hwcState = *state.hwc;
Lloyd Pique66d68602019-02-13 14:23:31 -0800670
671 detectDisallowedCompositionTypeChange(hwcState.hwcCompositionType, compositionType);
672
673 hwcState.hwcCompositionType = compositionType;
674}
675
676void OutputLayer::prepareForDeviceLayerRequests() {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700677 auto& state = editState();
678 state.clearClientTarget = false;
Lloyd Pique66d68602019-02-13 14:23:31 -0800679}
680
Peiyong Line9d809e2020-04-14 13:10:48 -0700681void OutputLayer::applyDeviceLayerRequest(hal::LayerRequest request) {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700682 auto& state = editState();
Lloyd Pique66d68602019-02-13 14:23:31 -0800683 switch (request) {
Peiyong Line9d809e2020-04-14 13:10:48 -0700684 case hal::LayerRequest::CLEAR_CLIENT_TARGET:
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700685 state.clearClientTarget = true;
Lloyd Pique66d68602019-02-13 14:23:31 -0800686 break;
687
688 default:
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700689 ALOGE("[%s] Unknown device layer request %s (%d)", getLayerFE().getDebugName(),
Lloyd Pique66d68602019-02-13 14:23:31 -0800690 toString(request).c_str(), static_cast<int>(request));
691 break;
692 }
693}
694
Lloyd Pique688abd42019-02-15 15:42:24 -0800695bool OutputLayer::needsFiltering() const {
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700696 const auto& state = getState();
697 const auto& displayFrame = state.displayFrame;
698 const auto& sourceCrop = state.sourceCrop;
Lloyd Pique688abd42019-02-15 15:42:24 -0800699 return sourceCrop.getHeight() != displayFrame.getHeight() ||
700 sourceCrop.getWidth() != displayFrame.getWidth();
701}
702
Dan Stoza6166c312021-01-15 16:34:05 -0800703std::vector<LayerFE::LayerSettings> OutputLayer::getOverrideCompositionList() const {
704 if (getState().overrideInfo.buffer == nullptr) {
705 return {};
706 }
707
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700708 // Compute the geometry boundaries in layer stack space: we need to transform from the
709 // framebuffer space of the override buffer to layer space.
710 const ProjectionSpace& layerSpace = getOutput().getState().layerStackSpace;
711 const ui::Transform transform = getState().overrideInfo.displaySpace.getTransform(layerSpace);
712 const Rect boundaries = transform.transform(getState().overrideInfo.displayFrame);
713
Dan Stoza6166c312021-01-15 16:34:05 -0800714 LayerFE::LayerSettings settings;
715 settings.geometry = renderengine::Geometry{
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700716 .boundaries = boundaries.toFloatRect(),
Dan Stoza6166c312021-01-15 16:34:05 -0800717 };
Alec Mouria90a5702021-04-16 16:36:21 +0000718 settings.bufferId = getState().overrideInfo.buffer->getBuffer()->getId();
Alec Mouri7be6c0a2021-03-19 15:22:01 -0700719 settings.source = renderengine::PixelSource{
720 .buffer = renderengine::Buffer{
721 .buffer = getState().overrideInfo.buffer,
722 .fence = getState().overrideInfo.acquireFence,
723 // If the transform from layer space to display space contains a rotation, we
724 // need to undo the rotation in the texture transform
725 .textureTransform =
726 ui::Transform(transform.inverse().getOrientation(), 1, 1).asMatrix4(),
727 }};
Alec Mouri9c8fce02021-03-12 18:30:42 -0800728 settings.sourceDataspace = getState().overrideInfo.dataspace;
Dan Stoza6166c312021-01-15 16:34:05 -0800729 settings.alpha = 1.0f;
730
731 return {static_cast<LayerFE::LayerSettings>(settings)};
732}
733
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800734void OutputLayer::dump(std::string& out) const {
735 using android::base::StringAppendF;
736
Lloyd Piquede196652020-01-22 17:29:58 -0800737 StringAppendF(&out, " - Output Layer %p(%s)\n", this, getLayerFE().getDebugName());
Lloyd Piquea38ea7e2019-04-16 18:10:26 -0700738 dumpState(out);
Lloyd Pique37c2c9b2018-12-04 17:25:10 -0800739}
740
Lloyd Piquecc01a452018-12-04 17:24:00 -0800741} // namespace impl
742} // namespace android::compositionengine