Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix incorrect capture when using DisplayManager API #4840

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 14 additions & 6 deletions server/src/main/java/com/genymobile/scrcpy/ScreenCapture.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ public void start(Surface surface) {
SurfaceControl.destroyDisplay(display);
display = null;
}
if (virtualDisplay != null) {
virtualDisplay.release();
virtualDisplay = null;
}

try {
display = createDisplay();
Expand All @@ -51,8 +47,20 @@ public void start(Surface surface) {
} catch (Exception surfaceControlException) {
Rect videoRect = screenInfo.getVideoSize().toRect();
try {
virtualDisplay = ServiceManager.getDisplayManager()
.createVirtualDisplay("scrcpy", videoRect.width(), videoRect.height(), device.getDisplayId(), surface);
if (virtualDisplay == null) {
// Do not release virtual display, to avoid displayId increase
virtualDisplay = ServiceManager.getDisplayManager()
.createVirtualDisplay("scrcpy", videoRect.width(), videoRect.height(), device.getDisplayId(), surface);
} else {
// Density doesn't matter since this virtual display is only used for mirroring.
virtualDisplay.resize(videoRect.width(), videoRect.height(), 1);
virtualDisplay.setSurface(surface);
}
// 'createVirtualDisplay' will copy the configuration of the original display (including the rotation),
// but 'videoRect' is already rotated according to the device rotation,
// so we need to freeze the rotation to 0 to avoid a double rotation
int displayId = virtualDisplay.getDisplay().getDisplayId();
ServiceManager.getWindowManager().freezeRotation(displayId, 0);
Ln.d("Display: using DisplayManager API");
} catch (Exception displayManagerException) {
Ln.e("Could not create display using SurfaceControl", surfaceControlException);
Expand Down