| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package android.text; |
| 17 |
|
| 18 |
import android.graphics.RecordingCanvas; |
| 19 |
import android.graphics.RenderNode; |
| 20 |
import android.perftests.utils.BenchmarkState; |
| 21 |
import android.perftests.utils.PerfStatusReporter; |
| 22 |
|
| 23 |
import androidx.test.filters.LargeTest; |
| 24 |
import androidx.test.runner.AndroidJUnit4; |
| 25 |
|
| 26 |
import org.junit.Before; |
| 27 |
import org.junit.Rule; |
| 28 |
import org.junit.Test; |
| 29 |
import org.junit.runner.RunWith; |
| 30 |
|
| 31 |
import java.util.Random; |
| 32 |
|
| 33 |
@LargeTest |
| 34 |
@RunWith(AndroidJUnit4.class) |
| 35 |
public class CanvasDrawTextTest { |
| 36 |
private static final int WORD_LENGTH = 9; |
| 37 |
|
| 38 |
private static final TextPaint PAINT = new TextPaint(); |
| 39 |
|
| 40 |
@Rule |
| 41 |
public PerfStatusReporter mPerfStatusReporter = new PerfStatusReporter(); |
| 42 |
|
| 43 |
private TextPerfUtils mTextUtil = new TextPerfUtils(); |
| 44 |
|
| 45 |
@Before |
| 46 |
public void setUp() { |
| 47 |
mTextUtil.resetRandom(0 ); |
| 48 |
} |
| 49 |
|
| 50 |
@Test |
| 51 |
public void drawText_LongText_SmallWindow() { |
| 52 |
final BenchmarkState state = mPerfStatusReporter.getBenchmarkState(); |
| 53 |
final String text = mTextUtil.nextRandomParagraph( |
| 54 |
WORD_LENGTH, 4 * 1024 * 1024 ).toString(); |
| 55 |
final RenderNode node = RenderNode.create("benchmark", null); |
| 56 |
|
| 57 |
final Random r = new Random(0); |
| 58 |
while (state.keepRunning()) { |
| 59 |
state.pauseTiming(); |
| 60 |
RecordingCanvas canvas = node.beginRecording(); |
| 61 |
int start = r.nextInt(text.length() - 100); |
| 62 |
state.resumeTiming(); |
| 63 |
|
| 64 |
canvas.drawText(text, start, start + 100, 0, 0, PAINT); |
| 65 |
|
| 66 |
state.pauseTiming(); |
| 67 |
node.endRecording(); |
| 68 |
state.resumeTiming(); |
| 69 |
} |
| 70 |
} |
| 71 |
} |