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

Commit c81808f8 authored by John Reck's avatar John Reck
Browse files

Add a benchmark for createScaled of P3 & sRGB

Bug: 316972621
Test: atest android.graphics.perftests.CanvasPerfTest
Change-Id: I73ccfab4e9f325b1f864eb1d8f41c71a7c6ed7a5
parent aa38e194
Loading
Loading
Loading
Loading
+24 −1
Original line number Diff line number Diff line
@@ -16,12 +16,14 @@

package android.graphics.perftests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.Color;
import android.graphics.ColorSpace;
import android.graphics.ImageDecoder;
import android.graphics.Paint;
import android.graphics.RecordingCanvas;
@@ -104,15 +106,36 @@ public class CanvasPerfTest {
    }

    @Test
    public void testCreateScaledBitmap() throws IOException {
    public void testCreateScaledSrgbBitmap() throws IOException {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final Context context = InstrumentationRegistry.getContext();
        Bitmap source = ImageDecoder.decodeBitmap(
                ImageDecoder.createSource(context.getResources(), R.drawable.fountain_night),
                (decoder, info, source1) -> {
                    decoder.setAllocator(ImageDecoder.ALLOCATOR_SOFTWARE);
                    decoder.setTargetColorSpace(ColorSpace.get(ColorSpace.Named.SRGB));
                });
        source.setGainmap(null);
        assertEquals(source.getColorSpace().getId(), ColorSpace.Named.SRGB.ordinal());

        while (state.keepRunning()) {
            Bitmap.createScaledBitmap(source, source.getWidth() / 2, source.getHeight() / 2, true)
                    .recycle();
        }
    }

    @Test
    public void testCreateScaledP3Bitmap() throws IOException {
        BenchmarkState state = mPerfStatusReporter.getBenchmarkState();
        final Context context = InstrumentationRegistry.getContext();
        Bitmap source = ImageDecoder.decodeBitmap(
                ImageDecoder.createSource(context.getResources(), R.drawable.fountain_night),
                (decoder, info, source1) -> {
                    decoder.setAllocator(ImageDecoder.ALLOCATOR_SOFTWARE);
                    decoder.setTargetColorSpace(ColorSpace.get(ColorSpace.Named.DISPLAY_P3));
                });
        source.setGainmap(null);
        assertEquals(source.getColorSpace().getId(), ColorSpace.Named.DISPLAY_P3.ordinal());

        while (state.keepRunning()) {
            Bitmap.createScaledBitmap(source, source.getWidth() / 2, source.getHeight() / 2, true)