diff options
| author | Seigo Nonaka <nona@google.com> | 2018-11-16 10:41:32 -0800 |
|---|---|---|
| committer | Seigo Nonaka <nona@google.com> | 2018-12-10 16:18:02 -0800 |
| commit | 291ef0536d2ed154f5c559dbcdbfc92b10a21e66 (patch) | |
| tree | 0ea279c1774d2f8e0e22f18319da9f36064714a8 /core/java/android/widget/TextView.java | |
| parent | c70a74e1a740a67ad98702b08e06dba572ca7289 (diff) | |
Recompute PcT with existing PcT for different direction
The text direction can not be fully determined in detached state.
To improve even in that case, compute PrecomputedText from existing
PrecomputedText with new direction.
Here is the performance difference. According to the perf test result,
up to 80% of computation can be recycled from existing PrecomputedText.
android.text.StaticLayoutPerfTest (u sec):
PrecomputedText Greedy NoHyphenation : 371 -> 371: ( +0, +0.0%)
PrecomputedText Greedy NoHyphenation DirDifferent: 6,923 -> 1,437: (-5486, -79.2%)
RandomText Greedy NoHyphenation : 6,633 -> 6,627: ( -6, -0.1%)
On the other hand, this CL increase the memory usage of the
PrecomputedText up to 10%. Here is an reference memory usage.
android.text.PrecomputedTextMemoryUsageTest (bytes):
MemoryUsage
Arabic Hyphenation : 17,135 -> 18,116: ( +981, +5.7%)
Arabic NoHyphenation : 17,135 -> 18,116: ( +981, +5.7%)
CJK Hyphenation : 29,000 -> 31,584: (+2584, +8.9%)
CJK NoHyphenation : 29,000 -> 31,584: (+2584, +8.9%)
Latin Hyphenation : 16,526 -> 17,185: ( +659, +4.0%)
Latin NoHyphenation : 14,200 -> 14,784: ( +584, +4.1%)
Bug: 119312268
Test: atest CtsWidgetTestCases
Test: atest CtsTextTestCases
Test: atest CtsGraphicsTestCases
Test: minikin_tests
Change-Id: Ia02c201afac5d7d1c086a45f15696f39a6b2a76c
Diffstat (limited to 'core/java/android/widget/TextView.java')
| -rw-r--r-- | core/java/android/widget/TextView.java | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 2a4223201af1..a9735959d588 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -6028,14 +6028,22 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener if (mTextDir == null) { mTextDir = getTextDirectionHeuristic(); } - if (!precomputed.getParams().isSameTextMetricsInternal( - getPaint(), mTextDir, mBreakStrategy, mHyphenationFrequency)) { - throw new IllegalArgumentException( + final @PrecomputedText.Params.CheckResultUsableResult int checkResult = + precomputed.getParams().checkResultUsable(getPaint(), mTextDir, mBreakStrategy, + mHyphenationFrequency); + switch (checkResult) { + case PrecomputedText.Params.UNUSABLE: + throw new IllegalArgumentException( "PrecomputedText's Parameters don't match the parameters of this TextView." + "Consider using setTextMetricsParams(precomputedText.getParams()) " + "to override the settings of this TextView: " + "PrecomputedText: " + precomputed.getParams() + "TextView: " + getTextMetricsParams()); + case PrecomputedText.Params.NEED_RECOMPUTE: + precomputed = PrecomputedText.create(precomputed, getTextMetricsParams()); + break; + case PrecomputedText.Params.USABLE: + // pass through } } else if (type == BufferType.SPANNABLE || mMovement != null) { text = mSpannableFactory.newSpannable(text); |
