summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Høgsberg <krh@bitplanet.net>2013-12-06 22:02:45 -0800
committerKristian Høgsberg <krh@bitplanet.net>2013-12-07 22:26:23 -0800
commitdeb322237b8aeec4fb2a283ab28ce535a3c0c648 (patch)
tree151d4caae092a4c710a1e3c18e583031f4aa135a
parent40c0c3f91eeb747b86df64579e3b3706cc5450af (diff)
simple-egl: Print fps for the spinning triangle
This is not a benchmark.
-rw-r--r--clients/simple-egl.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/clients/simple-egl.c b/clients/simple-egl.c
index f23243fb..3db0e640 100644
--- a/clients/simple-egl.c
+++ b/clients/simple-egl.c
@@ -87,6 +87,7 @@ struct window {
GLuint col;
} gl;
+ uint32_t benchmark_time, frames;
struct wl_egl_window *native;
struct wl_surface *surface;
struct wl_shell_surface *shell_surface;
@@ -412,11 +413,11 @@ redraw(void *data, struct wl_callback *callback, uint32_t time)
{ 0, 0, 1, 0 },
{ 0, 0, 0, 1 }
};
- static const int32_t speed_div = 5;
- static uint32_t start_time = 0;
+ static const int32_t speed_div = 5, benchmark_interval = 5;
struct wl_region *region;
EGLint rect[4];
EGLint buffer_age = 0;
+ struct timeval tv;
assert(window->callback == callback);
window->callback = NULL;
@@ -427,10 +428,20 @@ redraw(void *data, struct wl_callback *callback, uint32_t time)
if (!window->configured)
return;
- if (start_time == 0)
- start_time = time;
+ gettimeofday(&tv, NULL);
+ time = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+ if (window->frames == 0)
+ window->benchmark_time = time;
+ if (time - window->benchmark_time > (benchmark_interval * 1000)) {
+ printf("%d frames in %d seconds: %f fps\n",
+ window->frames,
+ benchmark_interval,
+ (float) window->frames / benchmark_interval);
+ window->benchmark_time = time;
+ window->frames = 0;
+ }
- angle = ((time-start_time) / speed_div) % 360 * M_PI / 180.0;
+ angle = (time / speed_div) % 360 * M_PI / 180.0;
rotation[0][0] = cos(angle);
rotation[0][2] = sin(angle);
rotation[2][0] = -sin(angle);
@@ -483,6 +494,7 @@ redraw(void *data, struct wl_callback *callback, uint32_t time)
} else {
eglSwapBuffers(display->egl.dpy, window->egl_surface);
}
+ window->frames++;
}
static const struct wl_callback_listener frame_listener = {