Add get_screen_refresh_rate() to OS

This method can be used to get the refresh rate of a given screen.
It is supported on Windows, macOS, Linux, Android and iOS (but not
HTML5).
This commit is contained in:
Hugo Locurcio 2022-03-06 00:34:56 +01:00
parent 8975470bc2
commit cec7c908ca
No known key found for this signature in database
GPG key ID: 39E8F8BE30B0A49C
17 changed files with 177 additions and 1 deletions

View file

@ -53,6 +53,7 @@ GodotIOJavaWrapper::GodotIOJavaWrapper(JNIEnv *p_env, jobject p_godot_io_instanc
_get_locale = p_env->GetMethodID(cls, "getLocale", "()Ljava/lang/String;");
_get_model = p_env->GetMethodID(cls, "getModel", "()Ljava/lang/String;");
_get_screen_DPI = p_env->GetMethodID(cls, "getScreenDPI", "()I");
_get_screen_refresh_rate = p_env->GetMethodID(cls, "getScreenRefreshRate", "(D)D");
_get_window_safe_area = p_env->GetMethodID(cls, "getWindowSafeArea", "()[I"),
_get_unique_id = p_env->GetMethodID(cls, "getUniqueID", "()Ljava/lang/String;");
_show_keyboard = p_env->GetMethodID(cls, "showKeyboard", "(Ljava/lang/String;ZIII)V");
@ -136,6 +137,19 @@ int GodotIOJavaWrapper::get_screen_dpi() {
}
}
float GodotIOJavaWrapper::get_screen_refresh_rate(float p_fallback) {
if (_get_screen_refresh_rate) {
JNIEnv *env = get_jni_env();
if (env == nullptr) {
ERR_PRINT("An error occurred while trying to get screen refresh rate.");
return p_fallback;
}
return (float)env->CallDoubleMethod(godot_io_instance, _get_screen_refresh_rate, (double)p_fallback);
}
ERR_PRINT("An error occurred while trying to get the screen refresh rate.");
return p_fallback;
}
void GodotIOJavaWrapper::get_window_safe_area(int (&p_rect_xywh)[4]) {
if (_get_window_safe_area) {
JNIEnv *env = get_jni_env();