mirror of
https://github.com/Genymobile/scrcpy
synced 2024-12-27 01:22:09 +00:00
Move toUnsigned() to a Binary util class
PR #3369 <https://github.com/Genymobile/scrcpy/pull/3369>
This commit is contained in:
parent
3a66b5fd01
commit
5b8e9aa0e9
15
server/src/main/java/com/genymobile/scrcpy/Binary.java
Normal file
15
server/src/main/java/com/genymobile/scrcpy/Binary.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package com.genymobile.scrcpy;
|
||||||
|
|
||||||
|
public final class Binary {
|
||||||
|
private Binary() {
|
||||||
|
// not instantiable
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int toUnsigned(short value) {
|
||||||
|
return value & 0xffff;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int toUnsigned(byte value) {
|
||||||
|
return value & 0xff;
|
||||||
|
}
|
||||||
|
}
|
@ -103,7 +103,7 @@ public class ControlMessageReader {
|
|||||||
if (buffer.remaining() < INJECT_KEYCODE_PAYLOAD_LENGTH) {
|
if (buffer.remaining() < INJECT_KEYCODE_PAYLOAD_LENGTH) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int action = toUnsigned(buffer.get());
|
int action = Binary.toUnsigned(buffer.get());
|
||||||
int keycode = buffer.getInt();
|
int keycode = buffer.getInt();
|
||||||
int repeat = buffer.getInt();
|
int repeat = buffer.getInt();
|
||||||
int metaState = buffer.getInt();
|
int metaState = buffer.getInt();
|
||||||
@ -136,11 +136,11 @@ public class ControlMessageReader {
|
|||||||
if (buffer.remaining() < INJECT_TOUCH_EVENT_PAYLOAD_LENGTH) {
|
if (buffer.remaining() < INJECT_TOUCH_EVENT_PAYLOAD_LENGTH) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int action = toUnsigned(buffer.get());
|
int action = Binary.toUnsigned(buffer.get());
|
||||||
long pointerId = buffer.getLong();
|
long pointerId = buffer.getLong();
|
||||||
Position position = readPosition(buffer);
|
Position position = readPosition(buffer);
|
||||||
// 16 bits fixed-point
|
// 16 bits fixed-point
|
||||||
int pressureInt = toUnsigned(buffer.getShort());
|
int pressureInt = Binary.toUnsigned(buffer.getShort());
|
||||||
// convert it to a float between 0 and 1 (0x1p16f is 2^16 as float)
|
// convert it to a float between 0 and 1 (0x1p16f is 2^16 as float)
|
||||||
float pressure = pressureInt == 0xffff ? 1f : (pressureInt / 0x1p16f);
|
float pressure = pressureInt == 0xffff ? 1f : (pressureInt / 0x1p16f);
|
||||||
int buttons = buffer.getInt();
|
int buttons = buffer.getInt();
|
||||||
@ -162,7 +162,7 @@ public class ControlMessageReader {
|
|||||||
if (buffer.remaining() < BACK_OR_SCREEN_ON_LENGTH) {
|
if (buffer.remaining() < BACK_OR_SCREEN_ON_LENGTH) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int action = toUnsigned(buffer.get());
|
int action = Binary.toUnsigned(buffer.get());
|
||||||
return ControlMessage.createBackOrScreenOn(action);
|
return ControlMessage.createBackOrScreenOn(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -170,7 +170,7 @@ public class ControlMessageReader {
|
|||||||
if (buffer.remaining() < GET_CLIPBOARD_LENGTH) {
|
if (buffer.remaining() < GET_CLIPBOARD_LENGTH) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
int copyKey = toUnsigned(buffer.get());
|
int copyKey = Binary.toUnsigned(buffer.get());
|
||||||
return ControlMessage.createGetClipboard(copyKey);
|
return ControlMessage.createGetClipboard(copyKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,16 +198,8 @@ public class ControlMessageReader {
|
|||||||
private static Position readPosition(ByteBuffer buffer) {
|
private static Position readPosition(ByteBuffer buffer) {
|
||||||
int x = buffer.getInt();
|
int x = buffer.getInt();
|
||||||
int y = buffer.getInt();
|
int y = buffer.getInt();
|
||||||
int screenWidth = toUnsigned(buffer.getShort());
|
int screenWidth = Binary.toUnsigned(buffer.getShort());
|
||||||
int screenHeight = toUnsigned(buffer.getShort());
|
int screenHeight = Binary.toUnsigned(buffer.getShort());
|
||||||
return new Position(x, y, screenWidth, screenHeight);
|
return new Position(x, y, screenWidth, screenHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int toUnsigned(short value) {
|
|
||||||
return value & 0xffff;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int toUnsigned(byte value) {
|
|
||||||
return value & 0xff;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user