SetError if forEachMtlsSetup fails sanity check

bug 19866850

Explicitly set error when a kernel launch fails.

Change-Id: If42419f3cf7557c524afc5bb27a0753460ca7e4e
(cherry-pick 80afd424b02291e6f088cab2961537c7ba1ee2a5 from AOSP)
diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp
index fd40c21..3f64534 100644
--- a/cpu_ref/rsCpuScript.cpp
+++ b/cpu_ref/rsCpuScript.cpp
@@ -566,7 +566,11 @@
     } else {
         mtls->start.x = rsMin(mtls->fep.dim.x, sc->xStart);
         mtls->end.x = rsMin(mtls->fep.dim.x, sc->xEnd);
-        if (mtls->start.x >= mtls->end.x) return false;
+        if (mtls->start.x >= mtls->end.x) {
+            mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT,
+              "Failed to launch kernel; Invalid xStart or xEnd.");
+            return false;
+        }
     }
 
     if (!sc || (sc->yEnd == 0)) {
@@ -574,7 +578,11 @@
     } else {
         mtls->start.y = rsMin(mtls->fep.dim.y, sc->yStart);
         mtls->end.y = rsMin(mtls->fep.dim.y, sc->yEnd);
-        if (mtls->start.y >= mtls->end.y) return false;
+        if (mtls->start.y >= mtls->end.y) {
+            mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT,
+              "Failed to launch kernel; Invalid yStart or yEnd.");
+            return false;
+        }
     }
 
     if (!sc || (sc->zEnd == 0)) {
@@ -582,7 +590,11 @@
     } else {
         mtls->start.z = rsMin(mtls->fep.dim.z, sc->zStart);
         mtls->end.z = rsMin(mtls->fep.dim.z, sc->zEnd);
-        if (mtls->start.z >= mtls->end.z) return false;
+        if (mtls->start.z >= mtls->end.z) {
+            mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT,
+              "Failed to launch kernel; Invalid zStart or zEnd.");
+            return false;
+        }
     }
 
     if (!sc || (sc->arrayEnd == 0)) {
@@ -590,7 +602,11 @@
     } else {
         mtls->start.array[0] = rsMin(mtls->fep.dim.array[0], sc->arrayStart);
         mtls->end.array[0] = rsMin(mtls->fep.dim.array[0], sc->arrayEnd);
-        if (mtls->start.array[0] >= mtls->end.array[0]) return false;
+        if (mtls->start.array[0] >= mtls->end.array[0]) {
+            mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT,
+              "Failed to launch kernel; Invalid arrayStart or arrayEnd.");
+            return false;
+        }
     }
 
     if (!sc || (sc->array2End == 0)) {
@@ -598,7 +614,11 @@
     } else {
         mtls->start.array[1] = rsMin(mtls->fep.dim.array[1], sc->array2Start);
         mtls->end.array[1] = rsMin(mtls->fep.dim.array[1], sc->array2End);
-        if (mtls->start.array[1] >= mtls->end.array[1]) return false;
+        if (mtls->start.array[1] >= mtls->end.array[1]) {
+            mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT,
+              "Failed to launch kernel; Invalid array2Start or array2End.");
+            return false;
+        }
     }
 
     if (!sc || (sc->array3End == 0)) {
@@ -606,7 +626,11 @@
     } else {
         mtls->start.array[2] = rsMin(mtls->fep.dim.array[2], sc->array3Start);
         mtls->end.array[2] = rsMin(mtls->fep.dim.array[2], sc->array3End);
-        if (mtls->start.array[2] >= mtls->end.array[2]) return false;
+        if (mtls->start.array[2] >= mtls->end.array[2]) {
+            mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT,
+              "Failed to launch kernel; Invalid array3Start or array3End.");
+            return false;
+        }
     }
 
     if (!sc || (sc->array4End == 0)) {
@@ -614,7 +638,11 @@
     } else {
         mtls->start.array[3] = rsMin(mtls->fep.dim.array[3], sc->array4Start);
         mtls->end.array[3] = rsMin(mtls->fep.dim.array[3], sc->array4End);
-        if (mtls->start.array[3] >= mtls->end.array[3]) return false;
+        if (mtls->start.array[3] >= mtls->end.array[3]) {
+            mCtx->getContext()->setError(RS_ERROR_BAD_SCRIPT,
+              "Failed to launch kernel; Invalid array4Start or array4End.");
+            return false;
+        }
     }