Manual: Fix part 1 of FS#11874 - touchscreen region in the manual isn't 100% correct.
[kugel-rb.git] / apps / plugins / test_fps.c
blob295c172524efb55a94609f3af9c29123c7e8a043
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 defined(BUTTON_OFF)
39 #define FPS_QUIT BUTTON_OFF
40 #else
41 #define FPS_QUIT BUTTON_POWER
42 #endif
44 #define DURATION (2*HZ) /* longer duration gives more precise results */
48 /* Screen logging */
49 static int line;
50 static int max_line;
51 #ifdef HAVE_REMOTE_LCD
52 static int remote_line;
53 static int remote_max_line;
54 #endif
56 static void log_init(void)
58 int h;
60 rb->lcd_getstringsize("A", NULL, &h);
61 max_line = LCD_HEIGHT / h;
62 line = 0;
63 rb->lcd_clear_display();
64 rb->lcd_update();
65 #ifdef HAVE_REMOTE_LCD
66 rb->lcd_remote_getstringsize("A", NULL, &h);
67 remote_max_line = LCD_REMOTE_HEIGHT / h;
68 remote_line = 0;
69 rb->lcd_remote_clear_display();
70 rb->lcd_remote_update();
71 #endif
74 static void log_text(char *text)
76 rb->lcd_puts(0, line, text);
77 if (++line >= max_line)
78 line = 0;
79 rb->lcd_update();
80 #ifdef HAVE_REMOTE_LCD
81 rb->lcd_remote_puts(0, remote_line, text);
82 if (++remote_line >= remote_max_line)
83 remote_line = 0;
84 rb->lcd_remote_update();
85 #endif
88 static int calc_tenth_fps(int framecount, long ticks)
90 return (10*HZ) * framecount / ticks;
93 static void time_main_update(void)
95 char str[32]; /* text buffer */
96 long time_start; /* start tickcount */
97 long time_end; /* end tickcount */
98 int frame_count;
99 int fps;
101 const int part14_x = LCD_WIDTH/4; /* x-offset for 1/4 update test */
102 const int part14_w = LCD_WIDTH/2; /* x-size for 1/4 update test */
103 const int part14_y = LCD_HEIGHT/4; /* y-offset for 1/4 update test */
104 const int part14_h = LCD_HEIGHT/2; /* y-size for 1/4 update test */
106 log_text("Main LCD Update");
108 /* Test 1: full LCD update */
109 frame_count = 0;
110 rb->sleep(0); /* sync to tick */
111 time_start = *rb->current_tick;
112 while((time_end = *rb->current_tick) - time_start < DURATION)
114 rb->lcd_update();
115 frame_count++;
117 fps = calc_tenth_fps(frame_count, time_end - time_start);
118 rb->snprintf(str, sizeof(str), "1/1: %d.%d fps", fps / 10, fps % 10);
119 log_text(str);
121 /* Test 2: quarter LCD update */
122 frame_count = 0;
123 rb->sleep(0); /* sync to tick */
124 time_start = *rb->current_tick;
125 while((time_end = *rb->current_tick) - time_start < DURATION)
127 rb->lcd_update_rect(part14_x, part14_y, part14_w, part14_h);
128 frame_count++;
130 fps = calc_tenth_fps(frame_count, time_end - time_start);
131 rb->snprintf(str, sizeof(str), "1/4: %d.%d fps", fps / 10, fps % 10);
132 log_text(str);
135 #if defined(HAVE_LCD_COLOR) && (MEMORYSIZE > 2)
137 #if LCD_WIDTH >= LCD_HEIGHT
138 #define YUV_WIDTH LCD_WIDTH
139 #define YUV_HEIGHT LCD_HEIGHT
140 #else /* Assume the screen is rotated on portrait LCDs */
141 #define YUV_WIDTH LCD_HEIGHT
142 #define YUV_HEIGHT LCD_WIDTH
143 #endif
145 static unsigned char ydata[YUV_HEIGHT][YUV_WIDTH];
146 static unsigned char udata[YUV_HEIGHT/2][YUV_WIDTH/2];
147 static unsigned char vdata[YUV_HEIGHT/2][YUV_WIDTH/2];
149 static unsigned char * const yuvbuf[3] = {
150 (void*)ydata,
151 (void*)udata,
152 (void*)vdata
155 static void make_gradient_rect(int width, int height)
157 unsigned char vline[YUV_WIDTH/2];
158 int x, y;
160 width /= 2;
161 height /= 2;
163 for (x = 0; x < width; x++)
164 vline[x] = (x << 8) / width;
165 for (y = 0; y < height; y++)
167 rb->memset(udata[y], (y << 8) / height, width);
168 rb->memcpy(vdata[y], vline, width);
172 static void time_main_yuv(void)
174 char str[32]; /* text buffer */
175 long time_start; /* start tickcount */
176 long time_end; /* end tickcount */
177 int frame_count;
178 int fps;
180 const int part14_x = YUV_WIDTH/4; /* x-offset for 1/4 update test */
181 const int part14_w = YUV_WIDTH/2; /* x-size for 1/4 update test */
182 const int part14_y = YUV_HEIGHT/4; /* y-offset for 1/4 update test */
183 const int part14_h = YUV_HEIGHT/2; /* y-size for 1/4 update test */
185 log_text("Main LCD YUV");
187 rb->memset(ydata, 128, sizeof(ydata)); /* medium grey */
189 /* Test 1: full LCD update */
190 make_gradient_rect(YUV_WIDTH, YUV_HEIGHT);
192 frame_count = 0;
193 rb->sleep(0); /* sync to tick */
194 time_start = *rb->current_tick;
195 while((time_end = *rb->current_tick) - time_start < DURATION)
197 rb->lcd_blit_yuv(yuvbuf, 0, 0, YUV_WIDTH,
198 0, 0, YUV_WIDTH, YUV_HEIGHT);
199 frame_count++;
201 fps = calc_tenth_fps(frame_count, time_end - time_start);
202 rb->snprintf(str, sizeof(str), "1/1: %d.%d fps", fps / 10, fps % 10);
203 log_text(str);
205 /* Test 2: quarter LCD update */
206 make_gradient_rect(YUV_WIDTH/2, YUV_HEIGHT/2);
208 frame_count = 0;
209 rb->sleep(0); /* sync to tick */
210 time_start = *rb->current_tick;
211 while((time_end = *rb->current_tick) - time_start < DURATION)
213 rb->lcd_blit_yuv(yuvbuf, 0, 0, YUV_WIDTH,
214 part14_x, part14_y, part14_w, part14_h);
215 frame_count++;
217 fps = calc_tenth_fps(frame_count, time_end - time_start);
218 rb->snprintf(str, sizeof(str), "1/4: %d.%d fps", fps / 10, fps % 10);
219 log_text(str);
221 #endif
223 #ifdef HAVE_REMOTE_LCD
224 static void time_remote_update(void)
226 char str[32]; /* text buffer */
227 long time_start; /* start tickcount */
228 long time_end; /* end tickcount */
229 int frame_count;
230 int fps;
232 const int part14_x = LCD_REMOTE_WIDTH/4; /* x-offset for 1/4 update test */
233 const int part14_w = LCD_REMOTE_WIDTH/2; /* x-size for 1/4 update test */
234 const int part14_y = LCD_REMOTE_HEIGHT/4; /* y-offset for 1/4 update test */
235 const int part14_h = LCD_REMOTE_HEIGHT/2; /* y-size for 1/4 update test */
237 log_text("Remote LCD Update");
239 /* Test 1: full LCD update */
240 frame_count = 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 rb->lcd_remote_update();
246 frame_count++;
248 fps = calc_tenth_fps(frame_count, time_end - time_start);
249 rb->snprintf(str, sizeof(str), "1/1: %d.%d fps", fps / 10, fps % 10);
250 log_text(str);
252 /* Test 2: quarter LCD update */
253 frame_count = 0;
254 rb->sleep(0); /* sync to tick */
255 time_start = *rb->current_tick;
256 while((time_end = *rb->current_tick) - time_start < DURATION)
258 rb->lcd_remote_update_rect(part14_x, part14_y, part14_w, part14_h);
259 frame_count++;
261 fps = calc_tenth_fps(frame_count, time_end - time_start);
262 rb->snprintf(str, sizeof(str), "1/4: %d.%d fps", fps / 10, fps % 10);
263 log_text(str);
265 #endif
267 #if LCD_DEPTH < 4
269 GREY_INFO_STRUCT_IRAM
270 static unsigned char greydata[LCD_HEIGHT][LCD_WIDTH];
272 static void make_grey_rect(int width, int height)
274 unsigned char vline[LCD_WIDTH];
275 int x, y;
277 for (x = 0; x < width; x++)
278 vline[x] = (x << 8) / width;
279 for (y = 0; y < height; y++)
280 rb->memcpy(greydata[y], vline, width);
283 static void time_greyscale(void)
285 char str[32]; /* text buffer */
286 long time_start; /* start tickcount */
287 long time_end; /* end tickcount */
288 long time_1, time_2;
289 int frames_1, frames_2;
290 int fps, load;
291 size_t gbuf_size;
292 unsigned char *gbuf = (unsigned char *) rb->plugin_get_buffer(&gbuf_size);
294 #if NUM_CORES > 1
295 int i;
296 for (i = 0; i < NUM_CORES; i++)
298 rb->snprintf(str, sizeof(str), "Greyscale (%s)",
299 (i > 0) ? "COP" : "CPU");
300 log_text(str);
301 #else
302 const int i = 0;
303 log_text("Greyscale library");
305 #endif
307 if (!grey_init(gbuf, gbuf_size, (i > 0) ? GREY_ON_COP : 0,
308 LCD_WIDTH, LCD_HEIGHT, NULL))
310 log_text("greylib: out of memory.");
311 return;
313 make_grey_rect(LCD_WIDTH, LCD_HEIGHT);
315 /* Test 1 - greyscale overlay not yet enabled */
316 frames_1 = 0;
317 rb->sleep(0); /* sync to tick */
318 time_start = *rb->current_tick;
319 while((time_end = *rb->current_tick) - time_start < DURATION)
321 grey_ub_gray_bitmap(greydata[0], 0, 0, LCD_WIDTH, LCD_HEIGHT);
322 frames_1++;
324 time_1 = time_end - time_start;
326 /* Test 2 - greyscale overlay enabled */
327 grey_show(true);
328 frames_2 = 0;
329 rb->sleep(0); /* sync to tick */
330 time_start = *rb->current_tick;
331 while((time_end = *rb->current_tick) - time_start < DURATION)
333 grey_ub_gray_bitmap(greydata[0], 0, 0, LCD_WIDTH, LCD_HEIGHT);
334 frames_2++;
336 time_2 = time_end - time_start;
338 grey_release();
339 fps = calc_tenth_fps(frames_2, time_2);
340 load = 100 - (100 * frames_2 * time_1) / (frames_1 * time_2);
341 rb->snprintf(str, sizeof(str), "1/1: %d.%d fps", fps / 10, fps % 10);
342 log_text(str);
344 if (load > 0 && load < 100)
346 rb->snprintf(str, sizeof(str), "CPU load: %d%%", load);
347 log_text(str);
349 else
350 log_text("CPU load err (boost?)");
353 #endif
355 /* plugin entry point */
356 enum plugin_status plugin_start(const void* parameter)
358 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
359 char str[32];
360 int cpu_freq;
361 #endif
363 /* standard stuff */
364 (void)parameter;
366 log_init();
367 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
368 cpu_freq = *rb->cpu_frequency; /* remember CPU frequency */
369 #endif
370 backlight_force_on(); /* backlight control in lib/helper.c */
372 time_main_update();
373 rb->sleep(HZ);
374 #if defined(HAVE_LCD_COLOR) && (MEMORYSIZE > 2)
375 time_main_yuv();
376 #endif
377 #if LCD_DEPTH < 4
378 time_greyscale();
379 #endif
380 #ifdef HAVE_REMOTE_LCD
381 time_remote_update();
382 #endif
384 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
385 if (*rb->cpu_frequency != cpu_freq)
386 rb->snprintf(str, sizeof(str), "CPU clock changed!");
387 else
388 rb->snprintf(str, sizeof(str), "CPU: %d MHz",
389 (cpu_freq + 500000) / 1000000);
390 log_text(str);
391 #endif
392 backlight_use_settings(); /* backlight control in lib/helper.c */
394 /* wait until user closes plugin */
395 while (rb->button_get(true) != FPS_QUIT);
397 return PLUGIN_OK;