compute.cpp revision 943eb670c86242755f5af7460d46578243e0401e
1
2#include "RenderScript.h"
3
4#include "ScriptC_mono.h"
5
6using namespace android;
7using namespace renderscriptCpp;
8
9int 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    sp<ScriptC_mono> sc = new ScriptC_mono(rs, NULL, 0);
36    printf("new script\n");
37
38    uint32_t *buf = new uint32_t[t->getCount()];
39    for (uint32_t ct=0; ct < t->getCount(); ct++) {
40        buf[ct] = ct | (ct << 16);
41    }
42    //ain->copy1DRangeFrom(0, 128*128, (int32_t *)buf, 128*128*4);
43    ain->copy1DRangeFromUnchecked(0, t->getCount(), buf, t->getCount()*4);
44
45    sc->forEach_root(ain, aout);
46    printf("for each done\n");
47
48    printf("Deleting stuff\n");
49    sc.clear();
50    t.clear();
51    a1.clear();
52    e.clear();
53    ain.clear();
54    aout.clear();
55    //    delete rs;
56    printf("Delete OK\n");
57}
58