The open source OpenXR runtime
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

xrt: Add Android-specific features to xrt_instance.

Describe Android lifecycle callbacks

Co-authored-By: Jarvis Huang <quic_jarvhuan@quicinc.com>
Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/1655>

+157 -1
+1
doc/changes/xrt/mr.1655.md
··· 1 1 - Move `xrt_instance_info` members to nested `xrt_application_info` struct, and add a parallel `xrt_platform_info`. 2 2 - Add `xrt/xrt_android.h` header. 3 + - Add `xrt_instance_android` interface, optional aspect of `xrt_instance` when building on Android.
+147
src/xrt/include/xrt/xrt_android.h
··· 47 47 enum xrt_android_lifecycle_event event, 48 48 void *userdata); 49 49 50 + #ifdef XRT_OS_ANDROID 51 + 52 + /*! 53 + * @interface xrt_instance_android 54 + * 55 + * This is the interface to the Android-specific "aspect" of @ref xrt_instance. 56 + * 57 + * It is expected that your implementation of this interface will be nested in your 58 + * implementation of @ref xrt_instance. It does not have a separate create or 59 + * destroy function as it is an (optional) aspect of the instance. 60 + */ 61 + struct xrt_instance_android 62 + { 63 + 64 + /*! 65 + * @name Interface Methods 66 + * 67 + * All Android-based implementations of the xrt_instance interface must additionally populate all these function 68 + * pointers with their implementation methods. To use this interface, see the helper functions. 69 + * @{ 70 + */ 71 + /*! 72 + * Retrieve the stored Java VM instance pointer. 73 + * 74 + * @note Code consuming this interface should use xrt_instance_android_get_vm() 75 + * 76 + * @param xinst_android Pointer to self 77 + * 78 + * @return The VM pointer. 79 + */ 80 + struct _JavaVM *(*get_vm)(const struct xrt_instance_android *xinst_android); 81 + 82 + /*! 83 + * Retrieve the stored activity android.content.Context jobject. 84 + * 85 + * For usage, cast the return value to jobject - a typedef whose definition 86 + * differs between C (a void *) and C++ (a pointer to an empty class) 87 + * 88 + * @note Code consuming this interface should use xrt_instance_android_get_context() 89 + * 90 + * @param xinst_android Pointer to self 91 + * 92 + * @return The activity context. 93 + */ 94 + void *(*get_context)(const struct xrt_instance_android *xinst_android); 95 + 96 + /*! 97 + * Register a activity lifecycle event callback. 98 + * 99 + * @note Code consuming this interface should use xrt_instance_android_register_activity_lifecycle_callback() 100 + * 101 + * @param xinst_android Pointer to self 102 + * @param callback Function pointer for callback 103 + * @param event_mask bitwise-OR of one or more values from @ref xrt_android_lifecycle_event 104 + * @param userdata An opaque pointer for use by the callback. Whatever you pass here will be passed to the 105 + * callback when invoked. 106 + * 107 + * @return XRT_SUCCESS on success, other error code on error. 108 + */ 109 + xrt_result_t (*register_activity_lifecycle_callback)(struct xrt_instance_android *xinst_android, 110 + xrt_android_lifecycle_event_handler_t callback, 111 + enum xrt_android_lifecycle_event event_mask, 112 + void *userdata); 113 + 114 + /*! 115 + * Remove a activity lifecycle event callback that matches the supplied parameters. 116 + * 117 + * @note Code consuming this interface should use xrt_instance_android_remove_activity_lifecycle_callback() 118 + * 119 + * @param xinst_android Pointer to self 120 + * @param callback Function pointer for callback 121 + * @param event_mask bitwise-OR of one or more values from @ref xrt_android_lifecycle_event 122 + * @param userdata An opaque pointer for use by the callback. Whatever you pass here will be passed to the 123 + * callback when invoked. 124 + * 125 + * @return XRT_SUCCESS on success (at least one callback was removed), @ref XRT_ERROR_ANDROID on error. 126 + */ 127 + xrt_result_t (*remove_activity_lifecycle_callback)(struct xrt_instance_android *xinst_android, 128 + xrt_android_lifecycle_event_handler_t callback, 129 + enum xrt_android_lifecycle_event event_mask, 130 + void *userdata); 131 + 132 + /*! 133 + * @} 134 + */ 135 + }; 136 + 137 + /*! 138 + * @copydoc xrt_instance_android::get_vm 139 + * 140 + * Helper for calling through the function pointer. 141 + * 142 + * @public @memberof xrt_instance_android 143 + */ 144 + static inline struct _JavaVM * 145 + xrt_instance_android_get_vm(struct xrt_instance_android *xinst_android) 146 + { 147 + return xinst_android->get_vm(xinst_android); 148 + } 149 + 150 + /*! 151 + * @copydoc xrt_instance_android::get_context 152 + * 153 + * Helper for calling through the function pointer. 154 + * 155 + * @public @memberof xrt_instance_android 156 + */ 157 + static inline void * 158 + xrt_instance_android_get_context(struct xrt_instance_android *xinst_android) 159 + { 160 + return xinst_android->get_context(xinst_android); 161 + } 162 + 163 + /*! 164 + * @copydoc xrt_instance_android::register_activity_lifecycle_callback 165 + * 166 + * Helper for calling through the function pointer. 167 + * 168 + * @public @memberof xrt_instance_android 169 + */ 170 + static inline xrt_result_t 171 + xrt_instance_android_register_activity_lifecycle_callback(struct xrt_instance_android *xinst_android, 172 + xrt_android_lifecycle_event_handler_t callback, 173 + enum xrt_android_lifecycle_event event_mask, 174 + void *userdata) 175 + { 176 + return xinst_android->register_activity_lifecycle_callback(xinst_android, callback, event_mask, userdata); 177 + } 178 + 179 + /*! 180 + * @copydoc xrt_instance_android::remove_activity_lifecycle_callback 181 + * 182 + * Helper for calling through the function pointer. 183 + * 184 + * @public @memberof xrt_instance_android 185 + */ 186 + static inline xrt_result_t 187 + xrt_instance_android_remove_activity_lifecycle_callback(struct xrt_instance_android *xinst_android, 188 + xrt_android_lifecycle_event_handler_t callback, 189 + enum xrt_android_lifecycle_event event_mask, 190 + void *userdata) 191 + { 192 + return xinst_android->remove_activity_lifecycle_callback(xinst_android, callback, event_mask, userdata); 193 + } 194 + 195 + #endif // XRT_OS_ANDROID 196 + 50 197 #ifdef __cplusplus 51 198 } 52 199 #endif
+9 -1
src/xrt/include/xrt/xrt_instance.h
··· 22 22 23 23 struct xrt_prober; 24 24 struct xrt_device; 25 + struct xrt_instance_android; 25 26 struct xrt_space_overseer; 26 27 struct xrt_system; 27 28 struct xrt_system_devices; ··· 114 115 /*! 115 116 * @name Interface Methods 116 117 * 117 - * All implementations of the xrt_instance implementation must 118 + * All implementations of the xrt_instance interface must 118 119 * populate all these function pointers with their implementation 119 120 * methods. To use this interface, see the helper functions. 120 121 * @{ ··· 178 179 struct xrt_instance_info instance_info; 179 180 180 181 uint64_t startup_timestamp; 182 + 183 + /*! 184 + * An "aspect" of the xrt_instance interface, used only on Android. 185 + * 186 + * @see xrt_instance_android 187 + */ 188 + struct xrt_instance_android *android_instance; 181 189 }; 182 190 183 191 /*!