summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Vishnu Nair <vishnun@google.com> 2023-02-27 19:40:24 +0000
committer Vishnu Nair <vishnun@google.com> 2023-02-27 19:48:39 +0000
commit93b8b794958edd145ffdb5818f8d748c69e60b5d (patch)
treed24e4398bfb72e6e05d9618699c45643d80c4b47
parentea6ff8192014357d3e720263bee60444e1f8f1d7 (diff)
[sf] provide a unique id for snapshots
Input and layer tracing relies on the fact that all layers have a unique id. Because mirror layers are no longer implemented by duplicating layers, we can have multiple snapshots with the same id. To fix this, provide a unique id that can be used by consumers who require them. Test: atest FlickerTest Bug: 238781169 Change-Id: Ibe54154b6e14f72bfe73a15faa0e7e0d19293e36
-rw-r--r--services/surfaceflinger/FrontEnd/LayerSnapshot.cpp6
-rw-r--r--services/surfaceflinger/FrontEnd/LayerSnapshot.h6
-rw-r--r--services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp2
-rw-r--r--services/surfaceflinger/LayerProtoHelper.cpp3
4 files changed, 14 insertions, 3 deletions
diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp
index 85b00d77b4..8a450933f0 100644
--- a/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp
+++ b/services/surfaceflinger/FrontEnd/LayerSnapshot.cpp
@@ -27,12 +27,16 @@ using namespace ftl::flag_operators;
LayerSnapshot::LayerSnapshot(const RequestedLayerState& state,
const LayerHierarchy::TraversalPath& path)
: path(path) {
+ static uint32_t sUniqueSequenceId = 0;
+ // Provide a unique id for clones otherwise keeping using the sequence id.
+ // The seq id can still be useful for debugging if its available.
+ uniqueSequence = (path.isClone()) ? sUniqueSequenceId++ : state.id;
sequence = static_cast<int32_t>(state.id);
name = state.name;
textureName = state.textureName;
premultipliedAlpha = state.premultipliedAlpha;
inputInfo.name = state.name;
- inputInfo.id = static_cast<int32_t>(state.id);
+ inputInfo.id = static_cast<int32_t>(uniqueSequence);
inputInfo.ownerUid = static_cast<int32_t>(state.ownerUid);
inputInfo.ownerPid = state.ownerPid;
changes = RequestedLayerState::Changes::Created;
diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshot.h b/services/surfaceflinger/FrontEnd/LayerSnapshot.h
index 07aa12269a..e069a63201 100644
--- a/services/surfaceflinger/FrontEnd/LayerSnapshot.h
+++ b/services/surfaceflinger/FrontEnd/LayerSnapshot.h
@@ -57,6 +57,12 @@ struct LayerSnapshot : public compositionengine::LayerFECompositionState {
bool isHiddenByPolicyFromParent = false;
bool isHiddenByPolicyFromRelativeParent = false;
ftl::Flags<RequestedLayerState::Changes> changes;
+ // Some consumers of this snapshot (input, layer traces) rely on each snapshot to be unique.
+ // For mirrored layers, snapshots will have the same sequence so this unique id provides
+ // an alternative identifier when needed.
+ uint32_t uniqueSequence;
+ // Layer id used to create this snapshot. Multiple snapshots will have the same sequence if they
+ // generated from the same layer, for example when mirroring.
int32_t sequence;
std::string name;
uint32_t textureName;
diff --git a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp
index db6e716311..344dab4522 100644
--- a/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp
+++ b/services/surfaceflinger/FrontEnd/LayerSnapshotBuilder.cpp
@@ -957,7 +957,7 @@ void LayerSnapshotBuilder::updateInput(LayerSnapshot& snapshot,
}
snapshot.inputInfo.name = requested.name;
- snapshot.inputInfo.id = static_cast<int32_t>(requested.id);
+ snapshot.inputInfo.id = static_cast<int32_t>(snapshot.uniqueSequence);
snapshot.inputInfo.ownerUid = static_cast<int32_t>(requested.ownerUid);
snapshot.inputInfo.ownerPid = requested.ownerPid;
snapshot.inputInfo.displayId = static_cast<int32_t>(snapshot.outputFilter.layerStack.id);
diff --git a/services/surfaceflinger/LayerProtoHelper.cpp b/services/surfaceflinger/LayerProtoHelper.cpp
index 1a828bf88c..55281fa962 100644
--- a/services/surfaceflinger/LayerProtoHelper.cpp
+++ b/services/surfaceflinger/LayerProtoHelper.cpp
@@ -260,6 +260,7 @@ void LayerProtoHelper::writeHierarchyToProto(
frontend::LayerSnapshot* snapshot = snapshotBuilder.getSnapshot(layer.id);
if (!snapshot) {
+ defaultSnapshot.uniqueSequence = layer.id;
snapshot = &defaultSnapshot;
}
writeSnapshotToProto(layerProto, layer, *snapshot, traceFlags);
@@ -343,7 +344,7 @@ void LayerProtoHelper::writeSnapshotToProto(LayerProto* layerInfo,
[&]() { return layerInfo->mutable_corner_radius_crop(); });
layerInfo->set_shadow_radius(snapshot.shadowRadius);
- layerInfo->set_id(requestedState.id);
+ layerInfo->set_id(snapshot.uniqueSequence);
layerInfo->set_name(requestedState.name);
layerInfo->set_type("Layer");