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

Commit 6b0c318d authored by Tim Murray's avatar Tim Murray
Browse files

TouchLatency: don't recreate DecimalFormat on every frame

reduces UI thread time by 20%

Test: manual
Change-Id: If9053d19fc0db1491a0b9402c54243aff8f12432
parent 0ed11d02
Loading
Loading
Loading
Loading
+6 −3
Original line number Diff line number Diff line
@@ -73,6 +73,10 @@ class TouchLatencyView extends View implements View.OnTouchListener {
        mFps = 0;
        mLastFpsUpdate = 0;
        mFrameCount = 0;

        mDf = new DecimalFormat("fps: #.##");
        mDf.setRoundingMode(RoundingMode.HALF_UP);

        Trace.endSection();
    }

@@ -181,9 +185,7 @@ class TouchLatencyView extends View implements View.OnTouchListener {
        // Draw the ball
        canvas.drawColor(BACKGROUND_COLOR);
        canvas.drawOval(left, top, right, bottom, getBallColor());
        DecimalFormat df = new DecimalFormat("fps: #.##");
        df.setRoundingMode(RoundingMode.HALF_UP);
        canvas.drawText(df.format(mFps), width, 100, mTextPaint);
        canvas.drawText(mDf.format(mFps), width, 100, mTextPaint);

        invalidate();
        Trace.endSection();
@@ -220,6 +222,7 @@ class TouchLatencyView extends View implements View.OnTouchListener {

    private long mLastDrawNano, mLastFpsUpdate, mFrameCount;
    private float mFps;
    private DecimalFormat mDf;
}

public class TouchLatencyActivity extends Activity {