diff --git a/android/native/jni/android_general.h b/android/native/jni/android_general.h index 34056ed9d9..74cb0ed7f2 100644 --- a/android/native/jni/android_general.h +++ b/android/native/jni/android_general.h @@ -37,6 +37,7 @@ struct droid int32_t last_orient; unsigned reinit_video; unsigned activity_paused; + float disp_refresh_rate; }; extern struct droid g_android; diff --git a/android/native/jni/main.c b/android/native/jni/main.c index 7cb1d9627f..a6cebc9831 100644 --- a/android/native/jni/main.c +++ b/android/native/jni/main.c @@ -26,6 +26,10 @@ #include "../../../performance.h" #include "../../../driver.h" +#ifdef PHOENIX_LEGACY +#include "../../../config.def.h" +#endif + void free_saved_state(struct android_app* android_app) { pthread_mutex_lock(&android_app->mutex); @@ -334,12 +338,21 @@ static void* android_app_entry(void* param) // Get arguments */ android_get_char_argv(rom_path, sizeof(rom_path), "ROM"); android_get_char_argv(libretro_path, sizeof(libretro_path), "LIBRETRO"); +#ifdef PHOENIX_LEGACY + char refreshrate_char[128]; + float refreshrate; + + android_get_char_argv(refreshrate_char,sizeof(refreshrate_char), "REFRESHRATE"); + + refreshrate = (float)strtod(refreshrate_char, NULL); +#endif RARCH_LOG("Checking arguments passed...\n"); RARCH_LOG("ROM Filename: [%s].\n", rom_path); RARCH_LOG("Libretro path: [%s].\n", libretro_path); - #ifdef PHOENIX_LEGACY + RARCH_LOG("Display Refresh rate: %.2fHz.\n", refreshrate); + /* ugly hack for now - hardcode libretro path to 'allowed' dir */ snprintf(libretro_path, sizeof(libretro_path), "/data/data/com.retroarch/lib/libretro.so"); #endif @@ -377,6 +390,23 @@ static void* android_app_entry(void* param) g_extern.verbose = true; +#ifdef PHOENIX_LEGACY + bool disp_refresh_read = refreshrate > 0.0f; + + g_android.disp_refresh_rate = refresh_rate; + + if(disp_refresh_read) + { + if(refreshrate < refresh_rate) + { + RARCH_WARN("Display refresh rate of your device is likely lower than 60Hz.\n"); + g_android.disp_refresh_rate = refreshrate; + } + } + + RARCH_LOG("Setting RetroArch video refresh rate to: %.2fHz.\n", g_android.disp_refresh_rate); +#endif + while(!(g_android.input_state & (1ULL << RARCH_WINDOW_READY))) { if(!android_run_events(android_app)) diff --git a/android/phoenix-legacy/src/com/retroarch/phoenix.java b/android/phoenix-legacy/src/com/retroarch/phoenix.java index 762fc421e1..f6f7b343df 100644 --- a/android/phoenix-legacy/src/com/retroarch/phoenix.java +++ b/android/phoenix-legacy/src/com/retroarch/phoenix.java @@ -21,10 +21,13 @@ import com.retroarch.fileio.FileChooser; import android.app.Activity; import android.app.NativeActivity; +import android.content.Context; import android.content.Intent; +import android.view.Display; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.WindowManager; import android.widget.Toast; import android.os.Bundle; @@ -50,6 +53,14 @@ public class phoenix extends Activity return true; } + public float getRefreshRate() + { + final WindowManager wm = (WindowManager)getSystemService(Context.WINDOW_SERVICE); + final Display display = wm.getDefaultDisplay(); + float rate = display.getRefreshRate(); + return rate; + } + public boolean onOptionsItemSelected(MenuItem item) { Intent myIntent; @@ -91,6 +102,7 @@ public class phoenix extends Activity myIntent = new Intent(this, NativeActivity.class); myIntent.putExtra("ROM", data.getStringExtra("PATH")); myIntent.putExtra("LIBRETRO", libretro_path); + myIntent.putExtra("REFRESHRATE", Float.toString(getRefreshRate())); startActivity(myIntent); } else diff --git a/settings.c b/settings.c index 4da5367d5f..4796c62601 100644 --- a/settings.c +++ b/settings.c @@ -189,7 +189,13 @@ void config_set_defaults(void) g_settings.video.second_pass_smooth = second_pass_smooth; #endif + // Android screens can have variable refresh rates - don't set a + // hardcoded value for Android devices +#if defined(ANDROID) && defined(PHOENIX_LEGACY) + g_settings.video.refresh_rate = g_android.disp_refresh_rate; +#else g_settings.video.refresh_rate = refresh_rate; +#endif g_settings.video.post_filter_record = post_filter_record; g_settings.video.gpu_record = gpu_record; g_settings.video.gpu_screenshot = gpu_screenshot;