WaitAttach.cpp revision 7d72c9e5ad10e85789a0bc2e63c3f918c609ae49
1#include <RenderScript.h>
2
3#include "ScriptC_simple.h"
4
5int main()
6{
7    static const int size = 8;
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::RGBA_8888(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    // Script is executed once, then the data is copied back when finished
22    sp<ScriptC_simple> s = new ScriptC_simple(rs);
23    s->forEach_simple_kernel(a, b);
24    uint32_t * output = new uint32_t[size*size];
25    b->copy2DRangeTo(0, 0, size, size, output);
26    delete [] output;
27
28    s->forEach_other_kernel(a, b);
29
30    rs->finish();
31    return 0;
32}
33