Commit 1dd3c7e8 authored by Vlad Zahorodnii's avatar Vlad Zahorodnii

[effects/showfps] Calculate "correct" FPS

Summary:
cca0e15b broke code that calculates the value of the fps counter.

The frames field stores timestamps of previous frames, not time between
each two consecutive frames.

This change doesn't attempt to make the show fps compute more accurate
performance metrics, e.g. how much times it takes to execute rendering
commands on the GPU, etc.

Test Plan: The Show FPS effect displays more sensible values.

Reviewers: #kwin, davidedmundson

Reviewed By: #kwin, davidedmundson

Subscribers: davidedmundson, broulik, kwin

Tags: #kwin

Differential Revision: https://phabricator.kde.org/D29247
parent e38a2410
......@@ -123,13 +123,14 @@ void ShowFpsEffect::reconfigure(ReconfigureFlags)
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::paintWindow(EffectWindow* w, int mask, QRegion region, Windo
void ShowFpsEffect::paintScreen(int mask, const QRegion &region, 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
......
......@@ -89,7 +89,7 @@ private:
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;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment