[sf] Pass metadata to layer during composition
Adds the simple bits of code to grab a snapshot of the front-end Layer
generic metadata, storing a copy in LayerFECompositionState, and then
sending int to the HWC2::Layer along with other "geometry update"
settings.
As the metadata stored in the layers uses integer keys, they need to be
translated to name strings. For hard-coded mapping is defined, with a
TODO left to remove the hard-coded mapping.
A test is added to ensure that the metadata is written by OutputLayer
when present, and that it is not set as part of a "per-frame" update.
Bug: 139747351
Test: atest libcompositionengine_test
Change-Id: I63f2a34e1fb70e1aefc5aa7e97ce56b7c2579a29
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index 6ff23c5..e04e0ab 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -475,6 +475,26 @@
compositionState->type = type;
compositionState->appId = appId;
+
+ compositionState->metadata.clear();
+ const auto& supportedMetadata = mFlinger->getHwComposer().getSupportedLayerGenericMetadata();
+ for (const auto& [key, mandatory] : supportedMetadata) {
+ const auto& genericLayerMetadataCompatibilityMap =
+ mFlinger->getGenericLayerMetadataKeyMap();
+ auto compatIter = genericLayerMetadataCompatibilityMap.find(key);
+ if (compatIter == std::end(genericLayerMetadataCompatibilityMap)) {
+ continue;
+ }
+ const uint32_t id = compatIter->second;
+
+ auto it = drawingState.metadata.mMap.find(id);
+ if (it == std::end(drawingState.metadata.mMap)) {
+ continue;
+ }
+
+ compositionState->metadata
+ .emplace(key, compositionengine::GenericLayerMetadataEntry{mandatory, it->second});
+ }
}
void Layer::preparePerFrameCompositionState() {