diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2020-10-05 13:07:18 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2020-10-05 19:43:15 +0200 |
commit | d3792300afec9c9cb8751cae5b46e8f9198214b4 (patch) | |
tree | 82c1902d48fccc8ea0f769d7b6af524008632ae0 /slideshow | |
parent | e366c928819c44b5c253c45dca6dae40b71c9808 (diff) |
try not to hog the CPU during slideshow animations
Try to sleep for most of the busy-waiting loop. Seeing this CPU
usage is annoying when profiling.
Change-Id: Ia01b547b28a22ffcb0e841ea582c93891cf1c5c5
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103960
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'slideshow')
-rw-r--r-- | slideshow/source/engine/slideshowimpl.cxx | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/slideshow/source/engine/slideshowimpl.cxx b/slideshow/source/engine/slideshowimpl.cxx index ba4d17cd6c1d..3bfee3cb88ba 100644 --- a/slideshow/source/engine/slideshowimpl.cxx +++ b/slideshow/source/engine/slideshowimpl.cxx @@ -28,6 +28,7 @@ #include <comphelper/scopeguard.hxx> #include <comphelper/storagehelper.hxx> #include <cppcanvas/polypolygon.hxx> +#include <osl/thread.hxx> #include <tools/debug.hxx> @@ -2395,8 +2396,16 @@ void FrameSynchronization::Synchronize() if (mbIsActive) { // Do busy waiting for now. - while (maTimer.getElapsedTime() < mnNextFrameTargetTime) - ; + for(;;) + { + double remainingTime = mnNextFrameTargetTime - maTimer.getElapsedTime(); + if(remainingTime <= 0) + break; + // Try to sleep most of it. + int remainingMilliseconds = remainingTime * 1000; + if(remainingMilliseconds > 2) + osl::Thread::wait(std::chrono::milliseconds(remainingMilliseconds - 2)); + } } MarkCurrentFrame(); |