From 5eaf072a858c3c0889729f88a62a287f92b20fd9 Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Fri, 15 Nov 2024 18:59:44 +0100 Subject: [PATCH] Do not recreate display on every rotation This semantically reverts 7e3b9359322fff65bd350febfdc02a76186981cd. The issue seems to be fixed if setSurface() is called before resize() on the virtual display. Refs #4840 --- .../scrcpy/video/ScreenCapture.java | 22 +++++++++---------- 1 file changed, 10 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 8cbb00d0..ef82c87b 100644 --- a/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java +++ b/server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java @@ -133,15 +133,6 @@ public class ScreenCapture extends DisplayCapture { @Override public void start(Surface surface) throws IOException { - if (display != null) { - SurfaceControl.destroyDisplay(display); - display = null; - } - if (virtualDisplay != null) { - virtualDisplay.release(); - virtualDisplay = null; - } - Size inputSize; if (transform != null) { // If there is a filter, it must receive the full display content @@ -158,8 +149,13 @@ public class ScreenCapture extends DisplayCapture { int virtualDisplayId; PositionMapper positionMapper; try { - virtualDisplay = ServiceManager.getDisplayManager() - .createVirtualDisplay("scrcpy", inputSize.getWidth(), inputSize.getHeight(), displayId, surface); + if (virtualDisplay == null) { + virtualDisplay = ServiceManager.getDisplayManager() + .createVirtualDisplay("scrcpy", inputSize.getWidth(), inputSize.getHeight(), displayId, surface); + } else { + virtualDisplay.setSurface(surface); + virtualDisplay.resize(inputSize.getWidth(), inputSize.getHeight(), displayInfo.getDpi()); + } virtualDisplayId = virtualDisplay.getDisplay().getDisplayId(); // The positions are relative to the virtual display, not the original display (so use inputSize, not deviceSize!) @@ -167,7 +163,9 @@ public class ScreenCapture extends DisplayCapture { Ln.d("Display: using DisplayManager API"); } catch (Exception displayManagerException) { try { - display = createDisplay(); + if (display == null) { + display = createDisplay(); + } Size deviceSize = displayInfo.getSize(); int layerStack = displayInfo.getLayerStack();