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/SurfaceFlinger.h b/services/surfaceflinger/SurfaceFlinger.h
index 551b0e8..6f9bbeb 100644
--- a/services/surfaceflinger/SurfaceFlinger.h
+++ b/services/surfaceflinger/SurfaceFlinger.h
@@ -96,12 +96,12 @@
#include <utility>
#include <aidl/android/hardware/graphics/common/DisplayDecorationSupport.h>
+#include "Client.h"
using namespace android::surfaceflinger;
namespace android {
-class Client;
class EventThread;
class FlagManager;
class FpsReporter;
@@ -819,6 +819,9 @@
status_t mirrorLayer(const LayerCreationArgs& args, const sp<IBinder>& mirrorFromHandle,
sp<IBinder>* outHandle, int32_t* outLayerId);
+ status_t mirrorDisplay(DisplayId displayId, const LayerCreationArgs& args,
+ sp<IBinder>* outHandle, int32_t* outLayerId);
+
// called when all clients have released all their references to
// this layer meaning it is entirely safe to destroy all
// resources associated to this layer.
@@ -1372,6 +1375,19 @@
void handleLayerCreatedLocked(const LayerCreatedState& state, int64_t vsyncId)
REQUIRES(mStateLock);
+ mutable std::mutex mMirrorDisplayLock;
+ struct MirrorDisplayState {
+ MirrorDisplayState(ui::LayerStack layerStack, sp<IBinder>& rootHandle,
+ const sp<Client>& client)
+ : layerStack(layerStack), rootHandle(rootHandle), client(client) {}
+
+ ui::LayerStack layerStack;
+ sp<IBinder> rootHandle;
+ const sp<Client> client;
+ };
+ std::vector<MirrorDisplayState> mMirrorDisplays GUARDED_BY(mMirrorDisplayLock);
+ bool commitMirrorDisplays(int64_t vsyncId);
+
std::atomic<ui::Transform::RotationFlags> mActiveDisplayTransformHint;
bool isRefreshRateOverlayEnabled() const REQUIRES(mStateLock) {