Fix red in bootloaders
[maemo-rb.git] / apps / plugins / test_gfx.c
blob728eb5600e07cd18a06e8769092d792fa43d42a7
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2009 by Jens Arnold
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "plugin.h"
20 #include "lib/grey.h"
21 #include "lib/helper.h"
23 //#define TEST_GREYLIB /* Uncomment for testing greylib instead of core gfx */
25 #ifdef TEST_GREYLIB
26 #define MYLCD(fn) grey_ ## fn
27 GREY_INFO_STRUCT
28 static unsigned char *gbuf;
29 static size_t gbuf_size = 0;
30 #else
31 #define MYLCD(fn) rb->lcd_ ## fn
32 #endif
34 #define DURATION (HZ) /* longer duration gives more precise results */
35 #define RND_SEED 0x43A678C3 /* arbirary */
37 PLUGIN_HEADER
39 static uint16_t rand_table[0x400];
40 static int log_fd;
43 static int log_init(void)
45 char logfilename[MAX_PATH];
46 int fd;
48 rb->create_numbered_filename(logfilename, "/", "test_gfx_log_", ".txt",
49 2 IF_CNFN_NUM_(, NULL));
50 fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC);
51 return fd;
54 static void init_rand_table(void)
56 int i;
58 rb->srand(RND_SEED); /* make it reproducable */
59 for (i = 0; i < 0x400; i++)
60 rand_table[i] = rb->rand();
63 static void time_drawpixel(void)
65 long time_start; /* start tickcount */
66 long time_end; /* end tickcount */
67 int count1, count2, count3, count4;
69 /* Test 1: DRMODE_SOLID */
70 MYLCD(set_drawmode)(DRMODE_SOLID);
71 count1 = 0;
72 rb->sleep(0); /* sync to tick */
73 time_start = *rb->current_tick;
74 while((time_end = *rb->current_tick) - time_start < DURATION)
76 unsigned rnd = rand_table[count1++ & 0x3ff];
77 MYLCD(drawpixel)((rnd >> 8) & 0x3f, rnd & 0x3f);
80 /* Test 2: DRMODE_FG */
81 MYLCD(set_drawmode)(DRMODE_FG);
82 count2 = 0;
83 rb->sleep(0); /* sync to tick */
84 time_start = *rb->current_tick;
85 while((time_end = *rb->current_tick) - time_start < DURATION)
87 unsigned rnd = rand_table[count2++ & 0x3ff];
88 MYLCD(drawpixel)((rnd >> 8) & 0x3f, rnd & 0x3f);
90 /* Test 3: DRMODE_BG */
91 MYLCD(set_drawmode)(DRMODE_BG);
92 count3 = 0;
93 rb->sleep(0); /* sync to tick */
94 time_start = *rb->current_tick;
95 while((time_end = *rb->current_tick) - time_start < DURATION)
97 unsigned rnd = rand_table[count3++ & 0x3ff];
98 MYLCD(drawpixel)((rnd >> 8) & 0x3f, rnd & 0x3f);
100 /* Test 4: DRMODE_COMPLEMENT */
101 MYLCD(set_drawmode)(DRMODE_COMPLEMENT);
102 count4 = 0;
103 rb->sleep(0); /* sync to tick */
104 time_start = *rb->current_tick;
105 while((time_end = *rb->current_tick) - time_start < DURATION)
107 unsigned rnd = rand_table[count4++ & 0x3ff];
108 MYLCD(drawpixel)((rnd >> 8) & 0x3f, rnd & 0x3f);
111 rb->fdprintf(log_fd, "lcd_drawpixel (pixels/s): %d/%d/%d/%d\n",
112 count1, count2, count3, count4);
115 static void time_drawline(void)
117 long time_start; /* start tickcount */
118 long time_end; /* end tickcount */
119 int count1, count2, count3, count4;
121 /* Test 1: DRMODE_SOLID */
122 MYLCD(set_drawmode)(DRMODE_SOLID);
123 count1 = 0;
124 rb->sleep(0); /* sync to tick */
125 time_start = *rb->current_tick;
126 while((time_end = *rb->current_tick) - time_start < DURATION)
128 unsigned rnd1 = rand_table[count1++ & 0x3ff];
129 unsigned rnd2 = rand_table[count1++ & 0x3ff];
130 MYLCD(drawline)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
131 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
134 /* Test 2: DRMODE_FG */
135 MYLCD(set_drawmode)(DRMODE_FG);
136 count2 = 0;
137 rb->sleep(0); /* sync to tick */
138 time_start = *rb->current_tick;
139 while((time_end = *rb->current_tick) - time_start < DURATION)
141 unsigned rnd1 = rand_table[count2++ & 0x3ff];
142 unsigned rnd2 = rand_table[count2++ & 0x3ff];
143 MYLCD(drawline)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
144 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
146 /* Test 3: DRMODE_BG */
147 MYLCD(set_drawmode)(DRMODE_BG);
148 count3 = 0;
149 rb->sleep(0); /* sync to tick */
150 time_start = *rb->current_tick;
151 while((time_end = *rb->current_tick) - time_start < DURATION)
153 unsigned rnd1 = rand_table[count3++ & 0x3ff];
154 unsigned rnd2 = rand_table[count3++ & 0x3ff];
155 MYLCD(drawline)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
156 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
158 /* Test 4: DRMODE_COMPLEMENT */
159 MYLCD(set_drawmode)(DRMODE_COMPLEMENT);
160 count4 = 0;
161 rb->sleep(0); /* sync to tick */
162 time_start = *rb->current_tick;
163 while((time_end = *rb->current_tick) - time_start < DURATION)
165 unsigned rnd1 = rand_table[count4++ & 0x3ff];
166 unsigned rnd2 = rand_table[count4++ & 0x3ff];
167 MYLCD(drawline)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
168 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
171 rb->fdprintf(log_fd, "lcd_drawline (lines/s): %d/%d/%d/%d\n",
172 count1, count2, count3, count4);
175 static void time_hline(void)
177 long time_start; /* start tickcount */
178 long time_end; /* end tickcount */
179 int count1, count2, count3, count4;
181 /* Test 1: DRMODE_SOLID */
182 MYLCD(set_drawmode)(DRMODE_SOLID);
183 count1 = 0;
184 rb->sleep(0); /* sync to tick */
185 time_start = *rb->current_tick;
186 while((time_end = *rb->current_tick) - time_start < DURATION)
188 unsigned rnd1 = rand_table[count1++ & 0x3ff];
189 unsigned rnd2 = rand_table[count1++ & 0x3ff];
190 MYLCD(hline)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
193 /* Test 2: DRMODE_FG */
194 MYLCD(set_drawmode)(DRMODE_FG);
195 count2 = 0;
196 rb->sleep(0); /* sync to tick */
197 time_start = *rb->current_tick;
198 while((time_end = *rb->current_tick) - time_start < DURATION)
200 unsigned rnd1 = rand_table[count2++ & 0x3ff];
201 unsigned rnd2 = rand_table[count2++ & 0x3ff];
202 MYLCD(hline)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
204 /* Test 3: DRMODE_BG */
205 MYLCD(set_drawmode)(DRMODE_BG);
206 count3 = 0;
207 rb->sleep(0); /* sync to tick */
208 time_start = *rb->current_tick;
209 while((time_end = *rb->current_tick) - time_start < DURATION)
211 unsigned rnd1 = rand_table[count3++ & 0x3ff];
212 unsigned rnd2 = rand_table[count3++ & 0x3ff];
213 MYLCD(hline)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
215 /* Test 4: DRMODE_COMPLEMENT */
216 MYLCD(set_drawmode)(DRMODE_COMPLEMENT);
217 count4 = 0;
218 rb->sleep(0); /* sync to tick */
219 time_start = *rb->current_tick;
220 while((time_end = *rb->current_tick) - time_start < DURATION)
222 unsigned rnd1 = rand_table[count4++ & 0x3ff];
223 unsigned rnd2 = rand_table[count4++ & 0x3ff];
224 MYLCD(hline)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
227 rb->fdprintf(log_fd, "lcd_hline (lines/s): %d/%d/%d/%d\n",
228 count1, count2, count3, count4);
231 static void time_vline(void)
233 long time_start; /* start tickcount */
234 long time_end; /* end tickcount */
235 int count1, count2, count3, count4;
237 /* Test 1: DRMODE_SOLID */
238 MYLCD(set_drawmode)(DRMODE_SOLID);
239 count1 = 0;
240 rb->sleep(0); /* sync to tick */
241 time_start = *rb->current_tick;
242 while((time_end = *rb->current_tick) - time_start < DURATION)
244 unsigned rnd1 = rand_table[count1++ & 0x3ff];
245 unsigned rnd2 = rand_table[count1++ & 0x3ff];
246 MYLCD(vline)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
249 /* Test 2: DRMODE_FG */
250 MYLCD(set_drawmode)(DRMODE_FG);
251 count2 = 0;
252 rb->sleep(0); /* sync to tick */
253 time_start = *rb->current_tick;
254 while((time_end = *rb->current_tick) - time_start < DURATION)
256 unsigned rnd1 = rand_table[count2++ & 0x3ff];
257 unsigned rnd2 = rand_table[count2++ & 0x3ff];
258 MYLCD(vline)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
260 /* Test 3: DRMODE_BG */
261 MYLCD(set_drawmode)(DRMODE_BG);
262 count3 = 0;
263 rb->sleep(0); /* sync to tick */
264 time_start = *rb->current_tick;
265 while((time_end = *rb->current_tick) - time_start < DURATION)
267 unsigned rnd1 = rand_table[count3++ & 0x3ff];
268 unsigned rnd2 = rand_table[count3++ & 0x3ff];
269 MYLCD(vline)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
271 /* Test 4: DRMODE_COMPLEMENT */
272 MYLCD(set_drawmode)(DRMODE_COMPLEMENT);
273 count4 = 0;
274 rb->sleep(0); /* sync to tick */
275 time_start = *rb->current_tick;
276 while((time_end = *rb->current_tick) - time_start < DURATION)
278 unsigned rnd1 = rand_table[count4++ & 0x3ff];
279 unsigned rnd2 = rand_table[count4++ & 0x3ff];
280 MYLCD(vline)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
283 rb->fdprintf(log_fd, "lcd_vline (lines/s): %d/%d/%d/%d\n",
284 count1, count2, count3, count4);
287 static void time_fillrect(void)
289 long time_start; /* start tickcount */
290 long time_end; /* end tickcount */
291 int count1, count2, count3, count4;
293 /* Test 1: DRMODE_SOLID */
294 MYLCD(set_drawmode)(DRMODE_SOLID);
295 count1 = 0;
296 rb->sleep(0); /* sync to tick */
297 time_start = *rb->current_tick;
298 while((time_end = *rb->current_tick) - time_start < DURATION)
300 unsigned rnd1 = rand_table[count1++ & 0x3ff];
301 unsigned rnd2 = rand_table[count1++ & 0x3ff];
302 MYLCD(fillrect)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
303 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
306 /* Test 2: DRMODE_FG */
307 MYLCD(set_drawmode)(DRMODE_FG);
308 count2 = 0;
309 rb->sleep(0); /* sync to tick */
310 time_start = *rb->current_tick;
311 while((time_end = *rb->current_tick) - time_start < DURATION)
313 unsigned rnd1 = rand_table[count2++ & 0x3ff];
314 unsigned rnd2 = rand_table[count2++ & 0x3ff];
315 MYLCD(fillrect)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
316 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
318 /* Test 3: DRMODE_BG */
319 MYLCD(set_drawmode)(DRMODE_BG);
320 count3 = 0;
321 rb->sleep(0); /* sync to tick */
322 time_start = *rb->current_tick;
323 while((time_end = *rb->current_tick) - time_start < DURATION)
325 unsigned rnd1 = rand_table[count3++ & 0x3ff];
326 unsigned rnd2 = rand_table[count3++ & 0x3ff];
327 MYLCD(fillrect)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
328 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
330 /* Test 4: DRMODE_COMPLEMENT */
331 MYLCD(set_drawmode)(DRMODE_COMPLEMENT);
332 count4 = 0;
333 rb->sleep(0); /* sync to tick */
334 time_start = *rb->current_tick;
335 while((time_end = *rb->current_tick) - time_start < DURATION)
337 unsigned rnd1 = rand_table[count4++ & 0x3ff];
338 unsigned rnd2 = rand_table[count4++ & 0x3ff];
339 MYLCD(fillrect)((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
340 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
343 rb->fdprintf(log_fd, "lcd_fillrect (rects/s): %d/%d/%d/%d\n",
344 count1, count2, count3, count4);
347 static void time_text(void) /* tests mono_bitmap performance */
349 long time_start; /* start tickcount */
350 long time_end; /* end tickcount */
351 int count1, count2, count3, count4;
353 rb->lcd_setfont(FONT_SYSFIXED);
355 /* Test 1: DRMODE_SOLID */
356 MYLCD(set_drawmode)(DRMODE_SOLID);
357 count1 = 0;
358 rb->sleep(0); /* sync to tick */
359 time_start = *rb->current_tick;
360 while((time_end = *rb->current_tick) - time_start < DURATION)
362 unsigned rnd = rand_table[count1++ & 0x3ff];
363 MYLCD(putsxy)((rnd >> 8) & 0x3f, rnd & 0x3f, "Rockbox!");
366 /* Test 2: DRMODE_FG */
367 MYLCD(set_drawmode)(DRMODE_FG);
368 count2 = 0;
369 rb->sleep(0); /* sync to tick */
370 time_start = *rb->current_tick;
371 while((time_end = *rb->current_tick) - time_start < DURATION)
373 unsigned rnd = rand_table[count2++ & 0x3ff];
374 MYLCD(putsxy)((rnd >> 8) & 0x3f, rnd & 0x3f, "Rockbox!");
376 /* Test 3: DRMODE_BG */
377 MYLCD(set_drawmode)(DRMODE_BG);
378 count3 = 0;
379 rb->sleep(0); /* sync to tick */
380 time_start = *rb->current_tick;
381 while((time_end = *rb->current_tick) - time_start < DURATION)
383 unsigned rnd = rand_table[count3++ & 0x3ff];
384 MYLCD(putsxy)((rnd >> 8) & 0x3f, rnd & 0x3f, "Rockbox!");
386 /* Test 4: DRMODE_COMPLEMENT */
387 MYLCD(set_drawmode)(DRMODE_COMPLEMENT);
388 count4 = 0;
389 rb->sleep(0); /* sync to tick */
390 time_start = *rb->current_tick;
391 while((time_end = *rb->current_tick) - time_start < DURATION)
393 unsigned rnd = rand_table[count4++ & 0x3ff];
394 MYLCD(putsxy)((rnd >> 8) & 0x3f, rnd & 0x3f, "Rockbox!");
397 rb->fdprintf(log_fd, "lcd_putsxy (strings/s): %d/%d/%d/%d\n",
398 count1, count2, count3, count4);
401 /* plugin entry point */
402 enum plugin_status plugin_start(const void* parameter)
404 #ifndef SIMULATOR
405 int cpu_freq;
406 #endif
408 /* standard stuff */
409 (void)parameter;
411 log_fd = log_init();
412 if (log_fd < 0)
414 rb->splash(HZ, "Could not create logfile");
415 return PLUGIN_ERROR;
417 rb->fdprintf(log_fd, "%s",
418 #ifdef TEST_GREYLIB
419 "Greylib performance test.\n"
420 #else
421 "LCD driver performance test.\n"
422 #endif
423 "----------------------------\n\n"
424 "Results are printed in the following drawmode order:\n"
425 "solid/foreground/background/complement\n\n");
427 #ifdef TEST_GREYLIB
428 /* get the remainder of the plugin buffer */
429 gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
431 /* initialize the greyscale buffer.*/
432 if (!grey_init(gbuf, gbuf_size, GREY_BUFFERED|GREY_ON_COP,
433 LCD_WIDTH, LCD_HEIGHT, NULL))
435 rb->close(log_fd);
436 rb->splash(HZ, "Couldn't init greyscale library");
437 return PLUGIN_ERROR;
439 #elif LCD_DEPTH > 1
440 rb->lcd_set_backdrop(NULL);
441 rb->lcd_clear_display();
442 #endif
443 backlight_force_on(); /* backlight control in lib/helper.c */
445 rb->splashf(0, "LCD driver performance test, please wait %d sec",
446 6*4*DURATION/HZ);
447 init_rand_table();
449 #ifndef SIMULATOR
450 cpu_freq = *rb->cpu_frequency; /* remember CPU frequency */
451 #endif
453 time_drawpixel();
454 time_drawline();
455 time_hline();
456 time_vline();
457 time_fillrect();
458 time_text();
460 #ifndef SIMULATOR
461 if (*rb->cpu_frequency != cpu_freq)
462 rb->fdprintf(log_fd, "\nCPU: %s\n", "clock changed!");
463 else
464 rb->fdprintf(log_fd, "\nCPU: %d MHz\n",
465 (cpu_freq + 500000) / 1000000);
466 #endif
467 rb->close(log_fd);
468 backlight_use_settings();
469 #ifdef TEST_GREYLIB
470 grey_release();
471 #endif
473 return PLUGIN_OK;