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 851563a
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 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 @@ -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;
Expand Down Expand Up @@ -129,29 +130,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 851563a

Please sign in to comment.