1
0
mirror of https://github.com/godotengine/godot.git synced 2025-12-05 17:15:09 +00:00

openxr: Sync with upstream 1.0.30

This commit is contained in:
Rémi Verschelde
2023-09-30 13:01:45 +02:00
parent fd33c7b32f
commit 94810115fe
20 changed files with 485 additions and 123 deletions

View File

@@ -1,5 +0,0 @@
# Copyright (c) 2020 The Khronos Group Inc.
#
# SPDX-License-Identifier: Apache-2.0
!openxr_loader_for_android.pom

View File

@@ -237,21 +237,23 @@ XrResult ApiLayerInterface::LoadApiLayers(const std::string& openxr_command, uin
for (const auto& layer_name : enabled_explicit_api_layer_names) {
bool found_this_layer = false;
for (auto it = explicit_layer_manifest_files.begin(); it != explicit_layer_manifest_files.end();) {
bool erased_layer_manifest_file = false;
if (layers_already_found.count(layer_name) > 0) {
found_this_layer = true;
} else {
for (auto it = explicit_layer_manifest_files.begin(); it != explicit_layer_manifest_files.end();) {
bool erased_layer_manifest_file = false;
if (layers_already_found.count(layer_name) > 0) {
found_this_layer = true;
} else if (layer_name == (*it)->LayerName()) {
found_this_layer = true;
layers_already_found.insert(layer_name);
enabled_layer_manifest_files_in_init_order.push_back(std::move(*it));
it = explicit_layer_manifest_files.erase(it);
erased_layer_manifest_file = true;
}
if (layer_name == (*it)->LayerName()) {
found_this_layer = true;
layers_already_found.insert(layer_name);
enabled_layer_manifest_files_in_init_order.push_back(std::move(*it));
it = explicit_layer_manifest_files.erase(it);
erased_layer_manifest_file = true;
}
if (!erased_layer_manifest_file) {
it++;
if (!erased_layer_manifest_file) {
it++;
}
}
}

View File

@@ -19,7 +19,7 @@
#include "loader_logger.hpp"
#include "loader_platform.hpp"
#include "runtime_interface.hpp"
#include "xr_generated_dispatch_table.h"
#include "xr_generated_dispatch_table_core.h"
#include "xr_generated_loader.hpp"
#include <openxr/openxr.h>

View File

@@ -18,7 +18,7 @@
#include "loader_interfaces.h"
#include "loader_logger.hpp"
#include "runtime_interface.hpp"
#include "xr_generated_dispatch_table.h"
#include "xr_generated_dispatch_table_core.h"
#include "xr_generated_loader.hpp"
#include <openxr/openxr.h>

View File

@@ -274,16 +274,45 @@ static std::string GetXDGEnvAbsolute(const char *name, const char *fallback_path
return fallback_paths;
}
/// @param rt_dir_prefix Directory prefix with a trailing slash
static bool FindEitherActiveRuntimeFilename(const char *prefix_desc, const std::string &rt_dir_prefix, uint16_t major_version,
std::string &out) {
{
std::ostringstream oss;
oss << "Looking for active_runtime." XR_ARCH_ABI ".json or active_runtime.json in ";
oss << prefix_desc;
oss << ": ";
oss << rt_dir_prefix;
LoaderLogger::LogInfoMessage("", oss.str());
}
{
auto decorated_path = rt_dir_prefix + std::to_string(major_version) + "/active_runtime." XR_ARCH_ABI ".json";
if (FileSysUtilsPathExists(decorated_path)) {
out = decorated_path;
return true;
}
}
{
auto undecorated_path = rt_dir_prefix + std::to_string(major_version) + "/active_runtime.json";
if (FileSysUtilsPathExists(undecorated_path)) {
out = undecorated_path;
return true;
}
}
return false;
}
// Return the first instance of relative_path occurring in an XDG config dir according to standard
// precedence order.
static bool FindXDGConfigFile(const std::string &relative_path, std::string &out) {
out = GetXDGEnvHome("XDG_CONFIG_HOME", ".config");
if (!out.empty()) {
out += "/";
out += relative_path;
LoaderLogger::LogInfoMessage("", "Looking for " + relative_path + " in XDG_CONFIG_HOME: " + out);
if (FileSysUtilsPathExists(out)) {
static bool FindXDGConfigFile(const char *relative_dir, uint16_t major_version, std::string &out) {
const std::string message{"Looking for active_runtime." XR_ARCH_ABI ".json or active_runtime.json"};
std::string dir_prefix = GetXDGEnvHome("XDG_CONFIG_HOME", ".config");
if (!dir_prefix.empty()) {
dir_prefix += "/";
dir_prefix += relative_dir;
if (FindEitherActiveRuntimeFilename("XDG_CONFIG_HOME", dir_prefix, major_version, out)) {
return true;
}
}
@@ -294,29 +323,26 @@ static bool FindXDGConfigFile(const std::string &relative_path, std::string &out
if (path.empty()) {
continue;
}
out = path;
out += "/";
out += relative_path;
LoaderLogger::LogInfoMessage("", "Looking for " + relative_path + " in an entry of XDG_CONFIG_DIRS: " + out);
if (FileSysUtilsPathExists(out)) {
dir_prefix = std::move(path);
dir_prefix += "/";
dir_prefix += relative_dir;
if (FindEitherActiveRuntimeFilename("an entry of XDG_CONFIG_DIRS", dir_prefix, major_version, out)) {
return true;
}
}
out = SYSCONFDIR;
out += "/";
out += relative_path;
LoaderLogger::LogInfoMessage("", "Looking for " + relative_path + " in compiled-in SYSCONFDIR: " + out);
if (FileSysUtilsPathExists(out)) {
dir_prefix = SYSCONFDIR;
dir_prefix += "/";
dir_prefix += relative_dir;
if (FindEitherActiveRuntimeFilename("compiled-in SYSCONFDIR", dir_prefix, major_version, out)) {
return true;
}
#if defined(EXTRASYSCONFDIR)
out = EXTRASYSCONFDIR;
out += "/";
out += relative_path;
LoaderLogger::LogInfoMessage("", "Looking for " + relative_path + " in compiled-in EXTRASYSCONFDIR: " + out);
if (FileSysUtilsPathExists(out)) {
dir_prefix = EXTRASYSCONFDIR;
dir_prefix += "/";
dir_prefix += relative_dir;
if (FindEitherActiveRuntimeFilename("compiled-in EXTRASYSCONFDIR", dir_prefix, major_version, out)) {
return true;
}
#endif
@@ -632,9 +658,8 @@ XrResult RuntimeManifestFile::FindManifestFiles(std::vector<std::unique_ptr<Runt
LoaderLogger::LogInfoMessage("",
"RuntimeManifestFile::FindManifestFiles - using registry-specified runtime file " + filename);
#elif defined(XR_OS_LINUX)
const std::string relative_path =
"openxr/" + std::to_string(XR_VERSION_MAJOR(XR_CURRENT_API_VERSION)) + "/active_runtime.json";
if (!FindXDGConfigFile(relative_path, filename)) {
if (!FindXDGConfigFile("openxr/", XR_VERSION_MAJOR(XR_CURRENT_API_VERSION), filename)) {
LoaderLogger::LogErrorMessage(
"", "RuntimeManifestFile::FindManifestFiles - failed to determine active runtime file path for this environment");
return XR_ERROR_RUNTIME_UNAVAILABLE;

View File

@@ -13,7 +13,7 @@
#include "loader_interfaces.h"
#include "loader_logger.hpp"
#include "loader_platform.hpp"
#include "xr_generated_dispatch_table.h"
#include "xr_generated_dispatch_table_core.h"
#include <openxr/openxr.h>
@@ -29,6 +29,10 @@
#include "android_utilities.h"
#include <android/asset_manager_jni.h>
#include <json/value.h>
// Needed for the loader init struct
#include <xr_dependencies.h>
#include <openxr/openxr_platform.h>
#endif // XR_USE_PLATFORM_ANDROID
#ifdef XR_KHR_LOADER_INIT_SUPPORT
@@ -105,33 +109,22 @@ XrResult LoaderInitData::initialize(const XrLoaderInitInfoBaseHeaderKHR* info) {
if (cast_info->applicationContext == nullptr) {
return XR_ERROR_VALIDATION_FAILURE;
}
// Copy and store the JVM pointer and Android Context, ensuring the JVM is initialised.
_data = *cast_info;
jni::init((jni::JavaVM*)_data.applicationVM);
_data.next = nullptr;
JNIEnv* Env;
((jni::JavaVM*)(cast_info->applicationVM))->AttachCurrentThread(&Env, nullptr);
const jclass contextClass = Env->GetObjectClass((jobject)_data.applicationContext);
jni::init(static_cast<jni::JavaVM*>(_data.applicationVM));
const jni::Object context = jni::Object{static_cast<jni::jobject>(_data.applicationContext)};
const jmethodID getAssetsMethod = Env->GetMethodID(contextClass, "getAssets", "()Landroid/content/res/AssetManager;");
const jobject AssetManagerObject = Env->CallObjectMethod((jobject)_data.applicationContext, getAssetsMethod);
_android_asset_manager = AAssetManager_fromJava(Env, AssetManagerObject);
// Retrieve a reference to the Android AssetManager.
const auto assetManager = context.call<jni::Object>("getAssets()Landroid/content/res/AssetManager;");
_android_asset_manager = AAssetManager_fromJava(jni::env(), assetManager.getHandle());
// Retrieve the path to the native libraries.
const auto applicationContext = context.call<jni::Object>("getApplicationContext()Landroid/content/Context;");
const auto applicationInfo = context.call<jni::Object>("getApplicationInfo()Landroid/content/pm/ApplicationInfo;");
_native_library_path = applicationInfo.get<std::string>("nativeLibraryDir");
const jmethodID getApplicationContextMethod =
Env->GetMethodID(contextClass, "getApplicationContext", "()Landroid/content/Context;");
const jobject contextObject = Env->CallObjectMethod((jobject)_data.applicationContext, getApplicationContextMethod);
const jmethodID getApplicationInfoMethod =
Env->GetMethodID(contextClass, "getApplicationInfo", "()Landroid/content/pm/ApplicationInfo;");
const jobject applicationInfoObject = Env->CallObjectMethod(contextObject, getApplicationInfoMethod);
const jfieldID nativeLibraryDirField =
Env->GetFieldID(Env->GetObjectClass(applicationInfoObject), "nativeLibraryDir", "Ljava/lang/String;");
const jobject nativeLibraryDirObject = Env->GetObjectField(applicationInfoObject, nativeLibraryDirField);
const jmethodID getBytesMethod =
Env->GetMethodID(Env->GetObjectClass(nativeLibraryDirObject), "getBytes", "(Ljava/lang/String;)[B");
const auto bytesObject =
static_cast<jbyteArray>(Env->CallObjectMethod(nativeLibraryDirObject, getBytesMethod, Env->NewStringUTF("UTF-8")));
const size_t length = Env->GetArrayLength(bytesObject);
const jbyte* const bytes = Env->GetByteArrayElements(bytesObject, nullptr);
_native_library_path = std::string(reinterpret_cast<const char*>(bytes), length);
_initialized = true;
return XR_SUCCESS;
}

View File

@@ -36,7 +36,7 @@
#include "loader_logger.hpp"
#include "loader_platform.hpp"
#include "runtime_interface.hpp"
#include "xr_generated_dispatch_table.h"
#include "xr_generated_dispatch_table_core.h"
#include "xr_dependencies.h"
#include <openxr/openxr.h>