lin
2025-04-14 e0c033f30287744d392a8d700693b1c0b78afc7c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
/*
 * Allwinner SoCs bootGUI.
 *
 * Copyright (C) 2017 Allwinner.
 *
 * This file is licensed under the terms of the GNU General Public
 * License version 2.  This program is licensed "as is" without any
 * warranty of any kind, whether express or implied.
 */
 
#include <common.h>
#include <command.h>
#include <boot_gui.h>
 
#define THIS_USAGE "accept 2 args:\n" \
   "boot_gui_test 1 : get fb informations.\n" \
   "boot_gui_test 2 : fb_lock and fb_unlock, draw fb0 directly.\n" \
   "boot_gui_test 3 : test boot gui with double buffers.\n" \
   "boot_gui_test 4 : draw geometry by canvas on fb0.\n" \
   "boot_gui_test 5 : draw chars by canvas on fb0.\n" \
   "boot_gui_test 6 : show fb0 on two different devices.\n" \
   "boot_gui_test 7 : show fb0 on device_0, fb1 on device_1.\n"
 
static int print_fb_info(int fb_id)
{
   struct canvas *cv = fb_lock(fb_id);
   if (NULL == cv)
       return -1;
   printf("fb%d: width=%d, height=%d, bits_per_pixel=%d, line_stride=%d\n",
       fb_id, cv->width, cv->height, cv->bpp, cv->stride);
   fb_unlock(fb_id, NULL, 0);
   return 0;
}
 
static int print_all_fb_info(void)
{
   unsigned int fb_id;
 
   for (fb_id = FB_ID_0; fb_id < FB_ID_NUM; ++fb_id) {
       print_fb_info(fb_id);
   }
   return 0;
}
 
static int my_fill_rect(char *data, unsigned int bpp, unsigned int stride,
   unsigned int width, unsigned height, unsigned int color)
{
   char *data_end = data + stride * height;
 
   if (32 == bpp) {
       for (; data < data_end; data += stride) {
           int *p = (int *)data;
           int *p_end = p + width;
           for (; p < p_end;)
               *p++ = (int)color;
       }
   } else if (24 == bpp) {
       for (; data < data_end; data += stride) {
           char *p = data;
           char *p_end = p + width * 3;
           for (; p < p_end;) {
               *p++ = color & 0xFF;
               *p++ = (color >> 8) & 0xFF;
               *p++ = (color >> 16) & 0xFF;
           }
       }
   }
   return 0;
}
 
static int test_draw_fb_direct(void)
{
   unsigned int loop_cnt = 0;
   unsigned int clist[] = {
       0xFFFF0000,
       0xFF00FF00,
       0xFF0000FF,
       0xFFFFFF00,
       0xFF00FFFF,
       0xFFFF00FF,
   };
 
   printf("%s begin\n", __func__);
   loop_cnt = 10;
   while (loop_cnt--) {
       char *pdata;
       unsigned int color;
       rect_t dirty_rect;
       struct canvas *cv = fb_lock(FB_ID_0);
       if (NULL == cv) {
           printf("%s: fb lock failed\n", __func__);
           return -1;
       }
 
       color = clist[loop_cnt % (sizeof(clist) / sizeof(clist[0]))];
       dirty_rect.left = cv->width >> 2;
       dirty_rect.top = cv->height >> 2;
       dirty_rect.right = cv->width - dirty_rect.left;
       dirty_rect.bottom = cv->height - dirty_rect.top;
       pdata = (char *)cv->base + (cv->stride * dirty_rect.top)
           + (cv->bpp * dirty_rect.left >> 3);
       my_fill_rect(pdata, cv->bpp, cv->stride, dirty_rect.right - dirty_rect.left,
           dirty_rect.bottom - dirty_rect.top, color);
       /* fb_unlock(FB_ID_0, &dirty_rect, 1); */ /* refresh dirty_rect of screen */
       fb_unlock(FB_ID_0, NULL, 1); /* refresh whole screen */
       __msdelay(300);
   }
   return 0;
}
 
static int test_draw_fb_with_double_buf(void)
{
#ifdef CONFIG_BOOT_GUI_DOUBLE_BUF
   printf("%s begin\n", __func__);
   unsigned int loop_cnt = 0;
   unsigned int clist[] = {
       0xFFFF0000,
       0xFF00FF00,
       0xFF0000FF,
       0xFFFFFF00,
       0xFF00FFFF,
       0xFFFF00FF,
       0xFFFFFFFF,
   };
   rect_t dirty_rects[4];
   struct canvas *cv = fb_lock(FB_ID_0);
   if (NULL == cv) {
       printf("%s: fb lock failed\n", __func__);
       return -1;
   }
   dirty_rects[0].left = cv->width >> 2;
   dirty_rects[0].right = cv->width >> 1;
   dirty_rects[0].top = cv->height >> 2;
   dirty_rects[0].bottom = cv->height >> 1;
   dirty_rects[1].left = cv->width >> 1;
   dirty_rects[1].right = cv->width - (cv->width >> 2);
   dirty_rects[1].top = cv->height >> 2;
   dirty_rects[1].bottom = cv->height >> 1;
   dirty_rects[2].left = cv->width >> 1;
   dirty_rects[2].right = cv->width - (cv->width >> 2);
   dirty_rects[2].top = cv->height >> 1;
   dirty_rects[2].bottom = cv->height - (cv->height >> 2);
   dirty_rects[3].left = cv->width >> 2;
   dirty_rects[3].right = cv->width >> 1;
   dirty_rects[3].top = cv->height >> 1;
   dirty_rects[3].bottom = cv->height - (cv->height >> 2);
   fb_unlock(FB_ID_0, NULL, 0);
 
   loop_cnt = 50;
   while (loop_cnt--) {
       char *pdata;
       unsigned int color;
       rect_t *p_rect;
       struct canvas *cv = fb_lock(FB_ID_0);
       if (NULL == cv) {
           printf("%s: fb lock failed\n", __func__);
           return -1;
       }
 
       color = clist[loop_cnt % (sizeof(clist) / sizeof(clist[0]))];
       p_rect = &dirty_rects[loop_cnt % (sizeof(dirty_rects) / sizeof(dirty_rects[0]))];
       pdata = (char *)cv->base + (cv->stride * p_rect->top)
           + (cv->bpp * p_rect->left >> 3);
       my_fill_rect(pdata, cv->bpp, cv->stride, p_rect->right - p_rect->left,
           p_rect->bottom - p_rect->top, color);
       fb_unlock(FB_ID_0, p_rect, 1);
       __msdelay(300);
   }
   return 0;
#else
   printf("please to define CONFIG_BOOT_GUI_DOUBLE_BUF\n");
   return -1;
#endif
}
 
static int test_draw_geometry(void)
{
#ifdef CONFIG_SUPORT_DRAW_GEOMETRY
   printf("%s begin, wait for finish\n", __func__);
   int loop_cnt = 0;
   struct canvas *cv = NULL;
   int width = 0;
   int height = 0;
   unsigned int color = 0xFF000000;
   unsigned int bg_color = 0xFF000000;
   argb_t *p_color = (argb_t *)&color;
   argb_t *p_bg_color = (argb_t *)&bg_color;
 
   rect_t bound;
   rect_t in_rect;
   point_t from;
   point_t to;
 
   unsigned int clist[] = {
       0xFFFF0000,
       0xFF00FF00,
       0xFF0000FF,
       0xFFFFFF00,
       0xFF00FFFF,
       0xFFFF00FF,
   };
 
   cv = fb_lock(FB_ID_0);
   if (NULL == cv)
       return -1;
   width = cv->width;
   height = cv->height;
   fb_unlock(FB_ID_0, NULL, 0); /* not refresh the screen */
 
   bound.left = 0;
   bound.top = 0;
   bound.right = width;
   bound.bottom = height;
 
   in_rect.left = width >> 2;
   in_rect.top = height >> 2;
   in_rect.right = width - in_rect.left;
   in_rect.bottom = height - in_rect.top;
 
   loop_cnt = 100;
   while (0 < loop_cnt) {
       --loop_cnt;
       cv = fb_lock(FB_ID_0);
       if (NULL == cv)
           return -1;
 
       bg_color += 0x080808;
       if (0xFF888888 < bg_color)
           bg_color = 0xFF000000;
       cv->fill_rect(cv, p_bg_color, &bound); /* fill background color */
 
       color = clist[loop_cnt % (sizeof(clist) / sizeof(clist[0]))];
       cv->draw_rect(cv, p_color, &bound); /* draw the bound of screen */
       cv->fill_rect(cv, p_color, &in_rect); /* fill the inner rect */
 
       from.x = 0;
       from.y = 0;
       to.x = width - 1;
       to.y = height - 1;
       cv->draw_line(cv, p_color, &from, &to); /* draw a corner line */
       from.x = 0;
       from.y = height - 1;
       to.x = width - 1;
       to.y = 0;
       cv->draw_line(cv, p_color, &from, &to); /* draw another corner line */
 
       fb_unlock(FB_ID_0, NULL, 1); /* refresh screen */
 
       __msdelay(500);
   }
   return 0;
#else
   printf("please to define CONFIG_SUPORT_DRAW_GEOMETRY\n");
   return -1;
#endif
}
 
static int test_draw_chars(void)
{
#ifdef CONFIG_SURPORT_DRAW_CHARS
   unsigned int loop_cnt = 0;
 
   struct canvas *cv = NULL;
   int width = 0;
   int height = 0;
 
   point_t char_p;
   unsigned int color = 0xFF000000;
   unsigned int clist[] = {
       0xFFFF0000,
       0xFF00FF00,
       0xFF0000FF,
       0xFFFFFF00,
       0xFF00FFFF,
       0xFFFF00FF,
   };
   char *str = "HELLO BOOTGUI !";
 
   printf("%s begin\n", __func__);
   cv = fb_lock(FB_ID_0);
   if (NULL == cv)
       return -1;
   width = cv->width;
   height = cv->height;
   fb_unlock(FB_ID_0, NULL, 0);
 
   char_p.x = width >> 2;
   char_p.y = height >> 2;
 
   loop_cnt = 20;
   while (loop_cnt) {
       loop_cnt--;
 
       cv = fb_lock(FB_ID_0);
       if (NULL == cv)
           return -1;
       memset((void *)cv->base, 0, cv->stride * cv->height);
       color = clist[loop_cnt % (sizeof(clist) / sizeof(clist[0]))];
       cv->draw_chars(cv, (argb_t *)&color, &char_p, str, strlen(str));
 
       fb_unlock(FB_ID_0, NULL, 1);
       __msdelay(500);
   }
 
   do {
       for (char_p.y = 0; char_p.y < height; char_p.y += 4) {
           for (char_p.x = 0; char_p.x < width; char_p.x += 4) {
               cv = fb_lock(FB_ID_0);
               if (NULL == cv)
                   return -1;
               memset((void *)cv->base, 0, cv->stride * cv->height);
               cv->draw_chars(cv, (argb_t *)&color, &char_p, str, strlen(str));
               fb_unlock(FB_ID_0, NULL, 1);
               __msdelay(200);
           }
       }
   } while (0);
   return 0;
#else
   printf("please to define CONFIG_SURPORT_DRAW_CHARS\n");
   return -1;
#endif
}
 
static int test_open_other_device(void)
{
   extern int disp_device_open_ex(int dev_id, int fb_id, int flag);
 
   if (disp_device_open_ex(1, FB_ID_0, 0)) {
       printf("disp_device_open_ex failed\n");
       return -1;
   }
   return 0;
}
 
static int test_show_2_fb_on_different_devices(void)
{
   extern int disp_device_open_ex(int dev_id, int fb_id, int flag);
 
   unsigned int fb_id;
   struct canvas *cv = NULL;
 
   if (disp_device_open_ex(1, FB_ID_1, 0)) {
       printf("disp_device_open_ex for fb1 failed\n");
       return -1;
   }
 
   for (fb_id = FB_ID_0; fb_id < FB_ID_2; ++fb_id) {
       int color;
       point_t p;
       char *str;
       cv = fb_lock(fb_id);
       if (NULL == cv) {
           printf("fb%d is invalid\n", fb_id);
           return -1;
       }
       if (FB_ID_0 == fb_id) {
           color = 0xFFFFFF00;
           p.x = cv->width >> 2;
           p.y = cv->height >> 2;
           str = "THIS IS BOOT_FB0";
       } else if (FB_ID_1 == fb_id) {
           color = 0xFF00FFFF;
           p.x = cv->width >> 1;
           p.y = cv->height >> 1;
           str = "THIS IS BOOT_FB1";
       }
       cv->draw_chars(cv, (argb_t *)&color, &p, str, strlen(str));
       fb_unlock(fb_id, NULL, 1);
   }
 
   return 0;
}
 
static int boot_gui_test(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
{
   int cmd;
   if (2 > argc) {
       return -1;
   }
   /* printf("%s begin. argc=%d, cmd=%s\n", __func__, argc, argv[1]); */
   cmd = simple_strtoul(argv[1], NULL, 10);
   switch (cmd) {
   case 1:
       print_all_fb_info();
       break;
   case 2:
       test_draw_fb_direct();
       break;
   case 3:
       test_draw_fb_with_double_buf();
       break;
   case 4:
       test_draw_geometry();
       break;
   case 5:
       test_draw_chars();
       break;
   case 6:
       test_open_other_device();
       break;
   case 7:
       test_show_2_fb_on_different_devices();
       break;
   default:
       printf("%s: no support this cmd(%s)\n", __func__, argv[1]);
       return -1;
   }
   return 0;
}
 
U_BOOT_CMD(
   boot_gui_test, 2, 0, boot_gui_test,
   "boot gui test", THIS_USAGE
);