[PATCH 2/2] gears: show FPS count (as in glxgears from mesa/demos)
Ander Conselvan de Oliveira
conselvan2 at gmail.com
Wed Jul 25 05:50:43 PDT 2012
On 07/25/2012 03:33 PM, Olivier Blin wrote:
> ---
> clients/gears.c | 31 +++++++++++++++++++++++++++++++
> 1 file changed, 31 insertions(+)
>
> diff --git a/clients/gears.c b/clients/gears.c
> index 70ec86c..8e7d4df 100644
> --- a/clients/gears.c
> +++ b/clients/gears.c
> @@ -59,6 +59,8 @@ struct gears {
>
> GLint gear_list[3];
> int fullscreen;
> + int frames;
> + struct timespec last_fps;
> };
>
> struct gear_template {
> @@ -203,10 +205,37 @@ make_gear(const struct gear_template *t)
> }
>
> static void
> +update_fps(struct gears *gears)
> +{
> + struct timespec now;
> + long diff_ms;
> +
> + gears->frames++;
> +
> + clock_gettime(CLOCK_MONOTONIC, &now);
> +
> + diff_ms = (now.tv_sec - gears->last_fps.tv_sec) * 1000 +
> + (now.tv_nsec - gears->last_fps.tv_nsec) / 1000000;
You should just pass the timestamp of the frame callback instead of
using clock_gettime().
Cheers,
Ander
> +
> + 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 = now;
> + }
> +}
> +
> +static void
> frame_callback(void *data, struct wl_callback *callback, uint32_t time)
> {
> struct gears *gears = data;
>
> + update_fps(gears);
> +
> gears->angle = (GLfloat) (time % 8192) * 360 / 8192.0;
>
> window_schedule_redraw(gears->window);
> @@ -407,6 +436,8 @@ gears_create(struct display *display)
> gears->view.rotx = 20.0;
> gears->view.roty = 30.0;
>
> + clock_gettime(CLOCK_MONOTONIC, &gears->last_fps);
> +
> glEnable(GL_NORMALIZE);
>
> glMatrixMode(GL_PROJECTION);
>
More information about the wayland-devel
mailing list