summaryrefslogtreecommitdiff
path: root/clients/gears.c
diff options
context:
space:
mode:
authorOlivier Blin <olivier.blin@softathome.com>2012-07-25 15:19:23 +0200
committerKristian Høgsberg <krh@bitplanet.net>2012-07-26 22:03:21 -0400
commita1d0cf5d6978b7ac1bd0079f91c37b3e3a969385 (patch)
tree1919f536c9ea21b77e45bdeecaa535ea54b09865 /clients/gears.c
parent2f9ed71a8f28854868e5643b621035046c5f41e9 (diff)
downloadweston-a1d0cf5d6978b7ac1bd0079f91c37b3e3a969385.tar.gz
gears: show FPS count (as in glxgears from mesa/demos)
Diffstat (limited to 'clients/gears.c')
-rw-r--r--clients/gears.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/clients/gears.c b/clients/gears.c
index 70ec86c4..19165e75 100644
--- a/clients/gears.c
+++ b/clients/gears.c
@@ -59,6 +59,8 @@ struct gears {
GLint gear_list[3];
int fullscreen;
+ int frames;
+ uint32_t last_fps;
};
struct gear_template {
@@ -203,10 +205,33 @@ make_gear(const struct gear_template *t)
}
static void
+update_fps(struct gears *gears, uint32_t time)
+{
+ long diff_ms;
+
+ gears->frames++;
+
+ diff_ms = time - gears->last_fps;
+
+ if (diff_ms > 5000) {
+ float seconds = diff_ms / 1000.0;
+ float fps = gears->frames / seconds;
+
+ printf("%d frames in %6.3f seconds = %6.3f FPS\n", gears->frames, seconds, fps);
+ fflush(stdout);
+
+ gears->frames = 0;
+ gears->last_fps = time;
+ }
+}
+
+static void
frame_callback(void *data, struct wl_callback *callback, uint32_t time)
{
struct gears *gears = data;
+ update_fps(gears, time);
+
gears->angle = (GLfloat) (time % 8192) * 360 / 8192.0;
window_schedule_redraw(gears->window);
@@ -368,6 +393,7 @@ gears_create(struct display *display)
{
const int width = 450, height = 500;
struct gears *gears;
+ struct timeval tv;
int i;
gears = malloc(sizeof *gears);
@@ -407,6 +433,9 @@ gears_create(struct display *display)
gears->view.rotx = 20.0;
gears->view.roty = 30.0;
+ gettimeofday(&tv, NULL);
+ gears->last_fps = tv.tv_sec * 1000 + tv.tv_usec / 1000;
+
glEnable(GL_NORMALIZE);
glMatrixMode(GL_PROJECTION);