diff options
author | Seigo Nonaka <nona@google.com> | 2018-01-11 16:32:22 -0800 |
---|---|---|
committer | Seigo Nonaka <nona@google.com> | 2018-01-16 18:08:37 -0800 |
commit | c9611626465f9e11817854f554e7b7d0c6cee905 (patch) | |
tree | e62df95a9cf531b6817779ef0c0306219b7d832a /include | |
parent | 366f57fb4efd0ddf5d48cd232cd88d3777517ea2 (diff) | |
download | minikin-c9611626465f9e11817854f554e7b7d0c6cee905.tar.gz |
Store hyphenated pieces in MeasuredText
Do hyphenation calculation at the same time of measuring character
widths. We can do the 93% of line break work beforehand.
Here is a raw performance score:
(walleye-userdebug, w/o patch -> w/ patch, N=30)
Measured Balanced Hyphenation : 11,428,287 -> 703,417 (-93.8%)
Measured Balanced NoHyphenation: 535,660 -> 536,210 (+0.1%)
Random Balanced Hyphenation : 18,903,251 -> 19,046,535 (+0.8%)
Random Balanced NoHyphenation : 7,973,160 -> 7,956,803 (-0.2%)
Measured Greedy Hyphenation : 486,633 -> 486,381 (-0.1%)
Measured Greedy NoHyphenation : 484,716 -> 490,018 (+1.1%)
Random Greedy Hyphenation : 7,966,823 -> 7,921,520 (-0.6%)
Random Greedy NoHyphenation : 7,918,480 -> 7,925,110 (+0.1%)
This CL also removes overhang member variable from MeasuredText since
this is no longer used in line breaker.
Bug: 67504091
Test: bit CtsTextTestCases:*
Test: bit CtsWidgetTestCases:android.widget.cts.TextViewTest
Test: minikin_tests
Change-Id: I94c65980bf1190c9351d50dc0c811a377fb93ee6
Diffstat (limited to 'include')
-rw-r--r-- | include/minikin/MeasuredText.h | 44 |
1 files changed, 33 insertions, 11 deletions
diff --git a/include/minikin/MeasuredText.h b/include/minikin/MeasuredText.h index 6937202..13f5fbb 100644 --- a/include/minikin/MeasuredText.h +++ b/include/minikin/MeasuredText.h @@ -125,12 +125,35 @@ private: const uint32_t mLocaleListId; }; +// Represents a hyphenation break point. +struct HyphenBreak { + // The break offset. + uint32_t offset; + + // The hyphenation type. + HyphenationType type; + + // The width of preceding piece after break at hyphenation point. + float first; + + // The width of following piece after break at hyphenation point. + float second; + + HyphenBreak(uint32_t offset, HyphenationType type, float first, float second) + : offset(offset), type(type), first(first), second(second) {} +}; + class MeasuredText { public: - // Following three vectors have the same length. + // Character widths. std::vector<float> widths; + + // Font vertical extents for characters. + // TODO: Introduce compression for extents. Usually, this has the same values for all chars. std::vector<MinikinExtent> extents; - std::vector<LayoutOverhang> overhangs; + + // Hyphenation points. + std::vector<HyphenBreak> hyphenBreaks; // The style information. std::vector<std::unique_ptr<Run>> runs; @@ -143,15 +166,13 @@ public: private: friend class MeasuredTextBuilder; - void measure(const U16StringPiece& textBuf); + void measure(const U16StringPiece& textBuf, bool computeHyphenation); // Use MeasuredTextBuilder instead. - MeasuredText(const U16StringPiece& textBuf, std::vector<std::unique_ptr<Run>>&& runs) - : widths(textBuf.size()), - extents(textBuf.size()), - overhangs(textBuf.size()), - runs(std::move(runs)) { - measure(textBuf); + MeasuredText(const U16StringPiece& textBuf, std::vector<std::unique_ptr<Run>>&& runs, + bool computeHyphenation) + : widths(textBuf.size()), extents(textBuf.size()), runs(std::move(runs)) { + measure(textBuf, computeHyphenation); } }; @@ -175,9 +196,10 @@ public: mRuns.emplace_back(std::make_unique<T>(std::forward<Args>(args)...)); } - std::unique_ptr<MeasuredText> build(const U16StringPiece& textBuf) { + std::unique_ptr<MeasuredText> build(const U16StringPiece& textBuf, bool computeHyphenation) { // Unable to use make_unique here since make_unique is not a friend of MeasuredText. - return std::unique_ptr<MeasuredText>(new MeasuredText(textBuf, std::move(mRuns))); + return std::unique_ptr<MeasuredText>( + new MeasuredText(textBuf, std::move(mRuns), computeHyphenation)); } PREVENT_COPY_ASSIGN_AND_MOVE(MeasuredTextBuilder); |