Skip to content

Commit 35f9fab

Browse files
Melody HsuAndroid (Google) Code Review
authored andcommitted
Merge "Rename invalid LayerStacks to "unassigned"" into main
2 parents 97d6ef2 + c6a0cc6 commit 35f9fab

File tree

11 files changed

+35
-32
lines changed

11 files changed

+35
-32
lines changed

libs/ui/include/ui/LayerStack.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
namespace android::ui {
2626

2727
// A LayerStack identifies a Z-ordered group of layers. A layer can only be associated to a single
28-
// LayerStack, but a LayerStack can be associated to multiple displays, mirroring the same content.
28+
// LayerStack, and a LayerStack should be unique to each display in the composition target.
2929
struct LayerStack {
3030
uint32_t id = UINT32_MAX;
3131

@@ -40,7 +40,9 @@ struct LayerStack {
4040
}
4141
};
4242

43-
constexpr LayerStack INVALID_LAYER_STACK;
43+
// An unassigned LayerStack can indicate that a layer is offscreen and will not be
44+
// rendered onto a display. Multiple displays are allowed to have unassigned LayerStacks.
45+
constexpr LayerStack UNASSIGNED_LAYER_STACK;
4446
constexpr LayerStack DEFAULT_LAYER_STACK{0u};
4547

4648
inline bool operator==(LayerStack lhs, LayerStack rhs) {
@@ -70,7 +72,7 @@ struct LayerFilter {
7072
// Returns true if the input filter can be output to this filter.
7173
bool includes(LayerFilter other) const {
7274
// The layer stacks must match.
73-
if (other.layerStack == INVALID_LAYER_STACK || other.layerStack != layerStack) {
75+
if (other.layerStack == UNASSIGNED_LAYER_STACK || other.layerStack != layerStack) {
7476
return false;
7577
}
7678

services/surfaceflinger/CompositionEngine/tests/DisplayTest.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ TEST_F(DisplaySetConfigurationTest, configuresPhysicalDisplay) {
302302
EXPECT_FALSE(mDisplay->isValid());
303303

304304
const auto& filter = mDisplay->getState().layerFilter;
305-
EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
305+
EXPECT_EQ(ui::UNASSIGNED_LAYER_STACK, filter.layerStack);
306306
EXPECT_FALSE(filter.toInternalDisplay);
307307
}
308308

@@ -322,7 +322,7 @@ TEST_F(DisplaySetConfigurationTest, configuresHalVirtualDisplay) {
322322
EXPECT_FALSE(mDisplay->isValid());
323323

324324
const auto& filter = mDisplay->getState().layerFilter;
325-
EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
325+
EXPECT_EQ(ui::UNASSIGNED_LAYER_STACK, filter.layerStack);
326326
EXPECT_FALSE(filter.toInternalDisplay);
327327
}
328328

@@ -342,7 +342,7 @@ TEST_F(DisplaySetConfigurationTest, configuresGpuVirtualDisplay) {
342342
EXPECT_FALSE(mDisplay->isValid());
343343

344344
const auto& filter = mDisplay->getState().layerFilter;
345-
EXPECT_EQ(ui::INVALID_LAYER_STACK, filter.layerStack);
345+
EXPECT_EQ(ui::UNASSIGNED_LAYER_STACK, filter.layerStack);
346346
EXPECT_FALSE(filter.toInternalDisplay);
347347
}
348348

services/surfaceflinger/CompositionEngine/tests/OutputTest.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -646,8 +646,8 @@ TEST_F(OutputTest, layerFiltering) {
646646
mOutput->setLayerFilter({layerStack1, true});
647647

648648
// It excludes layers with no layer stack, internal-only or not.
649-
EXPECT_FALSE(mOutput->includesLayer({ui::INVALID_LAYER_STACK, false}));
650-
EXPECT_FALSE(mOutput->includesLayer({ui::INVALID_LAYER_STACK, true}));
649+
EXPECT_FALSE(mOutput->includesLayer({ui::UNASSIGNED_LAYER_STACK, false}));
650+
EXPECT_FALSE(mOutput->includesLayer({ui::UNASSIGNED_LAYER_STACK, true}));
651651

652652
// It includes layers on layerStack1, internal-only or not.
653653
EXPECT_TRUE(mOutput->includesLayer({layerStack1, false}));
@@ -685,10 +685,10 @@ TEST_F(OutputTest, layerFilteringWithCompositionState) {
685685
mOutput->setLayerFilter({layerStack1, true});
686686

687687
// It excludes layers with no layer stack, internal-only or not.
688-
layer.layerFEState.outputFilter = {ui::INVALID_LAYER_STACK, false};
688+
layer.layerFEState.outputFilter = {ui::UNASSIGNED_LAYER_STACK, false};
689689
EXPECT_FALSE(mOutput->includesLayer(layerFE));
690690

691-
layer.layerFEState.outputFilter = {ui::INVALID_LAYER_STACK, true};
691+
layer.layerFEState.outputFilter = {ui::UNASSIGNED_LAYER_STACK, true};
692692
EXPECT_FALSE(mOutput->includesLayer(layerFE));
693693

694694
// It includes layers on layerStack1, internal-only or not.

services/surfaceflinger/FrontEnd/LayerCreationArgs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ std::string LayerCreationArgs::getDebugString() const {
8686
if (layerIdToMirror != UNASSIGNED_LAYER_ID) {
8787
stream << " layerIdToMirror=" << layerIdToMirror;
8888
}
89-
if (layerStackToMirror != ui::INVALID_LAYER_STACK) {
89+
if (layerStackToMirror != ui::UNASSIGNED_LAYER_STACK) {
9090
stream << " layerStackToMirror=" << layerStackToMirror.id;
9191
}
9292
return stream.str();

services/surfaceflinger/FrontEnd/LayerCreationArgs.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ struct LayerCreationArgs {
5858
bool addToRoot = true;
5959
wp<IBinder> parentHandle = nullptr;
6060
wp<IBinder> mirrorLayerHandle = nullptr;
61-
ui::LayerStack layerStackToMirror = ui::INVALID_LAYER_STACK;
61+
ui::LayerStack layerStackToMirror = ui::UNASSIGNED_LAYER_STACK;
6262
uint32_t parentId = UNASSIGNED_LAYER_ID;
6363
uint32_t layerIdToMirror = UNASSIGNED_LAYER_ID;
6464
std::atomic<int32_t>* pendingBuffers = 0;

services/surfaceflinger/FrontEnd/LayerLifecycleManager.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ void LayerLifecycleManager::addLayers(std::vector<std::unique_ptr<RequestedLayer
5555
mChangedLayers.push_back(newLayer.get());
5656
layer.parentId = linkLayer(layer.parentId, layer.id);
5757
layer.relativeParentId = linkLayer(layer.relativeParentId, layer.id);
58-
if (layer.layerStackToMirror != ui::INVALID_LAYER_STACK) {
58+
if (layer.layerStackToMirror != ui::UNASSIGNED_LAYER_STACK) {
5959
// Set mirror layer's default layer stack to -1 so it doesn't end up rendered on a
6060
// display accidentally.
61-
layer.layerStack = ui::INVALID_LAYER_STACK;
61+
layer.layerStack = ui::UNASSIGNED_LAYER_STACK;
6262

6363
// if this layer is mirroring a display, then walk though all the existing root layers
6464
// for the layer stack and add them as children to be mirrored.
@@ -124,7 +124,7 @@ void LayerLifecycleManager::onHandlesDestroyed(
124124

125125
layer.parentId = unlinkLayer(layer.parentId, layer.id);
126126
layer.relativeParentId = unlinkLayer(layer.relativeParentId, layer.id);
127-
if (layer.layerStackToMirror != ui::INVALID_LAYER_STACK) {
127+
if (layer.layerStackToMirror != ui::UNASSIGNED_LAYER_STACK) {
128128
layer.mirrorIds = unlinkLayers(layer.mirrorIds, layer.id);
129129
swapErase(mDisplayMirroringLayers, layer.id);
130130
} else {

services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ void LayerSnapshotBuilder::updateSnapshot(LayerSnapshot& snapshot, const Args& a
781781
// Display mirrors are always placed in a VirtualDisplay so we never want to capture layers
782782
// marked as skip capture
783783
snapshot.handleSkipScreenshotFlag = parentSnapshot.handleSkipScreenshotFlag ||
784-
(requested.layerStackToMirror != ui::INVALID_LAYER_STACK);
784+
(requested.layerStackToMirror != ui::UNASSIGNED_LAYER_STACK);
785785
}
786786

787787
if (forceUpdate || snapshot.clientChanges & layer_state_t::eAlphaChanged) {

services/surfaceflinger/FrontEnd/RequestedLayerState.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ RequestedLayerState::RequestedLayerState(const LayerCreationArgs& args)
7373
}
7474
if (layerIdToMirror != UNASSIGNED_LAYER_ID) {
7575
changes |= RequestedLayerState::Changes::Mirror;
76-
} else if (args.layerStackToMirror != ui::INVALID_LAYER_STACK) {
76+
} else if (args.layerStackToMirror != ui::UNASSIGNED_LAYER_STACK) {
7777
layerStackToMirror = args.layerStackToMirror;
7878
changes |= RequestedLayerState::Changes::Mirror;
7979
}

services/surfaceflinger/FrontEnd/RequestedLayerState.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ struct RequestedLayerState : layer_state_t {
128128
uint32_t parentId = UNASSIGNED_LAYER_ID;
129129
uint32_t relativeParentId = UNASSIGNED_LAYER_ID;
130130
uint32_t layerIdToMirror = UNASSIGNED_LAYER_ID;
131-
ui::LayerStack layerStackToMirror = ui::INVALID_LAYER_STACK;
131+
ui::LayerStack layerStackToMirror = ui::UNASSIGNED_LAYER_STACK;
132132
uint32_t touchCropId = UNASSIGNED_LAYER_ID;
133133
uint32_t bgColorLayerId = UNASSIGNED_LAYER_ID;
134134
uint64_t barrierFrameNumber = 0;

services/surfaceflinger/SurfaceFlinger.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2867,7 +2867,8 @@ CompositeResultsPerDisplay SurfaceFlinger::composite(
28672867
ui::DisplayMap<ui::LayerStack, ftl::Unit> outputLayerStacks;
28682868
auto isUniqueOutputLayerStack = [&outputLayerStacks](DisplayId id, ui::LayerStack layerStack) {
28692869
if (FlagManager::getInstance().reject_dupe_layerstacks()) {
2870-
if (layerStack != ui::INVALID_LAYER_STACK && outputLayerStacks.contains(layerStack)) {
2870+
if (layerStack != ui::UNASSIGNED_LAYER_STACK &&
2871+
outputLayerStacks.contains(layerStack)) {
28712872
// TODO: remove log and DisplayId from params once reject_dupe_layerstacks flag is
28722873
// removed
28732874
ALOGD("Existing layer stack ID %d output to another display %" PRIu64
@@ -2996,9 +2997,9 @@ CompositeResultsPerDisplay SurfaceFlinger::composite(
29962997
LayerFE::ReleaseFencePromiseStatus::UNINITIALIZED ||
29972998
layerFE->getReleaseFencePromiseStatus() ==
29982999
LayerFE::ReleaseFencePromiseStatus::FULFILLED) {
2999-
// layerStack is invalid because layer is not on a display
3000+
// layerStack is unassigned because layer is not on a display
30003001
attachReleaseFenceFutureToLayer(layer.get(), layerFE.get(),
3001-
ui::INVALID_LAYER_STACK);
3002+
ui::UNASSIGNED_LAYER_STACK);
30023003
}
30033004
}
30043005
}
@@ -3015,13 +3016,13 @@ CompositeResultsPerDisplay SurfaceFlinger::composite(
30153016

30163017
int index = 0;
30173018
ftl::StaticVector<char, WorkloadTracer::COMPOSITION_SUMMARY_SIZE> compositionSummary;
3018-
auto lastLayerStack = ui::INVALID_LAYER_STACK;
3019+
auto lastLayerStack = ui::UNASSIGNED_LAYER_STACK;
30193020

30203021
uint64_t prevOverrideBufferId = 0;
30213022
for (auto& [layer, layerFE] : layers) {
30223023
CompositionResult compositionResult{layerFE->stealCompositionResult()};
30233024
if (lastLayerStack != layerFE->mSnapshot->outputFilter.layerStack) {
3024-
if (lastLayerStack != ui::INVALID_LAYER_STACK) {
3025+
if (lastLayerStack != ui::UNASSIGNED_LAYER_STACK) {
30253026
// add a space to separate displays
30263027
compositionSummary.push_back(' ');
30273028
}
@@ -3346,7 +3347,7 @@ void SurfaceFlinger::onCompositionPresented(PhysicalDisplayId pacesetterId,
33463347
if (optDisplay && !optDisplay->get()->isVirtual()) {
33473348
auto fence = getHwComposer().getPresentFence(optDisplay->get()->getPhysicalId());
33483349
layer->prepareReleaseCallbacks(ftl::yield<FenceResult>(fence),
3349-
ui::INVALID_LAYER_STACK);
3350+
ui::UNASSIGNED_LAYER_STACK);
33503351
}
33513352
}
33523353
layer->releasePendingBuffer(presentTime.ns());
@@ -6182,7 +6183,7 @@ void SurfaceFlinger::dumpHdrInfo(std::string& result) const {
61826183
void SurfaceFlinger::dumpFrontEnd(std::string& result) {
61836184
std::ostringstream out;
61846185
out << "\nComposition list (bottom to top)\n";
6185-
ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK;
6186+
ui::LayerStack lastPrintedLayerStackHeader = ui::UNASSIGNED_LAYER_STACK;
61866187
for (const auto& snapshot : mLayerSnapshotBuilder.getSnapshots()) {
61876188
if (lastPrintedLayerStackHeader != snapshot->outputFilter.layerStack) {
61886189
lastPrintedLayerStackHeader = snapshot->outputFilter.layerStack;
@@ -6192,7 +6193,7 @@ void SurfaceFlinger::dumpFrontEnd(std::string& result) {
61926193
}
61936194

61946195
out << "\nInput list\n";
6195-
lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK;
6196+
lastPrintedLayerStackHeader = ui::UNASSIGNED_LAYER_STACK;
61966197
mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) {
61976198
if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) {
61986199
lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack;
@@ -6210,7 +6211,7 @@ void SurfaceFlinger::dumpFrontEnd(std::string& result) {
62106211
void SurfaceFlinger::dumpVisibleFrontEnd(std::string& result) {
62116212
std::ostringstream out;
62126213
out << "\nComposition list (bottom to top)\n";
6213-
ui::LayerStack lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK;
6214+
ui::LayerStack lastPrintedLayerStackHeader = ui::UNASSIGNED_LAYER_STACK;
62146215
mLayerSnapshotBuilder.forEachVisibleSnapshot(
62156216
[&](std::unique_ptr<frontend::LayerSnapshot>& snapshot) {
62166217
if (snapshot->hasSomethingToDraw()) {
@@ -6223,7 +6224,7 @@ void SurfaceFlinger::dumpVisibleFrontEnd(std::string& result) {
62236224
});
62246225

62256226
out << "\nInput list\n";
6226-
lastPrintedLayerStackHeader = ui::INVALID_LAYER_STACK;
6227+
lastPrintedLayerStackHeader = ui::UNASSIGNED_LAYER_STACK;
62276228
mLayerSnapshotBuilder.forEachInputSnapshot([&](const frontend::LayerSnapshot& snapshot) {
62286229
if (lastPrintedLayerStackHeader != snapshot.outputFilter.layerStack) {
62296230
lastPrintedLayerStackHeader = snapshot.outputFilter.layerStack;
@@ -7683,7 +7684,7 @@ bool SurfaceFlinger::getSnapshotsFromMainThread(
76837684
if (mRenderEngine->isThreaded()) {
76847685
for (auto& [layer, layerFE] : layers) {
76857686
attachReleaseFenceFutureToLayer(layer, layerFE.get(),
7686-
ui::INVALID_LAYER_STACK);
7687+
ui::UNASSIGNED_LAYER_STACK);
76877688
}
76887689
}
76897690
return getDisplayStateOnMainThread(args);
@@ -7965,7 +7966,7 @@ ftl::SharedFuture<FenceResult> SurfaceFlinger::renderScreenImpl(
79657966
// deadlocks between main thread and binder threads waiting for the future fence
79667967
// result, fences should be added to layers in the same hop onto the main thread.
79677968
if (!mRenderEngine->isThreaded()) {
7968-
attachReleaseFenceFutureToLayer(layer, layerFE.get(), ui::INVALID_LAYER_STACK);
7969+
attachReleaseFenceFutureToLayer(layer, layerFE.get(), ui::UNASSIGNED_LAYER_STACK);
79697970
}
79707971
layerFEs.push_back(layerFE);
79717972
}

0 commit comments

Comments
 (0)