Introduce FontCollection construct perf test

Test: ran minikin_perftest
Bug: 36232655
Change-Id: Ic4d88663d522be17540e2ac17c9b7ae64210275f
This commit is contained in:
Seigo Nonaka
2017-03-16 15:55:25 -07:00
parent 464d63f0d8
commit 2d0bfff203
3 changed files with 35 additions and 11 deletions

View File

@@ -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<std::shared_ptr<FontFamily>> families =
getFontFamilies(SYSTEM_FONT_PATH, SYSTEM_FONT_XML);
while (state.KeepRunning()) {
std::make_shared<FontCollection>(families);
}
}
BENCHMARK(BM_FontCollection_construct);
static void BM_FontCollection_hasVariationSelector(benchmark::State& state) {
std::shared_ptr<FontCollection> collection(
getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML));

View File

@@ -28,7 +28,7 @@
namespace minikin {
FontCollection* getFontCollection(const char* fontDir, const char* fontXml) {
std::vector<std::shared_ptr<FontFamily>> 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> minikinFont(new MinikinFontForTest(fontPath));
std::shared_ptr<MinikinFont> minikinFont =
std::make_shared<MinikinFontForTest>(fontPath);
fonts.push_back(Font(minikinFont, FontStyle(weight, italic)));
} else {
std::shared_ptr<MinikinFont> minikinFont(
new MinikinFontForTest(fontPath, atoi((const char*)index)));
std::shared_ptr<MinikinFont> minikinFont =
std::make_shared<MinikinFontForTest>(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<FontFamily> family;
if (lang == nullptr) {
family.reset(new FontFamily(variant, std::move(fonts)));
family = std::make_shared<FontFamily>(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<FontFamily>(langId, variant, std::move(fonts));
}
families.push_back(family);
}
xmlFreeDoc(doc);
return new FontCollection(families);
return families;
}
std::shared_ptr<FontCollection> getFontCollection(const char* fontDir, const char* fontXml) {
return std::make_shared<FontCollection>(getFontFamilies(fontDir, fontXml));
}
} // namespace minikin

View File

@@ -19,17 +19,28 @@
#include <minikin/FontCollection.h>
#include <memory>
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<std::shared_ptr<FontFamily>> 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<FontCollection> getFontCollection(const char* fontDir, const char* fontXml);
} // namespace minikin
#endif // MINIKIN_FONT_TEST_UTILS_H