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
15#ifdef XRT_OS_ANDROID
16
17#include <android/native_window.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23struct _JNIEnv;
24struct _JavaVM;
25
26struct xrt_android_display_metrics
27{
28 int width_pixels;
29 int height_pixels;
30 int density_dpi;
31 float density;
32 float scaled_density;
33 float xdpi;
34 float ydpi;
35 float refresh_rate;
36};
37
38/*!
39 * Opaque type representing a custom surface added to a window, and the async
40 * operation to perform this adding.
41 *
42 * @note You must keep this around for as long as you're using the surface.
43 */
45
46/*!
47 * Start adding a custom surface to a window.
48 *
49 * This is an asynchronous operation, so this creates an opaque pointer for you
50 * to check on the results and maintain a reference to the result.
51 *
52 * Uses org.freedesktop.monado.auxiliary.MonadoView
53 *
54 * @param vm Java VM pointer
55 * @param context An android.content.Context jobject, cast to `void *`.
56 * @param display_id ID of the display that the surface is attached to.
57 * @param surface_title Title of the surface.
58 * @param preferred_display_mode_id The preferred display mode ID.
59 * A value of 0 indicates no preference.
60 * Non-zero values map to the corresponding display mode
61 * ID that are returned from the getSupportedModes() method for
62 * the given Android display. (the 1-indexed IDs.)
63 *
64 * @return An opaque handle for monitoring this operation and referencing the
65 * surface, or NULL if there was an error.
66 *
67 * @public @memberof android_custom_surface
68 */
70android_custom_surface_async_start(struct _JavaVM *vm,
71 void *context,
72 int32_t display_id,
73 const char *surface_title,
74 int32_t preferred_display_mode_id);
75
76/*!
77 * Destroy the native handle for the custom surface.
78 *
79 * Depending on the state, this may not necessarily destroy the underlying
80 * surface, if other references exist. However, a flag will be set to indicate
81 * that native code is done using it.
82 *
83 * @param ptr_custom_surface Pointer to the opaque pointer: will be set to NULL.
84 *
85 * @public @memberof android_custom_surface
86 */
87void
88android_custom_surface_destroy(struct android_custom_surface **ptr_custom_surface);
89
90/*!
91 * Get the ANativeWindow pointer corresponding to the added Surface, if
92 * available, waiting up to the specified duration.
93 *
94 * This may return NULL because the underlying operation is asynchronous.
95 *
96 * @public @memberof android_custom_surface
97 */
98ANativeWindow *
99android_custom_surface_wait_get_surface(struct android_custom_surface *custom_surface, uint64_t timeout_ms);
100
101bool
103 void *activity,
104 struct xrt_android_display_metrics *out_metrics);
105
106bool
107android_custom_surface_can_draw_overlays(struct _JavaVM *vm, void *context);
108
109#ifdef __cplusplus
110}
111#endif
112
113#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
Definition: android_custom_surface.cpp:38
Auto detect OS and certain features.