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/TextLine.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/TextLine.java')
| -rw-r--r-- | core/java/android/text/TextLine.java | 42 |
1 files changed, 28 insertions, 14 deletions
diff --git a/core/java/android/text/TextLine.java b/core/java/android/text/TextLine.java index 55367dcce47e..be5bb4d1809a 100644 --- a/core/java/android/text/TextLine.java +++ b/core/java/android/text/TextLine.java @@ -16,6 +16,7 @@ package android.text; +import android.annotation.IntRange; import android.annotation.NonNull; import android.annotation.Nullable; import android.graphics.Canvas; @@ -60,7 +61,7 @@ public class TextLine { private char[] mChars; private boolean mCharsValid; private Spanned mSpanned; - private MeasuredText mMeasured; + private PrecomputedText mComputed; // Additional width of whitespace for justification. This value is per whitespace, thus // the line width will increase by mAddedWidth x (number of stretchable whitespaces). @@ -119,7 +120,7 @@ public class TextLine { tl.mSpanned = null; tl.mTabs = null; tl.mChars = null; - tl.mMeasured = null; + tl.mComputed = null; tl.mMetricAffectingSpanSpanSet.recycle(); tl.mCharacterStyleSpanSet.recycle(); @@ -149,10 +150,31 @@ public class TextLine { * @param tabStops the tabStops. Can be null. */ @VisibleForTesting(visibility = VisibleForTesting.Visibility.PACKAGE) - public void set(TextPaint paint, CharSequence text, int start, int limit, int dir, - Directions directions, boolean hasTabs, TabStops tabStops) { + public void set(TextPaint paint, CharSequence text, int start, + int limit, int dir, Directions directions, boolean hasTabs, TabStops tabStops) { + set(paint, text, null, start, limit, dir, directions, hasTabs, tabStops); + } + + /** + * Initializes a TextLine and prepares it for use. + * + * @param paint the base paint for the line + * @param text the text, can be Styled + * @param precomputed the precomputed text + * @param start the start of the line relative to the text + * @param limit the limit of the line relative to the text + * @param dir the paragraph direction of this line + * @param directions the directions information of this line + * @param hasTabs true if the line might contain tabs + * @param tabStops the tabStops. + */ + public void set(@NonNull TextPaint paint, @NonNull CharSequence text, + @Nullable PrecomputedText precomputed, @IntRange(from = 0) int start, + @IntRange(from = 0) int limit, int dir, @NonNull Directions directions, boolean hasTabs, + @Nullable TabStops tabStops) { mPaint = paint; mText = text; + mComputed = precomputed; mStart = start; mLen = limit - start; mDir = dir; @@ -170,14 +192,6 @@ public class TextLine { hasReplacement = mReplacementSpanSpanSet.numberOfSpans > 0; } - mMeasured = null; - if (text instanceof MeasuredText) { - MeasuredText mt = (MeasuredText) text; - if (mt.canUseMeasuredResult(paint)) { - mMeasured = mt; - } - } - mCharsValid = hasReplacement || hasTabs || directions != Layout.DIRS_ALL_LEFT_TO_RIGHT; if (mCharsValid) { @@ -746,12 +760,12 @@ public class TextLine { return wp.getRunAdvance(mChars, start, end, contextStart, contextEnd, runIsRtl, offset); } else { final int delta = mStart; - if (mMeasured == null) { + if (mComputed == null) { // TODO: Enable measured getRunAdvance for ReplacementSpan and RTL text. return wp.getRunAdvance(mText, delta + start, delta + end, delta + contextStart, delta + contextEnd, runIsRtl, delta + offset); } else { - return mMeasured.getWidth(start + delta, end + delta); + return mComputed.getWidth(start + delta, end + delta); } } } |
