[PATCH weston] gears: fix invalid calculation of the first FPS

Ryo Munakata ryomnktml at gmail.com
Sun Aug 10 01:55:35 PDT 2014


At the calculation of the first FPS, gears has initialized last
FPS time with gettimeofday().
But the callback_data passed in the callback of wl_surface_frame()
is the current time, in milliseconds, with an undefined base.
Because of this subtracting last FPS time from callback_data makes no sense.
So now let's initialize last FPS time with the callback_data passed in
the first callback to calculate the first FPS properly.
---
 clients/gears.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/clients/gears.c b/clients/gears.c
index 95f0bb2..2413b31 100644
--- a/clients/gears.c
+++ b/clients/gears.c
@@ -23,6 +23,7 @@
 #include "config.h"
 
 #include <stdint.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -208,8 +209,13 @@ static void
 update_fps(struct gears *gears, uint32_t time)
 {
 	long diff_ms;
+	static bool first_call = true;
 
-	gears->frames++;
+	if (first_call) {
+		gears->last_fps = time;
+		first_call = false;
+	} else
+		gears->frames++;
 
 	diff_ms = time - gears->last_fps;
 
@@ -437,8 +443,6 @@ 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;
 	printf("Warning: FPS count is limited by the wayland compositor or monitor refresh rate\n");
 
 	glEnable(GL_NORMALIZE);
-- 
2.0.4



More information about the wayland-devel mailing list