Skip to content

Commit

Permalink
Do not recreate display on every rotation
Browse files Browse the repository at this point in the history
Refs #4840 <#4840>

DONOTMERGE This reintroduces the bugs fixed
7e3b935.
  • Loading branch information
rom1v committed Nov 3, 2024
1 parent f08a6d8 commit d73de2d
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 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 @@ -129,29 +129,28 @@ 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
positionMapper = new PositionMapper(videoSize, contentRect, 0);
Ln.d("Display: using DisplayManager API");
} catch (Exception displayManagerException) {
try {
display = createDisplay();
if (display == null) {
display = createDisplay();
}

Rect contentRect = screenInfo.getContentRect();

Expand Down

0 comments on commit d73de2d

Please sign in to comment.