jniinfiniteloop.cpp revision dcecc0c8d22e894525e25a122ce25129b51338f2
1#include <memory> 2#include <unistd.h> 3 4#include <jni.h> 5#include <RenderScript.h> 6 7#include "ScriptC_infiniteLoop.h" 8 9using namespace android; 10using namespace RSC; 11 12extern "C" void JNICALL 13Java_com_android_rs_jniinfiniteloop_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); 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 sp<ScriptC_infiniteLoop> s = new ScriptC_infiniteLoop(rs); 35 36 // Test is designed to loop forever, waits for two seconds 37 // between each invocation of the kernel 38 bool forever = true; 39 while(forever) 40 { 41 s->forEach_simple_kernel(a, b); 42 sleep(2); 43 } 44 45 uint32_t * output = new uint32_t[size*size]; 46 b->copy2DRangeTo(0, 0, size, size, output); 47 delete [] output; 48} 49 50