ScreenSaver SetTickSize(): apparent bug? and patch
|Reported by:||rogueeve||Owned by:||korli|
I believe I may have found a bug in the ScreenSaverRunner (/src/kits/screensaver/ScreenSaverRunner.cpp:202).
The Be Book states in regards to the SetTickSize() function:
<< The default tick size is 50000 (50 milliseconds). Setting the tick size to 0 causes Draw()/DirectDraw() to be called with almost no delay; in reality, there will be some variable delay depending on scheduling latency >>
-- which implies that there is no specific minimum tick rate. However, the replacement ScreenSaverRunner used by Haiku is unable to honor tick sizes smaller than 50ms, and will never tick at a rate faster than 50ms. If you check the code:
const uint32 kTickBase = 50000;
break the idle time up into ticks so that we can evaluate
the quit condition with greater responsiveness
otherwise a screen saver that sets, say, a 30 second tick
will result in the screen saver not responding to deactivation
for that length of time
if (system_time() - lastTickTime < tick)
re-evaluate the tick time after each successful wakeup -
screensavers can adjust it on the fly and we must be prepared to accomodate that
tick = fSaver ? fSaver->TickSize() : kTickBase;
lastTickTime = system_time();
If the screen saver sets the tick size smaller than kTickBase (50000us), then the runner will see it but stills snoozes for 50000 before checking if the time is up. This prevents the screensaver from running at it's requested rate.
The addition of something such as
if (tick < kTickBase) kTickBase = tick;
else if (kTickBase < 50000 && tick >= 50000) kTickBase = 50000;
after "tick = fSaver ? fSaver->TickSize() : kTickBase", should solve the issue. Of course a #define to replace 50000 might be nice as well. I assume the "k" in "kTickBase" is hungarian notation for "constant", so that might would want to be changed also.