Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 1 | |
| 2 | #include "RenderScript.h" |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 3 | |
Jason Sams | f1e6d22 | 2012-02-24 14:24:56 -0800 | [diff] [blame] | 4 | #include "ScriptC_mono.h" |
| 5 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 6 | using namespace android; |
Tim Murray | 9eb7f4b | 2012-11-16 14:02:18 -0800 | [diff] [blame] | 7 | using namespace RSC; |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 8 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 9 | int main(int argc, char** argv) |
| 10 | { |
| 11 | |
Tim Murray | 8d8fb3e | 2012-11-02 17:02:32 -0700 | [diff] [blame] | 12 | sp<RS> rs = new RS(); |
| 13 | printf("New RS %p\n", rs.get()); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 14 | |
Tim Murray | 8d8fb3e | 2012-11-02 17:02:32 -0700 | [diff] [blame] | 15 | bool r = rs->init(); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 16 | printf("Init returned %i\n", r); |
| 17 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 18 | sp<const Element> e = Element::RGBA_8888(rs); |
| 19 | printf("Element %p\n", e.get()); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 20 | |
| 21 | Type::Builder tb(rs, e); |
| 22 | tb.setX(128); |
| 23 | tb.setY(128); |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 24 | sp<const Type> t = tb.create(); |
| 25 | printf("Type %p\n", t.get()); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 26 | |
| 27 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 28 | sp<Allocation> a1 = Allocation::createSized(rs, e, 1000); |
| 29 | printf("Allocation %p\n", a1.get()); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 30 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 31 | sp<Allocation> ain = Allocation::createTyped(rs, t); |
| 32 | sp<Allocation> aout = Allocation::createTyped(rs, t); |
| 33 | printf("Allocation %p %p\n", ain.get(), aout.get()); |
Jason Sams | f1e6d22 | 2012-02-24 14:24:56 -0800 | [diff] [blame] | 34 | |
Tim Murray | 4a92d12 | 2013-07-22 10:56:18 -0700 | [diff] [blame^] | 35 | sp<ScriptC_mono> sc = new ScriptC_mono(rs); |
Jason Sams | f1e6d22 | 2012-02-24 14:24:56 -0800 | [diff] [blame] | 36 | printf("new script\n"); |
| 37 | |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 38 | // We read back the status from the script-side via a "failed" allocation. |
| 39 | sp<const Element> failed_e = Element::BOOLEAN(rs); |
| 40 | Type::Builder failed_tb(rs, failed_e); |
| 41 | failed_tb.setX(1); |
| 42 | sp<const Type> failed_t = failed_tb.create(); |
| 43 | sp<Allocation> failed_alloc = Allocation::createTyped(rs, failed_t); |
| 44 | bool failed = false; |
| 45 | failed_alloc->copy1DRangeFrom(0, failed_t->getCount(), &failed); |
| 46 | sc->bind_failed(failed_alloc); |
| 47 | |
Jason Sams | f1e6d22 | 2012-02-24 14:24:56 -0800 | [diff] [blame] | 48 | uint32_t *buf = new uint32_t[t->getCount()]; |
| 49 | for (uint32_t ct=0; ct < t->getCount(); ct++) { |
| 50 | buf[ct] = ct | (ct << 16); |
| 51 | } |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 52 | ain->copy1DRangeFrom(0, t->getCount(), buf); |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 53 | delete [] buf; |
Jason Sams | f1e6d22 | 2012-02-24 14:24:56 -0800 | [diff] [blame] | 54 | |
Jason Sams | f1e6d22 | 2012-02-24 14:24:56 -0800 | [diff] [blame] | 55 | sc->forEach_root(ain, aout); |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 56 | |
| 57 | sc->invoke_foo(99, 3.1f); |
| 58 | sc->set_g_f(39.9f); |
| 59 | sc->set_g_i(-14); |
| 60 | sc->invoke_foo(99, 3.1f); |
Jason Sams | f1e6d22 | 2012-02-24 14:24:56 -0800 | [diff] [blame] | 61 | printf("for each done\n"); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 62 | |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 63 | sc->invoke_bar(47, -3, 'c', -7, 14, -8); |
| 64 | |
| 65 | // Verify a simple kernel. |
| 66 | { |
| 67 | sp<const Element> e = Element::I32(rs); |
| 68 | Type::Builder tb(rs, e); |
Tim Murray | 4a92d12 | 2013-07-22 10:56:18 -0700 | [diff] [blame^] | 69 | tb.setX(8); |
| 70 | tb.setY(8); |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 71 | sp<const Type> t = tb.create(); |
| 72 | sp<Allocation> kern1_in = Allocation::createTyped(rs, t); |
| 73 | sp<Allocation> kern1_out = Allocation::createTyped(rs, t); |
| 74 | |
| 75 | int *buf = new int[t->getCount()]; |
| 76 | for (uint32_t ct=0; ct < t->getCount(); ct++) { |
| 77 | buf[ct] = 0; |
| 78 | } |
| 79 | kern1_in->copy1DFrom(buf); |
| 80 | delete [] buf; |
| 81 | |
| 82 | sc->forEach_kern1(kern1_in, kern1_out); |
| 83 | sc->forEach_verify_kern1(kern1_out); |
| 84 | |
| 85 | rs->finish(); |
| 86 | failed_alloc->copy1DTo(&failed); |
| 87 | |
| 88 | e.clear(); |
| 89 | t.clear(); |
| 90 | kern1_in.clear(); |
| 91 | kern1_out.clear(); |
| 92 | } |
| 93 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 94 | printf("Deleting stuff\n"); |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 95 | sc.clear(); |
| 96 | t.clear(); |
| 97 | a1.clear(); |
| 98 | e.clear(); |
Tim Murray | 16b9512 | 2012-10-31 16:02:59 -0700 | [diff] [blame] | 99 | ain.clear(); |
| 100 | aout.clear(); |
Tim Murray | 8d8fb3e | 2012-11-02 17:02:32 -0700 | [diff] [blame] | 101 | // delete rs; |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 102 | printf("Delete OK\n"); |
Stephen Hines | 43514cd | 2012-11-16 14:33:47 -0800 | [diff] [blame] | 103 | |
| 104 | if (failed) { |
| 105 | printf("TEST FAILED!\n"); |
| 106 | } else { |
| 107 | printf("TEST PASSED!\n"); |
| 108 | } |
| 109 | |
| 110 | return failed; |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 111 | } |