Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2022 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 | |
| 17 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 18 | #undef LOG_TAG |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 19 | #define LOG_TAG "SurfaceFlinger" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 20 | |
| 21 | #include "LayerSnapshot.h" |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 22 | #include "Layer.h" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 23 | |
| 24 | namespace android::surfaceflinger::frontend { |
| 25 | |
| 26 | using namespace ftl::flag_operators; |
| 27 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 28 | namespace { |
| 29 | |
| 30 | void updateSurfaceDamage(const RequestedLayerState& requested, bool hasReadyFrame, |
| 31 | bool forceFullDamage, Region& outSurfaceDamageRegion) { |
| 32 | if (!hasReadyFrame) { |
| 33 | outSurfaceDamageRegion.clear(); |
| 34 | return; |
| 35 | } |
| 36 | if (forceFullDamage) { |
| 37 | outSurfaceDamageRegion = Region::INVALID_REGION; |
| 38 | } else { |
| 39 | outSurfaceDamageRegion = requested.surfaceDamageRegion; |
| 40 | } |
| 41 | } |
| 42 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 43 | std::ostream& operator<<(std::ostream& os, const ui::Transform& transform) { |
| 44 | const uint32_t type = transform.getType(); |
| 45 | const uint32_t orientation = transform.getOrientation(); |
| 46 | if (type == ui::Transform::IDENTITY) { |
| 47 | return os; |
| 48 | } |
| 49 | |
| 50 | if (type & ui::Transform::UNKNOWN) { |
| 51 | std::string out; |
| 52 | transform.dump(out, "", ""); |
| 53 | os << out; |
| 54 | return os; |
| 55 | } |
| 56 | |
| 57 | if (type & ui::Transform::ROTATE) { |
| 58 | switch (orientation) { |
| 59 | case ui::Transform::ROT_0: |
| 60 | os << "ROT_0"; |
| 61 | break; |
| 62 | case ui::Transform::FLIP_H: |
| 63 | os << "FLIP_H"; |
| 64 | break; |
| 65 | case ui::Transform::FLIP_V: |
| 66 | os << "FLIP_V"; |
| 67 | break; |
| 68 | case ui::Transform::ROT_90: |
| 69 | os << "ROT_90"; |
| 70 | break; |
| 71 | case ui::Transform::ROT_180: |
| 72 | os << "ROT_180"; |
| 73 | break; |
| 74 | case ui::Transform::ROT_270: |
| 75 | os << "ROT_270"; |
| 76 | break; |
| 77 | case ui::Transform::ROT_INVALID: |
| 78 | default: |
| 79 | os << "ROT_INVALID"; |
| 80 | break; |
| 81 | } |
| 82 | } |
| 83 | |
| 84 | if (type & ui::Transform::SCALE) { |
| 85 | std::string out; |
| 86 | android::base::StringAppendF(&out, " scale x=%.4f y=%.4f ", transform.getScaleX(), |
| 87 | transform.getScaleY()); |
| 88 | os << out; |
| 89 | } |
| 90 | |
| 91 | if (type & ui::Transform::TRANSLATE) { |
| 92 | std::string out; |
| 93 | android::base::StringAppendF(&out, " tx=%.4f ty=%.4f ", transform.tx(), transform.ty()); |
| 94 | os << out; |
| 95 | } |
| 96 | |
| 97 | return os; |
| 98 | } |
| 99 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 100 | } // namespace |
| 101 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 102 | LayerSnapshot::LayerSnapshot(const RequestedLayerState& state, |
| 103 | const LayerHierarchy::TraversalPath& path) |
| 104 | : path(path) { |
Vishnu Nair | d018360 | 2023-03-16 18:52:15 +0000 | [diff] [blame] | 105 | // Provide a unique id for all snapshots. |
| 106 | // A front end layer can generate multiple snapshots if its mirrored. |
| 107 | // Additionally, if the layer is not reachable, we may choose to destroy |
| 108 | // and recreate the snapshot in which case the unique sequence id will |
| 109 | // change. The consumer shouldn't tie any lifetimes to this unique id but |
| 110 | // register a LayerLifecycleManager::ILifecycleListener or get a list of |
| 111 | // destroyed layers from LayerLifecycleManager. |
Vishnu Nair | 150065b | 2023-04-17 19:14:11 -0700 | [diff] [blame] | 112 | if (path.isClone()) { |
| 113 | uniqueSequence = |
| 114 | LayerCreationArgs::getInternalLayerId(LayerCreationArgs::sInternalSequence++); |
| 115 | } else { |
| 116 | uniqueSequence = state.id; |
| 117 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 118 | sequence = static_cast<int32_t>(state.id); |
| 119 | name = state.name; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 120 | debugName = state.debugName; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 121 | premultipliedAlpha = state.premultipliedAlpha; |
| 122 | inputInfo.name = state.name; |
Vishnu Nair | 93b8b79 | 2023-02-27 19:40:24 +0000 | [diff] [blame] | 123 | inputInfo.id = static_cast<int32_t>(uniqueSequence); |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 124 | inputInfo.ownerUid = gui::Uid{state.ownerUid}; |
Prabir Pradhan | e59c6dc | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 125 | inputInfo.ownerPid = gui::Pid{state.ownerPid}; |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 126 | uid = state.ownerUid; |
| 127 | pid = state.ownerPid; |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 128 | changes = RequestedLayerState::Changes::Created; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 129 | clientChanges = 0; |
Vishnu Nair | 491827d | 2024-04-29 23:43:26 +0000 | [diff] [blame] | 130 | mirrorRootPath = |
| 131 | LayerHierarchy::isMirror(path.variant) ? path : LayerHierarchy::TraversalPath::ROOT; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 132 | reachablilty = LayerSnapshot::Reachablilty::Unreachable; |
Vishnu Nair | 3d8565a | 2023-06-30 07:23:24 +0000 | [diff] [blame] | 133 | frameRateSelectionPriority = state.frameRateSelectionPriority; |
| 134 | layerMetadata = state.metadata; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 135 | } |
| 136 | |
| 137 | // As documented in libhardware header, formats in the range |
| 138 | // 0x100 - 0x1FF are specific to the HAL implementation, and |
| 139 | // are known to have no alpha channel |
| 140 | // TODO: move definition for device-specific range into |
| 141 | // hardware.h, instead of using hard-coded values here. |
| 142 | #define HARDWARE_IS_DEVICE_FORMAT(f) ((f) >= 0x100 && (f) <= 0x1FF) |
| 143 | |
| 144 | bool LayerSnapshot::isOpaqueFormat(PixelFormat format) { |
| 145 | if (HARDWARE_IS_DEVICE_FORMAT(format)) { |
| 146 | return true; |
| 147 | } |
| 148 | switch (format) { |
| 149 | case PIXEL_FORMAT_RGBA_8888: |
| 150 | case PIXEL_FORMAT_BGRA_8888: |
| 151 | case PIXEL_FORMAT_RGBA_FP16: |
| 152 | case PIXEL_FORMAT_RGBA_1010102: |
| 153 | case PIXEL_FORMAT_R_8: |
| 154 | return false; |
| 155 | } |
| 156 | // in all other case, we have no blending (also for unknown formats) |
| 157 | return true; |
| 158 | } |
| 159 | |
| 160 | bool LayerSnapshot::hasBufferOrSidebandStream() const { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 161 | return ((sidebandStream != nullptr) || (externalTexture != nullptr)); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 162 | } |
| 163 | |
| 164 | bool LayerSnapshot::drawShadows() const { |
| 165 | return shadowSettings.length > 0.f; |
| 166 | } |
| 167 | |
| 168 | bool LayerSnapshot::fillsColor() const { |
| 169 | return !hasBufferOrSidebandStream() && color.r >= 0.0_hf && color.g >= 0.0_hf && |
| 170 | color.b >= 0.0_hf; |
| 171 | } |
| 172 | |
| 173 | bool LayerSnapshot::hasBlur() const { |
| 174 | return backgroundBlurRadius > 0 || blurRegions.size() > 0; |
| 175 | } |
| 176 | |
| 177 | bool LayerSnapshot::hasEffect() const { |
| 178 | return fillsColor() || drawShadows() || hasBlur(); |
| 179 | } |
| 180 | |
| 181 | bool LayerSnapshot::hasSomethingToDraw() const { |
| 182 | return hasEffect() || hasBufferOrSidebandStream(); |
| 183 | } |
| 184 | |
| 185 | bool LayerSnapshot::isContentOpaque() const { |
| 186 | // if we don't have a buffer or sidebandStream yet, we're translucent regardless of the |
| 187 | // layer's opaque flag. |
| 188 | if (!hasSomethingToDraw()) { |
| 189 | return false; |
| 190 | } |
| 191 | |
| 192 | // if the layer has the opaque flag, then we're always opaque |
| 193 | if (layerOpaqueFlagSet) { |
| 194 | return true; |
| 195 | } |
| 196 | |
| 197 | // If the buffer has no alpha channel, then we are opaque |
| 198 | if (hasBufferOrSidebandStream() && |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 199 | isOpaqueFormat(externalTexture ? externalTexture->getPixelFormat() : PIXEL_FORMAT_NONE)) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 200 | return true; |
| 201 | } |
| 202 | |
| 203 | // Lastly consider the layer opaque if drawing a color with alpha == 1.0 |
| 204 | return fillsColor() && color.a == 1.0_hf; |
| 205 | } |
| 206 | |
| 207 | bool LayerSnapshot::isHiddenByPolicy() const { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 208 | return invalidTransform || isHiddenByPolicyFromParent || isHiddenByPolicyFromRelativeParent; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 209 | } |
| 210 | |
| 211 | bool LayerSnapshot::getIsVisible() const { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 212 | if (reachablilty != LayerSnapshot::Reachablilty::Reachable) { |
| 213 | return false; |
| 214 | } |
| 215 | |
Vishnu Nair | a9c4376 | 2023-01-27 19:10:25 +0000 | [diff] [blame] | 216 | if (handleSkipScreenshotFlag & outputFilter.toInternalDisplay) { |
| 217 | return false; |
| 218 | } |
| 219 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 220 | if (!hasSomethingToDraw()) { |
| 221 | return false; |
| 222 | } |
| 223 | |
| 224 | if (isHiddenByPolicy()) { |
| 225 | return false; |
| 226 | } |
| 227 | |
| 228 | return color.a > 0.0f || hasBlur(); |
| 229 | } |
| 230 | |
| 231 | std::string LayerSnapshot::getIsVisibleReason() const { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 232 | // not visible |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 233 | if (reachablilty == LayerSnapshot::Reachablilty::Unreachable) |
| 234 | return "layer not reachable from root"; |
| 235 | if (reachablilty == LayerSnapshot::Reachablilty::ReachableByRelativeParent) |
| 236 | return "layer only reachable via relative parent"; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 237 | if (isHiddenByPolicyFromParent) return "hidden by parent or layer flag"; |
| 238 | if (isHiddenByPolicyFromRelativeParent) return "hidden by relative parent"; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 239 | if (handleSkipScreenshotFlag & outputFilter.toInternalDisplay) return "eLayerSkipScreenshot"; |
| 240 | if (invalidTransform) return "invalidTransform"; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 241 | if (color.a == 0.0f && !hasBlur()) return "alpha = 0 and no blur"; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 242 | if (!hasSomethingToDraw()) return "nothing to draw"; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 243 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 244 | // visible |
| 245 | std::stringstream reason; |
| 246 | if (sidebandStream != nullptr) reason << " sidebandStream"; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 247 | if (externalTexture != nullptr) |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 248 | reason << " buffer=" << externalTexture->getId() << " frame=" << frameNumber; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 249 | if (fillsColor() || color.a > 0.0f) reason << " color{" << color << "}"; |
| 250 | if (drawShadows()) reason << " shadowSettings.length=" << shadowSettings.length; |
| 251 | if (backgroundBlurRadius > 0) reason << " backgroundBlurRadius=" << backgroundBlurRadius; |
| 252 | if (blurRegions.size() > 0) reason << " blurRegions.size()=" << blurRegions.size(); |
| 253 | return reason.str(); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | bool LayerSnapshot::canReceiveInput() const { |
| 257 | return !isHiddenByPolicy() && (!hasBufferOrSidebandStream() || color.a > 0.0f); |
| 258 | } |
| 259 | |
| 260 | bool LayerSnapshot::isTransformValid(const ui::Transform& t) { |
| 261 | float transformDet = t.det(); |
| 262 | return transformDet != 0 && !isinf(transformDet) && !isnan(transformDet); |
| 263 | } |
| 264 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 265 | bool LayerSnapshot::hasInputInfo() const { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 266 | return (inputInfo.token != nullptr || |
| 267 | inputInfo.inputConfig.test(gui::WindowInfo::InputConfig::NO_INPUT_CHANNEL)) && |
| 268 | reachablilty == Reachablilty::Reachable; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 269 | } |
| 270 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 271 | std::string LayerSnapshot::getDebugString() const { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 272 | std::stringstream debug; |
| 273 | debug << "Snapshot{" << path.toString() << name << " isVisible=" << isVisible << " {" |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 274 | << getIsVisibleReason() << "} changes=" << changes.string() |
Vishnu Nair | 36d5f8e | 2023-03-19 13:31:35 -0700 | [diff] [blame] | 275 | << " layerStack=" << outputFilter.layerStack.id << " geomLayerBounds={" |
| 276 | << geomLayerBounds.left << "," << geomLayerBounds.top << "," << geomLayerBounds.bottom |
| 277 | << "," << geomLayerBounds.right << "}" |
| 278 | << " geomLayerTransform={tx=" << geomLayerTransform.tx() |
| 279 | << ",ty=" << geomLayerTransform.ty() << "}" |
| 280 | << "}"; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 281 | if (hasInputInfo()) { |
| 282 | debug << " input{" |
| 283 | << "(" << inputInfo.inputConfig.string() << ")"; |
| 284 | if (touchCropId != UNASSIGNED_LAYER_ID) debug << " touchCropId=" << touchCropId; |
| 285 | if (inputInfo.replaceTouchableRegionWithCrop) debug << " replaceTouchableRegionWithCrop"; |
| 286 | auto touchableRegion = inputInfo.touchableRegion.getBounds(); |
| 287 | debug << " touchableRegion={" << touchableRegion.left << "," << touchableRegion.top << "," |
| 288 | << touchableRegion.bottom << "," << touchableRegion.right << "}" |
| 289 | << "}"; |
| 290 | } |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 291 | return debug.str(); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 294 | std::ostream& operator<<(std::ostream& out, const LayerSnapshot& obj) { |
| 295 | out << "Layer [" << obj.path.id; |
Vishnu Nair | 6f87831 | 2023-09-08 11:05:01 -0700 | [diff] [blame] | 296 | if (!obj.path.mirrorRootIds.empty()) { |
| 297 | out << " mirrored from "; |
| 298 | for (auto rootId : obj.path.mirrorRootIds) { |
| 299 | out << rootId << ","; |
| 300 | } |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 301 | } |
| 302 | out << "] " << obj.name << "\n " << (obj.isVisible ? "visible" : "invisible") |
| 303 | << " reason=" << obj.getIsVisibleReason(); |
| 304 | |
| 305 | if (!obj.geomLayerBounds.isEmpty()) { |
| 306 | out << "\n bounds={" << obj.transformedBounds.left << "," << obj.transformedBounds.top |
| 307 | << "," << obj.transformedBounds.bottom << "," << obj.transformedBounds.right << "}"; |
| 308 | } |
| 309 | |
| 310 | if (obj.geomLayerTransform.getType() != ui::Transform::IDENTITY) { |
| 311 | out << " toDisplayTransform={" << obj.geomLayerTransform << "}"; |
| 312 | } |
| 313 | |
| 314 | if (obj.hasInputInfo()) { |
| 315 | out << "\n input{" |
| 316 | << "(" << obj.inputInfo.inputConfig.string() << ")"; |
Vishnu Nair | 59a6be3 | 2024-01-29 10:26:21 -0800 | [diff] [blame] | 317 | if (obj.inputInfo.canOccludePresentation) out << " canOccludePresentation"; |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 318 | if (obj.touchCropId != UNASSIGNED_LAYER_ID) out << " touchCropId=" << obj.touchCropId; |
| 319 | if (obj.inputInfo.replaceTouchableRegionWithCrop) out << " replaceTouchableRegionWithCrop"; |
| 320 | auto touchableRegion = obj.inputInfo.touchableRegion.getBounds(); |
| 321 | out << " touchableRegion={" << touchableRegion.left << "," << touchableRegion.top << "," |
| 322 | << touchableRegion.bottom << "," << touchableRegion.right << "}" |
| 323 | << "}"; |
| 324 | } |
Marzia Favaro | dcc9d9b | 2024-01-10 10:17:00 +0000 | [diff] [blame] | 325 | |
| 326 | if (obj.edgeExtensionEffect.hasEffect()) { |
| 327 | out << obj.edgeExtensionEffect; |
| 328 | } |
Vishnu Nair | 3cc15a4 | 2023-06-30 06:20:22 +0000 | [diff] [blame] | 329 | return out; |
| 330 | } |
| 331 | |
Vishnu Nair | 781d725 | 2023-01-30 18:16:01 +0000 | [diff] [blame] | 332 | FloatRect LayerSnapshot::sourceBounds() const { |
| 333 | if (!externalTexture) { |
| 334 | return geomLayerBounds; |
| 335 | } |
| 336 | return geomBufferSize.toFloatRect(); |
| 337 | } |
| 338 | |
Alec Mouri | 89f5d4e | 2023-10-20 17:12:49 +0000 | [diff] [blame] | 339 | bool LayerSnapshot::isFrontBuffered() const { |
| 340 | if (!externalTexture) { |
| 341 | return false; |
| 342 | } |
| 343 | |
| 344 | return externalTexture->getUsage() & AHARDWAREBUFFER_USAGE_FRONT_BUFFER; |
| 345 | } |
| 346 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 347 | Hwc2::IComposerClient::BlendMode LayerSnapshot::getBlendMode( |
| 348 | const RequestedLayerState& requested) const { |
| 349 | auto blendMode = Hwc2::IComposerClient::BlendMode::NONE; |
| 350 | if (alpha != 1.0f || !contentOpaque) { |
| 351 | blendMode = requested.premultipliedAlpha ? Hwc2::IComposerClient::BlendMode::PREMULTIPLIED |
| 352 | : Hwc2::IComposerClient::BlendMode::COVERAGE; |
| 353 | } |
| 354 | return blendMode; |
| 355 | } |
| 356 | |
| 357 | void LayerSnapshot::merge(const RequestedLayerState& requested, bool forceUpdate, |
| 358 | bool displayChanges, bool forceFullDamage, |
| 359 | uint32_t displayRotationFlags) { |
| 360 | clientChanges = requested.what; |
| 361 | changes = requested.changes; |
| 362 | contentDirty = requested.what & layer_state_t::CONTENT_DIRTY; |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 363 | hasReadyFrame = requested.autoRefresh; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 364 | sidebandStreamHasFrame = requested.hasSidebandStreamFrame(); |
Vishnu Nair | 6f209e2 | 2023-08-04 16:33:23 +0000 | [diff] [blame] | 365 | updateSurfaceDamage(requested, requested.hasReadyFrame(), forceFullDamage, surfaceDamage); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 366 | |
| 367 | if (forceUpdate || requested.what & layer_state_t::eTransparentRegionChanged) { |
| 368 | transparentRegionHint = requested.transparentRegion; |
| 369 | } |
| 370 | if (forceUpdate || requested.what & layer_state_t::eFlagsChanged) { |
| 371 | layerOpaqueFlagSet = |
| 372 | (requested.flags & layer_state_t::eLayerOpaque) == layer_state_t::eLayerOpaque; |
| 373 | } |
| 374 | if (forceUpdate || requested.what & layer_state_t::eBufferTransformChanged) { |
| 375 | geomBufferTransform = requested.bufferTransform; |
| 376 | } |
| 377 | if (forceUpdate || requested.what & layer_state_t::eTransformToDisplayInverseChanged) { |
| 378 | geomBufferUsesDisplayInverseTransform = requested.transformToDisplayInverse; |
| 379 | } |
| 380 | if (forceUpdate || requested.what & layer_state_t::eDataspaceChanged) { |
Vishnu Nair | 3996ee3 | 2023-08-14 04:32:31 +0000 | [diff] [blame] | 381 | dataspace = Layer::translateDataspace(requested.dataspace); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 382 | } |
| 383 | if (forceUpdate || requested.what & layer_state_t::eExtendedRangeBrightnessChanged) { |
| 384 | currentHdrSdrRatio = requested.currentHdrSdrRatio; |
| 385 | desiredHdrSdrRatio = requested.desiredHdrSdrRatio; |
| 386 | } |
Alec Mouri | 1b0d4e1 | 2024-02-12 22:27:19 +0000 | [diff] [blame] | 387 | if (forceUpdate || requested.what & layer_state_t::eDesiredHdrHeadroomChanged) { |
| 388 | desiredHdrSdrRatio = requested.desiredHdrSdrRatio; |
| 389 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 390 | if (forceUpdate || requested.what & layer_state_t::eCachingHintChanged) { |
| 391 | cachingHint = requested.cachingHint; |
| 392 | } |
| 393 | if (forceUpdate || requested.what & layer_state_t::eHdrMetadataChanged) { |
| 394 | hdrMetadata = requested.hdrMetadata; |
| 395 | } |
| 396 | if (forceUpdate || requested.what & layer_state_t::eSidebandStreamChanged) { |
| 397 | sidebandStream = requested.sidebandStream; |
| 398 | } |
| 399 | if (forceUpdate || requested.what & layer_state_t::eShadowRadiusChanged) { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 400 | shadowSettings.length = requested.shadowRadius; |
| 401 | } |
| 402 | if (forceUpdate || requested.what & layer_state_t::eFrameRateSelectionPriority) { |
| 403 | frameRateSelectionPriority = requested.frameRateSelectionPriority; |
| 404 | } |
| 405 | if (forceUpdate || requested.what & layer_state_t::eColorSpaceAgnosticChanged) { |
| 406 | isColorspaceAgnostic = requested.colorSpaceAgnostic; |
| 407 | } |
| 408 | if (forceUpdate || requested.what & layer_state_t::eDimmingEnabledChanged) { |
| 409 | dimmingEnabled = requested.dimmingEnabled; |
| 410 | } |
| 411 | if (forceUpdate || requested.what & layer_state_t::eCropChanged) { |
| 412 | geomCrop = requested.crop; |
| 413 | } |
| 414 | |
Vishnu Nair | 80e8cfe | 2023-09-29 17:03:45 -0700 | [diff] [blame] | 415 | if (forceUpdate || requested.what & layer_state_t::eDefaultFrameRateCompatibilityChanged) { |
| 416 | const auto compatibility = |
| 417 | Layer::FrameRate::convertCompatibility(requested.defaultFrameRateCompatibility); |
| 418 | if (defaultFrameRateCompatibility != compatibility) { |
| 419 | clientChanges |= layer_state_t::eDefaultFrameRateCompatibilityChanged; |
| 420 | } |
| 421 | defaultFrameRateCompatibility = compatibility; |
| 422 | } |
| 423 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 424 | if (forceUpdate || |
| 425 | requested.what & |
| 426 | (layer_state_t::eFlagsChanged | layer_state_t::eBufferChanged | |
| 427 | layer_state_t::eSidebandStreamChanged)) { |
| 428 | compositionType = requested.getCompositionType(); |
| 429 | } |
| 430 | |
| 431 | if (forceUpdate || requested.what & layer_state_t::eInputInfoChanged) { |
| 432 | if (requested.windowInfoHandle) { |
| 433 | inputInfo = *requested.windowInfoHandle->getInfo(); |
| 434 | } else { |
| 435 | inputInfo = {}; |
| 436 | // b/271132344 revisit this and see if we can always use the layers uid/pid |
| 437 | inputInfo.name = requested.name; |
| 438 | inputInfo.ownerUid = requested.ownerUid; |
| 439 | inputInfo.ownerPid = requested.ownerPid; |
| 440 | } |
| 441 | inputInfo.id = static_cast<int32_t>(uniqueSequence); |
| 442 | touchCropId = requested.touchCropId; |
| 443 | } |
| 444 | |
| 445 | if (forceUpdate || |
| 446 | requested.what & |
| 447 | (layer_state_t::eColorChanged | layer_state_t::eBufferChanged | |
| 448 | layer_state_t::eSidebandStreamChanged)) { |
| 449 | color.rgb = requested.getColor().rgb; |
| 450 | } |
| 451 | |
| 452 | if (forceUpdate || requested.what & layer_state_t::eBufferChanged) { |
| 453 | acquireFence = |
| 454 | (requested.externalTexture && |
| 455 | requested.bufferData->flags.test(BufferData::BufferDataChange::fenceChanged)) |
| 456 | ? requested.bufferData->acquireFence |
| 457 | : Fence::NO_FENCE; |
| 458 | buffer = requested.externalTexture ? requested.externalTexture->getBuffer() : nullptr; |
| 459 | externalTexture = requested.externalTexture; |
| 460 | frameNumber = (requested.bufferData) ? requested.bufferData->frameNumber : 0; |
| 461 | hasProtectedContent = requested.externalTexture && |
| 462 | requested.externalTexture->getUsage() & GRALLOC_USAGE_PROTECTED; |
| 463 | geomUsesSourceCrop = hasBufferOrSidebandStream(); |
| 464 | } |
| 465 | |
| 466 | if (forceUpdate || |
| 467 | requested.what & |
| 468 | (layer_state_t::eCropChanged | layer_state_t::eBufferCropChanged | |
| 469 | layer_state_t::eBufferTransformChanged | |
| 470 | layer_state_t::eTransformToDisplayInverseChanged) || |
| 471 | requested.changes.test(RequestedLayerState::Changes::BufferSize) || displayChanges) { |
| 472 | bufferSize = requested.getBufferSize(displayRotationFlags); |
| 473 | geomBufferSize = bufferSize; |
| 474 | croppedBufferSize = requested.getCroppedBufferSize(bufferSize); |
| 475 | geomContentCrop = requested.getBufferCrop(); |
| 476 | } |
| 477 | |
Vishnu Nair | 491827d | 2024-04-29 23:43:26 +0000 | [diff] [blame] | 478 | if ((forceUpdate || |
| 479 | requested.what & |
| 480 | (layer_state_t::eFlagsChanged | layer_state_t::eDestinationFrameChanged | |
| 481 | layer_state_t::ePositionChanged | layer_state_t::eMatrixChanged | |
| 482 | layer_state_t::eBufferTransformChanged | |
| 483 | layer_state_t::eTransformToDisplayInverseChanged) || |
| 484 | requested.changes.test(RequestedLayerState::Changes::BufferSize) || displayChanges) && |
| 485 | !ignoreLocalTransform) { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 486 | localTransform = requested.getTransform(displayRotationFlags); |
| 487 | localTransformInverse = localTransform.inverse(); |
| 488 | } |
| 489 | |
| 490 | if (forceUpdate || requested.what & (layer_state_t::eColorChanged) || |
| 491 | requested.changes.test(RequestedLayerState::Changes::BufferSize)) { |
| 492 | color.rgb = requested.getColor().rgb; |
| 493 | } |
| 494 | |
| 495 | if (forceUpdate || |
| 496 | requested.what & |
| 497 | (layer_state_t::eBufferChanged | layer_state_t::eDataspaceChanged | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 498 | layer_state_t::eApiChanged | layer_state_t::eShadowRadiusChanged | |
Marzia Favaro | dcc9d9b | 2024-01-10 10:17:00 +0000 | [diff] [blame] | 499 | layer_state_t::eBlurRegionsChanged | layer_state_t::eStretchChanged | |
| 500 | layer_state_t::eEdgeExtensionChanged)) { |
| 501 | forceClientComposition = shadowSettings.length > 0 || stretchEffect.hasEffect() || |
| 502 | edgeExtensionEffect.hasEffect(); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | if (forceUpdate || |
| 506 | requested.what & |
| 507 | (layer_state_t::eColorChanged | layer_state_t::eShadowRadiusChanged | |
| 508 | layer_state_t::eBlurRegionsChanged | layer_state_t::eBackgroundBlurRadiusChanged | |
| 509 | layer_state_t::eCornerRadiusChanged | layer_state_t::eAlphaChanged | |
| 510 | layer_state_t::eFlagsChanged | layer_state_t::eBufferChanged | |
| 511 | layer_state_t::eSidebandStreamChanged)) { |
| 512 | contentOpaque = isContentOpaque(); |
| 513 | isOpaque = contentOpaque && !roundedCorner.hasRoundedCorners() && color.a == 1.f; |
| 514 | blendMode = getBlendMode(requested); |
| 515 | } |
Sally Qi | 0abc4a5 | 2024-09-26 16:13:06 -0700 | [diff] [blame^] | 516 | |
| 517 | if (forceUpdate || requested.what & layer_state_t::eLutsChanged) { |
| 518 | luts = requested.luts; |
| 519 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 522 | } // namespace android::surfaceflinger::frontend |