From 63307aec2e5cdf3443703681a0cd3adb1037e740 Mon Sep 17 00:00:00 2001 From: Lubos Date: Thu, 21 Mar 2024 12:29:22 +0100 Subject: [PATCH] OpenXR - One APK for Android and standalone VR --- Common/VR/PPSSPPVR.cpp | 9 ++++-- Common/VR/PPSSPPVR.h | 1 + android/AndroidManifest.xml | 6 ++++ android/VRManifest.xml | 22 ------------- android/build.gradle | 32 +++---------------- android/jni/app-android.cpp | 7 ++-- .../src/org/ppsspp/ppsspp/NativeActivity.java | 13 ++++++-- 7 files changed, 33 insertions(+), 57 deletions(-) delete mode 100644 android/VRManifest.xml diff --git a/Common/VR/PPSSPPVR.cpp b/Common/VR/PPSSPPVR.cpp index 84c76e970b..8386f471d9 100644 --- a/Common/VR/PPSSPPVR.cpp +++ b/Common/VR/PPSSPPVR.cpp @@ -42,6 +42,7 @@ static std::map pspKeys; // key can be virtual, so not using the enu static int vr3DGeometryCount = 0; static long vrCompat[VR_COMPAT_MAX]; +static bool vrEnabled = false; static bool vrFlatForced = false; static bool vrFlatGame = false; static double vrFov[2] = {}; @@ -129,10 +130,8 @@ VR app flow integration */ bool IsVREnabled() { - // For now, let the OPENXR build flag control enablement. - // This will change. #ifdef OPENXR - return true; + return vrEnabled; #else return false; #endif @@ -205,6 +204,10 @@ void SetVRCallbacks(void (*axis)(const AxisInput *axis, size_t count), bool(*key cbNativeTouch = touch; } +void SetVREnabled(bool enabled) { + vrEnabled = enabled; +} + /* ================================================================================ diff --git a/Common/VR/PPSSPPVR.h b/Common/VR/PPSSPPVR.h index b78000e4e1..11455ed83c 100644 --- a/Common/VR/PPSSPPVR.h +++ b/Common/VR/PPSSPPVR.h @@ -33,6 +33,7 @@ void InitVROnAndroid(void* vm, void* activity, const char* system, int version, void EnterVR(bool firstStart, void* vulkanContext); void GetVRResolutionPerEye(int* width, int* height); void SetVRCallbacks(void(*axis)(const AxisInput *axis, size_t count), bool(*key)(const KeyInput &key), void(*touch)(const TouchInput &touch)); +void SetVREnabled(bool enabled); // VR input integration void SetVRAppMode(VRAppMode mode); diff --git a/android/AndroidManifest.xml b/android/AndroidManifest.xml index a073d82392..367648925a 100644 --- a/android/AndroidManifest.xml +++ b/android/AndroidManifest.xml @@ -16,6 +16,8 @@ + + @@ -116,6 +118,10 @@ + + + + diff --git a/android/VRManifest.xml b/android/VRManifest.xml deleted file mode 100644 index dc1a3aa1eb..0000000000 --- a/android/VRManifest.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - diff --git a/android/build.gradle b/android/build.gradle index 157ca6ca14..91cd9c3a35 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -109,9 +109,6 @@ android { gold { res.srcDirs = ['gold/res'] } - vr { - manifest.srcFile 'VRManifest.xml' - } } productFlavors { normal { @@ -124,7 +121,8 @@ android { '-DANDROID_PLATFORM=android-16', '-DANDROID_TOOLCHAIN=clang', '-DANDROID_CPP_FEATURES=', - '-DANDROID_STL=c++_static' + '-DANDROID_STL=c++_static', + '-DOPENXR=TRUE' } } ndk { @@ -143,31 +141,12 @@ android { '-DANDROID_CPP_FEATURES=', '-DANDROID_STL=c++_static', '-DANDROID_ARM_NEON=TRUE', - '-DGOLD=TRUE' - } - } - ndk { - abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64' - } - } - vr { - applicationId 'org.ppsspp.ppssppvr' - dimension "variant" - targetSdkVersion 29 // Do not upgrade this, we depend on not requiring scoped storage on Oculus. - externalNativeBuild { - cmake { - // Available arguments listed at https://developer.android.com/ndk/guides/cmake.html - arguments '-DANDROID=true', - '-DANDROID_PLATFORM=android-16', - '-DANDROID_TOOLCHAIN=clang', - '-DANDROID_CPP_FEATURES=', - '-DANDROID_STL=c++_static', - '-DANDROID_ARM_NEON=TRUE', + '-DGOLD=TRUE', '-DOPENXR=TRUE' } } ndk { - abiFilters 'arm64-v8a' + abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86_64' } } } @@ -177,9 +156,6 @@ android { 'normalOptimized', // for testing 'normalRelease', // for Google Play releases 'goldRelease', // for Google Play releases - 'vrDebug', // for VR debugging - 'vrOptimized', // for VR testing - 'vrRelease', // for VR releases ] variant.setIgnore(!needed) } diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 6dcb3d79a5..81ac9e08b9 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -508,12 +508,12 @@ bool System_GetPropertyBool(SystemProperty prop) { case SYSPROP_HAS_FILE_BROWSER: // It's only really needed with scoped storage, but why not make it available // as far back as possible - works just fine. - return (androidVersion >= 19) && (deviceType != DEVICE_TYPE_VR); // when ACTION_OPEN_DOCUMENT was added + return (androidVersion >= 19); // when ACTION_OPEN_DOCUMENT was added case SYSPROP_HAS_FOLDER_BROWSER: // Uses OPEN_DOCUMENT_TREE to let you select a folder. // Doesn't actually mean it's usable though, in many early versions of Android // this dialog is complete garbage and only lets you select subfolders of the Downloads folder. - return (androidVersion >= 21) && (deviceType != DEVICE_TYPE_VR); // when ACTION_OPEN_DOCUMENT_TREE was added + return (androidVersion >= 21); // when ACTION_OPEN_DOCUMENT_TREE was added case SYSPROP_SUPPORTS_OPEN_FILE_IN_EDITOR: return false; // Update if we add support in FileUtil.cpp: OpenFileInEditor case SYSPROP_APP_GOLD: @@ -733,6 +733,9 @@ extern "C" void Java_org_ppsspp_ppsspp_NativeApp_init exitRenderLoop = false; androidVersion = jAndroidVersion; deviceType = jdeviceType; + if (deviceType == DEVICE_TYPE_VR) { + SetVREnabled(true); + } Path apkPath(GetJavaString(env, japkpath)); g_VFS.Register("", ZipFileReader::Create(apkPath, "assets/")); diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index 9f68f904d1..45150e7c79 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -615,7 +615,7 @@ public abstract class NativeActivity extends Activity { if (javaGL) { mGLSurfaceView = new NativeGLView(this); nativeRenderer = new NativeRenderer(this); - mGLSurfaceView.setEGLContextClientVersion(isVRDevice() ? 3 : 2); + mGLSurfaceView.setEGLContextClientVersion(2); sizeManager.setSurfaceView(mGLSurfaceView); // Setup the GLSurface and ask android for the correct @@ -1670,6 +1670,15 @@ public abstract class NativeActivity extends Activity { } public static boolean isVRDevice() { - return BuildConfig.FLAVOR.startsWith("vr"); + String manufacturer = Build.MANUFACTURER; + if (manufacturer.compareToIgnoreCase("meta") == 0) { + return true; + } else if (manufacturer.compareToIgnoreCase("oculus") == 0) { + return true; + } else if (manufacturer.compareToIgnoreCase("pico") == 0) { + return true; + } else { + return false; + } } }