From 851563ae9d56dc6ecf4526c48dea2ae6a09abf59 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Sun, 3 Nov 2024 13:15:58 +0100 Subject: [PATCH] Do not recreate display on every rotation Refs #4840 DONOTMERGE This reintroduces the bugs fixed 7e3b9359322fff65bd350febfdc02a76186981cd. --- .../scrcpy/video/ScreenCapture.java | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java b/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java index 04e4280080..17d8972ee1 100644 --- a/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java +++ b/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java @@ -17,6 +17,7 @@ import android.os.Handler; import android.os.HandlerThread; import android.os.IBinder; +import android.util.DisplayMetrics; import android.view.IDisplayFoldListener; import android.view.IRotationWatcher; import android.view.Surface; @@ -129,21 +130,18 @@ public void prepare() throws ConfigurationException { @Override public void start(Surface surface) { - if (display != null) { - SurfaceControl.destroyDisplay(display); - display = null; - } - if (virtualDisplay != null) { - virtualDisplay.release(); - virtualDisplay = null; - } - int virtualDisplayId; PositionMapper positionMapper; try { Size videoSize = screenInfo.getVideoSize(); - virtualDisplay = ServiceManager.getDisplayManager() - .createVirtualDisplay("scrcpy", videoSize.getWidth(), videoSize.getHeight(), displayId, surface); + if (virtualDisplay == null) { + virtualDisplay = ServiceManager.getDisplayManager() + .createVirtualDisplay("scrcpy", videoSize.getWidth(), videoSize.getHeight(), displayId, surface); + } else { + // density doesn't matter since this virtual display is only used for mirroring + virtualDisplay.resize(videoSize.getWidth(), videoSize.getHeight(), 1); + virtualDisplay.setSurface(surface); + } virtualDisplayId = virtualDisplay.getDisplay().getDisplayId(); Rect contentRect = new Rect(0, 0, videoSize.getWidth(), videoSize.getHeight()); // The position are relative to the virtual display, not the original display @@ -151,7 +149,9 @@ public void start(Surface surface) { Ln.d("Display: using DisplayManager API"); } catch (Exception displayManagerException) { try { - display = createDisplay(); + if (display == null) { + display = createDisplay(); + } Rect contentRect = screenInfo.getContentRect();