Rockbox Utility: make the window icon also include a larger one.
[maemo-rb.git] / apps / plugins / test_fps.c
blobda4684f60adb9996b1cb030e380a55b300101e55
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2005 Peter D'Hoye
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "plugin.h"
22 #include "lib/helper.h"
23 #include "lib/grey.h"
25 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
26 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
27 #define FPS_QUIT BUTTON_MENU
28 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
29 #define FPS_QUIT BUTTON_RC_REC
30 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
31 #define FPS_QUIT BUTTON_PLAY
32 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
33 #define FPS_QUIT (BUTTON_HOME|BUTTON_REPEAT)
34 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
35 #define FPS_QUIT (BUTTON_REC|BUTTON_PLAY)
36 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
37 #define FPS_QUIT (BUTTON_REC|BUTTON_REPEAT)
38 #elif CONFIG_KEYPAD == RK27XX_GENERIC_PAD
39 #define FPS_QUIT (BUTTON_M|BUTTON_REPEAT)
40 #elif defined(BUTTON_OFF)
41 #define FPS_QUIT BUTTON_OFF
42 #else
43 #define FPS_QUIT BUTTON_POWER
44 #endif
46 #define DURATION (2*HZ) /* longer duration gives more precise results */
50 /* Screen logging */
51 static int line;
52 static int max_line;
53 #ifdef HAVE_REMOTE_LCD
54 static int remote_line;
55 static int remote_max_line;
56 #endif
58 static void log_init(void)
60 int h;
62 rb->lcd_getstringsize("A", NULL, &h);
63 max_line = LCD_HEIGHT / h;
64 line = 0;
65 rb->lcd_clear_display();
66 rb->lcd_update();
67 #ifdef HAVE_REMOTE_LCD
68 rb->lcd_remote_getstringsize("A", NULL, &h);
69 remote_max_line = LCD_REMOTE_HEIGHT / h;
70 remote_line = 0;
71 rb->lcd_remote_clear_display();
72 rb->lcd_remote_update();
73 #endif
76 static void log_text(char *text)
78 rb->lcd_puts(0, line, text);
79 if (++line >= max_line)
80 line = 0;
81 rb->lcd_update();
82 #ifdef HAVE_REMOTE_LCD
83 rb->lcd_remote_puts(0, remote_line, text);
84 if (++remote_line >= remote_max_line)
85 remote_line = 0;
86 rb->lcd_remote_update();
87 #endif
90 static int calc_tenth_fps(int framecount, long ticks)
92 return (10*HZ) * framecount / ticks;
95 static void time_main_update(void)
97 char str[32]; /* text buffer */
98 long time_start; /* start tickcount */
99 long time_end; /* end tickcount */
100 int frame_count;
101 int fps;
103 const int part14_x = LCD_WIDTH/4; /* x-offset for 1/4 update test */
104 const int part14_w = LCD_WIDTH/2; /* x-size for 1/4 update test */
105 const int part14_y = LCD_HEIGHT/4; /* y-offset for 1/4 update test */
106 const int part14_h = LCD_HEIGHT/2; /* y-size for 1/4 update test */
108 log_text("Main LCD Update");
110 /* Test 1: full LCD update */
111 frame_count = 0;
112 rb->sleep(0); /* sync to tick */
113 time_start = *rb->current_tick;
114 while((time_end = *rb->current_tick) - time_start < DURATION)
116 rb->lcd_update();
117 frame_count++;
119 fps = calc_tenth_fps(frame_count, time_end - time_start);
120 rb->snprintf(str, sizeof(str), "1/1: %d.%d fps", fps / 10, fps % 10);
121 log_text(str);
123 /* Test 2: quarter LCD update */
124 frame_count = 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 rb->lcd_update_rect(part14_x, part14_y, part14_w, part14_h);
130 frame_count++;
132 fps = calc_tenth_fps(frame_count, time_end - time_start);
133 rb->snprintf(str, sizeof(str), "1/4: %d.%d fps", fps / 10, fps % 10);
134 log_text(str);
137 #if defined(HAVE_LCD_COLOR) && (MEMORYSIZE > 2)
139 #if LCD_WIDTH >= LCD_HEIGHT
140 #define YUV_WIDTH LCD_WIDTH
141 #define YUV_HEIGHT LCD_HEIGHT
142 #else /* Assume the screen is rotated on portrait LCDs */
143 #define YUV_WIDTH LCD_HEIGHT
144 #define YUV_HEIGHT LCD_WIDTH
145 #endif
147 static unsigned char ydata[YUV_HEIGHT][YUV_WIDTH];
148 static unsigned char udata[YUV_HEIGHT/2][YUV_WIDTH/2];
149 static unsigned char vdata[YUV_HEIGHT/2][YUV_WIDTH/2];
151 static unsigned char * const yuvbuf[3] = {
152 (void*)ydata,
153 (void*)udata,
154 (void*)vdata
157 static void make_gradient_rect(int width, int height)
159 unsigned char vline[YUV_WIDTH/2];
160 int x, y;
162 width /= 2;
163 height /= 2;
165 for (x = 0; x < width; x++)
166 vline[x] = (x << 8) / width;
167 for (y = 0; y < height; y++)
169 rb->memset(udata[y], (y << 8) / height, width);
170 rb->memcpy(vdata[y], vline, width);
174 static void time_main_yuv(void)
176 char str[32]; /* text buffer */
177 long time_start; /* start tickcount */
178 long time_end; /* end tickcount */
179 int frame_count;
180 int fps;
182 const int part14_x = YUV_WIDTH/4; /* x-offset for 1/4 update test */
183 const int part14_w = YUV_WIDTH/2; /* x-size for 1/4 update test */
184 const int part14_y = YUV_HEIGHT/4; /* y-offset for 1/4 update test */
185 const int part14_h = YUV_HEIGHT/2; /* y-size for 1/4 update test */
187 log_text("Main LCD YUV");
189 rb->memset(ydata, 128, sizeof(ydata)); /* medium grey */
191 /* Test 1: full LCD update */
192 make_gradient_rect(YUV_WIDTH, YUV_HEIGHT);
194 frame_count = 0;
195 rb->sleep(0); /* sync to tick */
196 time_start = *rb->current_tick;
197 while((time_end = *rb->current_tick) - time_start < DURATION)
199 rb->lcd_blit_yuv(yuvbuf, 0, 0, YUV_WIDTH,
200 0, 0, YUV_WIDTH, YUV_HEIGHT);
201 frame_count++;
203 fps = calc_tenth_fps(frame_count, time_end - time_start);
204 rb->snprintf(str, sizeof(str), "1/1: %d.%d fps", fps / 10, fps % 10);
205 log_text(str);
207 /* Test 2: quarter LCD update */
208 make_gradient_rect(YUV_WIDTH/2, YUV_HEIGHT/2);
210 frame_count = 0;
211 rb->sleep(0); /* sync to tick */
212 time_start = *rb->current_tick;
213 while((time_end = *rb->current_tick) - time_start < DURATION)
215 rb->lcd_blit_yuv(yuvbuf, 0, 0, YUV_WIDTH,
216 part14_x, part14_y, part14_w, part14_h);
217 frame_count++;
219 fps = calc_tenth_fps(frame_count, time_end - time_start);
220 rb->snprintf(str, sizeof(str), "1/4: %d.%d fps", fps / 10, fps % 10);
221 log_text(str);
223 #endif
225 #ifdef HAVE_REMOTE_LCD
226 static void time_remote_update(void)
228 char str[32]; /* text buffer */
229 long time_start; /* start tickcount */
230 long time_end; /* end tickcount */
231 int frame_count;
232 int fps;
234 const int part14_x = LCD_REMOTE_WIDTH/4; /* x-offset for 1/4 update test */
235 const int part14_w = LCD_REMOTE_WIDTH/2; /* x-size for 1/4 update test */
236 const int part14_y = LCD_REMOTE_HEIGHT/4; /* y-offset for 1/4 update test */
237 const int part14_h = LCD_REMOTE_HEIGHT/2; /* y-size for 1/4 update test */
239 log_text("Remote LCD Update");
241 /* Test 1: full LCD update */
242 frame_count = 0;
243 rb->sleep(0); /* sync to tick */
244 time_start = *rb->current_tick;
245 while((time_end = *rb->current_tick) - time_start < DURATION)
247 rb->lcd_remote_update();
248 frame_count++;
250 fps = calc_tenth_fps(frame_count, time_end - time_start);
251 rb->snprintf(str, sizeof(str), "1/1: %d.%d fps", fps / 10, fps % 10);
252 log_text(str);
254 /* Test 2: quarter LCD update */
255 frame_count = 0;
256 rb->sleep(0); /* sync to tick */
257 time_start = *rb->current_tick;
258 while((time_end = *rb->current_tick) - time_start < DURATION)
260 rb->lcd_remote_update_rect(part14_x, part14_y, part14_w, part14_h);
261 frame_count++;
263 fps = calc_tenth_fps(frame_count, time_end - time_start);
264 rb->snprintf(str, sizeof(str), "1/4: %d.%d fps", fps / 10, fps % 10);
265 log_text(str);
267 #endif
269 #if LCD_DEPTH < 4
271 GREY_INFO_STRUCT_IRAM
272 static unsigned char greydata[LCD_HEIGHT][LCD_WIDTH];
274 static void make_grey_rect(int width, int height)
276 unsigned char vline[LCD_WIDTH];
277 int x, y;
279 for (x = 0; x < width; x++)
280 vline[x] = (x << 8) / width;
281 for (y = 0; y < height; y++)
282 rb->memcpy(greydata[y], vline, width);
285 static void time_greyscale(void)
287 char str[32]; /* text buffer */
288 long time_start; /* start tickcount */
289 long time_end; /* end tickcount */
290 long time_1, time_2;
291 int frames_1, frames_2;
292 int fps, load;
293 size_t gbuf_size;
294 unsigned char *gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
296 #if NUM_CORES > 1
297 int i;
298 for (i = 0; i < NUM_CORES; i++)
300 rb->snprintf(str, sizeof(str), "Greyscale (%s)",
301 (i > 0) ? "COP" : "CPU");
302 log_text(str);
303 #else
304 const int i = 0;
305 log_text("Greyscale library");
307 #endif
309 if (!grey_init(gbuf, gbuf_size, (i > 0) ? GREY_ON_COP : 0,
310 LCD_WIDTH, LCD_HEIGHT, NULL))
312 log_text("greylib: out of memory.");
313 return;
315 make_grey_rect(LCD_WIDTH, LCD_HEIGHT);
317 /* Test 1 - greyscale overlay not yet enabled */
318 frames_1 = 0;
319 rb->sleep(0); /* sync to tick */
320 time_start = *rb->current_tick;
321 while((time_end = *rb->current_tick) - time_start < DURATION)
323 grey_ub_gray_bitmap(greydata[0], 0, 0, LCD_WIDTH, LCD_HEIGHT);
324 frames_1++;
326 time_1 = time_end - time_start;
328 /* Test 2 - greyscale overlay enabled */
329 grey_show(true);
330 frames_2 = 0;
331 rb->sleep(0); /* sync to tick */
332 time_start = *rb->current_tick;
333 while((time_end = *rb->current_tick) - time_start < DURATION)
335 grey_ub_gray_bitmap(greydata[0], 0, 0, LCD_WIDTH, LCD_HEIGHT);
336 frames_2++;
338 time_2 = time_end - time_start;
340 grey_release();
341 fps = calc_tenth_fps(frames_2, time_2);
342 load = 100 - (100 * frames_2 * time_1) / (frames_1 * time_2);
343 rb->snprintf(str, sizeof(str), "1/1: %d.%d fps", fps / 10, fps % 10);
344 log_text(str);
346 if (load > 0 && load < 100)
348 rb->snprintf(str, sizeof(str), "CPU load: %d%%", load);
349 log_text(str);
351 else
352 log_text("CPU load err (boost?)");
355 #endif
357 /* plugin entry point */
358 enum plugin_status plugin_start(const void* parameter)
360 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
361 char str[32];
362 int cpu_freq;
363 #endif
365 /* standard stuff */
366 (void)parameter;
368 log_init();
369 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
370 cpu_freq = *rb->cpu_frequency; /* remember CPU frequency */
371 #endif
372 backlight_ignore_timeout();
374 time_main_update();
375 rb->sleep(HZ);
376 #if defined(HAVE_LCD_COLOR) && (MEMORYSIZE > 2)
377 time_main_yuv();
378 #endif
379 #if LCD_DEPTH < 4
380 time_greyscale();
381 #endif
382 #ifdef HAVE_REMOTE_LCD
383 time_remote_update();
384 #endif
386 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
387 if (*rb->cpu_frequency != cpu_freq)
388 rb->snprintf(str, sizeof(str), "CPU clock changed!");
389 else
390 rb->snprintf(str, sizeof(str), "CPU: %d MHz",
391 (cpu_freq + 500000) / 1000000);
392 log_text(str);
393 #endif
394 backlight_use_settings();
396 /* wait until user closes plugin */
397 while (rb->button_get(true) != FPS_QUIT);
399 return PLUGIN_OK;