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