From 5ed18499acb99b992c9bd5f4e0f937695c4b632d Mon Sep 17 00:00:00 2001 From: chaviw Date: Mon, 8 Nov 2021 16:01:31 -0600 Subject: [PATCH] Remove overlay when DC is mirroring Layers can be added to the overlay when DisplayContent is mirroring which would add content that's not from the original display. This change puts the overlay layer offscreen so the root layer will only have the mirrored content below. This fixes an issue where screen recording with MediaProjection would show a black frame as the first frame. That frame was the RotationLayer getting put on top since the system thinks it needs to freeze the display. Test: No longer black frame as first frame in recording Test: SurfaceViewSyncTest Fixes: 205235272 Change-Id: I96323db05221d02db4d7762c7f36d3af904ef49e --- .../core/java/com/android/server/wm/DisplayContent.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/services/core/java/com/android/server/wm/DisplayContent.java b/services/core/java/com/android/server/wm/DisplayContent.java index cb376520e000f..29b1a80b7b581 100644 --- a/services/core/java/com/android/server/wm/DisplayContent.java +++ b/services/core/java/com/android/server/wm/DisplayContent.java @@ -6162,7 +6162,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp // Reparent the SurfaceControl of this DisplayContent to null, to prevent content // being added to it. This ensures that no app launched explicitly on the // VirtualDisplay will show up as part of the mirrored content. - .reparent(mWindowingLayer, null); + .reparent(mWindowingLayer, null) + .reparent(mOverlayLayer, null); // Retrieve the size of the DisplayArea to mirror. updateMirroredSurface(transaction, wc.getDisplayContent().getBounds(), surfaceSize); mTokenToMirror = tokenToMirror; @@ -6192,7 +6193,9 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp // Reparent the SurfaceControl of this DisplayContent back to mSurfaceControl, // to allow content to be added to it. This allows this DisplayContent to stop // mirroring and show content normally. - .reparent(mWindowingLayer, mSurfaceControl).apply(); + .reparent(mWindowingLayer, mSurfaceControl) + .reparent(mOverlayLayer, mSurfaceControl) + .apply(); // Stop mirroring by destroying the reference to the mirrored layer. mMirroredSurface = null; // Do not un-set the token, in case content is removed and mirroring should begin again.