From 54149b12b91fe85a7f2cfbd3f07e347c8804171e Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Tue, 18 Aug 2020 15:33:21 -0500 Subject: [PATCH] st/oxr: Handle the android extension --- doc/changes/state_trackers/mr.492.md | 1 + scripts/generate_oxr_ext_support.py | 1 + src/xrt/state_trackers/oxr/oxr_api_instance.c | 62 +++++++++++++++++++ .../oxr/oxr_extension_support.h | 13 ++++ src/xrt/state_trackers/oxr/oxr_instance.c | 17 +++++ 5 files changed, 94 insertions(+) create mode 100644 doc/changes/state_trackers/mr.492.md diff --git a/doc/changes/state_trackers/mr.492.md b/doc/changes/state_trackers/mr.492.md new file mode 100644 index 000000000..21e3e4133 --- /dev/null +++ b/doc/changes/state_trackers/mr.492.md @@ -0,0 +1 @@ +OpenXR: Enable the `XR_KHR_android_create_instance` extension. diff --git a/scripts/generate_oxr_ext_support.py b/scripts/generate_oxr_ext_support.py index 8e850a4c1..784c11235 100755 --- a/scripts/generate_oxr_ext_support.py +++ b/scripts/generate_oxr_ext_support.py @@ -10,6 +10,7 @@ from pathlib import Path # the first one must be the name of the extension itself. # Keep sorted. EXTENSIONS = ( + ['XR_KHR_android_create_instance', 'XR_USE_PLATFORM_ANDROID'], ['XR_KHR_convert_timespec_time', 'XR_USE_TIMESPEC'], ['XR_KHR_opengl_enable', 'XR_USE_GRAPHICS_API_OPENGL'], ['XR_KHR_opengl_es_enable', 'XR_USE_GRAPHICS_API_OPENGL_ES'], diff --git a/src/xrt/state_trackers/oxr/oxr_api_instance.c b/src/xrt/state_trackers/oxr/oxr_api_instance.c index a844eee7a..76448c090 100644 --- a/src/xrt/state_trackers/oxr/oxr_api_instance.c +++ b/src/xrt/state_trackers/oxr/oxr_api_instance.c @@ -15,6 +15,7 @@ #include "oxr_logger.h" #include "oxr_two_call.h" #include "oxr_extension_support.h" +#include "oxr_chain.h" #include "oxr_api_funcs.h" #include "oxr_api_verify.h" @@ -48,6 +49,60 @@ oxr_xrEnumerateInstanceExtensionProperties(const char *layerName, extension_properties, XR_SUCCESS); } +#ifdef XRT_OS_ANDROID +static XrResult +oxr_check_android_extensions(struct oxr_logger *log, + const XrInstanceCreateInfo *createInfo) +{ + + bool foundAndroidExtension = false; + for (uint32_t i = 0; i < createInfo->enabledExtensionCount; ++i) { + if (strcmp(createInfo->enabledExtensionNames[i], + XR_KHR_ANDROID_CREATE_INSTANCE_EXTENSION_NAME) == + 0) { + foundAndroidExtension = true; + break; + } + } + if (!foundAndroidExtension) { + return oxr_error( + log, XR_ERROR_INITIALIZATION_FAILED, + "(createInfo->enabledExtensionNames) " + "Mandatory platform-specific " + "extension" + " " XR_KHR_ANDROID_CREATE_INSTANCE_EXTENSION_NAME + " not specified"); + } + + { + // Verify that it exists and is populated. + XrInstanceCreateInfoAndroidKHR const *createInfoAndroid = + OXR_GET_INPUT_FROM_CHAIN( + createInfo, XR_TYPE_INSTANCE_CREATE_INFO_ANDROID_KHR, + XrInstanceCreateInfoAndroidKHR); + if (createInfoAndroid == NULL) { + return oxr_error( + log, XR_ERROR_VALIDATION_FAILURE, + "(createInfo->next...) " + "Did not find XrInstanceCreateInfoAndroidKHR in " + "chain"); + } + if (createInfoAndroid->applicationVM == NULL) { + return oxr_error(log, XR_ERROR_VALIDATION_FAILURE, + "(createInfo->next...->applicationVM) " + "applicationVM must be populated"); + } + if (createInfoAndroid->applicationActivity == NULL) { + return oxr_error( + log, XR_ERROR_VALIDATION_FAILURE, + "(createInfo->next...->applicationActivity) " + "applicationActivity must be populated"); + } + } + return XR_SUCCESS; +} +#endif // XRT_OS_ANDROID + XrResult oxr_xrCreateInstance(const XrInstanceCreateInfo *createInfo, XrInstance *out_instance) @@ -102,6 +157,13 @@ oxr_xrCreateInstance(const XrInstanceCreateInfo *createInfo, i); } + +#ifdef XRT_OS_ANDROID + ret = oxr_check_android_extensions(&log, createInfo); + if (ret != XR_SUCCESS) { + return ret; + } +#endif struct oxr_instance *inst = NULL; ret = oxr_instance_create(&log, createInfo, &inst); diff --git a/src/xrt/state_trackers/oxr/oxr_extension_support.h b/src/xrt/state_trackers/oxr/oxr_extension_support.h index 9120fc1ff..aeaa276b7 100644 --- a/src/xrt/state_trackers/oxr/oxr_extension_support.h +++ b/src/xrt/state_trackers/oxr/oxr_extension_support.h @@ -20,6 +20,18 @@ // beginning of GENERATED defines - do not modify - used by scripts +/* + * XR_KHR_android_create_instance + */ +#if defined(XR_KHR_android_create_instance) && defined(XR_USE_PLATFORM_ANDROID) +#define OXR_HAVE_KHR_android_create_instance +#define OXR_EXTENSION_SUPPORT_KHR_android_create_instance(_) \ + _(KHR_android_create_instance, KHR_ANDROID_CREATE_INSTANCE) +#else +#define OXR_EXTENSION_SUPPORT_KHR_android_create_instance(_) +#endif + + /* * XR_KHR_convert_timespec_time */ @@ -215,6 +227,7 @@ */ // clang-format off #define OXR_EXTENSION_SUPPORT_GENERATE(_) \ + OXR_EXTENSION_SUPPORT_KHR_android_create_instance(_) \ OXR_EXTENSION_SUPPORT_KHR_convert_timespec_time(_) \ OXR_EXTENSION_SUPPORT_KHR_opengl_enable(_) \ OXR_EXTENSION_SUPPORT_KHR_opengl_es_enable(_) \ diff --git a/src/xrt/state_trackers/oxr/oxr_instance.c b/src/xrt/state_trackers/oxr/oxr_instance.c index 9c2b08cdc..3b1e5ab61 100644 --- a/src/xrt/state_trackers/oxr/oxr_instance.c +++ b/src/xrt/state_trackers/oxr/oxr_instance.c @@ -14,12 +14,19 @@ #include "util/u_debug.h" #include "xrt/xrt_instance.h" +#include "xrt/xrt_config_os.h" + + +#ifdef XRT_OS_ANDROID +#include "util/u_android.h" +#endif #include "oxr_objects.h" #include "oxr_logger.h" #include "oxr_handle.h" #include "oxr_extension_support.h" #include "oxr_subaction.h" +#include "oxr_chain.h" #include #include @@ -222,6 +229,16 @@ oxr_instance_create(struct oxr_logger *log, sizeof(inst->xinst->instance_info.application_name), "%s", createInfo->applicationInfo.applicationName); +#ifdef XRT_OS_ANDROID + XrInstanceCreateInfoAndroidKHR const *create_info_android = + OXR_GET_INPUT_FROM_CHAIN(createInfo, + XR_TYPE_INSTANCE_CREATE_INFO_ANDROID_KHR, + XrInstanceCreateInfoAndroidKHR); + u_android_store_vm_and_activity( + (struct _JavaVM *)create_info_android->applicationVM, + create_info_android->applicationActivity); +#endif + xinst_ret = xrt_instance_create(&i_info, &inst->xinst); if (xinst_ret != 0) { ret = oxr_error(log, XR_ERROR_RUNTIME_FAILURE,