MultipleRSFiles.cpp revision 7d72c9e5ad10e85789a0bc2e63c3f918c609ae49
1#include <RenderScript.h>
2
3#include "ScriptC_first.h"
4#include "ScriptC_second.h"
5
6int main()
7{
8    static const int size = 64;
9    sp<RS> rs = new RS();
10
11    rs->init("/data/rscache", RS_INIT_LOW_LATENCY | RS_INIT_WAIT_FOR_ATTACH);
12
13    auto e = Element::RGBA_8888(rs);
14    Type::Builder tb(rs, e);
15    tb.setX(size);
16    tb.setY(size);
17    auto t = tb.create();
18
19    auto a = Allocation::createTyped(rs, t);
20    auto b = Allocation::createTyped(rs, t);
21
22    // Script is executed once, then the data is copied back when finished
23    sp<ScriptC_first> s1 = new ScriptC_first(rs);
24    sp<ScriptC_second> s2 = new ScriptC_second(rs);
25
26    s1->forEach_first_kernel(a, b);
27    uint32_t * output = new uint32_t[size*size];
28    b->copy2DRangeTo(0, 0, size, size, output);
29    delete [] output;
30
31    s2->forEach_second_kernel(a, b);
32
33    rs->finish();
34    return 0;
35}
36