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 | |
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 | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 19 | #include <compositionengine/LayerFE.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> |
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> |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 25 | |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 26 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 27 | #pragma clang diagnostic push |
| 28 | #pragma clang diagnostic ignored "-Wconversion" |
| 29 | |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 30 | #include "DisplayHardware/HWComposer.h" |
| 31 | |
Lloyd Pique | 3b5a69e | 2020-01-16 17:51:01 -0800 | [diff] [blame] | 32 | // TODO(b/129481165): remove the #pragma below and fix conversion issues |
| 33 | #pragma clang diagnostic pop // ignored "-Wconversion" |
| 34 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 35 | namespace android::compositionengine { |
| 36 | |
| 37 | OutputLayer::~OutputLayer() = default; |
| 38 | |
| 39 | namespace impl { |
| 40 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 41 | namespace { |
| 42 | |
| 43 | FloatRect reduce(const FloatRect& win, const Region& exclude) { |
| 44 | if (CC_LIKELY(exclude.isEmpty())) { |
| 45 | return win; |
| 46 | } |
| 47 | // Convert through Rect (by rounding) for lack of FloatRegion |
| 48 | return Region(Rect{win}).subtract(exclude).getBounds().toFloatRect(); |
| 49 | } |
| 50 | |
| 51 | } // namespace |
| 52 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 53 | std::unique_ptr<OutputLayer> createOutputLayer(const compositionengine::Output& output, |
| 54 | const sp<compositionengine::LayerFE>& layerFE) { |
| 55 | return createOutputLayerTemplated<OutputLayer>(output, layerFE); |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 56 | } |
| 57 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 58 | OutputLayer::~OutputLayer() = default; |
| 59 | |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 60 | void OutputLayer::setHwcLayer(std::shared_ptr<HWC2::Layer> hwcLayer) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 61 | auto& state = editState(); |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 62 | if (hwcLayer) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 63 | state.hwc.emplace(std::move(hwcLayer)); |
Lloyd Pique | df336d9 | 2019-03-07 21:38:42 -0800 | [diff] [blame] | 64 | } else { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 65 | state.hwc.reset(); |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 66 | } |
Lloyd Pique | 07e3321 | 2018-12-18 16:33:37 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 69 | Rect OutputLayer::calculateInitialCrop() const { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 70 | const auto& layerState = *getLayerFE().getCompositionState(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 71 | |
| 72 | // apply the projection's clipping to the window crop in |
| 73 | // layerstack space, and convert-back to layer space. |
| 74 | // if there are no window scaling involved, this operation will map to full |
| 75 | // pixels in the buffer. |
| 76 | |
| 77 | FloatRect activeCropFloat = |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 78 | reduce(layerState.geomLayerBounds, layerState.transparentRegionHint); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 79 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 80 | const Rect& viewport = getOutput().getState().viewport; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 81 | const ui::Transform& layerTransform = layerState.geomLayerTransform; |
| 82 | const ui::Transform& inverseLayerTransform = layerState.geomInverseLayerTransform; |
| 83 | // Transform to screen space. |
| 84 | activeCropFloat = layerTransform.transform(activeCropFloat); |
| 85 | activeCropFloat = activeCropFloat.intersect(viewport.toFloatRect()); |
| 86 | // Back to layer space to work with the content crop. |
| 87 | activeCropFloat = inverseLayerTransform.transform(activeCropFloat); |
| 88 | |
| 89 | // This needs to be here as transform.transform(Rect) computes the |
| 90 | // transformed rect and then takes the bounding box of the result before |
| 91 | // returning. This means |
| 92 | // transform.inverse().transform(transform.transform(Rect)) != Rect |
| 93 | // in which case we need to make sure the final rect is clipped to the |
| 94 | // display bounds. |
| 95 | Rect activeCrop{activeCropFloat}; |
| 96 | if (!activeCrop.intersect(layerState.geomBufferSize, &activeCrop)) { |
| 97 | activeCrop.clear(); |
| 98 | } |
| 99 | return activeCrop; |
| 100 | } |
| 101 | |
| 102 | FloatRect OutputLayer::calculateOutputSourceCrop() const { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 103 | const auto& layerState = *getLayerFE().getCompositionState(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 104 | const auto& outputState = getOutput().getState(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 105 | |
| 106 | if (!layerState.geomUsesSourceCrop) { |
| 107 | return {}; |
| 108 | } |
| 109 | |
| 110 | // the content crop is the area of the content that gets scaled to the |
| 111 | // layer's size. This is in buffer space. |
| 112 | FloatRect crop = layerState.geomContentCrop.toFloatRect(); |
| 113 | |
| 114 | // In addition there is a WM-specified crop we pull from our drawing state. |
| 115 | Rect activeCrop = calculateInitialCrop(); |
| 116 | const Rect& bufferSize = layerState.geomBufferSize; |
| 117 | |
| 118 | int winWidth = bufferSize.getWidth(); |
| 119 | int winHeight = bufferSize.getHeight(); |
| 120 | |
| 121 | // The bufferSize for buffer state layers can be unbounded ([0, 0, -1, -1]) |
| 122 | // if display frame hasn't been set and the parent is an unbounded layer. |
| 123 | if (winWidth < 0 && winHeight < 0) { |
| 124 | return crop; |
| 125 | } |
| 126 | |
| 127 | // Transform the window crop to match the buffer coordinate system, |
| 128 | // which means using the inverse of the current transform set on the |
| 129 | // SurfaceFlingerConsumer. |
| 130 | uint32_t invTransform = layerState.geomBufferTransform; |
| 131 | if (layerState.geomBufferUsesDisplayInverseTransform) { |
| 132 | /* |
| 133 | * the code below applies the primary display's inverse transform to the |
| 134 | * buffer |
| 135 | */ |
| 136 | uint32_t invTransformOrient = outputState.orientation; |
| 137 | // calculate the inverse transform |
| 138 | if (invTransformOrient & HAL_TRANSFORM_ROT_90) { |
| 139 | invTransformOrient ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H; |
| 140 | } |
| 141 | // and apply to the current transform |
| 142 | invTransform = |
| 143 | (ui::Transform(invTransformOrient) * ui::Transform(invTransform)).getOrientation(); |
| 144 | } |
| 145 | |
| 146 | if (invTransform & HAL_TRANSFORM_ROT_90) { |
| 147 | // If the activeCrop has been rotate the ends are rotated but not |
| 148 | // the space itself so when transforming ends back we can't rely on |
| 149 | // a modification of the axes of rotation. To account for this we |
| 150 | // need to reorient the inverse rotation in terms of the current |
| 151 | // axes of rotation. |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame^] | 152 | bool isHFlipped = (invTransform & HAL_TRANSFORM_FLIP_H) != 0; |
| 153 | bool isVFlipped = (invTransform & HAL_TRANSFORM_FLIP_V) != 0; |
| 154 | if (isHFlipped == isVFlipped) { |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 155 | invTransform ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H; |
| 156 | } |
| 157 | std::swap(winWidth, winHeight); |
| 158 | } |
| 159 | const Rect winCrop = |
| 160 | activeCrop.transform(invTransform, bufferSize.getWidth(), bufferSize.getHeight()); |
| 161 | |
| 162 | // below, crop is intersected with winCrop expressed in crop's coordinate space |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame^] | 163 | const float xScale = crop.getWidth() / float(winWidth); |
| 164 | const float yScale = crop.getHeight() / float(winHeight); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 165 | |
Marin Shalamanov | cfeebd4 | 2020-05-15 15:23:49 +0200 | [diff] [blame^] | 166 | const float insetLeft = winCrop.left * xScale; |
| 167 | const float insetTop = winCrop.top * yScale; |
| 168 | const float insetRight = (winWidth - winCrop.right) * xScale; |
| 169 | const float insetBottom = (winHeight - winCrop.bottom) * yScale; |
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 | crop.left += insetLeft; |
| 172 | crop.top += insetTop; |
| 173 | crop.right -= insetRight; |
| 174 | crop.bottom -= insetBottom; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 175 | |
| 176 | return crop; |
| 177 | } |
| 178 | |
| 179 | Rect OutputLayer::calculateOutputDisplayFrame() const { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 180 | const auto& layerState = *getLayerFE().getCompositionState(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 181 | const auto& outputState = getOutput().getState(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 182 | |
| 183 | // apply the layer's transform, followed by the display's global transform |
| 184 | // here we're guaranteed that the layer's transform preserves rects |
Lloyd Pique | c668734 | 2019-03-07 21:34:57 -0800 | [diff] [blame] | 185 | Region activeTransparentRegion = layerState.transparentRegionHint; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 186 | const ui::Transform& layerTransform = layerState.geomLayerTransform; |
| 187 | const ui::Transform& inverseLayerTransform = layerState.geomInverseLayerTransform; |
| 188 | const Rect& bufferSize = layerState.geomBufferSize; |
| 189 | Rect activeCrop = layerState.geomCrop; |
| 190 | if (!activeCrop.isEmpty() && bufferSize.isValid()) { |
| 191 | activeCrop = layerTransform.transform(activeCrop); |
| 192 | if (!activeCrop.intersect(outputState.viewport, &activeCrop)) { |
| 193 | activeCrop.clear(); |
| 194 | } |
| 195 | activeCrop = inverseLayerTransform.transform(activeCrop, true); |
| 196 | // This needs to be here as transform.transform(Rect) computes the |
| 197 | // transformed rect and then takes the bounding box of the result before |
| 198 | // returning. This means |
| 199 | // transform.inverse().transform(transform.transform(Rect)) != Rect |
| 200 | // in which case we need to make sure the final rect is clipped to the |
| 201 | // display bounds. |
| 202 | if (!activeCrop.intersect(bufferSize, &activeCrop)) { |
| 203 | activeCrop.clear(); |
| 204 | } |
| 205 | // mark regions outside the crop as transparent |
| 206 | activeTransparentRegion.orSelf(Rect(0, 0, bufferSize.getWidth(), activeCrop.top)); |
| 207 | activeTransparentRegion.orSelf( |
| 208 | Rect(0, activeCrop.bottom, bufferSize.getWidth(), bufferSize.getHeight())); |
| 209 | activeTransparentRegion.orSelf(Rect(0, activeCrop.top, activeCrop.left, activeCrop.bottom)); |
| 210 | activeTransparentRegion.orSelf( |
| 211 | Rect(activeCrop.right, activeCrop.top, bufferSize.getWidth(), activeCrop.bottom)); |
| 212 | } |
| 213 | |
| 214 | // reduce uses a FloatRect to provide more accuracy during the |
| 215 | // transformation. We then round upon constructing 'frame'. |
| 216 | Rect frame{ |
| 217 | layerTransform.transform(reduce(layerState.geomLayerBounds, activeTransparentRegion))}; |
| 218 | if (!frame.intersect(outputState.viewport, &frame)) { |
| 219 | frame.clear(); |
| 220 | } |
| 221 | const ui::Transform displayTransform{outputState.transform}; |
| 222 | |
| 223 | return displayTransform.transform(frame); |
| 224 | } |
| 225 | |
| 226 | uint32_t OutputLayer::calculateOutputRelativeBufferTransform() const { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 227 | const auto& layerState = *getLayerFE().getCompositionState(); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 228 | const auto& outputState = getOutput().getState(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 229 | |
| 230 | /* |
| 231 | * Transformations are applied in this order: |
| 232 | * 1) buffer orientation/flip/mirror |
| 233 | * 2) state transformation (window manager) |
| 234 | * 3) layer orientation (screen orientation) |
| 235 | * (NOTE: the matrices are multiplied in reverse order) |
| 236 | */ |
| 237 | const ui::Transform& layerTransform = layerState.geomLayerTransform; |
Rashed Abdel-Tawab | 6643cd8 | 2019-10-29 10:01:56 -0700 | [diff] [blame] | 238 | const ui::Transform displayTransform{outputState.transform}; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 239 | const ui::Transform bufferTransform{layerState.geomBufferTransform}; |
| 240 | ui::Transform transform(displayTransform * layerTransform * bufferTransform); |
| 241 | |
| 242 | if (layerState.geomBufferUsesDisplayInverseTransform) { |
| 243 | /* |
| 244 | * the code below applies the primary display's inverse transform to the |
| 245 | * buffer |
| 246 | */ |
| 247 | uint32_t invTransform = outputState.orientation; |
| 248 | // calculate the inverse transform |
| 249 | if (invTransform & HAL_TRANSFORM_ROT_90) { |
| 250 | invTransform ^= HAL_TRANSFORM_FLIP_V | HAL_TRANSFORM_FLIP_H; |
| 251 | } |
| 252 | |
| 253 | /* |
| 254 | * Here we cancel out the orientation component of the WM transform. |
| 255 | * The scaling and translate components are already included in our bounds |
| 256 | * computation so it's enough to just omit it in the composition. |
| 257 | * See comment in BufferLayer::prepareClientLayer with ref to b/36727915 for why. |
| 258 | */ |
Lloyd Pique | 546a245 | 2019-03-18 20:53:27 +0000 | [diff] [blame] | 259 | transform = ui::Transform(invTransform) * displayTransform * bufferTransform; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | // this gives us only the "orientation" component of the transform |
| 263 | return transform.getOrientation(); |
| 264 | } // namespace impl |
| 265 | |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 266 | void OutputLayer::updateCompositionState(bool includeGeometry, bool forceClientComposition) { |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 267 | const auto* layerFEState = getLayerFE().getCompositionState(); |
| 268 | if (!layerFEState) { |
| 269 | return; |
| 270 | } |
| 271 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 272 | const auto& outputState = getOutput().getState(); |
| 273 | const auto& profile = *getOutput().getDisplayColorProfile(); |
| 274 | auto& state = editState(); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 275 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 276 | if (includeGeometry) { |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 277 | // Clear the forceClientComposition flag before it is set for any |
| 278 | // reason. Note that since it can be set by some checks below when |
| 279 | // updating the geometry state, we only clear it when updating the |
| 280 | // geometry since those conditions for forcing client composition won't |
| 281 | // go away otherwise. |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 282 | state.forceClientComposition = false; |
Lloyd Pique | fe67102 | 2019-09-24 10:43:03 -0700 | [diff] [blame] | 283 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 284 | state.displayFrame = calculateOutputDisplayFrame(); |
| 285 | state.sourceCrop = calculateOutputSourceCrop(); |
| 286 | state.bufferTransform = |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 287 | static_cast<Hwc2::Transform>(calculateOutputRelativeBufferTransform()); |
| 288 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 289 | if ((layerFEState->isSecure && !outputState.isSecure) || |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 290 | (state.bufferTransform & ui::Transform::ROT_INVALID)) { |
| 291 | state.forceClientComposition = true; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 292 | } |
| 293 | } |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 294 | |
| 295 | // Determine the output dependent dataspace for this layer. If it is |
| 296 | // colorspace agnostic, it just uses the dataspace chosen for the output to |
| 297 | // avoid the need for color conversion. |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 298 | state.dataspace = layerFEState->isColorspaceAgnostic && |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 299 | outputState.targetDataspace != ui::Dataspace::UNKNOWN |
| 300 | ? outputState.targetDataspace |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 301 | : layerFEState->dataspace; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 302 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 303 | // These are evaluated every frame as they can potentially change at any |
| 304 | // time. |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 305 | if (layerFEState->forceClientComposition || !profile.isDataspaceSupported(state.dataspace) || |
Lloyd Pique | 7a23491 | 2019-10-03 11:54:27 -0700 | [diff] [blame] | 306 | forceClientComposition) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 307 | state.forceClientComposition = true; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 308 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 311 | void OutputLayer::writeStateToHWC(bool includeGeometry) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 312 | const auto& state = getState(); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 313 | // Skip doing this if there is no HWC interface |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 314 | if (!state.hwc) { |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 315 | return; |
| 316 | } |
| 317 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 318 | auto& hwcLayer = (*state.hwc).hwcLayer; |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 319 | if (!hwcLayer) { |
| 320 | 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] | 321 | getLayerFE().getDebugName(), getOutput().getName().c_str()); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 322 | return; |
| 323 | } |
| 324 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 325 | const auto* outputIndependentState = getLayerFE().getCompositionState(); |
| 326 | if (!outputIndependentState) { |
| 327 | return; |
| 328 | } |
| 329 | |
| 330 | auto requestedCompositionType = outputIndependentState->compositionType; |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 331 | |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 332 | if (includeGeometry) { |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 333 | writeOutputDependentGeometryStateToHWC(hwcLayer.get(), requestedCompositionType); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 334 | writeOutputIndependentGeometryStateToHWC(hwcLayer.get(), *outputIndependentState); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 335 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 336 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 337 | writeOutputDependentPerFrameStateToHWC(hwcLayer.get()); |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 338 | writeOutputIndependentPerFrameStateToHWC(hwcLayer.get(), *outputIndependentState); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 339 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 340 | writeCompositionTypeToHWC(hwcLayer.get(), requestedCompositionType); |
Lloyd Pique | 46b72df | 2019-10-29 13:19:27 -0700 | [diff] [blame] | 341 | |
| 342 | // Always set the layer color after setting the composition type. |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 343 | writeSolidColorStateToHWC(hwcLayer.get(), *outputIndependentState); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 344 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 345 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 346 | void OutputLayer::writeOutputDependentGeometryStateToHWC( |
| 347 | HWC2::Layer* hwcLayer, Hwc2::IComposerClient::Composition requestedCompositionType) { |
| 348 | const auto& outputDependentState = getState(); |
| 349 | |
| 350 | if (auto error = hwcLayer->setDisplayFrame(outputDependentState.displayFrame); |
| 351 | error != HWC2::Error::None) { |
| 352 | ALOGE("[%s] Failed to set display frame [%d, %d, %d, %d]: %s (%d)", |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 353 | getLayerFE().getDebugName(), outputDependentState.displayFrame.left, |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 354 | outputDependentState.displayFrame.top, outputDependentState.displayFrame.right, |
| 355 | outputDependentState.displayFrame.bottom, to_string(error).c_str(), |
| 356 | static_cast<int32_t>(error)); |
| 357 | } |
| 358 | |
| 359 | if (auto error = hwcLayer->setSourceCrop(outputDependentState.sourceCrop); |
| 360 | error != HWC2::Error::None) { |
| 361 | ALOGE("[%s] Failed to set source crop [%.3f, %.3f, %.3f, %.3f]: " |
| 362 | "%s (%d)", |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 363 | getLayerFE().getDebugName(), outputDependentState.sourceCrop.left, |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 364 | outputDependentState.sourceCrop.top, outputDependentState.sourceCrop.right, |
| 365 | outputDependentState.sourceCrop.bottom, to_string(error).c_str(), |
| 366 | static_cast<int32_t>(error)); |
| 367 | } |
| 368 | |
| 369 | if (auto error = hwcLayer->setZOrder(outputDependentState.z); error != HWC2::Error::None) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 370 | ALOGE("[%s] Failed to set Z %u: %s (%d)", getLayerFE().getDebugName(), |
| 371 | outputDependentState.z, to_string(error).c_str(), static_cast<int32_t>(error)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | // Solid-color layers should always use an identity transform. |
| 375 | const auto bufferTransform = |
| 376 | requestedCompositionType != Hwc2::IComposerClient::Composition::SOLID_COLOR |
| 377 | ? outputDependentState.bufferTransform |
| 378 | : static_cast<Hwc2::Transform>(0); |
| 379 | if (auto error = hwcLayer->setTransform(static_cast<HWC2::Transform>(bufferTransform)); |
| 380 | error != HWC2::Error::None) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 381 | ALOGE("[%s] Failed to set transform %s: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 382 | toString(outputDependentState.bufferTransform).c_str(), to_string(error).c_str(), |
| 383 | static_cast<int32_t>(error)); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | void OutputLayer::writeOutputIndependentGeometryStateToHWC( |
| 388 | HWC2::Layer* hwcLayer, const LayerFECompositionState& outputIndependentState) { |
| 389 | if (auto error = hwcLayer->setBlendMode( |
| 390 | static_cast<HWC2::BlendMode>(outputIndependentState.blendMode)); |
| 391 | error != HWC2::Error::None) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 392 | ALOGE("[%s] Failed to set blend mode %s: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 393 | toString(outputIndependentState.blendMode).c_str(), to_string(error).c_str(), |
| 394 | static_cast<int32_t>(error)); |
| 395 | } |
| 396 | |
| 397 | if (auto error = hwcLayer->setPlaneAlpha(outputIndependentState.alpha); |
| 398 | error != HWC2::Error::None) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 399 | ALOGE("[%s] Failed to set plane alpha %.3f: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 400 | outputIndependentState.alpha, to_string(error).c_str(), static_cast<int32_t>(error)); |
| 401 | } |
| 402 | |
Lloyd Pique | 0a45623 | 2020-01-16 17:51:13 -0800 | [diff] [blame] | 403 | if (auto error = hwcLayer->setInfo(static_cast<uint32_t>(outputIndependentState.type), |
| 404 | static_cast<uint32_t>(outputIndependentState.appId)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 405 | error != HWC2::Error::None) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 406 | ALOGE("[%s] Failed to set info %s (%d)", getLayerFE().getDebugName(), |
| 407 | to_string(error).c_str(), static_cast<int32_t>(error)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 408 | } |
Lloyd Pique | 8d9f836 | 2020-02-11 19:13:09 -0800 | [diff] [blame] | 409 | |
| 410 | for (const auto& [name, entry] : outputIndependentState.metadata) { |
| 411 | if (auto error = hwcLayer->setLayerGenericMetadata(name, entry.mandatory, entry.value); |
| 412 | error != HWC2::Error::None) { |
| 413 | ALOGE("[%s] Failed to set generic metadata %s %s (%d)", getLayerFE().getDebugName(), |
| 414 | name.c_str(), to_string(error).c_str(), static_cast<int32_t>(error)); |
| 415 | } |
| 416 | } |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 417 | } |
| 418 | |
| 419 | void OutputLayer::writeOutputDependentPerFrameStateToHWC(HWC2::Layer* hwcLayer) { |
| 420 | const auto& outputDependentState = getState(); |
| 421 | |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 422 | // TODO(lpique): b/121291683 outputSpaceVisibleRegion is output-dependent geometry |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 423 | // state and should not change every frame. |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 424 | if (auto error = hwcLayer->setVisibleRegion(outputDependentState.outputSpaceVisibleRegion); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 425 | error != HWC2::Error::None) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 426 | ALOGE("[%s] Failed to set visible region: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 427 | to_string(error).c_str(), static_cast<int32_t>(error)); |
Lloyd Pique | a246866 | 2019-03-07 21:31:06 -0800 | [diff] [blame] | 428 | outputDependentState.outputSpaceVisibleRegion.dump(LOG_TAG); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | if (auto error = hwcLayer->setDataspace(outputDependentState.dataspace); |
| 432 | error != HWC2::Error::None) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 433 | ALOGE("[%s] Failed to set dataspace %d: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 434 | outputDependentState.dataspace, to_string(error).c_str(), |
| 435 | static_cast<int32_t>(error)); |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | void OutputLayer::writeOutputIndependentPerFrameStateToHWC( |
| 440 | HWC2::Layer* hwcLayer, const LayerFECompositionState& outputIndependentState) { |
| 441 | switch (auto error = hwcLayer->setColorTransform(outputIndependentState.colorTransform)) { |
| 442 | case HWC2::Error::None: |
| 443 | break; |
| 444 | case HWC2::Error::Unsupported: |
| 445 | editState().forceClientComposition = true; |
| 446 | break; |
| 447 | default: |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 448 | ALOGE("[%s] Failed to set color transform: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 449 | to_string(error).c_str(), static_cast<int32_t>(error)); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 450 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 451 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 452 | if (auto error = hwcLayer->setSurfaceDamage(outputIndependentState.surfaceDamage); |
| 453 | error != HWC2::Error::None) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 454 | ALOGE("[%s] Failed to set surface damage: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 455 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 456 | outputIndependentState.surfaceDamage.dump(LOG_TAG); |
| 457 | } |
| 458 | |
| 459 | // Content-specific per-frame state |
| 460 | switch (outputIndependentState.compositionType) { |
| 461 | case Hwc2::IComposerClient::Composition::SOLID_COLOR: |
Lloyd Pique | 46b72df | 2019-10-29 13:19:27 -0700 | [diff] [blame] | 462 | // For compatibility, should be written AFTER the composition type. |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 463 | break; |
| 464 | case Hwc2::IComposerClient::Composition::SIDEBAND: |
| 465 | writeSidebandStateToHWC(hwcLayer, outputIndependentState); |
| 466 | break; |
| 467 | case Hwc2::IComposerClient::Composition::CURSOR: |
| 468 | case Hwc2::IComposerClient::Composition::DEVICE: |
| 469 | writeBufferStateToHWC(hwcLayer, outputIndependentState); |
| 470 | break; |
| 471 | case Hwc2::IComposerClient::Composition::INVALID: |
| 472 | case Hwc2::IComposerClient::Composition::CLIENT: |
| 473 | // Ignored |
| 474 | break; |
| 475 | } |
| 476 | } |
| 477 | |
| 478 | void OutputLayer::writeSolidColorStateToHWC(HWC2::Layer* hwcLayer, |
| 479 | const LayerFECompositionState& outputIndependentState) { |
Lloyd Pique | 46b72df | 2019-10-29 13:19:27 -0700 | [diff] [blame] | 480 | if (outputIndependentState.compositionType != Hwc2::IComposerClient::Composition::SOLID_COLOR) { |
| 481 | return; |
| 482 | } |
| 483 | |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 484 | hwc_color_t color = {static_cast<uint8_t>(std::round(255.0f * outputIndependentState.color.r)), |
| 485 | static_cast<uint8_t>(std::round(255.0f * outputIndependentState.color.g)), |
| 486 | static_cast<uint8_t>(std::round(255.0f * outputIndependentState.color.b)), |
| 487 | 255}; |
| 488 | |
| 489 | if (auto error = hwcLayer->setColor(color); error != HWC2::Error::None) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 490 | ALOGE("[%s] Failed to set color: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 491 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 492 | } |
| 493 | } |
| 494 | |
| 495 | void OutputLayer::writeSidebandStateToHWC(HWC2::Layer* hwcLayer, |
| 496 | const LayerFECompositionState& outputIndependentState) { |
| 497 | if (auto error = hwcLayer->setSidebandStream(outputIndependentState.sidebandStream->handle()); |
| 498 | error != HWC2::Error::None) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 499 | ALOGE("[%s] Failed to set sideband stream %p: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 500 | outputIndependentState.sidebandStream->handle(), to_string(error).c_str(), |
| 501 | static_cast<int32_t>(error)); |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | void OutputLayer::writeBufferStateToHWC(HWC2::Layer* hwcLayer, |
| 506 | const LayerFECompositionState& outputIndependentState) { |
| 507 | auto supportedPerFrameMetadata = |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 508 | getOutput().getDisplayColorProfile()->getSupportedPerFrameMetadata(); |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 509 | if (auto error = hwcLayer->setPerFrameMetadata(supportedPerFrameMetadata, |
| 510 | outputIndependentState.hdrMetadata); |
| 511 | error != HWC2::Error::None && error != HWC2::Error::Unsupported) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 512 | ALOGE("[%s] Failed to set hdrMetadata: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 513 | to_string(error).c_str(), static_cast<int32_t>(error)); |
| 514 | } |
| 515 | |
| 516 | uint32_t hwcSlot = 0; |
| 517 | sp<GraphicBuffer> hwcBuffer; |
| 518 | // We need access to the output-dependent state for the buffer cache there, |
| 519 | // though otherwise the buffer is not output-dependent. |
| 520 | editState().hwc->hwcBufferCache.getHwcBuffer(outputIndependentState.bufferSlot, |
| 521 | outputIndependentState.buffer, &hwcSlot, |
| 522 | &hwcBuffer); |
| 523 | |
| 524 | if (auto error = hwcLayer->setBuffer(hwcSlot, hwcBuffer, outputIndependentState.acquireFence); |
| 525 | error != HWC2::Error::None) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 526 | ALOGE("[%s] Failed to set buffer %p: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 527 | outputIndependentState.buffer->handle, to_string(error).c_str(), |
| 528 | static_cast<int32_t>(error)); |
| 529 | } |
| 530 | } |
| 531 | |
| 532 | void OutputLayer::writeCompositionTypeToHWC( |
| 533 | HWC2::Layer* hwcLayer, Hwc2::IComposerClient::Composition requestedCompositionType) { |
| 534 | auto& outputDependentState = editState(); |
| 535 | |
| 536 | // If we are forcing client composition, we need to tell the HWC |
| 537 | if (outputDependentState.forceClientComposition) { |
| 538 | requestedCompositionType = Hwc2::IComposerClient::Composition::CLIENT; |
| 539 | } |
| 540 | |
| 541 | // Set the requested composition type with the HWC whenever it changes |
| 542 | if (outputDependentState.hwc->hwcCompositionType != requestedCompositionType) { |
| 543 | outputDependentState.hwc->hwcCompositionType = requestedCompositionType; |
| 544 | |
| 545 | if (auto error = hwcLayer->setCompositionType( |
| 546 | static_cast<HWC2::Composition>(requestedCompositionType)); |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 547 | error != HWC2::Error::None) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 548 | ALOGE("[%s] Failed to set composition type %s: %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | f527548 | 2019-01-29 18:42:42 -0800 | [diff] [blame] | 549 | toString(requestedCompositionType).c_str(), to_string(error).c_str(), |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 550 | static_cast<int32_t>(error)); |
| 551 | } |
Lloyd Pique | a83776c | 2019-01-29 18:42:32 -0800 | [diff] [blame] | 552 | } |
| 553 | } |
| 554 | |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 555 | void OutputLayer::writeCursorPositionToHWC() const { |
| 556 | // Skip doing this if there is no HWC interface |
| 557 | auto hwcLayer = getHwcLayer(); |
| 558 | if (!hwcLayer) { |
| 559 | return; |
| 560 | } |
| 561 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 562 | const auto* layerFEState = getLayerFE().getCompositionState(); |
| 563 | if (!layerFEState) { |
| 564 | return; |
| 565 | } |
| 566 | |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 567 | const auto& outputState = getOutput().getState(); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 568 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 569 | Rect frame = layerFEState->cursorFrame; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 570 | frame.intersect(outputState.viewport, &frame); |
| 571 | Rect position = outputState.transform.transform(frame); |
| 572 | |
| 573 | if (auto error = hwcLayer->setCursorPosition(position.left, position.top); |
| 574 | error != HWC2::Error::None) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 575 | ALOGE("[%s] Failed to set cursor position to (%d, %d): %s (%d)", |
| 576 | getLayerFE().getDebugName(), position.left, position.top, to_string(error).c_str(), |
| 577 | static_cast<int32_t>(error)); |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 578 | } |
| 579 | } |
| 580 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 581 | HWC2::Layer* OutputLayer::getHwcLayer() const { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 582 | const auto& state = getState(); |
| 583 | return state.hwc ? state.hwc->hwcLayer.get() : nullptr; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 584 | } |
| 585 | |
| 586 | bool OutputLayer::requiresClientComposition() const { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 587 | const auto& state = getState(); |
| 588 | return !state.hwc || |
| 589 | state.hwc->hwcCompositionType == Hwc2::IComposerClient::Composition::CLIENT; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 590 | } |
| 591 | |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 592 | bool OutputLayer::isHardwareCursor() const { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 593 | const auto& state = getState(); |
| 594 | return state.hwc && state.hwc->hwcCompositionType == Hwc2::IComposerClient::Composition::CURSOR; |
Lloyd Pique | c7b0c75 | 2019-03-07 20:59:59 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 597 | void OutputLayer::detectDisallowedCompositionTypeChange( |
| 598 | Hwc2::IComposerClient::Composition from, Hwc2::IComposerClient::Composition to) const { |
| 599 | bool result = false; |
| 600 | switch (from) { |
| 601 | case Hwc2::IComposerClient::Composition::INVALID: |
| 602 | case Hwc2::IComposerClient::Composition::CLIENT: |
| 603 | result = false; |
| 604 | break; |
| 605 | |
| 606 | case Hwc2::IComposerClient::Composition::DEVICE: |
| 607 | case Hwc2::IComposerClient::Composition::SOLID_COLOR: |
| 608 | result = (to == Hwc2::IComposerClient::Composition::CLIENT); |
| 609 | break; |
| 610 | |
| 611 | case Hwc2::IComposerClient::Composition::CURSOR: |
| 612 | case Hwc2::IComposerClient::Composition::SIDEBAND: |
| 613 | result = (to == Hwc2::IComposerClient::Composition::CLIENT || |
| 614 | to == Hwc2::IComposerClient::Composition::DEVICE); |
| 615 | break; |
| 616 | } |
| 617 | |
| 618 | if (!result) { |
| 619 | ALOGE("[%s] Invalid device requested composition type change: %s (%d) --> %s (%d)", |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 620 | getLayerFE().getDebugName(), toString(from).c_str(), static_cast<int>(from), |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 621 | toString(to).c_str(), static_cast<int>(to)); |
| 622 | } |
| 623 | } |
| 624 | |
| 625 | void OutputLayer::applyDeviceCompositionTypeChange( |
| 626 | Hwc2::IComposerClient::Composition compositionType) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 627 | auto& state = editState(); |
| 628 | LOG_FATAL_IF(!state.hwc); |
| 629 | auto& hwcState = *state.hwc; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 630 | |
| 631 | detectDisallowedCompositionTypeChange(hwcState.hwcCompositionType, compositionType); |
| 632 | |
| 633 | hwcState.hwcCompositionType = compositionType; |
| 634 | } |
| 635 | |
| 636 | void OutputLayer::prepareForDeviceLayerRequests() { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 637 | auto& state = editState(); |
| 638 | state.clearClientTarget = false; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | void OutputLayer::applyDeviceLayerRequest(Hwc2::IComposerClient::LayerRequest request) { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 642 | auto& state = editState(); |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 643 | switch (request) { |
| 644 | case Hwc2::IComposerClient::LayerRequest::CLEAR_CLIENT_TARGET: |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 645 | state.clearClientTarget = true; |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 646 | break; |
| 647 | |
| 648 | default: |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 649 | ALOGE("[%s] Unknown device layer request %s (%d)", getLayerFE().getDebugName(), |
Lloyd Pique | 66d6860 | 2019-02-13 14:23:31 -0800 | [diff] [blame] | 650 | toString(request).c_str(), static_cast<int>(request)); |
| 651 | break; |
| 652 | } |
| 653 | } |
| 654 | |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 655 | bool OutputLayer::needsFiltering() const { |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 656 | const auto& state = getState(); |
| 657 | const auto& displayFrame = state.displayFrame; |
| 658 | const auto& sourceCrop = state.sourceCrop; |
Lloyd Pique | 688abd4 | 2019-02-15 15:42:24 -0800 | [diff] [blame] | 659 | return sourceCrop.getHeight() != displayFrame.getHeight() || |
| 660 | sourceCrop.getWidth() != displayFrame.getWidth(); |
| 661 | } |
| 662 | |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 663 | void OutputLayer::dump(std::string& out) const { |
| 664 | using android::base::StringAppendF; |
| 665 | |
Lloyd Pique | de19665 | 2020-01-22 17:29:58 -0800 | [diff] [blame] | 666 | StringAppendF(&out, " - Output Layer %p(%s)\n", this, getLayerFE().getDebugName()); |
Lloyd Pique | a38ea7e | 2019-04-16 18:10:26 -0700 | [diff] [blame] | 667 | dumpState(out); |
Lloyd Pique | 37c2c9b | 2018-12-04 17:25:10 -0800 | [diff] [blame] | 668 | } |
| 669 | |
Lloyd Pique | cc01a45 | 2018-12-04 17:24:00 -0800 | [diff] [blame] | 670 | } // namespace impl |
| 671 | } // namespace android::compositionengine |