-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathfb_mandelbrot.c
94 lines (76 loc) · 2.62 KB
/
fb_mandelbrot.c
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
fbmark Linux Framebuffer Benchmark
Copyright (C) 2014-2017 Nicolas Caramelli
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <linux/fb.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/time.h>
int main(int argc, char **argv)
{
int fd, width, height, posx, posy;
struct fb_var_screeninfo info;
size_t len;
unsigned char *buffer, c;
unsigned int iters = 1, i, j, n;
float a, b, tmp, x, y, seconds;
struct timeval start, stop;
fd = getenv("FRAMEBUFFER") ? open(getenv("FRAMEBUFFER"), O_RDWR) : open("/dev/fb0", O_RDWR);
if (fd == -1) {
printf("Failed to open Framebuffer device: %m\n");
return 1;
}
ioctl(fd, FBIOGET_VSCREENINFO, &info);
if (getenv("WIDTH")) width = atoi(getenv("WIDTH"));
else width = info.xres;
if (getenv("HEIGHT")) height = atoi(getenv("HEIGHT"));
else height = info.yres;
if (getenv("POSX")) posx = atoi(getenv("POSX"));
else posx = 0;
if (getenv("POSY")) posy = atoi(getenv("POSY"));
else posy = 0;
len = info.xres * info.yres * info.bits_per_pixel / 8;
buffer = mmap(NULL, len, PROT_WRITE, MAP_SHARED, fd, 0);
gettimeofday(&start, NULL);
while (iters <= 48) {
for (i = 0; i < height; i++) {
for (j = 0; j < width; j++) {
x = y = c = 0;
a = 3. * j / width - 2;
b = 1 - 2. * i / height;
do {
tmp = x;
x = x * x - y * y + a;
y = 2 * tmp * y + b;
if (x * x + y * y > 4)
break;
} while (++c < iters);
for (n = 0; n < 3; n++) {
buffer[(posy + i) * info.xres * info.bits_per_pixel / 8 + (posx + j) * info.bits_per_pixel / 8 + n] = c * 255 / iters;
}
}
}
iters++;
}
gettimeofday(&stop, NULL);
seconds = (stop.tv_sec - start.tv_sec) + (stop.tv_usec - start.tv_usec) / 1000000.;
printf("Mandelbrot frame buffer test bench\n");
printf("Benchmarking 48 iterations: %.2f seconds\n", seconds);
munmap(buffer, len);
close(fd);
return 0;
}