Do not recreate display on every rotation

This semantically reverts 7e3b935932.

The issue seems to be fixed if setSurface() is called before resize() on
the virtual display.

Refs #4840 <https://github.com/Genymobile/scrcpy/pull/4840>
This commit is contained in:
Romain Vimont 2024-11-15 18:59:44 +01:00
parent 532fcf91f8
commit 8c1cf2d78a
1 changed files with 10 additions and 12 deletions

View File

@ -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();