summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--apct-tests/perftests/core/src/android/text/CanvasDrawTextTest.java70
-rw-r--r--apct-tests/perftests/core/src/android/text/TextPerfUtils.java13
-rw-r--r--core/jni/android_graphics_Canvas.cpp15
3 files changed, 88 insertions, 10 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());
diff --git a/core/jni/android_graphics_Canvas.cpp b/core/jni/android_graphics_Canvas.cpp
index dca2da369540..84f53468e941 100644
--- a/core/jni/android_graphics_Canvas.cpp
+++ b/core/jni/android_graphics_Canvas.cpp
@@ -523,10 +523,11 @@ static void drawTextChars(JNIEnv* env, jobject, jlong canvasHandle, jcharArray c
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
const Typeface* typeface = paint->getAndroidTypeface();
ScopedCharArrayRO text(env, charArray);
+ // drawTextString and drawTextChars doesn't use context info
get_canvas(canvasHandle)->drawText(
- text.get(), text.size(), // text buffer
- index, count, // draw range
- 0, text.size(), // context range
+ text.get() + index, count, // text buffer
+ 0, count, // draw range
+ 0, count, // context range
x, y, // draw position
static_cast<minikin::Bidi>(bidiFlags), *paint, typeface, nullptr /* measured text */);
}
@@ -537,10 +538,12 @@ static void drawTextString(JNIEnv* env, jobject, jlong canvasHandle, jstring str
ScopedStringChars text(env, strObj);
Paint* paint = reinterpret_cast<Paint*>(paintHandle);
const Typeface* typeface = paint->getAndroidTypeface();
+ const int count = end - start;
+ // drawTextString and drawTextChars doesn't use context info
get_canvas(canvasHandle)->drawText(
- text.get(), text.size(), // text buffer
- start, end - start, // draw range
- 0, text.size(), // context range
+ text.get() + start, count, // text buffer
+ 0, count, // draw range
+ 0, count, // context range
x, y, // draw position
static_cast<minikin::Bidi>(bidiFlags), *paint, typeface, nullptr /* measured text */);
}