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

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

Fix TextViewSetTextMeasurePerfTest to set proper width

The TextViewSetTextMeasurePerfTest measures text with 0 pixel width
and height which is uncommon situation, so setting proper
width/height for measuring realistic numbers.

Bug: 323606812
Test: atest TextViewSetTextMeasurePerfTest
Change-Id: If864d9b3d11861da01da5881a746959baf3f160c
parent 404ed228
Loading
Loading
Loading
Loading
+14 −4
Original line number Original line Diff line number Diff line
@@ -20,10 +20,12 @@ import static android.view.View.MeasureSpec.UNSPECIFIED;


import android.graphics.Canvas;
import android.graphics.Canvas;
import android.graphics.RecordingCanvas;
import android.graphics.RecordingCanvas;
import android.graphics.RectF;
import android.graphics.RenderNode;
import android.graphics.RenderNode;
import android.perftests.utils.BenchmarkState;
import android.perftests.utils.BenchmarkState;
import android.perftests.utils.PerfStatusReporter;
import android.perftests.utils.PerfStatusReporter;
import android.text.NonEditableTextGenerator.TextType;
import android.text.NonEditableTextGenerator.TextType;
import android.view.View;
import android.widget.TextView;
import android.widget.TextView;


import androidx.test.InstrumentationRegistry;
import androidx.test.InstrumentationRegistry;
@@ -79,7 +81,7 @@ public class TextViewSetTextMeasurePerfTest {
        mCached = cached;
        mCached = cached;
        mTextPaint = new TextPaint();
        mTextPaint = new TextPaint();
        mTextPaint.setTextSize(10);
        mTextPaint.setTextSize(10);
        mLineWidth = Integer.MAX_VALUE;
        mLineWidth = 2048;
    }
    }


    /**
    /**
@@ -106,7 +108,9 @@ public class TextViewSetTextMeasurePerfTest {
            state.resumeTiming();
            state.resumeTiming();


            textView.setText(text);
            textView.setText(text);
            textView.measure(AT_MOST | mLineWidth, UNSPECIFIED);
            textView.measure(
                    View.MeasureSpec.makeMeasureSpec(mLineWidth, AT_MOST),
                    UNSPECIFIED);
        }
        }
    }
    }


@@ -129,10 +133,16 @@ public class TextViewSetTextMeasurePerfTest {
        while (state.keepRunning()) {
        while (state.keepRunning()) {


            state.pauseTiming();
            state.pauseTiming();
            final RecordingCanvas canvas = node.start(1200, 200);
            int save = canvas.save();
            textView.setTextLocale(Locale.UK);
            textView.setTextLocale(Locale.UK);
            textView.setTextLocale(Locale.US);
            textView.setTextLocale(Locale.US);
            textView.measure(
                    View.MeasureSpec.makeMeasureSpec(mLineWidth, AT_MOST),
                    UNSPECIFIED);
            RectF bounds = textView.getLayout().computeDrawingBoundingBox();
            final RecordingCanvas canvas = node.start(
                    (int) Math.ceil(bounds.width()),
                    (int) Math.ceil(bounds.height()));
            int save = canvas.save();
            if (!mCached) Canvas.freeTextLayoutCaches();
            if (!mCached) Canvas.freeTextLayoutCaches();
            state.resumeTiming();
            state.resumeTiming();