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

Commit 52d3b672 authored by Seigo Nonaka's avatar Seigo Nonaka
Browse files

Add StaticLayoutPerfTest for drawing

Bug: 63897135
Test: Here is the sample result on walleye-userdebug

draw MeasuredText NoStyled             :    714,657
draw MeasuredText NoStyled WithoutCache:  9,775,025
draw MeasuredText Styled               :  3,341,118
draw MeasuredText Styled WithoutCache  : 13,214,933
draw RandomText NoStyled               :    649,611
draw RandomText NoStyled WithoutCache  :  9,625,940
draw RandomText Styled                 :  3,296,206
draw RandomText Styled WithoutCache    : 13,735,996

Change-Id: I9c784014ffda997fe60d667734d0e41975198265
parent bd9b0cf9
Loading
Loading
Loading
Loading
+156 −0
Original line number Diff line number Diff line
@@ -25,9 +25,12 @@ import android.support.test.filters.LargeTest;
import android.support.test.runner.AndroidJUnit4;

import android.content.res.ColorStateList;
import android.graphics.Canvas;
import android.graphics.Typeface;
import android.text.Layout;
import android.text.style.TextAppearanceSpan;
import android.view.DisplayListCanvas;
import android.view.RenderNode;

import org.junit.Before;
import org.junit.Rule;
@@ -285,4 +288,157 @@ public class StaticLayoutPerfTest {
                    .build();
        }
    }

    @Test
    public void testDraw_FixedText_NoStyled() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final CharSequence text = generateRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT);
        final RenderNode node = RenderNode.create("benchmark", null);
        while (state.keepRunning()) {
            state.pauseTiming();
            final StaticLayout layout =
                    StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build();
            final DisplayListCanvas c = node.start(1200, 200);
            state.resumeTiming();

            layout.draw(c);
        }
    }

    @Test
    public void testDraw_RandomText_Styled() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final RenderNode node = RenderNode.create("benchmark", null);
        while (state.keepRunning()) {
            state.pauseTiming();
            final CharSequence text = generateRandomParagraph(WORD_LENGTH, STYLE_TEXT);
            final StaticLayout layout =
                    StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build();
            final DisplayListCanvas c = node.start(1200, 200);
            state.resumeTiming();

            layout.draw(c);
        }
    }

    @Test
    public void testDraw_RandomText_NoStyled() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final RenderNode node = RenderNode.create("benchmark", null);
        while (state.keepRunning()) {
            state.pauseTiming();
            final CharSequence text = generateRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT);
            final StaticLayout layout =
                    StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build();
            final DisplayListCanvas c = node.start(1200, 200);
            state.resumeTiming();

            layout.draw(c);
        }
    }

    @Test
    public void testDraw_RandomText_Styled_WithoutCache() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final RenderNode node = RenderNode.create("benchmark", null);
        while (state.keepRunning()) {
            state.pauseTiming();
            final CharSequence text = generateRandomParagraph(WORD_LENGTH, STYLE_TEXT);
            final StaticLayout layout =
                    StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build();
            final DisplayListCanvas c = node.start(1200, 200);
            Canvas.freeTextLayoutCaches();
            state.resumeTiming();

            layout.draw(c);
        }
    }

    @Test
    public void testDraw_RandomText_NoStyled_WithoutCache() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final RenderNode node = RenderNode.create("benchmark", null);
        while (state.keepRunning()) {
            state.pauseTiming();
            final CharSequence text = generateRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT);
            final StaticLayout layout =
                    StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build();
            final DisplayListCanvas c = node.start(1200, 200);
            Canvas.freeTextLayoutCaches();
            state.resumeTiming();

            layout.draw(c);
        }
    }

    @Test
    public void testDraw_MeasuredText_Styled() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final RenderNode node = RenderNode.create("benchmark", null);
        while (state.keepRunning()) {
            state.pauseTiming();
            final MeasuredText text = new MeasuredText.Builder(
                    generateRandomParagraph(WORD_LENGTH, STYLE_TEXT), PAINT).build();
            final StaticLayout layout =
                    StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build();
            final DisplayListCanvas c = node.start(1200, 200);
            state.resumeTiming();

            layout.draw(c);
        }
    }

    @Test
    public void testDraw_MeasuredText_NoStyled() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final RenderNode node = RenderNode.create("benchmark", null);
        while (state.keepRunning()) {
            state.pauseTiming();
            final MeasuredText text = new MeasuredText.Builder(
                    generateRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT).build();
            final StaticLayout layout =
                    StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build();
            final DisplayListCanvas c = node.start(1200, 200);
            state.resumeTiming();

            layout.draw(c);
        }
    }

    @Test
    public void testDraw_MeasuredText_Styled_WithoutCache() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final RenderNode node = RenderNode.create("benchmark", null);
        while (state.keepRunning()) {
            state.pauseTiming();
            final MeasuredText text = new MeasuredText.Builder(
                    generateRandomParagraph(WORD_LENGTH, STYLE_TEXT), PAINT).build();
            final StaticLayout layout =
                    StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build();
            final DisplayListCanvas c = node.start(1200, 200);
            Canvas.freeTextLayoutCaches();
            state.resumeTiming();

            layout.draw(c);
        }
    }

    @Test
    public void testDraw_MeasuredText_NoStyled_WithoutCache() {
        final BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final RenderNode node = RenderNode.create("benchmark", null);
        while (state.keepRunning()) {
            state.pauseTiming();
            final MeasuredText text = new MeasuredText.Builder(
                    generateRandomParagraph(WORD_LENGTH, NO_STYLE_TEXT), PAINT).build();
            final StaticLayout layout =
                    StaticLayout.Builder.obtain(text, 0, text.length(), PAINT, TEXT_WIDTH).build();
            final DisplayListCanvas c = node.start(1200, 200);
            Canvas.freeTextLayoutCaches();
            state.resumeTiming();

            layout.draw(c);
        }
    }

}