Fixed bug 2816 - [patch] Android: Expose screen refresh rate Jonas Kulla Display::getRefreshRate() is available on all API levels.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
diff --git a/android-project/src/org/libsdl/app/SDLActivity.java b/android-project/src/org/libsdl/app/SDLActivity.java
index f65a010..a864aa0 100644
--- a/android-project/src/org/libsdl/app/SDLActivity.java
+++ b/android-project/src/org/libsdl/app/SDLActivity.java
@@ -392,7 +392,7 @@ public class SDLActivity extends Activity {
public static native void nativeQuit();
public static native void nativePause();
public static native void nativeResume();
- public static native void onNativeResize(int x, int y, int format);
+ public static native void onNativeResize(int x, int y, int format, float rate);
public static native int onNativePadDown(int device_id, int keycode);
public static native int onNativePadUp(int device_id, int keycode);
public static native void onNativeJoy(int device_id, int axis,
@@ -1041,7 +1041,7 @@ class SDLSurface extends SurfaceView implements SurfaceHolder.Callback,
mWidth = width;
mHeight = height;
- SDLActivity.onNativeResize(width, height, sdlFormat);
+ SDLActivity.onNativeResize(width, height, sdlFormat, mDisplay.getRefreshRate());
Log.v("SDL", "Window size:" + width + "x"+height);
// Set mIsSurfaceReady to 'true' *before* making a call to handleResume
diff --git a/src/core/android/SDL_android.c b/src/core/android/SDL_android.c
index e09b06d..a908954 100644
--- a/src/core/android/SDL_android.c
+++ b/src/core/android/SDL_android.c
@@ -143,9 +143,9 @@ JNIEXPORT void JNICALL SDL_Android_Init(JNIEnv* mEnv, jclass cls)
/* Resize */
JNIEXPORT void JNICALL Java_org_libsdl_app_SDLActivity_onNativeResize(
JNIEnv* env, jclass jcls,
- jint width, jint height, jint format)
+ jint width, jint height, jint format, jfloat rate)
{
- Android_SetScreenResolution(width, height, format);
+ Android_SetScreenResolution(width, height, format, rate);
}
/* Paddown */
diff --git a/src/video/android/SDL_androidvideo.c b/src/video/android/SDL_androidvideo.c
index 05c0753..ed3d3b3 100644
--- a/src/video/android/SDL_androidvideo.c
+++ b/src/video/android/SDL_androidvideo.c
@@ -64,6 +64,8 @@ extern int Android_GLES_LoadLibrary(_THIS, const char *path);
int Android_ScreenWidth = 0;
int Android_ScreenHeight = 0;
Uint32 Android_ScreenFormat = SDL_PIXELFORMAT_UNKNOWN;
+int Android_ScreenRate = 0;
+
SDL_sem *Android_PauseSem = NULL, *Android_ResumeSem = NULL;
/* Currently only one window */
@@ -166,7 +168,7 @@ Android_VideoInit(_THIS)
mode.format = Android_ScreenFormat;
mode.w = Android_ScreenWidth;
mode.h = Android_ScreenHeight;
- mode.refresh_rate = 0;
+ mode.refresh_rate = Android_ScreenRate;
mode.driverdata = NULL;
if (SDL_AddBasicVideoDisplay(&mode) < 0) {
return -1;
@@ -189,11 +191,12 @@ Android_VideoQuit(_THIS)
/* This function gets called before VideoInit() */
void
-Android_SetScreenResolution(int width, int height, Uint32 format)
+Android_SetScreenResolution(int width, int height, Uint32 format, float rate)
{
Android_ScreenWidth = width;
Android_ScreenHeight = height;
Android_ScreenFormat = format;
+ Android_ScreenRate = rate;
if (Android_Window) {
SDL_SendWindowEvent(Android_Window, SDL_WINDOWEVENT_RESIZED, width, height);
diff --git a/src/video/android/SDL_androidvideo.h b/src/video/android/SDL_androidvideo.h
index ccd5d7a..a403c81 100644
--- a/src/video/android/SDL_androidvideo.h
+++ b/src/video/android/SDL_androidvideo.h
@@ -28,7 +28,7 @@
#include "../SDL_sysvideo.h"
/* Called by the JNI layer when the screen changes size or format */
-extern void Android_SetScreenResolution(int width, int height, Uint32 format);
+extern void Android_SetScreenResolution(int width, int height, Uint32 format, float rate);
/* Private display data */