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