Skip to content

Commit a3552c5

Browse files
RusinoSkia Commit-Bot
authored andcommitted
Reland "SkParagraph"
This is a reland of 10ad0b9 Original change's description: > SkParagraph > > Change-Id: I0a4be75fd0c18021c201bcc1edfdfad8556edeff > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/192100 > Reviewed-by: Ben Wagner <bungeman@google.com> > Reviewed-by: Mike Reed <reed@google.com> > Commit-Queue: Julia Lavrova <jlavrova@google.com> Change-Id: I46cf43eae693edf68e45345acd0eb39e04e02bfc Reviewed-on: https://skia-review.googlesource.com/c/skia/+/219863 Reviewed-by: Herb Derby <herb@google.com> Commit-Queue: Julia Lavrova <jlavrova@google.com>
1 parent 2d170c3 commit a3552c5

39 files changed

+8791
-3
lines changed

BUILD.gn

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1691,6 +1691,7 @@ if (skia_enable_tools) {
16911691
":skvm_builders",
16921692
":tool_utils",
16931693
"modules/skottie:tests",
1694+
"modules/skparagraph:tests",
16941695
"modules/sksg:tests",
16951696
"modules/skshaper",
16961697
"//third_party/libpng",
@@ -1712,6 +1713,8 @@ if (skia_enable_tools) {
17121713
":skia",
17131714
":skvm_builders",
17141715
":tool_utils",
1716+
"modules/skshaper",
1717+
"modules/skparagraph:bench",
17151718
]
17161719
}
17171720

@@ -1815,6 +1818,7 @@ if (skia_enable_tools) {
18151818
":flags",
18161819
":gpu_tool_utils",
18171820
":xml",
1821+
"modules/skparagraph:samples",
18181822
"modules/sksg",
18191823
"modules/skshaper",
18201824
]
@@ -1923,6 +1927,8 @@ if (skia_enable_tools) {
19231927
":tool_utils",
19241928
":trace",
19251929
"modules/sksg",
1930+
"modules/skparagraph:bench",
1931+
"modules/skshaper",
19261932
]
19271933
}
19281934

bench/ParagraphBench.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2019 Google LLC.
2+
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.
3+
4+
#include "bench/Benchmark.h"
5+
6+
#if !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3)
7+
8+
#include "modules/skparagraph/include/Paragraph.h"
9+
#include "modules/skparagraph/src/ParagraphBuilderImpl.h"
10+
#include "modules/skparagraph/include/FontCollection.h"
11+
#include "modules/skparagraph/src/ParagraphImpl.h"
12+
#include "tools/Resources.h"
13+
14+
#include <cfloat>
15+
16+
using namespace skia::textlayout;
17+
namespace {
18+
struct ParagraphBench : public Benchmark {
19+
ParagraphBench(SkScalar width, const char* r, const char* n)
20+
: fResource(r), fName(n), fWidth(width) {}
21+
sk_sp<SkData> fData;
22+
const char* fResource;
23+
const char* fName;
24+
SkScalar fWidth;
25+
const char* onGetName() override { return fName; }
26+
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
27+
void onDelayedSetup() override { fData = GetResourceAsData(fResource); }
28+
void onDraw(int loops, SkCanvas*) override {
29+
if (!fData) {
30+
return;
31+
}
32+
33+
const char* text = (const char*)fData->data();
34+
35+
sk_sp<FontCollection> fontCollection = sk_make_sp<FontCollection>();
36+
ParagraphStyle paragraph_style;
37+
paragraph_style.turnHintingOff();
38+
ParagraphBuilderImpl builder(paragraph_style, fontCollection);
39+
builder.addText(text);
40+
auto paragraph = builder.Build();
41+
42+
while (loops-- > 0) {
43+
paragraph->layout(fWidth);
44+
auto impl = static_cast<ParagraphImpl*>(paragraph.get());
45+
impl->formatLines(fWidth);
46+
}
47+
}
48+
};
49+
} // namespace
50+
51+
#define PARAGRAPH_BENCH(X) DEF_BENCH(return new ParagraphBench(500, "text/" #X ".txt", "paragraph_" #X);)
52+
//PARAGRAPH_BENCH(arabic)
53+
//PARAGRAPH_BENCH(emoji)
54+
PARAGRAPH_BENCH(english)
55+
#undef PARAGRAPH_BENCH
56+
57+
#endif // !defined(SK_BUILD_FOR_ANDROID_FRAMEWORK) && !defined(SK_BUILD_FOR_GOOGLE3)

gn/bench.gni

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ bench_sources = [
104104
"$_bench/ScalarBench.cpp",
105105
"$_bench/ShaderMaskFilterBench.cpp",
106106
"$_bench/ShadowBench.cpp",
107-
"$_bench/ShaperBench.cpp",
108107
"$_bench/ShapesBench.cpp",
109108
"$_bench/Sk4fBench.cpp",
110109
"$_bench/SkGlyphCacheBench.cpp",
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
1
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2017 Google Inc.
4+
#
5+
# Use of this source code is governed by a BSD-style license that can be
6+
# found in the LICENSE file.
7+
8+
9+
"""Common vars used by scripts in this directory."""
10+
11+
12+
import os
13+
import sys
14+
15+
FILE_DIR = os.path.dirname(os.path.abspath(__file__))
16+
INFRA_BOTS_DIR = os.path.realpath(os.path.join(FILE_DIR, os.pardir, os.pardir))
17+
18+
sys.path.insert(0, INFRA_BOTS_DIR)
19+
from assets import assets
20+
21+
ASSET_NAME = os.path.basename(FILE_DIR)
22+
23+
24+
def run(cmd):
25+
"""Run a command, eg. "upload" or "download". """
26+
assets.main([cmd, ASSET_NAME] + sys.argv[1:])
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2017 Google Inc.
4+
#
5+
# Use of this source code is governed by a BSD-style license that can be
6+
# found in the LICENSE file.
7+
8+
9+
"""Download the current version of the asset."""
10+
11+
12+
import common
13+
14+
15+
if __name__ == '__main__':
16+
common.run('download')
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
#
3+
# Copyright 2017 Google Inc.
4+
#
5+
# Use of this source code is governed by a BSD-style license that can be
6+
# found in the LICENSE file.
7+
8+
9+
"""Upload a new version of the asset."""
10+
11+
12+
import common
13+
14+
15+
if __name__ == '__main__':
16+
common.run('upload')

modules/skottie/BUILD.gn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ if (skia_enable_skottie) {
3939

4040
public_configs = [ ":utils_config" ]
4141
configs += [ "../../:skia_private" ]
42+
4243
sources = [
43-
"utils/SkottieUtils.cpp",
44+
"utils/SkottieUtils.cpp",
4445
]
4546
deps = [
4647
":skottie",

modules/skparagraph/BUILD.gn

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Copyright 2019 Google LLC.
2+
3+
import("../../gn/skia.gni")
4+
5+
declare_args() {
6+
skia_enable_skparagraph = !(is_win && is_component_build)
7+
paragraph_tests_enabled = true
8+
paragraph_bench_enabled = false
9+
}
10+
11+
if (skia_enable_skparagraph) {
12+
13+
config("public_config") {
14+
include_dirs = [ "include" ]
15+
}
16+
17+
component("skparagraph") {
18+
import("skparagraph.gni")
19+
public_configs = [ ":public_config" ]
20+
public = skparagraph_public
21+
if (skia_use_icu && skia_use_harfbuzz) {
22+
sources = skparagraph_sources
23+
} else {
24+
sources = []
25+
}
26+
deps = [
27+
"../..:skia",
28+
"../skshaper",
29+
"//third_party/icu",
30+
]
31+
}
32+
33+
if (defined(is_skia_standalone) && skia_enable_tools) {
34+
source_set("tests") {
35+
if (skia_use_icu && skia_use_harfbuzz && paragraph_tests_enabled) {
36+
testonly = true
37+
sources = [
38+
"//tests/SkParagraphTest.cpp"
39+
]
40+
deps = [
41+
"../..:skia",
42+
"../..:gpu_tool_utils",
43+
":skparagraph",
44+
"../skshaper",
45+
"//third_party/icu",
46+
]
47+
}
48+
}
49+
50+
source_set("bench") {
51+
if (skia_use_icu && skia_use_harfbuzz && paragraph_bench_enabled) {
52+
testonly = true
53+
sources = [
54+
"//bench/ParagraphBench.cpp"
55+
]
56+
deps = [
57+
"../..:skia",
58+
":skparagraph",
59+
"../skshaper",
60+
"//third_party/icu",
61+
]
62+
}
63+
}
64+
65+
source_set("samples") {
66+
if (skia_use_icu && skia_use_harfbuzz) {
67+
testonly = true
68+
sources = [
69+
"//samplecode/SampleParagraph.cpp",
70+
]
71+
deps = [
72+
"../..:skia",
73+
":skparagraph",
74+
"../skshaper",
75+
"//third_party/icu",
76+
]
77+
}
78+
}
79+
}
80+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
// Copyright 2019 Google LLC.
2+
3+
#ifndef DartTypes_DEFINED
4+
#define DartTypes_DEFINED
5+
6+
#include "include/core/SkRect.h"
7+
8+
namespace skia {
9+
namespace textlayout {
10+
11+
enum Affinity { kUpstream, kDownstream };
12+
13+
enum class RectHeightStyle {
14+
// Provide tight bounding boxes that fit heights per run.
15+
kTight,
16+
17+
// The height of the boxes will be the maximum height of all runs in the
18+
// line. All rects in the same line will be the same height.
19+
kMax,
20+
21+
// Extends the top and/or bottom edge of the bounds to fully cover any line
22+
// spacing. The top edge of each line should be the same as the bottom edge
23+
// of the line above. There should be no gaps in vertical coverage given any
24+
// ParagraphStyle line_height.
25+
//
26+
// The top and bottom of each rect will cover half of the
27+
// space above and half of the space below the line.
28+
kIncludeLineSpacingMiddle,
29+
// The line spacing will be added to the top of the rect.
30+
kIncludeLineSpacingTop,
31+
// The line spacing will be added to the bottom of the rect.
32+
kIncludeLineSpacingBottom
33+
};
34+
35+
enum class RectWidthStyle {
36+
// Provide tight bounding boxes that fit widths to the runs of each line
37+
// independently.
38+
kTight,
39+
40+
// Extends the width of the last rect of each line to match the position of
41+
// the widest rect over all the lines.
42+
kMax
43+
};
44+
45+
enum class TextAlign {
46+
kLeft,
47+
kRight,
48+
kCenter,
49+
kJustify,
50+
kStart,
51+
kEnd,
52+
};
53+
54+
enum class TextDirection {
55+
kRtl,
56+
kLtr,
57+
};
58+
59+
struct PositionWithAffinity {
60+
int32_t position;
61+
Affinity affinity;
62+
63+
PositionWithAffinity(int32_t p, Affinity a) : position(p), affinity(a) {}
64+
};
65+
66+
struct TextBox {
67+
SkRect rect;
68+
TextDirection direction;
69+
70+
TextBox(SkRect r, TextDirection d) : rect(r), direction(d) {}
71+
};
72+
73+
template <typename T> struct SkRange {
74+
SkRange() : start(), end() {}
75+
SkRange(T s, T e) : start(s), end(e) {}
76+
77+
T start, end;
78+
79+
bool operator==(const SkRange<T>& other) const {
80+
return start == other.start && end == other.end;
81+
}
82+
83+
T width() { return end - start; }
84+
85+
void Shift(T delta) {
86+
start += delta;
87+
end += delta;
88+
}
89+
};
90+
91+
enum class TextBaseline {
92+
kAlphabetic,
93+
kIdeographic,
94+
};
95+
} // namespace textlayout
96+
} // namespace skia
97+
98+
#endif // DartTypes_DEFINED

0 commit comments

Comments
 (0)