summaryrefslogtreecommitdiff
path: root/src/fps.c
blob: 30b65cf99eaad1b97afe8896fc65c28ebbf0994b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <signal.h>
#include <stdio.h>
#include <sys/time.h>

#include "til_fb.h"
#include "til_util.h"


static int	print_fps;


static void sigalrm_handler(int signum)
{
	print_fps = 1;
}


int fps_setup(void)
{
#ifdef __WIN32__

#else
	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;
#endif
}


void fps_print(til_fb_t *fb)
{
#ifdef __WIN32__

#else
	unsigned	n;

	if (!print_fps)
		return;

	til_fb_get_put_pages_count(fb, &n);
	printf("FPS: %u\n", n);

	print_fps = 0;
#endif
}
© All Rights Reserved