Yury Khmel | 9dbde7b | 2015-08-31 17:51:42 +0900 | [diff] [blame] | 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 | |
Yury Khmel | 9e433bb | 2015-10-05 19:15:57 +0900 | [diff] [blame] | 18 | import android.app.Activity; |
Yury Khmel | 9dbde7b | 2015-08-31 17:51:42 +0900 | [diff] [blame] | 19 | import android.graphics.PixelFormat; |
Yury Khmel | 7578d10 | 2015-10-28 14:04:48 +0900 | [diff] [blame] | 20 | import android.os.Build; |
Yury Khmel | 9e433bb | 2015-10-05 19:15:57 +0900 | [diff] [blame] | 21 | import android.os.Bundle; |
Yury Khmel | 9dbde7b | 2015-08-31 17:51:42 +0900 | [diff] [blame] | 22 | import android.surfacecomposition.SurfaceCompositionMeasuringActivity.AllocationScore; |
| 23 | import android.surfacecomposition.SurfaceCompositionMeasuringActivity.CompositorScore; |
| 24 | import android.test.ActivityInstrumentationTestCase2; |
| 25 | import android.test.suitebuilder.annotation.SmallTest; |
| 26 | import android.util.Log; |
| 27 | |
| 28 | public class SurfaceCompositionTest extends |
| 29 | ActivityInstrumentationTestCase2<SurfaceCompositionMeasuringActivity> { |
| 30 | private final static String TAG = "SurfaceCompositionTest"; |
Yury Khmel | 9e433bb | 2015-10-05 19:15:57 +0900 | [diff] [blame] | 31 | private final static String KEY_SURFACE_COMPOSITION_PERFORMANCE = |
| 32 | "surface-compoistion-peformance-sps"; |
| 33 | private final static String KEY_SURFACE_COMPOSITION_BANDWITH = |
| 34 | "surface-compoistion-bandwidth-gbps"; |
| 35 | private final static String KEY_SURFACE_ALLOCATION_PERFORMANCE_MEDIAN = |
| 36 | "surface-allocation-performance-median-sps"; |
| 37 | private final static String KEY_SURFACE_ALLOCATION_PERFORMANCE_MIN = |
| 38 | "surface-allocation-performance-min-sps"; |
| 39 | private final static String KEY_SURFACE_ALLOCATION_PERFORMANCE_MAX = |
| 40 | "surface-allocation-performance-max-sps"; |
Yury Khmel | 9dbde7b | 2015-08-31 17:51:42 +0900 | [diff] [blame] | 41 | |
| 42 | // Pass threshold for major pixel formats. |
| 43 | private final static int[] TEST_PIXEL_FORMATS = new int[] { |
| 44 | PixelFormat.TRANSLUCENT, |
| 45 | PixelFormat.OPAQUE, |
| 46 | }; |
| 47 | |
Yury Khmel | 7578d10 | 2015-10-28 14:04:48 +0900 | [diff] [blame] | 48 | // Nexus 9 performance is around 8.8. We distinguish results for Andromeda and |
| 49 | // Android devices. Andromeda devices require higher performance score. |
| 50 | private final static double[] MIN_ACCEPTED_COMPOSITION_SCORE_ANDROMDEDA = new double[] { |
Yury Khmel | 9dbde7b | 2015-08-31 17:51:42 +0900 | [diff] [blame] | 51 | 8.0, |
| 52 | 8.0, |
| 53 | }; |
Yury Khmel | 7578d10 | 2015-10-28 14:04:48 +0900 | [diff] [blame] | 54 | private final static double[] MIN_ACCEPTED_COMPOSITION_SCORE_ANDROID = new double[] { |
| 55 | 4.0, |
| 56 | 4.0, |
| 57 | }; |
Yury Khmel | 9dbde7b | 2015-08-31 17:51:42 +0900 | [diff] [blame] | 58 | |
| 59 | // Based on Nexus 6 performance which is usually < 28.0. |
| 60 | private final static double[] MIN_ACCEPTED_ALLOCATION_SCORE = new double[] { |
| 61 | 20.0, |
| 62 | 20.0, |
| 63 | }; |
| 64 | |
| 65 | public SurfaceCompositionTest() { |
| 66 | super(SurfaceCompositionMeasuringActivity.class); |
| 67 | } |
| 68 | |
| 69 | private void testRestoreContexts() { |
| 70 | } |
| 71 | |
| 72 | @SmallTest |
| 73 | public void testSurfaceCompositionPerformance() { |
Yury Khmel | 9e433bb | 2015-10-05 19:15:57 +0900 | [diff] [blame] | 74 | Bundle status = new Bundle(); |
Yury Khmel | 7578d10 | 2015-10-28 14:04:48 +0900 | [diff] [blame] | 75 | double[] minScores = getActivity().isAndromeda() ? |
| 76 | MIN_ACCEPTED_COMPOSITION_SCORE_ANDROMDEDA : MIN_ACCEPTED_COMPOSITION_SCORE_ANDROID; |
Yury Khmel | 9dbde7b | 2015-08-31 17:51:42 +0900 | [diff] [blame] | 77 | for (int i = 0; i < TEST_PIXEL_FORMATS.length; ++i) { |
| 78 | int pixelFormat = TEST_PIXEL_FORMATS[i]; |
| 79 | String formatName = SurfaceCompositionMeasuringActivity.getPixelFormatInfo(pixelFormat); |
| 80 | CompositorScore score = getActivity().measureCompositionScore(pixelFormat); |
| 81 | Log.i(TAG, "testSurfaceCompositionPerformance(" + formatName + ") = " + score); |
| 82 | assertTrue("Device does not support surface(" + formatName + ") composition " + |
| 83 | "performance score. " + score.mSurfaces + " < " + |
Yury Khmel | 7578d10 | 2015-10-28 14:04:48 +0900 | [diff] [blame] | 84 | minScores[i] + ". Build: " + Build.FINGERPRINT + ".", |
| 85 | score.mSurfaces >= minScores[i]); |
Yury Khmel | 9e433bb | 2015-10-05 19:15:57 +0900 | [diff] [blame] | 86 | // Send status only for TRANSLUCENT format. |
| 87 | if (pixelFormat == PixelFormat.TRANSLUCENT) { |
| 88 | status.putDouble(KEY_SURFACE_COMPOSITION_PERFORMANCE, score.mSurfaces); |
| 89 | // Put bandwidth in GBPS. |
| 90 | status.putDouble(KEY_SURFACE_COMPOSITION_BANDWITH, score.mBandwidth / |
| 91 | (1024.0 * 1024.0 * 1024.0)); |
| 92 | } |
Yury Khmel | 9dbde7b | 2015-08-31 17:51:42 +0900 | [diff] [blame] | 93 | } |
Yury Khmel | 9e433bb | 2015-10-05 19:15:57 +0900 | [diff] [blame] | 94 | getInstrumentation().sendStatus(Activity.RESULT_OK, status); |
Yury Khmel | 9dbde7b | 2015-08-31 17:51:42 +0900 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | @SmallTest |
| 98 | public void testSurfaceAllocationPerformance() { |
Yury Khmel | 9e433bb | 2015-10-05 19:15:57 +0900 | [diff] [blame] | 99 | Bundle status = new Bundle(); |
Yury Khmel | 9dbde7b | 2015-08-31 17:51:42 +0900 | [diff] [blame] | 100 | for (int i = 0; i < TEST_PIXEL_FORMATS.length; ++i) { |
| 101 | int pixelFormat = TEST_PIXEL_FORMATS[i]; |
| 102 | String formatName = SurfaceCompositionMeasuringActivity.getPixelFormatInfo(pixelFormat); |
| 103 | AllocationScore score = getActivity().measureAllocationScore(pixelFormat); |
| 104 | Log.i(TAG, "testSurfaceAllocationPerformance(" + formatName + ") = " + score); |
| 105 | assertTrue("Device does not support surface(" + formatName + ") allocation " + |
| 106 | "performance score. " + score.mMedian + " < " + |
Yury Khmel | 7578d10 | 2015-10-28 14:04:48 +0900 | [diff] [blame] | 107 | MIN_ACCEPTED_ALLOCATION_SCORE[i] + ". Build: " + |
| 108 | Build.FINGERPRINT + ".", |
Yury Khmel | 9dbde7b | 2015-08-31 17:51:42 +0900 | [diff] [blame] | 109 | score.mMedian >= MIN_ACCEPTED_ALLOCATION_SCORE[i]); |
Yury Khmel | 9e433bb | 2015-10-05 19:15:57 +0900 | [diff] [blame] | 110 | // Send status only for TRANSLUCENT format. |
| 111 | if (pixelFormat == PixelFormat.TRANSLUCENT) { |
| 112 | status.putDouble(KEY_SURFACE_ALLOCATION_PERFORMANCE_MEDIAN, score.mMedian); |
| 113 | status.putDouble(KEY_SURFACE_ALLOCATION_PERFORMANCE_MIN, score.mMin); |
| 114 | status.putDouble(KEY_SURFACE_ALLOCATION_PERFORMANCE_MAX, score.mMax); |
| 115 | } |
Yury Khmel | 9dbde7b | 2015-08-31 17:51:42 +0900 | [diff] [blame] | 116 | } |
Yury Khmel | 9e433bb | 2015-10-05 19:15:57 +0900 | [diff] [blame] | 117 | getInstrumentation().sendStatus(Activity.RESULT_OK, status); |
Yury Khmel | 9dbde7b | 2015-08-31 17:51:42 +0900 | [diff] [blame] | 118 | } |
| 119 | } |