1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
// Copyright (c) 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/time/time.h"
#include "cc/base/lap_timer.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_test.h"
#include "third_party/blink/renderer/platform/fonts/font.h"
#include "third_party/blink/renderer/platform/fonts/font_description.h"
#include "third_party/blink/renderer/platform/testing/font_test_helpers.h"
#include "third_party/blink/renderer/platform/testing/unit_test_helpers.h"
using blink::test::CreateTestFont;
namespace blink {
static const int kTimeLimitMillis = 3000;
static const int kWarmupRuns = 10000;
static const int kTimeCheckInterval = 1000000;
class ShapeResultPerfTest {
public:
enum FontName {
ahem,
amiri,
megalopolis,
roboto,
};
ShapeResultPerfTest()
: timer(kWarmupRuns,
base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
kTimeCheckInterval) {}
protected:
TextRun SetupFont(FontName font_name, const String& text, bool ltr) {
FontDescription::VariantLigatures ligatures(
FontDescription::kEnabledLigaturesState);
font = CreateTestFont("TestFont",
test::PlatformTestDataPath(font_path[font_name]), 100,
&ligatures);
return TextRun(
text, /* xpos */ 0, /* expansion */ 0,
TextRun::kAllowTrailingExpansion | TextRun::kForbidLeadingExpansion,
ltr ? TextDirection::kLtr : TextDirection::kRtl, false);
}
Font font;
std::map<FontName, String> font_path = {
{ahem, "Ahem.woff"},
{amiri, "third_party/Amiri/amiri_arabic.woff2"},
{megalopolis, "third_party/MEgalopolis/MEgalopolisExtra.woff"},
{roboto, "third_party/Roboto/roboto-regular.woff2"},
};
cc::LapTimer timer;
};
class OffsetForPositionPerfTest : public ShapeResultPerfTest,
public testing::TestWithParam<float> {
public:
void OffsetForPosition(TextRun& run,
IncludePartialGlyphsOption partial,
BreakGlyphsOption breakopt) {
timer.Reset();
float position = GetParam();
do {
font.OffsetForPosition(run, position, partial, breakopt);
timer.NextLap();
} while (!timer.HasTimeLimitExpired());
}
};
class CharacterRangePerfTest : public ShapeResultPerfTest,
public testing::TestWithParam<int> {
public:
void GetCharacter(TextRun& run) {
timer.Reset();
int endpos = GetParam();
do {
font.SelectionRectForText(run, FloatPoint(), 100, 0, endpos);
timer.NextLap();
} while (!timer.HasTimeLimitExpired());
}
};
TEST_P(OffsetForPositionPerfTest, LTROffsetForPositionFullBreak) {
TextRun run = SetupFont(ahem, "FURACOLO", true);
OffsetForPosition(run, OnlyFullGlyphs, BreakGlyphs);
perf_test::PrintResult("OffsetForPositionPerfTest", " LTR full break", "",
timer.LapsPerSecond(), "runs/s", true);
}
TEST_P(OffsetForPositionPerfTest, LTROffsetForPositionFullDontBreak) {
TextRun run = SetupFont(ahem, "FURACOLO", true);
OffsetForPosition(run, OnlyFullGlyphs, DontBreakGlyphs);
perf_test::PrintResult("OffsetForPositionPerfTest", " LTR full", "",
timer.LapsPerSecond(), "runs/s", true);
}
TEST_P(OffsetForPositionPerfTest, LTROffsetForPositionIncludePartialBreak) {
TextRun run = SetupFont(ahem, "FURACOLO", true);
OffsetForPosition(run, IncludePartialGlyphs, BreakGlyphs);
perf_test::PrintResult("OffsetForPositionPerfTest", " LTR partial break", "",
timer.LapsPerSecond(), "runs/s", true);
}
TEST_P(OffsetForPositionPerfTest, LTROffsetForPositionIncludePartialDontBreak) {
TextRun run = SetupFont(ahem, "FURACOLO", true);
OffsetForPosition(run, IncludePartialGlyphs, DontBreakGlyphs);
perf_test::PrintResult("OffsetForPositionPerfTest", " LTR partial", "",
timer.LapsPerSecond(), "runs/s", true);
}
TEST_P(OffsetForPositionPerfTest, RTLOffsetForPositionFullBreak) {
TextRun run = SetupFont(ahem, "OLOCARUF", false);
OffsetForPosition(run, OnlyFullGlyphs, BreakGlyphs);
perf_test::PrintResult("OffsetForPositionPerfTest", " RTL full break", "",
timer.LapsPerSecond(), "runs/s", true);
}
TEST_P(OffsetForPositionPerfTest, RTLOffsetForPositionFullDontBreak) {
TextRun run = SetupFont(ahem, "OLOCARUF", false);
OffsetForPosition(run, OnlyFullGlyphs, DontBreakGlyphs);
perf_test::PrintResult("OffsetForPositionPerfTest", " RTL full", "",
timer.LapsPerSecond(), "runs/s", true);
}
TEST_P(OffsetForPositionPerfTest, RTLOffsetForPositionIncludePartialBreak) {
TextRun run = SetupFont(ahem, "OLOCARUF", false);
OffsetForPosition(run, IncludePartialGlyphs, BreakGlyphs);
perf_test::PrintResult("OffsetForPositionPerfTest", " RTL partial break", "",
timer.LapsPerSecond(), "runs/s", true);
}
TEST_P(OffsetForPositionPerfTest, RTLOffsetForPositionIncludePartialDontBreak) {
TextRun run = SetupFont(ahem, "OLOCARUF", false);
OffsetForPosition(run, IncludePartialGlyphs, DontBreakGlyphs);
perf_test::PrintResult("OffsetForPositionPerfTest", " RTL partial", "",
timer.LapsPerSecond(), "runs/s", true);
}
INSTANTIATE_TEST_CASE_P(OffsetForPosition,
OffsetForPositionPerfTest,
testing::Values(0, 10, 60, 100, 200, 350));
TEST_P(CharacterRangePerfTest, LTRCharacterForPosition) {
TextRun run = SetupFont(ahem, "FURACOLO", true);
GetCharacter(run);
perf_test::PrintResult("CharacterRangePerfTest", " LTR", "",
timer.LapsPerSecond(), "runs/s", true);
}
TEST_P(CharacterRangePerfTest, RTLCharacterForPosition) {
TextRun run = SetupFont(ahem, "OLOCARUF", false);
GetCharacter(run);
perf_test::PrintResult("CharacterRangePerfTest", " RTL", "",
timer.LapsPerSecond(), "runs/s", true);
}
INSTANTIATE_TEST_CASE_P(CharacterRange,
CharacterRangePerfTest,
testing::Values(0, 1, 2, 4, 8));
} // namespace blink
|