jninodebugwaitattach.cpp revision dcecc0c8d22e894525e25a122ce25129b51338f2
1#include <memory> 2 3#include <jni.h> 4#include <RenderScript.h> 5 6#include "ScriptC_simple.h" 7 8using namespace android; 9using namespace RSC; 10 11extern "C" void JNICALL 12Java_com_android_rs_jninodebugwaitattach_MainActivity_nativeRS( 13 JNIEnv * env, 14 jclass, 15 jstring pathObj) 16{ 17 static const int size = 8; 18 sp<RS> rs = new RS(); 19 20 const char * path = env->GetStringUTFChars(pathObj, nullptr); 21 rs->init(path, RS_INIT_LOW_LATENCY | RS_INIT_WAIT_FOR_ATTACH); 22 env->ReleaseStringUTFChars(pathObj, path); 23 24 auto e = Element::RGBA_8888(rs); 25 Type::Builder tb(rs, e); 26 tb.setX(size); 27 tb.setY(size); 28 auto t = tb.create(); 29 30 auto a = Allocation::createTyped(rs, t); 31 auto b = Allocation::createTyped(rs, t); 32 33 // Script is executed once, then the data is copied back when finished 34 sp<ScriptC_simple> s = new ScriptC_simple(rs); 35 s->forEach_simple_kernel(a, b); 36 uint32_t * output = new uint32_t[size*size]; 37 b->copy2DRangeTo(0, 0, size, size, output); 38 delete [] output; 39 40 rs->finish(); 41} 42 43