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