Changeset View
Changeset View
Standalone View
Standalone View
effects/showfps/showfps.cpp
Show First 20 Lines • Show All 117 Lines • ▼ Show 20 Line(s) | 117 | default: | |||
---|---|---|---|---|---|
118 | fpsTextRect = QRect(x, y, FPS_WIDTH + NUM_PAINTS, MAX_TIME); | 118 | fpsTextRect = QRect(x, y, FPS_WIDTH + NUM_PAINTS, MAX_TIME); | ||
119 | textAlign = Qt::AlignTop | Qt::AlignRight; | 119 | textAlign = Qt::AlignTop | Qt::AlignRight; | ||
120 | break; | 120 | break; | ||
121 | } | 121 | } | ||
122 | } | 122 | } | ||
123 | 123 | | |||
124 | void ShowFpsEffect::prePaintScreen(ScreenPrePaintData& data, int time) | 124 | void ShowFpsEffect::prePaintScreen(ScreenPrePaintData& data, int time) | ||
125 | { | 125 | { | ||
126 | frames[ frames_pos ] = t.restart(); | 126 | frames[ frames_pos ] = QDateTime::currentMSecsSinceEpoch(); | ||
broulik: Can you not store the current time of the timer rather than going through `QDateTime`? | |||||
zzag: Uh, do you suggest to use an alternative approach for counting fps? | |||||
127 | if (++frames_pos == MAX_FPS) | 127 | if (++frames_pos == MAX_FPS) | ||
128 | frames_pos = 0; | 128 | frames_pos = 0; | ||
129 | effects->prePaintScreen(data, time); | 129 | effects->prePaintScreen(data, time); | ||
130 | data.paint += fps_rect; | 130 | data.paint += fps_rect; | ||
131 | 131 | | |||
132 | paint_size[ paints_pos ] = 0; | 132 | paint_size[ paints_pos ] = 0; | ||
133 | t.restart(); | ||||
133 | } | 134 | } | ||
134 | 135 | | |||
135 | void ShowFpsEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) | 136 | void ShowFpsEffect::paintWindow(EffectWindow* w, int mask, QRegion region, WindowPaintData& data) | ||
136 | { | 137 | { | ||
137 | effects->paintWindow(w, mask, region, data); | 138 | effects->paintWindow(w, mask, region, data); | ||
138 | 139 | | |||
139 | // Take intersection of region and actual window's rect, minus the fps area | 140 | // Take intersection of region and actual window's rect, minus the fps area | ||
140 | // (since we keep repainting it) and count the pixels. | 141 | // (since we keep repainting it) and count the pixels. | ||
141 | QRegion r2 = region & QRect(w->x(), w->y(), w->width(), w->height()); | 142 | QRegion r2 = region & QRect(w->x(), w->y(), w->width(), w->height()); | ||
142 | r2 -= fps_rect; | 143 | r2 -= fps_rect; | ||
143 | int winsize = 0; | 144 | int winsize = 0; | ||
144 | for (const QRect &r : r2) { | 145 | for (const QRect &r : r2) { | ||
145 | winsize += r.width() * r.height(); | 146 | winsize += r.width() * r.height(); | ||
146 | } | 147 | } | ||
147 | paint_size[ paints_pos ] += winsize; | 148 | paint_size[ paints_pos ] += winsize; | ||
148 | } | 149 | } | ||
149 | 150 | | |||
150 | void ShowFpsEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData& data) | 151 | void ShowFpsEffect::paintScreen(int mask, const QRegion ®ion, ScreenPaintData& data) | ||
151 | { | 152 | { | ||
152 | effects->paintScreen(mask, region, data); | 153 | effects->paintScreen(mask, region, data); | ||
154 | int lastFrame = frames_pos - 1; | ||||
155 | if (lastFrame < 0) | ||||
156 | lastFrame = MAX_FPS - 1; | ||||
157 | const qint64 lastTimestamp = frames[lastFrame]; | ||||
153 | int fps = 0; | 158 | int fps = 0; | ||
154 | for (int i = 0; | 159 | for (int i = 0; | ||
155 | i < MAX_FPS; | 160 | i < MAX_FPS; | ||
156 | ++i) | 161 | ++i) | ||
157 | if (abs(t.elapsed() - frames[ i ]) < 1000) | 162 | if (abs(lastTimestamp - frames[ i ]) < 1000) | ||
158 | ++fps; // count all frames in the last second | 163 | ++fps; // count all frames in the last second | ||
159 | if (fps > MAX_TIME) | 164 | if (fps > MAX_TIME) | ||
160 | fps = MAX_TIME; // keep it the same height | 165 | fps = MAX_TIME; // keep it the same height | ||
161 | if (effects->isOpenGLCompositing()) { | 166 | if (effects->isOpenGLCompositing()) { | ||
162 | paintGL(fps, data.projectionMatrix()); | 167 | paintGL(fps, data.projectionMatrix()); | ||
163 | glFinish(); // make sure all rendering is done | 168 | glFinish(); // make sure all rendering is done | ||
164 | } | 169 | } | ||
165 | #ifdef KWIN_HAVE_XRENDER_COMPOSITING | 170 | #ifdef KWIN_HAVE_XRENDER_COMPOSITING | ||
▲ Show 20 Lines • Show All 381 Lines • Show Last 20 Lines |
Can you not store the current time of the timer rather than going through QDateTime?