gears: fix invalid calculation of the first FPS

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.
 For example, below is the result of running weston-gears on weston with
drm backend:

$ weston-gears
Warning: FPS count is limited by the wayland compositor or monitor refresh rate
1 frames in 1094460.125 seconds =  0.000 FPS
301 frames in  5.016 seconds = 60.008 FPS
301 frames in  5.016 seconds = 60.008 FPS
301 frames in  5.016 seconds = 60.008 FPS

As you can see, the the first FPS value is something odd.

This patch fixes it by initializing last FPS time with the callback_data passed in
the first callback.

Reviewed-by: Nils Chr. Brause <nilschrbrause@gmail.com>
dev
Ryo Munakata 10 years ago committed by Pekka Paalanen
parent f322f8efea
commit a3a5debe31
  1. 11
      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;
@ -398,7 +404,6 @@ gears_create(struct display *display)
{
const int width = 450, height = 500;
struct gears *gears;
struct timeval tv;
int i;
gears = zalloc(sizeof *gears);
@ -437,8 +442,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);

Loading…
Cancel
Save