c/main: Implement display refresh rates supports on Android

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/1786>
This commit is contained in:
Zhongwang Zhang 2023-04-18 14:28:21 +08:00 committed by Rylie Pavlik
parent f2f092521f
commit 7cf30da9b1

View file

@ -82,6 +82,10 @@
#include <unistd.h>
#endif
#ifdef XRT_OS_ANDROID
#include "android/android_custom_surface.h"
#include "android/android_globals.h"
#endif
#define WINDOW_TITLE "Monado"
@ -1106,9 +1110,28 @@ comp_main_create_system_compositor(struct xrt_device *xdev,
u_var_add_native_images_debug(c, &c->scratch.views[i].unid, tmp);
}
#ifdef XRT_OS_ANDROID
// Get info about display.
struct xrt_android_display_metrics metrics;
if (!android_custom_surface_get_display_metrics(android_globals_get_vm(), android_globals_get_context(),
&metrics)) {
U_LOG_E("Could not get Android display metrics.");
/* Fallback to default values */
metrics.refresh_rates[0] = 60.0f;
metrics.refresh_rate_count = 1;
metrics.refresh_rate = metrics.refresh_rates[0];
}
// Copy data to info.
sys_info->refresh_rate_count = metrics.refresh_rate_count;
for (size_t i = 0; i < sys_info->refresh_rate_count; ++i) {
sys_info->refresh_rates_hz[i] = metrics.refresh_rates[i];
}
#else
//! @todo: Query all supported refresh rates of the current mode
sys_info->refresh_rate_count = 1;
sys_info->refresh_rates_hz[0] = (float)(1. / time_ns_to_s(c->settings.nominal_frame_interval_ns));
#endif // XRT_OS_ANDROID
// Needs to be delayed until after compositor's u_var has been setup.
if (!c->deferred_surface) {