WaitAttach.cpp revision dcecc0c8d22e894525e25a122ce25129b51338f2
1#include <RenderScript.h> 2 3#include "ScriptC_simple.h" 4 5using namespace android; 6using namespace RSC; 7 8int main() 9{ 10 static const int size = 8; 11 sp<RS> rs = new RS(); 12 13 rs->init("/data/rscache", RS_INIT_LOW_LATENCY | RS_INIT_WAIT_FOR_ATTACH); 14 15 auto e = Element::RGBA_8888(rs); 16 Type::Builder tb(rs, e); 17 tb.setX(size); 18 tb.setY(size); 19 auto t = tb.create(); 20 21 auto a = Allocation::createTyped(rs, t); 22 auto b = Allocation::createTyped(rs, t); 23 24 // Script is executed once, then the data is copied back when finished 25 sp<ScriptC_simple> s = new ScriptC_simple(rs); 26 s->forEach_simple_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 s->forEach_other_kernel(a, b); 32 33 rs->finish(); 34 return 0; 35} 36