| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package android.surfacecomposition; |
| 17 |
|
| 18 |
import android.app.Activity; |
| 19 |
import android.graphics.PixelFormat; |
| 20 |
import android.os.Build; |
| 21 |
import android.os.Bundle; |
| 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"; |
| 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"; |
| 41 |
|
| 42 |
|
| 43 |
private final static int[] TEST_PIXEL_FORMATS = new int[] { |
| 44 |
PixelFormat.TRANSLUCENT, |
| 45 |
PixelFormat.OPAQUE, |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
private final static double[] MIN_ACCEPTED_COMPOSITION_SCORE_ANDROMDEDA = new double[] { |
| 51 |
8.0, |
| 52 |
8.0, |
| 53 |
}; |
| 54 |
private final static double[] MIN_ACCEPTED_COMPOSITION_SCORE_ANDROID = new double[] { |
| 55 |
4.0, |
| 56 |
4.0, |
| 57 |
}; |
| 58 |
|
| 59 |
|
| 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 |
@SmallTest |
| 70 |
public void testSurfaceCompositionPerformance() { |
| 71 |
Bundle status = new Bundle(); |
| 72 |
double[] minScores = getActivity().isAndromeda() ? |
| 73 |
MIN_ACCEPTED_COMPOSITION_SCORE_ANDROMDEDA : MIN_ACCEPTED_COMPOSITION_SCORE_ANDROID; |
| 74 |
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 + " < " + |
| 81 |
minScores[i] + ". Build: " + Build.FINGERPRINT + ".", |
| 82 |
score.mSurfaces >= minScores[i]); |
| 83 |
|
| 84 |
if (pixelFormat == PixelFormat.TRANSLUCENT) { |
| 85 |
status.putDouble(KEY_SURFACE_COMPOSITION_PERFORMANCE, score.mSurfaces); |
| 86 |
|
| 87 |
status.putDouble(KEY_SURFACE_COMPOSITION_BANDWITH, score.mBandwidth / |
| 88 |
(1024.0 * 1024.0 * 1024.0)); |
| 89 |
} |
| 90 |
} |
| 91 |
getInstrumentation().sendStatus(Activity.RESULT_OK, status); |
| 92 |
} |
| 93 |
|
| 94 |
@SmallTest |
| 95 |
public void testSurfaceAllocationPerformance() { |
| 96 |
Bundle status = new Bundle(); |
| 97 |
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 + " < " + |
| 104 |
MIN_ACCEPTED_ALLOCATION_SCORE[i] + ". Build: " + |
| 105 |
Build.FINGERPRINT + ".", |
| 106 |
score.mMedian >= MIN_ACCEPTED_ALLOCATION_SCORE[i]); |
| 107 |
|
| 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 |
} |
| 113 |
} |
| 114 |
getInstrumentation().sendStatus(Activity.RESULT_OK, status); |
| 115 |
} |
| 116 |
} |