Path: blob/master/thirdparty/openxr/src/loader/loader_init_data.cpp
9917 views
// Copyright (c) 2017-2025 The Khronos Group Inc.1// Copyright (c) 2017-2019 Valve Corporation2// Copyright (c) 2017-2019 LunarG, Inc.3//4// SPDX-License-Identifier: Apache-2.0 OR MIT5//6// Initial Author: Mark Young <[email protected]>7//89#include "loader_init_data.hpp"1011#ifdef XR_KHR_LOADER_INIT_SUPPORT1213// Check and copy the Android-specific init data.14XrResult LoaderInitData::initialize(const XrLoaderInitInfoBaseHeaderKHR* info) {15#if defined(XR_USE_PLATFORM_ANDROID)16if (info->type != XR_TYPE_LOADER_INIT_INFO_ANDROID_KHR) {17return XR_ERROR_VALIDATION_FAILURE;18}19auto cast_info = reinterpret_cast<XrLoaderInitInfoAndroidKHR const*>(info);2021if (cast_info->applicationVM == nullptr) {22return XR_ERROR_VALIDATION_FAILURE;23}24if (cast_info->applicationContext == nullptr) {25return XR_ERROR_VALIDATION_FAILURE;26}2728// Copy and store the JVM pointer and Android Context, ensuring the JVM is initialised.29_data = *cast_info;30_data.next = nullptr;31jni::init(static_cast<jni::JavaVM*>(_data.applicationVM));32const jni::Object context = jni::Object{static_cast<jni::jobject>(_data.applicationContext)};3334// Retrieve a reference to the Android AssetManager.35const auto assetManager = context.call<jni::Object>("getAssets()Landroid/content/res/AssetManager;");36_android_asset_manager = AAssetManager_fromJava(jni::env(), assetManager.getHandle());3738// Retrieve the path to the native libraries.39const auto applicationContext = context.call<jni::Object>("getApplicationContext()Landroid/content/Context;");40const auto applicationInfo = context.call<jni::Object>("getApplicationInfo()Landroid/content/pm/ApplicationInfo;");41_native_library_path = applicationInfo.get<std::string>("nativeLibraryDir");42#else43#error "Platform specific XR_KHR_loader_init structure is not defined for this platform."44#endif // XR_USE_PLATFORM_ANDROID4546_initialized = true;47return XR_SUCCESS;48}4950XrResult InitializeLoaderInitData(const XrLoaderInitInfoBaseHeaderKHR* loaderInitInfo) {51return LoaderInitData::instance().initialize(loaderInitInfo);52}5354#ifdef XR_USE_PLATFORM_ANDROID55std::string GetAndroidNativeLibraryDir() { return LoaderInitData::instance()._native_library_path; }5657void* Android_Get_Asset_Manager() { return LoaderInitData::instance()._android_asset_manager; }58#endif // XR_USE_PLATFORM_ANDROID5960#endif // XR_KHR_LOADER_INIT_SUPPORT616263