Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 2a6fb346 authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Stop copying PrecomputedText buffer

PrecomputedText already has a copy of the text. No need to copy the
buffer.

android.text.StaticLayoutPerfTest:
  draw
    PrecomputedText NoStyle: 610 -> 616: (  +6, +1.0%)
    PrecomputedText Style  : 811 -> 831: ( +20, +2.5%)
    RandomText NoStyle     : 547 -> 544: (  -3, -0.5%)
    RandomText Style       : 730 -> 744: ( +14, +1.9%)

Bug: 72461923
Test: atest CtsWidgetTestCases:EditTextTest
    CtsWidgetTestCases:TextViewFadingEdgeTest
    FrameworksCoreTests:TextViewFallbackLineSpacingTest
    FrameworksCoreTests:TextViewTest FrameworksCoreTests:TypefaceTest
    CtsGraphicsTestCases:TypefaceTest CtsWidgetTestCases:TextViewTest
    CtsTextTestCases FrameworksCoreTests:android.text
    CtsWidgetTestCases:TextViewPrecomputedTextTest
Change-Id: I4b9d1c003f127a796d7d4f0d4aecfa7d016b89f6
parent 9f359cc2
Loading
Loading
Loading
Loading
+21 −10
Original line number Original line Diff line number Diff line
@@ -34,6 +34,7 @@ import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.RectF;
import android.graphics.TemporaryBuffer;
import android.graphics.TemporaryBuffer;
import android.text.GraphicsOperations;
import android.text.GraphicsOperations;
import android.text.MeasuredParagraph;
import android.text.PrecomputedText;
import android.text.PrecomputedText;
import android.text.SpannableString;
import android.text.SpannableString;
import android.text.SpannedString;
import android.text.SpannedString;
@@ -500,21 +501,31 @@ public class RecordingCanvas extends Canvas {
            ((GraphicsOperations) text).drawTextRun(this, start, end,
            ((GraphicsOperations) text).drawTextRun(this, start, end,
                    contextStart, contextEnd, x, y, isRtl, paint);
                    contextStart, contextEnd, x, y, isRtl, paint);
        } else {
        } else {
            int contextLen = contextEnd - contextStart;
            int len = end - start;
            char[] buf = TemporaryBuffer.obtain(contextLen);
            TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
            long measuredTextPtr = 0;
            if (text instanceof PrecomputedText) {
            if (text instanceof PrecomputedText) {
                PrecomputedText mt = (PrecomputedText) text;
                final PrecomputedText pt = (PrecomputedText) text;
                int paraIndex = mt.findParaIndex(start);
                final int paraIndex = pt.findParaIndex(start);
                if (end <= mt.getParagraphEnd(paraIndex)) {
                if (end <= pt.getParagraphEnd(paraIndex)) {
                    final int paraStart = pt.getParagraphStart(paraIndex);
                    final MeasuredParagraph mp = pt.getMeasuredParagraph(paraIndex);
                    // Only support if the target is in the same paragraph.
                    // Only support if the target is in the same paragraph.
                    measuredTextPtr = mt.getMeasuredParagraph(paraIndex).getNativePtr();
                    nDrawTextRun(mNativeCanvasWrapper,
                            mp.getChars(),
                            start - paraStart,
                            end - start,
                            contextStart - paraStart,
                            contextEnd - contextStart,
                            x, y, isRtl, paint.getNativeInstance(),
                            mp.getNativePtr());
                    return;
                }
                }
            }
            }
            int contextLen = contextEnd - contextStart;
            int len = end - start;
            char[] buf = TemporaryBuffer.obtain(contextLen);
            TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
            nDrawTextRun(mNativeCanvasWrapper, buf, start - contextStart, len,
            nDrawTextRun(mNativeCanvasWrapper, buf, start - contextStart, len,
                    0, contextLen, x, y, isRtl, paint.getNativeInstance(), measuredTextPtr);
                    0, contextLen, x, y, isRtl, paint.getNativeInstance(),
                    0 /* measured paragraph pointer */);
            TemporaryBuffer.recycle(buf);
            TemporaryBuffer.recycle(buf);
        }
        }
    }
    }
+21 −10
Original line number Original line Diff line number Diff line
@@ -22,6 +22,7 @@ import android.annotation.Nullable;
import android.annotation.Size;
import android.annotation.Size;
import android.graphics.Canvas.VertexMode;
import android.graphics.Canvas.VertexMode;
import android.text.GraphicsOperations;
import android.text.GraphicsOperations;
import android.text.MeasuredParagraph;
import android.text.PrecomputedText;
import android.text.PrecomputedText;
import android.text.SpannableString;
import android.text.SpannableString;
import android.text.SpannedString;
import android.text.SpannedString;
@@ -486,21 +487,31 @@ public abstract class BaseCanvas {
            ((GraphicsOperations) text).drawTextRun(this, start, end,
            ((GraphicsOperations) text).drawTextRun(this, start, end,
                    contextStart, contextEnd, x, y, isRtl, paint);
                    contextStart, contextEnd, x, y, isRtl, paint);
        } else {
        } else {
            if (text instanceof PrecomputedText) {
                final PrecomputedText pt = (PrecomputedText) text;
                final int paraIndex = pt.findParaIndex(start);
                if (end <= pt.getParagraphEnd(paraIndex)) {
                    final int paraStart = pt.getParagraphStart(paraIndex);
                    final MeasuredParagraph mp = pt.getMeasuredParagraph(paraIndex);
                    // Only support the text in the same paragraph.
                    nDrawTextRun(mNativeCanvasWrapper,
                            mp.getChars(),
                            start - paraStart,
                            end - start,
                            contextStart - paraStart,
                            contextEnd - contextStart,
                            x, y, isRtl, paint.getNativeInstance(),
                            mp.getNativePtr());
                    return;
                }
            }
            int contextLen = contextEnd - contextStart;
            int contextLen = contextEnd - contextStart;
            int len = end - start;
            int len = end - start;
            char[] buf = TemporaryBuffer.obtain(contextLen);
            char[] buf = TemporaryBuffer.obtain(contextLen);
            TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
            TextUtils.getChars(text, contextStart, contextEnd, buf, 0);
            long measuredTextPtr = 0;
            if (text instanceof PrecomputedText) {
                PrecomputedText mt = (PrecomputedText) text;
                int paraIndex = mt.findParaIndex(start);
                if (end <= mt.getParagraphEnd(paraIndex)) {
                    // Only suppor the text in the same paragraph.
                    measuredTextPtr = mt.getMeasuredParagraph(paraIndex).getNativePtr();
                }
            }
            nDrawTextRun(mNativeCanvasWrapper, buf, start - contextStart, len,
            nDrawTextRun(mNativeCanvasWrapper, buf, start - contextStart, len,
                    0, contextLen, x, y, isRtl, paint.getNativeInstance(), measuredTextPtr);
                    0, contextLen, x, y, isRtl, paint.getNativeInstance(),
                    0 /* measured paragraph pointer */);
            TemporaryBuffer.recycle(buf);
            TemporaryBuffer.recycle(buf);
        }
        }
    }
    }