Hello, Here's debdiff against rss-glx-0.8.1-11 with patchset to 1. fix frame time calculations when frame limiter is enabled. 2. allow --nice/--max-fps options to disable frame limiter. 3. enable frame limiter and set default fps 50.
With 1. and 3. rss-glx screensavers doesn't hog 100% CPU anymore, patch 2. is because --nice/--max-fps were there only to enable frame limiter and couldn't be used to disable. - Jussi
diff -u rss-glx-0.8.1/debian/control rss-glx-0.8.1/debian/control --- rss-glx-0.8.1/debian/control +++ rss-glx-0.8.1/debian/control @@ -2,7 +2,7 @@ Section: x11 Priority: optional Maintainer: Ari Pollak <[EMAIL PROTECTED]> -Build-Depends: debhelper (>> 4.0.0), libx11-dev, libxt-dev, libgl1-mesa-swx11-dev | libgl-dev, libglu1-mesa-dev | libglu-dev, libglew1.5-dev | libglew-dev, libopenal-dev, libalut-dev, libmagickwand-dev, libtool, pkg-config +Build-Depends: debhelper (>> 4.0.0), dpatch, libx11-dev, libxt-dev, libgl1-mesa-swx11-dev | libgl-dev, libglu1-mesa-dev | libglu-dev, libglew1.5-dev | libglew-dev, libopenal-dev, libalut-dev, libmagickwand-dev, libtool, pkg-config Standards-Version: 3.6.1 Package: rss-glx diff -u rss-glx-0.8.1/debian/rules rss-glx-0.8.1/debian/rules --- rss-glx-0.8.1/debian/rules +++ rss-glx-0.8.1/debian/rules @@ -2,6 +2,8 @@ # Sample debian/rules that uses debhelper. # GNU copyright 1997 to 1999 by Joey Hess. +include /usr/share/dpatch/dpatch.make + # Uncomment this to turn on verbose mode. #export DH_VERBOSE=1 @@ -34,7 +36,7 @@ build: build-stamp -build-stamp: config.status +build-stamp: patch-stamp config.status dh_testdir # Add here commands to compile the package. @@ -43,7 +45,7 @@ touch build-stamp -clean: +clean: unpatch dh_testdir dh_testroot rm -f build-stamp diff -u rss-glx-0.8.1/debian/changelog rss-glx-0.8.1/debian/changelog --- rss-glx-0.8.1/debian/changelog +++ rss-glx-0.8.1/debian/changelog @@ -1,3 +1,12 @@ +rss-glx (0.8.1-11jk1) experimental; urgency=low + + * Fix rss-glx screensavers hogging 100% CPU (Closes: #445204) + - Fix frame time calculations when frame limiter is enabled + - Allow --nice and --max-fps options to be used to disable frame limiter + - Enabled frame limiter by default with FPS set to 50. + + -- Jussi Kivilinna <[EMAIL PROTECTED]> Thu, 28 Aug 2008 11:24:15 +0300 + rss-glx (0.8.1-11) experimental; urgency=low * Apply patch to build with new ImageMagick in experimental only in patch2: unchanged: --- rss-glx-0.8.1.orig/debian/patches/00list +++ rss-glx-0.8.1/debian/patches/00list @@ -0,0 +1,3 @@ +01_fix-frame-time-calculations.dpatch +02_expand-driver_cpp-opts-to-allow-disabling-frame-limiter.dpatch +03_enable-frame-limiter-by-default-with-fps-50.dpatch only in patch2: unchanged: --- rss-glx-0.8.1.orig/debian/patches/01_fix-frame-time-calculations.dpatch +++ rss-glx-0.8.1/debian/patches/01_fix-frame-time-calculations.dpatch @@ -0,0 +1,136 @@ +#! /bin/sh /usr/share/dpatch/dpatch-run +## 01_fix-frame-time-calculations.dpatch by Jussi Kivilinna <[EMAIL PROTECTED]> +## +## All lines beginning with `## DP:' are a description of the patch. +## DP: Old frame time calculation stored current time of frame to local +## DP: variable 'now'. Problem was that 'now' was used and overwritten other +## DP: places (idle sleep code and fps display) and as result calculated frame +## DP: times were too short, when frame limiter was activated. + [EMAIL PROTECTED]@ + +diff --git a/src/driver.cpp b/src/driver.cpp +index 0b48d0f..3e7ddb8 100644 +--- a/src/driver.cpp ++++ b/src/driver.cpp +@@ -148,13 +148,21 @@ void clearBuffers() { + } + } + ++static double getSeconds(void) ++{ ++ struct timeval now; ++ ++ gettimeofday (&now, NULL); ++ return (double)now.tv_sec + now.tv_usec / 1000000.0; ++} ++ + void mainLoop (void) + { + int bFPS = False; + XEvent event; + Atom XA_WM_PROTOCOLS = XInternAtom (XStuff->display, "WM_PROTOCOLS", False); + Atom XA_WM_DELETE_WINDOW = XInternAtom (XStuff->display, "WM_DELETE_WINDOW", False); +- struct timeval then, now, fps_time; ++ double currFrameTime, currFrameTimeSoFar, currFrameStartTime, prevFrameStartTime, now, fps_time; + int fps = 0; + + if (!rootWindow) { +@@ -163,10 +171,16 @@ void mainLoop (void) + + clearBuffers(); + +- gettimeofday (&now, NULL); +- int frameTimeSoFar = 0; ++ currFrameStartTime = getSeconds(); + while (!signalled) { +- hack_draw (XStuff, (double)now.tv_sec + now.tv_usec / 1000000.0f, frameTimeSoFar / 1000000.0f); ++ prevFrameStartTime = currFrameStartTime; ++ currFrameStartTime = getSeconds(); ++ currFrameTime = currFrameStartTime - prevFrameStartTime; ++ ++ if (currFrameTime < 0.0) ++ currFrameTime = 0.01; ++ ++ hack_draw (XStuff, currFrameStartTime, currFrameTime); + + glXSwapBuffers (XStuff->display, XStuff->window); + +@@ -174,16 +188,14 @@ void mainLoop (void) + if (fps != -1) + fps++; + +- gettimeofday (&now, NULL); +- +- if (now.tv_sec > fps_time.tv_sec) { ++ now = getSeconds(); ++ if (now >= fps_time + 1.0) { + if (fps != -1) { +- printf ("%d fps\n", fps); ++ printf ("%.4f fps\n", fps * (now - fps_time)); + } + + fps = 0; +- fps_time.tv_sec = now.tv_sec; +- fps_time.tv_usec = now.tv_usec; ++ fps_time = now; + } + } + +@@ -212,7 +224,7 @@ void mainLoop (void) + + if (bFPS) { + fps = -1; +- gettimeofday (&fps_time, NULL); ++ fps_time = getSeconds(); + } + } + +@@ -232,12 +244,10 @@ void mainLoop (void) + } + } + +- then = now; +- gettimeofday (&now, NULL); +- frameTimeSoFar = (now.tv_sec - then.tv_sec) * 1000000 + now.tv_usec - then.tv_usec; ++ currFrameTimeSoFar = getSeconds() - currFrameStartTime; + + if (frameTime) { +- while (frameTimeSoFar < frameTime) { ++ while (currFrameTimeSoFar * 1000000.0 < frameTime) { + if (be_nice) { + /* nanosleep on Linux/i386 seems completely ineffective for idling for < 20ms */ + /* +@@ -245,25 +255,27 @@ void mainLoop (void) + struct timespec hundreth; + + hundreth.tv_sec = 0; +- hundreth.tv_nsec = frameTime - frameTimeSoFar; ++ hundreth.tv_nsec = frameTime - currFrameTimeSoFar * 1000000.0; + + nanosleep(&hundreth, NULL); + #endif + */ + + /* +- usleep(frameTime - frameTimeSoFar); ++ usleep(frameTime - currFrameTimeSoFar * 1000000.0); + */ + + struct timeval tv; + + tv.tv_sec = 0; +- tv.tv_usec = frameTime - frameTimeSoFar; ++ tv.tv_usec = frameTime - currFrameTimeSoFar * 1000000.0; + select (0, 0, 0, 0, &tv); + } + +- gettimeofday (&now, NULL); +- frameTimeSoFar = (now.tv_sec - then.tv_sec) * 1000000 + now.tv_usec - then.tv_usec; ++ currFrameTimeSoFar = getSeconds() - currFrameStartTime; ++ ++ if (signalled) ++ return; + } + } else if (be_nice) { + struct timeval tv; only in patch2: unchanged: --- rss-glx-0.8.1.orig/debian/patches/02_expand-driver_cpp-opts-to-allow-disabling-frame-limiter.dpatch +++ rss-glx-0.8.1/debian/patches/02_expand-driver_cpp-opts-to-allow-disabling-frame-limiter.dpatch @@ -0,0 +1,54 @@ +#! /bin/sh /usr/share/dpatch/dpatch-run +## 02_expand-driver_cpp-opts-to-allow-disabling-frame-limiter.dpatch by Jussi Kivilinna <[EMAIL PROTECTED]> +## +## All lines beginning with `## DP:' are a description of the patch. +## DP: Expands --max-fps and --nice parameters so they can used to disable +## DP: frame limiter, not just turn it on. Useful if frame limiter is turned +## DP: on by default. + [EMAIL PROTECTED]@ +diff -urNad rss-glx-0.8.1~/src/driver.cpp rss-glx-0.8.1/src/driver.cpp +--- rss-glx-0.8.1~/src/driver.cpp 2008-08-28 11:17:30.865954629 +0300 ++++ rss-glx-0.8.1/src/driver.cpp 2008-08-28 11:17:31.029070056 +0300 +@@ -295,13 +295,15 @@ + + break; + case 'x': +- c = strtol_minmaxdef (optarg, 10, 1, 10000, 1, 100, "--maxfps: "); ++ c = strtol_minmaxdef (optarg, 10, 0, 10000, 1, 100, "--maxfps: "); + +- frameTime = 1000000 / c; ++ frameTime = c ? 1000000 / c : 0; + + break; + case 'n': +- be_nice = 1; ++ c = strtol_minmaxdef (optarg, 10, 0, 1, 1, 1, NULL); ++ ++ be_nice = c; + + break; + } +@@ -309,7 +311,7 @@ + + int strtol_minmaxdef (char *optarg, int base, int min, int max, int type, int def, char *errmsg) + { +- int result = strtol (optarg, (char **)NULL, base); ++ int result = optarg != NULL ? strtol (optarg, (char **)NULL, base) : def; + + if (result < min) { + if (errmsg) { +diff -urNad rss-glx-0.8.1~/src/driver.h rss-glx-0.8.1/src/driver.h +--- rss-glx-0.8.1~/src/driver.h 2008-08-28 11:10:38.000000000 +0300 ++++ rss-glx-0.8.1/src/driver.h 2008-08-28 11:17:31.029070056 +0300 +@@ -38,8 +38,8 @@ + void *hackstuff; + } xstuff_t; + +-#define DRIVER_OPTIONS_LONG {"root", 0, 0, 'r'}, {"maxfps", 1, 0, 'x'}, {"nice", 0, 0, 'n'}, +-#define DRIVER_OPTIONS_SHORT "rx:n" ++#define DRIVER_OPTIONS_LONG {"root", 0, 0, 'r'}, {"maxfps", 1, 0, 'x'}, {"nice", 2, 0, 'n'}, ++#define DRIVER_OPTIONS_SHORT "rx:n::" + #define DRIVER_OPTIONS_HELP "\t--root/-r\n" "\t--maxfps/-x <arg>\n" "\t--nice/-n\n" + #define DRIVER_OPTIONS_CASES case 'r': case 'x': case 'n': handle_global_opts(c); break; + only in patch2: unchanged: --- rss-glx-0.8.1.orig/debian/patches/03_enable-frame-limiter-by-default-with-fps-50.dpatch +++ rss-glx-0.8.1/debian/patches/03_enable-frame-limiter-by-default-with-fps-50.dpatch @@ -0,0 +1,30 @@ +#! /bin/sh /usr/share/dpatch/dpatch-run +## 03_enable-frame-limiter-by-default-with-fps-50.dpatch by Jussi Kivilinna <[EMAIL PROTECTED]> +## +## All lines beginning with `## DP:' are a description of the patch. +## DP: Enable frame limiter by default and set FPS at 50. This prevents +## DP: screensaver to hog 100% CPU + [EMAIL PROTECTED]@ + +diff --git a/src/driver.cpp b/src/driver.cpp +index 6e60b80..90f7735 100644 +--- a/src/driver.cpp ++++ b/src/driver.cpp +@@ -39,12 +39,14 @@ xstuff_t *XStuff; + + extern char *hack_name; + ++#define DEFAULT_FPS 50 ++ + /* + * display parameters + */ + int rootWindow = False; +-int frameTime = 0; +-int be_nice = 0; ++int frameTime = (DEFAULT_FPS == 0) ? 0 : (1000000 / DEFAULT_FPS); ++int be_nice = (DEFAULT_FPS != 0) ? True : False; + int signalled = 0; + + void createWindow (int argc, char **argv)