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 LOG_NDEBUG 0 |
| 18 | #define ATRACE_TAG ATRACE_TAG_GRAPHICS |
| 19 | #undef LOG_TAG |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 20 | #define LOG_TAG "SurfaceFlinger" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 21 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 22 | #include <numeric> |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 23 | #include <optional> |
| 24 | |
Vishnu Nair | 9e0017e | 2024-05-22 19:02:44 +0000 | [diff] [blame] | 25 | #include <common/FlagManager.h> |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 26 | #include <common/trace.h> |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 27 | #include <ftl/small_map.h> |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 28 | #include <ui/DisplayMap.h> |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 29 | #include <ui/FloatRect.h> |
| 30 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 31 | #include "DisplayHardware/HWC2.h" |
| 32 | #include "DisplayHardware/Hal.h" |
Vishnu Nair | 3d8565a | 2023-06-30 07:23:24 +0000 | [diff] [blame] | 33 | #include "Layer.h" // eFrameRateSelectionPriority constants |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 34 | #include "LayerLog.h" |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 35 | #include "LayerSnapshotBuilder.h" |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 36 | #include "TimeStats/TimeStats.h" |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 37 | #include "Tracing/TransactionTracing.h" |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 38 | |
| 39 | namespace android::surfaceflinger::frontend { |
| 40 | |
| 41 | using namespace ftl::flag_operators; |
| 42 | |
| 43 | namespace { |
Dominik Laskowski | 6b049ff | 2023-01-29 15:46:45 -0500 | [diff] [blame] | 44 | |
| 45 | FloatRect getMaxDisplayBounds(const DisplayInfos& displays) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 46 | const ui::Size maxSize = [&displays] { |
| 47 | if (displays.empty()) return ui::Size{5000, 5000}; |
| 48 | |
| 49 | return std::accumulate(displays.begin(), displays.end(), ui::kEmptySize, |
| 50 | [](ui::Size size, const auto& pair) -> ui::Size { |
| 51 | const auto& display = pair.second; |
| 52 | return {std::max(size.getWidth(), display.info.logicalWidth), |
| 53 | std::max(size.getHeight(), display.info.logicalHeight)}; |
| 54 | }); |
| 55 | }(); |
| 56 | |
| 57 | // Ignore display bounds for now since they will be computed later. Use a large Rect bound |
| 58 | // to ensure it's bigger than an actual display will be. |
| 59 | const float xMax = static_cast<float>(maxSize.getWidth()) * 10.f; |
| 60 | const float yMax = static_cast<float>(maxSize.getHeight()) * 10.f; |
| 61 | |
| 62 | return {-xMax, -yMax, xMax, yMax}; |
| 63 | } |
| 64 | |
| 65 | // Applies the given transform to the region, while protecting against overflows caused by any |
| 66 | // offsets. If applying the offset in the transform to any of the Rects in the region would result |
| 67 | // in an overflow, they are not added to the output Region. |
| 68 | Region transformTouchableRegionSafely(const ui::Transform& t, const Region& r, |
| 69 | const std::string& debugWindowName) { |
| 70 | // Round the translation using the same rounding strategy used by ui::Transform. |
| 71 | const auto tx = static_cast<int32_t>(t.tx() + 0.5); |
| 72 | const auto ty = static_cast<int32_t>(t.ty() + 0.5); |
| 73 | |
| 74 | ui::Transform transformWithoutOffset = t; |
| 75 | transformWithoutOffset.set(0.f, 0.f); |
| 76 | |
| 77 | const Region transformed = transformWithoutOffset.transform(r); |
| 78 | |
| 79 | // Apply the translation to each of the Rects in the region while discarding any that overflow. |
| 80 | Region ret; |
| 81 | for (const auto& rect : transformed) { |
| 82 | Rect newRect; |
| 83 | if (__builtin_add_overflow(rect.left, tx, &newRect.left) || |
| 84 | __builtin_add_overflow(rect.top, ty, &newRect.top) || |
| 85 | __builtin_add_overflow(rect.right, tx, &newRect.right) || |
| 86 | __builtin_add_overflow(rect.bottom, ty, &newRect.bottom)) { |
| 87 | ALOGE("Applying transform to touchable region of window '%s' resulted in an overflow.", |
| 88 | debugWindowName.c_str()); |
| 89 | continue; |
| 90 | } |
| 91 | ret.orSelf(newRect); |
| 92 | } |
| 93 | return ret; |
| 94 | } |
| 95 | |
| 96 | /* |
| 97 | * We don't want to send the layer's transform to input, but rather the |
| 98 | * parent's transform. This is because Layer's transform is |
| 99 | * information about how the buffer is placed on screen. The parent's |
| 100 | * transform makes more sense to send since it's information about how the |
| 101 | * layer is placed on screen. This transform is used by input to determine |
| 102 | * how to go from screen space back to window space. |
| 103 | */ |
| 104 | ui::Transform getInputTransform(const LayerSnapshot& snapshot) { |
| 105 | if (!snapshot.hasBufferOrSidebandStream()) { |
| 106 | return snapshot.geomLayerTransform; |
| 107 | } |
| 108 | return snapshot.parentTransform; |
| 109 | } |
| 110 | |
| 111 | /** |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 112 | * Returns the bounds used to fill the input frame and the touchable region. |
| 113 | * |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 114 | * Similar to getInputTransform, we need to update the bounds to include the transform. |
| 115 | * This is because bounds don't include the buffer transform, where the input assumes |
| 116 | * that's already included. |
| 117 | */ |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 118 | std::pair<FloatRect, bool> getInputBounds(const LayerSnapshot& snapshot, bool fillParentBounds) { |
Vishnu Nair | a9123c8 | 2024-10-03 03:56:44 +0000 | [diff] [blame^] | 119 | FloatRect inputBounds = snapshot.croppedBufferSize; |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 120 | if (snapshot.hasBufferOrSidebandStream() && snapshot.croppedBufferSize.isValid() && |
| 121 | snapshot.localTransform.getType() != ui::Transform::IDENTITY) { |
| 122 | inputBounds = snapshot.localTransform.transform(inputBounds); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 125 | bool inputBoundsValid = snapshot.croppedBufferSize.isValid(); |
| 126 | if (!inputBoundsValid) { |
| 127 | /** |
| 128 | * Input bounds are based on the layer crop or buffer size. But if we are using |
| 129 | * the layer bounds as the input bounds (replaceTouchableRegionWithCrop flag) then |
| 130 | * we can use the parent bounds as the input bounds if the layer does not have buffer |
| 131 | * or a crop. We want to unify this logic but because of compat reasons we cannot always |
| 132 | * use the parent bounds. A layer without a buffer can get input. So when a window is |
| 133 | * initially added, its touchable region can fill its parent layer bounds and that can |
| 134 | * have negative consequences. |
| 135 | */ |
| 136 | inputBounds = fillParentBounds ? snapshot.geomLayerBounds : FloatRect{}; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 137 | } |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 138 | |
| 139 | // Clamp surface inset to the input bounds. |
| 140 | const float inset = static_cast<float>(snapshot.inputInfo.surfaceInset); |
| 141 | const float xSurfaceInset = std::clamp(inset, 0.f, inputBounds.getWidth() / 2.f); |
| 142 | const float ySurfaceInset = std::clamp(inset, 0.f, inputBounds.getHeight() / 2.f); |
| 143 | |
| 144 | // Apply the insets to the input bounds. |
| 145 | inputBounds.left += xSurfaceInset; |
| 146 | inputBounds.top += ySurfaceInset; |
| 147 | inputBounds.right -= xSurfaceInset; |
| 148 | inputBounds.bottom -= ySurfaceInset; |
| 149 | return {inputBounds, inputBoundsValid}; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 152 | Rect getInputBoundsInDisplaySpace(const LayerSnapshot& snapshot, const FloatRect& insetBounds, |
| 153 | const ui::Transform& screenToDisplay) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 154 | // InputDispatcher works in the display device's coordinate space. Here, we calculate the |
| 155 | // frame and transform used for the layer, which determines the bounds and the coordinate space |
| 156 | // within which the layer will receive input. |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 157 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 158 | // Coordinate space definitions: |
| 159 | // - display: The display device's coordinate space. Correlates to pixels on the display. |
| 160 | // - screen: The post-rotation coordinate space for the display, a.k.a. logical display space. |
| 161 | // - layer: The coordinate space of this layer. |
| 162 | // - input: The coordinate space in which this layer will receive input events. This could be |
| 163 | // different than layer space if a surfaceInset is used, which changes the origin |
| 164 | // of the input space. |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 165 | |
| 166 | // Crop the input bounds to ensure it is within the parent's bounds. |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 167 | const FloatRect croppedInsetBoundsInLayer = snapshot.geomLayerBounds.intersect(insetBounds); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 168 | |
| 169 | const ui::Transform layerToScreen = getInputTransform(snapshot); |
| 170 | const ui::Transform layerToDisplay = screenToDisplay * layerToScreen; |
| 171 | |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 172 | return Rect{layerToDisplay.transform(croppedInsetBoundsInLayer)}; |
| 173 | } |
| 174 | |
| 175 | void fillInputFrameInfo(gui::WindowInfo& info, const ui::Transform& screenToDisplay, |
| 176 | const LayerSnapshot& snapshot) { |
| 177 | auto [inputBounds, inputBoundsValid] = getInputBounds(snapshot, /*fillParentBounds=*/false); |
| 178 | if (!inputBoundsValid) { |
| 179 | info.touchableRegion.clear(); |
| 180 | } |
| 181 | |
Chavi Weingarten | 7f01919 | 2023-08-08 20:39:01 +0000 | [diff] [blame] | 182 | info.frame = getInputBoundsInDisplaySpace(snapshot, inputBounds, screenToDisplay); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 183 | |
| 184 | ui::Transform inputToLayer; |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 185 | inputToLayer.set(inputBounds.left, inputBounds.top); |
| 186 | const ui::Transform layerToScreen = getInputTransform(snapshot); |
| 187 | const ui::Transform inputToDisplay = screenToDisplay * layerToScreen * inputToLayer; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 188 | |
| 189 | // InputDispatcher expects a display-to-input transform. |
| 190 | info.transform = inputToDisplay.inverse(); |
| 191 | |
| 192 | // The touchable region is specified in the input coordinate space. Change it to display space. |
| 193 | info.touchableRegion = |
| 194 | transformTouchableRegionSafely(inputToDisplay, info.touchableRegion, snapshot.name); |
| 195 | } |
| 196 | |
| 197 | void handleDropInputMode(LayerSnapshot& snapshot, const LayerSnapshot& parentSnapshot) { |
| 198 | if (snapshot.inputInfo.inputConfig.test(gui::WindowInfo::InputConfig::NO_INPUT_CHANNEL)) { |
| 199 | return; |
| 200 | } |
| 201 | |
| 202 | // Check if we need to drop input unconditionally |
| 203 | const gui::DropInputMode dropInputMode = snapshot.dropInputMode; |
| 204 | if (dropInputMode == gui::DropInputMode::ALL) { |
| 205 | snapshot.inputInfo.inputConfig |= gui::WindowInfo::InputConfig::DROP_INPUT; |
| 206 | ALOGV("Dropping input for %s as requested by policy.", snapshot.name.c_str()); |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | // Check if we need to check if the window is obscured by parent |
| 211 | if (dropInputMode != gui::DropInputMode::OBSCURED) { |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | // Check if the parent has set an alpha on the layer |
| 216 | if (parentSnapshot.color.a != 1.0_hf) { |
| 217 | snapshot.inputInfo.inputConfig |= gui::WindowInfo::InputConfig::DROP_INPUT; |
| 218 | ALOGV("Dropping input for %s as requested by policy because alpha=%f", |
| 219 | snapshot.name.c_str(), static_cast<float>(parentSnapshot.color.a)); |
| 220 | } |
| 221 | |
| 222 | // Check if the parent has cropped the buffer |
Vishnu Nair | a9123c8 | 2024-10-03 03:56:44 +0000 | [diff] [blame^] | 223 | FloatRect bufferSize = snapshot.croppedBufferSize; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 224 | if (!bufferSize.isValid()) { |
| 225 | snapshot.inputInfo.inputConfig |= gui::WindowInfo::InputConfig::DROP_INPUT_IF_OBSCURED; |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | // Screenbounds are the layer bounds cropped by parents, transformed to screenspace. |
| 230 | // To check if the layer has been cropped, we take the buffer bounds, apply the local |
| 231 | // layer crop and apply the same set of transforms to move to screenspace. If the bounds |
| 232 | // match then the layer has not been cropped by its parents. |
| 233 | Rect bufferInScreenSpace(snapshot.geomLayerTransform.transform(bufferSize)); |
| 234 | bool croppedByParent = bufferInScreenSpace != Rect{snapshot.transformedBounds}; |
| 235 | |
| 236 | if (croppedByParent) { |
| 237 | snapshot.inputInfo.inputConfig |= gui::WindowInfo::InputConfig::DROP_INPUT; |
| 238 | ALOGV("Dropping input for %s as requested by policy because buffer is cropped by parent", |
| 239 | snapshot.name.c_str()); |
| 240 | } else { |
| 241 | // If the layer is not obscured by its parents (by setting an alpha or crop), then only drop |
| 242 | // input if the window is obscured. This check should be done in surfaceflinger but the |
| 243 | // logic currently resides in inputflinger. So pass the if_obscured check to input to only |
| 244 | // drop input events if the window is obscured. |
| 245 | snapshot.inputInfo.inputConfig |= gui::WindowInfo::InputConfig::DROP_INPUT_IF_OBSCURED; |
| 246 | } |
| 247 | } |
| 248 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 249 | auto getBlendMode(const LayerSnapshot& snapshot, const RequestedLayerState& requested) { |
| 250 | auto blendMode = Hwc2::IComposerClient::BlendMode::NONE; |
| 251 | if (snapshot.alpha != 1.0f || !snapshot.isContentOpaque()) { |
| 252 | blendMode = requested.premultipliedAlpha ? Hwc2::IComposerClient::BlendMode::PREMULTIPLIED |
| 253 | : Hwc2::IComposerClient::BlendMode::COVERAGE; |
| 254 | } |
| 255 | return blendMode; |
| 256 | } |
| 257 | |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 258 | void updateVisibility(LayerSnapshot& snapshot, bool visible) { |
Vishnu Nair | b4a6a77 | 2024-06-12 14:41:08 -0700 | [diff] [blame] | 259 | if (snapshot.isVisible != visible) { |
| 260 | snapshot.changes |= RequestedLayerState::Changes::Visibility; |
| 261 | } |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 262 | snapshot.isVisible = visible; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 263 | |
| 264 | // TODO(b/238781169) we are ignoring this compat for now, since we will have |
| 265 | // to remove any optimization based on visibility. |
| 266 | |
| 267 | // For compatibility reasons we let layers which can receive input |
| 268 | // receive input before they have actually submitted a buffer. Because |
| 269 | // of this we use canReceiveInput instead of isVisible to check the |
| 270 | // policy-visibility, ignoring the buffer state. However for layers with |
| 271 | // hasInputInfo()==false we can use the real visibility state. |
| 272 | // We are just using these layers for occlusion detection in |
| 273 | // InputDispatcher, and obviously if they aren't visible they can't occlude |
| 274 | // anything. |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 275 | const bool visibleForInput = |
Vishnu Nair | 40d0228 | 2023-02-28 21:11:40 +0000 | [diff] [blame] | 276 | snapshot.hasInputInfo() ? snapshot.canReceiveInput() : snapshot.isVisible; |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 277 | snapshot.inputInfo.setInputConfig(gui::WindowInfo::InputConfig::NOT_VISIBLE, !visibleForInput); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 278 | LLOGV(snapshot.sequence, "updating visibility %s %s", visible ? "true" : "false", |
| 279 | snapshot.getDebugString().c_str()); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 282 | void updateMetadata(LayerSnapshot& snapshot, const RequestedLayerState& requested, |
| 283 | const LayerSnapshotBuilder::Args& args) { |
| 284 | snapshot.metadata.clear(); |
| 285 | for (const auto& [key, mandatory] : args.supportedLayerGenericMetadata) { |
| 286 | auto compatIter = args.genericLayerMetadataKeyMap.find(key); |
| 287 | if (compatIter == std::end(args.genericLayerMetadataKeyMap)) { |
| 288 | continue; |
| 289 | } |
| 290 | const uint32_t id = compatIter->second; |
| 291 | auto it = requested.metadata.mMap.find(id); |
| 292 | if (it == std::end(requested.metadata.mMap)) { |
| 293 | continue; |
| 294 | } |
| 295 | |
| 296 | snapshot.metadata.emplace(key, |
| 297 | compositionengine::GenericLayerMetadataEntry{mandatory, |
| 298 | it->second}); |
| 299 | } |
| 300 | } |
| 301 | |
Nergi Rahardi | 0dfc096 | 2024-05-23 06:57:36 +0000 | [diff] [blame] | 302 | void updateMetadataAndGameMode(LayerSnapshot& snapshot, const RequestedLayerState& requested, |
| 303 | const LayerSnapshotBuilder::Args& args, |
| 304 | const LayerSnapshot& parentSnapshot) { |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 305 | snapshot.gameMode = requested.metadata.has(gui::METADATA_GAME_MODE) ? requested.gameMode |
| 306 | : parentSnapshot.gameMode; |
Nergi Rahardi | 0dfc096 | 2024-05-23 06:57:36 +0000 | [diff] [blame] | 307 | updateMetadata(snapshot, requested, args); |
| 308 | if (args.includeMetadata) { |
| 309 | snapshot.layerMetadata = parentSnapshot.layerMetadata; |
| 310 | snapshot.layerMetadata.merge(requested.metadata); |
| 311 | } |
| 312 | } |
| 313 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 314 | void clearChanges(LayerSnapshot& snapshot) { |
| 315 | snapshot.changes.clear(); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 316 | snapshot.clientChanges = 0; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 317 | snapshot.contentDirty = false; |
| 318 | snapshot.hasReadyFrame = false; |
| 319 | snapshot.sidebandStreamHasFrame = false; |
| 320 | snapshot.surfaceDamage.clear(); |
| 321 | } |
| 322 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 323 | // TODO (b/259407931): Remove. |
| 324 | uint32_t getPrimaryDisplayRotationFlags( |
| 325 | const ui::DisplayMap<ui::LayerStack, frontend::DisplayInfo>& displays) { |
| 326 | for (auto& [_, display] : displays) { |
| 327 | if (display.isPrimary) { |
| 328 | return display.rotationFlags; |
| 329 | } |
| 330 | } |
| 331 | return 0; |
| 332 | } |
| 333 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 334 | } // namespace |
| 335 | |
| 336 | LayerSnapshot LayerSnapshotBuilder::getRootSnapshot() { |
| 337 | LayerSnapshot snapshot; |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 338 | snapshot.path = LayerHierarchy::TraversalPath::ROOT; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 339 | snapshot.changes = ftl::Flags<RequestedLayerState::Changes>(); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 340 | snapshot.clientChanges = 0; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 341 | snapshot.isHiddenByPolicyFromParent = false; |
| 342 | snapshot.isHiddenByPolicyFromRelativeParent = false; |
| 343 | snapshot.parentTransform.reset(); |
| 344 | snapshot.geomLayerTransform.reset(); |
| 345 | snapshot.geomInverseLayerTransform.reset(); |
| 346 | snapshot.geomLayerBounds = getMaxDisplayBounds({}); |
| 347 | snapshot.roundedCorner = RoundedCornerState(); |
| 348 | snapshot.stretchEffect = {}; |
Marzia Favaro | dcc9d9b | 2024-01-10 10:17:00 +0000 | [diff] [blame] | 349 | snapshot.edgeExtensionEffect = {}; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 350 | snapshot.outputFilter.layerStack = ui::DEFAULT_LAYER_STACK; |
| 351 | snapshot.outputFilter.toInternalDisplay = false; |
| 352 | snapshot.isSecure = false; |
| 353 | snapshot.color.a = 1.0_hf; |
| 354 | snapshot.colorTransformIsIdentity = true; |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 355 | snapshot.shadowSettings.length = 0.f; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 356 | snapshot.layerMetadata.mMap.clear(); |
| 357 | snapshot.relativeLayerMetadata.mMap.clear(); |
| 358 | snapshot.inputInfo.touchOcclusionMode = gui::TouchOcclusionMode::BLOCK_UNTRUSTED; |
| 359 | snapshot.dropInputMode = gui::DropInputMode::NONE; |
Vishnu Nair | 9e0017e | 2024-05-22 19:02:44 +0000 | [diff] [blame] | 360 | snapshot.trustedOverlay = gui::TrustedOverlay::UNSET; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 361 | snapshot.gameMode = gui::GameMode::Unsupported; |
| 362 | snapshot.frameRate = {}; |
| 363 | snapshot.fixedTransformHint = ui::Transform::ROT_INVALID; |
Vishnu Nair | 422b81c | 2024-05-16 05:44:28 +0000 | [diff] [blame] | 364 | snapshot.ignoreLocalTransform = false; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 365 | return snapshot; |
| 366 | } |
| 367 | |
Chavi Weingarten | 4aa22af | 2023-11-17 19:37:07 +0000 | [diff] [blame] | 368 | LayerSnapshotBuilder::LayerSnapshotBuilder() {} |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 369 | |
| 370 | LayerSnapshotBuilder::LayerSnapshotBuilder(Args args) : LayerSnapshotBuilder() { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 371 | args.forceUpdate = ForceUpdateFlags::ALL; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 372 | updateSnapshots(args); |
| 373 | } |
| 374 | |
| 375 | bool LayerSnapshotBuilder::tryFastUpdate(const Args& args) { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 376 | const bool forceUpdate = args.forceUpdate != ForceUpdateFlags::NONE; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 377 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 378 | if (args.layerLifecycleManager.getGlobalChanges().get() == 0 && !forceUpdate && |
| 379 | !args.displayChanges) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 380 | return true; |
| 381 | } |
| 382 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 383 | // There are only content changes which do not require any child layer snapshots to be updated. |
| 384 | ALOGV("%s", __func__); |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 385 | SFTRACE_NAME("FastPath"); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 386 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 387 | uint32_t primaryDisplayRotationFlags = getPrimaryDisplayRotationFlags(args.displays); |
| 388 | if (forceUpdate || args.displayChanges) { |
| 389 | for (auto& snapshot : mSnapshots) { |
| 390 | const RequestedLayerState* requested = |
| 391 | args.layerLifecycleManager.getLayerFromId(snapshot->path.id); |
| 392 | if (!requested) continue; |
| 393 | snapshot->merge(*requested, forceUpdate, args.displayChanges, args.forceFullDamage, |
| 394 | primaryDisplayRotationFlags); |
| 395 | } |
| 396 | return false; |
| 397 | } |
| 398 | |
| 399 | // Walk through all the updated requested layer states and update the corresponding snapshots. |
| 400 | for (const RequestedLayerState* requested : args.layerLifecycleManager.getChangedLayers()) { |
| 401 | auto range = mIdToSnapshots.equal_range(requested->id); |
| 402 | for (auto it = range.first; it != range.second; it++) { |
| 403 | it->second->merge(*requested, forceUpdate, args.displayChanges, args.forceFullDamage, |
| 404 | primaryDisplayRotationFlags); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 405 | } |
| 406 | } |
| 407 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 408 | if ((args.layerLifecycleManager.getGlobalChanges().get() & |
| 409 | ~(RequestedLayerState::Changes::Content | RequestedLayerState::Changes::Buffer).get()) != |
| 410 | 0) { |
| 411 | // We have changes that require us to walk the hierarchy and update child layers. |
| 412 | // No fast path for you. |
| 413 | return false; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 414 | } |
| 415 | return true; |
| 416 | } |
| 417 | |
| 418 | void LayerSnapshotBuilder::updateSnapshots(const Args& args) { |
Vishnu Nair | be0ad90 | 2024-06-27 23:38:43 +0000 | [diff] [blame] | 419 | SFTRACE_NAME("UpdateSnapshots"); |
Chavi Weingarten | 4aa22af | 2023-11-17 19:37:07 +0000 | [diff] [blame] | 420 | LayerSnapshot rootSnapshot = args.rootSnapshot; |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 421 | if (args.parentCrop) { |
Chavi Weingarten | 4aa22af | 2023-11-17 19:37:07 +0000 | [diff] [blame] | 422 | rootSnapshot.geomLayerBounds = *args.parentCrop; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 423 | } else if (args.forceUpdate == ForceUpdateFlags::ALL || args.displayChanges) { |
Chavi Weingarten | 4aa22af | 2023-11-17 19:37:07 +0000 | [diff] [blame] | 424 | rootSnapshot.geomLayerBounds = getMaxDisplayBounds(args.displays); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 425 | } |
| 426 | if (args.displayChanges) { |
Chavi Weingarten | 4aa22af | 2023-11-17 19:37:07 +0000 | [diff] [blame] | 427 | rootSnapshot.changes = RequestedLayerState::Changes::AffectsChildren | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 428 | RequestedLayerState::Changes::Geometry; |
| 429 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 430 | if (args.forceUpdate == ForceUpdateFlags::HIERARCHY) { |
Chavi Weingarten | 4aa22af | 2023-11-17 19:37:07 +0000 | [diff] [blame] | 431 | rootSnapshot.changes |= |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 432 | RequestedLayerState::Changes::Hierarchy | RequestedLayerState::Changes::Visibility; |
Chavi Weingarten | 4aa22af | 2023-11-17 19:37:07 +0000 | [diff] [blame] | 433 | rootSnapshot.clientChanges |= layer_state_t::eReparent; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 434 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 435 | |
| 436 | for (auto& snapshot : mSnapshots) { |
| 437 | if (snapshot->reachablilty == LayerSnapshot::Reachablilty::Reachable) { |
| 438 | snapshot->reachablilty = LayerSnapshot::Reachablilty::Unreachable; |
| 439 | } |
| 440 | } |
| 441 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 442 | LayerHierarchy::TraversalPath root = LayerHierarchy::TraversalPath::ROOT; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 443 | if (args.root.getLayer()) { |
| 444 | // The hierarchy can have a root layer when used for screenshots otherwise, it will have |
| 445 | // multiple children. |
| 446 | LayerHierarchy::ScopedAddToTraversalPath addChildToPath(root, args.root.getLayer()->id, |
| 447 | LayerHierarchy::Variant::Attached); |
Chavi Weingarten | 4aa22af | 2023-11-17 19:37:07 +0000 | [diff] [blame] | 448 | updateSnapshotsInHierarchy(args, args.root, root, rootSnapshot, /*depth=*/0); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 449 | } else { |
| 450 | for (auto& [childHierarchy, variant] : args.root.mChildren) { |
| 451 | LayerHierarchy::ScopedAddToTraversalPath addChildToPath(root, |
| 452 | childHierarchy->getLayer()->id, |
| 453 | variant); |
Chavi Weingarten | 4aa22af | 2023-11-17 19:37:07 +0000 | [diff] [blame] | 454 | updateSnapshotsInHierarchy(args, *childHierarchy, root, rootSnapshot, /*depth=*/0); |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 455 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 456 | } |
| 457 | |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 458 | // Update touchable region crops outside the main update pass. This is because a layer could be |
| 459 | // cropped by any other layer and it requires both snapshots to be updated. |
| 460 | updateTouchableRegionCrop(args); |
| 461 | |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 462 | const bool hasUnreachableSnapshots = sortSnapshotsByZ(args); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 463 | |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 464 | // Destroy unreachable snapshots for clone layers. And destroy snapshots for non-clone |
| 465 | // layers if the layer have been destroyed. |
| 466 | // TODO(b/238781169) consider making clone layer ids stable as well |
| 467 | if (!hasUnreachableSnapshots && args.layerLifecycleManager.getDestroyedLayers().empty()) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 468 | return; |
| 469 | } |
| 470 | |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 471 | std::unordered_set<uint32_t> destroyedLayerIds; |
| 472 | for (auto& destroyedLayer : args.layerLifecycleManager.getDestroyedLayers()) { |
| 473 | destroyedLayerIds.insert(destroyedLayer->id); |
| 474 | } |
| 475 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 476 | auto it = mSnapshots.begin(); |
| 477 | while (it < mSnapshots.end()) { |
| 478 | auto& traversalPath = it->get()->path; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 479 | const bool unreachable = |
| 480 | it->get()->reachablilty == LayerSnapshot::Reachablilty::Unreachable; |
| 481 | const bool isClone = traversalPath.isClone(); |
| 482 | const bool layerIsDestroyed = |
| 483 | destroyedLayerIds.find(traversalPath.id) != destroyedLayerIds.end(); |
| 484 | const bool destroySnapshot = (unreachable && isClone) || layerIsDestroyed; |
| 485 | |
| 486 | if (!destroySnapshot) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 487 | it++; |
| 488 | continue; |
| 489 | } |
| 490 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 491 | mPathToSnapshot.erase(traversalPath); |
| 492 | |
| 493 | auto range = mIdToSnapshots.equal_range(traversalPath.id); |
| 494 | auto matchingSnapshot = |
| 495 | std::find_if(range.first, range.second, [&traversalPath](auto& snapshotWithId) { |
| 496 | return snapshotWithId.second->path == traversalPath; |
| 497 | }); |
| 498 | mIdToSnapshots.erase(matchingSnapshot); |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 499 | mNeedsTouchableRegionCrop.erase(traversalPath); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 500 | mSnapshots.back()->globalZ = it->get()->globalZ; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 501 | std::iter_swap(it, mSnapshots.end() - 1); |
| 502 | mSnapshots.erase(mSnapshots.end() - 1); |
| 503 | } |
| 504 | } |
| 505 | |
| 506 | void LayerSnapshotBuilder::update(const Args& args) { |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 507 | for (auto& snapshot : mSnapshots) { |
| 508 | clearChanges(*snapshot); |
| 509 | } |
| 510 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 511 | if (tryFastUpdate(args)) { |
| 512 | return; |
| 513 | } |
| 514 | updateSnapshots(args); |
| 515 | } |
| 516 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 517 | const LayerSnapshot& LayerSnapshotBuilder::updateSnapshotsInHierarchy( |
| 518 | const Args& args, const LayerHierarchy& hierarchy, |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 519 | LayerHierarchy::TraversalPath& traversalPath, const LayerSnapshot& parentSnapshot, |
| 520 | int depth) { |
Vishnu Nair | 606d9d0 | 2023-08-19 14:20:18 -0700 | [diff] [blame] | 521 | LLOG_ALWAYS_FATAL_WITH_TRACE_IF(depth > 50, |
| 522 | "Cycle detected in LayerSnapshotBuilder. See " |
| 523 | "builder_stack_overflow_transactions.winscope"); |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 524 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 525 | const RequestedLayerState* layer = hierarchy.getLayer(); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 526 | LayerSnapshot* snapshot = getSnapshot(traversalPath); |
| 527 | const bool newSnapshot = snapshot == nullptr; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 528 | uint32_t primaryDisplayRotationFlags = getPrimaryDisplayRotationFlags(args.displays); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 529 | if (newSnapshot) { |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 530 | snapshot = createSnapshot(traversalPath, *layer, parentSnapshot); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 531 | snapshot->merge(*layer, /*forceUpdate=*/true, /*displayChanges=*/true, args.forceFullDamage, |
| 532 | primaryDisplayRotationFlags); |
| 533 | snapshot->changes |= RequestedLayerState::Changes::Created; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 534 | } |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 535 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 536 | if (traversalPath.isRelative()) { |
| 537 | bool parentIsRelative = traversalPath.variant == LayerHierarchy::Variant::Relative; |
| 538 | updateRelativeState(*snapshot, parentSnapshot, parentIsRelative, args); |
| 539 | } else { |
| 540 | if (traversalPath.isAttached()) { |
| 541 | resetRelativeState(*snapshot); |
| 542 | } |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 543 | updateSnapshot(*snapshot, args, *layer, parentSnapshot, traversalPath); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 544 | } |
| 545 | |
Vishnu Nair | 0fd773f | 2024-08-05 21:16:15 +0000 | [diff] [blame] | 546 | bool childHasValidFrameRate = false; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 547 | for (auto& [childHierarchy, variant] : hierarchy.mChildren) { |
| 548 | LayerHierarchy::ScopedAddToTraversalPath addChildToPath(traversalPath, |
| 549 | childHierarchy->getLayer()->id, |
| 550 | variant); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 551 | const LayerSnapshot& childSnapshot = |
Vishnu Nair | d1f7498 | 2023-06-15 20:16:51 -0700 | [diff] [blame] | 552 | updateSnapshotsInHierarchy(args, *childHierarchy, traversalPath, *snapshot, |
| 553 | depth + 1); |
Vishnu Nair | 0fd773f | 2024-08-05 21:16:15 +0000 | [diff] [blame] | 554 | updateFrameRateFromChildSnapshot(*snapshot, childSnapshot, *childHierarchy->getLayer(), |
| 555 | args, &childHasValidFrameRate); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 556 | } |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 557 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 558 | return *snapshot; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | LayerSnapshot* LayerSnapshotBuilder::getSnapshot(uint32_t layerId) const { |
| 562 | if (layerId == UNASSIGNED_LAYER_ID) { |
| 563 | return nullptr; |
| 564 | } |
| 565 | LayerHierarchy::TraversalPath path{.id = layerId}; |
| 566 | return getSnapshot(path); |
| 567 | } |
| 568 | |
| 569 | LayerSnapshot* LayerSnapshotBuilder::getSnapshot(const LayerHierarchy::TraversalPath& id) const { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 570 | auto it = mPathToSnapshot.find(id); |
| 571 | return it == mPathToSnapshot.end() ? nullptr : it->second; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 572 | } |
| 573 | |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 574 | LayerSnapshot* LayerSnapshotBuilder::createSnapshot(const LayerHierarchy::TraversalPath& path, |
| 575 | const RequestedLayerState& layer, |
| 576 | const LayerSnapshot& parentSnapshot) { |
| 577 | mSnapshots.emplace_back(std::make_unique<LayerSnapshot>(layer, path)); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 578 | LayerSnapshot* snapshot = mSnapshots.back().get(); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 579 | snapshot->globalZ = static_cast<size_t>(mSnapshots.size()) - 1; |
Vishnu Nair | 491827d | 2024-04-29 23:43:26 +0000 | [diff] [blame] | 580 | if (path.isClone() && !LayerHierarchy::isMirror(path.variant)) { |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 581 | snapshot->mirrorRootPath = parentSnapshot.mirrorRootPath; |
| 582 | } |
Vishnu Nair | 491827d | 2024-04-29 23:43:26 +0000 | [diff] [blame] | 583 | snapshot->ignoreLocalTransform = |
| 584 | path.isClone() && path.variant == LayerHierarchy::Variant::Detached_Mirror; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 585 | mPathToSnapshot[path] = snapshot; |
| 586 | |
| 587 | mIdToSnapshots.emplace(path.id, snapshot); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 588 | return snapshot; |
| 589 | } |
| 590 | |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 591 | bool LayerSnapshotBuilder::sortSnapshotsByZ(const Args& args) { |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 592 | if (!mResortSnapshots && args.forceUpdate == ForceUpdateFlags::NONE && |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 593 | !args.layerLifecycleManager.getGlobalChanges().any( |
Chavi Weingarten | 92c7d8c | 2024-01-19 23:25:45 +0000 | [diff] [blame] | 594 | RequestedLayerState::Changes::Hierarchy | RequestedLayerState::Changes::Visibility | |
| 595 | RequestedLayerState::Changes::Input)) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 596 | // We are not force updating and there are no hierarchy or visibility changes. Avoid sorting |
| 597 | // the snapshots. |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 598 | return false; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 599 | } |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 600 | mResortSnapshots = false; |
| 601 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 602 | size_t globalZ = 0; |
| 603 | args.root.traverseInZOrder( |
| 604 | [this, &globalZ](const LayerHierarchy&, |
| 605 | const LayerHierarchy::TraversalPath& traversalPath) -> bool { |
| 606 | LayerSnapshot* snapshot = getSnapshot(traversalPath); |
| 607 | if (!snapshot) { |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 608 | return true; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 609 | } |
| 610 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 611 | if (snapshot->getIsVisible() || snapshot->hasInputInfo()) { |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 612 | updateVisibility(*snapshot, snapshot->getIsVisible()); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 613 | size_t oldZ = snapshot->globalZ; |
| 614 | size_t newZ = globalZ++; |
| 615 | snapshot->globalZ = newZ; |
| 616 | if (oldZ == newZ) { |
| 617 | return true; |
| 618 | } |
| 619 | mSnapshots[newZ]->globalZ = oldZ; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 620 | LLOGV(snapshot->sequence, "Made visible z=%zu -> %zu %s", oldZ, newZ, |
| 621 | snapshot->getDebugString().c_str()); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 622 | std::iter_swap(mSnapshots.begin() + static_cast<ssize_t>(oldZ), |
| 623 | mSnapshots.begin() + static_cast<ssize_t>(newZ)); |
| 624 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 625 | return true; |
| 626 | }); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 627 | mNumInterestingSnapshots = (int)globalZ; |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 628 | bool hasUnreachableSnapshots = false; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 629 | while (globalZ < mSnapshots.size()) { |
| 630 | mSnapshots[globalZ]->globalZ = globalZ; |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 631 | /* mark unreachable snapshots as explicitly invisible */ |
| 632 | updateVisibility(*mSnapshots[globalZ], false); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 633 | if (mSnapshots[globalZ]->reachablilty == LayerSnapshot::Reachablilty::Unreachable) { |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 634 | hasUnreachableSnapshots = true; |
| 635 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 636 | globalZ++; |
| 637 | } |
Vishnu Nair | fccd636 | 2023-02-24 23:39:53 +0000 | [diff] [blame] | 638 | return hasUnreachableSnapshots; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 639 | } |
| 640 | |
| 641 | void LayerSnapshotBuilder::updateRelativeState(LayerSnapshot& snapshot, |
| 642 | const LayerSnapshot& parentSnapshot, |
| 643 | bool parentIsRelative, const Args& args) { |
| 644 | if (parentIsRelative) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 645 | snapshot.isHiddenByPolicyFromRelativeParent = |
| 646 | parentSnapshot.isHiddenByPolicyFromParent || parentSnapshot.invalidTransform; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 647 | if (args.includeMetadata) { |
| 648 | snapshot.relativeLayerMetadata = parentSnapshot.layerMetadata; |
| 649 | } |
| 650 | } else { |
| 651 | snapshot.isHiddenByPolicyFromRelativeParent = |
| 652 | parentSnapshot.isHiddenByPolicyFromRelativeParent; |
| 653 | if (args.includeMetadata) { |
| 654 | snapshot.relativeLayerMetadata = parentSnapshot.relativeLayerMetadata; |
| 655 | } |
| 656 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 657 | if (snapshot.reachablilty == LayerSnapshot::Reachablilty::Unreachable) { |
| 658 | snapshot.reachablilty = LayerSnapshot::Reachablilty::ReachableByRelativeParent; |
| 659 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Vishnu Nair | 0fd773f | 2024-08-05 21:16:15 +0000 | [diff] [blame] | 662 | void LayerSnapshotBuilder::updateFrameRateFromChildSnapshot( |
| 663 | LayerSnapshot& snapshot, const LayerSnapshot& childSnapshot, |
| 664 | const RequestedLayerState& /* requestedChildState */, const Args& args, |
| 665 | bool* outChildHasValidFrameRate) { |
Vishnu Nair | 42b918e | 2023-07-18 20:05:29 +0000 | [diff] [blame] | 666 | if (args.forceUpdate == ForceUpdateFlags::NONE && |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 667 | !args.layerLifecycleManager.getGlobalChanges().any( |
| 668 | RequestedLayerState::Changes::Hierarchy) && |
| 669 | !childSnapshot.changes.any(RequestedLayerState::Changes::FrameRate) && |
| 670 | !snapshot.changes.any(RequestedLayerState::Changes::FrameRate)) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 671 | return; |
| 672 | } |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 673 | |
Vishnu Nair | 3fbe326 | 2023-09-29 17:07:00 -0700 | [diff] [blame] | 674 | using FrameRateCompatibility = scheduler::FrameRateCompatibility; |
Vishnu Nair | 0fd773f | 2024-08-05 21:16:15 +0000 | [diff] [blame] | 675 | if (snapshot.inheritedFrameRate.isValid() || *outChildHasValidFrameRate) { |
Vishnu Nair | 42b918e | 2023-07-18 20:05:29 +0000 | [diff] [blame] | 676 | // we already have a valid framerate. |
| 677 | return; |
| 678 | } |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 679 | |
Vishnu Nair | 42b918e | 2023-07-18 20:05:29 +0000 | [diff] [blame] | 680 | // We return whether this layer or its children has a vote. We ignore ExactOrMultiple votes |
| 681 | // for the same reason we are allowing touch boost for those layers. See |
| 682 | // RefreshRateSelector::rankFrameRates for details. |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 683 | const auto layerVotedWithDefaultCompatibility = childSnapshot.frameRate.vote.rate.isValid() && |
| 684 | childSnapshot.frameRate.vote.type == FrameRateCompatibility::Default; |
Vishnu Nair | 42b918e | 2023-07-18 20:05:29 +0000 | [diff] [blame] | 685 | const auto layerVotedWithNoVote = |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 686 | childSnapshot.frameRate.vote.type == FrameRateCompatibility::NoVote; |
| 687 | const auto layerVotedWithCategory = |
| 688 | childSnapshot.frameRate.category != FrameRateCategory::Default; |
| 689 | const auto layerVotedWithExactCompatibility = childSnapshot.frameRate.vote.rate.isValid() && |
| 690 | childSnapshot.frameRate.vote.type == FrameRateCompatibility::Exact; |
Vishnu Nair | 42b918e | 2023-07-18 20:05:29 +0000 | [diff] [blame] | 691 | |
Vishnu Nair | 0fd773f | 2024-08-05 21:16:15 +0000 | [diff] [blame] | 692 | *outChildHasValidFrameRate |= layerVotedWithDefaultCompatibility || layerVotedWithNoVote || |
Rachel Lee | ce6e004 | 2023-06-27 11:22:54 -0700 | [diff] [blame] | 693 | layerVotedWithCategory || layerVotedWithExactCompatibility; |
Vishnu Nair | 42b918e | 2023-07-18 20:05:29 +0000 | [diff] [blame] | 694 | |
| 695 | // If we don't have a valid frame rate, but the children do, we set this |
| 696 | // layer as NoVote to allow the children to control the refresh rate |
Vishnu Nair | 0fd773f | 2024-08-05 21:16:15 +0000 | [diff] [blame] | 697 | static const auto noVote = |
| 698 | scheduler::LayerInfo::FrameRate(Fps(), FrameRateCompatibility::NoVote); |
| 699 | if (*outChildHasValidFrameRate) { |
| 700 | snapshot.frameRate = noVote; |
| 701 | snapshot.changes |= RequestedLayerState::Changes::FrameRate; |
| 702 | } else if (snapshot.frameRate != snapshot.inheritedFrameRate) { |
| 703 | snapshot.frameRate = snapshot.inheritedFrameRate; |
Vishnu Nair | 42b918e | 2023-07-18 20:05:29 +0000 | [diff] [blame] | 704 | snapshot.changes |= RequestedLayerState::Changes::FrameRate; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 705 | } |
| 706 | } |
| 707 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 708 | void LayerSnapshotBuilder::resetRelativeState(LayerSnapshot& snapshot) { |
| 709 | snapshot.isHiddenByPolicyFromRelativeParent = false; |
| 710 | snapshot.relativeLayerMetadata.mMap.clear(); |
| 711 | } |
| 712 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 713 | void LayerSnapshotBuilder::updateSnapshot(LayerSnapshot& snapshot, const Args& args, |
| 714 | const RequestedLayerState& requested, |
| 715 | const LayerSnapshot& parentSnapshot, |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 716 | const LayerHierarchy::TraversalPath& path) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 717 | // Always update flags and visibility |
| 718 | ftl::Flags<RequestedLayerState::Changes> parentChanges = parentSnapshot.changes & |
| 719 | (RequestedLayerState::Changes::Hierarchy | RequestedLayerState::Changes::Geometry | |
| 720 | RequestedLayerState::Changes::Visibility | RequestedLayerState::Changes::Metadata | |
Vishnu Nair | f13c898 | 2023-12-02 11:26:09 -0800 | [diff] [blame] | 721 | RequestedLayerState::Changes::AffectsChildren | RequestedLayerState::Changes::Input | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 722 | RequestedLayerState::Changes::FrameRate | RequestedLayerState::Changes::GameMode); |
| 723 | snapshot.changes |= parentChanges; |
| 724 | if (args.displayChanges) snapshot.changes |= RequestedLayerState::Changes::Geometry; |
| 725 | snapshot.reachablilty = LayerSnapshot::Reachablilty::Reachable; |
| 726 | snapshot.clientChanges |= (parentSnapshot.clientChanges & layer_state_t::AFFECTS_CHILDREN); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 727 | snapshot.isHiddenByPolicyFromParent = parentSnapshot.isHiddenByPolicyFromParent || |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 728 | parentSnapshot.invalidTransform || requested.isHiddenByPolicy() || |
| 729 | (args.excludeLayerIds.find(path.id) != args.excludeLayerIds.end()); |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 730 | |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 731 | const bool forceUpdate = args.forceUpdate == ForceUpdateFlags::ALL || |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 732 | snapshot.clientChanges & layer_state_t::eReparent || |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 733 | snapshot.changes.any(RequestedLayerState::Changes::Visibility | |
| 734 | RequestedLayerState::Changes::Created); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 735 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 736 | if (forceUpdate || snapshot.clientChanges & layer_state_t::eLayerStackChanged) { |
| 737 | // If root layer, use the layer stack otherwise get the parent's layer stack. |
| 738 | snapshot.outputFilter.layerStack = |
| 739 | parentSnapshot.path == LayerHierarchy::TraversalPath::ROOT |
| 740 | ? requested.layerStack |
| 741 | : parentSnapshot.outputFilter.layerStack; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 742 | } |
| 743 | |
Chavi Weingarten | b74093a | 2023-10-11 20:29:59 +0000 | [diff] [blame] | 744 | if (forceUpdate || snapshot.clientChanges & layer_state_t::eTrustedOverlayChanged) { |
Vishnu Nair | 9e0017e | 2024-05-22 19:02:44 +0000 | [diff] [blame] | 745 | switch (requested.trustedOverlay) { |
| 746 | case gui::TrustedOverlay::UNSET: |
| 747 | snapshot.trustedOverlay = parentSnapshot.trustedOverlay; |
| 748 | break; |
| 749 | case gui::TrustedOverlay::DISABLED: |
| 750 | snapshot.trustedOverlay = FlagManager::getInstance().override_trusted_overlay() |
| 751 | ? requested.trustedOverlay |
| 752 | : parentSnapshot.trustedOverlay; |
| 753 | break; |
| 754 | case gui::TrustedOverlay::ENABLED: |
| 755 | snapshot.trustedOverlay = requested.trustedOverlay; |
| 756 | break; |
| 757 | } |
Chavi Weingarten | b74093a | 2023-10-11 20:29:59 +0000 | [diff] [blame] | 758 | } |
| 759 | |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 760 | if (snapshot.isHiddenByPolicyFromParent && |
| 761 | !snapshot.changes.test(RequestedLayerState::Changes::Created)) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 762 | if (forceUpdate || |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 763 | snapshot.changes.any(RequestedLayerState::Changes::Geometry | |
Vishnu Nair | 494a2e4 | 2023-11-10 17:21:19 -0800 | [diff] [blame] | 764 | RequestedLayerState::Changes::BufferSize | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 765 | RequestedLayerState::Changes::Input)) { |
| 766 | updateInput(snapshot, requested, parentSnapshot, path, args); |
| 767 | } |
Nergi Rahardi | 0dfc096 | 2024-05-23 06:57:36 +0000 | [diff] [blame] | 768 | if (forceUpdate || |
| 769 | (args.includeMetadata && |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 770 | snapshot.changes.any(RequestedLayerState::Changes::Metadata | |
| 771 | RequestedLayerState::Changes::Geometry))) { |
Nergi Rahardi | 0dfc096 | 2024-05-23 06:57:36 +0000 | [diff] [blame] | 772 | updateMetadataAndGameMode(snapshot, requested, args, parentSnapshot); |
| 773 | } |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 774 | return; |
| 775 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 776 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 777 | if (forceUpdate || snapshot.changes.any(RequestedLayerState::Changes::Mirror)) { |
| 778 | // Display mirrors are always placed in a VirtualDisplay so we never want to capture layers |
| 779 | // marked as skip capture |
| 780 | snapshot.handleSkipScreenshotFlag = parentSnapshot.handleSkipScreenshotFlag || |
| 781 | (requested.layerStackToMirror != ui::INVALID_LAYER_STACK); |
| 782 | } |
| 783 | |
| 784 | if (forceUpdate || snapshot.clientChanges & layer_state_t::eAlphaChanged) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 785 | snapshot.color.a = parentSnapshot.color.a * requested.color.a; |
| 786 | snapshot.alpha = snapshot.color.a; |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 787 | snapshot.inputInfo.alpha = snapshot.color.a; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 788 | } |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 789 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 790 | if (forceUpdate || snapshot.clientChanges & layer_state_t::eFlagsChanged) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 791 | snapshot.isSecure = |
| 792 | parentSnapshot.isSecure || (requested.flags & layer_state_t::eLayerSecure); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 793 | snapshot.outputFilter.toInternalDisplay = parentSnapshot.outputFilter.toInternalDisplay || |
| 794 | (requested.flags & layer_state_t::eLayerSkipScreenshot); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 795 | } |
| 796 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 797 | if (forceUpdate || snapshot.clientChanges & layer_state_t::eStretchChanged) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 798 | snapshot.stretchEffect = (requested.stretchEffect.hasEffect()) |
| 799 | ? requested.stretchEffect |
| 800 | : parentSnapshot.stretchEffect; |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 801 | } |
| 802 | |
Marzia Favaro | dcc9d9b | 2024-01-10 10:17:00 +0000 | [diff] [blame] | 803 | if (forceUpdate || |
| 804 | (snapshot.clientChanges | parentSnapshot.clientChanges) & |
| 805 | layer_state_t::eEdgeExtensionChanged) { |
| 806 | if (requested.edgeExtensionParameters.extendLeft || |
| 807 | requested.edgeExtensionParameters.extendRight || |
| 808 | requested.edgeExtensionParameters.extendTop || |
| 809 | requested.edgeExtensionParameters.extendBottom) { |
| 810 | // This is the root layer to which the extension is applied |
| 811 | snapshot.edgeExtensionEffect = |
| 812 | EdgeExtensionEffect(requested.edgeExtensionParameters.extendLeft, |
| 813 | requested.edgeExtensionParameters.extendRight, |
| 814 | requested.edgeExtensionParameters.extendTop, |
| 815 | requested.edgeExtensionParameters.extendBottom); |
| 816 | } else if (parentSnapshot.clientChanges & layer_state_t::eEdgeExtensionChanged) { |
| 817 | // Extension is inherited |
| 818 | snapshot.edgeExtensionEffect = parentSnapshot.edgeExtensionEffect; |
| 819 | } else { |
| 820 | // There is no edge extension |
| 821 | snapshot.edgeExtensionEffect.reset(); |
| 822 | } |
| 823 | if (snapshot.edgeExtensionEffect.hasEffect()) { |
| 824 | snapshot.clientChanges |= layer_state_t::eEdgeExtensionChanged; |
| 825 | snapshot.changes |= RequestedLayerState::Changes::Geometry; |
| 826 | } |
| 827 | } |
| 828 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 829 | if (forceUpdate || snapshot.clientChanges & layer_state_t::eColorTransformChanged) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 830 | if (!parentSnapshot.colorTransformIsIdentity) { |
| 831 | snapshot.colorTransform = parentSnapshot.colorTransform * requested.colorTransform; |
| 832 | snapshot.colorTransformIsIdentity = false; |
| 833 | } else { |
| 834 | snapshot.colorTransform = requested.colorTransform; |
| 835 | snapshot.colorTransformIsIdentity = !requested.hasColorTransform; |
| 836 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 837 | } |
| 838 | |
Vishnu Nair | 39a74a9 | 2024-07-29 19:01:50 +0000 | [diff] [blame] | 839 | if (forceUpdate || |
| 840 | snapshot.changes.any(RequestedLayerState::Changes::Metadata | |
| 841 | RequestedLayerState::Changes::Hierarchy)) { |
Nergi Rahardi | 0dfc096 | 2024-05-23 06:57:36 +0000 | [diff] [blame] | 842 | updateMetadataAndGameMode(snapshot, requested, args, parentSnapshot); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 843 | } |
| 844 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 845 | if (forceUpdate || snapshot.clientChanges & layer_state_t::eFixedTransformHintChanged || |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 846 | args.displayChanges) { |
| 847 | snapshot.fixedTransformHint = requested.fixedTransformHint != ui::Transform::ROT_INVALID |
| 848 | ? requested.fixedTransformHint |
| 849 | : parentSnapshot.fixedTransformHint; |
| 850 | |
| 851 | if (snapshot.fixedTransformHint != ui::Transform::ROT_INVALID) { |
| 852 | snapshot.transformHint = snapshot.fixedTransformHint; |
| 853 | } else { |
| 854 | const auto display = args.displays.get(snapshot.outputFilter.layerStack); |
| 855 | snapshot.transformHint = display.has_value() |
| 856 | ? std::make_optional<>(display->get().transformHint) |
| 857 | : std::nullopt; |
| 858 | } |
| 859 | } |
| 860 | |
Vishnu Nair | 42b918e | 2023-07-18 20:05:29 +0000 | [diff] [blame] | 861 | if (forceUpdate || |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 862 | args.layerLifecycleManager.getGlobalChanges().any( |
| 863 | RequestedLayerState::Changes::Hierarchy) || |
Vishnu Nair | 42b918e | 2023-07-18 20:05:29 +0000 | [diff] [blame] | 864 | snapshot.changes.any(RequestedLayerState::Changes::FrameRate | |
| 865 | RequestedLayerState::Changes::Hierarchy)) { |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 866 | const bool shouldOverrideChildren = parentSnapshot.frameRateSelectionStrategy == |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 867 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren; |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 868 | const bool propagationAllowed = parentSnapshot.frameRateSelectionStrategy != |
Rachel Lee | 70f7b69 | 2023-11-22 11:24:02 -0800 | [diff] [blame] | 869 | scheduler::LayerInfo::FrameRateSelectionStrategy::Self; |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 870 | if ((!requested.requestedFrameRate.isValid() && propagationAllowed) || |
| 871 | shouldOverrideChildren) { |
Vishnu Nair | 30515cb | 2023-10-19 21:54:08 -0700 | [diff] [blame] | 872 | snapshot.inheritedFrameRate = parentSnapshot.inheritedFrameRate; |
| 873 | } else { |
| 874 | snapshot.inheritedFrameRate = requested.requestedFrameRate; |
| 875 | } |
| 876 | // Set the framerate as the inherited frame rate and allow children to override it if |
| 877 | // needed. |
| 878 | snapshot.frameRate = snapshot.inheritedFrameRate; |
Vishnu Nair | 52d56fd | 2023-07-20 17:02:43 +0000 | [diff] [blame] | 879 | snapshot.changes |= RequestedLayerState::Changes::FrameRate; |
Vishnu Nair | d47bcee | 2023-02-24 18:08:51 +0000 | [diff] [blame] | 880 | } |
| 881 | |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 882 | if (forceUpdate || snapshot.clientChanges & layer_state_t::eFrameRateSelectionStrategyChanged) { |
Rachel Lee | a021bb0 | 2023-11-20 21:51:09 -0800 | [diff] [blame] | 883 | if (parentSnapshot.frameRateSelectionStrategy == |
| 884 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren) { |
| 885 | snapshot.frameRateSelectionStrategy = |
| 886 | scheduler::LayerInfo::FrameRateSelectionStrategy::OverrideChildren; |
| 887 | } else { |
| 888 | const auto strategy = scheduler::LayerInfo::convertFrameRateSelectionStrategy( |
| 889 | requested.frameRateSelectionStrategy); |
| 890 | snapshot.frameRateSelectionStrategy = strategy; |
| 891 | } |
Rachel Lee | 58cc90d | 2023-09-05 18:50:20 -0700 | [diff] [blame] | 892 | } |
| 893 | |
Vishnu Nair | 3d8565a | 2023-06-30 07:23:24 +0000 | [diff] [blame] | 894 | if (forceUpdate || snapshot.clientChanges & layer_state_t::eFrameRateSelectionPriority) { |
| 895 | snapshot.frameRateSelectionPriority = |
| 896 | (requested.frameRateSelectionPriority == Layer::PRIORITY_UNSET) |
| 897 | ? parentSnapshot.frameRateSelectionPriority |
| 898 | : requested.frameRateSelectionPriority; |
| 899 | } |
| 900 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 901 | if (forceUpdate || |
| 902 | snapshot.clientChanges & |
| 903 | (layer_state_t::eBackgroundBlurRadiusChanged | layer_state_t::eBlurRegionsChanged | |
| 904 | layer_state_t::eAlphaChanged)) { |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 905 | snapshot.backgroundBlurRadius = args.supportsBlur |
| 906 | ? static_cast<int>(parentSnapshot.color.a * (float)requested.backgroundBlurRadius) |
| 907 | : 0; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 908 | snapshot.blurRegions = requested.blurRegions; |
Vishnu Nair | 80a5a70 | 2023-02-11 01:21:51 +0000 | [diff] [blame] | 909 | for (auto& region : snapshot.blurRegions) { |
| 910 | region.alpha = region.alpha * snapshot.color.a; |
| 911 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 912 | } |
| 913 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 914 | if (forceUpdate || snapshot.changes.any(RequestedLayerState::Changes::Geometry)) { |
| 915 | uint32_t primaryDisplayRotationFlags = getPrimaryDisplayRotationFlags(args.displays); |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 916 | updateLayerBounds(snapshot, requested, parentSnapshot, primaryDisplayRotationFlags); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 917 | } |
| 918 | |
Marzia Favaro | dcc9d9b | 2024-01-10 10:17:00 +0000 | [diff] [blame] | 919 | if (snapshot.edgeExtensionEffect.hasEffect()) { |
| 920 | updateBoundsForEdgeExtension(snapshot); |
| 921 | } |
| 922 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 923 | if (forceUpdate || snapshot.clientChanges & layer_state_t::eCornerRadiusChanged || |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 924 | snapshot.changes.any(RequestedLayerState::Changes::Geometry | |
| 925 | RequestedLayerState::Changes::BufferUsageFlags)) { |
| 926 | updateRoundedCorner(snapshot, requested, parentSnapshot, args); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 927 | } |
| 928 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 929 | if (forceUpdate || snapshot.clientChanges & layer_state_t::eShadowRadiusChanged || |
| 930 | snapshot.changes.any(RequestedLayerState::Changes::Geometry)) { |
| 931 | updateShadows(snapshot, requested, args.globalShadowSettings); |
| 932 | } |
| 933 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 934 | if (forceUpdate || |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 935 | snapshot.changes.any(RequestedLayerState::Changes::Geometry | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 936 | RequestedLayerState::Changes::Input)) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 937 | updateInput(snapshot, requested, parentSnapshot, path, args); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 938 | } |
| 939 | |
| 940 | // computed snapshot properties |
Marzia Favaro | dcc9d9b | 2024-01-10 10:17:00 +0000 | [diff] [blame] | 941 | snapshot.forceClientComposition = snapshot.shadowSettings.length > 0 || |
| 942 | snapshot.stretchEffect.hasEffect() || snapshot.edgeExtensionEffect.hasEffect(); |
Vishnu Nair | c765c6c | 2023-02-23 00:08:01 +0000 | [diff] [blame] | 943 | snapshot.contentOpaque = snapshot.isContentOpaque(); |
| 944 | snapshot.isOpaque = snapshot.contentOpaque && !snapshot.roundedCorner.hasRoundedCorners() && |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 945 | snapshot.color.a == 1.f; |
| 946 | snapshot.blendMode = getBlendMode(snapshot, requested); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 947 | LLOGV(snapshot.sequence, |
Vishnu Nair | 92990e2 | 2023-02-24 20:01:05 +0000 | [diff] [blame] | 948 | "%supdated %s changes:%s parent:%s requested:%s requested:%s from parent %s", |
| 949 | args.forceUpdate == ForceUpdateFlags::ALL ? "Force " : "", |
| 950 | snapshot.getDebugString().c_str(), snapshot.changes.string().c_str(), |
| 951 | parentSnapshot.changes.string().c_str(), requested.changes.string().c_str(), |
| 952 | std::to_string(requested.what).c_str(), parentSnapshot.getDebugString().c_str()); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | void LayerSnapshotBuilder::updateRoundedCorner(LayerSnapshot& snapshot, |
| 956 | const RequestedLayerState& requested, |
Vishnu Nair | 0808ae6 | 2023-08-07 21:42:42 -0700 | [diff] [blame] | 957 | const LayerSnapshot& parentSnapshot, |
| 958 | const Args& args) { |
| 959 | if (args.skipRoundCornersWhenProtected && requested.isProtected()) { |
| 960 | snapshot.roundedCorner = RoundedCornerState(); |
| 961 | return; |
| 962 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 963 | snapshot.roundedCorner = RoundedCornerState(); |
| 964 | RoundedCornerState parentRoundedCorner; |
| 965 | if (parentSnapshot.roundedCorner.hasRoundedCorners()) { |
| 966 | parentRoundedCorner = parentSnapshot.roundedCorner; |
| 967 | ui::Transform t = snapshot.localTransform.inverse(); |
| 968 | parentRoundedCorner.cropRect = t.transform(parentRoundedCorner.cropRect); |
| 969 | parentRoundedCorner.radius.x *= t.getScaleX(); |
| 970 | parentRoundedCorner.radius.y *= t.getScaleY(); |
| 971 | } |
| 972 | |
Vishnu Nair | a9123c8 | 2024-10-03 03:56:44 +0000 | [diff] [blame^] | 973 | FloatRect layerCropRect = snapshot.croppedBufferSize; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 974 | const vec2 radius(requested.cornerRadius, requested.cornerRadius); |
| 975 | RoundedCornerState layerSettings(layerCropRect, radius); |
| 976 | const bool layerSettingsValid = layerSettings.hasRoundedCorners() && !layerCropRect.isEmpty(); |
| 977 | const bool parentRoundedCornerValid = parentRoundedCorner.hasRoundedCorners(); |
| 978 | if (layerSettingsValid && parentRoundedCornerValid) { |
| 979 | // If the parent and the layer have rounded corner settings, use the parent settings if |
| 980 | // the parent crop is entirely inside the layer crop. This has limitations and cause |
| 981 | // rendering artifacts. See b/200300845 for correct fix. |
| 982 | if (parentRoundedCorner.cropRect.left > layerCropRect.left && |
| 983 | parentRoundedCorner.cropRect.top > layerCropRect.top && |
| 984 | parentRoundedCorner.cropRect.right < layerCropRect.right && |
| 985 | parentRoundedCorner.cropRect.bottom < layerCropRect.bottom) { |
| 986 | snapshot.roundedCorner = parentRoundedCorner; |
| 987 | } else { |
| 988 | snapshot.roundedCorner = layerSettings; |
| 989 | } |
| 990 | } else if (layerSettingsValid) { |
| 991 | snapshot.roundedCorner = layerSettings; |
| 992 | } else if (parentRoundedCornerValid) { |
| 993 | snapshot.roundedCorner = parentRoundedCorner; |
| 994 | } |
| 995 | } |
| 996 | |
Marzia Favaro | dcc9d9b | 2024-01-10 10:17:00 +0000 | [diff] [blame] | 997 | /** |
| 998 | * According to the edges that we are requested to extend, we increase the bounds to the maximum |
| 999 | * extension allowed by the crop (parent crop + requested crop). The animation that called |
| 1000 | * Transition#setEdgeExtensionEffect is in charge of setting the requested crop. |
| 1001 | * @param snapshot |
| 1002 | */ |
| 1003 | void LayerSnapshotBuilder::updateBoundsForEdgeExtension(LayerSnapshot& snapshot) { |
| 1004 | EdgeExtensionEffect& effect = snapshot.edgeExtensionEffect; |
| 1005 | |
| 1006 | if (effect.extendsEdge(LEFT)) { |
| 1007 | snapshot.geomLayerBounds.left = snapshot.geomLayerCrop.left; |
| 1008 | } |
| 1009 | if (effect.extendsEdge(RIGHT)) { |
| 1010 | snapshot.geomLayerBounds.right = snapshot.geomLayerCrop.right; |
| 1011 | } |
| 1012 | if (effect.extendsEdge(TOP)) { |
| 1013 | snapshot.geomLayerBounds.top = snapshot.geomLayerCrop.top; |
| 1014 | } |
| 1015 | if (effect.extendsEdge(BOTTOM)) { |
| 1016 | snapshot.geomLayerBounds.bottom = snapshot.geomLayerCrop.bottom; |
| 1017 | } |
| 1018 | |
| 1019 | snapshot.transformedBounds = snapshot.geomLayerTransform.transform(snapshot.geomLayerBounds); |
| 1020 | } |
| 1021 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1022 | void LayerSnapshotBuilder::updateLayerBounds(LayerSnapshot& snapshot, |
| 1023 | const RequestedLayerState& requested, |
| 1024 | const LayerSnapshot& parentSnapshot, |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 1025 | uint32_t primaryDisplayRotationFlags) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1026 | snapshot.geomLayerTransform = parentSnapshot.geomLayerTransform * snapshot.localTransform; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1027 | const bool transformWasInvalid = snapshot.invalidTransform; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1028 | snapshot.invalidTransform = !LayerSnapshot::isTransformValid(snapshot.geomLayerTransform); |
| 1029 | if (snapshot.invalidTransform) { |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1030 | auto& t = snapshot.geomLayerTransform; |
| 1031 | auto& requestedT = requested.requestedTransform; |
| 1032 | std::string transformDebug = |
| 1033 | base::StringPrintf(" transform={%f,%f,%f,%f} requestedTransform={%f,%f,%f,%f}", |
| 1034 | t.dsdx(), t.dsdy(), t.dtdx(), t.dtdy(), requestedT.dsdx(), |
| 1035 | requestedT.dsdy(), requestedT.dtdx(), requestedT.dtdy()); |
| 1036 | std::string bufferDebug; |
| 1037 | if (requested.externalTexture) { |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 1038 | auto unRotBuffer = requested.getUnrotatedBufferSize(primaryDisplayRotationFlags); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1039 | auto& destFrame = requested.destinationFrame; |
| 1040 | bufferDebug = base::StringPrintf(" buffer={%d,%d} displayRot=%d" |
| 1041 | " destFrame={%d,%d,%d,%d} unRotBuffer={%d,%d}", |
| 1042 | requested.externalTexture->getWidth(), |
| 1043 | requested.externalTexture->getHeight(), |
Vishnu Nair | b76d99a | 2023-03-19 18:22:31 -0700 | [diff] [blame] | 1044 | primaryDisplayRotationFlags, destFrame.left, |
| 1045 | destFrame.top, destFrame.right, destFrame.bottom, |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1046 | unRotBuffer.getHeight(), unRotBuffer.getWidth()); |
| 1047 | } |
| 1048 | ALOGW("Resetting transform for %s because it is invalid.%s%s", |
| 1049 | snapshot.getDebugString().c_str(), transformDebug.c_str(), bufferDebug.c_str()); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1050 | snapshot.geomLayerTransform.reset(); |
| 1051 | } |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1052 | if (transformWasInvalid != snapshot.invalidTransform) { |
| 1053 | // If transform is invalid, the layer will be hidden. |
| 1054 | mResortSnapshots = true; |
| 1055 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1056 | snapshot.geomInverseLayerTransform = snapshot.geomLayerTransform.inverse(); |
| 1057 | |
| 1058 | FloatRect parentBounds = parentSnapshot.geomLayerBounds; |
| 1059 | parentBounds = snapshot.localTransform.inverse().transform(parentBounds); |
| 1060 | snapshot.geomLayerBounds = |
Marzia Favaro | dcc9d9b | 2024-01-10 10:17:00 +0000 | [diff] [blame] | 1061 | requested.externalTexture ? snapshot.bufferSize.toFloatRect() : parentBounds; |
| 1062 | snapshot.geomLayerCrop = parentBounds; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1063 | if (!requested.crop.isEmpty()) { |
Vishnu Nair | a9123c8 | 2024-10-03 03:56:44 +0000 | [diff] [blame^] | 1064 | snapshot.geomLayerCrop = snapshot.geomLayerCrop.intersect(requested.crop); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1065 | } |
Marzia Favaro | dcc9d9b | 2024-01-10 10:17:00 +0000 | [diff] [blame] | 1066 | snapshot.geomLayerBounds = snapshot.geomLayerBounds.intersect(snapshot.geomLayerCrop); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1067 | snapshot.transformedBounds = snapshot.geomLayerTransform.transform(snapshot.geomLayerBounds); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1068 | const Rect geomLayerBoundsWithoutTransparentRegion = |
| 1069 | RequestedLayerState::reduce(Rect(snapshot.geomLayerBounds), |
| 1070 | requested.transparentRegion); |
| 1071 | snapshot.transformedBoundsWithoutTransparentRegion = |
| 1072 | snapshot.geomLayerTransform.transform(geomLayerBoundsWithoutTransparentRegion); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1073 | snapshot.parentTransform = parentSnapshot.geomLayerTransform; |
| 1074 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1075 | if (requested.potentialCursor) { |
Vishnu Nair | a9123c8 | 2024-10-03 03:56:44 +0000 | [diff] [blame^] | 1076 | // Subtract the transparent region and snap to the bounds |
| 1077 | const Rect bounds = RequestedLayerState::reduce(Rect(snapshot.croppedBufferSize), |
| 1078 | requested.transparentRegion); |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1079 | snapshot.cursorFrame = snapshot.geomLayerTransform.transform(bounds); |
| 1080 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1081 | } |
| 1082 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 1083 | void LayerSnapshotBuilder::updateShadows(LayerSnapshot& snapshot, const RequestedLayerState&, |
Vishnu Nair | d9e4f46 | 2023-10-06 04:05:45 +0000 | [diff] [blame] | 1084 | const ShadowSettings& globalShadowSettings) { |
| 1085 | if (snapshot.shadowSettings.length > 0.f) { |
| 1086 | snapshot.shadowSettings.ambientColor = globalShadowSettings.ambientColor; |
| 1087 | snapshot.shadowSettings.spotColor = globalShadowSettings.spotColor; |
| 1088 | snapshot.shadowSettings.lightPos = globalShadowSettings.lightPos; |
| 1089 | snapshot.shadowSettings.lightRadius = globalShadowSettings.lightRadius; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1090 | |
| 1091 | // Note: this preserves existing behavior of shadowing the entire layer and not cropping |
| 1092 | // it if transparent regions are present. This may not be necessary since shadows are |
| 1093 | // typically cast by layers without transparent regions. |
| 1094 | snapshot.shadowSettings.boundaries = snapshot.geomLayerBounds; |
| 1095 | |
| 1096 | // If the casting layer is translucent, we need to fill in the shadow underneath the |
| 1097 | // layer. Otherwise the generated shadow will only be shown around the casting layer. |
| 1098 | snapshot.shadowSettings.casterIsTranslucent = |
| 1099 | !snapshot.isContentOpaque() || (snapshot.alpha < 1.0f); |
| 1100 | snapshot.shadowSettings.ambientColor *= snapshot.alpha; |
| 1101 | snapshot.shadowSettings.spotColor *= snapshot.alpha; |
| 1102 | } |
| 1103 | } |
| 1104 | |
| 1105 | void LayerSnapshotBuilder::updateInput(LayerSnapshot& snapshot, |
| 1106 | const RequestedLayerState& requested, |
| 1107 | const LayerSnapshot& parentSnapshot, |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1108 | const LayerHierarchy::TraversalPath& path, |
| 1109 | const Args& args) { |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1110 | using InputConfig = gui::WindowInfo::InputConfig; |
| 1111 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1112 | if (requested.windowInfoHandle) { |
| 1113 | snapshot.inputInfo = *requested.windowInfoHandle->getInfo(); |
| 1114 | } else { |
| 1115 | snapshot.inputInfo = {}; |
Vishnu Nair | 40d0228 | 2023-02-28 21:11:40 +0000 | [diff] [blame] | 1116 | // b/271132344 revisit this and see if we can always use the layers uid/pid |
| 1117 | snapshot.inputInfo.name = requested.name; |
Prabir Pradhan | 8a5c41d | 2023-06-08 19:13:46 +0000 | [diff] [blame] | 1118 | snapshot.inputInfo.ownerUid = gui::Uid{requested.ownerUid}; |
Prabir Pradhan | e59c6dc | 2023-06-13 19:53:03 +0000 | [diff] [blame] | 1119 | snapshot.inputInfo.ownerPid = gui::Pid{requested.ownerPid}; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1120 | } |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 1121 | snapshot.touchCropId = requested.touchCropId; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1122 | |
Vishnu Nair | 93b8b79 | 2023-02-27 19:40:24 +0000 | [diff] [blame] | 1123 | snapshot.inputInfo.id = static_cast<int32_t>(snapshot.uniqueSequence); |
Linnan Li | 13bf76a | 2024-05-05 19:18:02 +0800 | [diff] [blame] | 1124 | snapshot.inputInfo.displayId = |
| 1125 | ui::LogicalDisplayId{static_cast<int32_t>(snapshot.outputFilter.layerStack.id)}; |
Vishnu Nair | f13c898 | 2023-12-02 11:26:09 -0800 | [diff] [blame] | 1126 | snapshot.inputInfo.touchOcclusionMode = requested.hasInputInfo() |
| 1127 | ? requested.windowInfoHandle->getInfo()->touchOcclusionMode |
| 1128 | : parentSnapshot.inputInfo.touchOcclusionMode; |
Vishnu Nair | 59a6be3 | 2024-01-29 10:26:21 -0800 | [diff] [blame] | 1129 | snapshot.inputInfo.canOccludePresentation = parentSnapshot.inputInfo.canOccludePresentation || |
| 1130 | (requested.flags & layer_state_t::eCanOccludePresentation); |
Vishnu Nair | f13c898 | 2023-12-02 11:26:09 -0800 | [diff] [blame] | 1131 | if (requested.dropInputMode == gui::DropInputMode::ALL || |
| 1132 | parentSnapshot.dropInputMode == gui::DropInputMode::ALL) { |
| 1133 | snapshot.dropInputMode = gui::DropInputMode::ALL; |
| 1134 | } else if (requested.dropInputMode == gui::DropInputMode::OBSCURED || |
| 1135 | parentSnapshot.dropInputMode == gui::DropInputMode::OBSCURED) { |
| 1136 | snapshot.dropInputMode = gui::DropInputMode::OBSCURED; |
| 1137 | } else { |
| 1138 | snapshot.dropInputMode = gui::DropInputMode::NONE; |
| 1139 | } |
| 1140 | |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1141 | if (snapshot.isSecure || |
Arpit Singh | 490ccc9 | 2024-04-30 14:26:21 +0000 | [diff] [blame] | 1142 | parentSnapshot.inputInfo.inputConfig.test(InputConfig::SENSITIVE_FOR_PRIVACY)) { |
| 1143 | snapshot.inputInfo.inputConfig |= InputConfig::SENSITIVE_FOR_PRIVACY; |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1144 | } |
| 1145 | |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 1146 | updateVisibility(snapshot, snapshot.isVisible); |
Wenhui Yang | ab89d81 | 2024-09-11 23:21:38 +0000 | [diff] [blame] | 1147 | if (!requested.needsInputInfo()) { |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1148 | return; |
| 1149 | } |
| 1150 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1151 | static frontend::DisplayInfo sDefaultInfo = {.isSecure = false}; |
| 1152 | const std::optional<frontend::DisplayInfo> displayInfoOpt = |
| 1153 | args.displays.get(snapshot.outputFilter.layerStack); |
| 1154 | bool noValidDisplay = !displayInfoOpt.has_value(); |
| 1155 | auto displayInfo = displayInfoOpt.value_or(sDefaultInfo); |
| 1156 | |
Wenhui Yang | ab89d81 | 2024-09-11 23:21:38 +0000 | [diff] [blame] | 1157 | if (!requested.hasInputInfo()) { |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1158 | snapshot.inputInfo.inputConfig = InputConfig::NO_INPUT_CHANNEL; |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1159 | } |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1160 | fillInputFrameInfo(snapshot.inputInfo, displayInfo.transform, snapshot); |
| 1161 | |
| 1162 | if (noValidDisplay) { |
| 1163 | // Do not let the window receive touches if it is not associated with a valid display |
| 1164 | // transform. We still allow the window to receive keys and prevent ANRs. |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1165 | snapshot.inputInfo.inputConfig |= InputConfig::NOT_TOUCHABLE; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1166 | } |
| 1167 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1168 | snapshot.inputInfo.alpha = snapshot.color.a; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1169 | |
| 1170 | handleDropInputMode(snapshot, parentSnapshot); |
| 1171 | |
| 1172 | // If the window will be blacked out on a display because the display does not have the secure |
| 1173 | // flag and the layer has the secure flag set, then drop input. |
| 1174 | if (!displayInfo.isSecure && snapshot.isSecure) { |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1175 | snapshot.inputInfo.inputConfig |= InputConfig::DROP_INPUT; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 1178 | if (requested.touchCropId != UNASSIGNED_LAYER_ID || path.isClone()) { |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 1179 | mNeedsTouchableRegionCrop.insert(path); |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 1180 | } |
| 1181 | auto cropLayerSnapshot = getSnapshot(requested.touchCropId); |
| 1182 | if (!cropLayerSnapshot && snapshot.inputInfo.replaceTouchableRegionWithCrop) { |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 1183 | FloatRect inputBounds = getInputBounds(snapshot, /*fillParentBounds=*/true).first; |
Vishnu Nair | fed7c12 | 2023-03-18 01:54:43 +0000 | [diff] [blame] | 1184 | Rect inputBoundsInDisplaySpace = |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 1185 | getInputBoundsInDisplaySpace(snapshot, inputBounds, displayInfo.transform); |
| 1186 | snapshot.inputInfo.touchableRegion = Region(inputBoundsInDisplaySpace); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1187 | } |
| 1188 | |
| 1189 | // Inherit the trusted state from the parent hierarchy, but don't clobber the trusted state |
| 1190 | // if it was set by WM for a known system overlay |
Vishnu Nair | 9e0017e | 2024-05-22 19:02:44 +0000 | [diff] [blame] | 1191 | if (snapshot.trustedOverlay == gui::TrustedOverlay::ENABLED) { |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1192 | snapshot.inputInfo.inputConfig |= InputConfig::TRUSTED_OVERLAY; |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1193 | } |
| 1194 | |
Vishnu Nair | a9123c8 | 2024-10-03 03:56:44 +0000 | [diff] [blame^] | 1195 | snapshot.inputInfo.contentSize = {snapshot.croppedBufferSize.getHeight(), |
| 1196 | snapshot.croppedBufferSize.getWidth()}; |
Vishnu Nair | 494a2e4 | 2023-11-10 17:21:19 -0800 | [diff] [blame] | 1197 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1198 | // If the layer is a clone, we need to crop the input region to cloned root to prevent |
| 1199 | // touches from going outside the cloned area. |
| 1200 | if (path.isClone()) { |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1201 | snapshot.inputInfo.inputConfig |= InputConfig::CLONE; |
Vishnu Nair | 444f395 | 2023-04-11 13:01:02 -0700 | [diff] [blame] | 1202 | // Cloned layers shouldn't handle watch outside since their z order is not determined by |
| 1203 | // WM or the client. |
Prabir Pradhan | cf35919 | 2024-03-20 00:42:57 +0000 | [diff] [blame] | 1204 | snapshot.inputInfo.inputConfig.clear(InputConfig::WATCH_OUTSIDE_TOUCH); |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1205 | } |
| 1206 | } |
| 1207 | |
| 1208 | std::vector<std::unique_ptr<LayerSnapshot>>& LayerSnapshotBuilder::getSnapshots() { |
| 1209 | return mSnapshots; |
| 1210 | } |
| 1211 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1212 | void LayerSnapshotBuilder::forEachVisibleSnapshot(const ConstVisitor& visitor) const { |
| 1213 | for (int i = 0; i < mNumInterestingSnapshots; i++) { |
| 1214 | LayerSnapshot& snapshot = *mSnapshots[(size_t)i]; |
| 1215 | if (!snapshot.isVisible) continue; |
| 1216 | visitor(snapshot); |
| 1217 | } |
| 1218 | } |
| 1219 | |
Vishnu Nair | 3af0ec0 | 2023-02-10 04:13:48 +0000 | [diff] [blame] | 1220 | // Visit each visible snapshot in z-order |
| 1221 | void LayerSnapshotBuilder::forEachVisibleSnapshot(const ConstVisitor& visitor, |
| 1222 | const LayerHierarchy& root) const { |
| 1223 | root.traverseInZOrder( |
| 1224 | [this, visitor](const LayerHierarchy&, |
| 1225 | const LayerHierarchy::TraversalPath& traversalPath) -> bool { |
| 1226 | LayerSnapshot* snapshot = getSnapshot(traversalPath); |
| 1227 | if (snapshot && snapshot->isVisible) { |
| 1228 | visitor(*snapshot); |
| 1229 | } |
| 1230 | return true; |
| 1231 | }); |
| 1232 | } |
| 1233 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1234 | void LayerSnapshotBuilder::forEachVisibleSnapshot(const Visitor& visitor) { |
| 1235 | for (int i = 0; i < mNumInterestingSnapshots; i++) { |
| 1236 | std::unique_ptr<LayerSnapshot>& snapshot = mSnapshots.at((size_t)i); |
| 1237 | if (!snapshot->isVisible) continue; |
| 1238 | visitor(snapshot); |
| 1239 | } |
| 1240 | } |
| 1241 | |
Nergi Rahardi | 0dfc096 | 2024-05-23 06:57:36 +0000 | [diff] [blame] | 1242 | void LayerSnapshotBuilder::forEachSnapshot(const Visitor& visitor, |
| 1243 | const ConstPredicate& predicate) { |
| 1244 | for (int i = 0; i < mNumInterestingSnapshots; i++) { |
| 1245 | std::unique_ptr<LayerSnapshot>& snapshot = mSnapshots.at((size_t)i); |
| 1246 | if (!predicate(*snapshot)) continue; |
| 1247 | visitor(snapshot); |
| 1248 | } |
| 1249 | } |
| 1250 | |
Vishnu Nair | 438a0ac | 2024-08-15 08:09:32 +0000 | [diff] [blame] | 1251 | void LayerSnapshotBuilder::forEachSnapshot(const ConstVisitor& visitor) const { |
| 1252 | for (auto& snapshot : mSnapshots) { |
| 1253 | visitor(*snapshot); |
| 1254 | } |
| 1255 | } |
| 1256 | |
Vishnu Nair | cfb2d25 | 2023-01-19 04:44:02 +0000 | [diff] [blame] | 1257 | void LayerSnapshotBuilder::forEachInputSnapshot(const ConstVisitor& visitor) const { |
| 1258 | for (int i = mNumInterestingSnapshots - 1; i >= 0; i--) { |
| 1259 | LayerSnapshot& snapshot = *mSnapshots[(size_t)i]; |
| 1260 | if (!snapshot.hasInputInfo()) continue; |
| 1261 | visitor(snapshot); |
| 1262 | } |
| 1263 | } |
| 1264 | |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 1265 | void LayerSnapshotBuilder::updateTouchableRegionCrop(const Args& args) { |
| 1266 | if (mNeedsTouchableRegionCrop.empty()) { |
| 1267 | return; |
| 1268 | } |
| 1269 | |
| 1270 | static constexpr ftl::Flags<RequestedLayerState::Changes> AFFECTS_INPUT = |
| 1271 | RequestedLayerState::Changes::Visibility | RequestedLayerState::Changes::Created | |
| 1272 | RequestedLayerState::Changes::Hierarchy | RequestedLayerState::Changes::Geometry | |
| 1273 | RequestedLayerState::Changes::Input; |
| 1274 | |
| 1275 | if (args.forceUpdate != ForceUpdateFlags::ALL && |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 1276 | !args.layerLifecycleManager.getGlobalChanges().any(AFFECTS_INPUT) && !args.displayChanges) { |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 1277 | return; |
| 1278 | } |
| 1279 | |
| 1280 | for (auto& path : mNeedsTouchableRegionCrop) { |
| 1281 | frontend::LayerSnapshot* snapshot = getSnapshot(path); |
| 1282 | if (!snapshot) { |
| 1283 | continue; |
| 1284 | } |
Vishnu Nair | a02943f | 2023-06-03 13:44:46 -0700 | [diff] [blame] | 1285 | LLOGV(snapshot->sequence, "updateTouchableRegionCrop=%s", |
| 1286 | snapshot->getDebugString().c_str()); |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 1287 | const std::optional<frontend::DisplayInfo> displayInfoOpt = |
| 1288 | args.displays.get(snapshot->outputFilter.layerStack); |
| 1289 | static frontend::DisplayInfo sDefaultInfo = {.isSecure = false}; |
| 1290 | auto displayInfo = displayInfoOpt.value_or(sDefaultInfo); |
| 1291 | |
| 1292 | bool needsUpdate = |
| 1293 | args.forceUpdate == ForceUpdateFlags::ALL || snapshot->changes.any(AFFECTS_INPUT); |
| 1294 | auto cropLayerSnapshot = getSnapshot(snapshot->touchCropId); |
| 1295 | needsUpdate = |
| 1296 | needsUpdate || (cropLayerSnapshot && cropLayerSnapshot->changes.any(AFFECTS_INPUT)); |
| 1297 | auto clonedRootSnapshot = path.isClone() ? getSnapshot(snapshot->mirrorRootPath) : nullptr; |
| 1298 | needsUpdate = needsUpdate || |
| 1299 | (clonedRootSnapshot && clonedRootSnapshot->changes.any(AFFECTS_INPUT)); |
| 1300 | |
| 1301 | if (!needsUpdate) { |
| 1302 | continue; |
| 1303 | } |
| 1304 | |
| 1305 | if (snapshot->inputInfo.replaceTouchableRegionWithCrop) { |
| 1306 | Rect inputBoundsInDisplaySpace; |
| 1307 | if (!cropLayerSnapshot) { |
| 1308 | FloatRect inputBounds = getInputBounds(*snapshot, /*fillParentBounds=*/true).first; |
| 1309 | inputBoundsInDisplaySpace = |
| 1310 | getInputBoundsInDisplaySpace(*snapshot, inputBounds, displayInfo.transform); |
| 1311 | } else { |
| 1312 | FloatRect inputBounds = |
| 1313 | getInputBounds(*cropLayerSnapshot, /*fillParentBounds=*/true).first; |
| 1314 | inputBoundsInDisplaySpace = |
| 1315 | getInputBoundsInDisplaySpace(*cropLayerSnapshot, inputBounds, |
| 1316 | displayInfo.transform); |
| 1317 | } |
| 1318 | snapshot->inputInfo.touchableRegion = Region(inputBoundsInDisplaySpace); |
| 1319 | } else if (cropLayerSnapshot) { |
| 1320 | FloatRect inputBounds = |
| 1321 | getInputBounds(*cropLayerSnapshot, /*fillParentBounds=*/true).first; |
| 1322 | Rect inputBoundsInDisplaySpace = |
| 1323 | getInputBoundsInDisplaySpace(*cropLayerSnapshot, inputBounds, |
| 1324 | displayInfo.transform); |
Chavi Weingarten | 1ba381e | 2024-01-09 21:54:11 +0000 | [diff] [blame] | 1325 | snapshot->inputInfo.touchableRegion = |
| 1326 | snapshot->inputInfo.touchableRegion.intersect(inputBoundsInDisplaySpace); |
Vishnu Nair | 29354ec | 2023-03-28 18:51:28 -0700 | [diff] [blame] | 1327 | } |
| 1328 | |
| 1329 | // If the layer is a clone, we need to crop the input region to cloned root to prevent |
| 1330 | // touches from going outside the cloned area. |
| 1331 | if (clonedRootSnapshot) { |
| 1332 | const Rect rect = |
| 1333 | displayInfo.transform.transform(Rect{clonedRootSnapshot->transformedBounds}); |
| 1334 | snapshot->inputInfo.touchableRegion = |
| 1335 | snapshot->inputInfo.touchableRegion.intersect(rect); |
| 1336 | } |
| 1337 | } |
| 1338 | } |
| 1339 | |
Vishnu Nair | 8fc721b | 2022-12-22 20:06:32 +0000 | [diff] [blame] | 1340 | } // namespace android::surfaceflinger::frontend |