From f7541d9e42323ab3227bcf08bbae62421dd1a1bb Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Tue, 14 Jun 2022 12:16:44 +0200 Subject: [PATCH] clients/simple-egl: Fix angle reset on benchmark interval Commit 62ab6891db976 intended to change the angle calculation so that the a time delta since the first frame would be used instead of the absolute time. That was done in order to ensure the angle would always start with the same value, allowing users to differentiate left and right, which again is needed when testing flipped transforms. However, the `benchmark_time` variable is unsuitable for that purpose as it gets reset on each benchmark interval, abruptly changing the angle. Thus introduce a dedicated variable. Fixes 62ab6891db976 Signed-off-by: Robert Mader --- clients/simple-egl.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/clients/simple-egl.c b/clients/simple-egl.c index 05a0ffcb..c530d8d5 100644 --- a/clients/simple-egl.c +++ b/clients/simple-egl.c @@ -99,7 +99,9 @@ struct window { GLuint col; } gl; - uint32_t benchmark_time, frames; + uint32_t frames; + uint32_t initial_frame_time; + uint32_t benchmark_time; struct wl_egl_window *native; struct wl_surface *surface; struct xdg_surface *xdg_surface; @@ -624,8 +626,10 @@ redraw(struct window *window) gettimeofday(&tv, NULL); uint32_t time = tv.tv_sec * 1000 + tv.tv_usec / 1000; - if (window->frames == 0) + if (window->frames == 0) { + window->initial_frame_time = time; window->benchmark_time = time; + } if (time - window->benchmark_time > (benchmark_interval * 1000)) { printf("%d frames in %d seconds: %f fps\n", window->frames, @@ -636,7 +640,7 @@ redraw(struct window *window) } weston_matrix_init(&rotation); - angle = ((time - window->benchmark_time) / speed_div) % 360 * M_PI / 180.0; + angle = ((time - window->initial_frame_time) / speed_div) % 360 * M_PI / 180.0; rotation.d[0] = cos(angle); rotation.d[2] = sin(angle); rotation.d[8] = -sin(angle);