WIP max refresh rate

This commit is contained in:
Xavier Del Campo Romero 2022-07-31 17:09:13 +02:00
parent 072af2155e
commit 00ac492a27
10 changed files with 65 additions and 28 deletions

View File

@ -27,6 +27,7 @@
<attnum name="gamma" val="1"/>
<attstr name="video mode detect" in="auto,manual" val="auto"/>
<attstr name="video mode init" in="compatible,best" val="compatible"/>
<attnum name="maximum refresh frequency" val="50"/>
</section>
<section name="Menu Font">

View File

@ -143,13 +143,12 @@
<attstr name="font" val="medium"/>
</section>
<!--
<section name="MaxRefreshRateCombo">
<attstr name="type" val="combo box"/>
<attnum name="max len" val="4"/>
<attstr name="tip" val="Select your max. refresh rate"/>
<attnum name="x" val="320"/>
<attnum name="y" val="158"/>
<attnum name="x" val="270"/>
<attnum name="y" val="228"/>
<attnum name="width" val="220"/>
<attnum name="arrows width" val="24"/>
<attnum name="arrows height" val="24"/>
@ -157,7 +156,6 @@
<attstr name="focused color" val="0xFFFFFF"/>
<attstr name="font" val="medium"/>
</section>
-->
<section name="CancelButton">
<attstr name="type" val="text button"/>
@ -315,6 +313,17 @@
<attstr name="font" val="small_t"/>
</section>
<section name="12">
<attstr name="type" val="label"/>
<attnum name="x" val="20"/>
<attnum name="y" val="232"/>
<attstr name="text" val="Max FPS:"/>
<attstr name="tip" val="Sets maximum frames per second rate"/>
<attstr name="h align" val="right"/>
<attnum name="width" val="220"/>
<attstr name="font" val="small_t"/>
</section>
</section>
</params>

View File

@ -278,9 +278,4 @@ void GfEventLoop::recompute()
// Call the 'recompute' callback if any.
if (_pPrivate->cbRecompute)
_pPrivate->cbRecompute();
// ... otherwise let the CPU take breath (and fans stay at low and quiet speed,
// which would not be the case if really doing nothing).
else
SDL_Delay(1); // ms.
}

View File

@ -19,6 +19,8 @@
#include <SDL.h>
#include "tgfclient.h"
#include <chrono>
#include "tgf.h"
#ifdef WEBSERVER
#include "webserver.h"
@ -48,13 +50,23 @@ class GfuiEventLoop::Private
// Variables.
bool bRedisplay; // Flag to say if a redisplay is necessary.
double max_refresh; // Max refresh rate.
};
GfuiEventLoop::Private::Private()
: cbMouseButton(0), cbMouseMotion(0), cbMousePassiveMotion(0), cbMouseWheel(0),
cbJoystickAxis(0), cbJoystickButton(0),
cbDisplay(0), cbReshape(0), bRedisplay(false)
cbDisplay(0), cbReshape(0), bRedisplay(false),
max_refresh(50.0)
{
void *hparmScrConf = GfParmReadFileLocal(GFSCR_CONF_FILE, GFPARM_RMODE_STD);
if (hparmScrConf)
{
max_refresh = GfParmGetNum(hparmScrConf, GFSCR_SECT_VALIDPROPS,
GFSCR_ATT_MAXREFRESH, NULL, 50.0);
GfParmReleaseHandle(hparmScrConf);
}
}
// GfuiEventLoop class ============================================================
@ -238,11 +250,25 @@ void GfuiEventLoop::operator()()
if (!quitRequested())
{
const auto now = std::chrono::system_clock::now();
// Recompute if anything to.
recompute();
// Redisplay if anything to.
redisplay();
const std::chrono::duration<double> elapsed = std::chrono::system_clock::now() - now;
double rate;
if (_pPrivate->max_refresh)
{
rate = 1.0 / _pPrivate->max_refresh;
if (elapsed.count() < rate)
GfSleep(rate - elapsed.count());
}
}
}
@ -294,6 +320,11 @@ void GfuiEventLoop::postRedisplay(void)
_pPrivate->bRedisplay = true;
}
void GfuiEventLoop::setMaxRefreshRate(double rate)
{
_pPrivate->max_refresh = rate;
}
void GfuiEventLoop::forceRedisplay()
{
#ifdef WEBSERVER

View File

@ -205,6 +205,7 @@ ScreenSizeVector GfScrGetSupportedSizes(int nDisplayIndex)
tScreenSize last;
last.width = 0;
last.height = 0;
last.refresh_rate = 0;
bounds.w = 0;
bounds.h = 0;
@ -238,6 +239,7 @@ ScreenSizeVector GfScrGetSupportedSizes(int nDisplayIndex)
GfLogDebug(" %d x %d x %d @ %d hz\n",mode.w,mode.h,SDL_BITSPERPIXEL(mode.format),mode.refresh_rate);
last.width = mode.w;
last.height = mode.h;
last.refresh_rate = mode.refresh_rate;
vecSizes.push_back(last);
}
}
@ -257,6 +259,7 @@ ScreenSizeVector GfScrGetSupportedSizes(int nDisplayIndex)
// Desperation stick the Display Bounds into the vector
last.width = bounds.w;
last.height = bounds.h;
last.refresh_rate = mode.refresh_rate;
vecSizes.push_back(last);
}
@ -802,6 +805,8 @@ void GfScrShutdown(void)
GfParmGetNum(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_STARTUPDISPLAY, 0, 0));
GfParmSetStr(hparmScreen, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_VDETECT,
GfParmGetStr(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_VDETECT, GFSCR_VAL_VDETECT_AUTO));
GfParmSetNum(hparmScreen, GFSCR_SECT_VALIDPROPS, GFSCR_ATT_MAXREFRESH, 0,
GfParmGetNum(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_MAXREFRESH, 0, 50));
const char* pszVInitMode =
GfParmGetStr(hparmScreen, GFSCR_SECT_INTESTPROPS, GFSCR_ATT_VINIT,
GFSCR_VAL_VINIT_COMPATIBLE);
@ -1372,4 +1377,4 @@ void gfScrDisableResizable()
GfParmWriteFile(NULL, hparmScreen, "Screen");
GfParmReleaseHandle(hparmScreen);
}
}
}

View File

@ -75,6 +75,7 @@ typedef struct ScreenSize
{
int width; // Width in pixels.
int height; // Height in pixels.
double refresh_rate; // Refresh rate in Hz.
} tScreenSize;
typedef std::vector<tScreenSize> ScreenSizeVector;
@ -759,6 +760,9 @@ class TGFCLIENT_API GfuiEventLoop : public GfEventLoop
//! Force a call to the "redisplay/refresh" callback function.
void forceRedisplay();
//! Sets maximum refresh rate to the event loop.
void setMaxRefreshRate(double rate);
protected:
//! Process a keyboard event.
@ -840,5 +844,3 @@ void ScreenRelease(void* screen);
void UnregisterScreens(void* screen);
#endif /* __TGFCLIENT__H__ */

View File

@ -34,7 +34,7 @@ static const char* MonitorTypes[DisplayMenu::nDisplayTypes] = { "none", "4:3", "
static const char* SpansplitValues[] = { GR_VAL_NO, GR_VAL_YES };
static const int NbSpansplitValues = sizeof(SpansplitValues) / sizeof(SpansplitValues[0]);
#ifndef NoMaxRefreshRate
static const int AMaxRefreshRates[] = { 0, 30, 40, 50, 60, 75, 85, 100, 120, 150, 200 };
static const int AMaxRefreshRates[] = {30, 40, 50, 60, 75, 85, 100, 120, 150, 200 };
static const int NMaxRefreshRates = sizeof(AMaxRefreshRates) / sizeof(AMaxRefreshRates[0]);
#endif
@ -202,7 +202,8 @@ bool DisplayMenu::restartNeeded()
bool needRestart = ((_eDisplayMode != _eOriginalDisplayMode)
|| (_nScreenWidth !=_nOriginalScreenWidth)
|| (_nScreenHeight != _nOriginalScreenHeight)
|| (_nOriginalMenuDisplay != _nMenuDisplay));
|| (_nOriginalMenuDisplay != _nMenuDisplay))
|| (_nOriginalMaxRefreshRate != _nMaxRefreshRate);
if(GfScrUsingResizableWindow() && (_eDisplayMode == eResizable))
needRestart = false;
@ -305,7 +306,7 @@ void DisplayMenu::loadSettings()
#ifndef NoMaxRefreshRate
// Max. refresh rate (Hz).
_nMaxRefreshRate =
_nMaxRefreshRate = _nOriginalMaxRefreshRate =
(int)GfParmGetNum(hScrConfParams, pszScrPropSec, GFSCR_ATT_MAXREFRESH, NULL, 0);
#endif
@ -468,6 +469,7 @@ void DisplayMenu::resetScreenSizes()
tScreenSize _currSize = GfScrGetCurrentDisplaySize( _nMenuDisplay);
_nScreenWidth = _currSize.width;
_nScreenHeight = _currSize.height;
_nMaxRefreshRate = _currSize.refresh_rate;
}
else
{
@ -586,7 +588,7 @@ DisplayMenu::DisplayMenu()
_nOriginalMenuDisplay = 0;
_eOriginalDisplayMode = eWindowed;
#ifndef NoMaxRefreshRate
_nMaxRefreshRate = 0;
_nMaxRefreshRate = AMaxRefreshRates[0];
#endif
}
@ -708,4 +710,4 @@ void DisplayMenuRelease(void)
{
delete PDisplayMenu;
PDisplayMenu = NULL;
}
}

View File

@ -26,7 +26,7 @@
#include "confscreens.h"
// Comment-out to activate max. refresh rate settings.
#define NoMaxRefreshRate 1
//#define NoMaxRefreshRate 1
class DisplayMenu : public GfuiMenuScreen
@ -111,6 +111,7 @@ private:
#ifndef NoMaxRefreshRate
//! Currently selected max. refresh rate (Hz).
int _nMaxRefreshRate;
int _nOriginalMaxRefreshRate;
#endif
};

View File

@ -543,9 +543,6 @@ HostServerIdle(void)
GfuiApp().eventLoop().postRedisplay();
}
/* Let CPU take breath (and fans stay at low and quiet speed) */
GfSleep(0.001);
}

View File

@ -544,9 +544,6 @@ HostServerIdle(void)
GfuiApp().eventLoop().postRedisplay();
}
/* Let CPU take breath (and fans stay at low and quiet speed) */
GfSleep(0.001);
}
@ -581,9 +578,6 @@ ClientIdle(void)
GfuiApp().eventLoop().postRedisplay();
}
/* Let CPU take breath (and fans stay at low and quiet speed) */
GfSleep(0.001);
}
static void