mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
* perf: Add OpenMP support for widget rendering (#118) - Modified src/Makefile.am and added compiler option. - Modified src/display.c and added preprocessor directives for OpenMP. - To check whether multithreading is possible, the string is output to standard output. However, I will remove it before merging. * test: add rendering performance test * build: add OpenMP configure option * refactor: change include path of `config.h` and remove printf() * perf: split the dirty rectangles into four parts for rendering * fix(linux): missing surface size access method * refactor(display): update dirty rectangle collection method * test: update test_render.c * build: add vs project file for test render * fix(display): Convert `rects` list to array and follow a "Canonical Loop Form" defined in OpenMP * refactor: Change where variable i is initialized * fix: Widget_GenerateHash() not work * test: improved widget update performance Co-authored-by: Liu <lc-soft@live.cn>
This commit is contained in:
committed by
Liu
co-authored by
Liu
parent
460354c489
commit
d8583337fb
@@ -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
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\test\test_render.c" />
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{a67c7df6-b233-4125-883b-ef1424e1b52c}</ProjectGuid>
|
||||
<Keyword>Win32Proj</Keyword>
|
||||
<RootNamespace>test_render</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>7.0</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>true</UseDebugLibraries>
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
<CharacterSet>Unicode</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
<UseDebugLibraries>false</UseDebugLibraries>
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
<WholeProgramOptimization>true</WholeProgramOptimization>
|
||||
<CharacterSet>MultiByte</CharacterSet>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<ImportGroup Label="ExtensionSettings">
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<PropertyGroup Label="UserMacros" />
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
<OutDir>$(SolutionDir)..\..\bin\$(PlatformTarget)-windows\$(Configuration)\</OutDir>
|
||||
<IntDir>$(ProjectDir)$(Configuration)\$(Platform)\objs\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<LinkIncremental>true</LinkIncremental>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
<OutDir>$(SolutionDir)..\..\bin\$(PlatformTarget)-windows\$(Configuration)\</OutDir>
|
||||
<IntDir>$(ProjectDir)$(Configuration)\$(Platform)\objs\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
<OutDir>$(SolutionDir)..\..\bin\$(PlatformTarget)-windows\$(Configuration)\</OutDir>
|
||||
<IntDir>$(ProjectDir)$(Configuration)\$(Platform)\objs\</IntDir>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<LinkIncremental>false</LinkIncremental>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<CodeAnalysisRules />
|
||||
<CodeAnalysisRuleAssemblies />
|
||||
<OutDir>$(SolutionDir)..\..\bin\$(PlatformTarget)-windows\$(Configuration)\</OutDir>
|
||||
<IntDir>$(ProjectDir)$(Configuration)\$(Platform)\objs\</IntDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;BATCH_TEST;_CRT_SECURE_NO_WARNINGS;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\include\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<CompileAs>CompileAsC</CompileAs>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>LCUI.lib;LCUIMain.lib;</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<ClCompile>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<Optimization>Disabled</Optimization>
|
||||
<PreprocessorDefinitions>WIN32;BATCH_TEST;_CRT_SECURE_NO_WARNINGS;_DEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\include\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<CompileAs>CompileAsC</CompileAs>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>LCUI.lib;LCUIMain.lib;</AdditionalDependencies>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;BATCH_TEST;_CRT_SECURE_NO_WARNINGS;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\include\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4819</DisableSpecificWarnings>
|
||||
<BrowseInformation>true</BrowseInformation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>LCUI.lib;LCUIMain.lib;</AdditionalDependencies>
|
||||
</Link>
|
||||
<Bscmake>
|
||||
<PreserveSbr>true</PreserveSbr>
|
||||
</Bscmake>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<WarningLevel>Level3</WarningLevel>
|
||||
<PrecompiledHeader>
|
||||
</PrecompiledHeader>
|
||||
<Optimization>MaxSpeed</Optimization>
|
||||
<FunctionLevelLinking>true</FunctionLevelLinking>
|
||||
<IntrinsicFunctions>true</IntrinsicFunctions>
|
||||
<PreprocessorDefinitions>WIN32;BATCH_TEST;_CRT_SECURE_NO_WARNINGS;NDEBUG;_WINDOWS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(SolutionDir)\include;$(SolutionDir)\include\..\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<DisableSpecificWarnings>4819</DisableSpecificWarnings>
|
||||
<BrowseInformation>true</BrowseInformation>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Windows</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<EnableCOMDATFolding>true</EnableCOMDATFolding>
|
||||
<OptimizeReferences>true</OptimizeReferences>
|
||||
<AdditionalLibraryDirectories>$(OutDir)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>LCUI.lib;LCUIMain.lib;</AdditionalDependencies>
|
||||
</Link>
|
||||
<Bscmake>
|
||||
<PreserveSbr>true</PreserveSbr>
|
||||
</Bscmake>
|
||||
</ItemDefinitionGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
</ImportGroup>
|
||||
</Project>
|
||||
@@ -0,0 +1,22 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup>
|
||||
<Filter Include="源文件">
|
||||
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
|
||||
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="头文件">
|
||||
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
|
||||
<Extensions>h;hpp;hxx;hm;inl;inc;xsd</Extensions>
|
||||
</Filter>
|
||||
<Filter Include="资源文件">
|
||||
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
|
||||
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\test\test_render.c">
|
||||
<Filter>源文件</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
+135
-68
@@ -27,9 +27,14 @@
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <time.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#ifdef USE_OPENMP
|
||||
#include <omp.h>
|
||||
#endif
|
||||
#include <LCUI_Build.h>
|
||||
#include <LCUI/LCUI.h>
|
||||
#include <LCUI/input.h>
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+4
-1
@@ -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@
|
||||
|
||||
@@ -0,0 +1,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);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user