From 723fca552c77555060bbff2bda18a8972476b8e8 Mon Sep 17 00:00:00 2001 From: Alexis Maiquez Date: Sat, 6 May 2023 14:14:21 +0200 Subject: [PATCH] Wayland: Moved frame-time checking to CWaylandOpenGLDriver instead of viewports Wayland doesn't require specifics timings, each frame drawn re-queues a new frame so treating it as "render the screens" seems to be a safe bet for now As indicated in the TODOs once actual work is being done in the event loop it should be replaced by a non-blocking option in case no surface is being rendered Signed-off-by: Alexis Maiquez --- .../Render/Drivers/CWaylandOpenGLDriver.cpp | 18 +++++++++++++++++- .../Render/Drivers/CWaylandOpenGLDriver.h | 1 + .../Render/Drivers/CX11OpenGLDriver.cpp | 2 ++ .../Drivers/Output/CWaylandOutputViewport.cpp | 7 ------- .../Drivers/Output/CWaylandOutputViewport.h | 1 - 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.cpp b/src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.cpp index 47d6bab..0228f6d 100644 --- a/src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.cpp +++ b/src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.cpp @@ -235,6 +235,7 @@ CWaylandOpenGLDriver::CWaylandOpenGLDriver(CApplicationContext& context, CWallpa m_fullscreenDetector (context, *this), m_output (context, *this), m_requestedExit (false), + m_context (context), CVideoDriver (app) { m_waylandContext.display = wl_display_connect (nullptr); @@ -304,11 +305,26 @@ void CWaylandOpenGLDriver::dispatchEventQueue() for (const auto& viewport : this->getOutput ().getViewports ()) this->getApp ().update (viewport.second); } - + + // TODO: FRAMETIME CONTROL SHOULD GO BACK TO THE CWALLPAPAERAPPLICATION ONCE ACTUAL PARTICLES ARE IMPLEMENTED + // TODO: AS THOSE, MORE THAN LIKELY, WILL REQUIRE OF A DIFFERENT PROCESSING RATE + + // TODO: WRITE A NON-BLOCKING VERSION OF THIS ONCE PARTICLE SIMULATION STARTS WORKING + // TODO: OTHERWISE wl_display_dispatch WILL BLOCK IF NO SURFACES ARE BEING DRAWN + static float startTime, endTime, minimumTime = 1.0f / this->m_context.settings.render.maximumFPS; + // get the start time of the frame + startTime = this->getRenderTime (); + if (wl_display_dispatch(m_waylandContext.display) == -1) m_requestedExit = true; m_frameCounter ++; + + endTime = this->getRenderTime (); + + // ensure the frame time is correct to not overrun FPS + if ((endTime - startTime) < minimumTime) + usleep ((minimumTime - (endTime - startTime)) * CLOCKS_PER_SEC); } Detectors::CFullScreenDetector& CWaylandOpenGLDriver::getFullscreenDetector () diff --git a/src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h b/src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h index 5b5fe77..4c7e3d0 100644 --- a/src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h +++ b/src/WallpaperEngine/Render/Drivers/CWaylandOpenGLDriver.h @@ -106,6 +106,7 @@ namespace WallpaperEngine::Render::Drivers void finishEGL(); uint32_t m_frameCounter; + CApplicationContext& m_context; std::chrono::high_resolution_clock::time_point renderStart = std::chrono::high_resolution_clock::now(); }; diff --git a/src/WallpaperEngine/Render/Drivers/CX11OpenGLDriver.cpp b/src/WallpaperEngine/Render/Drivers/CX11OpenGLDriver.cpp index 9b94b93..ccb979d 100644 --- a/src/WallpaperEngine/Render/Drivers/CX11OpenGLDriver.cpp +++ b/src/WallpaperEngine/Render/Drivers/CX11OpenGLDriver.cpp @@ -158,6 +158,8 @@ void CX11OpenGLDriver::dispatchEventQueue() this->m_output->getImageBuffer () ); + // TODO: FRAMETIME CONTROL SHOULD GO BACK TO THE CWALLPAPAERAPPLICATION ONCE ACTUAL PARTICLES ARE IMPLEMENTED + // TODO: AS THOSE, MORE THAN LIKELY, WILL REQUIRE OF A DIFFERENT PROCESSING RATE // update the output with the given image this->m_output->updateRender (); // do buffer swapping first diff --git a/src/WallpaperEngine/Render/Drivers/Output/CWaylandOutputViewport.cpp b/src/WallpaperEngine/Render/Drivers/Output/CWaylandOutputViewport.cpp index b6effff..c47fa2b 100644 --- a/src/WallpaperEngine/Render/Drivers/Output/CWaylandOutputViewport.cpp +++ b/src/WallpaperEngine/Render/Drivers/Output/CWaylandOutputViewport.cpp @@ -104,11 +104,6 @@ static void surfaceFrameCallback(void *data, struct wl_callback *cb, uint32_t ti viewport->rendering = false; float renderTime = viewport->getDriver ()->getRenderTime(); - - if ((renderTime - viewport->lastTime) < viewport->minimumTime) - usleep ((viewport->minimumTime - (renderTime - viewport->lastTime)) * CLOCKS_PER_SEC); - - viewport->lastTime = renderTime; } const struct wl_callback_listener frameListener = @@ -184,8 +179,6 @@ void CWaylandOutputViewport::setupLS () if (eglMakeCurrent(m_driver->getEGLContext ()->display, eglSurface, eglSurface, m_driver->getEGLContext ()->context) == EGL_FALSE) sLog.exception("Failed to make egl current"); - minimumTime = 1.0f / m_driver->getApp ().getContext().settings.render.maximumFPS; - this->m_driver->getOutput ().reset (); } diff --git a/src/WallpaperEngine/Render/Drivers/Output/CWaylandOutputViewport.h b/src/WallpaperEngine/Render/Drivers/Output/CWaylandOutputViewport.h index c49fe5a..671dfca 100644 --- a/src/WallpaperEngine/Render/Drivers/Output/CWaylandOutputViewport.h +++ b/src/WallpaperEngine/Render/Drivers/Output/CWaylandOutputViewport.h @@ -49,7 +49,6 @@ namespace WallpaperEngine::Render::Drivers wl_cursor* pointer = nullptr; wl_surface* cursorSurface = nullptr; bool callbackInitialized = false; - float lastTime, minimumTime; void setupLS ();