1 /* 2 * Copyright (C) 2015 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package android.surfacecomposition; 17 18 import android.app.Activity; 19 import android.graphics.PixelFormat; 20 import android.os.Build; 21 import android.os.Bundle; 22 import android.surfacecomposition.SurfaceCompositionMeasuringActivity.AllocationScore; 23 import android.surfacecomposition.SurfaceCompositionMeasuringActivity.CompositorScore; 24 import android.test.ActivityInstrumentationTestCase2; 25 import android.util.Log; 26 27 import androidx.test.filters.SmallTest; 28 29 public class SurfaceCompositionTest extends 30 ActivityInstrumentationTestCase2<SurfaceCompositionMeasuringActivity> { 31 private final static String TAG = "SurfaceCompositionTest"; 32 private final static String KEY_SURFACE_COMPOSITION_PERFORMANCE = 33 "surface-compoistion-peformance-sps"; 34 private final static String KEY_SURFACE_COMPOSITION_BANDWITH = 35 "surface-compoistion-bandwidth-gbps"; 36 private final static String KEY_SURFACE_ALLOCATION_PERFORMANCE_MEDIAN = 37 "surface-allocation-performance-median-sps"; 38 private final static String KEY_SURFACE_ALLOCATION_PERFORMANCE_MIN = 39 "surface-allocation-performance-min-sps"; 40 private final static String KEY_SURFACE_ALLOCATION_PERFORMANCE_MAX = 41 "surface-allocation-performance-max-sps"; 42 43 // Pass threshold for major pixel formats. 44 private final static int[] TEST_PIXEL_FORMATS = new int[] { 45 PixelFormat.TRANSLUCENT, 46 PixelFormat.OPAQUE, 47 }; 48 49 // Nexus 9 performance is around 8.8. We distinguish results for Andromeda and 50 // Android devices. Andromeda devices require higher performance score. 51 private final static double[] MIN_ACCEPTED_COMPOSITION_SCORE_ANDROMDEDA = new double[] { 52 8.0, 53 8.0, 54 }; 55 private final static double[] MIN_ACCEPTED_COMPOSITION_SCORE_ANDROID = new double[] { 56 4.0, 57 4.0, 58 }; 59 60 // Based on Nexus 6 performance which is usually < 28.0. 61 private final static double[] MIN_ACCEPTED_ALLOCATION_SCORE = new double[] { 62 20.0, 63 20.0, 64 }; 65 SurfaceCompositionTest()66 public SurfaceCompositionTest() { 67 super(SurfaceCompositionMeasuringActivity.class); 68 } 69 70 @SmallTest testSurfaceCompositionPerformance()71 public void testSurfaceCompositionPerformance() { 72 Bundle status = new Bundle(); 73 double[] minScores = getActivity().isAndromeda() ? 74 MIN_ACCEPTED_COMPOSITION_SCORE_ANDROMDEDA : MIN_ACCEPTED_COMPOSITION_SCORE_ANDROID; 75 for (int i = 0; i < TEST_PIXEL_FORMATS.length; ++i) { 76 int pixelFormat = TEST_PIXEL_FORMATS[i]; 77 String formatName = SurfaceCompositionMeasuringActivity.getPixelFormatInfo(pixelFormat); 78 CompositorScore score = getActivity().measureCompositionScore(pixelFormat); 79 Log.i(TAG, "testSurfaceCompositionPerformance(" + formatName + ") = " + score); 80 assertTrue("Device does not support surface(" + formatName + ") composition " + 81 "performance score. " + score.mSurfaces + " < " + 82 minScores[i] + ". Build: " + Build.FINGERPRINT + ".", 83 score.mSurfaces >= minScores[i]); 84 // Send status only for TRANSLUCENT format. 85 if (pixelFormat == PixelFormat.TRANSLUCENT) { 86 status.putDouble(KEY_SURFACE_COMPOSITION_PERFORMANCE, score.mSurfaces); 87 // Put bandwidth in GBPS. 88 status.putDouble(KEY_SURFACE_COMPOSITION_BANDWITH, score.mBandwidth / 89 (1024.0 * 1024.0 * 1024.0)); 90 } 91 } 92 getInstrumentation().sendStatus(Activity.RESULT_OK, status); 93 } 94 95 @SmallTest testSurfaceAllocationPerformance()96 public void testSurfaceAllocationPerformance() { 97 Bundle status = new Bundle(); 98 for (int i = 0; i < TEST_PIXEL_FORMATS.length; ++i) { 99 int pixelFormat = TEST_PIXEL_FORMATS[i]; 100 String formatName = SurfaceCompositionMeasuringActivity.getPixelFormatInfo(pixelFormat); 101 AllocationScore score = getActivity().measureAllocationScore(pixelFormat); 102 Log.i(TAG, "testSurfaceAllocationPerformance(" + formatName + ") = " + score); 103 assertTrue("Device does not support surface(" + formatName + ") allocation " + 104 "performance score. " + score.mMedian + " < " + 105 MIN_ACCEPTED_ALLOCATION_SCORE[i] + ". Build: " + 106 Build.FINGERPRINT + ".", 107 score.mMedian >= MIN_ACCEPTED_ALLOCATION_SCORE[i]); 108 // Send status only for TRANSLUCENT format. 109 if (pixelFormat == PixelFormat.TRANSLUCENT) { 110 status.putDouble(KEY_SURFACE_ALLOCATION_PERFORMANCE_MEDIAN, score.mMedian); 111 status.putDouble(KEY_SURFACE_ALLOCATION_PERFORMANCE_MIN, score.mMin); 112 status.putDouble(KEY_SURFACE_ALLOCATION_PERFORMANCE_MAX, score.mMax); 113 } 114 } 115 getInstrumentation().sendStatus(Activity.RESULT_OK, status); 116 } 117 } 118