mirror of https://github.com/Genymobile/scrcpy
Merge branch 'Genymobile:master' into master
commit
f00314ea4c
@ -0,0 +1,91 @@
|
||||
#include "common.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
#include "options.h"
|
||||
|
||||
static void test_transforms(void) {
|
||||
#define O(X) SC_ORIENTATION_ ## X
|
||||
#define ASSERT_TRANSFORM(SRC, TR, RES) \
|
||||
assert(sc_orientation_apply(O(SRC), O(TR)) == O(RES));
|
||||
|
||||
ASSERT_TRANSFORM(0, 0, 0);
|
||||
ASSERT_TRANSFORM(0, 90, 90);
|
||||
ASSERT_TRANSFORM(0, 180, 180);
|
||||
ASSERT_TRANSFORM(0, 270, 270);
|
||||
ASSERT_TRANSFORM(0, FLIP_0, FLIP_0);
|
||||
ASSERT_TRANSFORM(0, FLIP_90, FLIP_90);
|
||||
ASSERT_TRANSFORM(0, FLIP_180, FLIP_180);
|
||||
ASSERT_TRANSFORM(0, FLIP_270, FLIP_270);
|
||||
|
||||
ASSERT_TRANSFORM(90, 0, 90);
|
||||
ASSERT_TRANSFORM(90, 90, 180);
|
||||
ASSERT_TRANSFORM(90, 180, 270);
|
||||
ASSERT_TRANSFORM(90, 270, 0);
|
||||
ASSERT_TRANSFORM(90, FLIP_0, FLIP_270);
|
||||
ASSERT_TRANSFORM(90, FLIP_90, FLIP_0);
|
||||
ASSERT_TRANSFORM(90, FLIP_180, FLIP_90);
|
||||
ASSERT_TRANSFORM(90, FLIP_270, FLIP_180);
|
||||
|
||||
ASSERT_TRANSFORM(180, 0, 180);
|
||||
ASSERT_TRANSFORM(180, 90, 270);
|
||||
ASSERT_TRANSFORM(180, 180, 0);
|
||||
ASSERT_TRANSFORM(180, 270, 90);
|
||||
ASSERT_TRANSFORM(180, FLIP_0, FLIP_180);
|
||||
ASSERT_TRANSFORM(180, FLIP_90, FLIP_270);
|
||||
ASSERT_TRANSFORM(180, FLIP_180, FLIP_0);
|
||||
ASSERT_TRANSFORM(180, FLIP_270, FLIP_90);
|
||||
|
||||
ASSERT_TRANSFORM(270, 0, 270);
|
||||
ASSERT_TRANSFORM(270, 90, 0);
|
||||
ASSERT_TRANSFORM(270, 180, 90);
|
||||
ASSERT_TRANSFORM(270, 270, 180);
|
||||
ASSERT_TRANSFORM(270, FLIP_0, FLIP_90);
|
||||
ASSERT_TRANSFORM(270, FLIP_90, FLIP_180);
|
||||
ASSERT_TRANSFORM(270, FLIP_180, FLIP_270);
|
||||
ASSERT_TRANSFORM(270, FLIP_270, FLIP_0);
|
||||
|
||||
ASSERT_TRANSFORM(FLIP_0, 0, FLIP_0);
|
||||
ASSERT_TRANSFORM(FLIP_0, 90, FLIP_90);
|
||||
ASSERT_TRANSFORM(FLIP_0, 180, FLIP_180);
|
||||
ASSERT_TRANSFORM(FLIP_0, 270, FLIP_270);
|
||||
ASSERT_TRANSFORM(FLIP_0, FLIP_0, 0);
|
||||
ASSERT_TRANSFORM(FLIP_0, FLIP_90, 90);
|
||||
ASSERT_TRANSFORM(FLIP_0, FLIP_180, 180);
|
||||
ASSERT_TRANSFORM(FLIP_0, FLIP_270, 270);
|
||||
|
||||
ASSERT_TRANSFORM(FLIP_90, 0, FLIP_90);
|
||||
ASSERT_TRANSFORM(FLIP_90, 90, FLIP_180);
|
||||
ASSERT_TRANSFORM(FLIP_90, 180, FLIP_270);
|
||||
ASSERT_TRANSFORM(FLIP_90, 270, FLIP_0);
|
||||
ASSERT_TRANSFORM(FLIP_90, FLIP_0, 270);
|
||||
ASSERT_TRANSFORM(FLIP_90, FLIP_90, 0);
|
||||
ASSERT_TRANSFORM(FLIP_90, FLIP_180, 90);
|
||||
ASSERT_TRANSFORM(FLIP_90, FLIP_270, 180);
|
||||
|
||||
ASSERT_TRANSFORM(FLIP_180, 0, FLIP_180);
|
||||
ASSERT_TRANSFORM(FLIP_180, 90, FLIP_270);
|
||||
ASSERT_TRANSFORM(FLIP_180, 180, FLIP_0);
|
||||
ASSERT_TRANSFORM(FLIP_180, 270, FLIP_90);
|
||||
ASSERT_TRANSFORM(FLIP_180, FLIP_0, 180);
|
||||
ASSERT_TRANSFORM(FLIP_180, FLIP_90, 270);
|
||||
ASSERT_TRANSFORM(FLIP_180, FLIP_180, 0);
|
||||
ASSERT_TRANSFORM(FLIP_180, FLIP_270, 90);
|
||||
|
||||
ASSERT_TRANSFORM(FLIP_270, 0, FLIP_270);
|
||||
ASSERT_TRANSFORM(FLIP_270, 90, FLIP_0);
|
||||
ASSERT_TRANSFORM(FLIP_270, 180, FLIP_90);
|
||||
ASSERT_TRANSFORM(FLIP_270, 270, FLIP_180);
|
||||
ASSERT_TRANSFORM(FLIP_270, FLIP_0, 90);
|
||||
ASSERT_TRANSFORM(FLIP_270, FLIP_90, 180);
|
||||
ASSERT_TRANSFORM(FLIP_270, FLIP_180, 270);
|
||||
ASSERT_TRANSFORM(FLIP_270, FLIP_270, 0);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
(void) argc;
|
||||
(void) argv;
|
||||
|
||||
test_transforms();
|
||||
return 0;
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
@ -0,0 +1,80 @@
|
||||
package com.genymobile.scrcpy.wrappers;
|
||||
|
||||
import com.genymobile.scrcpy.Ln;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.os.Build;
|
||||
import android.os.IBinder;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@SuppressLint({"PrivateApi", "SoonBlockedPrivateApi", "BlockedPrivateApi"})
|
||||
@TargetApi(Build.VERSION_CODES.UPSIDE_DOWN_CAKE)
|
||||
public final class DisplayControl {
|
||||
|
||||
private static final Class<?> CLASS;
|
||||
|
||||
static {
|
||||
Class<?> displayControlClass = null;
|
||||
try {
|
||||
Class<?> classLoaderFactoryClass = Class.forName("com.android.internal.os.ClassLoaderFactory");
|
||||
Method createClassLoaderMethod = classLoaderFactoryClass.getDeclaredMethod("createClassLoader", String.class, String.class, String.class,
|
||||
ClassLoader.class, int.class, boolean.class, String.class);
|
||||
ClassLoader classLoader = (ClassLoader) createClassLoaderMethod.invoke(null, "/system/framework/services.jar", null, null,
|
||||
ClassLoader.getSystemClassLoader(), 0, true, null);
|
||||
|
||||
displayControlClass = classLoader.loadClass("com.android.server.display.DisplayControl");
|
||||
|
||||
Method loadMethod = Runtime.class.getDeclaredMethod("loadLibrary0", Class.class, String.class);
|
||||
loadMethod.setAccessible(true);
|
||||
loadMethod.invoke(Runtime.getRuntime(), displayControlClass, "android_servers");
|
||||
} catch (Throwable e) {
|
||||
Ln.e("Could not initialize DisplayControl", e);
|
||||
// Do not throw an exception here, the methods will fail when they are called
|
||||
}
|
||||
CLASS = displayControlClass;
|
||||
}
|
||||
|
||||
private static Method getPhysicalDisplayTokenMethod;
|
||||
private static Method getPhysicalDisplayIdsMethod;
|
||||
|
||||
private DisplayControl() {
|
||||
// only static methods
|
||||
}
|
||||
|
||||
private static Method getGetPhysicalDisplayTokenMethod() throws NoSuchMethodException {
|
||||
if (getPhysicalDisplayTokenMethod == null) {
|
||||
getPhysicalDisplayTokenMethod = CLASS.getMethod("getPhysicalDisplayToken", long.class);
|
||||
}
|
||||
return getPhysicalDisplayTokenMethod;
|
||||
}
|
||||
|
||||
public static IBinder getPhysicalDisplayToken(long physicalDisplayId) {
|
||||
try {
|
||||
Method method = getGetPhysicalDisplayTokenMethod();
|
||||
return (IBinder) method.invoke(null, physicalDisplayId);
|
||||
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
||||
Ln.e("Could not invoke method", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private static Method getGetPhysicalDisplayIdsMethod() throws NoSuchMethodException {
|
||||
if (getPhysicalDisplayIdsMethod == null) {
|
||||
getPhysicalDisplayIdsMethod = CLASS.getMethod("getPhysicalDisplayIds");
|
||||
}
|
||||
return getPhysicalDisplayIdsMethod;
|
||||
}
|
||||
|
||||
public static long[] getPhysicalDisplayIds() {
|
||||
try {
|
||||
Method method = getGetPhysicalDisplayIdsMethod();
|
||||
return (long[]) method.invoke(null);
|
||||
} catch (InvocationTargetException | IllegalAccessException | NoSuchMethodException e) {
|
||||
Ln.e("Could not invoke method", e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue