Add another delay in the AMSv2 sd controller driver as a work-around for SD initialis...
[maemo-rb.git] / apps / plugins / test_gfx.c
blobcde77c55fe76537b245305e9a98187837220a04b
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 ****************************************************************************/
20 //#define TEST_GREYLIB /* Uncomment for testing greylib instead of core gfx */
22 #include "plugin.h"
23 #ifdef TEST_GREYLIB /* otherwise, mylcd defaults to core gfx */
24 #include "lib/grey.h"
25 #endif
26 #include "lib/helper.h"
27 #include "lib/mylcd.h"
29 #ifdef TEST_GREYLIB
30 GREY_INFO_STRUCT
31 static unsigned char *gbuf;
32 static size_t gbuf_size = 0;
33 #endif
35 #define DURATION (HZ) /* longer duration gives more precise results */
36 #define RND_SEED 0x43A678C3 /* arbirary */
40 static uint16_t rand_table[0x400];
41 static int log_fd;
44 static int log_init(void)
46 char logfilename[MAX_PATH];
47 int fd;
49 rb->create_numbered_filename(logfilename, "/", "test_gfx_log_", ".txt",
50 2 IF_CNFN_NUM_(, NULL));
51 fd = rb->open(logfilename, O_RDWR|O_CREAT|O_TRUNC, 0666);
52 return fd;
55 static void init_rand_table(void)
57 int i;
59 rb->srand(RND_SEED); /* make it reproducable */
60 for (i = 0; i < 0x400; i++)
61 rand_table[i] = rb->rand();
64 static void time_drawpixel(void)
66 long time_start; /* start tickcount */
67 long time_end; /* end tickcount */
68 int count1, count2, count3, count4;
70 /* Test 1: DRMODE_SOLID */
71 mylcd_set_drawmode(DRMODE_SOLID);
72 count1 = 0;
73 rb->sleep(0); /* sync to tick */
74 time_start = *rb->current_tick;
75 while((time_end = *rb->current_tick) - time_start < DURATION)
77 unsigned rnd = rand_table[count1++ & 0x3ff];
78 mylcd_drawpixel((rnd >> 8) & 0x3f, rnd & 0x3f);
81 /* Test 2: DRMODE_FG */
82 mylcd_set_drawmode(DRMODE_FG);
83 count2 = 0;
84 rb->sleep(0); /* sync to tick */
85 time_start = *rb->current_tick;
86 while((time_end = *rb->current_tick) - time_start < DURATION)
88 unsigned rnd = rand_table[count2++ & 0x3ff];
89 mylcd_drawpixel((rnd >> 8) & 0x3f, rnd & 0x3f);
91 /* Test 3: DRMODE_BG */
92 mylcd_set_drawmode(DRMODE_BG);
93 count3 = 0;
94 rb->sleep(0); /* sync to tick */
95 time_start = *rb->current_tick;
96 while((time_end = *rb->current_tick) - time_start < DURATION)
98 unsigned rnd = rand_table[count3++ & 0x3ff];
99 mylcd_drawpixel((rnd >> 8) & 0x3f, rnd & 0x3f);
101 /* Test 4: DRMODE_COMPLEMENT */
102 mylcd_set_drawmode(DRMODE_COMPLEMENT);
103 count4 = 0;
104 rb->sleep(0); /* sync to tick */
105 time_start = *rb->current_tick;
106 while((time_end = *rb->current_tick) - time_start < DURATION)
108 unsigned rnd = rand_table[count4++ & 0x3ff];
109 mylcd_drawpixel((rnd >> 8) & 0x3f, rnd & 0x3f);
112 rb->fdprintf(log_fd, "lcd_drawpixel (pixels/s): %d/%d/%d/%d\n",
113 count1, count2, count3, count4);
116 static void time_drawline(void)
118 long time_start; /* start tickcount */
119 long time_end; /* end tickcount */
120 int count1, count2, count3, count4;
122 /* Test 1: DRMODE_SOLID */
123 mylcd_set_drawmode(DRMODE_SOLID);
124 count1 = 0;
125 rb->sleep(0); /* sync to tick */
126 time_start = *rb->current_tick;
127 while((time_end = *rb->current_tick) - time_start < DURATION)
129 unsigned rnd1 = rand_table[count1++ & 0x3ff];
130 unsigned rnd2 = rand_table[count1++ & 0x3ff];
131 mylcd_drawline((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
132 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
135 /* Test 2: DRMODE_FG */
136 mylcd_set_drawmode(DRMODE_FG);
137 count2 = 0;
138 rb->sleep(0); /* sync to tick */
139 time_start = *rb->current_tick;
140 while((time_end = *rb->current_tick) - time_start < DURATION)
142 unsigned rnd1 = rand_table[count2++ & 0x3ff];
143 unsigned rnd2 = rand_table[count2++ & 0x3ff];
144 mylcd_drawline((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
145 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
147 /* Test 3: DRMODE_BG */
148 mylcd_set_drawmode(DRMODE_BG);
149 count3 = 0;
150 rb->sleep(0); /* sync to tick */
151 time_start = *rb->current_tick;
152 while((time_end = *rb->current_tick) - time_start < DURATION)
154 unsigned rnd1 = rand_table[count3++ & 0x3ff];
155 unsigned rnd2 = rand_table[count3++ & 0x3ff];
156 mylcd_drawline((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
157 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
159 /* Test 4: DRMODE_COMPLEMENT */
160 mylcd_set_drawmode(DRMODE_COMPLEMENT);
161 count4 = 0;
162 rb->sleep(0); /* sync to tick */
163 time_start = *rb->current_tick;
164 while((time_end = *rb->current_tick) - time_start < DURATION)
166 unsigned rnd1 = rand_table[count4++ & 0x3ff];
167 unsigned rnd2 = rand_table[count4++ & 0x3ff];
168 mylcd_drawline((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
169 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
172 rb->fdprintf(log_fd, "lcd_drawline (lines/s): %d/%d/%d/%d\n",
173 count1, count2, count3, count4);
176 static void time_hline(void)
178 long time_start; /* start tickcount */
179 long time_end; /* end tickcount */
180 int count1, count2, count3, count4;
182 /* Test 1: DRMODE_SOLID */
183 mylcd_set_drawmode(DRMODE_SOLID);
184 count1 = 0;
185 rb->sleep(0); /* sync to tick */
186 time_start = *rb->current_tick;
187 while((time_end = *rb->current_tick) - time_start < DURATION)
189 unsigned rnd1 = rand_table[count1++ & 0x3ff];
190 unsigned rnd2 = rand_table[count1++ & 0x3ff];
191 mylcd_hline((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
194 /* Test 2: DRMODE_FG */
195 mylcd_set_drawmode(DRMODE_FG);
196 count2 = 0;
197 rb->sleep(0); /* sync to tick */
198 time_start = *rb->current_tick;
199 while((time_end = *rb->current_tick) - time_start < DURATION)
201 unsigned rnd1 = rand_table[count2++ & 0x3ff];
202 unsigned rnd2 = rand_table[count2++ & 0x3ff];
203 mylcd_hline((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
205 /* Test 3: DRMODE_BG */
206 mylcd_set_drawmode(DRMODE_BG);
207 count3 = 0;
208 rb->sleep(0); /* sync to tick */
209 time_start = *rb->current_tick;
210 while((time_end = *rb->current_tick) - time_start < DURATION)
212 unsigned rnd1 = rand_table[count3++ & 0x3ff];
213 unsigned rnd2 = rand_table[count3++ & 0x3ff];
214 mylcd_hline((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
216 /* Test 4: DRMODE_COMPLEMENT */
217 mylcd_set_drawmode(DRMODE_COMPLEMENT);
218 count4 = 0;
219 rb->sleep(0); /* sync to tick */
220 time_start = *rb->current_tick;
221 while((time_end = *rb->current_tick) - time_start < DURATION)
223 unsigned rnd1 = rand_table[count4++ & 0x3ff];
224 unsigned rnd2 = rand_table[count4++ & 0x3ff];
225 mylcd_hline((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
228 rb->fdprintf(log_fd, "lcd_hline (lines/s): %d/%d/%d/%d\n",
229 count1, count2, count3, count4);
232 static void time_vline(void)
234 long time_start; /* start tickcount */
235 long time_end; /* end tickcount */
236 int count1, count2, count3, count4;
238 /* Test 1: DRMODE_SOLID */
239 mylcd_set_drawmode(DRMODE_SOLID);
240 count1 = 0;
241 rb->sleep(0); /* sync to tick */
242 time_start = *rb->current_tick;
243 while((time_end = *rb->current_tick) - time_start < DURATION)
245 unsigned rnd1 = rand_table[count1++ & 0x3ff];
246 unsigned rnd2 = rand_table[count1++ & 0x3ff];
247 mylcd_vline((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
250 /* Test 2: DRMODE_FG */
251 mylcd_set_drawmode(DRMODE_FG);
252 count2 = 0;
253 rb->sleep(0); /* sync to tick */
254 time_start = *rb->current_tick;
255 while((time_end = *rb->current_tick) - time_start < DURATION)
257 unsigned rnd1 = rand_table[count2++ & 0x3ff];
258 unsigned rnd2 = rand_table[count2++ & 0x3ff];
259 mylcd_vline((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
261 /* Test 3: DRMODE_BG */
262 mylcd_set_drawmode(DRMODE_BG);
263 count3 = 0;
264 rb->sleep(0); /* sync to tick */
265 time_start = *rb->current_tick;
266 while((time_end = *rb->current_tick) - time_start < DURATION)
268 unsigned rnd1 = rand_table[count3++ & 0x3ff];
269 unsigned rnd2 = rand_table[count3++ & 0x3ff];
270 mylcd_vline((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
272 /* Test 4: DRMODE_COMPLEMENT */
273 mylcd_set_drawmode(DRMODE_COMPLEMENT);
274 count4 = 0;
275 rb->sleep(0); /* sync to tick */
276 time_start = *rb->current_tick;
277 while((time_end = *rb->current_tick) - time_start < DURATION)
279 unsigned rnd1 = rand_table[count4++ & 0x3ff];
280 unsigned rnd2 = rand_table[count4++ & 0x3ff];
281 mylcd_vline((rnd1 >> 8) & 0x3f, rnd1 & 0x3f, rnd2 & 0x3f);
284 rb->fdprintf(log_fd, "lcd_vline (lines/s): %d/%d/%d/%d\n",
285 count1, count2, count3, count4);
288 static void time_fillrect(void)
290 long time_start; /* start tickcount */
291 long time_end; /* end tickcount */
292 int count1, count2, count3, count4;
294 /* Test 1: DRMODE_SOLID */
295 mylcd_set_drawmode(DRMODE_SOLID);
296 count1 = 0;
297 rb->sleep(0); /* sync to tick */
298 time_start = *rb->current_tick;
299 while((time_end = *rb->current_tick) - time_start < DURATION)
301 unsigned rnd1 = rand_table[count1++ & 0x3ff];
302 unsigned rnd2 = rand_table[count1++ & 0x3ff];
303 mylcd_fillrect((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
304 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
307 /* Test 2: DRMODE_FG */
308 mylcd_set_drawmode(DRMODE_FG);
309 count2 = 0;
310 rb->sleep(0); /* sync to tick */
311 time_start = *rb->current_tick;
312 while((time_end = *rb->current_tick) - time_start < DURATION)
314 unsigned rnd1 = rand_table[count2++ & 0x3ff];
315 unsigned rnd2 = rand_table[count2++ & 0x3ff];
316 mylcd_fillrect((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
317 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
319 /* Test 3: DRMODE_BG */
320 mylcd_set_drawmode(DRMODE_BG);
321 count3 = 0;
322 rb->sleep(0); /* sync to tick */
323 time_start = *rb->current_tick;
324 while((time_end = *rb->current_tick) - time_start < DURATION)
326 unsigned rnd1 = rand_table[count3++ & 0x3ff];
327 unsigned rnd2 = rand_table[count3++ & 0x3ff];
328 mylcd_fillrect((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
329 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
331 /* Test 4: DRMODE_COMPLEMENT */
332 mylcd_set_drawmode(DRMODE_COMPLEMENT);
333 count4 = 0;
334 rb->sleep(0); /* sync to tick */
335 time_start = *rb->current_tick;
336 while((time_end = *rb->current_tick) - time_start < DURATION)
338 unsigned rnd1 = rand_table[count4++ & 0x3ff];
339 unsigned rnd2 = rand_table[count4++ & 0x3ff];
340 mylcd_fillrect((rnd1 >> 8) & 0x3f, rnd1 & 0x3f,
341 (rnd2 >> 8) & 0x3f, rnd2 & 0x3f);
344 rb->fdprintf(log_fd, "lcd_fillrect (rects/s): %d/%d/%d/%d\n",
345 count1, count2, count3, count4);
348 static void time_text(void) /* tests mono_bitmap performance */
350 long time_start; /* start tickcount */
351 long time_end; /* end tickcount */
352 int count1, count2, count3, count4;
354 rb->lcd_setfont(FONT_SYSFIXED);
356 /* Test 1: DRMODE_SOLID */
357 mylcd_set_drawmode(DRMODE_SOLID);
358 count1 = 0;
359 rb->sleep(0); /* sync to tick */
360 time_start = *rb->current_tick;
361 while((time_end = *rb->current_tick) - time_start < DURATION)
363 unsigned rnd = rand_table[count1++ & 0x3ff];
364 mylcd_putsxy((rnd >> 8) & 0x3f, rnd & 0x3f, "Rockbox!");
367 /* Test 2: DRMODE_FG */
368 mylcd_set_drawmode(DRMODE_FG);
369 count2 = 0;
370 rb->sleep(0); /* sync to tick */
371 time_start = *rb->current_tick;
372 while((time_end = *rb->current_tick) - time_start < DURATION)
374 unsigned rnd = rand_table[count2++ & 0x3ff];
375 mylcd_putsxy((rnd >> 8) & 0x3f, rnd & 0x3f, "Rockbox!");
377 /* Test 3: DRMODE_BG */
378 mylcd_set_drawmode(DRMODE_BG);
379 count3 = 0;
380 rb->sleep(0); /* sync to tick */
381 time_start = *rb->current_tick;
382 while((time_end = *rb->current_tick) - time_start < DURATION)
384 unsigned rnd = rand_table[count3++ & 0x3ff];
385 mylcd_putsxy((rnd >> 8) & 0x3f, rnd & 0x3f, "Rockbox!");
387 /* Test 4: DRMODE_COMPLEMENT */
388 mylcd_set_drawmode(DRMODE_COMPLEMENT);
389 count4 = 0;
390 rb->sleep(0); /* sync to tick */
391 time_start = *rb->current_tick;
392 while((time_end = *rb->current_tick) - time_start < DURATION)
394 unsigned rnd = rand_table[count4++ & 0x3ff];
395 mylcd_putsxy((rnd >> 8) & 0x3f, rnd & 0x3f, "Rockbox!");
398 rb->fdprintf(log_fd, "lcd_putsxy (strings/s): %d/%d/%d/%d\n",
399 count1, count2, count3, count4);
402 /* plugin entry point */
403 enum plugin_status plugin_start(const void* parameter)
405 #ifndef SIMULATOR
406 int cpu_freq;
407 #endif
409 /* standard stuff */
410 (void)parameter;
412 log_fd = log_init();
413 if (log_fd < 0)
415 rb->splash(HZ, "Could not create logfile");
416 return PLUGIN_ERROR;
418 rb->fdprintf(log_fd, "%s",
419 #ifdef TEST_GREYLIB
420 "Greylib performance test.\n"
421 #else
422 "LCD driver performance test.\n"
423 #endif
424 "----------------------------\n\n"
425 "Results are printed in the following drawmode order:\n"
426 "solid/foreground/background/complement\n\n");
428 #ifdef TEST_GREYLIB
429 /* get the remainder of the plugin buffer */
430 gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
432 /* initialize the greyscale buffer.*/
433 if (!grey_init(gbuf, gbuf_size, GREY_BUFFERED|GREY_ON_COP,
434 LCD_WIDTH, LCD_HEIGHT, NULL))
436 rb->close(log_fd);
437 rb->splash(HZ, "Couldn't init greyscale library");
438 return PLUGIN_ERROR;
440 #elif LCD_DEPTH > 1
441 rb->lcd_set_backdrop(NULL);
442 rb->lcd_clear_display();
443 #endif
444 backlight_ignore_timeout();
446 rb->splashf(0, "LCD driver performance test, please wait %d sec",
447 6*4*DURATION/HZ);
448 init_rand_table();
450 #ifndef SIMULATOR
451 cpu_freq = *rb->cpu_frequency; /* remember CPU frequency */
452 #endif
454 time_drawpixel();
455 time_drawline();
456 time_hline();
457 time_vline();
458 time_fillrect();
459 time_text();
461 #ifndef SIMULATOR
462 if (*rb->cpu_frequency != cpu_freq)
463 rb->fdprintf(log_fd, "\nCPU: %s\n", "clock changed!");
464 else
465 rb->fdprintf(log_fd, "\nCPU: %d MHz\n",
466 (cpu_freq + 500000) / 1000000);
467 #endif
468 rb->close(log_fd);
469 backlight_use_settings();
470 #ifdef TEST_GREYLIB
471 grey_release();
472 #endif
474 return PLUGIN_OK;