| 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 | |
| 18 | import android.graphics.PixelFormat; |
| 19 | import android.surfacecomposition.SurfaceCompositionMeasuringActivity.AllocationScore; |
| 20 | import android.surfacecomposition.SurfaceCompositionMeasuringActivity.CompositorScore; |
| 21 | import android.test.ActivityInstrumentationTestCase2; |
| 22 | import android.test.suitebuilder.annotation.SmallTest; |
| 23 | import android.util.Log; |
| 24 | |
| 25 | public class SurfaceCompositionTest extends |
| 26 | ActivityInstrumentationTestCase2<SurfaceCompositionMeasuringActivity> { |
| 27 | private final static String TAG = "SurfaceCompositionTest"; |
| 28 | |
| 29 | // Pass threshold for major pixel formats. |
| 30 | private final static int[] TEST_PIXEL_FORMATS = new int[] { |
| 31 | PixelFormat.TRANSLUCENT, |
| 32 | PixelFormat.OPAQUE, |
| 33 | }; |
| 34 | |
| 35 | // Based on Nexus 9 performance which is usually < 9.0. |
| 36 | private final static double[] MIN_ACCEPTED_COMPOSITION_SCORE = new double[] { |
| 37 | 8.0, |
| 38 | 8.0, |
| 39 | }; |
| 40 | |
| 41 | // Based on Nexus 6 performance which is usually < 28.0. |
| 42 | private final static double[] MIN_ACCEPTED_ALLOCATION_SCORE = new double[] { |
| 43 | 20.0, |
| 44 | 20.0, |
| 45 | }; |
| 46 | |
| 47 | public SurfaceCompositionTest() { |
| 48 | super(SurfaceCompositionMeasuringActivity.class); |
| 49 | } |
| 50 | |
| 51 | private void testRestoreContexts() { |
| 52 | } |
| 53 | |
| 54 | @SmallTest |
| 55 | public void testSurfaceCompositionPerformance() { |
| 56 | for (int i = 0; i < TEST_PIXEL_FORMATS.length; ++i) { |
| 57 | int pixelFormat = TEST_PIXEL_FORMATS[i]; |
| 58 | String formatName = SurfaceCompositionMeasuringActivity.getPixelFormatInfo(pixelFormat); |
| 59 | CompositorScore score = getActivity().measureCompositionScore(pixelFormat); |
| 60 | Log.i(TAG, "testSurfaceCompositionPerformance(" + formatName + ") = " + score); |
| 61 | assertTrue("Device does not support surface(" + formatName + ") composition " + |
| 62 | "performance score. " + score.mSurfaces + " < " + |
| 63 | MIN_ACCEPTED_COMPOSITION_SCORE[i] + ".", |
| 64 | score.mSurfaces >= MIN_ACCEPTED_COMPOSITION_SCORE[i]); |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | @SmallTest |
| 69 | public void testSurfaceAllocationPerformance() { |
| 70 | for (int i = 0; i < TEST_PIXEL_FORMATS.length; ++i) { |
| 71 | int pixelFormat = TEST_PIXEL_FORMATS[i]; |
| 72 | String formatName = SurfaceCompositionMeasuringActivity.getPixelFormatInfo(pixelFormat); |
| 73 | AllocationScore score = getActivity().measureAllocationScore(pixelFormat); |
| 74 | Log.i(TAG, "testSurfaceAllocationPerformance(" + formatName + ") = " + score); |
| 75 | assertTrue("Device does not support surface(" + formatName + ") allocation " + |
| 76 | "performance score. " + score.mMedian + " < " + |
| 77 | MIN_ACCEPTED_ALLOCATION_SCORE[i] + ".", |
| 78 | score.mMedian >= MIN_ACCEPTED_ALLOCATION_SCORE[i]); |
| 79 | } |
| 80 | } |
| 81 | } |