Skip to content

Commit

Permalink
Do not recreate display on every rotation
Browse files Browse the repository at this point in the history
This semantically reverts 7e3b935.

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

Refs #4840 <#4840>
  • Loading branch information
rom1v committed Nov 16, 2024
1 parent 8a0bb72 commit 5eaf072
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions server/src/main/java/com/genymobile/scrcpy/video/ScreenCapture.java
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,6 @@ public void prepare() throws ConfigurationException {

@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
Expand All @@ -158,16 +149,23 @@ public void start(Surface surface) throws IOException {
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!)
positionMapper = PositionMapper.create(videoSize, transform, inputSize);
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();
Expand Down

0 comments on commit 5eaf072

Please sign in to comment.