st/oxr: Handle the android extension

This commit is contained in:
Ryan Pavlik 2020-08-18 15:33:21 -05:00
parent 430f79a7ca
commit 54149b12b9
5 changed files with 94 additions and 0 deletions

View file

@ -0,0 +1 @@
OpenXR: Enable the `XR_KHR_android_create_instance` extension.

View file

@ -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'],

View file

@ -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);

View file

@ -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(_) \

View file

@ -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 <sys/types.h>
#include <unistd.h>
@ -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,