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