blob: 261ea2ec866d568d837335ee44b5a91bc0d553c3 [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 Khmel7578d102015-10-28 14:04:48 +090020import android.os.Build;
Yury Khmel9e433bb2015-10-05 19:15:57 +090021import android.os.Bundle;
Yury Khmel9dbde7b2015-08-31 17:51:42 +090022import android.surfacecomposition.SurfaceCompositionMeasuringActivity.AllocationScore;
23import android.surfacecomposition.SurfaceCompositionMeasuringActivity.CompositorScore;
24import android.test.ActivityInstrumentationTestCase2;
25import android.test.suitebuilder.annotation.SmallTest;
26import android.util.Log;
27
28public class SurfaceCompositionTest extends
29 ActivityInstrumentationTestCase2<SurfaceCompositionMeasuringActivity> {
30 private final static String TAG = "SurfaceCompositionTest";
Yury Khmel9e433bb2015-10-05 19:15:57 +090031 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 Khmel9dbde7b2015-08-31 17:51:42 +090041
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 Khmel7578d102015-10-28 14:04:48 +090048 // 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 Khmel9dbde7b2015-08-31 17:51:42 +090051 8.0,
52 8.0,
53 };
Yury Khmel7578d102015-10-28 14:04:48 +090054 private final static double[] MIN_ACCEPTED_COMPOSITION_SCORE_ANDROID = new double[] {
55 4.0,
56 4.0,
57 };
Yury Khmel9dbde7b2015-08-31 17:51:42 +090058
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
Yury Khmel9dbde7b2015-08-31 17:51:42 +090069 @SmallTest
70 public void testSurfaceCompositionPerformance() {
Yury Khmel9e433bb2015-10-05 19:15:57 +090071 Bundle status = new Bundle();
Yury Khmel7578d102015-10-28 14:04:48 +090072 double[] minScores = getActivity().isAndromeda() ?
73 MIN_ACCEPTED_COMPOSITION_SCORE_ANDROMDEDA : MIN_ACCEPTED_COMPOSITION_SCORE_ANDROID;
Yury Khmel9dbde7b2015-08-31 17:51:42 +090074 for (int i = 0; i < TEST_PIXEL_FORMATS.length; ++i) {
75 int pixelFormat = TEST_PIXEL_FORMATS[i];
76 String formatName = SurfaceCompositionMeasuringActivity.getPixelFormatInfo(pixelFormat);
77 CompositorScore score = getActivity().measureCompositionScore(pixelFormat);
78 Log.i(TAG, "testSurfaceCompositionPerformance(" + formatName + ") = " + score);
79 assertTrue("Device does not support surface(" + formatName + ") composition " +
80 "performance score. " + score.mSurfaces + " < " +
Yury Khmel7578d102015-10-28 14:04:48 +090081 minScores[i] + ". Build: " + Build.FINGERPRINT + ".",
82 score.mSurfaces >= minScores[i]);
Yury Khmel9e433bb2015-10-05 19:15:57 +090083 // Send status only for TRANSLUCENT format.
84 if (pixelFormat == PixelFormat.TRANSLUCENT) {
85 status.putDouble(KEY_SURFACE_COMPOSITION_PERFORMANCE, score.mSurfaces);
86 // Put bandwidth in GBPS.
87 status.putDouble(KEY_SURFACE_COMPOSITION_BANDWITH, score.mBandwidth /
88 (1024.0 * 1024.0 * 1024.0));
89 }
Yury Khmel9dbde7b2015-08-31 17:51:42 +090090 }
Yury Khmel9e433bb2015-10-05 19:15:57 +090091 getInstrumentation().sendStatus(Activity.RESULT_OK, status);
Yury Khmel9dbde7b2015-08-31 17:51:42 +090092 }
93
94 @SmallTest
95 public void testSurfaceAllocationPerformance() {
Yury Khmel9e433bb2015-10-05 19:15:57 +090096 Bundle status = new Bundle();
Yury Khmel9dbde7b2015-08-31 17:51:42 +090097 for (int i = 0; i < TEST_PIXEL_FORMATS.length; ++i) {
98 int pixelFormat = TEST_PIXEL_FORMATS[i];
99 String formatName = SurfaceCompositionMeasuringActivity.getPixelFormatInfo(pixelFormat);
100 AllocationScore score = getActivity().measureAllocationScore(pixelFormat);
101 Log.i(TAG, "testSurfaceAllocationPerformance(" + formatName + ") = " + score);
102 assertTrue("Device does not support surface(" + formatName + ") allocation " +
103 "performance score. " + score.mMedian + " < " +
Yury Khmel7578d102015-10-28 14:04:48 +0900104 MIN_ACCEPTED_ALLOCATION_SCORE[i] + ". Build: " +
105 Build.FINGERPRINT + ".",
Yury Khmel9dbde7b2015-08-31 17:51:42 +0900106 score.mMedian >= MIN_ACCEPTED_ALLOCATION_SCORE[i]);
Yury Khmel9e433bb2015-10-05 19:15:57 +0900107 // Send status only for TRANSLUCENT format.
108 if (pixelFormat == PixelFormat.TRANSLUCENT) {
109 status.putDouble(KEY_SURFACE_ALLOCATION_PERFORMANCE_MEDIAN, score.mMedian);
110 status.putDouble(KEY_SURFACE_ALLOCATION_PERFORMANCE_MIN, score.mMin);
111 status.putDouble(KEY_SURFACE_ALLOCATION_PERFORMANCE_MAX, score.mMax);
112 }
Yury Khmel9dbde7b2015-08-31 17:51:42 +0900113 }
Yury Khmel9e433bb2015-10-05 19:15:57 +0900114 getInstrumentation().sendStatus(Activity.RESULT_OK, status);
Yury Khmel9dbde7b2015-08-31 17:51:42 +0900115 }
116}