Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 1 | /* |
| 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 | |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 17 | #include <DisplayHardware/Hal.h> |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 18 | #include <android-base/stringprintf.h> |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 19 | #include <compositionengine/DisplayColorProfile.h> |
Lloyd Pique | 9755fb7 | 2019-03-26 14:44:40 -0700 | [diff] [blame] | 20 | #include <compositionengine/LayerFECompositionState.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 21 | #include <compositionengine/Output.h> |
Alec Mouri | e7cc1c2 | 2021-04-27 15:23:26 -0700 | [diff] [blame] | 22 | #include <compositionengine/impl/HwcBufferCache.h> |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 23 | #include <compositionengine/impl/OutputCompositionState.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 24 | #include <compositionengine/impl/OutputLayer.h> |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 25 | #include <compositionengine/impl/OutputLayerCompositionState.h> |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 26 | #include <cstdint> |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 27 | #include "system/graphics-base-v1.0.h" |
| 28 | |
| 29 | #include <ui/DataspaceUtils.h> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 30 | |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 31 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 32 | #pragma clang diagnostic push |
| 33 | #pragma clang diagnostic ignored "-Wconversion" |
| 34 | |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 35 | #include "DisplayHardware/HWComposer.h" |
| 36 | |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 37 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 38 | #pragma clang diagnostic pop // ignored "-Wconversion" |
| 39 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 40 | using aidl::android::hardware::graphics::composer3::Composition; |
| 41 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 42 | namespace android::compositionengine { |
| 43 | |
| 44 | OutputLayer::~OutputLayer() = default; |
| 45 | |
| 46 | namespace impl { |
| 47 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 48 | namespace { |
| 49 | |
| 50 | FloatRect reduce(const FloatRect& win, const Region& exclude) { |
| 51 | if (CC_LIKELY(exclude.isEmpty())) { |
| 52 | return win; |
| 53 | } |
| 54 | // Convert through Rect (by rounding) for lack of FloatRegion |
| 55 | return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect(); |
| 56 | } |
| 57 | |
| 58 | } // namespace |
| 59 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 60 | std::unique_ptr<OutputLayer> createOutputLayer(const compositionengine::Output& output, |
| 61 | const sp<compositionengine::LayerFE>& layerFE) { |
| 62 | return createOutputLayerTemplated<OutputLayer>(output, layerFE); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 63 | } |
| 64 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 65 | OutputLayer::~OutputLayer() = default; |
| 66 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 67 | void OutputLayer::setHwcLayer(std::shared_ptr<HWC2::Layer> hwcLayer) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 68 | auto& state = editState(); |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 69 | if (hwcLayer) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 70 | state.hwc.emplace(std::move(hwcLayer)); |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 71 | } else { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 72 | state.hwc.reset(); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 73 | } |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 76 | Rect OutputLayer::calculateInitialCrop() const { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 77 | const auto& layerState = *getLayerFE().getCompositionState(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 78 | |
| 79 | // apply the projection's clipping to the window crop in |
| 80 | // layerstack space, and convert-back to layer space. |
| 81 | // if there are no window scaling involved, this operation will map to full |
| 82 | // pixels in the buffer. |
| 83 | |
| 84 | FloatRect activeCropFloat = |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 85 | reduce(layerState.geomLayerBounds, layerState.transparentRegionHint); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 86 | |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 87 | const Rect& viewport = getOutput().getState().layerStackSpace.getContent(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 88 | const ui::Transform& layerTransform = layerState.geomLayerTransform; |
| 89 | const ui::Transform& inverseLayerTransform = layerState.geomInverseLayerTransform; |
| 90 | // Transform to screen space. |
| 91 | activeCropFloat = layerTransform.transform(activeCropFloat); |
| 92 | activeCropFloat = activeCropFloat.intersect(viewport.toFloatRect()); |
| 93 | // Back to layer space to work with the content crop. |
| 94 | activeCropFloat = inverseLayerTransform.transform(activeCropFloat); |
| 95 | |
| 96 | // This needs to be here as transform.transform(Rect) computes the |
| 97 | // transformed rect and then takes the bounding box of the result before |
| 98 | // returning. This means |
| 99 | // transform.inverse().transform(transform.transform(Rect)) != Rect |
| 100 | // in which case we need to make sure the final rect is clipped to the |
| 101 | // display bounds. |
| 102 | Rect activeCrop{activeCropFloat}; |
| 103 | if (!activeCrop.intersect(layerState.geomBufferSize, &activeCrop)) { |
| 104 | activeCrop.clear(); |
| 105 | } |
| 106 | return activeCrop; |
| 107 | } |
| 108 | |
| 109 | FloatRect OutputLayer::calculateOutputSourceCrop() const { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 110 | const auto& layerState = *getLayerFE().getCompositionState(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 111 | const auto& outputState = getOutput().getState(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 112 | |
| 113 | if (!layerState.geomUsesSourceCrop) { |
| 114 | return {}; |
| 115 | } |
| 116 | |
| 117 | // the content crop is the area of the content that gets scaled to the |
| 118 | // layer's size. This is in buffer space. |
| 119 | FloatRect crop = layerState.geomContentCrop.toFloatRect(); |
| 120 | |
| 121 | // In addition there is a WM-specified crop we pull from our drawing state. |
| 122 | Rect activeCrop = calculateInitialCrop(); |
| 123 | const Rect& bufferSize = layerState.geomBufferSize; |
| 124 | |
| 125 | int winWidth = bufferSize.getWidth(); |
| 126 | int winHeight = bufferSize.getHeight(); |
| 127 | |
| 128 | // The bufferSize for buffer state layers can be unbounded ([0, 0, -1, -1]) |
| 129 | // if display frame hasn't been set and the parent is an unbounded layer. |
| 130 | if (winWidth < 0 && winHeight < 0) { |
| 131 | return crop; |
| 132 | } |
| 133 | |
| 134 | // Transform the window crop to match the buffer coordinate system, |
| 135 | // which means using the inverse of the current transform set on the |
| 136 | // SurfaceFlingerConsumer. |
| 137 | uint32_t invTransform = layerState.geomBufferTransform; |
| 138 | if (layerState.geomBufferUsesDisplayInverseTransform) { |
| 139 | /* |
| 140 | * the code below applies the primary display's inverse transform to the |
| 141 | * buffer |
| 142 | */ |
Marin Shalamanov | 68933fb | 2020-09-10 17:58:12 +0200 | [diff] [blame] | 143 | uint32_t invTransformOrient = |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 144 | ui::Transform::toRotationFlags(outputState.displaySpace.getOrientation()); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 145 | // calculate the inverse transform |
| 146 | if (invTransformOrient & HAL_TRANSFORM_ROT_90) { |
| 147 | invTransformOrient ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H; |
| 148 | } |
| 149 | // and apply to the current transform |
| 150 | invTransform = |
| 151 | (ui::Transform(invTransformOrient) * ui::Transform(invTransform)).getOrientation(); |
| 152 | } |
| 153 | |
| 154 | if (invTransform & HAL_TRANSFORM_ROT_90) { |
| 155 | // If the activeCrop has been rotate the ends are rotated but not |
| 156 | // the space itself so when transforming ends back we can't rely on |
| 157 | // a modification of the axes of rotation. To account for this we |
| 158 | // need to reorient the inverse rotation in terms of the current |
| 159 | // axes of rotation. |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame] | 160 | bool isHFlipped = (invTransform & HAL_TRANSFORM_FLIP_H) != 0; |
| 161 | bool isVFlipped = (invTransform & HAL_TRANSFORM_FLIP_V) != 0; |
| 162 | if (isHFlipped == isVFlipped) { |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 163 | invTransform ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H; |
| 164 | } |
| 165 | std::swap(winWidth, winHeight); |
| 166 | } |
| 167 | const Rect winCrop = |
| 168 | activeCrop.transform(invTransform, bufferSize.getWidth(), bufferSize.getHeight()); |
| 169 | |
| 170 | // below, crop is intersected with winCrop expressed in crop's coordinate space |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame] | 171 | const float xScale = crop.getWidth() / float(winWidth); |
| 172 | const float yScale = crop.getHeight() / float(winHeight); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 173 | |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame] | 174 | const float insetLeft = winCrop.left * xScale; |
| 175 | const float insetTop = winCrop.top * yScale; |
| 176 | const float insetRight = (winWidth - winCrop.right) * xScale; |
| 177 | const float insetBottom = (winHeight - winCrop.bottom) * yScale; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 178 | |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame] | 179 | crop.left += insetLeft; |
| 180 | crop.top += insetTop; |
| 181 | crop.right -= insetRight; |
| 182 | crop.bottom -= insetBottom; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 183 | |
| 184 | return crop; |
| 185 | } |
| 186 | |
| 187 | Rect OutputLayer::calculateOutputDisplayFrame() const { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 188 | const auto& layerState = *getLayerFE().getCompositionState(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 189 | const auto& outputState = getOutput().getState(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 190 | |
| 191 | // apply the layer's transform, followed by the display's global transform |
| 192 | // here we're guaranteed that the layer's transform preserves rects |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 193 | Region activeTransparentRegion = layerState.transparentRegionHint; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 194 | const ui::Transform& layerTransform = layerState.geomLayerTransform; |
| 195 | const ui::Transform& inverseLayerTransform = layerState.geomInverseLayerTransform; |
| 196 | const Rect& bufferSize = layerState.geomBufferSize; |
| 197 | Rect activeCrop = layerState.geomCrop; |
| 198 | if (!activeCrop.isEmpty() && bufferSize.isValid()) { |
| 199 | activeCrop = layerTransform.transform(activeCrop); |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 200 | if (!activeCrop.intersect(outputState.layerStackSpace.getContent(), &activeCrop)) { |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 201 | activeCrop.clear(); |
| 202 | } |
| 203 | activeCrop = inverseLayerTransform.transform(activeCrop, true); |
| 204 | // This needs to be here as transform.transform(Rect) computes the |
| 205 | // transformed rect and then takes the bounding box of the result before |
| 206 | // returning. This means |
| 207 | // transform.inverse().transform(transform.transform(Rect)) != Rect |
| 208 | // in which case we need to make sure the final rect is clipped to the |
| 209 | // display bounds. |
| 210 | if (!activeCrop.intersect(bufferSize, &activeCrop)) { |
| 211 | activeCrop.clear(); |
| 212 | } |
| 213 | // mark regions outside the crop as transparent |
| 214 | activeTransparentRegion.orSelf(Rect(0, 0, bufferSize.getWidth(), activeCrop.top)); |
| 215 | activeTransparentRegion.orSelf( |
| 216 | Rect(0, activeCrop.bottom, bufferSize.getWidth(), bufferSize.getHeight())); |
| 217 | activeTransparentRegion.orSelf(Rect(0, activeCrop.top, activeCrop.left, activeCrop.bottom)); |
| 218 | activeTransparentRegion.orSelf( |
| 219 | Rect(activeCrop.right, activeCrop.top, bufferSize.getWidth(), activeCrop.bottom)); |
| 220 | } |
| 221 | |
| 222 | // reduce uses a FloatRect to provide more accuracy during the |
| 223 | // transformation. We then round upon constructing 'frame'. |
Leon Scroggins III | d394d3c | 2021-06-24 11:30:32 -0400 | [diff] [blame] | 224 | FloatRect geomLayerBounds = layerState.geomLayerBounds; |
| 225 | |
| 226 | // Some HWCs may clip client composited input to its displayFrame. Make sure |
| 227 | // that this does not cut off the shadow. |
| 228 | if (layerState.forceClientComposition && layerState.shadowRadius > 0.0f) { |
| 229 | const auto outset = layerState.shadowRadius; |
| 230 | geomLayerBounds.left -= outset; |
| 231 | geomLayerBounds.top -= outset; |
| 232 | geomLayerBounds.right += outset; |
| 233 | geomLayerBounds.bottom += outset; |
| 234 | } |
| 235 | Rect frame{layerTransform.transform(reduce(geomLayerBounds, activeTransparentRegion))}; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 236 | if (!frame.intersect(outputState.layerStackSpace.getContent(), &frame)) { |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 237 | frame.clear(); |
| 238 | } |
| 239 | const ui::Transform displayTransform{outputState.transform}; |
| 240 | |
| 241 | return displayTransform.transform(frame); |
| 242 | } |
| 243 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 244 | uint32_t OutputLayer::calculateOutputRelativeBufferTransform( |
| 245 | uint32_t internalDisplayRotationFlags) const { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 246 | const auto& layerState = *getLayerFE().getCompositionState(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 247 | const auto& outputState = getOutput().getState(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 248 | |
| 249 | /* |
| 250 | * Transformations are applied in this order: |
| 251 | * 1) buffer orientation/flip/mirror |
| 252 | * 2) state transformation (window manager) |
| 253 | * 3) layer orientation (screen orientation) |
| 254 | * (NOTE: the matrices are multiplied in reverse order) |
| 255 | */ |
| 256 | const ui::Transform& layerTransform = layerState.geomLayerTransform; |
Rashed Abdel-Tawab | 6643cd8 | 2019-10-29 10:01:56 -0700 | [diff] [blame] | 257 | const ui::Transform displayTransform{outputState.transform}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 258 | const ui::Transform bufferTransform{layerState.geomBufferTransform}; |
| 259 | ui::Transform transform(displayTransform * layerTransform * bufferTransform); |
| 260 | |
| 261 | if (layerState.geomBufferUsesDisplayInverseTransform) { |
| 262 | /* |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 263 | * We must apply the internal display's inverse transform to the buffer |
| 264 | * transform, and not the one for the output this layer is on. |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 265 | */ |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 266 | uint32_t invTransform = internalDisplayRotationFlags; |
| 267 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 268 | // calculate the inverse transform |
| 269 | if (invTransform & HAL_TRANSFORM_ROT_90) { |
| 270 | invTransform ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H; |
| 271 | } |
| 272 | |
| 273 | /* |
| 274 | * Here we cancel out the orientation component of the WM transform. |
| 275 | * The scaling and translate components are already included in our bounds |
| 276 | * computation so it's enough to just omit it in the composition. |
| 277 | * See comment in BufferLayer::prepareClientLayer with ref to b/36727915 for why. |
| 278 | */ |
Lloyd Pique | 546a245 | 2019-03-18 20:53:27 +0000 | [diff] [blame] | 279 | transform = ui::Transform(invTransform) * displayTransform * bufferTransform; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 280 | } |
| 281 | |
| 282 | // this gives us only the "orientation" component of the transform |
| 283 | return transform.getOrientation(); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 284 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 285 | |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 286 | void OutputLayer::updateCompositionState( |
| 287 | bool includeGeometry, bool forceClientComposition, |
| 288 | ui::Transform::RotationFlags internalDisplayRotationFlags) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 289 | const auto* layerFEState = getLayerFE().getCompositionState(); |
| 290 | if (!layerFEState) { |
| 291 | return; |
| 292 | } |
| 293 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 294 | const auto& outputState = getOutput().getState(); |
| 295 | const auto& profile = *getOutput().getDisplayColorProfile(); |
| 296 | auto& state = editState(); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 297 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 298 | if (includeGeometry) { |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 299 | // Clear the forceClientComposition flag before it is set for any |
| 300 | // reason. Note that since it can be set by some checks below when |
| 301 | // updating the geometry state, we only clear it when updating the |
| 302 | // geometry since those conditions for forcing client composition won't |
| 303 | // go away otherwise. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 304 | state.forceClientComposition = false; |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 305 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 306 | state.displayFrame = calculateOutputDisplayFrame(); |
| 307 | state.sourceCrop = calculateOutputSourceCrop(); |
Snild Dolkow | 9e217d6 | 2020-04-22 15:53:42 +0200 | [diff] [blame] | 308 | state.bufferTransform = static_cast<Hwc2::Transform>( |
| 309 | calculateOutputRelativeBufferTransform(internalDisplayRotationFlags)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 310 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 311 | if ((layerFEState->isSecure && !outputState.isSecure) || |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 312 | (state.bufferTransform & ui::Transform::ROT_INVALID)) { |
| 313 | state.forceClientComposition = true; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 314 | } |
| 315 | } |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 316 | |
| 317 | // Determine the output dependent dataspace for this layer. If it is |
| 318 | // colorspace agnostic, it just uses the dataspace chosen for the output to |
| 319 | // avoid the need for color conversion. |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 320 | state.dataspace = layerFEState->isColorspaceAgnostic && |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 321 | outputState.targetDataspace != ui::Dataspace::UNKNOWN |
| 322 | ? outputState.targetDataspace |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 323 | : layerFEState->dataspace; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 324 | |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 325 | // For hdr content, treat the white point as the display brightness - HDR content should not be |
| 326 | // boosted or dimmed. |
| 327 | if (isHdrDataspace(state.dataspace)) { |
| 328 | state.whitePointNits = getOutput().getState().displayBrightnessNits; |
| 329 | } else { |
| 330 | state.whitePointNits = getOutput().getState().sdrWhitePointNits; |
| 331 | } |
| 332 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 333 | // These are evaluated every frame as they can potentially change at any |
| 334 | // time. |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 335 | if (layerFEState->forceClientComposition || !profile.isDataspaceSupported(state.dataspace) || |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 336 | forceClientComposition) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 337 | state.forceClientComposition = true; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 338 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 339 | } |
| 340 | |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 341 | void OutputLayer::writeStateToHWC(bool includeGeometry, bool skipLayer, uint32_t z, |
| 342 | bool zIsOverridden, bool isPeekingThrough) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 343 | const auto& state = getState(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 344 | // Skip doing this if there is no HWC interface |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 345 | if (!state.hwc) { |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 346 | return; |
| 347 | } |
| 348 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 349 | auto& hwcLayer = (*state.hwc).hwcLayer; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 350 | if (!hwcLayer) { |
| 351 | ALOGE("[%s] failed to write composition state to HWC -- no hwcLayer for output %s", |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 352 | getLayerFE().getDebugName(), getOutput().getName().c_str()); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 353 | return; |
| 354 | } |
| 355 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 356 | const auto* outputIndependentState = getLayerFE().getCompositionState(); |
| 357 | if (!outputIndependentState) { |
| 358 | return; |
| 359 | } |
| 360 | |
| 361 | auto requestedCompositionType = outputIndependentState->compositionType; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 362 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 363 | if (requestedCompositionType == Composition::SOLID_COLOR && state.overrideInfo.buffer) { |
| 364 | requestedCompositionType = Composition::DEVICE; |
Alec Mouri | 028676a | 2021-12-02 15:01:48 -0800 | [diff] [blame] | 365 | } |
| 366 | |
Yichi Chen | 413d46a | 2021-04-07 21:42:09 +0800 | [diff] [blame] | 367 | // TODO(b/181172795): We now update geometry for all flattened layers. We should update it |
| 368 | // only when the geometry actually changes |
Leon Scroggins III | 9aa25c2 | 2021-04-15 15:30:19 -0400 | [diff] [blame] | 369 | const bool isOverridden = |
| 370 | state.overrideInfo.buffer != nullptr || isPeekingThrough || zIsOverridden; |
Yichi Chen | 413d46a | 2021-04-07 21:42:09 +0800 | [diff] [blame] | 371 | const bool prevOverridden = state.hwc->stateOverridden; |
| 372 | if (isOverridden || prevOverridden || skipLayer || includeGeometry) { |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 373 | writeOutputDependentGeometryStateToHWC(hwcLayer.get(), requestedCompositionType, z); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 374 | writeOutputIndependentGeometryStateToHWC(hwcLayer.get(), *outputIndependentState, |
| 375 | skipLayer); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 376 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 377 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 378 | writeOutputDependentPerFrameStateToHWC(hwcLayer.get()); |
Alec Mouri | 028676a | 2021-12-02 15:01:48 -0800 | [diff] [blame] | 379 | writeOutputIndependentPerFrameStateToHWC(hwcLayer.get(), *outputIndependentState, |
| 380 | requestedCompositionType, skipLayer); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 381 | |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 382 | writeCompositionTypeToHWC(hwcLayer.get(), requestedCompositionType, isPeekingThrough, |
| 383 | skipLayer); |
Lloyd Pique | 46b72df | 2019-10-29 13:19:27 -0700 | [diff] [blame] | 384 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 385 | if (requestedCompositionType == Composition::SOLID_COLOR) { |
Alec Mouri | 028676a | 2021-12-02 15:01:48 -0800 | [diff] [blame] | 386 | writeSolidColorStateToHWC(hwcLayer.get(), *outputIndependentState); |
| 387 | } |
Yichi Chen | 413d46a | 2021-04-07 21:42:09 +0800 | [diff] [blame] | 388 | |
| 389 | editState().hwc->stateOverridden = isOverridden; |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 390 | editState().hwc->layerSkipped = skipLayer; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 391 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 392 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 393 | void OutputLayer::writeOutputDependentGeometryStateToHWC(HWC2::Layer* hwcLayer, |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 394 | Composition requestedCompositionType, |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 395 | uint32_t z) { |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 396 | const auto& outputDependentState = getState(); |
| 397 | |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 398 | Rect displayFrame = outputDependentState.displayFrame; |
| 399 | FloatRect sourceCrop = outputDependentState.sourceCrop; |
Huihong Luo | a582511 | 2021-03-24 12:28:29 -0700 | [diff] [blame] | 400 | |
Alec Mouri | 464352b | 2021-03-24 16:33:21 -0700 | [diff] [blame] | 401 | if (outputDependentState.overrideInfo.buffer != nullptr) { |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 402 | displayFrame = outputDependentState.overrideInfo.displayFrame; |
Wiwit Rifa'i | e30a585 | 2021-06-25 19:20:48 +0800 | [diff] [blame] | 403 | sourceCrop = displayFrame.toFloatRect(); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 404 | } |
| 405 | |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 406 | ALOGV("Writing display frame [%d, %d, %d, %d]", displayFrame.left, displayFrame.top, |
| 407 | displayFrame.right, displayFrame.bottom); |
| 408 | |
| 409 | if (auto error = hwcLayer->setDisplayFrame(displayFrame); error != hal::Error::NONE) { |
| 410 | ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)", |
| 411 | getLayerFE().getDebugName(), displayFrame.left, displayFrame.top, displayFrame.right, |
| 412 | displayFrame.bottom, to_string(error).c_str(), static_cast<int32_t>(error)); |
| 413 | } |
| 414 | |
| 415 | if (auto error = hwcLayer->setSourceCrop(sourceCrop); error != hal::Error::NONE) { |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 416 | ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: " |
| 417 | "%s (%d)", |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 418 | getLayerFE().getDebugName(), sourceCrop.left, sourceCrop.top, sourceCrop.right, |
| 419 | sourceCrop.bottom, to_string(error).c_str(), static_cast<int32_t>(error)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 420 | } |
| 421 | |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 422 | if (auto error = hwcLayer->setZOrder(z); error != hal::Error::NONE) { |
| 423 | ALOGE("[%s] Failed to set Z %u: %s (%d)", getLayerFE().getDebugName(), z, |
| 424 | to_string(error).c_str(), static_cast<int32_t>(error)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 425 | } |
| 426 | |
Alec Mouri | 7be6c0a | 2021-03-19 15:22:01 -0700 | [diff] [blame] | 427 | // Solid-color layers and overridden buffers should always use an identity transform. |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 428 | const auto bufferTransform = (requestedCompositionType != Composition::SOLID_COLOR && |
Alec Mouri | 7be6c0a | 2021-03-19 15:22:01 -0700 | [diff] [blame] | 429 | getState().overrideInfo.buffer == nullptr) |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 430 | ? outputDependentState.bufferTransform |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 431 | : static_cast<hal::Transform>(0); |
| 432 | if (auto error = hwcLayer->setTransform(static_cast<hal::Transform>(bufferTransform)); |
| 433 | error != hal::Error::NONE) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 434 | ALOGE("[%s] Failed to set transform %s: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 435 | toString(outputDependentState.bufferTransform).c_str(), to_string(error).c_str(), |
| 436 | static_cast<int32_t>(error)); |
| 437 | } |
| 438 | } |
| 439 | |
| 440 | void OutputLayer::writeOutputIndependentGeometryStateToHWC( |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 441 | HWC2::Layer* hwcLayer, const LayerFECompositionState& outputIndependentState, |
| 442 | bool skipLayer) { |
Leon Scroggins III | e2ee040 | 2021-04-02 16:59:37 -0400 | [diff] [blame] | 443 | // If there is a peekThroughLayer, then this layer has a hole in it. We need to use |
| 444 | // PREMULTIPLIED so it will peek through. |
| 445 | const auto& overrideInfo = getState().overrideInfo; |
| 446 | const auto blendMode = overrideInfo.buffer || overrideInfo.peekThroughLayer |
Alec Mouri | ee69a59 | 2021-03-23 15:00:45 -0700 | [diff] [blame] | 447 | ? hardware::graphics::composer::hal::BlendMode::PREMULTIPLIED |
| 448 | : outputIndependentState.blendMode; |
| 449 | if (auto error = hwcLayer->setBlendMode(blendMode); error != hal::Error::NONE) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 450 | ALOGE("[%s] Failed to set blend mode %s: %s (%d)", getLayerFE().getDebugName(), |
Alec Mouri | ee69a59 | 2021-03-23 15:00:45 -0700 | [diff] [blame] | 451 | toString(blendMode).c_str(), to_string(error).c_str(), static_cast<int32_t>(error)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Alec Mouri | ee69a59 | 2021-03-23 15:00:45 -0700 | [diff] [blame] | 454 | const float alpha = skipLayer |
| 455 | ? 0.0f |
| 456 | : (getState().overrideInfo.buffer ? 1.0f : outputIndependentState.alpha); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 457 | ALOGV("Writing alpha %f", alpha); |
| 458 | |
| 459 | if (auto error = hwcLayer->setPlaneAlpha(alpha); error != hal::Error::NONE) { |
| 460 | ALOGE("[%s] Failed to set plane alpha %.3f: %s (%d)", getLayerFE().getDebugName(), alpha, |
| 461 | to_string(error).c_str(), static_cast<int32_t>(error)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 462 | } |
| 463 | |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 464 | for (const auto& [name, entry] : outputIndependentState.metadata) { |
| 465 | if (auto error = hwcLayer->setLayerGenericMetadata(name, entry.mandatory, entry.value); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 466 | error != hal::Error::NONE) { |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 467 | ALOGE("[%s] Failed to set generic metadata %s %s (%d)", getLayerFE().getDebugName(), |
| 468 | name.c_str(), to_string(error).c_str(), static_cast<int32_t>(error)); |
| 469 | } |
| 470 | } |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 471 | } |
| 472 | |
| 473 | void OutputLayer::writeOutputDependentPerFrameStateToHWC(HWC2::Layer* hwcLayer) { |
| 474 | const auto& outputDependentState = getState(); |
| 475 | |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 476 | // TODO(lpique): b/121291683 outputSpaceVisibleRegion is output-dependent geometry |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 477 | // state and should not change every frame. |
Alec Mouri | 464352b | 2021-03-24 16:33:21 -0700 | [diff] [blame] | 478 | Region visibleRegion = outputDependentState.overrideInfo.buffer |
| 479 | ? Region(outputDependentState.overrideInfo.visibleRegion) |
| 480 | : outputDependentState.outputSpaceVisibleRegion; |
| 481 | if (auto error = hwcLayer->setVisibleRegion(visibleRegion); error != hal::Error::NONE) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 482 | ALOGE("[%s] Failed to set visible region: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 483 | to_string(error).c_str(), static_cast<int32_t>(error)); |
Leon Scroggins III | f2b8ec4 | 2022-01-05 13:23:36 -0500 | [diff] [blame] | 484 | visibleRegion.dump(LOG_TAG); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Leon Scroggins III | 9a0afda | 2022-01-11 16:53:09 -0500 | [diff] [blame^] | 487 | if (auto error = |
| 488 | hwcLayer->setBlockingRegion(outputDependentState.outputSpaceBlockingRegionHint); |
| 489 | error != hal::Error::NONE) { |
| 490 | ALOGE("[%s] Failed to set blocking region: %s (%d)", getLayerFE().getDebugName(), |
| 491 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 492 | outputDependentState.outputSpaceBlockingRegionHint.dump(LOG_TAG); |
| 493 | } |
| 494 | |
Alec Mouri | b7edfc2 | 2021-03-17 16:20:26 -0700 | [diff] [blame] | 495 | const auto dataspace = outputDependentState.overrideInfo.buffer |
| 496 | ? outputDependentState.overrideInfo.dataspace |
| 497 | : outputDependentState.dataspace; |
| 498 | |
| 499 | if (auto error = hwcLayer->setDataspace(dataspace); error != hal::Error::NONE) { |
| 500 | ALOGE("[%s] Failed to set dataspace %d: %s (%d)", getLayerFE().getDebugName(), dataspace, |
| 501 | to_string(error).c_str(), static_cast<int32_t>(error)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 502 | } |
Alec Mouri | cdf6cbc | 2021-11-01 17:21:15 -0700 | [diff] [blame] | 503 | |
| 504 | // Don't dim cached layers |
| 505 | const auto whitePointNits = outputDependentState.overrideInfo.buffer |
| 506 | ? getOutput().getState().displayBrightnessNits |
| 507 | : outputDependentState.whitePointNits; |
| 508 | |
| 509 | if (auto error = hwcLayer->setWhitePointNits(whitePointNits); error != hal::Error::NONE) { |
| 510 | ALOGE("[%s] Failed to set white point %f: %s (%d)", getLayerFE().getDebugName(), |
| 511 | whitePointNits, to_string(error).c_str(), static_cast<int32_t>(error)); |
| 512 | } |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | void OutputLayer::writeOutputIndependentPerFrameStateToHWC( |
Alec Mouri | 96ca45c | 2021-06-09 17:32:26 -0700 | [diff] [blame] | 516 | HWC2::Layer* hwcLayer, const LayerFECompositionState& outputIndependentState, |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 517 | Composition compositionType, bool skipLayer) { |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 518 | switch (auto error = hwcLayer->setColorTransform(outputIndependentState.colorTransform)) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 519 | case hal::Error::NONE: |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 520 | break; |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 521 | case hal::Error::UNSUPPORTED: |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 522 | editState().forceClientComposition = true; |
| 523 | break; |
| 524 | default: |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 525 | ALOGE("[%s] Failed to set color transform: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 526 | to_string(error).c_str(), static_cast<int32_t>(error)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 527 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 528 | |
Alec Mouri | 464352b | 2021-03-24 16:33:21 -0700 | [diff] [blame] | 529 | const Region& surfaceDamage = getState().overrideInfo.buffer |
| 530 | ? getState().overrideInfo.damageRegion |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 531 | : (getState().hwc->stateOverridden ? Region::INVALID_REGION |
| 532 | : outputIndependentState.surfaceDamage); |
Alec Mouri | 464352b | 2021-03-24 16:33:21 -0700 | [diff] [blame] | 533 | |
| 534 | if (auto error = hwcLayer->setSurfaceDamage(surfaceDamage); error != hal::Error::NONE) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 535 | ALOGE("[%s] Failed to set surface damage: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 536 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 537 | outputIndependentState.surfaceDamage.dump(LOG_TAG); |
| 538 | } |
| 539 | |
| 540 | // Content-specific per-frame state |
Alec Mouri | 028676a | 2021-12-02 15:01:48 -0800 | [diff] [blame] | 541 | switch (compositionType) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 542 | case Composition::SOLID_COLOR: |
Lloyd Pique | 46b72df | 2019-10-29 13:19:27 -0700 | [diff] [blame] | 543 | // For compatibility, should be written AFTER the composition type. |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 544 | break; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 545 | case Composition::SIDEBAND: |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 546 | writeSidebandStateToHWC(hwcLayer, outputIndependentState); |
| 547 | break; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 548 | case Composition::CURSOR: |
| 549 | case Composition::DEVICE: |
Leon Scroggins III | 09c2541 | 2021-12-02 14:49:56 -0500 | [diff] [blame] | 550 | case Composition::DISPLAY_DECORATION: |
Alec Mouri | 96ca45c | 2021-06-09 17:32:26 -0700 | [diff] [blame] | 551 | writeBufferStateToHWC(hwcLayer, outputIndependentState, skipLayer); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 552 | break; |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 553 | case Composition::INVALID: |
| 554 | case Composition::CLIENT: |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 555 | // Ignored |
| 556 | break; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | void OutputLayer::writeSolidColorStateToHWC(HWC2::Layer* hwcLayer, |
| 561 | const LayerFECompositionState& outputIndependentState) { |
Ady Abraham | 6e60b14 | 2022-01-06 18:10:35 -0800 | [diff] [blame] | 562 | aidl::android::hardware::graphics::composer3::Color color = {outputIndependentState.color.r, |
| 563 | outputIndependentState.color.g, |
| 564 | outputIndependentState.color.b, |
| 565 | 1.0f}; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 566 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 567 | if (auto error = hwcLayer->setColor(color); error != hal::Error::NONE) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 568 | ALOGE("[%s] Failed to set color: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 569 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 570 | } |
| 571 | } |
| 572 | |
| 573 | void OutputLayer::writeSidebandStateToHWC(HWC2::Layer* hwcLayer, |
| 574 | const LayerFECompositionState& outputIndependentState) { |
| 575 | if (auto error = hwcLayer->setSidebandStream(outputIndependentState.sidebandStream->handle()); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 576 | error != hal::Error::NONE) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 577 | ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 578 | outputIndependentState.sidebandStream->handle(), to_string(error).c_str(), |
| 579 | static_cast<int32_t>(error)); |
| 580 | } |
| 581 | } |
| 582 | |
| 583 | void OutputLayer::writeBufferStateToHWC(HWC2::Layer* hwcLayer, |
Alec Mouri | 96ca45c | 2021-06-09 17:32:26 -0700 | [diff] [blame] | 584 | const LayerFECompositionState& outputIndependentState, |
| 585 | bool skipLayer) { |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 586 | auto supportedPerFrameMetadata = |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 587 | getOutput().getDisplayColorProfile()->getSupportedPerFrameMetadata(); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 588 | if (auto error = hwcLayer->setPerFrameMetadata(supportedPerFrameMetadata, |
| 589 | outputIndependentState.hdrMetadata); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 590 | error != hal::Error::NONE && error != hal::Error::UNSUPPORTED) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 591 | ALOGE("[%s] Failed to set hdrMetadata: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 592 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 593 | } |
| 594 | |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 595 | sp<GraphicBuffer> buffer = outputIndependentState.buffer; |
| 596 | sp<Fence> acquireFence = outputIndependentState.acquireFence; |
Alec Mouri | e7cc1c2 | 2021-04-27 15:23:26 -0700 | [diff] [blame] | 597 | int slot = outputIndependentState.bufferSlot; |
Alec Mouri | 96ca45c | 2021-06-09 17:32:26 -0700 | [diff] [blame] | 598 | if (getState().overrideInfo.buffer != nullptr && !skipLayer) { |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 599 | buffer = getState().overrideInfo.buffer->getBuffer(); |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 600 | acquireFence = getState().overrideInfo.acquireFence; |
Alec Mouri | e7cc1c2 | 2021-04-27 15:23:26 -0700 | [diff] [blame] | 601 | slot = HwcBufferCache::FLATTENER_CACHING_SLOT; |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | ALOGV("Writing buffer %p", buffer.get()); |
| 605 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 606 | uint32_t hwcSlot = 0; |
| 607 | sp<GraphicBuffer> hwcBuffer; |
| 608 | // We need access to the output-dependent state for the buffer cache there, |
| 609 | // though otherwise the buffer is not output-dependent. |
Alec Mouri | e7cc1c2 | 2021-04-27 15:23:26 -0700 | [diff] [blame] | 610 | editState().hwc->hwcBufferCache.getHwcBuffer(slot, buffer, &hwcSlot, &hwcBuffer); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 611 | |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 612 | if (auto error = hwcLayer->setBuffer(hwcSlot, hwcBuffer, acquireFence); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 613 | error != hal::Error::NONE) { |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 614 | ALOGE("[%s] Failed to set buffer %p: %s (%d)", getLayerFE().getDebugName(), buffer->handle, |
| 615 | to_string(error).c_str(), static_cast<int32_t>(error)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 619 | void OutputLayer::writeCompositionTypeToHWC(HWC2::Layer* hwcLayer, |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 620 | Composition requestedCompositionType, |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 621 | bool isPeekingThrough, bool skipLayer) { |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 622 | auto& outputDependentState = editState(); |
| 623 | |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 624 | if (isClientCompositionForced(isPeekingThrough)) { |
| 625 | // If we are forcing client composition, we need to tell the HWC |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 626 | requestedCompositionType = Composition::CLIENT; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 627 | } |
| 628 | |
| 629 | // Set the requested composition type with the HWC whenever it changes |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 630 | // We also resend the composition type when this layer was previously skipped, to ensure that |
| 631 | // the composition type is up-to-date. |
| 632 | if (outputDependentState.hwc->hwcCompositionType != requestedCompositionType || |
| 633 | (outputDependentState.hwc->layerSkipped && !skipLayer)) { |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 634 | outputDependentState.hwc->hwcCompositionType = requestedCompositionType; |
| 635 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 636 | if (auto error = hwcLayer->setCompositionType(requestedCompositionType); |
| 637 | error != hal::Error::NONE) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 638 | ALOGE("[%s] Failed to set composition type %s: %s (%d)", getLayerFE().getDebugName(), |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 639 | to_string(requestedCompositionType).c_str(), to_string(error).c_str(), |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 640 | static_cast<int32_t>(error)); |
| 641 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 645 | void OutputLayer::writeCursorPositionToHWC() const { |
| 646 | // Skip doing this if there is no HWC interface |
| 647 | auto hwcLayer = getHwcLayer(); |
| 648 | if (!hwcLayer) { |
| 649 | return; |
| 650 | } |
| 651 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 652 | const auto* layerFEState = getLayerFE().getCompositionState(); |
| 653 | if (!layerFEState) { |
| 654 | return; |
| 655 | } |
| 656 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 657 | const auto& outputState = getOutput().getState(); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 658 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 659 | Rect frame = layerFEState->cursorFrame; |
Angel Aguayo | b084e0c | 2021-08-04 23:27:28 +0000 | [diff] [blame] | 660 | frame.intersect(outputState.layerStackSpace.getContent(), &frame); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 661 | Rect position = outputState.transform.transform(frame); |
| 662 | |
| 663 | if (auto error = hwcLayer->setCursorPosition(position.left, position.top); |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 664 | error != hal::Error::NONE) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 665 | ALOGE("[%s] Failed to set cursor position to (%d, %d): %s (%d)", |
| 666 | getLayerFE().getDebugName(), position.left, position.top, to_string(error).c_str(), |
| 667 | static_cast<int32_t>(error)); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 668 | } |
| 669 | } |
| 670 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 671 | HWC2::Layer* OutputLayer::getHwcLayer() const { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 672 | const auto& state = getState(); |
| 673 | return state.hwc ? state.hwc->hwcLayer.get() : nullptr; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 674 | } |
| 675 | |
| 676 | bool OutputLayer::requiresClientComposition() const { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 677 | const auto& state = getState(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 678 | return !state.hwc || state.hwc->hwcCompositionType == Composition::CLIENT; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 679 | } |
| 680 | |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 681 | bool OutputLayer::isHardwareCursor() const { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 682 | const auto& state = getState(); |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 683 | return state.hwc && state.hwc->hwcCompositionType == Composition::CURSOR; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 684 | } |
| 685 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 686 | void OutputLayer::detectDisallowedCompositionTypeChange(Composition from, Composition to) const { |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 687 | bool result = false; |
| 688 | switch (from) { |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 689 | case Composition::INVALID: |
| 690 | case Composition::CLIENT: |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 691 | result = false; |
| 692 | break; |
| 693 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 694 | case Composition::DEVICE: |
| 695 | case Composition::SOLID_COLOR: |
| 696 | result = (to == Composition::CLIENT); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 697 | break; |
| 698 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 699 | case Composition::CURSOR: |
| 700 | case Composition::SIDEBAND: |
Leon Scroggins | 7fd536f | 2021-12-28 14:43:12 +0000 | [diff] [blame] | 701 | case Composition::DISPLAY_DECORATION: |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 702 | result = (to == Composition::CLIENT || to == Composition::DEVICE); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 703 | break; |
| 704 | } |
| 705 | |
| 706 | if (!result) { |
| 707 | ALOGE("[%s] Invalid device requested composition type change: %s (%d) --> %s (%d)", |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 708 | getLayerFE().getDebugName(), to_string(from).c_str(), static_cast<int>(from), |
| 709 | to_string(to).c_str(), static_cast<int>(to)); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 710 | } |
| 711 | } |
| 712 | |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 713 | bool OutputLayer::isClientCompositionForced(bool isPeekingThrough) const { |
| 714 | return getState().forceClientComposition || |
| 715 | (!isPeekingThrough && getLayerFE().hasRoundedCorners()); |
| 716 | } |
| 717 | |
Leon Scroggins III | 2e1aa18 | 2021-12-01 17:33:12 -0500 | [diff] [blame] | 718 | void OutputLayer::applyDeviceCompositionTypeChange(Composition compositionType) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 719 | auto& state = editState(); |
| 720 | LOG_FATAL_IF(!state.hwc); |
| 721 | auto& hwcState = *state.hwc; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 722 | |
Alec Mouri | d1bf1b5 | 2021-05-05 18:44:58 -0700 | [diff] [blame] | 723 | // Only detected disallowed changes if this was not a skip layer, because the |
| 724 | // validated composition type may be arbitrary (usually DEVICE, to reflect that there were |
| 725 | // fewer GPU layers) |
| 726 | if (!hwcState.layerSkipped) { |
| 727 | detectDisallowedCompositionTypeChange(hwcState.hwcCompositionType, compositionType); |
| 728 | } |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 729 | |
| 730 | hwcState.hwcCompositionType = compositionType; |
| 731 | } |
| 732 | |
| 733 | void OutputLayer::prepareForDeviceLayerRequests() { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 734 | auto& state = editState(); |
| 735 | state.clearClientTarget = false; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 736 | } |
| 737 | |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 738 | void OutputLayer::applyDeviceLayerRequest(hal::LayerRequest request) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 739 | auto& state = editState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 740 | switch (request) { |
Peiyong Lin | e9d809e | 2020-04-14 13:10:48 -0700 | [diff] [blame] | 741 | case hal::LayerRequest::CLEAR_CLIENT_TARGET: |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 742 | state.clearClientTarget = true; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 743 | break; |
| 744 | |
| 745 | default: |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 746 | ALOGE("[%s] Unknown device layer request %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 747 | toString(request).c_str(), static_cast<int>(request)); |
| 748 | break; |
| 749 | } |
| 750 | } |
| 751 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 752 | bool OutputLayer::needsFiltering() const { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 753 | const auto& state = getState(); |
| 754 | const auto& displayFrame = state.displayFrame; |
| 755 | const auto& sourceCrop = state.sourceCrop; |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 756 | return sourceCrop.getHeight() != displayFrame.getHeight() || |
| 757 | sourceCrop.getWidth() != displayFrame.getWidth(); |
| 758 | } |
| 759 | |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 760 | std::vector<LayerFE::LayerSettings> OutputLayer::getOverrideCompositionList() const { |
| 761 | if (getState().overrideInfo.buffer == nullptr) { |
| 762 | return {}; |
| 763 | } |
| 764 | |
Alec Mouri | 7be6c0a | 2021-03-19 15:22:01 -0700 | [diff] [blame] | 765 | // Compute the geometry boundaries in layer stack space: we need to transform from the |
| 766 | // framebuffer space of the override buffer to layer space. |
| 767 | const ProjectionSpace& layerSpace = getOutput().getState().layerStackSpace; |
| 768 | const ui::Transform transform = getState().overrideInfo.displaySpace.getTransform(layerSpace); |
Wiwit Rifa'i | e30a585 | 2021-06-25 19:20:48 +0800 | [diff] [blame] | 769 | const Rect boundaries = transform.transform(getState().overrideInfo.displaySpace.getContent()); |
Alec Mouri | 7be6c0a | 2021-03-19 15:22:01 -0700 | [diff] [blame] | 770 | |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 771 | LayerFE::LayerSettings settings; |
| 772 | settings.geometry = renderengine::Geometry{ |
Alec Mouri | 7be6c0a | 2021-03-19 15:22:01 -0700 | [diff] [blame] | 773 | .boundaries = boundaries.toFloatRect(), |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 774 | }; |
Alec Mouri | a90a570 | 2021-04-16 16:36:21 +0000 | [diff] [blame] | 775 | settings.bufferId = getState().overrideInfo.buffer->getBuffer()->getId(); |
Alec Mouri | 7be6c0a | 2021-03-19 15:22:01 -0700 | [diff] [blame] | 776 | settings.source = renderengine::PixelSource{ |
| 777 | .buffer = renderengine::Buffer{ |
| 778 | .buffer = getState().overrideInfo.buffer, |
| 779 | .fence = getState().overrideInfo.acquireFence, |
| 780 | // If the transform from layer space to display space contains a rotation, we |
| 781 | // need to undo the rotation in the texture transform |
| 782 | .textureTransform = |
| 783 | ui::Transform(transform.inverse().getOrientation(), 1, 1).asMatrix4(), |
| 784 | }}; |
Alec Mouri | 9c8fce0 | 2021-03-12 18:30:42 -0800 | [diff] [blame] | 785 | settings.sourceDataspace = getState().overrideInfo.dataspace; |
Dan Stoza | 6166c31 | 2021-01-15 16:34:05 -0800 | [diff] [blame] | 786 | settings.alpha = 1.0f; |
| 787 | |
| 788 | return {static_cast<LayerFE::LayerSettings>(settings)}; |
| 789 | } |
| 790 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 791 | void OutputLayer::dump(std::string& out) const { |
| 792 | using android::base::StringAppendF; |
| 793 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 794 | StringAppendF(&out, " - Output Layer %p(%s)\n", this, getLayerFE().getDebugName()); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 795 | dumpState(out); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 796 | } |
| 797 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 798 | } // namespace impl |
| 799 | } // namespace android::compositionengine |