diff --git a/build/windows/LCUI-Demo.sln b/build/windows/LCUI-Demo.sln index 0e3d72f0..fe28cb83 100644 --- a/build/windows/LCUI-Demo.sln +++ b/build/windows/LCUI-Demo.sln @@ -31,6 +31,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_border", "test_border\ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_box_shadow", "test_box_shadow\test_box_shadow.vcxproj", "{83133071-0048-4400-92FD-842751D1EEDB}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "test_render", "test_render\test_render.vcxproj", "{A67C7DF6-B233-4125-883B-EF1424E1B52C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|ARM = Debug|ARM @@ -186,6 +188,16 @@ Global {83133071-0048-4400-92FD-842751D1EEDB}.Release|Win32.Build.0 = Release|Win32 {83133071-0048-4400-92FD-842751D1EEDB}.Release|x64.ActiveCfg = Release|x64 {83133071-0048-4400-92FD-842751D1EEDB}.Release|x64.Build.0 = Release|x64 + {A67C7DF6-B233-4125-883B-EF1424E1B52C}.Debug|ARM.ActiveCfg = Debug|Win32 + {A67C7DF6-B233-4125-883B-EF1424E1B52C}.Debug|Win32.ActiveCfg = Debug|Win32 + {A67C7DF6-B233-4125-883B-EF1424E1B52C}.Debug|Win32.Build.0 = Debug|Win32 + {A67C7DF6-B233-4125-883B-EF1424E1B52C}.Debug|x64.ActiveCfg = Debug|x64 + {A67C7DF6-B233-4125-883B-EF1424E1B52C}.Debug|x64.Build.0 = Debug|x64 + {A67C7DF6-B233-4125-883B-EF1424E1B52C}.Release|ARM.ActiveCfg = Release|Win32 + {A67C7DF6-B233-4125-883B-EF1424E1B52C}.Release|Win32.ActiveCfg = Release|Win32 + {A67C7DF6-B233-4125-883B-EF1424E1B52C}.Release|Win32.Build.0 = Release|Win32 + {A67C7DF6-B233-4125-883B-EF1424E1B52C}.Release|x64.ActiveCfg = Release|x64 + {A67C7DF6-B233-4125-883B-EF1424E1B52C}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/build/windows/test_render/test_render.vcxproj b/build/windows/test_render/test_render.vcxproj new file mode 100644 index 00000000..50934aa8 --- /dev/null +++ b/build/windows/test_render/test_render.vcxproj @@ -0,0 +1,192 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + + + + {a67c7df6-b233-4125-883b-ef1424e1b52c} + Win32Proj + test_render + 7.0 + + + + Application + true + v141_xp + Unicode + + + Application + true + v141_xp + Unicode + + + Application + false + v141_xp + true + MultiByte + + + Application + false + v141_xp + true + MultiByte + + + + + + + + + + + + + + + + + + + true + AllRules.ruleset + + + $(SolutionDir)..\..\bin\$(PlatformTarget)-windows\$(Configuration)\ + $(ProjectDir)$(Configuration)\$(Platform)\objs\ + + + true + AllRules.ruleset + + + $(SolutionDir)..\..\bin\$(PlatformTarget)-windows\$(Configuration)\ + $(ProjectDir)$(Configuration)\$(Platform)\objs\ + + + false + AllRules.ruleset + + + $(SolutionDir)..\..\bin\$(PlatformTarget)-windows\$(Configuration)\ + $(ProjectDir)$(Configuration)\$(Platform)\objs\ + + + false + AllRules.ruleset + + + $(SolutionDir)..\..\bin\$(PlatformTarget)-windows\$(Configuration)\ + $(ProjectDir)$(Configuration)\$(Platform)\objs\ + + + + + + Level3 + Disabled + WIN32;BATCH_TEST;_CRT_SECURE_NO_WARNINGS;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + $(SolutionDir)\include;$(SolutionDir)\include\..\..\..\include;%(AdditionalIncludeDirectories) + CompileAsC + + + Windows + true + $(OutDir) + LCUI.lib;LCUIMain.lib; + + + + + + + Level3 + Disabled + WIN32;BATCH_TEST;_CRT_SECURE_NO_WARNINGS;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) + $(SolutionDir)\include;$(SolutionDir)\include\..\..\..\include;%(AdditionalIncludeDirectories) + CompileAsC + + + Windows + true + $(OutDir) + LCUI.lib;LCUIMain.lib; + + + + + Level3 + + + MaxSpeed + true + true + WIN32;BATCH_TEST;_CRT_SECURE_NO_WARNINGS;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + $(SolutionDir)\include;$(SolutionDir)\include\..\..\..\include;%(AdditionalIncludeDirectories) + 4819 + true + + + Windows + true + true + true + $(OutDir) + LCUI.lib;LCUIMain.lib; + + + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;BATCH_TEST;_CRT_SECURE_NO_WARNINGS;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) + $(SolutionDir)\include;$(SolutionDir)\include\..\..\..\include;%(AdditionalIncludeDirectories) + 4819 + true + + + Windows + true + true + true + $(OutDir) + LCUI.lib;LCUIMain.lib; + + + true + + + + + + \ No newline at end of file diff --git a/build/windows/test_render/test_render.vcxproj.filters b/build/windows/test_render/test_render.vcxproj.filters new file mode 100644 index 00000000..668b2dc4 --- /dev/null +++ b/build/windows/test_render/test_render.vcxproj.filters @@ -0,0 +1,22 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + 源文件 + + + \ No newline at end of file diff --git a/configure.ac b/configure.ac index 2e82c07c..447d9209 100755 --- a/configure.ac +++ b/configure.ac @@ -73,6 +73,22 @@ if test "x$with_pthread" != "xno"; then ], [AC_MSG_ERROR([The support could not be configured for the POSIX thread programming interface.])]) fi +# openmp +want_openmp=no +AC_ARG_WITH(openmp, AC_HELP_STRING([--with-openmp], [use openmp (default)])) +if test "x$with_openmp" != "xno"; then + AC_OPENMP + if test "x$OPENMP_CFLAGS" != "x"; then + want_openmp=yes + CFLAGS="$CFLAGS $OPENMP_CFLAGS" + AC_DEFINE_UNQUOTED(USE_OPENMP, 1, Define to 1 if you are using OpenMP support.) + else + AC_MSG_ERROR([The support could not be configured for the OpenMP.]) + fi +else + want_openmp=no +fi + # libxml2 enable_builder=yes AC_ARG_ENABLE(lcui-builder, AC_HELP_STRING([--enable-lcui-builder], @@ -227,6 +243,7 @@ echo -e "Build with libjpeg support ......... : $want_jpeg" echo -e "Build with font-engine support ..... : $font_engine_name" echo -e "Build with fontconfig support ...... : $want_fontconfig" echo -e "Build with thread support .......... : $thread_name" +echo -e "Build with OpenMP support .......... : $want_openmp" echo -e "Build with video support ........... : $video_driver_name" echo diff --git a/include/LCUI/config.h.in b/include/LCUI/config.h.in index 1b2adbe1..75ab6275 100644 --- a/include/LCUI/config.h.in +++ b/include/LCUI/config.h.in @@ -159,6 +159,9 @@ /* Define to 1 if you have the libpng. */ #undef USE_LIBPNG +/* Define to 1 if you are using OpenMP support. */ +#undef USE_OPENMP + /* Version number of package */ #undef VERSION diff --git a/include/LCUI/surface.h b/include/LCUI/surface.h index 7600eaa8..e3f9f49e 100644 --- a/include/LCUI/surface.h +++ b/include/LCUI/surface.h @@ -55,6 +55,10 @@ LCUI_API LCUI_BOOL Surface_IsReady(LCUI_Surface surface); LCUI_API void Surface_Move(LCUI_Surface surface, int x, int y); +LCUI_API int Surface_GetWidth(LCUI_Surface surface); + +LCUI_API int Surface_GetHeight(LCUI_Surface surface); + LCUI_API void Surface_Resize(LCUI_Surface surface, int w, int h); LCUI_API void Surface_SetCaptionW(LCUI_Surface surface, const wchar_t *str); diff --git a/include/LCUI/util/rect.h b/include/LCUI/util/rect.h index 271a12ad..d4014b91 100644 --- a/include/LCUI/util/rect.h +++ b/include/LCUI/util/rect.h @@ -113,6 +113,13 @@ LCUI_API int RectList_Add(LinkedList *list, LCUI_Rect *rect); /** 删除脏矩形 */ LCUI_API int RectList_Delete(LinkedList *list, LCUI_Rect *rect); +/** + * Split each rectangle with the bounding box + */ +LCUI_API +size_t RectList_SplitWith(LinkedList *rects, const LCUI_Rect *bounding, + LinkedList *splited_rects); + #define RectList_Clear(LIST) LinkedList_Clear(LIST, free) LCUI_END_HEADER diff --git a/src/display.c b/src/display.c index 753fbfd1..bf8eb971 100644 --- a/src/display.c +++ b/src/display.c @@ -27,9 +27,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" + #include #include #include +#ifdef USE_OPENMP +#include +#endif #include #include #include @@ -94,6 +99,108 @@ static void DrawBorder(LCUI_PaintContext paint) Graph_DrawHorizLine(&paint->canvas, color, 1, pos, end_x); } +static void SurfaceRecord_DumpRects(SurfaceRecord record, + LinkedList *rects) +{ + LCUI_Rect rect; + const int width = Surface_GetWidth(record->surface); + const int height = Surface_GetHeight(record->surface); + + /* top left */ + rect.x = 0; + rect.y = 0; + rect.width = width / 2; + rect.height = height / 2; + RectList_SplitWith(&record->rects, &rect, rects); + + /* top right */ + rect.x = width / 2; + rect.width = width - rect.x; + RectList_SplitWith(&record->rects, &rect, rects); + + /* bottom left */ + rect.x = 0; + rect.y = height / 2; + rect.width = width / 2; + rect.height = height - rect.y; + RectList_SplitWith(&record->rects, &rect, rects); + + /* bottom right */ + rect.x = width / 2; + rect.width = width - rect.x; + RectList_SplitWith(&record->rects, &rect, rects); + + RectList_Clear(&record->rects); +} + +static size_t LCUIDisplay_RenderSurface(SurfaceRecord record) +{ + size_t count = 0; + int i; + LCUI_Rect *rect; + LCUI_PaintContext paint; + LCUI_SysEventRec ev; + LinkedList rects; + LinkedListNode *node; + LCUI_BOOL can_render; + LCUI_Rect **rectArray; + + ev.type = LCUI_PAINT; + can_render = record->widget && record->surface && + Surface_IsReady(record->surface); + record->rendered = FALSE; + LinkedList_Init(&rects); + SurfaceRecord_DumpRects(record, &rects); + if (rects.length < 1) { + return 0; + } + + rectArray = (LCUI_Rect **)malloc(sizeof(LCUI_Rect*) * rects.length); + i = 0; + for (LinkedList_Each(node, &rects)) { + rectArray[i] = node->data; + i++; + } +#ifdef USE_OPENMP +#pragma omp parallel for \ + default(none) \ + shared(can_render, display, rects, rectArray) \ + private(rect, paint) \ + firstprivate(record, ev) \ + reduction(+:count) +#endif + for (i = 0; i < rects.length; i++) { + rect = rectArray[i]; + ev.paint.rect = *rect; + LCUI_TriggerEvent(&ev, NULL); + if (!can_render) { + continue; + } + paint = Surface_BeginPaint(record->surface, rect); + if (!paint) { + continue; + } + DEBUG_MSG("rect: (%d,%d,%d,%d)\n", paint->rect.x, paint->rect.y, + paint->rect.width, paint->rect.height); + count += Widget_Render(record->widget, paint); + /** + * FIXME: Improve highlighting of repainted areas + * Let the highlighted areas disappear after a short + * period of time, just like flashing + */ + if (display.show_rect_border) { + DrawBorder(paint); + } + if (display.mode != LCUI_DMODE_SEAMLESS) { + LCUICursor_Paint(paint); + } + Surface_EndPaint(record->surface, paint); + } + RectList_Clear(&rects); + record->rendered = count > 0; + return count; +} + void LCUIDisplay_Update(void) { LCUI_Surface surface; @@ -122,70 +229,14 @@ void LCUIDisplay_Update(void) size_t LCUIDisplay_Render(void) { size_t count = 0; - LCUI_Rect *rect; - LCUI_Surface s; - LCUI_SysEventRec ev; - LCUI_BOOL can_render; - LCUI_PaintContext paint; - LinkedList rects; - LinkedListNode *sn, *rn; - SurfaceRecord record; + LinkedListNode *node; if (!display.active) { return 0; } - ev.type = LCUI_PAINT; - LinkedList_Init(&rects); - /* 遍历当前的 surface 记录列表 */ - for (LinkedList_Each(sn, &display.surfaces)) { - record = sn->data; - s = record->surface; - can_render = record->widget && s && Surface_IsReady(s); - record->rendered = FALSE; - /* collect and merge scattered rectangles */ - for (LinkedList_Each(rn, &record->rects)) { - rect = rn->data; - RectList_Add(&rects, rn->data); - } - - /** - * FIXME: add OpenMP support - * Dirty rectangle repaint tasks can be assigned to multiple CPU - * cores to improve rendering performance - */ - - /* Repaint dirty rectangles of surface */ - for (LinkedList_Each(rn, &rects)) { - rect = rn->data; - ev.paint.rect = *rect; - LCUI_TriggerEvent(&ev, NULL); - if (!can_render) { - continue; - } - paint = Surface_BeginPaint(s, rect); - if (!paint) { - continue; - } - DEBUG_MSG("rect: (%d,%d,%d,%d)\n", paint->rect.x, - paint->rect.y, paint->rect.width, - paint->rect.height); - count += Widget_Render(record->widget, paint); - /** - * FIXME: Improve highlighting of repainted areas - * Let the highlighted areas disappear after a short - * period of time, just like flashing - */ - if (display.show_rect_border) { - DrawBorder(paint); - } - if (display.mode != LCUI_DMODE_SEAMLESS) { - LCUICursor_Paint(paint); - } - Surface_EndPaint(s, paint); - record->rendered = TRUE; - } - RectList_Clear(&rects); - RectList_Clear(&record->rects); + for (LinkedList_Each(node, &display.surfaces)) { + count += LCUIDisplay_RenderSurface(node->data); + count += LCUIDisplay_UpdateFlashRects(node->data); } return count; } @@ -193,6 +244,7 @@ size_t LCUIDisplay_Render(void) void LCUIDisplay_Present(void) { LinkedListNode *sn; + if (!display.active) { return; } @@ -211,6 +263,7 @@ void LCUIDisplay_Present(void) void LCUIDisplay_InvalidateArea(LCUI_Rect *rect) { LCUI_Rect area; + if (!display.active) { return; } @@ -227,9 +280,11 @@ void LCUIDisplay_InvalidateArea(LCUI_Rect *rect) static LCUI_Widget LCUIDisplay_GetBindWidget(LCUI_Surface surface) { + SurfaceRecord record; LinkedListNode *node; + for (LinkedList_Each(node, &display.surfaces)) { - SurfaceRecord record = node->data; + record = node->data; if (record && record->surface == surface) { return record->widget; } @@ -239,9 +294,11 @@ static LCUI_Widget LCUIDisplay_GetBindWidget(LCUI_Surface surface) static LCUI_Surface LCUIDisplay_GetBindSurface(LCUI_Widget widget) { + SurfaceRecord record; LinkedListNode *node; + for (LinkedList_Each(node, &display.surfaces)) { - SurfaceRecord record = node->data; + record = node->data; if (record && record->widget == widget) { return record->surface; } @@ -264,6 +321,7 @@ LCUI_Surface LCUIDisplay_GetSurfaceOwner(LCUI_Widget w) LCUI_Surface LCUIDisplay_GetSurfaceByHandle(void *handle) { LinkedListNode *node; + for (LinkedList_Each(node, &display.surfaces)) { SurfaceRecord record = node->data; if (Surface_GetHandle(record->surface) == handle) { @@ -278,6 +336,7 @@ static void LCUIDisplay_BindSurface(LCUI_Widget widget) { LCUI_Rect rect; SurfaceRecord record; + if (LCUIDisplay_GetBindSurface(widget)) { return; } @@ -305,9 +364,11 @@ static void LCUIDisplay_BindSurface(LCUI_Widget widget) /** 解除 widget 与 sruface 的绑定 */ static void LCUIDisplay_UnbindSurface(LCUI_Widget widget) { + SurfaceRecord record; LinkedListNode *node; + for (LinkedList_Each(node, &display.surfaces)) { - SurfaceRecord record = node->data; + record = node->data; if (record && record->widget == widget) { Surface_Close(record->surface); LinkedList_DeleteNode(&display.surfaces, node); @@ -318,7 +379,9 @@ static void LCUIDisplay_UnbindSurface(LCUI_Widget widget) static int LCUIDisplay_Windowed(void) { - LCUI_Widget root = LCUIWidget_GetRoot(); + LCUI_Widget root; + + root = LCUIWidget_GetRoot(); switch (display.mode) { case LCUI_DMODE_WINDOWED: return 0; @@ -338,7 +401,9 @@ static int LCUIDisplay_Windowed(void) static int LCUIDisplay_FullScreen(void) { - LCUI_Widget root = LCUIWidget_GetRoot(); + LCUI_Widget root; + + root = LCUIWidget_GetRoot(); switch (display.mode) { case LCUI_DMODE_SEAMLESS: LCUIDisplay_CleanSurfaces(); @@ -365,7 +430,7 @@ static int LCUIDisplay_Seamless(void) { LinkedListNode *node; LCUI_Widget root = LCUIWidget_GetRoot(); - DEBUG_MSG("display.mode: %d\n", display.mode); + switch (display.mode) { case LCUI_DMODE_SEAMLESS: return 0; @@ -386,7 +451,7 @@ static int LCUIDisplay_Seamless(void) int LCUIDisplay_SetMode(int mode) { int ret; - DEBUG_MSG("mode: %d\n", mode); + switch (mode) { case LCUI_DMODE_WINDOWED: ret = LCUIDisplay_Windowed(); @@ -424,6 +489,7 @@ void LCUIDisplay_SetSize(int width, int height) float scale; LCUI_Widget root; LCUI_Surface surface; + if (display.mode == LCUI_DMODE_SEAMLESS) { return; } @@ -467,10 +533,11 @@ void Surface_Close(LCUI_Surface surface) void Surface_Destroy(LCUI_Surface surface) { + LinkedListNode *node; + if (!display.active) { return; } - LinkedListNode *node; for (LinkedList_Each(node, &display.surfaces)) { SurfaceRecord record = node->data; if (record && record->surface == surface) { diff --git a/src/gui/widget_base.c b/src/gui/widget_base.c index db81fbac..2700fb82 100755 --- a/src/gui/widget_base.c +++ b/src/gui/widget_base.c @@ -392,7 +392,7 @@ void Widget_GenerateHash(LCUI_Widget w) LinkedListNode *node; Widget_GenerateSelfHash(w); - for (LinkedList_Each(node, &w->children_show)) { + for (LinkedList_Each(node, &w->children)) { Widget_GenerateHash(node->data); } } diff --git a/src/platform/linux/linux_x11display.c b/src/platform/linux/linux_x11display.c index 6e669087..b882d6b9 100644 --- a/src/platform/linux/linux_x11display.c +++ b/src/platform/linux/linux_x11display.c @@ -399,6 +399,16 @@ static void *X11Surface_GetHandle(LCUI_Surface s) return NULL; } +static int X11Surface_GetWidth(LCUI_Surface s) +{ + return s->width; +} + +static int X11Surface_GetHeight(LCUI_Surface s) +{ + return s->height; +} + static int X11Display_GetWidth(void) { Screen *s = DefaultScreenOfDisplay(x11.app->display); @@ -476,6 +486,8 @@ LCUI_DisplayDriver LCUI_CreateLinuxX11DisplayDriver(void) driver->beginPaint = X11Surface_BeginPaint; driver->endPaint = X11Surface_EndPaint; driver->bindEvent = X11Display_BindEvent; + driver->getSurfaceWidth = X11Surface_GetWidth; + driver->getSurfaceHeight = X11Surface_GetHeight; LinkedList_Init(&x11.surfaces); LCUI_BindSysEvent(Expose, OnExpose, NULL, NULL); LCUI_BindSysEvent(ConfigureNotify, OnConfigureNotify, NULL, NULL); diff --git a/src/util/rect.c b/src/util/rect.c index 4b192655..7c5e355f 100644 --- a/src/util/rect.c +++ b/src/util/rect.c @@ -472,3 +472,16 @@ int RectList_Delete(LinkedList *list, LCUI_Rect *rect) LinkedList_Concat(list, &extra_list); return 1; } + +size_t RectList_SplitWith(LinkedList *rects, const LCUI_Rect *bounding, + LinkedList *splited_rects) +{ + LCUI_Rect splited_rect; + LinkedListNode *node; + + for (LinkedList_Each(node, rects)) { + LCUIRect_GetOverlayRect(bounding, node->data, &splited_rect); + RectList_AddEx(splited_rects, &splited_rect, FALSE); + } + return splited_rects->length; +} diff --git a/test/Makefile.am b/test/Makefile.am index 34c7279d..b7e891c0 100755 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -6,7 +6,7 @@ noinst_PROGRAMS = helloworld test test_charset test_touch test_char_render \ test_string_render test_widget_render test_widget_layout test_widget_rect \ test_widget_opacity test_widget_flex_layout test_widget_inline_block_layout \ test_scaling_support test_widget test_scrollbar test_textview_resize \ -test_image_scaling_bench +test_image_scaling_bench test_render ##指定测试程序的源码文件 helloworld_SOURCES = helloworld.c @@ -70,6 +70,9 @@ test_scrollbar_LDADD = $(top_builddir)/src/libLCUI.la test_widget_SOURCES = test_widget.c test_widget_LDADD = $(top_builddir)/src/libLCUI.la +test_render_SOURCES = test_render.c +test_render_LDADD = $(top_builddir)/src/libLCUI.la + test_image_scaling_bench_LDADD = $(top_builddir)/src/libLCUI.la @CODE_COVERAGE_RULES@ diff --git a/test/test_render.c b/test/test_render.c new file mode 100644 index 00000000..62ae6549 --- /dev/null +++ b/test/test_render.c @@ -0,0 +1,166 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#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); +} + +void UpdateFrame(void *arg) +{ + Widget_Each(arg, UpdateWidgetStyle, NULL); + LCUIWidget_RefreshStyle(); +} + +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 < 120; ++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; +}