cts: Use reduce for faster SurfacePixelValidator
A RenderScript reduce operation is faster for image operations.
This makes SurfaceViewSyncTests pass more on Volantis.
Bug: 30948346
Change-Id: I21ddacedc5a895f3c494a7a046f0405deb70b95a
diff --git a/tests/tests/view/src/android/view/cts/surfacevalidator/PixelCounter.rs b/tests/tests/view/src/android/view/cts/surfacevalidator/PixelCounter.rs
index 55bc251..f58b9cb 100644
--- a/tests/tests/view/src/android/view/cts/surfacevalidator/PixelCounter.rs
+++ b/tests/tests/view/src/android/view/cts/surfacevalidator/PixelCounter.rs
@@ -15,22 +15,18 @@
*/
#pragma version(1)
#pragma rs java_package_name(android.view.cts.surfacevalidator)
+#pragma rs reduce(countBlackishPixels) accumulator(countBlackishPixelsAccum) combiner(countBlackishPixelsCombiner)
-int WIDTH;
uchar THRESHOLD;
-rs_allocation image;
-
-void countBlackishPixels(const int32_t *v_in, int *v_out){
- int y = v_in[0];
- v_out[0] = 0;
-
- for(int i = 0 ; i < WIDTH; i++){
- uchar4 pixel = rsGetElementAt_uchar4(image, i, y);
- if (pixel.r < THRESHOLD
- && pixel.g < THRESHOLD
- && pixel.b < THRESHOLD) {
- v_out[0]++;
- }
+static void countBlackishPixelsAccum(int *accum, uchar4 pixel){
+ if (pixel.r < THRESHOLD
+ && pixel.g < THRESHOLD
+ && pixel.b < THRESHOLD) {
+ *accum += 1;
}
}
+
+static void countBlackishPixelsCombiner(int *accum, const int *other){
+ *accum += *other;
+}
diff --git a/tests/tests/view/src/android/view/cts/surfacevalidator/SurfacePixelValidator.java b/tests/tests/view/src/android/view/cts/surfacevalidator/SurfacePixelValidator.java
index 4f712c8..5a30b77 100644
--- a/tests/tests/view/src/android/view/cts/surfacevalidator/SurfacePixelValidator.java
+++ b/tests/tests/view/src/android/view/cts/surfacevalidator/SurfacePixelValidator.java
@@ -59,8 +59,6 @@
private final RenderScript mRS;
private final Allocation mInPixelsAllocation;
- private final Allocation mInRowsAllocation;
- private final Allocation mOutRowsAllocation;
private final ScriptC_PixelCounter mScript;
@@ -75,15 +73,10 @@
public void run() {
Trace.beginSection("consume buffer");
mInPixelsAllocation.ioReceive();
- mScript.set_image(mInPixelsAllocation);
Trace.endSection();
- Trace.beginSection("compare");
- mScript.forEach_countBlackishPixels(mInRowsAllocation, mOutRowsAllocation);
- Trace.endSection();
-
- Trace.beginSection("sum");
- int blackishPixelCount = sum1DIntAllocation(mOutRowsAllocation, mHeight);
+ Trace.beginSection("compare and sum");
+ int blackishPixelCount = mScript.reduce_countBlackishPixels(mInPixelsAllocation).get();
Trace.endSection();
boolean success = mPixelChecker.checkPixels(blackishPixelCount, mWidth, mHeight);
@@ -127,9 +120,6 @@
mScript = new ScriptC_PixelCounter(mRS);
mInPixelsAllocation = createBufferQueueAllocation();
- mInRowsAllocation = createInputRowIndexAllocation();
- mOutRowsAllocation = createOutputRowAllocation();
- mScript.set_WIDTH(mWidth);
mScript.set_THRESHOLD(PIXEL_CHANNEL_THRESHOLD);
mInPixelsAllocation.setOnBufferAvailableListener(
@@ -140,38 +130,6 @@
return mInPixelsAllocation.getSurface();
}
- static private int sum1DIntAllocation(Allocation array, int length) {
- //Get the values returned from the function
- int[] returnValue = new int[length];
- array.copyTo(returnValue);
- int sum = 0;
- //If any row had any different pixels, then it fails
- for (int i = 0; i < length; i++) {
- sum += returnValue[i];
- }
- return sum;
- }
-
- /**
- * Creates an allocation where the values in it are the indices of each row
- */
- private Allocation createInputRowIndexAllocation() {
- //Create an array with the index of each row
- int[] inputIndices = new int[mHeight];
- for (int i = 0; i < mHeight; i++) {
- inputIndices[i] = i;
- }
- //Create the allocation from that given array
- Allocation inputAllocation = Allocation.createSized(mRS, Element.I32(mRS),
- inputIndices.length, Allocation.USAGE_SCRIPT);
- inputAllocation.copyFrom(inputIndices);
- return inputAllocation;
- }
-
- private Allocation createOutputRowAllocation() {
- return Allocation.createSized(mRS, Element.I32(mRS), mHeight, Allocation.USAGE_SCRIPT);
- }
-
private Allocation createBufferQueueAllocation() {
return Allocation.createAllocations(mRS, Type.createXY(mRS,
Element.RGBA_8888(mRS)