From c9611626465f9e11817854f554e7b7d0c6cee905 Mon Sep 17 00:00:00 2001 From: Seigo Nonaka Date: Thu, 11 Jan 2018 16:32:22 -0800 Subject: 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 --- include/minikin/MeasuredText.h | 44 +++++++++++++++++++++++++++++++----------- 1 file changed, 33 insertions(+), 11 deletions(-) (limited to 'include') 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 widths; + + // Font vertical extents for characters. + // TODO: Introduce compression for extents. Usually, this has the same values for all chars. std::vector extents; - std::vector overhangs; + + // Hyphenation points. + std::vector hyphenBreaks; // The style information. std::vector> 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>&& runs) - : widths(textBuf.size()), - extents(textBuf.size()), - overhangs(textBuf.size()), - runs(std::move(runs)) { - measure(textBuf); + MeasuredText(const U16StringPiece& textBuf, std::vector>&& 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(std::forward(args)...)); } - std::unique_ptr build(const U16StringPiece& textBuf) { + std::unique_ptr 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(new MeasuredText(textBuf, std::move(mRuns))); + return std::unique_ptr( + new MeasuredText(textBuf, std::move(mRuns), computeHyphenation)); } PREVENT_COPY_ASSIGN_AND_MOVE(MeasuredTextBuilder); -- cgit v1.2.3