mirror of
https://github.com/Almamu/linux-wallpaperengine.git
synced 2025-09-14 13:56:48 +08:00
properly adhere to fps limits
This commit is contained in:
parent
997b9b8ec4
commit
87b765e618
@ -334,7 +334,16 @@ namespace WallpaperEngine::Application
|
|||||||
} else {
|
} else {
|
||||||
#endif
|
#endif
|
||||||
while (!videoDriver->closeRequested () && this->m_context.state.general.keepRunning) {
|
while (!videoDriver->closeRequested () && this->m_context.state.general.keepRunning) {
|
||||||
|
static float startTime, endTime, minimumTime = 1.0f / this->m_context.settings.render.maximumFPS;
|
||||||
|
// get the start time of the frame
|
||||||
|
startTime = videoDriver->getRenderTime ();
|
||||||
renderFrame();
|
renderFrame();
|
||||||
|
// get the end time of the frame
|
||||||
|
endTime = videoDriver->getRenderTime ();
|
||||||
|
|
||||||
|
// ensure the frame time is correct to not overrun FPS
|
||||||
|
if ((endTime - startTime) < minimumTime)
|
||||||
|
usleep ((minimumTime - (endTime - startTime)) * CLOCKS_PER_SEC);
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_WAYLAND
|
#ifdef ENABLE_WAYLAND
|
||||||
}
|
}
|
||||||
@ -349,8 +358,6 @@ namespace WallpaperEngine::Application
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CWallpaperApplication::renderFrame() {
|
void CWallpaperApplication::renderFrame() {
|
||||||
|
|
||||||
static float startTime, endTime, minimumTime = 1.0f / this->m_context.settings.render.maximumFPS;
|
|
||||||
static time_t seconds;
|
static time_t seconds;
|
||||||
static struct tm* timeinfo;
|
static struct tm* timeinfo;
|
||||||
|
|
||||||
@ -359,24 +366,17 @@ namespace WallpaperEngine::Application
|
|||||||
timeinfo = localtime(&seconds);
|
timeinfo = localtime(&seconds);
|
||||||
g_Daytime = ((timeinfo->tm_hour * 60) + timeinfo->tm_min) / (24.0 * 60.0);
|
g_Daytime = ((timeinfo->tm_hour * 60) + timeinfo->tm_min) / (24.0 * 60.0);
|
||||||
|
|
||||||
// update audio recorder
|
|
||||||
audioDriver->update ();
|
|
||||||
// update input information
|
|
||||||
inputContext->update ();
|
|
||||||
// keep track of the previous frame's time
|
// keep track of the previous frame's time
|
||||||
g_TimeLast = g_Time;
|
g_TimeLast = g_Time;
|
||||||
// calculate the current time value
|
// calculate the current time value
|
||||||
g_Time = videoDriver->getRenderTime ();
|
g_Time = videoDriver->getRenderTime ();
|
||||||
// get the start time of the frame
|
|
||||||
startTime = g_Time;
|
// update audio recorder
|
||||||
|
audioDriver->update ();
|
||||||
|
// update input information
|
||||||
|
inputContext->update ();
|
||||||
// render the scene
|
// render the scene
|
||||||
context->render ();
|
context->render ();
|
||||||
// get the end time of the frame
|
|
||||||
endTime = videoDriver->getRenderTime ();
|
|
||||||
|
|
||||||
// ensure the frame time is correct to not overrun FPS
|
|
||||||
if ((endTime - startTime) < minimumTime)
|
|
||||||
usleep ((minimumTime - (endTime - startTime)) * CLOCKS_PER_SEC);
|
|
||||||
|
|
||||||
if (!this->m_context.settings.screenshot.take || videoDriver->getFrameCounter () != 5)
|
if (!this->m_context.settings.screenshot.take || videoDriver->getFrameCounter () != 5)
|
||||||
return;
|
return;
|
||||||
|
@ -269,6 +269,13 @@ static void surfaceFrameCallback(void *data, struct wl_callback *cb, uint32_t ti
|
|||||||
PLS->output->rendering = true;
|
PLS->output->rendering = true;
|
||||||
PLS->output->driver->wallpaperApplication->renderFrame();
|
PLS->output->driver->wallpaperApplication->renderFrame();
|
||||||
PLS->output->rendering = false;
|
PLS->output->rendering = false;
|
||||||
|
|
||||||
|
float renderTime = PLS->output->driver->getRenderTime();
|
||||||
|
|
||||||
|
if ((renderTime - PLS->lastTime) < PLS->minimumTime)
|
||||||
|
usleep ((PLS->minimumTime - (renderTime - PLS->lastTime)) * CLOCKS_PER_SEC);
|
||||||
|
|
||||||
|
PLS->lastTime = renderTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct wl_callback_listener frameListener = {
|
const struct wl_callback_listener frameListener = {
|
||||||
@ -316,6 +323,8 @@ CLayerSurface::CLayerSurface(CWaylandOpenGLDriver* pDriver, SWaylandOutput* pOut
|
|||||||
|
|
||||||
if (eglMakeCurrent(pDriver->eglContext.display, eglSurface, eglSurface, pDriver->eglContext.context) == EGL_FALSE)
|
if (eglMakeCurrent(pDriver->eglContext.display, eglSurface, eglSurface, pDriver->eglContext.context) == EGL_FALSE)
|
||||||
sLog.exception("Failed to make egl current");
|
sLog.exception("Failed to make egl current");
|
||||||
|
|
||||||
|
minimumTime = 1.0f / pDriver->wallpaperApplication->getContext().settings.render.maximumFPS;
|
||||||
}
|
}
|
||||||
|
|
||||||
CLayerSurface::~CLayerSurface() {
|
CLayerSurface::~CLayerSurface() {
|
||||||
|
@ -56,6 +56,7 @@ namespace WallpaperEngine::Render::Drivers
|
|||||||
wl_cursor* pointer = nullptr;
|
wl_cursor* pointer = nullptr;
|
||||||
wl_surface* cursorSurface = nullptr;
|
wl_surface* cursorSurface = nullptr;
|
||||||
bool callbackInitialized = false;
|
bool callbackInitialized = false;
|
||||||
|
float lastTime, minimumTime;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CWaylandOpenGLDriver : public CVideoDriver
|
class CWaylandOpenGLDriver : public CVideoDriver
|
||||||
|
Loading…
Reference in New Issue
Block a user