Provide function to mirror display for screenrecord.
The current mirroring for shell screenrecording is by using the layer
stack mirroring. However, we want to port all layerStack mirroring to
use layer mirroring. This add a new function that allows the root layers
of a display to get mirrored by passing in a specified displayId.
The code will iterate though the layers and find root layers that are
rendered onto the desired display. SF will then clone the roots and set
them as a child of a new ContainerLayer that will be at the root of all
the mirrored roots. This is because a display may have multiple root
layers.
Test: adb shell screenrecord
Bug: 237664947
Change-Id: I31151527f5377079e2293be2c995f6a3316639da
diff --git a/services/surfaceflinger/Client.cpp b/services/surfaceflinger/Client.cpp
index ceded93..3685bb4 100644
--- a/services/surfaceflinger/Client.cpp
+++ b/services/surfaceflinger/Client.cpp
@@ -147,5 +147,20 @@
return binderStatusFromStatusT(status);
}
+binder::Status Client::mirrorDisplay(int64_t displayId, gui::MirrorSurfaceResult* outResult) {
+ sp<IBinder> handle;
+ int32_t layerId;
+ LayerCreationArgs args(mFlinger.get(), sp<Client>::fromExisting(this),
+ "MirrorRoot-" + std::to_string(displayId), 0 /* flags */,
+ gui::LayerMetadata());
+ std::optional<DisplayId> id = DisplayId::fromValue(static_cast<uint64_t>(displayId));
+ status_t status = mFlinger->mirrorDisplay(*id, args, &handle, &layerId);
+ if (status == NO_ERROR) {
+ outResult->handle = handle;
+ outResult->layerId = layerId;
+ }
+ return binderStatusFromStatusT(status);
+}
+
// ---------------------------------------------------------------------------
}; // namespace android