blob: 1e5a6fbd1e63806f868bcc3d7d55504d83bb2203 [file] [log] [blame]
Vishnu Nair04f89692022-11-16 23:21:05 +00001/*
2 * Copyright 2022 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define ATRACE_TAG ATRACE_TAG_GRAPHICS
18#undef LOG_TAG
Vishnu Naira02943f2023-06-03 13:44:46 -070019#define LOG_TAG "SurfaceFlinger"
Vishnu Nair04f89692022-11-16 23:21:05 +000020
21#include "LayerHierarchy.h"
Vishnu Nair80a5a702023-02-11 01:21:51 +000022#include "LayerLog.h"
Vishnu Nair04f89692022-11-16 23:21:05 +000023#include "SwapErase.h"
24
25namespace android::surfaceflinger::frontend {
26
27namespace {
28auto layerZCompare = [](const std::pair<LayerHierarchy*, LayerHierarchy::Variant>& lhs,
29 const std::pair<LayerHierarchy*, LayerHierarchy::Variant>& rhs) {
30 auto lhsLayer = lhs.first->getLayer();
31 auto rhsLayer = rhs.first->getLayer();
Vishnu Naircfb2d252023-01-19 04:44:02 +000032 if (lhsLayer->layerStack.id != rhsLayer->layerStack.id) {
Vishnu Nair444f3952023-04-11 13:01:02 -070033 return lhsLayer->layerStack.id < rhsLayer->layerStack.id;
Vishnu Nair04f89692022-11-16 23:21:05 +000034 }
35 if (lhsLayer->z != rhsLayer->z) {
36 return lhsLayer->z < rhsLayer->z;
37 }
38 return lhsLayer->id < rhsLayer->id;
39};
40
41void insertSorted(std::vector<std::pair<LayerHierarchy*, LayerHierarchy::Variant>>& vec,
42 std::pair<LayerHierarchy*, LayerHierarchy::Variant> value) {
43 auto it = std::upper_bound(vec.begin(), vec.end(), value, layerZCompare);
44 vec.insert(it, std::move(value));
45}
46} // namespace
47
48LayerHierarchy::LayerHierarchy(RequestedLayerState* layer) : mLayer(layer) {}
49
50LayerHierarchy::LayerHierarchy(const LayerHierarchy& hierarchy, bool childrenOnly) {
51 mLayer = (childrenOnly) ? nullptr : hierarchy.mLayer;
52 mChildren = hierarchy.mChildren;
53}
54
55void LayerHierarchy::traverse(const Visitor& visitor,
56 LayerHierarchy::TraversalPath& traversalPath) const {
57 if (mLayer) {
58 bool breakTraversal = !visitor(*this, traversalPath);
59 if (breakTraversal) {
60 return;
61 }
62 }
Vishnu Nair606d9d02023-08-19 14:20:18 -070063
64 LLOG_ALWAYS_FATAL_WITH_TRACE_IF(traversalPath.hasRelZLoop(), "Found relative z loop layerId:%d",
65 traversalPath.invalidRelativeRootId);
Vishnu Nair04f89692022-11-16 23:21:05 +000066 for (auto& [child, childVariant] : mChildren) {
67 ScopedAddToTraversalPath addChildToTraversalPath(traversalPath, child->mLayer->id,
68 childVariant);
69 child->traverse(visitor, traversalPath);
70 }
71}
72
73void LayerHierarchy::traverseInZOrder(const Visitor& visitor,
74 LayerHierarchy::TraversalPath& traversalPath) const {
75 bool traverseThisLayer = (mLayer != nullptr);
76 for (auto it = mChildren.begin(); it < mChildren.end(); it++) {
77 auto& [child, childVariant] = *it;
78 if (traverseThisLayer && child->getLayer()->z >= 0) {
Vishnu Naircfb2d252023-01-19 04:44:02 +000079 traverseThisLayer = false;
Vishnu Nair04f89692022-11-16 23:21:05 +000080 bool breakTraversal = !visitor(*this, traversalPath);
81 if (breakTraversal) {
82 return;
83 }
Vishnu Nair04f89692022-11-16 23:21:05 +000084 }
85 if (childVariant == LayerHierarchy::Variant::Detached) {
86 continue;
87 }
88 ScopedAddToTraversalPath addChildToTraversalPath(traversalPath, child->mLayer->id,
89 childVariant);
90 child->traverseInZOrder(visitor, traversalPath);
91 }
92
93 if (traverseThisLayer) {
94 visitor(*this, traversalPath);
95 }
96}
97
98void LayerHierarchy::addChild(LayerHierarchy* child, LayerHierarchy::Variant variant) {
99 insertSorted(mChildren, {child, variant});
100}
101
102void LayerHierarchy::removeChild(LayerHierarchy* child) {
103 auto it = std::find_if(mChildren.begin(), mChildren.end(),
104 [child](const std::pair<LayerHierarchy*, Variant>& x) {
105 return x.first == child;
106 });
Vishnu Nair606d9d02023-08-19 14:20:18 -0700107 LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mChildren.end(), "Could not find child!");
Vishnu Nair04f89692022-11-16 23:21:05 +0000108 mChildren.erase(it);
109}
110
111void LayerHierarchy::sortChildrenByZOrder() {
112 std::sort(mChildren.begin(), mChildren.end(), layerZCompare);
113}
114
115void LayerHierarchy::updateChild(LayerHierarchy* hierarchy, LayerHierarchy::Variant variant) {
116 auto it = std::find_if(mChildren.begin(), mChildren.end(),
117 [hierarchy](std::pair<LayerHierarchy*, Variant>& child) {
118 return child.first == hierarchy;
119 });
Vishnu Nair606d9d02023-08-19 14:20:18 -0700120 LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mChildren.end(), "Could not find child!");
121 it->second = variant;
Vishnu Nair04f89692022-11-16 23:21:05 +0000122}
123
124const RequestedLayerState* LayerHierarchy::getLayer() const {
125 return mLayer;
126}
127
Vishnu Nairea6ff812023-02-27 17:41:39 +0000128const LayerHierarchy* LayerHierarchy::getRelativeParent() const {
129 return mRelativeParent;
130}
131
132const LayerHierarchy* LayerHierarchy::getParent() const {
133 return mParent;
134}
135
Vishnu Nair04f89692022-11-16 23:21:05 +0000136std::string LayerHierarchy::getDebugStringShort() const {
137 std::string debug = "LayerHierarchy{";
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000138 debug += ((mLayer) ? mLayer->getDebugString() : "root") + " ";
Vishnu Nair04f89692022-11-16 23:21:05 +0000139 if (mChildren.empty()) {
140 debug += "no children";
141 } else {
142 debug += std::to_string(mChildren.size()) + " children";
143 }
144 return debug + "}";
145}
146
Vishnu Nair3cc15a42023-06-30 06:20:22 +0000147void LayerHierarchy::dump(std::ostream& out, const std::string& prefix,
Vishnu Nair6f878312023-09-08 11:05:01 -0700148 LayerHierarchy::Variant variant, bool isLastChild,
149 bool includeMirroredHierarchy) const {
Vishnu Nair3cc15a42023-06-30 06:20:22 +0000150 if (!mLayer) {
151 out << " ROOT";
152 } else {
153 out << prefix + (isLastChild ? "└─ " : "├─ ");
154 if (variant == LayerHierarchy::Variant::Relative) {
155 out << "(Relative) ";
156 } else if (variant == LayerHierarchy::Variant::Mirror) {
Vishnu Nair6f878312023-09-08 11:05:01 -0700157 if (!includeMirroredHierarchy) {
158 out << "(Mirroring) " << *mLayer << "\n" + prefix + " └─ ...";
159 return;
160 }
161 out << "(Mirroring) ";
Vishnu Nair3cc15a42023-06-30 06:20:22 +0000162 }
163 out << *mLayer;
Vishnu Nair04f89692022-11-16 23:21:05 +0000164 }
Vishnu Nair3cc15a42023-06-30 06:20:22 +0000165
166 for (size_t i = 0; i < mChildren.size(); i++) {
167 auto& [child, childVariant] = mChildren[i];
168 if (childVariant == LayerHierarchy::Variant::Detached) continue;
169 const bool lastChild = i == (mChildren.size() - 1);
170 std::string childPrefix = prefix;
171 if (mLayer) {
172 childPrefix += (isLastChild ? " " : "│ ");
173 }
174 out << "\n";
Vishnu Nair6f878312023-09-08 11:05:01 -0700175 child->dump(out, childPrefix, childVariant, lastChild, includeMirroredHierarchy);
Vishnu Nair3cc15a42023-06-30 06:20:22 +0000176 }
177 return;
Vishnu Nair04f89692022-11-16 23:21:05 +0000178}
179
180bool LayerHierarchy::hasRelZLoop(uint32_t& outInvalidRelativeRoot) const {
181 outInvalidRelativeRoot = UNASSIGNED_LAYER_ID;
182 traverse([&outInvalidRelativeRoot](const LayerHierarchy&,
183 const LayerHierarchy::TraversalPath& traversalPath) -> bool {
184 if (traversalPath.hasRelZLoop()) {
185 outInvalidRelativeRoot = traversalPath.invalidRelativeRootId;
186 return false;
187 }
188 return true;
189 });
190 return outInvalidRelativeRoot != UNASSIGNED_LAYER_ID;
191}
192
193LayerHierarchyBuilder::LayerHierarchyBuilder(
194 const std::vector<std::unique_ptr<RequestedLayerState>>& layers) {
195 mHierarchies.reserve(layers.size());
196 mLayerIdToHierarchy.reserve(layers.size());
197 for (auto& layer : layers) {
198 mHierarchies.emplace_back(std::make_unique<LayerHierarchy>(layer.get()));
199 mLayerIdToHierarchy[layer->id] = mHierarchies.back().get();
200 }
201 for (const auto& layer : layers) {
202 onLayerAdded(layer.get());
203 }
204 detachHierarchyFromRelativeParent(&mOffscreenRoot);
205}
206
207void LayerHierarchyBuilder::attachToParent(LayerHierarchy* hierarchy) {
208 auto layer = hierarchy->mLayer;
209 LayerHierarchy::Variant type = layer->hasValidRelativeParent()
210 ? LayerHierarchy::Variant::Detached
211 : LayerHierarchy::Variant::Attached;
212
213 LayerHierarchy* parent;
214
215 if (layer->parentId != UNASSIGNED_LAYER_ID) {
216 parent = getHierarchyFromId(layer->parentId);
217 } else if (layer->canBeRoot) {
218 parent = &mRoot;
219 } else {
220 parent = &mOffscreenRoot;
221 }
222 parent->addChild(hierarchy, type);
223 hierarchy->mParent = parent;
224}
225
226void LayerHierarchyBuilder::detachFromParent(LayerHierarchy* hierarchy) {
227 hierarchy->mParent->removeChild(hierarchy);
228 hierarchy->mParent = nullptr;
229}
230
231void LayerHierarchyBuilder::attachToRelativeParent(LayerHierarchy* hierarchy) {
232 auto layer = hierarchy->mLayer;
233 if (!layer->hasValidRelativeParent() || hierarchy->mRelativeParent) {
234 return;
235 }
236
237 if (layer->relativeParentId != UNASSIGNED_LAYER_ID) {
238 hierarchy->mRelativeParent = getHierarchyFromId(layer->relativeParentId);
239 } else {
240 hierarchy->mRelativeParent = &mOffscreenRoot;
241 }
242 hierarchy->mRelativeParent->addChild(hierarchy, LayerHierarchy::Variant::Relative);
243 hierarchy->mParent->updateChild(hierarchy, LayerHierarchy::Variant::Detached);
244}
245
246void LayerHierarchyBuilder::detachFromRelativeParent(LayerHierarchy* hierarchy) {
247 if (hierarchy->mRelativeParent) {
248 hierarchy->mRelativeParent->removeChild(hierarchy);
249 }
250 hierarchy->mRelativeParent = nullptr;
251 hierarchy->mParent->updateChild(hierarchy, LayerHierarchy::Variant::Attached);
252}
253
254void LayerHierarchyBuilder::attachHierarchyToRelativeParent(LayerHierarchy* root) {
255 if (root->mLayer) {
256 attachToRelativeParent(root);
257 }
258 for (auto& [child, childVariant] : root->mChildren) {
259 if (childVariant == LayerHierarchy::Variant::Detached ||
260 childVariant == LayerHierarchy::Variant::Attached) {
261 attachHierarchyToRelativeParent(child);
262 }
263 }
264}
265
266void LayerHierarchyBuilder::detachHierarchyFromRelativeParent(LayerHierarchy* root) {
267 if (root->mLayer) {
268 detachFromRelativeParent(root);
269 }
270 for (auto& [child, childVariant] : root->mChildren) {
271 if (childVariant == LayerHierarchy::Variant::Detached ||
272 childVariant == LayerHierarchy::Variant::Attached) {
273 detachHierarchyFromRelativeParent(child);
274 }
275 }
276}
277
278void LayerHierarchyBuilder::onLayerAdded(RequestedLayerState* layer) {
279 LayerHierarchy* hierarchy = getHierarchyFromId(layer->id);
280 attachToParent(hierarchy);
281 attachToRelativeParent(hierarchy);
282
Vishnu Naira9c43762023-01-27 19:10:25 +0000283 for (uint32_t mirrorId : layer->mirrorIds) {
284 LayerHierarchy* mirror = getHierarchyFromId(mirrorId);
Vishnu Nair04f89692022-11-16 23:21:05 +0000285 hierarchy->addChild(mirror, LayerHierarchy::Variant::Mirror);
286 }
287}
288
289void LayerHierarchyBuilder::onLayerDestroyed(RequestedLayerState* layer) {
Vishnu Nair80a5a702023-02-11 01:21:51 +0000290 LLOGV(layer->id, "");
Vishnu Nair04f89692022-11-16 23:21:05 +0000291 LayerHierarchy* hierarchy = getHierarchyFromId(layer->id, /*crashOnFailure=*/false);
292 if (!hierarchy) {
293 // Layer was never part of the hierarchy if it was created and destroyed in the same
294 // transaction.
295 return;
296 }
297 // detach from parent
298 detachFromRelativeParent(hierarchy);
299 detachFromParent(hierarchy);
300
301 // detach children
302 for (auto& [child, variant] : hierarchy->mChildren) {
303 if (variant == LayerHierarchy::Variant::Attached ||
304 variant == LayerHierarchy::Variant::Detached) {
305 mOffscreenRoot.addChild(child, LayerHierarchy::Variant::Attached);
306 child->mParent = &mOffscreenRoot;
307 } else if (variant == LayerHierarchy::Variant::Relative) {
308 mOffscreenRoot.addChild(child, LayerHierarchy::Variant::Attached);
309 child->mRelativeParent = &mOffscreenRoot;
310 }
311 }
312
313 swapErase(mHierarchies, [hierarchy](std::unique_ptr<LayerHierarchy>& layerHierarchy) {
314 return layerHierarchy.get() == hierarchy;
315 });
316 mLayerIdToHierarchy.erase(layer->id);
317}
318
319void LayerHierarchyBuilder::updateMirrorLayer(RequestedLayerState* layer) {
320 LayerHierarchy* hierarchy = getHierarchyFromId(layer->id);
321 auto it = hierarchy->mChildren.begin();
322 while (it != hierarchy->mChildren.end()) {
323 if (it->second == LayerHierarchy::Variant::Mirror) {
Vishnu Naira9c43762023-01-27 19:10:25 +0000324 it = hierarchy->mChildren.erase(it);
325 } else {
326 it++;
Vishnu Nair04f89692022-11-16 23:21:05 +0000327 }
Vishnu Nair04f89692022-11-16 23:21:05 +0000328 }
329
Vishnu Naira9c43762023-01-27 19:10:25 +0000330 for (uint32_t mirrorId : layer->mirrorIds) {
331 hierarchy->addChild(getHierarchyFromId(mirrorId), LayerHierarchy::Variant::Mirror);
Vishnu Nair04f89692022-11-16 23:21:05 +0000332 }
333}
334
335void LayerHierarchyBuilder::update(
336 const std::vector<std::unique_ptr<RequestedLayerState>>& layers,
337 const std::vector<std::unique_ptr<RequestedLayerState>>& destroyedLayers) {
338 // rebuild map
339 for (auto& layer : layers) {
340 if (layer->changes.test(RequestedLayerState::Changes::Created)) {
341 mHierarchies.emplace_back(std::make_unique<LayerHierarchy>(layer.get()));
342 mLayerIdToHierarchy[layer->id] = mHierarchies.back().get();
343 }
344 }
345
346 for (auto& layer : layers) {
347 if (layer->changes.get() == 0) {
348 continue;
349 }
350 if (layer->changes.test(RequestedLayerState::Changes::Created)) {
351 onLayerAdded(layer.get());
352 continue;
353 }
354 LayerHierarchy* hierarchy = getHierarchyFromId(layer->id);
355 if (layer->changes.test(RequestedLayerState::Changes::Parent)) {
356 detachFromParent(hierarchy);
357 attachToParent(hierarchy);
358 }
359 if (layer->changes.test(RequestedLayerState::Changes::RelativeParent)) {
360 detachFromRelativeParent(hierarchy);
361 attachToRelativeParent(hierarchy);
362 }
363 if (layer->changes.test(RequestedLayerState::Changes::Z)) {
364 hierarchy->mParent->sortChildrenByZOrder();
365 if (hierarchy->mRelativeParent) {
366 hierarchy->mRelativeParent->sortChildrenByZOrder();
367 }
368 }
369 if (layer->changes.test(RequestedLayerState::Changes::Mirror)) {
370 updateMirrorLayer(layer.get());
371 }
372 }
373
374 for (auto& layer : destroyedLayers) {
375 onLayerDestroyed(layer.get());
376 }
377 // When moving from onscreen to offscreen and vice versa, we need to attach and detach
378 // from our relative parents. This walks down both trees to do so. We can optimize this
379 // further by tracking onscreen, offscreen state in LayerHierarchy.
380 detachHierarchyFromRelativeParent(&mOffscreenRoot);
381 attachHierarchyToRelativeParent(&mRoot);
382}
383
384const LayerHierarchy& LayerHierarchyBuilder::getHierarchy() const {
385 return mRoot;
386}
387
388const LayerHierarchy& LayerHierarchyBuilder::getOffscreenHierarchy() const {
389 return mOffscreenRoot;
390}
391
392std::string LayerHierarchyBuilder::getDebugString(uint32_t layerId, uint32_t depth) const {
393 if (depth > 10) return "too deep, loop?";
394 if (layerId == UNASSIGNED_LAYER_ID) return "";
395 auto it = mLayerIdToHierarchy.find(layerId);
396 if (it == mLayerIdToHierarchy.end()) return "not found";
397
398 LayerHierarchy* hierarchy = it->second;
399 if (!hierarchy->mLayer) return "none";
400
401 std::string debug =
402 "[" + std::to_string(hierarchy->mLayer->id) + "] " + hierarchy->mLayer->name;
403 if (hierarchy->mRelativeParent) {
404 debug += " Relative:" + hierarchy->mRelativeParent->getDebugStringShort();
405 }
406 if (hierarchy->mParent) {
407 debug += " Parent:" + hierarchy->mParent->getDebugStringShort();
408 }
409 return debug;
410}
411
412LayerHierarchy LayerHierarchyBuilder::getPartialHierarchy(uint32_t layerId,
413 bool childrenOnly) const {
414 auto it = mLayerIdToHierarchy.find(layerId);
415 if (it == mLayerIdToHierarchy.end()) return {nullptr};
416
417 LayerHierarchy hierarchy(*it->second, childrenOnly);
418 return hierarchy;
419}
420
421LayerHierarchy* LayerHierarchyBuilder::getHierarchyFromId(uint32_t layerId, bool crashOnFailure) {
422 auto it = mLayerIdToHierarchy.find(layerId);
423 if (it == mLayerIdToHierarchy.end()) {
Vishnu Nair606d9d02023-08-19 14:20:18 -0700424 LLOG_ALWAYS_FATAL_WITH_TRACE_IF(crashOnFailure, "Could not find hierarchy for layer id %d",
425 layerId);
Vishnu Nair04f89692022-11-16 23:21:05 +0000426 return nullptr;
427 };
428
429 return it->second;
430}
431
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000432const LayerHierarchy::TraversalPath LayerHierarchy::TraversalPath::ROOT =
Vishnu Nair04f89692022-11-16 23:21:05 +0000433 {.id = UNASSIGNED_LAYER_ID, .variant = LayerHierarchy::Attached};
434
435std::string LayerHierarchy::TraversalPath::toString() const {
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000436 if (id == UNASSIGNED_LAYER_ID) {
437 return "TraversalPath{ROOT}";
438 }
Vishnu Nair80a5a702023-02-11 01:21:51 +0000439 std::stringstream ss;
440 ss << "TraversalPath{.id = " << id;
Vishnu Nair04f89692022-11-16 23:21:05 +0000441
Vishnu Nair6f878312023-09-08 11:05:01 -0700442 if (!mirrorRootIds.empty()) {
443 ss << ", .mirrorRootIds=";
444 for (auto rootId : mirrorRootIds) {
445 ss << rootId << ",";
446 }
Vishnu Nair04f89692022-11-16 23:21:05 +0000447 }
448
449 if (!relativeRootIds.empty()) {
Vishnu Nair80a5a702023-02-11 01:21:51 +0000450 ss << ", .relativeRootIds=";
Vishnu Nair04f89692022-11-16 23:21:05 +0000451 for (auto rootId : relativeRootIds) {
Vishnu Nair80a5a702023-02-11 01:21:51 +0000452 ss << rootId << ",";
Vishnu Nair04f89692022-11-16 23:21:05 +0000453 }
454 }
455
456 if (hasRelZLoop()) {
Vishnu Nair80a5a702023-02-11 01:21:51 +0000457 ss << "hasRelZLoop=true invalidRelativeRootId=" << invalidRelativeRootId << ",";
Vishnu Nair04f89692022-11-16 23:21:05 +0000458 }
Vishnu Nair80a5a702023-02-11 01:21:51 +0000459 ss << "}";
460 return ss.str();
461}
Vishnu Nair04f89692022-11-16 23:21:05 +0000462
Vishnu Nair04f89692022-11-16 23:21:05 +0000463// Helper class to update a passed in TraversalPath when visiting a child. When the object goes out
464// of scope the TraversalPath is reset to its original state.
465LayerHierarchy::ScopedAddToTraversalPath::ScopedAddToTraversalPath(TraversalPath& traversalPath,
466 uint32_t layerId,
467 LayerHierarchy::Variant variant)
Vishnu Nair80a5a702023-02-11 01:21:51 +0000468 : mTraversalPath(traversalPath), mParentPath(traversalPath) {
Vishnu Nair04f89692022-11-16 23:21:05 +0000469 // Update the traversal id with the child layer id and variant. Parent id and variant are
470 // stored to reset the id upon destruction.
471 traversalPath.id = layerId;
472 traversalPath.variant = variant;
473 if (variant == LayerHierarchy::Variant::Mirror) {
Vishnu Nair6f878312023-09-08 11:05:01 -0700474 traversalPath.mirrorRootIds.emplace_back(mParentPath.id);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000475 } else if (variant == LayerHierarchy::Variant::Relative) {
Vishnu Nair04f89692022-11-16 23:21:05 +0000476 if (std::find(traversalPath.relativeRootIds.begin(), traversalPath.relativeRootIds.end(),
477 layerId) != traversalPath.relativeRootIds.end()) {
478 traversalPath.invalidRelativeRootId = layerId;
479 }
480 traversalPath.relativeRootIds.emplace_back(layerId);
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000481 } else if (variant == LayerHierarchy::Variant::Detached) {
482 traversalPath.detached = true;
Vishnu Nair04f89692022-11-16 23:21:05 +0000483 }
484}
485LayerHierarchy::ScopedAddToTraversalPath::~ScopedAddToTraversalPath() {
486 // Reset the traversal id to its original parent state using the state that was saved in
487 // the constructor.
488 if (mTraversalPath.variant == LayerHierarchy::Variant::Mirror) {
Vishnu Nair6f878312023-09-08 11:05:01 -0700489 mTraversalPath.mirrorRootIds.pop_back();
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000490 } else if (mTraversalPath.variant == LayerHierarchy::Variant::Relative) {
Vishnu Nair04f89692022-11-16 23:21:05 +0000491 mTraversalPath.relativeRootIds.pop_back();
492 }
493 if (mTraversalPath.invalidRelativeRootId == mTraversalPath.id) {
494 mTraversalPath.invalidRelativeRootId = UNASSIGNED_LAYER_ID;
495 }
Vishnu Nair80a5a702023-02-11 01:21:51 +0000496 mTraversalPath.id = mParentPath.id;
497 mTraversalPath.variant = mParentPath.variant;
498 mTraversalPath.detached = mParentPath.detached;
Vishnu Nair04f89692022-11-16 23:21:05 +0000499}
500
501} // namespace android::surfaceflinger::frontend