Skip to content

Commit

Permalink
Recreate the display on rotation
Browse files Browse the repository at this point in the history
On Android 14 (Pixel 8), a device rotation while the camera app was
running resulted in an incorrect capture.

Destroying and recreating the display fixes the issue.
  • Loading branch information
rom1v committed Nov 16, 2023
1 parent abcb100 commit 7e3b935
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions server/src/main/java/com/genymobile/scrcpy/ScreenCapture.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public ScreenCapture(Device device) {

@Override
public void init() {
display = createDisplay();
device.setRotationListener(this);
device.setFoldListener(this);
}
Expand All @@ -32,14 +31,21 @@ public void start(Surface surface) {
Rect unlockedVideoRect = screenInfo.getUnlockedVideoSize().toRect();
int videoRotation = screenInfo.getVideoRotation();
int layerStack = device.getLayerStack();

if (display != null) {
SurfaceControl.destroyDisplay(display);
}
display = createDisplay();
setDisplaySurface(display, surface, videoRotation, contentRect, unlockedVideoRect, layerStack);
}

@Override
public void release() {
device.setRotationListener(null);
device.setFoldListener(null);
SurfaceControl.destroyDisplay(display);
if (display != null) {
SurfaceControl.destroyDisplay(display);
}
}

@Override
Expand Down

0 comments on commit 7e3b935

Please sign in to comment.