summaryrefslogtreecommitdiff
path: root/apct-tests
diff options
context:
space:
mode:
authorSeigo Nonaka <nona@google.com>2018-10-19 19:10:02 -0700
committerSeigo Nonaka <nona@google.com>2018-10-26 10:31:33 -0700
commitf307adc83eaa33a9fdf5e58f4134c4ff3a500deb (patch)
tree26e6b85c0b46462f742c8236b8015ad3fd15191c /apct-tests
parentffe3226069984e6c8e3f7bf08941d74c2afd3fdc (diff)
Do not pass context to minikin in case of Canvas.drawText
Canvas.drawText don't use context info, just draw the given slice of text. By this change the performance for the long text gets back. android.text.CanvasDrawTextTest drawText_LongText_SmallWindow : 94,526 us -> 11,268 us Bug: 111638688 Test: atest CanvasDrawTextTest Change-Id: I69f8cbf4ff361d213f5d041148dbcc41ebd16c84
Diffstat (limited to 'apct-tests')
-rw-r--r--apct-tests/perftests/core/src/android/text/CanvasDrawTextTest.java70
-rw-r--r--apct-tests/perftests/core/src/android/text/TextPerfUtils.java13
2 files changed, 79 insertions, 4 deletions
diff --git a/apct-tests/perftests/core/src/android/text/CanvasDrawTextTest.java b/apct-tests/perftests/core/src/android/text/CanvasDrawTextTest.java
new file mode 100644
index 000000000000..ad9fb5f5e99f
--- /dev/null
+++ b/apct-tests/perftests/core/src/android/text/CanvasDrawTextTest.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package android.text;
+
+import android.graphics.RecordingCanvas;
+import android.graphics.RenderNode;
+import android.perftests.utils.BenchmarkState;
+import android.perftests.utils.PerfStatusReporter;
+import android.support.test.filters.LargeTest;
+import android.support.test.runner.AndroidJUnit4;
+
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Random;
+
+@LargeTest
+@RunWith(AndroidJUnit4.class)
+public class CanvasDrawTextTest {
+ private static final int WORD_LENGTH = 9; // Random word has 9 characters.
+
+ private static final TextPaint PAINT = new TextPaint();
+
+ @Rule
+ public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter();
+
+ private TextPerfUtils mTextUtil = new TextPerfUtils();
+
+ @Before
+ public void setUp() {
+ mTextUtil.resetRandom(0 /* seed */);
+ }
+
+ @Test
+ public void drawText_LongText_SmallWindow() {
+ final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
+ final String text = mTextUtil.nextRandomParagraph(
+ WORD_LENGTH, 4 * 1024 * 1024 /* 4mb text */).toString();
+ final RenderNode node = RenderNode.create("benchmark", null);
+ final RenderNode child = RenderNode.create("child", null);
+ child.setLeftTopRightBottom(50, 50, 100, 100);
+
+ RecordingCanvas canvas = node.start(100, 100);
+ node.end(canvas);
+ canvas = child.start(50, 50);
+ child.end(canvas);
+
+ final Random r = new Random(0);
+
+ while (state.keepRunning()) {
+ int start = r.nextInt(text.length() - 100);
+ canvas.drawText(text, start, start + 100, 0, 0, PAINT);
+ }
+ }
+}
diff --git a/apct-tests/perftests/core/src/android/text/TextPerfUtils.java b/apct-tests/perftests/core/src/android/text/TextPerfUtils.java
index 22e516abe926..2a98ebf2c58d 100644
--- a/apct-tests/perftests/core/src/android/text/TextPerfUtils.java
+++ b/apct-tests/perftests/core/src/android/text/TextPerfUtils.java
@@ -65,18 +65,23 @@ public class TextPerfUtils {
}
public CharSequence nextRandomParagraph(int wordLen, boolean applyRandomStyle, String setStr) {
- return nextRandomParagraph(wordLen, applyRandomStyle, UnicodeSetToArray(setStr));
+ return nextRandomParagraph(wordLen, PARA_LENGTH, applyRandomStyle,
+ UnicodeSetToArray(setStr));
}
public CharSequence nextRandomParagraph(int wordLen, boolean applyRandomStyle) {
- return nextRandomParagraph(wordLen, applyRandomStyle, ALPHABET);
+ return nextRandomParagraph(wordLen, PARA_LENGTH, applyRandomStyle, ALPHABET);
}
- public CharSequence nextRandomParagraph(int wordLen, boolean applyRandomStyle,
+ public CharSequence nextRandomParagraph(int wordLen, int paraLength) {
+ return nextRandomParagraph(wordLen, paraLength, false /* no style */, ALPHABET);
+ }
+
+ public CharSequence nextRandomParagraph(int wordLen, int paraLength, boolean applyRandomStyle,
String[] charSet) {
ArrayList<Character> chars = new ArrayList<>();
ArrayList<Integer> wordOffsets = new ArrayList<>();
- for (int i = 0; i < PARA_LENGTH; i++) {
+ for (int i = 0; i < paraLength; i++) {
if (i % (wordLen + 1) == wordLen) {
chars.add(' ');
wordOffsets.add(chars.size());