1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
44
49
50
51
52
59
60
61
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
115
116
117
118
119
120
121
122
123
124
129
130
131
132
133
134
135
136
137
138
139
140
141
148
149
150
151
154
155
156
157
158
159
160
161
162
163
164
165
166
169
172
175
178
179
180
181
182
183
184
185
186
191
217
218
219
224
236
237
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
325
326
327
328
331
332
333
334
341
345
346
349
350
/* ... */
#include "DIALOG.h"
#include "k_module.h"
#include "benchmark_res.c"
#include "cpu_utils.h"
#include "k_rtc.h"
#include "k_modules_res.h"
6 includes
/* ... */
/* ... */
Includes
#define ID_FRAMEWIN_INFO (GUI_ID_USER + 0x01)
#define ID_FRAMEWIN_CPU (GUI_ID_USER + 0x03)
#define ID_CPU_GRAPH (GUI_ID_USER + 0x04)
#define ID_TEXT_CPU (GUI_ID_USER + 0x05)
#define ID_BENCH_CPU (GUI_ID_USER + 0x06)
#define ID_BUTTON_BKGND (GUI_ID_USER + 0x01)
6 definesPrivate defines
static void Startup(WM_HWIN hWin, uint16_t xpos, uint16_t ypos);
static int Run_SpeedTest(void);
extern void RestoreDefaultFillProcess(void);
Private function prototypes
K_ModuleItem_Typedef cpu_bench =
{
1,
"Benchmark",
&bmcpu,
Startup,
NULL,
...};
static const GUI_WIDGET_CREATE_INFO _aDialog[] =
{
{ FRAMEWIN_CreateIndirect, "Benchmark", ID_FRAMEWIN_INFO, 0, 0, 320, 215, 0, 0x64, 0 },
{ TEXT_CreateIndirect, " 00000000 Pixels/s ", ID_BENCH_CPU, 85, 125, 300, 25, 0, 0, 0 },
{ BUTTON_CreateIndirect, "Start Speed Benchmark", ID_BENCH_CPU, 70, 150, 160, 34, 0, 0, 0 },
...};
static const GUI_COLOR _aColor[8] = {
0x000000,
0x0000FF,
0x00FF00,
0x00FFFF,
0xFF0000,
0xFF00FF,
0xFFFF00,
0xFFFFFF
...};
GRAPH_DATA_Handle hData;
GRAPH_SCALE_Handle hScale;
uint32_t Stop_Test = 0;
Private variables
/* ... */
static U32 _GetPixelsPerSecond(void) {
GUI_COLOR Color, BkColor;
U32 x0, y0, x1, y1, xSize, ySize;
I32 t, t0;
U32 Cnt, PixelsPerSecond, PixelCnt;
xSize = LCD_GetXSize();
ySize = LCD_GetYSize();
Cnt = 0;
x0 = 0;
x1 = xSize - 1;
y0 = 65;
y1 = ySize - 60 - 1;
Color = GUI_GetColor();
BkColor = GUI_GetBkColor();
GUI_SetColor(BkColor);
t0 = GUI_GetTime();
do {
GUI_FillRect(x0, y0, x1, y1);
GUI_Exec();
Cnt++;
t = GUI_GetTime();
...} while ((t - (t0 + 100)) <= 0);
t -= t0;
PixelCnt = (x1 - x0 + 1) * (y1 - y0 + 1) * Cnt;
PixelsPerSecond = PixelCnt / t * 1000;
GUI_SetColor(Color);
return PixelsPerSecond;
}{ ... }
/* ... */
static int Run_SpeedTest(void) {
int TimeStart, i;
U32 PixelsPerSecond;
unsigned aColorIndex[8];
int xSize, ySize, vySize;
GUI_RECT Rect, ClipRect;
xSize = LCD_GetXSize();
ySize = LCD_GetYSize();
vySize = LCD_GetVYSize();
#if GUI_SUPPORT_CURSOR
GUI_CURSOR_Hide();
#endif
if (vySize > ySize) {
ClipRect.x0 = 0;
ClipRect.y0 = 0;
ClipRect.x1 = xSize;
ClipRect.y1 = ySize;
GUI_SetClipRect(&ClipRect);
}if (vySize > ySize) { ... }
Stop_Test = 0;
for (i = 0; i< 8; i++) {
aColorIndex[i] = GUI_Color2Index(_aColor[i]);
}for (i = 0; i< 8; i++) { ... }
TimeStart = GUI_GetTime();
for (i = 0; ((GUI_GetTime() - TimeStart) < 5000) &&( Stop_Test == 0); i++) {
GUI_SetColorIndex(aColorIndex[i&7]);
Rect.x0 = rand() % xSize - xSize / 2;
Rect.y0 = rand() % ySize - ySize / 2;
Rect.x1 = Rect.x0 + 20 + rand() % xSize;
Rect.y1 = Rect.y0 + 20 + rand() % ySize;
GUI_FillRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1);
if (Rect.x1 >= xSize) {
Rect.x1 = xSize - 1;
}if (Rect.x1 >= xSize) { ... }
if (Rect.y1 >= ySize) {
Rect.y1 = ySize - 1;
}if (Rect.y1 >= ySize) { ... }
if (Rect.x0 < 0 ) {
Rect.x0 = 0;
}if (Rect.x0 < 0) { ... }
if (Rect.y1 < 0) {
Rect.y1 = 0;
}if (Rect.y1 < 0) { ... }
GUI_Exec();
}for (i = 0; ((GUI_GetTime() - TimeStart) < 5000) &&( Stop_Test == 0); i++) { ... }
PixelsPerSecond = _GetPixelsPerSecond();
GUI_SetClipRect(NULL);
return PixelsPerSecond;
}{ ... }
/* ... */
static void _cbCpuWindow(WM_MESSAGE * pMsg) {
static WM_HTIMER hTimerTime;
switch (pMsg->MsgId)
{
case WM_CREATE:
hTimerTime = WM_CreateTimer(pMsg->hWin, 0, 400, 0);
break;
case WM_CREATE:
case WM_TIMER:
GRAPH_DATA_YT_AddValue(hData , osGetCPUUsage());
WM_InvalidateWindow(pMsg->hWin);
WM_RestartTimer(pMsg->Data.v, 400);
break;
case WM_TIMER:
case WM_DELETE:
WM_DeleteTimer(hTimerTime);
break;
case WM_DELETE:
default:
WM_DefaultProc(pMsg);default
}switch (pMsg->MsgId) { ... }
}{ ... }
/* ... */
static void _ClearDesktop(WM_MESSAGE * pMsg) {
switch (pMsg->MsgId)
{
case WM_PAINT:
GUI_SetBkColor(GUI_BLACK);
GUI_Clear();
break;case WM_PAINT:
default:
WM_DefaultProc(pMsg);default
}switch (pMsg->MsgId) { ... }
}{ ... }
/* ... */
extern ICONVIEW_Handle hIcon;
static void _cbDialog(WM_MESSAGE * pMsg) {
WM_HWIN hItem;
int Id, NCode;
WM_HWIN hGraph;
int cpu_speed = 0;
char temp[50];
WM_CALLBACK *_cb;
switch (pMsg->MsgId) {
case WM_INIT_DIALOG:
hItem = pMsg->hWin;
FRAMEWIN_SetFont(hItem, GUI_FONT_13HB_ASCII);
FRAMEWIN_AddCloseButton(hItem, FRAMEWIN_BUTTON_RIGHT, 0);
hItem = TEXT_CreateEx(10, 30, 100, 25, pMsg->hWin, WM_CF_SHOW,0, 0x123,"");
TEXT_SetFont(hItem, GUI_FONT_13B_1);
TEXT_SetTextColor(hItem, 0x00804000);
TEXT_SetText(hItem, "CPU Usage %:");
hItem = WM_GetDialogItem(pMsg->hWin, ID_BENCH_CPU);
TEXT_SetFont(hItem, GUI_FONT_16B_ASCII);
TEXT_SetTextColor(hItem, GUI_DARKRED);
hItem = WM_GetDialogItem(pMsg->hWin, ID_CPU_GRAPH);
FRAMEWIN_SetBarColor(hItem, 0, GUI_DARKGRAY);
FRAMEWIN_SetBarColor(hItem, 1, GUI_DARKGRAY);
hGraph = GRAPH_CreateEx(10, 45, 300, 95, pMsg->hWin, WM_CF_SHOW, 0, GUI_ID_GRAPH0);
hData = GRAPH_DATA_YT_Create(GUI_LIGHTGREEN, 500, 0, 20);
GRAPH_SetGridVis(hGraph, 1);
GRAPH_SetBorder(hGraph, 20, 4, 5, 4);
GRAPH_AttachData(hGraph, hData);
hScale = GRAPH_SCALE_Create(20, GUI_TA_RIGHT, GRAPH_SCALE_CF_VERTICAL, 25);
GRAPH_AttachScale(hGraph, hScale);
GRAPH_SCALE_SetTextColor(hScale, GUI_YELLOW);
GRAPH_SetGridDistX(hGraph, 25);
GRAPH_SetGridDistY(hGraph, 25);
WM_CreateWindowAsChild(80, 45, 354, 23, pMsg->hWin, WM_CF_SHOW | WM_CF_HASTRANS, _cbCpuWindow , 0);
break;
case WM_INIT_DIALOG:
case WM_NOTIFY_PARENT:
Id = WM_GetId(pMsg->hWinSrc);
NCode = pMsg->Data.v;
switch (NCode) {
case WM_NOTIFICATION_RELEASED:
switch (Id) {
case ID_BENCH_CPU:
Stop_Test = 0;
WM_HideWindow(hIcon);
WM_HideWindow(pMsg->hWin);
WM_Exec();
_cb = WM_GetCallback(WM_HBKWIN);
WM_SetCallback(WM_HBKWIN, _ClearDesktop);
cpu_speed = Run_SpeedTest();
WM_ShowWindow(hIcon);
WM_ShowWindow(pMsg->hWin);
hItem = WM_GetDialogItem(pMsg->hWin, ID_BENCH_CPU);
sprintf (temp, "%d Pixels/s ", cpu_speed);
TEXT_SetText(hItem, temp);
WM_SetCallback(WM_HBKWIN, _cb);
hItem = WM_GetDialogItem(WM_HBKWIN, ID_BUTTON_BKGND);
WM_InvalidateWindow(hItem);
WM_InvalidateWindow(WM_HBKWIN);
WM_Paint(WM_HBKWIN);
break;case ID_BENCH_CPU:
}switch (Id) { ... }
break;
case WM_NOTIFICATION_RELEASED:
case WM_NOTIFICATION_CHILD_DELETED:
Stop_Test = 1;
break; case WM_NOTIFICATION_CHILD_DELETED:
}switch (NCode) { ... }
break;
case WM_NOTIFY_PARENT:
default:
WM_DefaultProc(pMsg);
break;default
}switch (pMsg->MsgId) { ... }
}{ ... }
/* ... */
static void Startup(WM_HWIN hWin, uint16_t xpos, uint16_t ypos)
{
GUI_CreateDialogBox(_aDialog, GUI_COUNTOF(_aDialog), _cbDialog, hWin, xpos, ypos);
}{ ... }
/* ... */
/* ... */