<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Sun, Aug 10, 2014 at 4:47 PM, Ryo Munakata <span dir="ltr"><<a href="mailto:ryomnktml@gmail.com" target="_blank">ryomnktml@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">At the calculation of the first FPS, gears has initialized last<br>
FPS time with gettimeofday().<br>
But the callback_data passed in the callback of wl_surface_frame()<br>
is the current time, in milliseconds, with an undefined base.<br>
Because of this subtracting last FPS time from callback_data makes no sense.<br>
For example, below is the result of running weston-gears on weston with<br>
drm backend:<br>
<br>
$ weston-gears<br>
Warning: FPS count is limited by the wayland compositor or monitor refresh rate<br>
1 frames in 1094460.125 seconds = 0.000 FPS<br>
301 frames in 5.016 seconds = 60.008 FPS<br>
301 frames in 5.016 seconds = 60.008 FPS<br>
301 frames in 5.016 seconds = 60.008 FPS<br>
<br>
As you can see, the the first FPS value is something odd.<br>
<br>
This patch fixes it by initializing last FPS time with the callback_data passed in<br>
the first callback.<br>
---<br>
clients/gears.c | 11 +++++++----<br>
1 file changed, 7 insertions(+), 4 deletions(-)<br>
<br>
diff --git a/clients/gears.c b/clients/gears.c<br>
index 95f0bb2..1fb77e0 100644<br>
--- a/clients/gears.c<br>
+++ b/clients/gears.c<br>
@@ -23,6 +23,7 @@<br>
#include "config.h"<br>
<br>
#include <stdint.h><br>
+#include <stdbool.h><br>
#include <stdio.h><br>
#include <stdlib.h><br>
#include <string.h><br>
@@ -208,8 +209,13 @@ static void<br>
update_fps(struct gears *gears, uint32_t time)<br>
{<br>
long diff_ms;<br>
+ static bool first_call = true;<br>
<br>
- gears->frames++;<br>
+ if (first_call) {<br>
+ gears->last_fps = time;<br>
+ first_call = false;<br>
+ } else<br>
+ gears->frames++;<br>
<br>
diff_ms = time - gears->last_fps;<br>
<br>
@@ -398,7 +404,6 @@ gears_create(struct display *display)<br>
{<br>
const int width = 450, height = 500;<br>
struct gears *gears;<br>
- struct timeval tv;<br>
int i;<br>
<br>
gears = zalloc(sizeof *gears);<br>
@@ -437,8 +442,6 @@ gears_create(struct display *display)<br>
gears->view.rotx = 20.0;<br>
gears->view.roty = 30.0;<br>
<br>
- gettimeofday(&tv, NULL);<br>
- gears->last_fps = tv.tv_sec * 1000 + tv.tv_usec / 1000;<br>
printf("Warning: FPS count is limited by the wayland compositor or monitor refresh rate\n");<br>
<br>
glEnable(GL_NORMALIZE);<br></blockquote><div><br></div><div>Perfect! :)<br><br></div><div>Reviewed-by: Nils Chr. Brause <<a href="mailto:nilschrbrause@gmail.com">nilschrbrause@gmail.com</a>><br><br></div>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<span><font color="#888888">--<br>
2.0.4<br>
<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org" target="_blank">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
</font></span></blockquote></div><br></div></div>