mirror of https://github.com/Genymobile/scrcpy
Keep screen info in cache
Currently, we only use screen information (width, height, rotation) once at initialization, to send the device size to the client. To be able to scale mouse events, make it accessible in memory. For this purpose, replace the "static" DeviceUtil to a singleton Device, and update it on every screen rotation.hidpi
parent
d7b00a9bab
commit
11a60e5767
@ -0,0 +1,70 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.RemoteException;
|
||||
import android.view.IRotationWatcher;
|
||||
|
||||
import com.genymobile.scrcpy.wrappers.InputManager;
|
||||
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
||||
|
||||
public class Device {
|
||||
|
||||
public interface RotationListener {
|
||||
void onRotationChanged(int rotation);
|
||||
}
|
||||
|
||||
private static final Device INSTANCE = new Device();
|
||||
private final ServiceManager serviceManager = new ServiceManager();
|
||||
|
||||
private ScreenInfo screenInfo;
|
||||
private RotationListener rotationListener;
|
||||
|
||||
private Device() {
|
||||
screenInfo = readScreenInfo();
|
||||
registerRotationWatcher(new IRotationWatcher.Stub() {
|
||||
@Override
|
||||
public void onRotationChanged(int rotation) throws RemoteException {
|
||||
synchronized (Device.this) {
|
||||
// update screenInfo cache
|
||||
screenInfo = screenInfo.withRotation(rotation);
|
||||
|
||||
// notify
|
||||
if (rotationListener != null) {
|
||||
rotationListener.onRotationChanged(rotation);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static Device getInstance() {
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
public synchronized ScreenInfo getScreenInfo() {
|
||||
if (screenInfo == null) {
|
||||
screenInfo = readScreenInfo();
|
||||
}
|
||||
return screenInfo;
|
||||
}
|
||||
|
||||
private ScreenInfo readScreenInfo() {
|
||||
return serviceManager.getDisplayManager().getScreenInfo();
|
||||
}
|
||||
|
||||
public static String getDeviceName() {
|
||||
return Build.MODEL;
|
||||
}
|
||||
|
||||
public InputManager getInputManager() {
|
||||
return serviceManager.getInputManager();
|
||||
}
|
||||
|
||||
public void registerRotationWatcher(IRotationWatcher rotationWatcher) {
|
||||
serviceManager.getWindowManager().registerRotationWatcher(rotationWatcher);
|
||||
}
|
||||
|
||||
public synchronized void setRotationListener(RotationListener rotationListener) {
|
||||
this.rotationListener = rotationListener;
|
||||
}
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
package com.genymobile.scrcpy;
|
||||
|
||||
import android.os.Build;
|
||||
import android.view.IRotationWatcher;
|
||||
|
||||
import com.genymobile.scrcpy.wrappers.InputManager;
|
||||
import com.genymobile.scrcpy.wrappers.ServiceManager;
|
||||
|
||||
public class DeviceUtil {
|
||||
|
||||
private static final ServiceManager serviceManager = new ServiceManager();
|
||||
|
||||
public static ScreenInfo getScreenInfo() {
|
||||
return serviceManager.getDisplayManager().getScreenInfo();
|
||||
}
|
||||
|
||||
public static void registerRotationWatcher(IRotationWatcher rotationWatcher) {
|
||||
serviceManager.getWindowManager().registerRotationWatcher(rotationWatcher);
|
||||
}
|
||||
|
||||
public static String getDeviceName() {
|
||||
return Build.MODEL;
|
||||
}
|
||||
|
||||
public static InputManager getInputManager() {
|
||||
return serviceManager.getInputManager();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue