FontCollection.cpp revision 815bc4a8fed3670682f4af3bff7df7b582bb2f4b
1/* 2 * Copyright (C) 2016 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16#include <benchmark/benchmark.h> 17 18#include <minikin/MinikinRefCounted.h> 19#include <minikin/FontCollection.h> 20#include <util/FontTestUtils.h> 21#include <util/UnicodeUtils.h> 22#include <MinikinInternal.h> 23 24namespace minikin { 25 26const char* SYSTEM_FONT_PATH = "/system/fonts/"; 27const char* SYSTEM_FONT_XML = "/system/etc/fonts.xml"; 28 29static void BM_FontCollection_hasVariationSelector(benchmark::State& state) { 30 MinikinAutoUnref<FontCollection> collection( 31 getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); 32 33 uint32_t baseCp = state.range(0); 34 uint32_t vsCp = state.range(1); 35 36 char titleBuffer[64]; 37 snprintf(titleBuffer, 64, "hasVariationSelector U+%04X,U+%04X", baseCp, vsCp); 38 state.SetLabel(titleBuffer); 39 40 while (state.KeepRunning()) { 41 collection->hasVariationSelector(baseCp, vsCp); 42 } 43} 44 45// TODO: Rewrite with BENCHMARK_CAPTURE for better test name. 46BENCHMARK(BM_FontCollection_hasVariationSelector) 47 ->ArgPair(0x2708, 0xFE0F) 48 ->ArgPair(0x2708, 0xFE0E) 49 ->ArgPair(0x3402, 0xE0100); 50 51struct ItemizeTestCases { 52 std::string itemizeText; 53 std::string languageTag; 54 std::string labelText; 55} ITEMIZE_TEST_CASES[] = { 56 { "'A' 'n' 'd' 'r' 'o' 'i' 'd'", "en", "English" }, 57 { "U+4E16", "zh-Hans", "CJK Ideograph" }, 58 { "U+4E16", "zh-Hans,zh-Hant,ja,en,es,pt,fr,de", "CJK Ideograph with many language fallback" }, 59 { "U+3402 U+E0100", "ja", "CJK Ideograph with variation selector" }, 60 { "'A' 'n' U+0E1A U+0E31 U+0645 U+062D U+0648", "en", "Mixture of English, Thai and Arabic" }, 61 { "U+2708 U+FE0E", "en", "Emoji with variation selector" }, 62 { "U+0031 U+FE0F U+20E3", "en", "KEYCAP" }, 63}; 64 65static void BM_FontCollection_itemize(benchmark::State& state) { 66 MinikinAutoUnref<FontCollection> collection( 67 getFontCollection(SYSTEM_FONT_PATH, SYSTEM_FONT_XML)); 68 69 size_t testIndex = state.range(0); 70 state.SetLabel("Itemize: " + ITEMIZE_TEST_CASES[testIndex].labelText); 71 72 uint16_t buffer[64]; 73 size_t utf16_length = 0; 74 ParseUnicode( 75 buffer, 64, ITEMIZE_TEST_CASES[testIndex].itemizeText.c_str(), &utf16_length, nullptr); 76 std::vector<FontCollection::Run> result; 77 FontStyle style(FontStyle::registerLanguageList(ITEMIZE_TEST_CASES[testIndex].languageTag)); 78 79 android::AutoMutex _l(gMinikinLock); 80 while (state.KeepRunning()) { 81 result.clear(); 82 collection->itemize(buffer, utf16_length, style, &result); 83 } 84} 85 86// TODO: Rewrite with BENCHMARK_CAPTURE once it is available in Android. 87BENCHMARK(BM_FontCollection_itemize) 88 ->Arg(0)->Arg(1)->Arg(2)->Arg(3)->Arg(4)->Arg(5)->Arg(6); 89 90} // namespace minikin 91