blob: 4b0618e5aa3fd6fc9d6b249b57c41acc113e3c5e [file] [log] [blame]
Vishnu Nairdc4d31b2022-11-17 03:20:58 +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
19#undef LOG_TAG
Vishnu Naira02943f2023-06-03 13:44:46 -070020#define LOG_TAG "SurfaceFlinger"
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000021
22#include "LayerLifecycleManager.h"
Vishnu Nair1391de22023-03-05 19:56:14 -080023#include "Client.h" // temporarily needed for LayerCreationArgs
Vishnu Nair80a5a702023-02-11 01:21:51 +000024#include "LayerLog.h"
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000025#include "SwapErase.h"
26
27namespace android::surfaceflinger::frontend {
28
29using namespace ftl::flag_operators;
30
Vishnu Nair52c4f252023-06-14 15:25:12 -070031namespace {
32// Returns true if the layer is root of a display and can be mirrored by mirroringLayer
33bool canMirrorRootLayer(RequestedLayerState& mirroringLayer, RequestedLayerState& rootLayer) {
34 return rootLayer.isRoot() && rootLayer.layerStack == mirroringLayer.layerStackToMirror &&
35 rootLayer.id != mirroringLayer.id;
36}
37} // namespace
38
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000039void LayerLifecycleManager::addLayers(std::vector<std::unique_ptr<RequestedLayerState>> newLayers) {
40 if (newLayers.empty()) {
41 return;
42 }
43
44 mGlobalChanges |= RequestedLayerState::Changes::Hierarchy;
45 for (auto& newLayer : newLayers) {
46 RequestedLayerState& layer = *newLayer.get();
47 auto [it, inserted] = mIdToLayer.try_emplace(layer.id, References{.owner = layer});
Vishnu Nair606d9d02023-08-19 14:20:18 -070048 LLOG_ALWAYS_FATAL_WITH_TRACE_IF(!inserted,
49 "Duplicate layer id found. New layer: %s Existing layer: "
50 "%s",
51 layer.getDebugString().c_str(),
52 it->second.owner.getDebugString().c_str());
Vishnu Nair150065b2023-04-17 19:14:11 -070053 mAddedLayers.push_back(newLayer.get());
Vishnu Naira02943f2023-06-03 13:44:46 -070054 mChangedLayers.push_back(newLayer.get());
Vishnu Nair04f89692022-11-16 23:21:05 +000055 layer.parentId = linkLayer(layer.parentId, layer.id);
56 layer.relativeParentId = linkLayer(layer.relativeParentId, layer.id);
Vishnu Naira9c43762023-01-27 19:10:25 +000057 if (layer.layerStackToMirror != ui::INVALID_LAYER_STACK) {
Vishnu Nair52c4f252023-06-14 15:25:12 -070058 // Set mirror layer's default layer stack to -1 so it doesn't end up rendered on a
59 // display accidentally.
60 layer.layerStack = ui::INVALID_LAYER_STACK;
61
Vishnu Naira9c43762023-01-27 19:10:25 +000062 // if this layer is mirroring a display, then walk though all the existing root layers
63 // for the layer stack and add them as children to be mirrored.
64 mDisplayMirroringLayers.emplace_back(layer.id);
65 for (auto& rootLayer : mLayers) {
Vishnu Nair52c4f252023-06-14 15:25:12 -070066 if (canMirrorRootLayer(layer, *rootLayer)) {
Vishnu Naira9c43762023-01-27 19:10:25 +000067 layer.mirrorIds.emplace_back(rootLayer->id);
68 linkLayer(rootLayer->id, layer.id);
69 }
70 }
71 } else {
72 // Check if we are mirroring a single layer, and if so add it to the list of children
73 // to be mirrored.
74 layer.layerIdToMirror = linkLayer(layer.layerIdToMirror, layer.id);
Vishnu Nair491827d2024-04-29 23:43:26 +000075 if (!FlagManager::getInstance().detached_mirror()) {
76 if (layer.layerIdToMirror != UNASSIGNED_LAYER_ID) {
77 layer.mirrorIds.emplace_back(layer.layerIdToMirror);
78 }
Vishnu Naira9c43762023-01-27 19:10:25 +000079 }
80 }
Vishnu Nair04f89692022-11-16 23:21:05 +000081 layer.touchCropId = linkLayer(layer.touchCropId, layer.id);
Vishnu Naira9c43762023-01-27 19:10:25 +000082 if (layer.isRoot()) {
83 updateDisplayMirrorLayers(layer);
84 }
Vishnu Nair92990e22023-02-24 20:01:05 +000085 LLOGV(layer.id, "%s", layer.getDebugString().c_str());
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000086 mLayers.emplace_back(std::move(newLayer));
87 }
88}
89
Vishnu Nair606d9d02023-08-19 14:20:18 -070090void LayerLifecycleManager::onHandlesDestroyed(
91 const std::vector<std::pair<uint32_t, std::string /* debugName */>>& destroyedHandles,
92 bool ignoreUnknownHandles) {
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000093 std::vector<uint32_t> layersToBeDestroyed;
Vishnu Nair606d9d02023-08-19 14:20:18 -070094 for (const auto& [layerId, name] : destroyedHandles) {
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000095 auto it = mIdToLayer.find(layerId);
96 if (it == mIdToLayer.end()) {
Vishnu Nair606d9d02023-08-19 14:20:18 -070097 LLOG_ALWAYS_FATAL_WITH_TRACE_IF(!ignoreUnknownHandles, "%s Layerid not found %s[%d]",
98 __func__, name.c_str(), layerId);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +000099 continue;
100 }
101 RequestedLayerState& layer = it->second.owner;
Vishnu Nair92990e22023-02-24 20:01:05 +0000102 LLOGV(layer.id, "%s", layer.getDebugString().c_str());
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000103 layer.handleAlive = false;
104 if (!layer.canBeDestroyed()) {
105 continue;
106 }
107 layer.changes |= RequestedLayerState::Changes::Destroyed;
108 layersToBeDestroyed.emplace_back(layerId);
109 }
110
111 if (layersToBeDestroyed.empty()) {
112 return;
113 }
114
115 mGlobalChanges |= RequestedLayerState::Changes::Hierarchy;
116 for (size_t i = 0; i < layersToBeDestroyed.size(); i++) {
117 uint32_t layerId = layersToBeDestroyed[i];
118 auto it = mIdToLayer.find(layerId);
Vishnu Nair606d9d02023-08-19 14:20:18 -0700119 LLOG_ALWAYS_FATAL_WITH_TRACE_IF(it == mIdToLayer.end(), "%s Layer with id %d not found",
120 __func__, layerId);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000121
122 RequestedLayerState& layer = it->second.owner;
123
Vishnu Nair04f89692022-11-16 23:21:05 +0000124 layer.parentId = unlinkLayer(layer.parentId, layer.id);
125 layer.relativeParentId = unlinkLayer(layer.relativeParentId, layer.id);
Vishnu Naira9c43762023-01-27 19:10:25 +0000126 if (layer.layerStackToMirror != ui::INVALID_LAYER_STACK) {
127 layer.mirrorIds = unlinkLayers(layer.mirrorIds, layer.id);
128 swapErase(mDisplayMirroringLayers, layer.id);
129 } else {
130 layer.layerIdToMirror = unlinkLayer(layer.layerIdToMirror, layer.id);
131 layer.mirrorIds.clear();
132 }
133
Vishnu Nair04f89692022-11-16 23:21:05 +0000134 layer.touchCropId = unlinkLayer(layer.touchCropId, layer.id);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000135
136 auto& references = it->second.references;
137 for (uint32_t linkedLayerId : references) {
138 RequestedLayerState* linkedLayer = getLayerFromId(linkedLayerId);
Vishnu Nair606d9d02023-08-19 14:20:18 -0700139 LLOG_ALWAYS_FATAL_WITH_TRACE_IF(!linkedLayer,
140 "%s Layerid reference %d not found for %d", __func__,
141 linkedLayerId, layer.id);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000142 if (linkedLayer->parentId == layer.id) {
143 linkedLayer->parentId = UNASSIGNED_LAYER_ID;
144 if (linkedLayer->canBeDestroyed()) {
145 linkedLayer->changes |= RequestedLayerState::Changes::Destroyed;
146 layersToBeDestroyed.emplace_back(linkedLayer->id);
147 }
148 }
149 if (linkedLayer->relativeParentId == layer.id) {
150 linkedLayer->relativeParentId = UNASSIGNED_LAYER_ID;
151 }
Vishnu Naira9c43762023-01-27 19:10:25 +0000152 if (swapErase(linkedLayer->mirrorIds, layer.id)) {
153 linkedLayer->changes |= RequestedLayerState::Changes::Mirror;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000154 }
155 if (linkedLayer->touchCropId == layer.id) {
156 linkedLayer->touchCropId = UNASSIGNED_LAYER_ID;
157 }
158 }
159 mIdToLayer.erase(it);
160 }
161
162 auto it = mLayers.begin();
163 while (it != mLayers.end()) {
164 RequestedLayerState* layer = it->get();
165 if (layer->changes.test(RequestedLayerState::Changes::Destroyed)) {
Vishnu Nair92990e22023-02-24 20:01:05 +0000166 LLOGV(layer->id, "destroyed %s", layer->getDebugStringShort().c_str());
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000167 std::iter_swap(it, mLayers.end() - 1);
168 mDestroyedLayers.emplace_back(std::move(mLayers.back()));
Vishnu Nairaa548fd2022-11-23 18:50:09 +0000169 if (it == mLayers.end() - 1) {
170 it = mLayers.erase(mLayers.end() - 1);
171 } else {
172 mLayers.erase(mLayers.end() - 1);
173 }
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000174 } else {
175 it++;
176 }
177 }
178}
179
Vishnu Nair20e1f962023-03-29 15:58:34 -0700180void LayerLifecycleManager::applyTransactions(const std::vector<TransactionState>& transactions,
181 bool ignoreUnknownLayers) {
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000182 for (const auto& transaction : transactions) {
183 for (const auto& resolvedComposerState : transaction.states) {
184 const auto& clientState = resolvedComposerState.state;
Vishnu Nair1391de22023-03-05 19:56:14 -0800185 uint32_t layerId = resolvedComposerState.layerId;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000186 if (layerId == UNASSIGNED_LAYER_ID) {
187 ALOGW("%s Handle %p is not valid", __func__, clientState.surface.get());
188 continue;
189 }
190
191 RequestedLayerState* layer = getLayerFromId(layerId);
192 if (layer == nullptr) {
Vishnu Nair606d9d02023-08-19 14:20:18 -0700193 LLOG_ALWAYS_FATAL_WITH_TRACE_IF(!ignoreUnknownLayers,
194 "%s Layer with layerid=%d not found", __func__,
195 layerId);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000196 continue;
197 }
198
Vishnu Nair606d9d02023-08-19 14:20:18 -0700199 LLOG_ALWAYS_FATAL_WITH_TRACE_IF(!layer->handleAlive,
200 "%s Layer's with layerid=%d) is not alive. Possible "
201 "out of "
202 "order LayerLifecycleManager updates",
203 __func__, layerId);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000204
Vishnu Naira02943f2023-06-03 13:44:46 -0700205 if (layer->changes.get() == 0) {
206 mChangedLayers.push_back(layer);
207 }
208
Vishnu Nairef68d6d2023-02-28 06:18:27 +0000209 if (transaction.flags & ISurfaceComposer::eAnimation) {
210 layer->changes |= RequestedLayerState::Changes::Animation;
211 }
212
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000213 uint32_t oldParentId = layer->parentId;
214 uint32_t oldRelativeParentId = layer->relativeParentId;
215 uint32_t oldTouchCropId = layer->touchCropId;
216 layer->merge(resolvedComposerState);
217
218 if (layer->what & layer_state_t::eBackgroundColorChanged) {
Vishnu Naird47bcee2023-02-24 18:08:51 +0000219 if (layer->bgColorLayerId == UNASSIGNED_LAYER_ID && layer->bgColor.a != 0) {
Vishnu Naire4af0952023-05-01 09:11:33 -0700220 LayerCreationArgs
221 backgroundLayerArgs(LayerCreationArgs::getInternalLayerId(
222 LayerCreationArgs::sInternalSequence++),
223 /*internalLayer=*/true);
Vishnu Nair1391de22023-03-05 19:56:14 -0800224 backgroundLayerArgs.parentId = layer->id;
225 backgroundLayerArgs.name = layer->name + "BackgroundColorLayer";
226 backgroundLayerArgs.flags = ISurfaceComposerClient::eFXSurfaceEffect;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000227 std::vector<std::unique_ptr<RequestedLayerState>> newLayers;
228 newLayers.emplace_back(
229 std::make_unique<RequestedLayerState>(backgroundLayerArgs));
230 RequestedLayerState* backgroundLayer = newLayers.back().get();
Vishnu Naird47bcee2023-02-24 18:08:51 +0000231 backgroundLayer->bgColorLayer = true;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000232 backgroundLayer->handleAlive = false;
233 backgroundLayer->parentId = layer->id;
234 backgroundLayer->z = std::numeric_limits<int32_t>::min();
Vishnu Naird47bcee2023-02-24 18:08:51 +0000235 backgroundLayer->color = layer->bgColor;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000236 backgroundLayer->dataspace = layer->bgColorDataspace;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000237 layer->bgColorLayerId = backgroundLayer->id;
238 addLayers({std::move(newLayers)});
Vishnu Naird47bcee2023-02-24 18:08:51 +0000239 } else if (layer->bgColorLayerId != UNASSIGNED_LAYER_ID && layer->bgColor.a == 0) {
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000240 RequestedLayerState* bgColorLayer = getLayerFromId(layer->bgColorLayerId);
Vishnu Naird47bcee2023-02-24 18:08:51 +0000241 layer->bgColorLayerId = UNASSIGNED_LAYER_ID;
242 bgColorLayer->parentId = unlinkLayer(bgColorLayer->parentId, bgColorLayer->id);
Vishnu Nair606d9d02023-08-19 14:20:18 -0700243 onHandlesDestroyed({{bgColorLayer->id, bgColorLayer->debugName}});
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000244 } else if (layer->bgColorLayerId != UNASSIGNED_LAYER_ID) {
245 RequestedLayerState* bgColorLayer = getLayerFromId(layer->bgColorLayerId);
Vishnu Naird47bcee2023-02-24 18:08:51 +0000246 bgColorLayer->color = layer->bgColor;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000247 bgColorLayer->dataspace = layer->bgColorDataspace;
Vishnu Naird47bcee2023-02-24 18:08:51 +0000248 bgColorLayer->what |= layer_state_t::eColorChanged |
249 layer_state_t::eDataspaceChanged | layer_state_t::eAlphaChanged;
250 bgColorLayer->changes |= RequestedLayerState::Changes::Content;
Vishnu Naira02943f2023-06-03 13:44:46 -0700251 mChangedLayers.push_back(bgColorLayer);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000252 mGlobalChanges |= RequestedLayerState::Changes::Content;
253 }
254 }
255
256 if (oldParentId != layer->parentId) {
257 unlinkLayer(oldParentId, layer->id);
Vishnu Nair04f89692022-11-16 23:21:05 +0000258 layer->parentId = linkLayer(layer->parentId, layer->id);
Vishnu Naira9c43762023-01-27 19:10:25 +0000259 if (oldParentId == UNASSIGNED_LAYER_ID) {
260 updateDisplayMirrorLayers(*layer);
261 }
262 }
263 if (layer->what & layer_state_t::eLayerStackChanged && layer->isRoot()) {
264 updateDisplayMirrorLayers(*layer);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000265 }
266 if (oldRelativeParentId != layer->relativeParentId) {
267 unlinkLayer(oldRelativeParentId, layer->id);
Vishnu Nair04f89692022-11-16 23:21:05 +0000268 layer->relativeParentId = linkLayer(layer->relativeParentId, layer->id);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000269 }
270 if (oldTouchCropId != layer->touchCropId) {
271 unlinkLayer(oldTouchCropId, layer->id);
Vishnu Nair04f89692022-11-16 23:21:05 +0000272 layer->touchCropId = linkLayer(layer->touchCropId, layer->id);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000273 }
274
Vishnu Nair8fc721b2022-12-22 20:06:32 +0000275 mGlobalChanges |= layer->changes;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000276 }
277 }
278}
279
280void LayerLifecycleManager::commitChanges() {
Vishnu Nair150065b2023-04-17 19:14:11 -0700281 for (auto layer : mAddedLayers) {
282 for (auto& listener : mListeners) {
283 listener->onLayerAdded(*layer);
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000284 }
Vishnu Nair150065b2023-04-17 19:14:11 -0700285 }
286 mAddedLayers.clear();
287
288 for (auto& layer : mLayers) {
Vishnu Naird47bcee2023-02-24 18:08:51 +0000289 layer->clearChanges();
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000290 }
291
292 for (auto& destroyedLayer : mDestroyedLayers) {
Vishnu Nair150065b2023-04-17 19:14:11 -0700293 for (auto& listener : mListeners) {
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000294 listener->onLayerDestroyed(*destroyedLayer);
295 }
296 }
297 mDestroyedLayers.clear();
Vishnu Naira02943f2023-06-03 13:44:46 -0700298 mChangedLayers.clear();
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000299 mGlobalChanges.clear();
300}
301
302void LayerLifecycleManager::addLifecycleListener(std::shared_ptr<ILifecycleListener> listener) {
303 mListeners.emplace_back(std::move(listener));
304}
305
306void LayerLifecycleManager::removeLifecycleListener(std::shared_ptr<ILifecycleListener> listener) {
307 swapErase(mListeners, listener);
308}
309
310const std::vector<std::unique_ptr<RequestedLayerState>>& LayerLifecycleManager::getLayers() const {
311 return mLayers;
312}
313
314const std::vector<std::unique_ptr<RequestedLayerState>>& LayerLifecycleManager::getDestroyedLayers()
315 const {
316 return mDestroyedLayers;
317}
318
Vishnu Naira02943f2023-06-03 13:44:46 -0700319const std::vector<RequestedLayerState*>& LayerLifecycleManager::getChangedLayers() const {
320 return mChangedLayers;
321}
322
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000323const ftl::Flags<RequestedLayerState::Changes> LayerLifecycleManager::getGlobalChanges() const {
324 return mGlobalChanges;
325}
326
Vishnu Naira02943f2023-06-03 13:44:46 -0700327const RequestedLayerState* LayerLifecycleManager::getLayerFromId(uint32_t id) const {
328 if (id == UNASSIGNED_LAYER_ID) {
329 return nullptr;
330 }
331 auto it = mIdToLayer.find(id);
332 if (it == mIdToLayer.end()) {
333 return nullptr;
334 }
335 return &it->second.owner;
336}
337
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000338RequestedLayerState* LayerLifecycleManager::getLayerFromId(uint32_t id) {
339 if (id == UNASSIGNED_LAYER_ID) {
340 return nullptr;
341 }
342 auto it = mIdToLayer.find(id);
343 if (it == mIdToLayer.end()) {
344 return nullptr;
345 }
346 return &it->second.owner;
347}
348
349std::vector<uint32_t>* LayerLifecycleManager::getLinkedLayersFromId(uint32_t id) {
350 if (id == UNASSIGNED_LAYER_ID) {
351 return nullptr;
352 }
353 auto it = mIdToLayer.find(id);
354 if (it == mIdToLayer.end()) {
355 return nullptr;
356 }
357 return &it->second.references;
358}
359
Vishnu Nair04f89692022-11-16 23:21:05 +0000360uint32_t LayerLifecycleManager::linkLayer(uint32_t layerId, uint32_t layerToLink) {
361 if (layerId == UNASSIGNED_LAYER_ID) {
362 return UNASSIGNED_LAYER_ID;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000363 }
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000364
365 std::vector<uint32_t>* linkedLayers = getLinkedLayersFromId(layerId);
366 if (!linkedLayers) {
Vishnu Nair04f89692022-11-16 23:21:05 +0000367 ALOGV("Could not find layer id %d to link %d. Parent is probably destroyed", layerId,
368 layerToLink);
369 return UNASSIGNED_LAYER_ID;
370 }
371 linkedLayers->emplace_back(layerToLink);
372 return layerId;
373}
374
375uint32_t LayerLifecycleManager::unlinkLayer(uint32_t layerId, uint32_t linkedLayer) {
376 std::vector<uint32_t>* linkedLayers = getLinkedLayersFromId(layerId);
377 if (!linkedLayers) {
378 return UNASSIGNED_LAYER_ID;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000379 }
380 swapErase(*linkedLayers, linkedLayer);
Vishnu Nair04f89692022-11-16 23:21:05 +0000381 return UNASSIGNED_LAYER_ID;
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000382}
383
Vishnu Naira9c43762023-01-27 19:10:25 +0000384std::vector<uint32_t> LayerLifecycleManager::unlinkLayers(const std::vector<uint32_t>& layerIds,
385 uint32_t linkedLayer) {
386 for (uint32_t layerId : layerIds) {
387 unlinkLayer(layerId, linkedLayer);
388 }
389 return {};
390}
391
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000392std::string LayerLifecycleManager::References::getDebugString() const {
393 std::string debugInfo = owner.name + "[" + std::to_string(owner.id) + "] refs:";
394 std::for_each(references.begin(), references.end(),
395 [&debugInfo = debugInfo](const uint32_t& reference) mutable {
396 debugInfo += std::to_string(reference) + ",";
397 });
398 return debugInfo;
399}
400
Vishnu Nair04f89692022-11-16 23:21:05 +0000401void LayerLifecycleManager::fixRelativeZLoop(uint32_t relativeRootId) {
402 auto it = mIdToLayer.find(relativeRootId);
403 if (it == mIdToLayer.end()) {
404 return;
405 }
406 RequestedLayerState& layer = it->second.owner;
407 layer.relativeParentId = unlinkLayer(layer.relativeParentId, layer.id);
408 layer.changes |=
409 RequestedLayerState::Changes::Hierarchy | RequestedLayerState::Changes::RelativeParent;
410 mGlobalChanges |= RequestedLayerState::Changes::Hierarchy;
411}
412
Vishnu Naira9c43762023-01-27 19:10:25 +0000413// Some layers mirror the entire display stack. Since we don't have a single root layer per display
414// we have to track all these layers and update what they mirror when the list of root layers
415// on a display changes. This function walks through the list of display mirroring layers
416// and updates its list of layers that its mirroring. This function should be called when a new
417// root layer is added, removed or moved to another display.
418void LayerLifecycleManager::updateDisplayMirrorLayers(RequestedLayerState& rootLayer) {
Vishnu Nair52c4f252023-06-14 15:25:12 -0700419 for (uint32_t mirroringLayerId : mDisplayMirroringLayers) {
420 RequestedLayerState* mirrorLayer = getLayerFromId(mirroringLayerId);
421 bool canBeMirrored = canMirrorRootLayer(*mirrorLayer, rootLayer);
Vishnu Naira9c43762023-01-27 19:10:25 +0000422 bool currentlyMirrored =
423 std::find(mirrorLayer->mirrorIds.begin(), mirrorLayer->mirrorIds.end(),
424 rootLayer.id) != mirrorLayer->mirrorIds.end();
425
426 if (canBeMirrored && !currentlyMirrored) {
427 mirrorLayer->mirrorIds.emplace_back(rootLayer.id);
428 linkLayer(rootLayer.id, mirrorLayer->id);
429 mirrorLayer->changes |= RequestedLayerState::Changes::Mirror;
430 } else if (!canBeMirrored && currentlyMirrored) {
431 swapErase(mirrorLayer->mirrorIds, rootLayer.id);
432 unlinkLayer(rootLayer.id, mirrorLayer->id);
433 mirrorLayer->changes |= RequestedLayerState::Changes::Mirror;
434 }
435 }
436}
437
Chavi Weingarten4aa22af2023-11-17 19:37:07 +0000438bool LayerLifecycleManager::isLayerSecure(uint32_t layerId) const {
439 if (layerId == UNASSIGNED_LAYER_ID) {
440 return false;
441 }
442
443 if (getLayerFromId(layerId)->flags & layer_state_t::eLayerSecure) {
444 return true;
445 }
446 return isLayerSecure(getLayerFromId(layerId)->parentId);
447}
448
Vishnu Nairdc4d31b2022-11-17 03:20:58 +0000449} // namespace android::surfaceflinger::frontend