mirror of https://github.com/Genymobile/scrcpy
Reimplement lock orientation using transforms
Reimplement the --lock-video-orientation feature using affine transforms.
This commit is contained in:
parent
58c73504d4
commit
26d66a7c28
|
@ -35,6 +35,7 @@ public class ScreenCapture extends SurfaceCapture {
|
||||||
private final int displayId;
|
private final int displayId;
|
||||||
private int maxSize;
|
private int maxSize;
|
||||||
private final Rect crop;
|
private final Rect crop;
|
||||||
|
private int lockVideoOrientation;
|
||||||
|
|
||||||
private DisplayInfo displayInfo;
|
private DisplayInfo displayInfo;
|
||||||
private Size videoSize;
|
private Size videoSize;
|
||||||
|
@ -64,6 +65,7 @@ public class ScreenCapture extends SurfaceCapture {
|
||||||
assert displayId != Device.DISPLAY_ID_NONE;
|
assert displayId != Device.DISPLAY_ID_NONE;
|
||||||
this.maxSize = options.getMaxSize();
|
this.maxSize = options.getMaxSize();
|
||||||
this.crop = options.getCrop();
|
this.crop = options.getCrop();
|
||||||
|
this.lockVideoOrientation = options.getLockVideoOrientation();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -136,6 +138,11 @@ public class ScreenCapture extends SurfaceCapture {
|
||||||
Size displaySize = displayInfo.getSize();
|
Size displaySize = displayInfo.getSize();
|
||||||
setSessionDisplaySize(displaySize);
|
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);
|
VideoFilter filter = new VideoFilter(displaySize);
|
||||||
|
|
||||||
if (crop != null) {
|
if (crop != null) {
|
||||||
|
@ -143,6 +150,10 @@ public class ScreenCapture extends SurfaceCapture {
|
||||||
filter.addCrop(crop, transposed);
|
filter.addCrop(crop, transposed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lockVideoOrientation != Device.LOCK_VIDEO_ORIENTATION_UNLOCKED) {
|
||||||
|
filter.addLockVideoOrientation(lockVideoOrientation, displayInfo.getRotation());
|
||||||
|
}
|
||||||
|
|
||||||
transform = filter.getInverseTransform();
|
transform = filter.getInverseTransform();
|
||||||
videoSize = filter.getOutputSize().limit(maxSize).round8();
|
videoSize = filter.getOutputSize().limit(maxSize).round8();
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,4 +61,20 @@ public class VideoFilter {
|
||||||
transform = AffineMatrix.reframe(x, y, w, h).multiply(transform);
|
transform = AffineMatrix.reframe(x, y, w, h).multiply(transform);
|
||||||
size = new Size(crop.width(), crop.height());
|
size = new Size(crop.width(), crop.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addRotation(int ccwRotation) {
|
||||||
|
if (ccwRotation == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
transform = AffineMatrix.rotateOrtho(ccwRotation).multiply(transform);
|
||||||
|
if (ccwRotation % 2 != 0) {
|
||||||
|
size = size.rotate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addLockVideoOrientation(int lockVideoOrientation, int displayRotation) {
|
||||||
|
int ccwRotation = (4 + lockVideoOrientation - displayRotation) % 4;
|
||||||
|
addRotation(ccwRotation);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue