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