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 #include <gmock/gmock.h>
18 #include <gtest/gtest.h>
19 
20 #include <gui/fake/BufferData.h>
21 #include <renderengine/mock/FakeExternalTexture.h>
22 #include <ui/ShadowSettings.h>
23 
24 #include "Client.h" // temporarily needed for LayerCreationArgs
25 #include "FrontEnd/LayerCreationArgs.h"
26 #include "FrontEnd/LayerHierarchy.h"
27 #include "FrontEnd/LayerLifecycleManager.h"
28 #include "FrontEnd/LayerSnapshotBuilder.h"
29 
30 namespace android::surfaceflinger::frontend {
31 
32 class LayerHierarchyTestBase : public testing::Test {
33 protected:
LayerHierarchyTestBase()34     LayerHierarchyTestBase() {
35         // tree with 3 levels of children
36         // ROOT
37         // ├── 1
38         // │   ├── 11
39         // │   │   └── 111
40         // │   ├── 12
41         // │   │   ├── 121
42         // │   │   └── 122
43         // │   │       └── 1221
44         // │   └── 13
45         // └── 2
46 
47         createRootLayer(1);
48         createRootLayer(2);
49         createLayer(11, 1);
50         createLayer(12, 1);
51         createLayer(13, 1);
52         createLayer(111, 11);
53         createLayer(121, 12);
54         createLayer(122, 12);
55         createLayer(1221, 122);
56     }
57 
createArgs(uint32_t id,bool canBeRoot,uint32_t parentId,uint32_t layerIdToMirror)58     LayerCreationArgs createArgs(uint32_t id, bool canBeRoot, uint32_t parentId,
59                                  uint32_t layerIdToMirror) {
60         LayerCreationArgs args(std::make_optional(id));
61         args.name = "testlayer";
62         args.addToRoot = canBeRoot;
63         args.parentId = parentId;
64         args.layerIdToMirror = layerIdToMirror;
65         return args;
66     }
67 
createDisplayMirrorArgs(uint32_t id,ui::LayerStack layerStackToMirror)68     LayerCreationArgs createDisplayMirrorArgs(uint32_t id, ui::LayerStack layerStackToMirror) {
69         LayerCreationArgs args(std::make_optional(id));
70         args.name = "testlayer";
71         args.addToRoot = true;
72         args.layerStackToMirror = layerStackToMirror;
73         return args;
74     }
75 
getTraversalPath(const LayerHierarchy & hierarchy)76     std::vector<uint32_t> getTraversalPath(const LayerHierarchy& hierarchy) const {
77         std::vector<uint32_t> layerIds;
78         hierarchy.traverse([&layerIds = layerIds](const LayerHierarchy& hierarchy,
79                                                   const LayerHierarchy::TraversalPath&) -> bool {
80             layerIds.emplace_back(hierarchy.getLayer()->id);
81             return true;
82         });
83         return layerIds;
84     }
85 
getTraversalPathInZOrder(const LayerHierarchy & hierarchy)86     std::vector<uint32_t> getTraversalPathInZOrder(const LayerHierarchy& hierarchy) const {
87         std::vector<uint32_t> layerIds;
88         hierarchy.traverseInZOrder(
89                 [&layerIds = layerIds](const LayerHierarchy& hierarchy,
90                                        const LayerHierarchy::TraversalPath&) -> bool {
91                     layerIds.emplace_back(hierarchy.getLayer()->id);
92                     return true;
93                 });
94         return layerIds;
95     }
96 
createRootLayer(uint32_t id)97     virtual void createRootLayer(uint32_t id) {
98         std::vector<std::unique_ptr<RequestedLayerState>> layers;
99         layers.emplace_back(std::make_unique<RequestedLayerState>(
100                 createArgs(/*id=*/id, /*canBeRoot=*/true, /*parent=*/UNASSIGNED_LAYER_ID,
101                            /*mirror=*/UNASSIGNED_LAYER_ID)));
102         mLifecycleManager.addLayers(std::move(layers));
103     }
104 
createDisplayMirrorLayer(uint32_t id,ui::LayerStack layerStack)105     void createDisplayMirrorLayer(uint32_t id, ui::LayerStack layerStack) {
106         std::vector<std::unique_ptr<RequestedLayerState>> layers;
107         layers.emplace_back(std::make_unique<RequestedLayerState>(
108                 createDisplayMirrorArgs(/*id=*/id, layerStack)));
109         mLifecycleManager.addLayers(std::move(layers));
110     }
111 
createLayer(uint32_t id,uint32_t parentId)112     virtual void createLayer(uint32_t id, uint32_t parentId) {
113         std::vector<std::unique_ptr<RequestedLayerState>> layers;
114         layers.emplace_back(std::make_unique<RequestedLayerState>(
115                 createArgs(/*id=*/id, /*canBeRoot=*/false, /*parent=*/parentId,
116                            /*mirror=*/UNASSIGNED_LAYER_ID)));
117         mLifecycleManager.addLayers(std::move(layers));
118     }
119 
reparentLayerTransaction(uint32_t id,uint32_t newParentId)120     std::vector<TransactionState> reparentLayerTransaction(uint32_t id, uint32_t newParentId) {
121         std::vector<TransactionState> transactions;
122         transactions.emplace_back();
123         transactions.back().states.push_back({});
124         transactions.back().states.front().parentId = newParentId;
125         transactions.back().states.front().state.what = layer_state_t::eReparent;
126         transactions.back().states.front().relativeParentId = UNASSIGNED_LAYER_ID;
127         transactions.back().states.front().layerId = id;
128         return transactions;
129     }
130 
reparentLayer(uint32_t id,uint32_t newParentId)131     void reparentLayer(uint32_t id, uint32_t newParentId) {
132         mLifecycleManager.applyTransactions(reparentLayerTransaction(id, newParentId));
133     }
134 
relativeLayerTransaction(uint32_t id,uint32_t relativeParentId)135     std::vector<TransactionState> relativeLayerTransaction(uint32_t id, uint32_t relativeParentId) {
136         std::vector<TransactionState> transactions;
137         transactions.emplace_back();
138         transactions.back().states.push_back({});
139         transactions.back().states.front().relativeParentId = relativeParentId;
140         transactions.back().states.front().state.what = layer_state_t::eRelativeLayerChanged;
141         transactions.back().states.front().layerId = id;
142         return transactions;
143     }
144 
reparentRelativeLayer(uint32_t id,uint32_t relativeParentId)145     void reparentRelativeLayer(uint32_t id, uint32_t relativeParentId) {
146         mLifecycleManager.applyTransactions(relativeLayerTransaction(id, relativeParentId));
147     }
148 
removeRelativeZ(uint32_t id)149     void removeRelativeZ(uint32_t id) {
150         std::vector<TransactionState> transactions;
151         transactions.emplace_back();
152         transactions.back().states.push_back({});
153         transactions.back().states.front().state.what = layer_state_t::eLayerChanged;
154         transactions.back().states.front().layerId = id;
155         mLifecycleManager.applyTransactions(transactions);
156     }
157 
setPosition(uint32_t id,float x,float y)158     void setPosition(uint32_t id, float x, float y) {
159         std::vector<TransactionState> transactions;
160         transactions.emplace_back();
161         transactions.back().states.push_back({});
162         transactions.back().states.front().state.what = layer_state_t::ePositionChanged;
163         transactions.back().states.front().state.x = x;
164         transactions.back().states.front().state.y = y;
165         transactions.back().states.front().layerId = id;
166         mLifecycleManager.applyTransactions(transactions);
167     }
168 
mirrorLayer(uint32_t id,uint32_t parentId,uint32_t layerIdToMirror)169     virtual void mirrorLayer(uint32_t id, uint32_t parentId, uint32_t layerIdToMirror) {
170         std::vector<std::unique_ptr<RequestedLayerState>> layers;
171         layers.emplace_back(std::make_unique<RequestedLayerState>(
172                 createArgs(/*id=*/id, /*canBeRoot=*/false, /*parent=*/parentId,
173                            /*mirror=*/layerIdToMirror)));
174         mLifecycleManager.addLayers(std::move(layers));
175     }
176 
updateBackgroundColor(uint32_t id,half alpha)177     void updateBackgroundColor(uint32_t id, half alpha) {
178         std::vector<TransactionState> transactions;
179         transactions.emplace_back();
180         transactions.back().states.push_back({});
181         transactions.back().states.front().state.what = layer_state_t::eBackgroundColorChanged;
182         transactions.back().states.front().state.bgColor.a = alpha;
183         transactions.back().states.front().layerId = id;
184         mLifecycleManager.applyTransactions(transactions);
185     }
186 
destroyLayerHandle(uint32_t id)187     void destroyLayerHandle(uint32_t id) { mLifecycleManager.onHandlesDestroyed({{id, "test"}}); }
188 
updateAndVerify(LayerHierarchyBuilder & hierarchyBuilder)189     void updateAndVerify(LayerHierarchyBuilder& hierarchyBuilder) {
190         hierarchyBuilder.update(mLifecycleManager);
191         mLifecycleManager.commitChanges();
192 
193         // rebuild layer hierarchy from scratch and verify that it matches the updated state.
194         LayerHierarchyBuilder newBuilder;
195         newBuilder.update(mLifecycleManager);
196         EXPECT_EQ(getTraversalPath(hierarchyBuilder.getHierarchy()),
197                   getTraversalPath(newBuilder.getHierarchy()));
198         EXPECT_EQ(getTraversalPathInZOrder(hierarchyBuilder.getHierarchy()),
199                   getTraversalPathInZOrder(newBuilder.getHierarchy()));
200         EXPECT_FALSE(
201                 mLifecycleManager.getGlobalChanges().test(RequestedLayerState::Changes::Hierarchy));
202     }
203 
setZTransaction(uint32_t id,int32_t z)204     std::vector<TransactionState> setZTransaction(uint32_t id, int32_t z) {
205         std::vector<TransactionState> transactions;
206         transactions.emplace_back();
207         transactions.back().states.push_back({});
208 
209         transactions.back().states.front().state.what = layer_state_t::eLayerChanged;
210         transactions.back().states.front().layerId = id;
211         transactions.back().states.front().state.z = z;
212         return transactions;
213     }
214 
setZ(uint32_t id,int32_t z)215     void setZ(uint32_t id, int32_t z) {
216         mLifecycleManager.applyTransactions(setZTransaction(id, z));
217     }
218 
setCrop(uint32_t id,const Rect & crop)219     void setCrop(uint32_t id, const Rect& crop) {
220         std::vector<TransactionState> transactions;
221         transactions.emplace_back();
222         transactions.back().states.push_back({});
223 
224         transactions.back().states.front().state.what = layer_state_t::eCropChanged;
225         transactions.back().states.front().layerId = id;
226         transactions.back().states.front().state.crop = crop;
227         mLifecycleManager.applyTransactions(transactions);
228     }
229 
setFlags(uint32_t id,uint32_t mask,uint32_t flags)230     void setFlags(uint32_t id, uint32_t mask, uint32_t flags) {
231         std::vector<TransactionState> transactions;
232         transactions.emplace_back();
233         transactions.back().states.push_back({});
234 
235         transactions.back().states.front().state.what = layer_state_t::eFlagsChanged;
236         transactions.back().states.front().state.flags = flags;
237         transactions.back().states.front().state.mask = mask;
238         transactions.back().states.front().layerId = id;
239         mLifecycleManager.applyTransactions(transactions);
240     }
241 
setAlpha(uint32_t id,float alpha)242     void setAlpha(uint32_t id, float alpha) {
243         std::vector<TransactionState> transactions;
244         transactions.emplace_back();
245         transactions.back().states.push_back({});
246 
247         transactions.back().states.front().state.what = layer_state_t::eAlphaChanged;
248         transactions.back().states.front().layerId = id;
249         transactions.back().states.front().state.color.a = static_cast<half>(alpha);
250         mLifecycleManager.applyTransactions(transactions);
251     }
252 
hideLayer(uint32_t id)253     void hideLayer(uint32_t id) {
254         setFlags(id, layer_state_t::eLayerHidden, layer_state_t::eLayerHidden);
255     }
256 
showLayer(uint32_t id)257     void showLayer(uint32_t id) { setFlags(id, layer_state_t::eLayerHidden, 0); }
258 
259     void setColor(uint32_t id, half3 rgb = half3(1._hf, 1._hf, 1._hf)) {
260         std::vector<TransactionState> transactions;
261         transactions.emplace_back();
262         transactions.back().states.push_back({});
263         transactions.back().states.front().state.what = layer_state_t::eColorChanged;
264         transactions.back().states.front().state.color.rgb = rgb;
265         transactions.back().states.front().layerId = id;
266         mLifecycleManager.applyTransactions(transactions);
267     }
268 
setLayerStack(uint32_t id,int32_t layerStack)269     void setLayerStack(uint32_t id, int32_t layerStack) {
270         std::vector<TransactionState> transactions;
271         transactions.emplace_back();
272         transactions.back().states.push_back({});
273 
274         transactions.back().states.front().state.what = layer_state_t::eLayerStackChanged;
275         transactions.back().states.front().layerId = id;
276         transactions.back().states.front().state.layerStack = ui::LayerStack::fromValue(layerStack);
277         mLifecycleManager.applyTransactions(transactions);
278     }
279 
setTouchableRegion(uint32_t id,Region region)280     void setTouchableRegion(uint32_t id, Region region) {
281         std::vector<TransactionState> transactions;
282         transactions.emplace_back();
283         transactions.back().states.push_back({});
284 
285         transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged;
286         transactions.back().states.front().layerId = id;
287         transactions.back().states.front().state.windowInfoHandle =
288                 sp<gui::WindowInfoHandle>::make();
289         auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo();
290         inputInfo->touchableRegion = region;
291         inputInfo->token = sp<BBinder>::make();
292         mLifecycleManager.applyTransactions(transactions);
293     }
294 
setInputInfo(uint32_t id,std::function<void (gui::WindowInfo &)> configureInput)295     void setInputInfo(uint32_t id, std::function<void(gui::WindowInfo&)> configureInput) {
296         std::vector<TransactionState> transactions;
297         transactions.emplace_back();
298         transactions.back().states.push_back({});
299 
300         transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged;
301         transactions.back().states.front().layerId = id;
302         transactions.back().states.front().state.windowInfoHandle =
303                 sp<gui::WindowInfoHandle>::make();
304         auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo();
305         if (!inputInfo->token) {
306             inputInfo->token = sp<BBinder>::make();
307         }
308         configureInput(*inputInfo);
309 
310         mLifecycleManager.applyTransactions(transactions);
311     }
312 
setTouchableRegionCrop(uint32_t id,Region region,uint32_t touchCropId,bool replaceTouchableRegionWithCrop)313     void setTouchableRegionCrop(uint32_t id, Region region, uint32_t touchCropId,
314                                 bool replaceTouchableRegionWithCrop) {
315         std::vector<TransactionState> transactions;
316         transactions.emplace_back();
317         transactions.back().states.push_back({});
318 
319         transactions.back().states.front().state.what = layer_state_t::eInputInfoChanged;
320         transactions.back().states.front().layerId = id;
321         transactions.back().states.front().state.windowInfoHandle =
322                 sp<gui::WindowInfoHandle>::make();
323         auto inputInfo = transactions.back().states.front().state.windowInfoHandle->editInfo();
324         inputInfo->touchableRegion = region;
325         inputInfo->replaceTouchableRegionWithCrop = replaceTouchableRegionWithCrop;
326         transactions.back().states.front().touchCropId = touchCropId;
327 
328         inputInfo->token = sp<BBinder>::make();
329         mLifecycleManager.applyTransactions(transactions);
330     }
331 
setBackgroundBlurRadius(uint32_t id,uint32_t backgroundBlurRadius)332     void setBackgroundBlurRadius(uint32_t id, uint32_t backgroundBlurRadius) {
333         std::vector<TransactionState> transactions;
334         transactions.emplace_back();
335         transactions.back().states.push_back({});
336 
337         transactions.back().states.front().state.what = layer_state_t::eBackgroundBlurRadiusChanged;
338         transactions.back().states.front().layerId = id;
339         transactions.back().states.front().state.backgroundBlurRadius = backgroundBlurRadius;
340         mLifecycleManager.applyTransactions(transactions);
341     }
342 
setFrameRateSelectionPriority(uint32_t id,int32_t priority)343     void setFrameRateSelectionPriority(uint32_t id, int32_t priority) {
344         std::vector<TransactionState> transactions;
345         transactions.emplace_back();
346         transactions.back().states.push_back({});
347 
348         transactions.back().states.front().state.what = layer_state_t::eFrameRateSelectionPriority;
349         transactions.back().states.front().layerId = id;
350         transactions.back().states.front().state.frameRateSelectionPriority = priority;
351         mLifecycleManager.applyTransactions(transactions);
352     }
353 
setFrameRate(uint32_t id,float frameRate,int8_t compatibility,int8_t changeFrameRateStrategy)354     void setFrameRate(uint32_t id, float frameRate, int8_t compatibility,
355                       int8_t changeFrameRateStrategy) {
356         std::vector<TransactionState> transactions;
357         transactions.emplace_back();
358         transactions.back().states.push_back({});
359 
360         transactions.back().states.front().state.what = layer_state_t::eFrameRateChanged;
361         transactions.back().states.front().layerId = id;
362         transactions.back().states.front().state.frameRate = frameRate;
363         transactions.back().states.front().state.frameRateCompatibility = compatibility;
364         transactions.back().states.front().state.changeFrameRateStrategy = changeFrameRateStrategy;
365         mLifecycleManager.applyTransactions(transactions);
366     }
367 
setFrameRateCategory(uint32_t id,int8_t frameRateCategory)368     void setFrameRateCategory(uint32_t id, int8_t frameRateCategory) {
369         std::vector<TransactionState> transactions;
370         transactions.emplace_back();
371         transactions.back().states.push_back({});
372 
373         transactions.back().states.front().state.what = layer_state_t::eFrameRateCategoryChanged;
374         transactions.back().states.front().layerId = id;
375         transactions.back().states.front().state.frameRateCategory = frameRateCategory;
376         mLifecycleManager.applyTransactions(transactions);
377     }
378 
setFrameRateSelectionStrategy(uint32_t id,int8_t strategy)379     void setFrameRateSelectionStrategy(uint32_t id, int8_t strategy) {
380         std::vector<TransactionState> transactions;
381         transactions.emplace_back();
382         transactions.back().states.push_back({});
383 
384         transactions.back().states.front().state.what =
385                 layer_state_t::eFrameRateSelectionStrategyChanged;
386         transactions.back().states.front().layerId = id;
387         transactions.back().states.front().state.frameRateSelectionStrategy = strategy;
388         mLifecycleManager.applyTransactions(transactions);
389     }
390 
setDefaultFrameRateCompatibility(uint32_t id,int8_t defaultFrameRateCompatibility)391     void setDefaultFrameRateCompatibility(uint32_t id, int8_t defaultFrameRateCompatibility) {
392         std::vector<TransactionState> transactions;
393         transactions.emplace_back();
394         transactions.back().states.push_back({});
395 
396         transactions.back().states.front().state.what =
397                 layer_state_t::eDefaultFrameRateCompatibilityChanged;
398         transactions.back().states.front().layerId = id;
399         transactions.back().states.front().state.defaultFrameRateCompatibility =
400                 defaultFrameRateCompatibility;
401         mLifecycleManager.applyTransactions(transactions);
402     }
403 
setRoundedCorners(uint32_t id,float radius)404     void setRoundedCorners(uint32_t id, float radius) {
405         std::vector<TransactionState> transactions;
406         transactions.emplace_back();
407         transactions.back().states.push_back({});
408 
409         transactions.back().states.front().state.what = layer_state_t::eCornerRadiusChanged;
410         transactions.back().states.front().layerId = id;
411         transactions.back().states.front().state.cornerRadius = radius;
412         mLifecycleManager.applyTransactions(transactions);
413     }
414 
setBuffer(uint32_t id,std::shared_ptr<renderengine::ExternalTexture> texture)415     void setBuffer(uint32_t id, std::shared_ptr<renderengine::ExternalTexture> texture) {
416         std::vector<TransactionState> transactions;
417         transactions.emplace_back();
418         transactions.back().states.push_back({});
419 
420         transactions.back().states.front().state.what = layer_state_t::eBufferChanged;
421         transactions.back().states.front().layerId = id;
422         transactions.back().states.front().externalTexture = texture;
423         transactions.back().states.front().state.bufferData =
424                 std::make_shared<fake::BufferData>(texture->getId(), texture->getWidth(),
425                                                    texture->getHeight(), texture->getPixelFormat(),
426                                                    texture->getUsage());
427         mLifecycleManager.applyTransactions(transactions);
428     }
429 
setBuffer(uint32_t id)430     void setBuffer(uint32_t id) {
431         static uint64_t sBufferId = 1;
432         setBuffer(id,
433                   std::make_shared<renderengine::mock::
434                                            FakeExternalTexture>(1U /*width*/, 1U /*height*/,
435                                                                 sBufferId++,
436                                                                 HAL_PIXEL_FORMAT_RGBA_8888,
437                                                                 GRALLOC_USAGE_PROTECTED /*usage*/));
438     }
439 
setBufferCrop(uint32_t id,const Rect & bufferCrop)440     void setBufferCrop(uint32_t id, const Rect& bufferCrop) {
441         std::vector<TransactionState> transactions;
442         transactions.emplace_back();
443         transactions.back().states.push_back({});
444 
445         transactions.back().states.front().state.what = layer_state_t::eBufferCropChanged;
446         transactions.back().states.front().layerId = id;
447         transactions.back().states.front().state.bufferCrop = bufferCrop;
448         mLifecycleManager.applyTransactions(transactions);
449     }
450 
setDamageRegion(uint32_t id,const Region & damageRegion)451     void setDamageRegion(uint32_t id, const Region& damageRegion) {
452         std::vector<TransactionState> transactions;
453         transactions.emplace_back();
454         transactions.back().states.push_back({});
455 
456         transactions.back().states.front().state.what = layer_state_t::eSurfaceDamageRegionChanged;
457         transactions.back().states.front().layerId = id;
458         transactions.back().states.front().state.surfaceDamageRegion = damageRegion;
459         mLifecycleManager.applyTransactions(transactions);
460     }
461 
setDataspace(uint32_t id,ui::Dataspace dataspace)462     void setDataspace(uint32_t id, ui::Dataspace dataspace) {
463         std::vector<TransactionState> transactions;
464         transactions.emplace_back();
465         transactions.back().states.push_back({});
466 
467         transactions.back().states.front().state.what = layer_state_t::eDataspaceChanged;
468         transactions.back().states.front().layerId = id;
469         transactions.back().states.front().state.dataspace = dataspace;
470         mLifecycleManager.applyTransactions(transactions);
471     }
472 
setMatrix(uint32_t id,float dsdx,float dtdx,float dtdy,float dsdy)473     void setMatrix(uint32_t id, float dsdx, float dtdx, float dtdy, float dsdy) {
474         layer_state_t::matrix22_t matrix{dsdx, dtdx, dtdy, dsdy};
475 
476         std::vector<TransactionState> transactions;
477         transactions.emplace_back();
478         transactions.back().states.push_back({});
479 
480         transactions.back().states.front().state.what = layer_state_t::eMatrixChanged;
481         transactions.back().states.front().layerId = id;
482         transactions.back().states.front().state.matrix = matrix;
483         mLifecycleManager.applyTransactions(transactions);
484     }
485 
setShadowRadius(uint32_t id,float shadowRadius)486     void setShadowRadius(uint32_t id, float shadowRadius) {
487         std::vector<TransactionState> transactions;
488         transactions.emplace_back();
489         transactions.back().states.push_back({});
490 
491         transactions.back().states.front().state.what = layer_state_t::eShadowRadiusChanged;
492         transactions.back().states.front().layerId = id;
493         transactions.back().states.front().state.shadowRadius = shadowRadius;
494         mLifecycleManager.applyTransactions(transactions);
495     }
496 
setTrustedOverlay(uint32_t id,gui::TrustedOverlay trustedOverlay)497     void setTrustedOverlay(uint32_t id, gui::TrustedOverlay trustedOverlay) {
498         std::vector<TransactionState> transactions;
499         transactions.emplace_back();
500         transactions.back().states.push_back({});
501 
502         transactions.back().states.front().state.what = layer_state_t::eTrustedOverlayChanged;
503         transactions.back().states.front().layerId = id;
504         transactions.back().states.front().state.trustedOverlay = trustedOverlay;
505         mLifecycleManager.applyTransactions(transactions);
506     }
507 
setDropInputMode(uint32_t id,gui::DropInputMode dropInputMode)508     void setDropInputMode(uint32_t id, gui::DropInputMode dropInputMode) {
509         std::vector<TransactionState> transactions;
510         transactions.emplace_back();
511         transactions.back().states.push_back({});
512 
513         transactions.back().states.front().state.what = layer_state_t::eDropInputModeChanged;
514         transactions.back().states.front().layerId = id;
515         transactions.back().states.front().state.dropInputMode = dropInputMode;
516         mLifecycleManager.applyTransactions(transactions);
517     }
518 
519     LayerLifecycleManager mLifecycleManager;
520 };
521 
522 class LayerSnapshotTestBase : public LayerHierarchyTestBase {
523 protected:
LayerSnapshotTestBase()524     LayerSnapshotTestBase() : LayerHierarchyTestBase() {}
525 
createRootLayer(uint32_t id)526     void createRootLayer(uint32_t id) override {
527         LayerHierarchyTestBase::createRootLayer(id);
528         setColor(id);
529     }
530 
createLayer(uint32_t id,uint32_t parentId)531     void createLayer(uint32_t id, uint32_t parentId) override {
532         LayerHierarchyTestBase::createLayer(id, parentId);
533         setColor(parentId);
534     }
535 
mirrorLayer(uint32_t id,uint32_t parent,uint32_t layerToMirror)536     void mirrorLayer(uint32_t id, uint32_t parent, uint32_t layerToMirror) override {
537         LayerHierarchyTestBase::mirrorLayer(id, parent, layerToMirror);
538         setColor(id);
539     }
540 
update(LayerSnapshotBuilder & snapshotBuilder)541     void update(LayerSnapshotBuilder& snapshotBuilder) {
542         mHierarchyBuilder.update(mLifecycleManager);
543         LayerSnapshotBuilder::Args args{.root = mHierarchyBuilder.getHierarchy(),
544                                         .layerLifecycleManager = mLifecycleManager,
545                                         .includeMetadata = false,
546                                         .displays = mFrontEndDisplayInfos,
547                                         .displayChanges = mHasDisplayChanges,
548                                         .globalShadowSettings = globalShadowSettings,
549                                         .supportsBlur = true,
550                                         .supportedLayerGenericMetadata = {},
551                                         .genericLayerMetadataKeyMap = {}};
552         snapshotBuilder.update(args);
553 
554         mLifecycleManager.commitChanges();
555     }
556 
557     LayerHierarchyBuilder mHierarchyBuilder;
558 
559     DisplayInfos mFrontEndDisplayInfos;
560     bool mHasDisplayChanges = false;
561 
562     ShadowSettings globalShadowSettings;
563 };
564 
565 } // namespace android::surfaceflinger::frontend
566