Path: blob/master/thirdparty/openxr/src/loader/loader_init_data.hpp
21320 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#pragma once1011#include <xr_dependencies.h>12#include <openxr/openxr_platform.h>1314#if defined(XR_USE_PLATFORM_ANDROID)15#include <json/value.h>16#include <android/asset_manager_jni.h>17#include "android_utilities.h"1819// Warning: For system software use only. Enabling this define in regular applications20// will make it incompatible with many conformant runtimes.21#if !defined(XR_DISABLE_LOADER_INIT_ANDROID_LOADER_KHR)22/*!23* Later code will assume that if this is defined then a platform-specific struct24* must be provided for successful initialization.25*/26#define XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT27#endif // !defined(XR_DISABLE_LOADER_INIT_ANDROID_LOADER_KHR)28#endif // defined(XR_USE_PLATFORM_ANDROID)2930/*!31* Stores a copy of the data passed to the xrInitializeLoaderKHR function in a singleton.32*/33class LoaderInitData {34public:35/*!36* Singleton accessor.37*/38static LoaderInitData& instance() {39static LoaderInitData obj;40return obj;41}4243#if defined(XR_USE_PLATFORM_ANDROID) && defined(XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT)44/*!45* Type alias for the platform-specific structure type.46*/47using PlatformStructType = XrLoaderInitInfoAndroidKHR;4849/*!50* Native library path.51*/52std::string _android_native_library_path;53/*!54* Android asset manager.55*/56AAssetManager* _android_asset_manager;57#endif5859/*!60* Get our copy of the data, casted to pass to the runtime's matching method.61* Only some platforms have platform-specific loader init info.62*/63// NOLINTNEXTLINE(readability-convert-member-functions-to-static)64const XrLoaderInitInfoBaseHeaderKHR* getPlatformParam() {65#if defined(XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT)66return reinterpret_cast<const XrLoaderInitInfoBaseHeaderKHR*>(&_platform_info);67#else68return nullptr;69#endif70}7172#if defined(XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT)7374/*!75* Get the data via its real structure type.76*/77const PlatformStructType& getPlatformData() const { return _platform_info; }78#endif7980/*!81* Has this been correctly initialized?82*/83bool initialized() const noexcept { return _initialized; }8485/*!86* Initialize loader data - called by InitializeLoaderInitData() and thus ultimately by the loader's xrInitializeLoaderKHR87* implementation.88*/89XrResult initialize(const XrLoaderInitInfoBaseHeaderKHR* info);9091private:92//! Private constructor, forces use of singleton accessor.93LoaderInitData() = default;9495/*!96* Initialize non-platform-specific loader data.97*/98// NOLINTNEXTLINE(readability-convert-member-functions-to-static)99XrResult initializeProperties(const XrLoaderInitInfoBaseHeaderKHR* info);100101/*!102* Initialize platform-specific loader data - called ultimately by the loader's xrInitializeLoaderKHR103* implementation. Each platform that needs this extension will provide an implementation of this.104*/105XrResult initializePlatform(const XrLoaderInitInfoBaseHeaderKHR* info);106107#if defined(XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT)108/*!109* Only some platforms have platform-specific loader init info.110*/111PlatformStructType _platform_info;112#endif // defined(XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT)113114//! Flag for indicating whether _platform_info is valid.115bool _initialized = false;116};117118//! Initialize loader init data, where required.119XrResult InitializeLoaderInitData(const XrLoaderInitInfoBaseHeaderKHR* loaderInitInfo);120121#if defined(XR_USE_PLATFORM_ANDROID) && defined(XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT)122XrResult GetPlatformRuntimeVirtualManifest(Json::Value& out_manifest);123std::string GetAndroidNativeLibraryDir();124void* GetAndroidAssetManager();125#endif // defined(XR_USE_PLATFORM_ANDROID) && defined(XR_HAS_REQUIRED_PLATFORM_LOADER_INIT_STRUCT)126127128