Commit fdf2d5ef authored by Emil A Eklund's avatar Emil A Eklund Committed by Commit Bot

Add perf test for ShapingLineBreaker

Add a new performance test for line breaking using ShapingLineBreaker to
allow us to catch/detect performance regressions and track progressions.

Test: Source/platform/testing/ShapingLineBreakerPerfTest.cpp
Change-Id: If95c2d3b3f2279219f3d883f0015a3d1de5eaa2a
Reviewed-on: https://chromium-review.googlesource.com/729560
Commit-Queue: Emil A Eklund <eae@chromium.org>
Reviewed-by: default avatarWalter Korman <wkorman@chromium.org>
Reviewed-by: default avatarKoji Ishii <kojii@chromium.org>
Cr-Commit-Position: refs/heads/master@{#513237}
parent 52366264
...@@ -1683,6 +1683,7 @@ jumbo_static_library("test_support") { ...@@ -1683,6 +1683,7 @@ jumbo_static_library("test_support") {
"//components/viz/test:test_support", "//components/viz/test:test_support",
"//testing/gmock", "//testing/gmock",
"//testing/gtest:gtest", "//testing/gtest:gtest",
"//testing/perf",
] ]
deps = [ deps = [
...@@ -1959,6 +1960,7 @@ test("blink_platform_perftests") { ...@@ -1959,6 +1960,7 @@ test("blink_platform_perftests") {
"testing/BlinkPerfTestSuite.cpp", "testing/BlinkPerfTestSuite.cpp",
"testing/BlinkPerfTestSuite.h", "testing/BlinkPerfTestSuite.h",
"testing/RunAllPerfTests.cpp", "testing/RunAllPerfTests.cpp",
"testing/ShapingLineBreakerPerfTest.cpp",
] ]
configs += [ configs += [
...@@ -1975,6 +1977,7 @@ test("blink_platform_perftests") { ...@@ -1975,6 +1977,7 @@ test("blink_platform_perftests") {
"//base/test:test_support", "//base/test:test_support",
"//testing/gtest", "//testing/gtest",
"//testing/perf", "//testing/perf",
"//third_party:freetype_harfbuzz",
"//third_party/WebKit/Source/platform/scheduler:perf_tests", "//third_party/WebKit/Source/platform/scheduler:perf_tests",
] ]
} }
......
...@@ -14,4 +14,5 @@ include_rules = [ ...@@ -14,4 +14,5 @@ include_rules = [
"+cc", "+cc",
"+components/viz/test", "+components/viz/test",
"+mojo/edk/embedder", "+mojo/edk/embedder",
'+testing',
] ]
// Copyright 2017 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 "platform/fonts/shaping/ShapingLineBreaker.h"
#include <unicode/uscript.h>
#include "base/time/time.h"
#include "cc/base/lap_timer.h"
#include "platform/fonts/Font.h"
#include "platform/fonts/FontCache.h"
#include "platform/fonts/FontTestUtilities.h"
#include "platform/fonts/shaping/ShapeResultInlineHeaders.h"
#include "platform/fonts/shaping/ShapeResultTestInfo.h"
#include "platform/text/TextBreakIterator.h"
#include "platform/text/TextRun.h"
#include "platform/wtf/Vector.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/perf/perf_test.h"
namespace blink {
namespace {
static const int kTimeLimitMillis = 2000;
static const int kWarmupRuns = 5;
static const int kTimeCheckInterval = 10;
LayoutUnit ShapeText(ShapingLineBreaker* breaker,
LayoutUnit available_space,
unsigned string_length) {
unsigned break_offset = 0;
LayoutUnit total_width;
ShapingLineBreaker::Result result;
RefPtr<ShapeResult> shape_result;
while (break_offset < string_length) {
shape_result = breaker->ShapeLine(break_offset, available_space, &result);
break_offset = result.break_offset;
total_width += shape_result->SnappedWidth();
}
return total_width;
}
} // anonymous namespace
class ShapingLineBreakerPerfTest : public ::testing::Test {
public:
ShapingLineBreakerPerfTest()
: timer_(kWarmupRuns,
base::TimeDelta::FromMilliseconds(kTimeLimitMillis),
kTimeCheckInterval) {}
void SetUp() override {
font_description.SetComputedSize(12.0);
font = Font(font_description);
font.Update(nullptr);
}
void TearDown() override {}
FontCachePurgePreventer font_cache_purge_preventer;
FontDescription font_description;
Font font;
unsigned start_index = 0;
unsigned num_glyphs = 0;
hb_script_t script = HB_SCRIPT_INVALID;
cc::LapTimer timer_;
};
TEST_F(ShapingLineBreakerPerfTest, ShapeLatinText) {
// "My Brother's Keeper?"
// By William Arthur Dunkerley (John Oxenham)
// In the public domain.
String string(
u"\"Am I my brother's keeper?\""
"Yes, of a truth!"
"Thine asking is thine answer."
"That self-condemning cry of Cain"
"Has been the plea of every selfish soul since then,"
"Which hath its brother slain."
"God's word is plain,"
"And doth thy shrinking soul arraign."
""
"Thy brother's keeper?"
"Yea, of a truth thou art!"
"For if not--who?"
"Are ye not both,--both thou and he"
"Of God's great family?"
"How rid thee of thy soul's responsibility?"
"For every ill in all the world"
"Each soul is sponsor and account must bear."
"And He, and he thy brother of despair,"
"Claim, of thy overmuch, their share."
""
"Thou hast had good, and he the strangled days;"
"But now,--the old things pass."
"No longer of thy grace"
"Is he content to live in evil case"
"For the anointing of thy shining face."
"The old things pass.--Beware lest ye pass with them,"
"And your place"
"Become an emptiness!"
""
"Beware! Lest, when the \"Have-nots\" claim,"
"From those who have, their rightful share,"
"Thy borders be swept bare"
"As by the final flame."
"Better to share before than after."
"\"After?\" ... For thee may be no after!"
"Only the howl of mocking laughter"
"At thy belated care. Make no mistake!--"
"\"After\" will be too late."
"When once the \"Have-nots\" claim ... they take."
"\"After!\" ... When that full claim is made,"
"You and your golden gods may all lie dead."
""
"Set now your house in order,"
"Ere it be too late!"
"For, once the storm of hate"
"Be loosed, no man shall stay it till"
"Its thirst has slaked its fill,"
"And you, poor victims of this last \"too late,\""
"Shall in the shadows mourn your lost estate.");
unsigned len = string.length();
LazyLineBreakIterator break_iterator(string, "en-US", LineBreakType::kNormal);
TextDirection direction = TextDirection::kLtr;
HarfBuzzShaper shaper(string.Characters16(), len);
RefPtr<ShapeResult> result = shaper.Shape(&font, direction);
ShapingLineBreaker breaker(&shaper, &font, result.get(), &break_iterator);
RefPtr<ShapeResult> line;
LayoutUnit available_width_px(500);
LayoutUnit expected_width = ShapeText(&breaker, available_width_px, len);
timer_.Reset();
do {
LayoutUnit width = ShapeText(&breaker, available_width_px, len);
EXPECT_EQ(expected_width, width);
timer_.NextLap();
} while (!timer_.HasTimeLimitExpired());
perf_test::PrintResult("ShapingLineBreakerPerfTest", "shape latin text", "",
timer_.LapsPerSecond(), "runs/s", true);
}
} // namespace blink
Amiri is a classical Arabic typeface in Naskh style for typesetting books and other running text. Its design is a revival of the beautiful typeface pioneered in early 20th century by Bulaq Press in Cairo, also known as Amiria Press, after which the font is named.
Read more about the project at www.amirifont.org
Updated in July 2017 to v0.109
SIL OPEN FONT LICENSE
Version 1.1 - 26 February 2007
PREAMBLE
The goals of the Open Font License (OFL) are to stimulate worldwide
development of collaborative font projects, to support the font creation
efforts of academic and linguistic communities, and to provide a free and
open framework in which fonts may be shared and improved in partnership
with others.
The OFL allows the licensed fonts to be used, studied, modified and
redistributed freely as long as they are not sold by themselves. The
fonts, including any derivative works, can be bundled, embedded,
redistributed and/or sold with any software provided that any reserved
names are not used by derivative works. The fonts and derivatives,
however, cannot be released under any other type of license. The
requirement for fonts to remain under this license does not apply
to any document created using the fonts or their derivatives.
DEFINITIONS
"Font Software" refers to the set of files released by the Copyright
Holder(s) under this license and clearly marked as such. This may
include source files, build scripts and documentation.
"Reserved Font Name" refers to any names specified as such after the
copyright statement(s).
"Original Version" refers to the collection of Font Software components as
distributed by the Copyright Holder(s).
"Modified Version" refers to any derivative made by adding to, deleting,
or substituting — in part or in whole — any of the components of the
Original Version, by changing formats or by porting the Font Software to a
new environment.
"Author" refers to any designer, engineer, programmer, technical
writer or other person who contributed to the Font Software.
PERMISSION & CONDITIONS
Permission is hereby granted, free of charge, to any person obtaining
a copy of the Font Software, to use, study, copy, merge, embed, modify,
redistribute, and sell modified and unmodified copies of the Font
Software, subject to the following conditions:
1) Neither the Font Software nor any of its individual components,
in Original or Modified Versions, may be sold by itself.
2) Original or Modified Versions of the Font Software may be bundled,
redistributed and/or sold with any software, provided that each copy
contains the above copyright notice and this license. These can be
included either as stand-alone text files, human-readable headers or
in the appropriate machine-readable metadata fields within text or
binary files as long as those fields can be easily viewed by the user.
3) No Modified Version of the Font Software may use the Reserved Font
Name(s) unless explicit written permission is granted by the corresponding
Copyright Holder. This restriction only applies to the primary font name as
presented to the users.
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font
Software shall not be used to promote, endorse or advertise any
Modified Version, except to acknowledge the contribution(s) of the
Copyright Holder(s) and the Author(s) or with their explicit written
permission.
5) The Font Software, modified or unmodified, in part or in whole,
must be distributed entirely under this license, and must not be
distributed under any other license. The requirement for fonts to
remain under this license does not apply to any document created
using the Font Software.
TERMINATION
This license becomes null and void if any of the above conditions are
not met.
DISCLAIMER
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE
COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
OTHER DEALINGS IN THE FONT SOFTWARE.
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment