fbui | Framebuffer-based graphical environment |
| download: https://git.y1.nz/archives/fbui.tar.gz | |
| README | Files | Log | Refs |
libfbui/Test/main.c
1
2 /*=========================================================================
3 *
4 * fbtest, a test for FBUI (in-kernel framebuffer UI)
5 * Copyright (C) 2004 Zachary T Smith, fbui@comcast.net
6 *
7 * This module is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This module is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this module; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 * (See the file COPYING in the main directory of this archive for
22 * more details.)
23 *
24 *=======================================================================*/
25
26
27 typedef unsigned long u32;
28 #include <stdio.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <fcntl.h>
32 #include <sys/ioctl.h>
33 #include <linux/fb.h>
34 #include <sys/mman.h>
35 #include <unistd.h>
36 #include <string.h>
37
38 #include <linux/vt.h>
39 #include <linux/input.h>
40
41
42 #include "libfbui.h"
43
44
45
46
47 void
48 random_rect_test(Display* dpy, Window *win)
49 {
50 int i=0;
51 srand(1243+time(NULL));
52 printf ("50000 random rectangles\n");
53 while (i++ < 50000)
54 {
55 int x0 = rand();
56 int y0 = rand();
57 int x1 = rand();
58 int y1= rand();
59 x0 &= 2047;
60 x1 &= 2047;
61 y0 &= 2047;
62 y1 &= 2047;
63 x0 -= 800;
64 y0 -= 800;
65 x1 -= 800;
66 y1 -= 800;
67 fbui_draw_rect (dpy,win,x0,y0,x1,y1,rand());
68 }
69 }
70
71
72
73 int
74 main(int argc, char** argv)
75 {
76 int i;
77 int vc=-1;
78
79 Display *dpy;
80 Window *win;
81 Font *pcf = font_new ();
82
83 if (!pcf_read (pcf, "timR12.pcf")) {
84 font_free (pcf);
85 pcf = NULL;
86 FATAL ("cannot load font");
87 }
88
89 short win_w, win_h;
90 long fg,bg;
91 bg=0x303030;
92
93 dpy = fbui_display_open ();
94 if (!dpy)
95 FATAL ("cannot open display");
96
97 win = fbui_window_open (dpy, 300,200, &win_w, &win_h, 9999,9999, 370, 15,
98 &fg, &bg, "fbtest", "",
99 FBUI_PROGTYPE_APP, false,false, vc,
100 false, false,false,
101 argc,argv);
102 if (!win)
103 FATAL ("cannot create window");
104
105 int whichtest = argc >= 2 ? atoi(argv[1]) : 0;
106
107 if (!whichtest || whichtest==1)
108 {
109 printf ("100000 lines\n");
110 for (i=0;i<100000; i++)
111 {
112 short x0 = (rand() & 2047) - 800;
113 short y0 = (rand() & 2047) - 800;
114 short x1 = (rand() & 2047) - 800;
115 short y1 = (rand() & 2047) - 800;
116 fbui_draw_line (dpy, win, x0,y0,x1,y1,rand());
117 }
118 }
119
120 if (!whichtest || whichtest==2)
121 {
122 printf ("500000 hlines\n");
123 int j;
124 for(j=0; j<1000; j++)
125 {
126 i=0;
127 unsigned long color=rand();
128 while(i < 500)
129 {
130 int x1 = rand() % 800;
131 int x2 = rand() % 800;
132 int y = rand() % 600;
133 fbui_draw_hline (dpy, win, x1,x2,y,color);
134 i++;
135 }
136 fbui_flush (dpy, win);
137 i=0;
138 while(i < 500)
139 {
140 fbui_draw_hline (dpy, win, 0, i, i,color);
141 i++;
142 }
143 fbui_flush (dpy, win);
144 }
145 }
146
147
148 if (!whichtest || whichtest==3)
149 {
150 if(pcf)
151 {
152 fbui_draw_line(dpy, win, 0,0,799,599,RGB_RED);
153 fbui_draw_line(dpy, win, 799,0,0,599,RGB_RED);
154
155 int n=0;
156 while(n<200) {
157 int y = 0;
158
159 while (y<600) {
160 #define TESTSTR "01234 ? ABC_EFGHI ~` JKLMNOPQRSTItest m,yYqpaafgjklz<>?!@#$%^&*()~"
161 int rv = fbui_draw_string (dpy, win, pcf,
162 -100,y, TESTSTR, rand() & 0xffffff);
163
164 y += pcf->ascent + pcf->descent;
165 }
166 n++;
167 }
168 }
169 if (pcf) font_free (pcf);
170
171 }
172
173
174 if (!whichtest || whichtest==4)
175 {
176 printf ("rects\n");
177 random_rect_test(dpy, win);
178 }
179
180 if (!whichtest || whichtest==5)
181 {
182 printf ("10000 random filled rectangles\n");
183 for (i=0; i<10000; i++)
184 {
185 fbui_fill_area (dpy,win, rand() % 1000,rand()%700,rand()%900,rand()%500,
186 rand());
187 }
188 }
189
190 if (!whichtest || whichtest==6)
191 {
192 fbui_fill_area (dpy, win, 0,0,799,599,RGB_ORANGE);
193
194 static unsigned char drawthis[256*3];
195 for (i=0; i<256; i++) {
196 drawthis[i*3] = i;
197 drawthis[i*3+1] = 255-i;
198 drawthis[i*3+2] = i/2;
199 }
200
201 printf ("10000 256x16 put-native operations\n");
202
203 i=0;
204 while(i<10000)
205 {
206 int j=0;
207 short x = rand() % 800;
208 short y = rand() % 600;
209 while (j<16) {
210 int tmp = fbui_put (dpy, win, x,j+y,256, drawthis );
211 if (tmp != FBUI_SUCCESS) {
212 fbui_window_close(dpy, win);
213 printf ("error %d from fbui_put\n", tmp);
214 exit(0);
215 }
216 j++;
217 }
218 i++;
219 }
220 }
221
222 if (!whichtest || whichtest==7)
223 {
224 printf ("5000 fullscreen filled rectangles\n");
225 for (i=0; i<5000; i++)
226 {
227 fbui_fill_area (dpy, win, -20,-20,1000,999,rand());
228 }
229 }
230
231 if (!whichtest || whichtest==8)
232 {
233 // draw 100,000 pixels
234 i=0;
235 while (i < 100000)
236 {
237 fbui_draw_point (dpy, win, i/2000,i&511, i & 0xff);
238 i++;
239 }
240 }
241
242 if (!whichtest || whichtest==9)
243 {
244 fbui_fill_area (dpy, win, 0,0,398,298, RGB_RED);
245 fbui_fill_area (dpy, win, 400,0,799,298, RGB_GREEN);
246 fbui_fill_area (dpy, win, 0,300,398,599, RGB_BLUE);
247 fbui_fill_area (dpy, win, 400,300,799,599, RGB_YELLOW);
248
249 printf ("10000 inverted lines\n");
250 for (i=0;i<10000; i++)
251 {
252 short x0 = (rand() & 2047) - 800;
253 short y0 = (rand() & 2047) - 800;
254 short x1 = (rand() & 2047) - 800;
255 short y1 = (rand() & 2047) - 800;
256
257 fbui_invert_line (dpy, win, x0,y0,x1,y1);
258 }
259 }
260
261 if (!whichtest || whichtest==10)
262 {
263 unsigned long drawthis[256];
264 for (i=0; i<256; i++) {
265 unsigned long value = i/2;
266 value <<= 8;
267 value |= 255-i;
268 value <<= 8;
269 value |= 192;
270 drawthis[i] = value;
271 }
272
273 printf ("50000 256x16 put-rgb operations\n");
274
275 i=0;
276 while(i<50000)
277 {
278 int j=0;
279 int x = (rand() & 2047) - 800;
280 int y = (rand() & 2047) - 800;
281 while(j<16) {
282 fbui_put_rgb (dpy, win, x,y+j,256, drawthis );
283 j++;
284 }
285 i++;
286 }
287 }
288
289 if (!whichtest || whichtest==11)
290 {
291 fbui_draw_line (dpy, win, 0,0,799,599, RGB_BLUE);
292 fbui_draw_line (dpy, win, 799,0,0,599, RGB_GREEN);
293
294 for (i=0; i<6; i++)
295 fbui_copy_area (dpy, win, 0,10,0,0,800,600);
296 }
297
298 if (!whichtest || whichtest==12)
299 {
300 fbui_draw_line (dpy, win, 0,0,799,599, RGB_BLUE);
301 fbui_draw_line (dpy, win, 799,0,0,599, RGB_BLUE);
302
303 for (i=0; i<6; i++)
304 fbui_copy_area (dpy, win, 0,0,0,10,800,800);
305 }
306
307 if (!whichtest || whichtest==13)
308 {
309 fbui_draw_line (dpy, win, 0,0,799,599, RGB_YELLOW);
310 fbui_draw_line (dpy, win, 799,0,0,599, RGB_ORANGE);
311
312 for (i=0; i<6; i++)
313 fbui_copy_area (dpy, win, 0,0,10,0,800,800);
314 }
315
316 if (!whichtest || whichtest==14)
317 {
318 fbui_draw_line (dpy, win, 0,0,799,599, RGB_BLUE);
319 fbui_draw_line (dpy, win, 799,0,0,599, RGB_BLUE);
320
321 for (i=0; i<6; i++)
322 fbui_copy_area (dpy, win, 10,0,0,0,800,800);
323 }
324
325 if (!whichtest || whichtest==15)
326 {
327 static unsigned char drawthis[768];
328 for (i=0; i<768; ) {
329 drawthis[i++] = i/6;
330 drawthis[i++] = 255-i/3;
331 drawthis[i++] = 0xff;
332 }
333
334 printf ("50000 256x16 put-rgb operations\n");
335
336 i=0;
337 while(i<50000)
338 {
339 int j=0;
340 int x = (rand() & 2047) - 800;
341 int y = (rand() & 2047) - 800;
342 while(j<16) {
343 fbui_put_rgb3 (dpy, win, x,y+j,256, drawthis );
344 j++;
345 }
346 i++;
347 }
348 }
349
350 if (!whichtest || whichtest==16)
351 {
352 int j=256;
353
354 printf ("vlines\n");
355
356 #if 1
357 for (j=0; j<256; j++) {
358 i=0;
359 unsigned long color = (rand() & 0xffff00) | (j & 255);
360 while(i<5000)
361 {
362 fbui_draw_vline (dpy, win, i-1000,i-2000,i-1000,color);
363 i++;
364 }
365 fbui_flush (dpy, win);
366 }
367 #endif
368 fbui_clear (dpy, win);
369 fbui_flush (dpy, win);
370 for (j=0 ; j<640; j++)
371 {
372 double r;
373 int factor = j / 160;
374 i=0;
375 unsigned long color=rand();
376 while(i<win_w)
377 {
378 r = i;
379 r /= win_w/4;
380 r *= 3.1415926536;
381 r *= factor;
382 r = sin(r);
383 int y = r*(win_h/2) + (win_h/2);
384 fbui_draw_vline (dpy, win, i, (j&1) ? 0 : win_h, y,color);
385 i++;
386 }
387 fbui_flush (dpy, win);
388 }
389 fbui_draw_vline (dpy, win, 100, 0, 100, RGB_WHITE);
390 fbui_draw_vline (dpy, win, 110, 100, 0, RGB_WHITE);
391 fbui_flush (dpy, win);
392 }
393
394 fbui_window_close(dpy, win);
395 fbui_display_close (dpy);
396
397 return 0;
398 }
This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.