Skip to content

Commit e1dc4b2

Browse files
committed
Added font texture atlas benchmarks.
1 parent a21a1a2 commit e1dc4b2

File tree

6 files changed

+90
-35
lines changed

6 files changed

+90
-35
lines changed
5.47 MB
Binary file not shown.

Source/Core/FontEngineDefault/FontFaceLayer.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ bool FontFaceLayer::Generate(
221221
return true;
222222
}
223223

224-
bool FontFaceLayer::GenerateTexture(Vector<byte>& texture_data, Vector2i& texture_dimensions, int texture_id, const FontGlyphMap& glyphs)
224+
bool FontFaceLayer::GenerateTexture(Vector<byte>& texture_data, Vector2i& texture_dimensions, int texture_id, const FontGlyphMap& /*glyphs*/)
225225
{
226-
if (texture_id < 0 || texture_id > sprite_set_textures.size())
226+
if (texture_id < 0 || texture_id > static_cast<int>(sprite_set_textures.size()))
227227
return false;
228228

229229
const unsigned char *const source = sprite_set_textures[texture_id];

Source/Core/FontEngineDefault/SpriteSet.cpp

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -120,19 +120,20 @@ SpriteSet::Handle SpriteSet::Add(
120120
)
121121
{
122122
auto texture_start = page.texture_data->begin() + (top_padding_y * page_size + slot.x) * bytes_per_pixel;
123-
std::fill(texture_start, texture_start + padded_width * bytes_per_pixel, 0);
123+
std::fill(texture_start, texture_start + padded_width * bytes_per_pixel, static_cast<unsigned char>(0));
124124
texture_start = page.texture_data->begin() + (bottom_padding_y * page_size + slot.x) * bytes_per_pixel;
125-
std::fill(texture_start, texture_start + padded_width * bytes_per_pixel, 0);
125+
std::fill(texture_start, texture_start + padded_width * bytes_per_pixel, static_cast<unsigned char>(0));
126126
}
127127
const unsigned int texture_y = shelf.y + sprite_padding;
128128
for (unsigned int local_y = 0; local_y != height; ++local_y)
129129
{
130130
const unsigned char* const data_start = data + local_y * row_stride * bytes_per_pixel;
131131
const auto texture_start = page.texture_data->begin()
132132
+ ((texture_y + local_y) * page_size + slot.x) * bytes_per_pixel;
133-
std::fill(texture_start, texture_start + sprite_padding * bytes_per_pixel, 0);
133+
std::fill(texture_start, texture_start + sprite_padding * bytes_per_pixel, static_cast<unsigned char>(0));
134134
std::fill(
135-
texture_start + (sprite_padding + width) * bytes_per_pixel, texture_start + padded_width * bytes_per_pixel, 0
135+
texture_start + (sprite_padding + width) * bytes_per_pixel, texture_start + padded_width * bytes_per_pixel,
136+
static_cast<unsigned char>(0)
136137
);
137138
std::copy(data_start, data_start + width * bytes_per_pixel, texture_start + sprite_padding * bytes_per_pixel);
138139
}
@@ -468,26 +469,4 @@ Vector<const unsigned char*> SpriteSet::GetTextures() const
468469
return textures;
469470
}
470471

471-
void SpriteSet::Dump(Vector<SpriteSet::SpriteData> &sprites) const
472-
{
473-
if (first_page_index == null_index)
474-
return;
475-
for (
476-
unsigned int shelf_index = page_pool[first_page_index].first_shelf_index;
477-
shelf_index != null_index; shelf_index = shelf_pool[shelf_index].next_index
478-
)
479-
{
480-
const unsigned int shelfY = shelf_pool[shelf_index].y;
481-
for (
482-
unsigned int slot_index = shelf_pool[shelf_index].first_slot_index;
483-
slot_index != null_index; slot_index = slot_pool[slot_index].next_index
484-
)
485-
{
486-
const Slot& slot = slot_pool[slot_index];
487-
if (slot.allocated)
488-
sprites.push_back({slot.x, shelfY, slot.width, slot.height});
489-
}
490-
}
491-
}
492-
493472
} // namespace Rml

Source/Core/FontEngineDefault/SpriteSet.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,6 @@ class SpriteSet final {
6969
/// @return An array of pointers to each page's texture data.
7070
Vector<const unsigned char*> GetTextures() const;
7171

72-
void Dump(std::vector<SpriteData> &sprites) const;
73-
7472
private:
7573
struct Page {
7674
unsigned int previous_index, next_index;

Tests/Source/Benchmarks/CMakeLists.txt

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
set(TARGET_NAME "rmlui_benchmarks")
22

33
add_executable(${TARGET_NAME}
4+
BackgroundBorder.cpp
5+
DataBinding.cpp
46
DataExpression.cpp
57
Element.cpp
6-
BackgroundBorder.cpp
78
ElementDocument.cpp
8-
Table.cpp
9-
Selectors.cpp
10-
main.cpp
11-
DataBinding.cpp
129
Flexbox.cpp
1310
FontEffect.cpp
11+
FontTextureAtlas.cpp
12+
Selectors.cpp
13+
Table.cpp
1414
WidgetTextInput.cpp
15+
main.cpp
1516
)
1617

1718
set_common_target_options(${TARGET_NAME})
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#include "../Common/TestsShell.h"
2+
#include <RmlUi/Core/Context.h>
3+
#include <RmlUi/Core/Core.h>
4+
#include <RmlUi/Core/Element.h>
5+
#include <RmlUi/Core/ElementDocument.h>
6+
#include <RmlUi/Core/Types.h>
7+
#include <doctest.h>
8+
#include <nanobench.h>
9+
10+
using namespace ankerl;
11+
using namespace Rml;
12+
13+
// Start of the "CJK unified ideographs" Unicode block.
14+
static constexpr int rml_font_texture_atlas_start_codepoint = 0x4E00;
15+
16+
static const String rml_font_texture_atlas_document = R"(
17+
<rml>
18+
<head>
19+
<title>Font texture atlas benchmark</title>
20+
<link type="text/rcss" href="/../Tests/Data/style.rcss"/>
21+
<style>
22+
body {
23+
font-family: "Noto Sans JP";
24+
font-size: %dpx;
25+
}
26+
</style>
27+
</head>
28+
<body id="body">
29+
</body>
30+
</rml>
31+
)";
32+
33+
TEST_CASE("font_texture_atlas")
34+
{
35+
Context* context = TestsShell::GetContext();
36+
REQUIRE(context);
37+
38+
LoadFontFace("assets/NotoSansJP-Regular.ttf");
39+
40+
nanobench::Bench bench;
41+
bench.title("Font texture atlas");
42+
bench.relative(true);
43+
44+
for (const int font_size : {12, 16, 24, 48, 96})
45+
{
46+
const String rml_document = CreateString(rml_font_texture_atlas_document.c_str(), font_size);
47+
48+
ElementDocument *const document = context->LoadDocumentFromMemory(rml_document);
49+
REQUIRE(document);
50+
Element *const body = document->GetElementById("body");
51+
REQUIRE(body);
52+
document->Show();
53+
context->Update();
54+
context->Render();
55+
56+
for (const int glyph_count : {10, 100, 1000})
57+
{
58+
String benchmark_name;
59+
FormatString(benchmark_name, "Size %d with %d glyphs", font_size, glyph_count);
60+
bench.run(benchmark_name.c_str(), [&]() {
61+
ReleaseFontResources();
62+
for (int i = 0; i < glyph_count; ++i)
63+
{
64+
body->SetInnerRML(StringUtilities::ToUTF8(static_cast<Character>(
65+
rml_font_texture_atlas_start_codepoint + i
66+
)));
67+
context->Update();
68+
context->Render();
69+
}
70+
});
71+
}
72+
73+
document->Close();
74+
}
75+
76+
TestsShell::ShutdownShell();
77+
}

0 commit comments

Comments
 (0)