1 /*
2  * Copyright (C) 2013 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  */
16 
17 #include <jni.h>
18 #include <android/log.h>
19 
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <math.h>
23 
24 #include <RenderScript.h>
25 
26 #define  LOG_TAG    "rscpptest"
27 #define  LOGI(...)  __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__)
28 #define  LOGE(...)  __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__)
29 
30 #include "ScriptC_setelementat.h"
31 
32 using namespace android::RSC;
33 
createTypedHelper(const sp<RS> & rs,sp<const Element> e)34 static void createTypedHelper (const sp<RS> &rs, sp<const Element> e) {
35     Type::Builder typeBuilder(rs, e);
36     for (int mips = 0; mips <= 1; mips ++) {
37         bool useMips = (mips == 1);
38 
39         for (int faces = 0; faces <= 1; faces++) {
40             bool useFaces = (faces == 1);
41 
42             for (uint32_t x = 1; x < 8; x ++) {
43                 for (uint32_t y = 1; y < 8; y ++) {
44                     typeBuilder.setMipmaps(useMips);
45                     typeBuilder.setFaces(useFaces);
46                     typeBuilder.setX(x);
47                     typeBuilder.setY(y);
48                     Allocation::createTyped(rs, typeBuilder.create());
49                 }
50             }
51         }
52     }
53 
54 }
55 
Java_android_cts_rscpp_RSAllocationTest_typedTest(JNIEnv * env,jclass obj,jstring pathObj)56 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSAllocationTest_typedTest(JNIEnv * env,
57                                                                                         jclass obj,
58                                                                                         jstring pathObj)
59 {
60     const char * path = env->GetStringUTFChars(pathObj, NULL);
61     sp<RS> rs = new RS();
62     rs->init(path);
63     env->ReleaseStringUTFChars(pathObj, path);
64 
65     createTypedHelper(rs, Element::A_8(rs));
66     createTypedHelper(rs, Element::RGBA_4444(rs));
67     createTypedHelper(rs, Element::RGBA_5551(rs));
68     createTypedHelper(rs, Element::RGB_565(rs));
69     createTypedHelper(rs, Element::RGB_888(rs));
70     createTypedHelper(rs, Element::RGBA_8888(rs));
71     createTypedHelper(rs, Element::F32(rs));
72     createTypedHelper(rs, Element::F32_2(rs));
73     createTypedHelper(rs, Element::F32_3(rs));
74     createTypedHelper(rs, Element::F32_4(rs));
75     createTypedHelper(rs, Element::F64(rs));
76     createTypedHelper(rs, Element::F64_2(rs));
77     createTypedHelper(rs, Element::F64_3(rs));
78     createTypedHelper(rs, Element::F64_4(rs));
79     createTypedHelper(rs, Element::I8(rs));
80     createTypedHelper(rs, Element::I8_2(rs));
81     createTypedHelper(rs, Element::I8_3(rs));
82     createTypedHelper(rs, Element::I8_4(rs));
83     createTypedHelper(rs, Element::I16(rs));
84     createTypedHelper(rs, Element::I16_2(rs));
85     createTypedHelper(rs, Element::I16_3(rs));
86     createTypedHelper(rs, Element::I16_4(rs));
87     createTypedHelper(rs, Element::I32(rs));
88     createTypedHelper(rs, Element::I32_2(rs));
89     createTypedHelper(rs, Element::I32_3(rs));
90     createTypedHelper(rs, Element::I32_4(rs));
91     createTypedHelper(rs, Element::I64(rs));
92     createTypedHelper(rs, Element::I64_2(rs));
93     createTypedHelper(rs, Element::I64_3(rs));
94     createTypedHelper(rs, Element::I64_4(rs));
95     createTypedHelper(rs, Element::U8(rs));
96     createTypedHelper(rs, Element::U8_2(rs));
97     createTypedHelper(rs, Element::U8_3(rs));
98     createTypedHelper(rs, Element::U8_4(rs));
99     createTypedHelper(rs, Element::U16(rs));
100     createTypedHelper(rs, Element::U16_2(rs));
101     createTypedHelper(rs, Element::U16_3(rs));
102     createTypedHelper(rs, Element::U16_4(rs));
103     createTypedHelper(rs, Element::U32(rs));
104     createTypedHelper(rs, Element::U32_2(rs));
105     createTypedHelper(rs, Element::U32_3(rs));
106     createTypedHelper(rs, Element::U32_4(rs));
107     createTypedHelper(rs, Element::U64(rs));
108     createTypedHelper(rs, Element::U64_2(rs));
109     createTypedHelper(rs, Element::U64_3(rs));
110     createTypedHelper(rs, Element::U64_4(rs));
111     createTypedHelper(rs, Element::MATRIX_2X2(rs));
112     createTypedHelper(rs, Element::MATRIX_3X3(rs));
113     createTypedHelper(rs, Element::MATRIX_4X4(rs));
114     createTypedHelper(rs, Element::SAMPLER(rs));
115     createTypedHelper(rs, Element::SCRIPT(rs));
116     createTypedHelper(rs, Element::TYPE(rs));
117     createTypedHelper(rs, Element::BOOLEAN(rs));
118     createTypedHelper(rs, Element::ELEMENT(rs));
119     createTypedHelper(rs, Element::ALLOCATION(rs));
120 
121     rs->finish();
122     return true;
123 }
124 
makeElement(const sp<RS> & rs,RsDataType dt,int vecSize)125 static sp<const Element> makeElement(const sp<RS> &rs, RsDataType dt, int vecSize) {
126     if (vecSize > 1) {
127         return Element::createVector(rs, dt, vecSize);
128     } else {
129         return Element::createUser(rs, dt);
130     }
131 }
132 
133 /**
134  * Test copyTo and copyFrom for all or part of a 1D Allocation.
135  *
136  * @param rs RS Context.
137  * @param cellCount Total number of elements in this Allocation.
138  * @param offset Offset of this Allocation for copy.
139  * @param count Number of elements need to copy.
140  * @param copyRange Copy the entire allocation or part of it (using different API).
141  * @param dt DataType intended to test.
142  * @param autoPadding Enable autoPadding or not.
143 */
144 template <class T>
helperCopy1D(const sp<RS> & rs,int cellCount,int offset,int count,bool copyRange,RsDataType dt,bool autoPadding=false)145 static bool helperCopy1D(const sp<RS> &rs, int cellCount, int offset, int count, bool copyRange,
146                          RsDataType dt, bool autoPadding = false) {
147     bool passed = true;
148     int arrLen = cellCount;
149     int copyCount = count;
150     int iOffset = offset;
151     sp<Allocation> alloc = nullptr;
152 
153     if (autoPadding) {
154         arrLen = cellCount * 3;
155         copyCount = count * 3;
156         iOffset = offset * 3;
157         alloc = Allocation::createSized(rs, makeElement(rs, dt, 3), cellCount);
158         alloc->setAutoPadding(autoPadding);
159     } else {
160         alloc = Allocation::createSized(rs, makeElement(rs, dt, 1), cellCount);
161     }
162 
163     T* src = new T[arrLen];
164     T* dst = new T[arrLen];
165 
166     for (int i = 0; i < copyCount; i++) {
167         src[i] = (T)rand();
168         dst[iOffset + i] = (T)(-1);
169     }
170 
171     if (!copyRange) {
172         alloc->copy1DFrom(src);
173     } else {
174         alloc->copy1DRangeFrom(offset, count, src);
175     }
176     alloc->copy1DTo(dst);
177 
178     for (int i = 0; i < copyCount; i++) {
179         if (dst[iOffset + i] != src[i]) {
180             passed = false;
181             break;
182         }
183     }
184 
185     delete[] src;
186     delete[] dst;
187     return passed;
188 }
189 
190 //Corresponding 1D allocation to allocation copy.
helperFloatAllocationCopy1D(const sp<RS> & rs,int cellCount,int offset,int count)191 static bool helperFloatAllocationCopy1D(const sp<RS> &rs, int cellCount, int offset, int count) {
192 
193     bool passed = true;
194     sp<Allocation> srcA = Allocation::createSized(rs, Element::F32(rs), cellCount);
195     sp<Allocation> dstA = Allocation::createSized(rs, Element::F32(rs), cellCount);
196 
197     float *src, *dst;
198     src = new float[cellCount];
199     dst = new float[cellCount];
200     for (int i = 0; i < cellCount; i++) {
201         src[i] = (float)rand();
202         dst[i] = -1.0f;
203     }
204 
205     // First populate the source allocation
206     srcA->copy1DFrom(src);
207     // Now test allocation to allocation copy
208     dstA->copy1DRangeFrom(offset, count, srcA, offset);
209     dstA->copy1DTo(dst);
210 
211     for (int i = 0; i < count; i++) {
212         if (dst[offset + i] != src[offset + i]) {
213             passed = false;
214             break;
215         }
216     }
217 
218     delete[] src;
219     delete[] dst;
220     return passed;
221 }
222 
223 /**
224  * Test copyTo and copyFrom for all or part of a 2D Allocation.
225  *
226  * @param rs RS Context.
227  * @param xElems Number of elements in X dimension in this Allocation.
228  * @param yElems Number of elements in Y dimension in this Allocation.
229  * @param xOffset Offset in X dimension of this Allocation for copy.
230  * @param yOffset Offset in Y dimension of this Allocation for copy.
231  * @param xCount Number of elements in X dimension need to copy.
232  * @param yCount Number of elements in Y dimension need to copy.
233  * @param dt DataType intended to test.
234  * @param autoPadding Enable autoPadding or not.
235 */
236 template <class T>
helperCopy2D(const sp<RS> & rs,int xElems,int yElems,int xOffset,int yOffset,int xCount,int yCount,RsDataType dt,bool autoPadding=false)237 static bool helperCopy2D(const sp<RS> &rs, int xElems, int yElems,
238                          int xOffset, int yOffset, int xCount, int yCount,
239                          RsDataType dt, bool autoPadding = false) {
240     bool passed = true;
241     int arrLen = xElems * yElems;
242     int copyCount = xCount * yCount;
243     sp<Allocation> alloc = nullptr;
244 
245     if (autoPadding) {
246         arrLen = arrLen * 3;
247         copyCount = copyCount * 3;
248         alloc = Allocation::createSized2D(rs, makeElement(rs, dt, 3), xElems, yElems);
249         alloc->setAutoPadding(autoPadding);
250     } else {
251         alloc = Allocation::createSized2D(rs, makeElement(rs, dt, 1), xElems, yElems);
252     }
253 
254     T* src = new T[arrLen];
255     T* dst = new T[arrLen];
256 
257     for (int i = 0; i < copyCount; i++) {
258         src[i] = (T)rand();
259         dst[i] = (T)(-1);
260     }
261 
262     alloc->copy2DRangeFrom(xOffset, yOffset, xCount, yCount, src);
263     alloc->copy2DRangeTo(xOffset, yOffset, xCount, yCount, dst);
264 
265     for (int i = 0; i < copyCount; i++) {
266         if (dst[i] != src[i]) {
267             passed = false;
268             break;
269         }
270     }
271 
272     delete[] src;
273     delete[] dst;
274     return passed;
275 }
276 
277 //Corresponding 2D allocation to allocation copy.
helperFloatAllocationCopy2D(const sp<RS> & rs,int xElems,int yElems,int xOffset,int yOffset,int xCount,int yCount)278 static bool helperFloatAllocationCopy2D(const sp<RS> &rs, int xElems, int yElems,
279                                         int xOffset, int yOffset, int xCount, int yCount) {
280 
281     bool passed = true;
282     sp<Allocation> srcA = Allocation::createSized2D(rs, Element::F32(rs), xElems, yElems);
283     sp<Allocation> dstA = Allocation::createSized2D(rs, Element::F32(rs), xElems, yElems);
284 
285     float *src, *dst;
286     src = new float[xElems * yElems];
287     dst = new float[xElems * yElems];
288     for (int i = 0; i < xCount * yCount; i++) {
289         src[i] = (float)rand();
290         dst[i] = -1.0f;
291     }
292 
293     // First populate the source allocation
294     srcA->copy2DRangeFrom(xOffset, yOffset, xCount, yCount, src);
295     // Now test allocation to allocation copy
296     dstA->copy2DRangeFrom(xOffset, yOffset, xCount, yCount, srcA, xOffset, yOffset);
297     dstA->copy2DRangeTo(xOffset, yOffset, xCount, yCount, dst);
298 
299     for (int i = 0; i < xCount * yCount; i++) {
300         if (dst[i] != src[i]) {
301             passed = false;
302             break;
303         }
304     }
305 
306     delete[] src;
307     delete[] dst;
308     return passed;
309 }
310 
311 /**
312  * Test copyTo and copyFrom for all or part of a 2D Allocation.
313  *
314  * @param rs RS Context.
315  * @param xElems Number of elements in X dimension in this Allocation.
316  * @param yElems Number of elements in Y dimension in this Allocation.
317  * @param zElems Number of elements in Z dimension in this Allocation.
318  * @param xOffset Offset in X dimension of this Allocation for copy.
319  * @param yOffset Offset in Y dimension of this Allocation for copy.
320  * @param zOffset Offset in Z dimension of this Allocation for copy.
321  * @param xCount Number of elements in X dimension need to copy.
322  * @param yCount Number of elements in Y dimension need to copy.
323  * @param zCount Number of elements in Z dimension need to copy.
324  * @param dt DataType intended to test.
325  * @param autoPadding Enable autoPadding or not.
326 */
327 template <class T>
helperCopy3D(const sp<RS> & rs,int xElems,int yElems,int zElems,int xOffset,int yOffset,int zOffset,int xCount,int yCount,int zCount,RsDataType dt,bool autoPadding=false)328 static bool helperCopy3D(const sp<RS> &rs, int xElems, int yElems, int zElems,
329                          int xOffset, int yOffset, int zOffset,
330                          int xCount, int yCount, int zCount,
331                          RsDataType dt, bool autoPadding = false) {
332     bool passed = true;
333     int arrLen = xElems * yElems * zElems;
334     int copyCount = xCount * yCount * zCount;
335     sp<Allocation> alloc = nullptr;
336 
337     if (autoPadding) {
338         arrLen = arrLen * 3;
339         copyCount = copyCount * 3;
340 
341         Type::Builder typeBuilder(rs, makeElement(rs, dt, 3));
342         typeBuilder.setX(xElems);
343         typeBuilder.setY(yElems);
344         typeBuilder.setZ(zElems);
345 
346         alloc = Allocation::createTyped(rs, typeBuilder.create());
347         alloc->setAutoPadding(autoPadding);
348     } else {
349         Type::Builder typeBuilder(rs, makeElement(rs, dt, 1));
350         typeBuilder.setX(xElems);
351         typeBuilder.setY(yElems);
352         typeBuilder.setZ(zElems);
353 
354         alloc = Allocation::createTyped(rs, typeBuilder.create());
355     }
356 
357     T* src = new T[arrLen];
358     T* dst = new T[arrLen];
359 
360     for (int i = 0; i < copyCount; i++) {
361         src[i] = (T)rand();
362         dst[i] = (T)(-1);
363     }
364 
365     alloc->copy3DRangeFrom(xOffset, yOffset, zOffset, xCount, yCount, zCount, src);
366     alloc->copy3DRangeTo(xOffset, yOffset, zOffset, xCount, yCount, zCount, dst);
367 
368     for (int i = 0; i < copyCount; i++) {
369         if (dst[i] != src[i]) {
370             passed = false;
371             break;
372         }
373     }
374 
375     delete[] src;
376     delete[] dst;
377     return passed;
378 }
379 
380 //Corresponding 3D allocation to allocation copy.
helperFloatAllocationCopy3D(const sp<RS> & rs,int xElems,int yElems,int zElems,int xOffset,int yOffset,int zOffset,int xCount,int yCount,int zCount)381 static bool helperFloatAllocationCopy3D(const sp<RS> &rs, int xElems, int yElems, int zElems,
382                                         int xOffset, int yOffset, int zOffset,
383                                         int xCount, int yCount, int zCount) {
384 
385     bool passed = true;
386     Type::Builder typeBuilder(rs, Element::F32(rs));
387 
388     typeBuilder.setX(xElems);
389     typeBuilder.setY(yElems);
390     typeBuilder.setZ(zElems);
391 
392     sp<Allocation> srcA = Allocation::createTyped(rs, typeBuilder.create());
393     sp<Allocation> dstA = Allocation::createTyped(rs, typeBuilder.create());
394 
395     float *src, *dst;
396     src = new float[xElems * yElems * zElems];
397     dst = new float[xElems * yElems * zElems];
398     for (int i = 0; i < xCount * yCount * zCount; i++) {
399         src[i] = (float)rand();
400         dst[i] = -1.0f;
401     }
402 
403     // First populate the source allocation
404     srcA->copy3DRangeFrom(xOffset, yOffset, zOffset, xCount, yCount, zCount, src);
405     // Now test allocation to allocation copy
406     dstA->copy3DRangeFrom(xOffset, yOffset, zOffset, xCount, yCount, zCount,
407                           srcA, xOffset, yOffset, zOffset);
408     dstA->copy3DRangeTo(xOffset, yOffset, zOffset, xCount, yCount, zCount, dst);
409 
410     for (int i = 0; i < xCount * yCount * zCount; i++) {
411         if (dst[i] != src[i]) {
412             passed = false;
413             break;
414         }
415     }
416 
417     delete[] src;
418     delete[] dst;
419     return passed;
420 }
421 
422 static int elemsToTest = 20;
423 
Java_android_cts_rscpp_RSAllocationTest_test1DCopy(JNIEnv * env,jclass obj,jstring pathObj)424 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSAllocationTest_test1DCopy(JNIEnv * env,
425                                                                                          jclass obj,
426                                                                                          jstring pathObj)
427 {
428     const char * path = env->GetStringUTFChars(pathObj, NULL);
429     sp<RS> rs = new RS();
430     rs->init(path);
431     env->ReleaseStringUTFChars(pathObj, path);
432     bool passed = true;
433 
434     for (int s = 8; s <= elemsToTest; s += 2) {
435         passed &= helperCopy1D<float>(rs, s, 0, s, false, RS_TYPE_FLOAT_32);
436         passed &= helperCopy1D<char>(rs, s, 0, s, false, RS_TYPE_SIGNED_8);
437         passed &= helperCopy1D<short>(rs, s, 0, s, false, RS_TYPE_SIGNED_16);
438         passed &= helperCopy1D<int>(rs, s, 0, s, false, RS_TYPE_SIGNED_32);
439         passed &= helperCopy1D<double>(rs, s, 0, s, false, RS_TYPE_FLOAT_64);
440 
441         // now test copy range
442         for (int off = 0; off < s; off ++) {
443             for (int count = 1; count <= s - off; count ++) {
444                 passed &= helperCopy1D<float>(rs, s, off, count, true, RS_TYPE_FLOAT_32);
445                 passed &= helperCopy1D<char>(rs, s, off, count, true, RS_TYPE_SIGNED_8);
446                 passed &= helperCopy1D<short>(rs, s, off, count, true, RS_TYPE_SIGNED_16);
447                 passed &= helperCopy1D<int>(rs, s, off, count, true, RS_TYPE_SIGNED_32);
448                 passed &= helperCopy1D<double>(rs, s, off, count, true, RS_TYPE_FLOAT_64);
449             }
450         }
451 
452         for (int off = 0; off < s; off ++) {
453             for (int count = 1; count <= s - off; count ++) {
454                 passed &= helperFloatAllocationCopy1D(rs, s, off, count);
455             }
456         }
457     }
458     return passed;
459 }
460 
Java_android_cts_rscpp_RSAllocationTest_test2DCopy(JNIEnv * env,jclass obj,jstring pathObj)461 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSAllocationTest_test2DCopy(JNIEnv * env,
462                                                                                          jclass obj,
463                                                                                          jstring pathObj)
464 {
465     const char * path = env->GetStringUTFChars(pathObj, NULL);
466     sp<RS> rs = new RS();
467     rs->init(path);
468     env->ReleaseStringUTFChars(pathObj, path);
469     bool passed = true;
470 
471     for (int s = 8; s <= elemsToTest; s += 2) {
472         // now test copy range
473         for (int off = 0; off < s; off ++) {
474             for (int count = 1; count <= s - off; count ++) {
475                 passed &= helperCopy2D<float>(rs, s, s, off, off, count, count, RS_TYPE_FLOAT_32);
476                 passed &= helperCopy2D<char>(rs, s, s, off, off, count, count, RS_TYPE_SIGNED_8);
477                 passed &= helperCopy2D<short>(rs, s, s, off, off, count, count, RS_TYPE_SIGNED_16);
478                 passed &= helperCopy2D<int>(rs, s, s, off, off, count, count, RS_TYPE_SIGNED_32);
479                 passed &= helperCopy2D<double>(rs, s, s, off, off, count, count, RS_TYPE_FLOAT_64);
480             }
481         }
482 
483         for (int off = 0; off < s; off ++) {
484             for (int count = 1; count <= s - off; count ++) {
485                 passed &= helperFloatAllocationCopy2D(rs, s, s, off, off, count, count);
486             }
487         }
488     }
489     return passed;
490 }
491 
Java_android_cts_rscpp_RSAllocationTest_test3DCopy(JNIEnv * env,jclass obj,jstring pathObj)492 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSAllocationTest_test3DCopy(JNIEnv * env,
493                                                                                          jclass obj,
494                                                                                          jstring pathObj)
495 {
496     const char * path = env->GetStringUTFChars(pathObj, NULL);
497     sp<RS> rs = new RS();
498     rs->init(path);
499     env->ReleaseStringUTFChars(pathObj, path);
500     bool passed = true;
501 
502     for (int s = 8; s <= elemsToTest; s += 2) {
503         // now test copy range
504         for (int off = 0; off < s; off ++) {
505             for (int count = 1; count <= s - off; count ++) {
506                 passed &= helperCopy3D<float>(rs, s, s, s, off, off, off, count, count, count, RS_TYPE_FLOAT_32);
507                 passed &= helperCopy3D<char>(rs, s, s, s, off, off, off, count, count, count, RS_TYPE_SIGNED_8);
508                 passed &= helperCopy3D<short>(rs, s, s, s, off, off, off, count, count, count, RS_TYPE_SIGNED_16);
509                 passed &= helperCopy3D<int>(rs, s, s, s, off, off, off, count, count, count, RS_TYPE_SIGNED_32);
510                 passed &= helperCopy3D<double>(rs, s, s, s, off, off, off, count, count, count, RS_TYPE_FLOAT_64);
511             }
512         }
513 
514         for (int off = 0; off < s; off ++) {
515             for (int count = 1; count <= s - off; count ++) {
516                 passed &= helperFloatAllocationCopy3D(rs, s, s, s, off, off, off, count, count, count);
517             }
518         }
519     }
520     return passed;
521 }
522 
Java_android_cts_rscpp_RSAllocationTest_test1DCopyPadded(JNIEnv * env,jclass obj,jstring pathObj)523 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSAllocationTest_test1DCopyPadded(JNIEnv * env,
524                                                                                                jclass obj,
525                                                                                                jstring pathObj)
526 {
527     const char * path = env->GetStringUTFChars(pathObj, NULL);
528     sp<RS> rs = new RS();
529     rs->init(path);
530     env->ReleaseStringUTFChars(pathObj, path);
531     bool passed = true;
532 
533     for (int s = 8; s <= elemsToTest; s += 2) {
534         passed &= helperCopy1D<float>(rs, s, 0, s, false, RS_TYPE_FLOAT_32, true);
535         passed &= helperCopy1D<char>(rs, s, 0, s, false, RS_TYPE_SIGNED_8, true);
536         passed &= helperCopy1D<short>(rs, s, 0, s, false, RS_TYPE_SIGNED_16, true);
537         passed &= helperCopy1D<int>(rs, s, 0, s, false, RS_TYPE_SIGNED_32, true);
538         passed &= helperCopy1D<double>(rs, s, 0, s, false, RS_TYPE_FLOAT_64, true);
539 
540         // now test copy range
541         for (int off = 0; off < s; off ++) {
542             for (int count = 1; count <= s - off; count ++) {
543                 passed &= helperCopy1D<float>(rs, s, off, count, true, RS_TYPE_FLOAT_32, true);
544                 passed &= helperCopy1D<char>(rs, s, off, count, true, RS_TYPE_SIGNED_8, true);
545                 passed &= helperCopy1D<short>(rs, s, off, count, true, RS_TYPE_SIGNED_16, true);
546                 passed &= helperCopy1D<int>(rs, s, off, count, true, RS_TYPE_SIGNED_32, true);
547                 passed &= helperCopy1D<double>(rs, s, off, count, true, RS_TYPE_FLOAT_64, true);
548             }
549         }
550     }
551     return passed;
552 }
553 
Java_android_cts_rscpp_RSAllocationTest_test2DCopyPadded(JNIEnv * env,jclass obj,jstring pathObj)554 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSAllocationTest_test2DCopyPadded(JNIEnv * env,
555                                                                                                jclass obj,
556                                                                                                jstring pathObj)
557 {
558     const char * path = env->GetStringUTFChars(pathObj, NULL);
559     sp<RS> rs = new RS();
560     rs->init(path);
561     env->ReleaseStringUTFChars(pathObj, path);
562     bool passed = true;
563 
564     for (int s = 8; s <= elemsToTest; s += 2) {
565         // now test copy range
566         for (int off = 0; off < s; off ++) {
567             for (int count = 1; count <= s - off; count ++) {
568                 passed &= helperCopy2D<float>(rs, s, s, off, off, count, count, RS_TYPE_FLOAT_32, true);
569                 passed &= helperCopy2D<char>(rs, s, s, off, off, count, count, RS_TYPE_SIGNED_8, true);
570                 passed &= helperCopy2D<short>(rs, s, s, off, off, count, count, RS_TYPE_SIGNED_16, true);
571                 passed &= helperCopy2D<int>(rs, s, s, off, off, count, count, RS_TYPE_SIGNED_32, true);
572                 passed &= helperCopy2D<double>(rs, s, s, off, off, count, count, RS_TYPE_FLOAT_64, true);
573             }
574         }
575     }
576     return passed;
577 }
578 
Java_android_cts_rscpp_RSAllocationTest_test3DCopyPadded(JNIEnv * env,jclass obj,jstring pathObj)579 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSAllocationTest_test3DCopyPadded(JNIEnv * env,
580                                                                                                jclass obj,
581                                                                                                jstring pathObj)
582 {
583     const char * path = env->GetStringUTFChars(pathObj, NULL);
584     sp<RS> rs = new RS();
585     rs->init(path);
586     env->ReleaseStringUTFChars(pathObj, path);
587     bool passed = true;
588 
589     for (int s = 8; s <= elemsToTest; s += 2) {
590         // now test copy range
591         for (int off = 0; off < s; off ++) {
592             for (int count = 1; count <= s - off; count ++) {
593                 passed &= helperCopy3D<float>(rs, s, s, s, off, off, off, count, count, count,
594                                               RS_TYPE_FLOAT_32, true);
595                 passed &= helperCopy3D<char>(rs, s, s, s, off, off, off, count, count, count,
596                                              RS_TYPE_SIGNED_8, true);
597                 passed &= helperCopy3D<short>(rs, s, s, s, off, off, off, count, count, count,
598                                               RS_TYPE_SIGNED_16, true);
599                 passed &= helperCopy3D<int>(rs, s, s, s, off, off, off, count, count, count,
600                                             RS_TYPE_SIGNED_32, true);
601                 passed &= helperCopy3D<double>(rs, s, s, s, off, off, off, count, count, count,
602                                                RS_TYPE_FLOAT_64, true);
603             }
604         }
605     }
606     return passed;
607 }
608 
Java_android_cts_rscpp_RSAllocationTest_testSetElementAt(JNIEnv * env,jclass obj,jstring pathObj)609 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSAllocationTest_testSetElementAt(JNIEnv * env,
610                                                                                                jclass obj,
611                                                                                                jstring pathObj)
612 {
613     const char * path = env->GetStringUTFChars(pathObj, NULL);
614     sp<RS> rs = new RS();
615     rs->init(path);
616     env->ReleaseStringUTFChars(pathObj, path);
617 
618     bool passed = true;
619 
620     Type::Builder b(rs, Element::I32(rs));
621     b.setX(48);
622     sp<Allocation> largeArray = Allocation::createTyped(rs, b.create());
623     b.setX(1);
624     sp<Allocation> singleElement = Allocation::createTyped(rs, b.create());
625 
626     sp<ScriptC_setelementat> script = new ScriptC_setelementat(rs);
627 
628     script->set_memset_toValue(1);
629     script->forEach_memset(singleElement);
630 
631     script->set_dimX(48);
632     script->set_array(largeArray);
633 
634     script->forEach_setLargeArray(singleElement);
635 
636     int result = 0;
637 
638     script->set_compare_value(10);
639     script->forEach_compare(largeArray);
640     script->forEach_getCompareResult(singleElement);
641     singleElement->copy1DTo(&result);
642     if (result != 2) {
643         passed = false;
644     }
645 
646     return passed;
647 }
648