Reimplement lock orientation using transforms

Reimplement the --lock-video-orientation feature using affine
transforms.

Fixes #4011 <https://github.com/Genymobile/scrcpy/issues/4011>
PR #5455 <https://github.com/Genymobile/scrcpy/pull/5455>
This commit is contained in:
Romain Vimont
2024-11-10 16:21:59 +01:00
parent 9fb0a3dac1
commit 06385ce83b
2 changed files with 27 additions and 0 deletions

View File

@@ -35,6 +35,7 @@ public class ScreenCapture extends SurfaceCapture {
private final int displayId;
private int maxSize;
private final Rect crop;
private int lockVideoOrientation;
private DisplayInfo displayInfo;
private Size videoSize;
@@ -64,6 +65,7 @@ public class ScreenCapture extends SurfaceCapture {
assert displayId != Device.DISPLAY_ID_NONE;
this.maxSize = options.getMaxSize();
this.crop = options.getCrop();
this.lockVideoOrientation = options.getLockVideoOrientation();
}
@Override
@@ -136,6 +138,11 @@ public class ScreenCapture extends SurfaceCapture {
Size displaySize = displayInfo.getSize();
setSessionDisplaySize(displaySize);
if (lockVideoOrientation == Device.LOCK_VIDEO_ORIENTATION_INITIAL) {
// The user requested to lock the video orientation to the current orientation
lockVideoOrientation = displayInfo.getRotation();
}
VideoFilter filter = new VideoFilter(displaySize);
if (crop != null) {
@@ -143,6 +150,10 @@ public class ScreenCapture extends SurfaceCapture {
filter.addCrop(crop, transposed);
}
if (lockVideoOrientation != Device.LOCK_VIDEO_ORIENTATION_UNLOCKED) {
filter.addLockVideoOrientation(lockVideoOrientation, displayInfo.getRotation());
}
transform = filter.getInverseTransform();
videoSize = filter.getOutputSize().limit(maxSize).round8();
}