diff --git a/data/config/screen.xml b/data/config/screen.xml
index 16cd12a47..76ddf0aad 100644
--- a/data/config/screen.xml
+++ b/data/config/screen.xml
@@ -27,6 +27,7 @@
+
diff --git a/data/data/menu/displayconfigmenu.xml b/data/data/menu/displayconfigmenu.xml
index c447dff40..cd9d51701 100644
--- a/data/data/menu/displayconfigmenu.xml
+++ b/data/data/menu/displayconfigmenu.xml
@@ -143,13 +143,12 @@
-
+
+
diff --git a/src/libs/tgf/eventloop.cpp b/src/libs/tgf/eventloop.cpp
index 1fb9945cf..229819aff 100644
--- a/src/libs/tgf/eventloop.cpp
+++ b/src/libs/tgf/eventloop.cpp
@@ -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.
}
diff --git a/src/libs/tgfclient/guieventloop.cpp b/src/libs/tgfclient/guieventloop.cpp
index fa3bacf9a..287753c5a 100644
--- a/src/libs/tgfclient/guieventloop.cpp
+++ b/src/libs/tgfclient/guieventloop.cpp
@@ -19,6 +19,8 @@
#include
#include "tgfclient.h"
+#include
+#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 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
diff --git a/src/libs/tgfclient/guiscreen.cpp b/src/libs/tgfclient/guiscreen.cpp
index 6baf75318..97842bd0a 100644
--- a/src/libs/tgfclient/guiscreen.cpp
+++ b/src/libs/tgfclient/guiscreen.cpp
@@ -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);
}
-}
\ No newline at end of file
+}
diff --git a/src/libs/tgfclient/tgfclient.h b/src/libs/tgfclient/tgfclient.h
index 2766b3651..f47e002d8 100644
--- a/src/libs/tgfclient/tgfclient.h
+++ b/src/libs/tgfclient/tgfclient.h
@@ -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 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__ */
-
-
diff --git a/src/modules/userinterface/legacymenu/confscreens/displayconfig.cpp b/src/modules/userinterface/legacymenu/confscreens/displayconfig.cpp
index 805ae0785..4da5015af 100644
--- a/src/modules/userinterface/legacymenu/confscreens/displayconfig.cpp
+++ b/src/modules/userinterface/legacymenu/confscreens/displayconfig.cpp
@@ -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;
-}
\ No newline at end of file
+}
diff --git a/src/modules/userinterface/legacymenu/confscreens/displayconfig.h b/src/modules/userinterface/legacymenu/confscreens/displayconfig.h
index 17e66836f..4df670a89 100644
--- a/src/modules/userinterface/legacymenu/confscreens/displayconfig.h
+++ b/src/modules/userinterface/legacymenu/confscreens/displayconfig.h
@@ -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
};
diff --git a/src/modules/userinterface/legacymenu/racescreens/csnetworkingmenu.cpp b/src/modules/userinterface/legacymenu/racescreens/csnetworkingmenu.cpp
index d1b24ac67..4e2c354d1 100644
--- a/src/modules/userinterface/legacymenu/racescreens/csnetworkingmenu.cpp
+++ b/src/modules/userinterface/legacymenu/racescreens/csnetworkingmenu.cpp
@@ -543,9 +543,6 @@ HostServerIdle(void)
GfuiApp().eventLoop().postRedisplay();
}
-
- /* Let CPU take breath (and fans stay at low and quiet speed) */
- GfSleep(0.001);
}
diff --git a/src/modules/userinterface/legacymenu/racescreens/networkingmenu.cpp b/src/modules/userinterface/legacymenu/racescreens/networkingmenu.cpp
index ab6b7e82c..b868e225c 100644
--- a/src/modules/userinterface/legacymenu/racescreens/networkingmenu.cpp
+++ b/src/modules/userinterface/legacymenu/racescreens/networkingmenu.cpp
@@ -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