forked from lc-soft/LCUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_render.c
166 lines (149 loc) · 4.19 KB
/
test_render.c
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
#include <LCUI_Build.h>
#include <LCUI/LCUI.h>
#include <LCUI/gui/widget.h>
#include <LCUI/gui/widget/textview.h>
#include <LCUI/display.h>
#include <LCUI/timer.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#define SCREEN_WIDTH 1600
#define SCREEN_HEIGHT 900
#define BLOCK_COUNT 60
static struct TestStatus {
size_t color_index;
unsigned int fps;
LCUI_Widget box;
} self;
void UpdateWidgetStyle(LCUI_Widget w, void *arg)
{
size_t index;
LCUI_Color color;
index = w->index % BLOCK_COUNT + w->index / BLOCK_COUNT;
index = ((index + self.color_index) * 256 / BLOCK_COUNT) % 512;
color.red = 255;
color.green = (unsigned char)(index > 255 ? 511 - index : index);
color.blue = 0;
color.alpha = 255;
Widget_SetStyle(w, key_background_color, color, color);
Widget_UpdateStyle(w, FALSE);
}
void UpdateFrame(void *arg)
{
Widget_Each(arg, UpdateWidgetStyle, NULL);
}
void UpdateRenderStatus(void *arg)
{
char str[32];
sprintf(str, "[size=24px]FPS: %d[/size]", self.fps);
TextView_SetText(arg, str);
self.fps = 0;
}
void InitModal(void)
{
LCUI_Widget dimmer;
LCUI_Widget dialog;
dimmer = LCUIWidget_New(NULL);
dialog = LCUIWidget_New(NULL);
Widget_Resize(dialog, 400, 400);
Widget_SetStyleString(dialog, "margin", "100px auto");
Widget_SetStyleString(dialog, "border-radius", "6px");
Widget_SetStyleString(dialog, "opacity", "0.9");
Widget_SetBoxShadow(dialog, 0, 4, 8, ARGB(100, 0, 0, 0));
Widget_SetStyleString(dialog, "background-color", "#fff");
Widget_SetStyle(dimmer, key_top, 0, px);
Widget_SetStyle(dimmer, key_left, 0, px);
Widget_SetStyle(dimmer, key_width, 1.0f, scale);
Widget_SetStyle(dimmer, key_height, 1.0f, scale);
Widget_SetStyle(dimmer, key_position, SV_ABSOLUTE, style);
Widget_SetStyleString(dimmer, "background-color", "rgba(0,0,0,0.5)");
Widget_Append(dimmer, dialog);
Widget_Append(LCUIWidget_GetRoot(), dimmer);
}
void InitBackground(void)
{
size_t i;
size_t c;
size_t n = BLOCK_COUNT;
LCUI_Widget w;
LCUI_Widget root;
LCUI_Color color;
LCUI_WidgetRulesRec rules = { 0 };
const float width = SCREEN_WIDTH * 1.0f / n;
const float height = SCREEN_HEIGHT * 1.0f / n;
color.red = 255;
color.green = 0;
color.blue = 0;
color.alpha = 255;
root = LCUIWidget_GetRoot();
self.box = LCUIWidget_New(NULL);
for (i = 0; i < n * n; ++i) {
if (i % n == 0) {
++self.color_index;
}
w = LCUIWidget_New(NULL);
c = ((i % n + i / n) * 256 / n) % 512;
color.green = (unsigned char)(c > 255 ? 511 - c : c);
Widget_Resize(w, width, height);
Widget_SetStyle(w, key_display, SV_INLINE_BLOCK, style);
Widget_SetStyle(w, key_background_color, color, color);
Widget_Append(self.box, w);
}
rules.cache_children_style = TRUE;
rules.ignore_classes_change = TRUE;
rules.ignore_status_change = TRUE;
rules.max_update_children_count = -1;
rules.max_render_children_count = 0;
Widget_GenerateHash(self.box);
Widget_SetRules(self.box, &rules);
Widget_Append(root, self.box);
}
void InitRenderStatus(void)
{
LCUI_Widget root;
LCUI_Widget status;
LCUI_Color white = RGB(255, 255, 255);
LCUI_Color black = RGB(0, 0, 0);
root = LCUIWidget_GetRoot();
status = LCUIWidget_New("textview");
Widget_SetStyle(status, key_top, 10, px);
Widget_SetStyle(status, key_right, 10, px);
Widget_SetStyle(status, key_position, SV_ABSOLUTE, style);
Widget_SetStyle(status, key_background_color, black, color);
Widget_SetPadding(status, 10, 15, 10, 15);
TextView_SetColor(status, white);
Widget_Append(root, status);
UpdateRenderStatus(status);
LCUI_SetInterval(1000, UpdateRenderStatus, status);
}
int main(void)
{
size_t i;
int64_t t;
Logger_SetLevel(LOGGER_LEVEL_WARNING);
LCUI_Init();
LCUIDisplay_SetSize(SCREEN_WIDTH, SCREEN_HEIGHT);
InitBackground();
InitModal();
InitRenderStatus();
printf("running rendering performance test\n");
LCUI_RunFrame();
t = LCUI_GetTime();
self.color_index = 0;
for (i = 0; i < 600; ++i) {
UpdateFrame(self.box);
LCUI_ProcessTimers();
LCUI_ProcessEvents();
LCUIWidget_Update();
LCUIDisplay_Update();
LCUIDisplay_Render();
LCUIDisplay_Present();
++self.fps;
++self.color_index;
}
t = LCUI_GetTimeDelta(t);
Logger_Warning(
"rendered %zu frames in %.2lfs, rendering speed is %.2lf fps\n", i,
t / 1000.f, i * 1000.f / t);
return 0;
}