The open source OpenXR runtime
at prediction-2 74 lines 2.3 kB view raw
1// Copyright 2023, Qualcomm Innovation Center, Inc. 2// Copyright 2020-2024, Collabora, Ltd. 3// SPDX-License-Identifier: BSL-1.0 4/*! 5 * @file 6 * @brief Base implementation of the @ref xrt_instance_android interface. 7 * @author Jarvis Huang 8 * @author Rylie Pavlik <rylie.pavlik@collabora.com> 9 * @ingroup aux_android 10 */ 11#pragma once 12 13#include "xrt/xrt_instance.h" 14#include "xrt/xrt_android.h" 15 16#ifdef __cplusplus 17extern "C" { 18#endif 19 20struct _JavaVM; 21struct android_lifecycle_callbacks; 22 23/*! 24 * @brief A basic implementation of the @ref xrt_instance_android interface, 25 * a platform-specific "aspect" of @ref xrt_instance. 26 * 27 * Store nested in your @ref xrt_instance implementation (by value, not separately allocated), 28 * and call @ref android_instance_base_init in your instance creation and 29 * @ref android_instance_base_cleanup in instance destruction. 30 * 31 */ 32struct android_instance_base 33{ 34 struct xrt_instance_android base; 35 struct _JavaVM *vm; 36 void *context; 37 struct android_lifecycle_callbacks *lifecycle_callbacks; 38}; 39 40/*! 41 * @brief Initialize resources owned by @p android_instance_base and 42 * sets the @ref xrt_instance::android_instance pointer. 43 * 44 * @param aib The object to initialize. 45 * @param xinst The xrt_instance to update. 46 * @param vm The JavaVM pointer. 47 * @param activity The activity jobject, cast to a void pointer. 48 * 49 * @returns @ref XRT_SUCCESS on success, @ref XRT_ERROR_ALLOCATION if we could not allocate 50 * our required objects, and @ref XRT_ERROR_ANDROID if something goes very wrong with Java/JNI 51 * that should be impossible and likely indicates a logic error in the code. 52 * 53 * @public @memberof android_instance_base 54 */ 55xrt_result_t 56android_instance_base_init(struct android_instance_base *aib, 57 struct xrt_instance *xinst, 58 const struct xrt_instance_info *ii); 59 60/*! 61 * @brief Release resources owned by @ref android_instance_base and unsets the aspect pointer 62 * - but does not free @p aib itself, since it is intended to be held by value. 63 * 64 * @param aib The object to de-initialize. 65 * @param xinst The xrt_instance to update. 66 * 67 * @public @memberof android_instance_base 68 */ 69void 70android_instance_base_cleanup(struct android_instance_base *aib, struct xrt_instance *xinst); 71 72#ifdef __cplusplus 73}; 74#endif