Don't raise refresh rate above stream FPS except in min latency mode

This commit is contained in:
Cameron Gutman 2022-05-14 20:53:07 -05:00
parent 226e580a30
commit f1ccba39e8

View File

@ -595,6 +595,11 @@ public class Game extends Activity implements SurfaceHolder.Callback,
inputCaptureProvider.onWindowFocusChanged(hasFocus); inputCaptureProvider.onWindowFocusChanged(hasFocus);
} }
private boolean isRefreshRateEqualMatch(float refreshRate) {
return refreshRate >= prefConfig.fps &&
refreshRate <= prefConfig.fps + 3;
}
private boolean isRefreshRateGoodMatch(float refreshRate) { private boolean isRefreshRateGoodMatch(float refreshRate) {
return refreshRate >= prefConfig.fps && return refreshRate >= prefConfig.fps &&
Math.round(refreshRate) % prefConfig.fps <= 3; Math.round(refreshRate) % prefConfig.fps <= 3;
@ -630,6 +635,7 @@ public class Game extends Activity implements SurfaceHolder.Callback,
Display.Mode bestMode = display.getMode(); Display.Mode bestMode = display.getMode();
boolean isNativeResolutionStream = PreferenceConfiguration.isNativeResolution(prefConfig.width, prefConfig.height); boolean isNativeResolutionStream = PreferenceConfiguration.isNativeResolution(prefConfig.width, prefConfig.height);
boolean refreshRateIsGood = isRefreshRateGoodMatch(bestMode.getRefreshRate()); boolean refreshRateIsGood = isRefreshRateGoodMatch(bestMode.getRefreshRate());
boolean refreshRateIsEqual = isRefreshRateEqualMatch(bestMode.getRefreshRate());
for (Display.Mode candidate : display.getSupportedModes()) { for (Display.Mode candidate : display.getSupportedModes()) {
boolean refreshRateReduced = candidate.getRefreshRate() < bestMode.getRefreshRate(); boolean refreshRateReduced = candidate.getRefreshRate() < bestMode.getRefreshRate();
boolean resolutionReduced = candidate.getPhysicalWidth() < bestMode.getPhysicalWidth() || boolean resolutionReduced = candidate.getPhysicalWidth() < bestMode.getPhysicalWidth() ||
@ -661,12 +667,30 @@ public class Game extends Activity implements SurfaceHolder.Callback,
continue; continue;
} }
if (refreshRateIsGood) { if (prefConfig.framePacing != PreferenceConfiguration.FRAME_PACING_MIN_LATENCY &&
// We have a good matching refresh rate, so we're looking for equal or greater refreshRateIsEqual && !isRefreshRateEqualMatch(candidate.getRefreshRate())) {
// that is also a good matching refresh rate for our stream frame rate. // If we had an equal refresh rate and this one is not, skip it. In min latency
if (refreshRateReduced || !isRefreshRateGoodMatch(candidate.getRefreshRate())) { // mode, we want to always prefer the highest frame rate even though it may cause
// microstuttering.
continue;
}
else if (refreshRateIsGood) {
// We've already got a good match, so if this one isn't also good, it's not
// worth considering at all.
if (!isRefreshRateGoodMatch(candidate.getRefreshRate())) {
continue; continue;
} }
// We don't want ever reduce our refresh rate unless we found an exact
// match and we're not in min latency mode.
if (refreshRateReduced) {
if (prefConfig.framePacing == PreferenceConfiguration.FRAME_PACING_MIN_LATENCY) {
continue;
}
else if (!isRefreshRateEqualMatch(candidate.getRefreshRate())) {
continue;
}
}
} }
else if (!isRefreshRateGoodMatch(candidate.getRefreshRate())) { else if (!isRefreshRateGoodMatch(candidate.getRefreshRate())) {
// We didn't have a good match and this match isn't good either, so just don't // We didn't have a good match and this match isn't good either, so just don't
@ -683,6 +707,7 @@ public class Game extends Activity implements SurfaceHolder.Callback,
bestMode = candidate; bestMode = candidate;
refreshRateIsGood = isRefreshRateGoodMatch(candidate.getRefreshRate()); refreshRateIsGood = isRefreshRateGoodMatch(candidate.getRefreshRate());
refreshRateIsEqual = isRefreshRateEqualMatch(candidate.getRefreshRate());
} }
LimeLog.info("Selected display mode: "+bestMode.getPhysicalWidth()+"x"+ LimeLog.info("Selected display mode: "+bestMode.getPhysicalWidth()+"x"+
bestMode.getPhysicalHeight()+"x"+bestMode.getRefreshRate()); bestMode.getPhysicalHeight()+"x"+bestMode.getRefreshRate());