From 7e3b9359322fff65bd350febfdc02a76186981cd Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 16 Nov 2023 08:56:04 +0100 Subject: [PATCH] Recreate the display on rotation On Android 14 (Pixel 8), a device rotation while the camera app was running resulted in an incorrect capture. Destroying and recreating the display fixes the issue. --- .../main/java/com/genymobile/scrcpy/ScreenCapture.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/ScreenCapture.java b/server/src/main/java/com/genymobile/scrcpy/ScreenCapture.java index f81332f5..e048354a 100644 --- a/server/src/main/java/com/genymobile/scrcpy/ScreenCapture.java +++ b/server/src/main/java/com/genymobile/scrcpy/ScreenCapture.java @@ -18,7 +18,6 @@ public class ScreenCapture extends SurfaceCapture implements Device.RotationList @Override public void init() { - display = createDisplay(); device.setRotationListener(this); device.setFoldListener(this); } @@ -32,6 +31,11 @@ public class ScreenCapture extends SurfaceCapture implements Device.RotationList Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect(); int videoRotation = screenInfo.getVideoRotation(); int layerStack = device.getLayerStack(); + + if (display != null) { + SurfaceControl.destroyDisplay(display); + } + display = createDisplay(); setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack); } @@ -39,7 +43,9 @@ public class ScreenCapture extends SurfaceCapture implements Device.RotationList public void release() { device.setRotationListener(null); device.setFoldListener(null); - SurfaceControl.destroyDisplay(display); + if (display != null) { + SurfaceControl.destroyDisplay(display); + } } @Override