From 524db0cf19648e3c7c78d3e73103b7a0bdcd6bfc Mon Sep 17 00:00:00 2001 From: Vito Caputo Date: Wed, 18 Jan 2017 17:14:52 -0800 Subject: *: move source into src/ subdir Restoring some organizational sanity since adopting autotools. --- src/fps.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 src/fps.c (limited to 'src/fps.c') diff --git a/src/fps.c b/src/fps.c new file mode 100644 index 0000000..99a3f85 --- /dev/null +++ b/src/fps.c @@ -0,0 +1,46 @@ +#include +#include +#include + +#include "fb.h" +#include "util.h" + + +static int print_fps; + + +static void sigalrm_handler(int signum) +{ + print_fps = 1; +} + + +int fps_setup(void) +{ + struct itimerval interval = { + .it_interval = { .tv_sec = 1, .tv_usec = 0 }, + .it_value = { .tv_sec = 1, .tv_usec = 0 }, + }; + + if (signal(SIGALRM, sigalrm_handler) == SIG_ERR) + return 0; + + if (setitimer(ITIMER_REAL, &interval, NULL) < 0) + return 0; + + return 1; +} + + +void fps_print(fb_t *fb) +{ + unsigned n; + + if (!print_fps) + return; + + fb_get_put_pages_count(fb, &n); + printf("FPS: %u\n", n); + + print_fps = 0; +} -- cgit v1.2.1