Monado OpenXR Runtime
android_custom_surface.h
Go to the documentation of this file.
1// Copyright 2020, Collabora, Ltd.
2// SPDX-License-Identifier: BSL-1.0
3/*!
4 * @file
5 * @brief Functions for adding a new Surface to a window and otherwise
6 * interacting with an Android View.
7 * @author Rylie Pavlik <rylie.pavlik@collabora.com>
8 * @ingroup aux_android
9 */
10
11#pragma once
12
13#include <xrt/xrt_config_os.h>
14#include <xrt/xrt_limits.h>
15
16#ifdef XRT_OS_ANDROID
17
18#include <android/native_window.h>
19
20#ifdef __cplusplus
21extern "C" {
22#endif
23
24struct _JNIEnv;
25struct _JavaVM;
26
27struct xrt_android_display_metrics
28{
29 int width_pixels;
30 int height_pixels;
31 int density_dpi;
32 float density;
33 float scaled_density;
34 float xdpi;
35 float ydpi;
36 float refresh_rate;
37 float refresh_rates[XRT_MAX_SUPPORTED_REFRESH_RATES];
38 uint32_t refresh_rate_count;
39};
40
41/*!
42 * Opaque type representing a custom surface added to a window, and the async
43 * operation to perform this adding.
44 *
45 * @note You must keep this around for as long as you're using the surface.
46 */
48
49/*!
50 * Start adding a custom surface to a window.
51 *
52 * This is an asynchronous operation, so this creates an opaque pointer for you
53 * to check on the results and maintain a reference to the result.
54 *
55 * Uses org.freedesktop.monado.auxiliary.MonadoView
56 *
57 * @param vm Java VM pointer
58 * @param context An android.content.Context jobject, cast to `void *`.
59 * @param display_id ID of the display that the surface is attached to.
60 * @param surface_title Title of the surface.
61 * @param preferred_display_mode_id The preferred display mode ID.
62 * A value of 0 indicates no preference.
63 * Non-zero values map to the corresponding display mode
64 * ID that are returned from the getSupportedModes() method for
65 * the given Android display. (the 1-indexed IDs.)
66 *
67 * @return An opaque handle for monitoring this operation and referencing the
68 * surface, or NULL if there was an error.
69 *
70 * @public @memberof android_custom_surface
71 */
73android_custom_surface_async_start(struct _JavaVM *vm,
74 void *context,
75 int32_t display_id,
76 const char *surface_title,
77 int32_t preferred_display_mode_id);
78
79/*!
80 * Destroy the native handle for the custom surface.
81 *
82 * Depending on the state, this may not necessarily destroy the underlying
83 * surface, if other references exist. However, a flag will be set to indicate
84 * that native code is done using it.
85 *
86 * @param ptr_custom_surface Pointer to the opaque pointer: will be set to NULL.
87 *
88 * @public @memberof android_custom_surface
89 */
90void
91android_custom_surface_destroy(struct android_custom_surface **ptr_custom_surface);
92
93/*!
94 * Get the ANativeWindow pointer corresponding to the added Surface, if
95 * available, waiting up to the specified duration.
96 *
97 * This may return NULL because the underlying operation is asynchronous.
98 *
99 * @public @memberof android_custom_surface
100 */
101ANativeWindow *
102android_custom_surface_wait_get_surface(struct android_custom_surface *custom_surface, uint64_t timeout_ms);
103
104bool
106 void *activity,
107 struct xrt_android_display_metrics *out_metrics);
108
109bool
110android_custom_surface_can_draw_overlays(struct _JavaVM *vm, void *context);
111
112float
113android_custom_surface_get_display_refresh_rate(struct _JavaVM *vm, void *context);
114
115#ifdef __cplusplus
116}
117#endif
118
119#endif // XRT_OS_ANDROID
bool android_custom_surface_get_display_metrics(struct _JavaVM *vm, void *context, struct xrt_android_display_metrics *out_metrics)
Definition: android_custom_surface.cpp:197
#define XRT_MAX_SUPPORTED_REFRESH_RATES
Max number of supported display refresh rates, artificial limit.
Definition: xrt_limits.h:49
Definition: android_custom_surface.cpp:38
Auto detect OS and certain features.
Header for limits of the XRT interfaces.