mirror of
https://github.com/libretro/RetroArch
synced 2025-04-01 04:20:27 +00:00
Add basic refresh rate check to Android.
This commit is contained in:
parent
3deb1e51a7
commit
cb41874e15
@ -21,6 +21,7 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name="org.retroarch.browser.DisplayRefreshRateTest"></activity>
|
||||||
<activity android:name="org.retroarch.browser.SettingsActivity"></activity>
|
<activity android:name="org.retroarch.browser.SettingsActivity"></activity>
|
||||||
<activity android:name="org.retroarch.browser.HelpActivity"></activity>
|
<activity android:name="org.retroarch.browser.HelpActivity"></activity>
|
||||||
<activity android:name="org.retroarch.browser.DirectoryActivity"></activity>
|
<activity android:name="org.retroarch.browser.DirectoryActivity"></activity>
|
||||||
|
@ -75,6 +75,13 @@
|
|||||||
android:summary="Force a specific refresh rate to be detected. Only use if auto-detection of refresh rate reports wrong refresh rate."
|
android:summary="Force a specific refresh rate to be detected. Only use if auto-detection of refresh rate reports wrong refresh rate."
|
||||||
android:title="Forced refresh rate (Hz)"
|
android:title="Forced refresh rate (Hz)"
|
||||||
android:numeric="decimal" />
|
android:numeric="decimal" />
|
||||||
|
<Preference
|
||||||
|
android:summary="Attempts to find the true refresh rate of monitor. Updates value in 'Force refresh rate (Hz)' option. To help ensure accuracy, make sure no intense background services are running, and avoid triggering screensaver."
|
||||||
|
android:title="Calibrate refresh rate" >
|
||||||
|
<intent
|
||||||
|
android:targetClass="org.retroarch.browser.DisplayRefreshRateTest"
|
||||||
|
android:targetPackage="org.retroarch" />
|
||||||
|
</Preference>
|
||||||
<CheckBoxPreference
|
<CheckBoxPreference
|
||||||
android:defaultValue="true"
|
android:defaultValue="true"
|
||||||
android:key="video_allow_rotate"
|
android:key="video_allow_rotate"
|
||||||
|
@ -0,0 +1,114 @@
|
|||||||
|
package org.retroarch.browser;
|
||||||
|
|
||||||
|
import javax.microedition.khronos.egl.EGLConfig;
|
||||||
|
import javax.microedition.khronos.opengles.GL10;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
|
import android.opengl.GLES20;
|
||||||
|
import android.opengl.GLSurfaceView;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
public class DisplayRefreshRateTest extends Activity {
|
||||||
|
|
||||||
|
private class Renderer implements GLSurfaceView.Renderer {
|
||||||
|
private static final String TAG = "GLESRenderer";
|
||||||
|
private static final double WARMUP_SECONDS = 2.0;
|
||||||
|
private static final double TEST_SECONDS = 10.0;
|
||||||
|
// Test states
|
||||||
|
private static final int STATE_START = 0;
|
||||||
|
private static final int STATE_WARMUP = 1;
|
||||||
|
private static final int STATE_TEST = 2;
|
||||||
|
private static final int STATE_DONE = 3;
|
||||||
|
private static final int STATE_DEAD = 4;
|
||||||
|
private int mState = STATE_START;
|
||||||
|
private double mStartTime = 0.0;
|
||||||
|
private int mNumFrames = 0;
|
||||||
|
|
||||||
|
private Activity activity;
|
||||||
|
|
||||||
|
public Renderer(Activity activity) {
|
||||||
|
this.activity = activity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setFPSSetting(double fps) {
|
||||||
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
||||||
|
SharedPreferences.Editor edit = prefs.edit();
|
||||||
|
edit.putString("video_refresh_rate", Double.valueOf(fps).toString());
|
||||||
|
edit.commit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDrawFrame(GL10 gl) {
|
||||||
|
double t = System.nanoTime() * 1.0e-9;
|
||||||
|
switch (mState) {
|
||||||
|
case STATE_START:
|
||||||
|
mStartTime = t;
|
||||||
|
mState = STATE_WARMUP;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_WARMUP:
|
||||||
|
if ((t - mStartTime) >= WARMUP_SECONDS) {
|
||||||
|
mStartTime = t;
|
||||||
|
mNumFrames = 0;
|
||||||
|
mState = STATE_TEST;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_TEST:
|
||||||
|
mNumFrames++;
|
||||||
|
double elapsed = t - mStartTime;
|
||||||
|
if (elapsed >= TEST_SECONDS) {
|
||||||
|
double fps = (double)mNumFrames / elapsed;
|
||||||
|
Log.i(TAG, "Measured FPS to: " + fps);
|
||||||
|
setFPSSetting(fps);
|
||||||
|
mState = STATE_DONE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_DONE:
|
||||||
|
activity.runOnUiThread(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
finish();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mState = STATE_DEAD;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_DEAD:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
float luma = (float)Math.sin((double)mNumFrames * 0.10);
|
||||||
|
luma *= 0.2f;
|
||||||
|
luma += 0.5f;
|
||||||
|
GLES20.glClearColor(luma, luma, luma, 1.0f);
|
||||||
|
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSurfaceChanged(GL10 gl, int width, int height) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private GLSurfaceView surfaceView;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
surfaceView = new GLSurfaceView(this);
|
||||||
|
surfaceView.setEGLConfigChooser(false);
|
||||||
|
surfaceView.setEGLContextClientVersion(2);
|
||||||
|
surfaceView.setRenderer(new Renderer(this));
|
||||||
|
setTitle("Refresh rate calibration");
|
||||||
|
setContentView(surfaceView);
|
||||||
|
}
|
||||||
|
}
|
@ -201,7 +201,6 @@ public class RetroArch extends Activity implements
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
config = new ConfigFile(new File(getDefaultConfigPath()));
|
config = new ConfigFile(new File(getDefaultConfigPath()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user