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