diff --git a/effects/showfps/showfps.h b/effects/showfps/showfps.h --- a/effects/showfps/showfps.h +++ b/effects/showfps/showfps.h @@ -89,7 +89,7 @@ int paint_size[ NUM_PAINTS ]; // number of pixels painted int paints_pos; // position in the queue enum { MAX_FPS = 200 }; - int frames[ MAX_FPS ]; // (sec*1000+msec) of the time the frame was done + qint64 frames[ MAX_FPS ]; // the time when the frame was done int frames_pos; // position in the queue double alpha; int x; diff --git a/effects/showfps/showfps.cpp b/effects/showfps/showfps.cpp --- a/effects/showfps/showfps.cpp +++ b/effects/showfps/showfps.cpp @@ -123,13 +123,14 @@ void ShowFpsEffect::prePaintScreen(ScreenPrePaintData& data, int time) { - frames[ frames_pos ] = t.restart(); + frames[ frames_pos ] = QDateTime::currentMSecsSinceEpoch(); if (++frames_pos == MAX_FPS) frames_pos = 0; effects->prePaintScreen(data, time); data.paint += fps_rect; paint_size[ paints_pos ] = 0; + t.restart(); } void ShowFpsEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) @@ -150,11 +151,15 @@ void ShowFpsEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData& data) { effects->paintScreen(mask, region, data); + int lastFrame = frames_pos - 1; + if (lastFrame < 0) + lastFrame = MAX_FPS - 1; + const qint64 lastTimestamp = frames[lastFrame]; int fps = 0; for (int i = 0; i < MAX_FPS; ++i) - if (abs(t.elapsed() - frames[ i ]) < 1000) + if (abs(lastTimestamp - frames[ i ]) < 1000) ++fps; // count all frames in the last second if (fps > MAX_TIME) fps = MAX_TIME; // keep it the same height