a/android: Add API for getting display refresh rate

Part-of: <https://gitlab.freedesktop.org/monado/monado/-/merge_requests/1786>
This commit is contained in:
Zhongwang Zhang 2023-05-25 16:19:30 +08:00 committed by Rylie Pavlik
parent 4029233069
commit f2f092521f
2 changed files with 25 additions and 0 deletions

View file

@ -251,3 +251,25 @@ android_custom_surface_can_draw_overlays(struct _JavaVM *vm, void *context)
jni::init(vm); jni::init(vm);
return Settings::canDrawOverlays(Context{(jobject)context}); return Settings::canDrawOverlays(Context{(jobject)context});
} }
float
android_custom_surface_get_display_refresh_rate(struct _JavaVM *vm, void *context)
{
jni::init(vm);
try {
auto clazz = loadClassFromRuntimeApk((jobject)context, MonadoView::getFullyQualifiedTypeName());
if (clazz.isNull()) {
U_LOG_E("Could not load class '%s' from package '%s'", MonadoView::getFullyQualifiedTypeName(),
XRT_ANDROID_PACKAGE);
return 0;
}
// Teach the wrapper our class before we start to use it.
MonadoView::staticInitClass((jclass)clazz.object().getHandle());
return MonadoView::getDisplayRefreshRate(Context((jobject)context));
} catch (std::exception const &e) {
U_LOG_E("Could not get display refresh rate: %s", e.what());
return 0;
}
}

View file

@ -109,6 +109,9 @@ android_custom_surface_get_display_metrics(struct _JavaVM *vm,
bool bool
android_custom_surface_can_draw_overlays(struct _JavaVM *vm, void *context); android_custom_surface_can_draw_overlays(struct _JavaVM *vm, void *context);
float
android_custom_surface_get_display_refresh_rate(struct _JavaVM *vm, void *context);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif