hack_virtual_display
This commit is contained in:
parent
9434718970
commit
5a2b929aac
@ -10,6 +10,7 @@ import com.genymobile.scrcpy.wrappers.ServiceManager;
|
||||
import com.genymobile.scrcpy.wrappers.SurfaceControl;
|
||||
|
||||
import android.graphics.Rect;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.hardware.display.VirtualDisplay;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
@ -26,6 +27,7 @@ public class ScreenCapture extends SurfaceCapture {
|
||||
private final Rect crop;
|
||||
private final int lockVideoOrientation;
|
||||
private int layerStack;
|
||||
private int dpi;
|
||||
|
||||
private Size deviceSize;
|
||||
private ScreenInfo screenInfo;
|
||||
@ -56,6 +58,7 @@ public class ScreenCapture extends SurfaceCapture {
|
||||
screenInfo = ScreenInfo.computeScreenInfo(displayInfo.getRotation(), deviceSize, crop, maxSize, lockVideoOrientation);
|
||||
device.setScreenInfo(screenInfo);
|
||||
layerStack = displayInfo.getLayerStack();
|
||||
dpi = displayInfo.getLogicalDensityDpi();
|
||||
|
||||
if (displayId == 0) {
|
||||
rotationWatcher = new IRotationWatcher.Stub() {
|
||||
@ -119,8 +122,11 @@ public class ScreenCapture extends SurfaceCapture {
|
||||
|
||||
try {
|
||||
Rect videoRect = screenInfo.getVideoSize().toRect();
|
||||
int flags = DisplayManager.VIRTUAL_DISPLAY_FLAG_PUBLIC | DisplayManager.VIRTUAL_DISPLAY_FLAG_OWN_CONTENT_ONLY | (1
|
||||
<< 6) /* DisplayManager.VIRTUAL_DISPLAY_FLAG_SUPPORT_TOUCH */ | 1 << 8 | 1 << 9 | 1 << 10 | 1 << 11 | 1 << 12 | 1 << 13 | 1 << 14;
|
||||
|
||||
virtualDisplay = ServiceManager.getDisplayManager()
|
||||
.createVirtualDisplay("scrcpy", videoRect.width(), videoRect.height(), displayId, surface);
|
||||
.createVirtualDisplay("scrcpy", videoRect.width(), videoRect.height(), dpi, surface, flags);
|
||||
device.setVirtualDisplayId(virtualDisplay.getDisplay().getDisplayId());
|
||||
Ln.d("Display: using DisplayManager API");
|
||||
} catch (Exception displayManagerException) {
|
||||
|
@ -1,15 +1,18 @@
|
||||
package com.genymobile.scrcpy.wrappers;
|
||||
|
||||
import com.genymobile.scrcpy.FakeContext;
|
||||
import com.genymobile.scrcpy.device.DisplayInfo;
|
||||
import com.genymobile.scrcpy.device.Size;
|
||||
import com.genymobile.scrcpy.util.Command;
|
||||
import com.genymobile.scrcpy.util.Ln;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.hardware.display.VirtualDisplay;
|
||||
import android.view.Display;
|
||||
import android.view.Surface;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.regex.Matcher;
|
||||
@ -117,13 +120,17 @@ public final class DisplayManager {
|
||||
private Method getCreateVirtualDisplayMethod() throws NoSuchMethodException {
|
||||
if (createVirtualDisplayMethod == null) {
|
||||
createVirtualDisplayMethod = android.hardware.display.DisplayManager.class
|
||||
.getMethod("createVirtualDisplay", String.class, int.class, int.class, int.class, Surface.class);
|
||||
.getMethod("createVirtualDisplay", String.class, int.class, int.class, int.class, Surface.class, int.class);
|
||||
}
|
||||
return createVirtualDisplayMethod;
|
||||
}
|
||||
|
||||
public VirtualDisplay createVirtualDisplay(String name, int width, int height, int displayIdToMirror, Surface surface) throws Exception {
|
||||
Method method = getCreateVirtualDisplayMethod();
|
||||
return (VirtualDisplay) method.invoke(null, name, width, height, displayIdToMirror, surface);
|
||||
public VirtualDisplay createVirtualDisplay(String name, int width, int height, int dpi, Surface surface, int flags) throws Exception {
|
||||
//Method method = getCreateVirtualDisplayMethod();
|
||||
Constructor<android.hardware.display.DisplayManager> ctor = android.hardware.display.DisplayManager.class.getDeclaredConstructor(Context.class);
|
||||
ctor.setAccessible(true);
|
||||
android.hardware.display.DisplayManager dm = ctor.newInstance(FakeContext.get());
|
||||
return dm.createVirtualDisplay(name, width, height, dpi, surface, flags);
|
||||
//return (VirtualDisplay) method.invoke(null, name, width, height, dpi, surface, flags);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user