Path: blob/master/thirdparty/openxr/src/loader/manifest_file.hpp
9917 views
// Copyright (c) 2017-2025 The Khronos Group Inc.1// Copyright (c) 2017 Valve Corporation2// Copyright (c) 2017 LunarG, Inc.3//4// SPDX-License-Identifier: Apache-2.0 OR MIT5//6// Initial Author: Mark Young <[email protected]>7//89#pragma once1011#include <openxr/openxr.h>1213#include <memory>14#include <string>15#include <vector>16#include <iosfwd>17#include <unordered_map>1819namespace Json {20class Value;21}2223enum ManifestFileType {24MANIFEST_TYPE_UNDEFINED = 0,25MANIFEST_TYPE_RUNTIME,26MANIFEST_TYPE_IMPLICIT_API_LAYER,27MANIFEST_TYPE_EXPLICIT_API_LAYER,28};2930struct JsonVersion {31uint32_t major;32uint32_t minor;33uint32_t patch;34};3536struct ExtensionListing {37std::string name;38uint32_t extension_version;39};4041// ManifestFile class -42// Base class responsible for finding and parsing manifest files.43class ManifestFile {44public:45// Non-copyable46ManifestFile(const ManifestFile &) = delete;47ManifestFile &operator=(const ManifestFile &) = delete;4849ManifestFileType Type() const { return _type; }50const std::string &Filename() const { return _filename; }51const std::string &LibraryPath() const { return _library_path; }52void GetInstanceExtensionProperties(std::vector<XrExtensionProperties> &props);53const std::string &GetFunctionName(const std::string &func_name) const;5455protected:56ManifestFile(ManifestFileType type, const std::string &filename, const std::string &library_path);57void ParseCommon(Json::Value const &root_node);58static bool IsValidJson(const Json::Value &root, JsonVersion &version);5960private:61std::string _filename;62ManifestFileType _type;63std::string _library_path;64std::vector<ExtensionListing> _instance_extensions;65std::unordered_map<std::string, std::string> _functions_renamed;66};6768// RuntimeManifestFile class -69// Responsible for finding and parsing Runtime-specific manifest files.70class RuntimeManifestFile : public ManifestFile {71public:72// Factory method73static XrResult FindManifestFiles(const std::string &openxr_command,74std::vector<std::unique_ptr<RuntimeManifestFile>> &manifest_files);7576private:77RuntimeManifestFile(const std::string &filename, const std::string &library_path);78static void CreateIfValid(const std::string &filename, std::vector<std::unique_ptr<RuntimeManifestFile>> &manifest_files);79static void CreateIfValid(const Json::Value &root_node, const std::string &filename,80std::vector<std::unique_ptr<RuntimeManifestFile>> &manifest_files);81};8283using LibraryLocator = bool (*)(const std::string &json_filename, const std::string &library_path, std::string &out_combined_path);8485// ApiLayerManifestFile class -86// Responsible for finding and parsing API Layer-specific manifest files.87class ApiLayerManifestFile : public ManifestFile {88public:89// Factory method90static XrResult FindManifestFiles(const std::string &openxr_command, ManifestFileType type,91std::vector<std::unique_ptr<ApiLayerManifestFile>> &manifest_files);9293const std::string &LayerName() const { return _layer_name; }94void PopulateApiLayerProperties(XrApiLayerProperties &props) const;9596private:97ApiLayerManifestFile(ManifestFileType type, const std::string &filename, const std::string &layer_name,98const std::string &description, const JsonVersion &api_version, const uint32_t &implementation_version,99const std::string &library_path);100101static void CreateIfValid(ManifestFileType type, const std::string &filename, std::istream &json_stream,102LibraryLocator locate_library, std::vector<std::unique_ptr<ApiLayerManifestFile>> &manifest_files);103static void CreateIfValid(ManifestFileType type, const std::string &filename,104std::vector<std::unique_ptr<ApiLayerManifestFile>> &manifest_files);105/// @return false if we could not find the library.106static bool LocateLibraryRelativeToJson(const std::string &json_filename, const std::string &library_path,107std::string &out_combined_path);108109#if defined(XR_KHR_LOADER_INIT_SUPPORT) && defined(XR_USE_PLATFORM_ANDROID)110static bool LocateLibraryInAssets(const std::string &json_filename, const std::string &library_path,111std::string &out_combined_path);112static void AddManifestFilesAndroid(const std::string &openxr_command, ManifestFileType type,113std::vector<std::unique_ptr<ApiLayerManifestFile>> &manifest_files);114#endif // defined(XR_USE_PLATFORM_ANDROID) && defined(XR_KHR_LOADER_INIT_SUPPORT)115116JsonVersion _api_version;117std::string _layer_name;118std::string _description;119uint32_t _implementation_version;120};121122123