blob: 3f04888da6370d5041dc4268c4ab33255e75c739 [file] [log] [blame]
Yury Khmel9dbde7b2015-08-31 17:51:42 +09001/*
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 */
16package android.surfacecomposition;
17
Yury Khmel9e433bb2015-10-05 19:15:57 +090018import android.app.Activity;
Yury Khmel9dbde7b2015-08-31 17:51:42 +090019import android.graphics.PixelFormat;
Yury Khmel9e433bb2015-10-05 19:15:57 +090020import android.os.Bundle;
Yury Khmel9dbde7b2015-08-31 17:51:42 +090021import android.surfacecomposition.SurfaceCompositionMeasuringActivity.AllocationScore;
22import android.surfacecomposition.SurfaceCompositionMeasuringActivity.CompositorScore;
23import android.test.ActivityInstrumentationTestCase2;
24import android.test.suitebuilder.annotation.SmallTest;
25import android.util.Log;
26
27public class SurfaceCompositionTest extends
28 ActivityInstrumentationTestCase2<SurfaceCompositionMeasuringActivity> {
29 private final static String TAG = "SurfaceCompositionTest";
Yury Khmel9e433bb2015-10-05 19:15:57 +090030 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 Khmel9dbde7b2015-08-31 17:51:42 +090040
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 Khmel9e433bb2015-10-05 19:15:57 +090068 Bundle status = new Bundle();
Yury Khmel9dbde7b2015-08-31 17:51:42 +090069 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 Khmel9e433bb2015-10-05 19:15:57 +090078 // 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 Khmel9dbde7b2015-08-31 17:51:42 +090085 }
Yury Khmel9e433bb2015-10-05 19:15:57 +090086 getInstrumentation().sendStatus(Activity.RESULT_OK, status);
Yury Khmel9dbde7b2015-08-31 17:51:42 +090087 }
88
89 @SmallTest
90 public void testSurfaceAllocationPerformance() {
Yury Khmel9e433bb2015-10-05 19:15:57 +090091 Bundle status = new Bundle();
Yury Khmel9dbde7b2015-08-31 17:51:42 +090092 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 Khmel9e433bb2015-10-05 19:15:57 +0900101 // 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 Khmel9dbde7b2015-08-31 17:51:42 +0900107 }
Yury Khmel9e433bb2015-10-05 19:15:57 +0900108 getInstrumentation().sendStatus(Activity.RESULT_OK, status);
Yury Khmel9dbde7b2015-08-31 17:51:42 +0900109 }
110}