Skip client composition requests
Keep track of client compositions requests in CompositionEngine and
the buffer used to render the request. If the requests do not change
and the buffer matches, reuse the buffer instead of going
to client composition.
Certain layers properties (buffer format, rounded corner or shadows)
will force the device to go into GPU or mixed composition. In mixed
composition scenarios, we can avoid redundant client composition
requests by reusing the RenderSurface buffers. If the device goes
into GPU composition then all the layers will be composited and there
will be no performance benefit.
Bug: b/136561771, b/144690120
Test: dump SurfaceFlinger --timestats -dump
Test: manual testing with mixed and gpu composition scenarios
Test: atest libcompositionengine_test libsurfaceflinger_unittest SurfaceFlinger_test
Change-Id: I466d5dcded0c9fcfa64bc72fd91dfaddd795f315
diff --git a/services/surfaceflinger/Layer.cpp b/services/surfaceflinger/Layer.cpp
index f4d4329..11ae46d 100644
--- a/services/surfaceflinger/Layer.cpp
+++ b/services/surfaceflinger/Layer.cpp
@@ -551,7 +551,7 @@
// drawing...
// ---------------------------------------------------------------------------
-std::optional<renderengine::LayerSettings> Layer::prepareClientComposition(
+std::optional<compositionengine::LayerFE::LayerSettings> Layer::prepareClientComposition(
compositionengine::LayerFE::ClientCompositionTargetSettings& targetSettings) {
if (!getCompositionLayer()) {
return {};
@@ -559,7 +559,8 @@
FloatRect bounds = getBounds();
half alpha = getAlpha();
- renderengine::LayerSettings layerSettings;
+
+ compositionengine::LayerFE::LayerSettings layerSettings;
layerSettings.geometry.boundaries = bounds;
if (targetSettings.useIdentityTransform) {
layerSettings.geometry.positionTransform = mat4();
@@ -581,8 +582,8 @@
return layerSettings;
}
-std::optional<renderengine::LayerSettings> Layer::prepareShadowClientComposition(
- const renderengine::LayerSettings& casterLayerSettings, const Rect& displayViewport,
+std::optional<compositionengine::LayerFE::LayerSettings> Layer::prepareShadowClientComposition(
+ const LayerFE::LayerSettings& casterLayerSettings, const Rect& displayViewport,
ui::Dataspace outputDataspace) {
renderengine::ShadowSettings shadow = getShadowSettings(displayViewport);
if (shadow.length <= 0.f) {
@@ -593,7 +594,8 @@
const bool casterIsOpaque = ((casterLayerSettings.source.buffer.buffer != nullptr) &&
casterLayerSettings.source.buffer.isOpaque);
- renderengine::LayerSettings shadowLayer = casterLayerSettings;
+ compositionengine::LayerFE::LayerSettings shadowLayer = casterLayerSettings;
+
shadowLayer.shadow = shadow;
shadowLayer.geometry.boundaries = mBounds; // ignore transparent region
@@ -604,13 +606,16 @@
shadowLayer.shadow.spotColor *= casterAlpha;
shadowLayer.sourceDataspace = outputDataspace;
shadowLayer.source.buffer.buffer = nullptr;
+ shadowLayer.source.buffer.fence = nullptr;
+ shadowLayer.frameNumber = 0;
+ shadowLayer.bufferId = 0;
if (shadowLayer.shadow.ambientColor.a <= 0.f && shadowLayer.shadow.spotColor.a <= 0.f) {
return {};
}
float casterCornerRadius = shadowLayer.geometry.roundedCornersRadius;
- const FloatRect& cornerRadiusCropRect = casterLayerSettings.geometry.roundedCornersCrop;
+ const FloatRect& cornerRadiusCropRect = shadowLayer.geometry.roundedCornersCrop;
const FloatRect& casterRect = shadowLayer.geometry.boundaries;
// crop used to set the corner radius may be larger than the content rect. Adjust the corner