diff options
| author | Seigo Nonaka <nona@google.com> | 2018-02-01 21:39:24 -0800 |
|---|---|---|
| committer | Seigo Nonaka <nona@google.com> | 2018-02-12 20:50:41 -0800 |
| commit | 7fd36d19e309ea515b4048cfaabb8035ceab7baf (patch) | |
| tree | 30db8688e29ada27b365300ed08014a220464517 /core/java/android/text/Layout.java | |
| parent | d3905e654452c68390835e31fcb752884e57a67b (diff) | |
Reorganize MeasuredText API
This CL changes the MeasuredText API:
- Rename MeasuredText to PrecomputedText.
- PrecomputedText is no longer a Spanned.
- Introduce PrecomputedText.Param which holds all text layout parameters.
- Add API to get PrecomputedText.Param from TextView.
- Remove MeasuredText.Builder and add PrecomputedText.create method instead.
- Remove setRange from MeasuredText since it is not for normal use case.
(It can not be used for TextView)
Here is a performance scores: (median, walleye-userdebug, N=20)
StaticLayout creation time (w/o patch -> w/ patch)
PrecomputedText Balanced Hyphenation : 743,615 -> 737,145: (-0.9%)
PrecomputedText Balanced NoHyphenation: 551,544 -> 542,715: (-1.6%)
PrecomputedText Greedy Hyphenation : 500,343 -> 499,601: (-0.1%)
PrecomputedText Greedy NoHyphenation : 497,987 -> 492,587: (-1.1%)
RandomText Balanced Hyphenation : 19,100,592 -> 19,135,289: (+0.2%)
RandomText Balanced NoHyphenation : 8,015,088 -> 7,954,260: (-0.8%)
RandomText Greedy Hyphenation : 7,950,915 -> 7,877,424: (-0.9%)
RandomText Greedy NoHyphenation : 7,939,337 -> 7,863,471: (-1.0%)
PrecomputedText creation time (w/o patch -> w/ patch)
NoStyled Hyphenation : 18,935,638 -> 18,925,422: (-0.1%)
NoStyled Hyphenation WidthOnly : 18,469,726 -> 18,978,413: (+2.8%)
NoStyled NoHyphenation : 7,940,792 -> 7,919,127: (-0.3%)
NoStyled NoHyphenation WidthOnly : 7,463,230 -> 7,922,643: (+6.2%)
Styled Hyphenation : 14,822,501 -> 14,809,017: (-0.1%)
Styled Hyphenation WidthOnly : 13,891,770 -> 14,656,617: (+5.5%)
Styled NoHyphenation : 14,511,134 -> 14,301,503: (-1.4%)
Styled NoHyphenation WidthOnly : 13,495,345 -> 14,264,314: (+5.7%)
StaticLayout draw time (w/o patch -> w/ patch)
PrecomputedText NoStyled : 663,974 -> 661,610: (-0.4%)
PrecomputedText NoStyled WithoutCache : 648,294 -> 648,766: (+0.1%)
PrecomputedText Styled : 879,322 -> 852,770: (-3.0%)
PrecomputedText Styled WithoutCache : 1,084,570 -> 1,110,147: (+2.4%)
RandomText NoStyled : 565,682 -> 555,435: (-1.8%)
RandomText NoStyled WithoutCache : 9,070,533 -> 9,064,825: (-0.1%)
RandomText Styled : 2,955,202 -> 2,962,008: (+0.2%)
RandomText Styled WithoutCache : 12,242,325 -> 12,228,573: (-0.1%)
Bug: 67504091
Bug: 73091756
Test: bit FrameworksCoreTests:android.text.
Test: atest CtsWidgetTestCases:EditTextTest \
CtsWidgetTestCases:TextViewFadingEdgeTest \
FrameworksCoreTests:TextViewFallbackLineSpacingTest \
FrameworksCoreTests:TextViewTest FrameworksCoreTests:TypefaceTest \
CtsGraphicsTestCases:TypefaceTest CtsWidgetTestCases:TextViewTest \
CtsTextTestCases
Change-Id: I7db9e2ca4db68a16648cfb8fcf63555f501304c2
Diffstat (limited to 'core/java/android/text/Layout.java')
| -rw-r--r-- | core/java/android/text/Layout.java | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/core/java/android/text/Layout.java b/core/java/android/text/Layout.java index aa97b2aba749..d5d35904031c 100644 --- a/core/java/android/text/Layout.java +++ b/core/java/android/text/Layout.java @@ -245,6 +245,13 @@ public abstract class Layout { protected Layout(CharSequence text, TextPaint paint, int width, Alignment align, TextDirectionHeuristic textDir, float spacingMult, float spacingAdd) { + this(text, null /* precomputed */, paint, width, align, textDir, spacingMult, spacingAdd); + } + + /** @hide */ + protected Layout(CharSequence text, PrecomputedText precomputed, TextPaint paint, + int width, Alignment align, TextDirectionHeuristic textDir, + float spacingMult, float spacingAdd) { if (width < 0) throw new IllegalArgumentException("Layout: " + width + " < 0"); @@ -259,6 +266,7 @@ public abstract class Layout { } mText = text; + mPrecomputed = precomputed; mPaint = paint; mWidth = width; mAlignment = align; @@ -562,7 +570,7 @@ public abstract class Layout { // XXX: assumes there's nothing additional to be done canvas.drawText(buf, start, end, x, lbaseline, paint); } else { - tl.set(paint, buf, start, end, dir, directions, hasTab, tabStops); + tl.set(paint, buf, mPrecomputed, start, end, dir, directions, hasTab, tabStops); if (justify) { tl.justify(right - left - indentWidth); } @@ -2264,6 +2272,7 @@ public abstract class Layout { } private CharSequence mText; + private PrecomputedText mPrecomputed; private TextPaint mPaint; private TextPaint mWorkPaint = new TextPaint(); private int mWidth; |
