Skip to content

Display and control your Android device

Extract video size computation

Romain Vimont820cd2bb5414
diff --git a/server/src/main/java/com/genymobile/scrcpy/Device.java b/server/src/main/java/com/genymobile/scrcpy/Device.java
index 07c15e2b..b9b8bb71 100644
--- a/server/src/main/java/com/genymobile/scrcpy/Device.java
+++ b/server/src/main/java/com/genymobile/scrcpy/Device.java
@@ -40,18 +40,23 @@ public final class Device {
return screenInfo;
}
- @SuppressWarnings("checkstyle:MagicNumber")
private ScreenInfo computeScreenInfo(int maxSize) {
+ DisplayInfo displayInfo = serviceManager.getDisplayManager().getDisplayInfo();
+ boolean rotated = (displayInfo.getRotation() & 1) != 0;
+ Size deviceSize = displayInfo.getSize();
+ Size videoSize = computeVideoSize(deviceSize, maxSize);
+ return new ScreenInfo(deviceSize, videoSize, rotated);
+ }
+
+ @SuppressWarnings("checkstyle:MagicNumber")
+ private static Size computeVideoSize(Size inputSize, int maxSize) {
// Compute the video size and the padding of the content inside this video.
// Principle:
// - scale down the great side of the screen to maxSize (if necessary);
// - scale down the other side so that the aspect ratio is preserved;
// - round this value to the nearest multiple of 8 (H.264 only accepts multiples of 8)
- DisplayInfo displayInfo = serviceManager.getDisplayManager().getDisplayInfo();
- boolean rotated = (displayInfo.getRotation() & 1) != 0;
- Size deviceSize = displayInfo.getSize();
- int w = deviceSize.getWidth() & ~7; // in case it's not a multiple of 8
- int h = deviceSize.getHeight() & ~7;
+ int w = inputSize.getWidth() & ~7; // in case it's not a multiple of 8
+ int h = inputSize.getHeight() & ~7;
if (maxSize > 0) {
if (BuildConfig.DEBUG && maxSize % 8 != 0) {
throw new AssertionError("Max size must be a multiple of 8");
@@ -68,8 +73,7 @@ public final class Device {
w = portrait ? minor : major;
h = portrait ? major : minor;
}
- Size videoSize = new Size(w, h);
- return new ScreenInfo(deviceSize, videoSize, rotated);
+ return new Size(w, h);
}
public Point getPhysicalPoint(Position position) {