diff --git a/engine/src/flutter/tests/perftests/FontCollection.cpp b/engine/src/flutter/tests/perftests/FontCollection.cpp index 6f9d636ca3..fd95cf1a60 100644 --- a/engine/src/flutter/tests/perftests/FontCollection.cpp +++ b/engine/src/flutter/tests/perftests/FontCollection.cpp @@ -27,6 +27,16 @@ namespace minikin { const char* SYSTEM_FONT_PATH = "/system/fonts/"; const char* SYSTEM_FONT_XML = "/system/etc/fonts.xml"; +static void BM_FontCollection_construct(benchmark::State& state) { + std::vector> families = + getFontFamilies(SYSTEM_FONT_PATH, SYSTEM_FONT_XML); + while (state.KeepRunning()) { + std::make_shared(families); + } +} + +BENCHMARK(BM_FontCollection_construct); + static void BM_FontCollection_hasVariationSelector(benchmark::State& state) { std::shared_ptr collection( getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); diff --git a/engine/src/flutter/tests/util/FontTestUtils.cpp b/engine/src/flutter/tests/util/FontTestUtils.cpp index 27a693e16d..13360d4aa2 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.cpp +++ b/engine/src/flutter/tests/util/FontTestUtils.cpp @@ -28,7 +28,7 @@ namespace minikin { -FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { +std::vector> getFontFamilies(const char* fontDir, const char* fontXml) { xmlDoc* doc = xmlReadFile(fontXml, NULL, 0); xmlNode* familySet = xmlDocGetRootElement(doc); @@ -69,11 +69,12 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { } if (index == nullptr) { - std::shared_ptr minikinFont(new MinikinFontForTest(fontPath)); + std::shared_ptr minikinFont = + std::make_shared(fontPath); fonts.push_back(Font(minikinFont, FontStyle(weight, italic))); } else { - std::shared_ptr minikinFont( - new MinikinFontForTest(fontPath, atoi((const char*)index))); + std::shared_ptr minikinFont = + std::make_shared(fontPath, atoi((const char*)index)); fonts.push_back(Font(minikinFont, FontStyle(weight, italic))); } } @@ -81,17 +82,19 @@ FontCollection* getFontCollection(const char* fontDir, const char* fontXml) { xmlChar* lang = xmlGetProp(familyNode, (const xmlChar*)"lang"); std::shared_ptr family; if (lang == nullptr) { - family.reset(new FontFamily(variant, std::move(fonts))); + family = std::make_shared(variant, std::move(fonts)); } else { uint32_t langId = FontStyle::registerLanguageList( std::string((const char*)lang, xmlStrlen(lang))); - family.reset(new FontFamily(langId, variant, std::move(fonts))); + family = std::make_shared(langId, variant, std::move(fonts)); } families.push_back(family); } xmlFreeDoc(doc); - - return new FontCollection(families); + return families; +} +std::shared_ptr getFontCollection(const char* fontDir, const char* fontXml) { + return std::make_shared(getFontFamilies(fontDir, fontXml)); } } // namespace minikin diff --git a/engine/src/flutter/tests/util/FontTestUtils.h b/engine/src/flutter/tests/util/FontTestUtils.h index 69ba841b43..dd5e5860e4 100644 --- a/engine/src/flutter/tests/util/FontTestUtils.h +++ b/engine/src/flutter/tests/util/FontTestUtils.h @@ -19,17 +19,28 @@ #include +#include + namespace minikin { +/** + * Returns list of FontFamily from installed fonts. + * + * This function reads an XML file and makes font families. + * + * Caller must unref the returned pointer. + */ +std::vector> getFontFamilies(const char* fontDir, const char* fontXml); + /** * Returns FontCollection from installed fonts. * - * This function reads /system/etc/fonts.xml and make font families and - * collections of them. MinikinFontForTest is used for FontFamily creation. + * This function reads an XML file and makes font families and collections of them. + * MinikinFontForTest is used for FontFamily creation. * * Caller must unref the returned pointer. */ -FontCollection* getFontCollection(const char* fontDir, const char* fontXml); +std::shared_ptr getFontCollection(const char* fontDir, const char* fontXml); } // namespace minikin #endif // MINIKIN_FONT_TEST_UTILS_H