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