Home | History | Annotate | Download | only in cppbasic
      1 
      2 #include "RenderScript.h"
      3 
      4 #include "ScriptC_mono.h"
      5 
      6 using namespace android;
      7 using namespace RSC;
      8 
      9 int main(int argc, char** argv)
     10 {
     11 
     12     sp<RS> rs = new RS();
     13     printf("New RS %p\n", rs.get());
     14 
     15     bool r = rs->init();
     16     printf("Init returned %i\n", r);
     17 
     18     sp<const Element> e = Element::RGBA_8888(rs);
     19     printf("Element %p\n", e.get());
     20 
     21     Type::Builder tb(rs, e);
     22     tb.setX(128);
     23     tb.setY(128);
     24     sp<const Type> t = tb.create();
     25     printf("Type %p\n", t.get());
     26 
     27 
     28     sp<Allocation> a1 = Allocation::createSized(rs, e, 1000);
     29     printf("Allocation %p\n", a1.get());
     30 
     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());
     34 
     35     ScriptC_mono* sc = new ScriptC_mono(rs);
     36     printf("new script\n");
     37 
     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 
     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     }
     52     ain->copy1DRangeFrom(0, t->getCount(), buf);
     53     delete [] buf;
     54 
     55     sc->forEach_root(ain, aout);
     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);
     61     printf("for each done\n");
     62 
     63     sc->invoke_bar(47, -3, 'c', -7, 14, -8);
     64 
     65     // Verify a simple kernel.
     66     {
     67         static const uint32_t xDim = 7;
     68         static const uint32_t yDim = 7;
     69         sp<const Element> e = Element::I32(rs);
     70         Type::Builder tb(rs, e);
     71         tb.setX(xDim);
     72         tb.setY(yDim);
     73         sp<const Type> t = tb.create();
     74         sp<Allocation> kern1_in = Allocation::createTyped(rs, t);
     75         sp<Allocation> kern1_out = Allocation::createTyped(rs, t);
     76 
     77         int *buf = new int[t->getCount()];
     78         for (uint32_t ct=0; ct < t->getCount(); ct++) {
     79             buf[ct] = 5;
     80         }
     81         kern1_in->copy2DRangeFrom(0, 0, xDim, yDim, buf);
     82         delete [] buf;
     83 
     84         sc->forEach_kern1(kern1_in, kern1_out);
     85         sc->forEach_verify_kern1(kern1_out);
     86 
     87         rs->finish();
     88         failed_alloc->copy1DTo(&failed);
     89     }
     90 
     91     printf("Deleting stuff\n");
     92     delete sc;
     93     printf("Delete OK\n");
     94 
     95     if (failed) {
     96         printf("TEST FAILED!\n");
     97     } else {
     98         printf("TEST PASSED!\n");
     99     }
    100 
    101     return failed;
    102 }
    103