SF: Refactor onLayerDisplayed
Adds a new LayerFE::onLayerDisplayed interface, and adjusts the
front-end Layer to match.
Adjusts the code in SurfaceFlinger to use the new interface, in
preparation to moving the loop over to CompositionEngine.
Test: atest libsurfaceflinger_unittest libcompositionengine_test
Bug: 121291683
Change-Id: I9231f4b425ea1b9f37363521c7e3f6aef63bcec6
diff --git a/services/surfaceflinger/SurfaceFlinger.cpp b/services/surfaceflinger/SurfaceFlinger.cpp
index 3bec6dc..e13a036 100644
--- a/services/surfaceflinger/SurfaceFlinger.cpp
+++ b/services/surfaceflinger/SurfaceFlinger.cpp
@@ -2448,16 +2448,19 @@
getHwComposer().presentAndGetReleaseFences(*displayId);
}
display->getRenderSurface()->onPresentDisplayCompleted();
- for (auto& layer : displayDevice->getVisibleLayersSortedByZ()) {
+ for (auto& layer : display->getOutputLayersOrderedByZ()) {
sp<Fence> releaseFence = Fence::NO_FENCE;
+ bool usedClientComposition = true;
// The layer buffer from the previous frame (if any) is released
// by HWC only when the release fence from this frame (if any) is
// signaled. Always get the release fence from HWC first.
- if (displayId && layer->hasHwcLayer(displayDevice)) {
+ if (layer->getState().hwc) {
+ const auto& hwcState = *layer->getState().hwc;
releaseFence =
- getHwComposer().getLayerReleaseFence(*displayId,
- layer->getHwcLayer(displayDevice));
+ getHwComposer().getLayerReleaseFence(*displayId, hwcState.hwcLayer.get());
+ usedClientComposition =
+ hwcState.hwcCompositionType == Hwc2::IComposerClient::Composition::CLIENT;
}
// If the layer was client composited in the previous frame, we
@@ -2465,14 +2468,13 @@
// Since we do not track that, always merge with the current
// client target acquire fence when it is available, even though
// this is suboptimal.
- if (layer->getCompositionType(displayDevice) ==
- Hwc2::IComposerClient::Composition::CLIENT) {
+ if (usedClientComposition) {
releaseFence =
Fence::merge("LayerRelease", releaseFence,
display->getRenderSurface()->getClientTargetAcquireFence());
}
- layer->getBE().onLayerDisplayed(releaseFence);
+ layer->getLayerFE().onLayerDisplayed(releaseFence);
}
// We've got a list of layers needing fences, that are disjoint with
@@ -2482,7 +2484,7 @@
sp<Fence> presentFence =
displayId ? getHwComposer().getPresentFence(*displayId) : Fence::NO_FENCE;
for (auto& layer : displayDevice->getLayersNeedingFences()) {
- layer->getBE().onLayerDisplayed(presentFence);
+ layer->getCompositionLayer()->getLayerFE()->onLayerDisplayed(presentFence);
}
}