-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
ANDROID Set display refresh rate based on the video->output->vertical refresh rate config value #18293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ro8inmorgan
wants to merge
1
commit into
libretro:master
Choose a base branch
from
ro8inmorgan:android_set_refreshrate
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
ANDROID Set display refresh rate based on the video->output->vertical refresh rate config value #18293
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| #include <jni.h> | ||
| #include <libretro.h> | ||
| #include "runloop.h" | ||
| #include "verbosity.h" | ||
| #include "configuration.h" | ||
|
|
||
| // ---------- Cached JNI handles ---------- | ||
| static JavaVM *g_vm = NULL; | ||
| static jclass g_cls_RetroActivityFuture = NULL; // GlobalRef | ||
| static jmethodID g_mid_nativePushContentFps = NULL; // (F)V | ||
|
|
||
| // Small helper: get/attach JNIEnv for the current thread | ||
| static JNIEnv* ra_get_env(bool *out_attached) | ||
| { | ||
| if (out_attached) *out_attached = false; | ||
| if (!g_vm) return NULL; | ||
|
|
||
| JNIEnv *env = NULL; | ||
| jint r = (*g_vm)->GetEnv(g_vm, (void**)&env, JNI_VERSION_1_6); | ||
| if (r == JNI_OK && env) return env; | ||
|
|
||
| // Not attached -> attach | ||
| if ((*g_vm)->AttachCurrentThread(g_vm, &env, NULL) != 0) | ||
| return NULL; | ||
| if (out_attached) *out_attached = true; | ||
| return env; | ||
| } | ||
|
|
||
| // ---------- JNI load/unload ---------- | ||
| JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) | ||
| { | ||
| g_vm = vm; | ||
| JNIEnv *env = NULL; | ||
| if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) != JNI_OK || !env) | ||
| return JNI_ERR; | ||
|
|
||
| jclass local = (*env)->FindClass(env, "com/retroarch/browser/retroactivity/RetroActivityFuture"); | ||
| if (!local) return JNI_ERR; | ||
|
|
||
| g_cls_RetroActivityFuture = (jclass)(*env)->NewGlobalRef(env, local); | ||
| (*env)->DeleteLocalRef(env, local); | ||
| if (!g_cls_RetroActivityFuture) return JNI_ERR; | ||
|
|
||
| // Cache static push method: public static void nativePushContentFps(float) | ||
| g_mid_nativePushContentFps = (*env)->GetStaticMethodID(env, g_cls_RetroActivityFuture, | ||
| "nativePushContentFps", "(F)V"); | ||
| // It's fine if Java side doesn't have it yet; we just won't call it | ||
| return JNI_VERSION_1_6; | ||
| } | ||
|
|
||
| JNIEXPORT void JNICALL JNI_OnUnload(JavaVM *vm, void *reserved) | ||
| { | ||
| JNIEnv *env = NULL; | ||
| if ((*vm)->GetEnv(vm, (void**)&env, JNI_VERSION_1_6) == JNI_OK && env) { | ||
| if (g_cls_RetroActivityFuture) { | ||
| (*env)->DeleteGlobalRef(env, g_cls_RetroActivityFuture); | ||
| g_cls_RetroActivityFuture = NULL; | ||
| } | ||
| } | ||
| g_vm = NULL; | ||
| g_mid_nativePushContentFps = NULL; | ||
| } | ||
|
|
||
| // ---------- Public C API: push fresh FPS to Java (optional) ---------- | ||
| void ra_notify_refresh_rate(float fps) | ||
| { | ||
| if (fps <= 0.f) return; | ||
| if (!g_vm || !g_cls_RetroActivityFuture || !g_mid_nativePushContentFps) return; | ||
|
|
||
| bool attached = false; | ||
| JNIEnv *env = ra_get_env(&attached); | ||
| if (!env) return; | ||
|
|
||
| (*env)->CallStaticVoidMethod(env, g_cls_RetroActivityFuture, | ||
| g_mid_nativePushContentFps, (jfloat)fps); | ||
|
|
||
| if (attached) | ||
| (*g_vm)->DetachCurrentThread(g_vm); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| #ifndef RA_ANDROID_BRIDGE_H | ||
| #define RA_ANDROID_BRIDGE_H | ||
|
|
||
| #ifdef __cplusplus | ||
| extern "C" { | ||
| #endif | ||
|
|
||
| void ra_notify_refresh_rate(float fps); | ||
|
|
||
| #ifdef __cplusplus | ||
| } | ||
| #endif | ||
| #endif |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Both of these override config loads call
config_load_file()so this only needs to be there.