jniinfiniteloop.cpp revision 7d72c9e5ad10e85789a0bc2e63c3f918c609ae49
1#include <memory>
2#include <unistd.h>
3
4#include <jni.h>
5#include <RenderScript.h>
6
7#include "ScriptC_infiniteloop.h"
8
9extern "C" void JNICALL
10Java_com_android_rs_jniinfiniteloop_MainActivity_nativeRS(
11    JNIEnv * env,
12    jclass,
13    jstring pathObj)
14{
15    static const int size = 64;
16    sp<RS> rs = new RS();
17
18    const char * path = env->GetStringUTFChars(pathObj, nullptr);
19    rs->init(path, RS_INIT_LOW_LATENCY);
20    env->ReleaseStringUTFChars(pathObj, path);
21
22    auto e = Element::RGBA_8888(rs);
23    Type::Builder tb(rs, e);
24    tb.setX(size);
25    tb.setY(size);
26    auto t = tb.create();
27
28    auto a = Allocation::createTyped(rs, t);
29    auto b = Allocation::createTyped(rs, t);
30
31    sp<ScriptC_infiniteloop> s = new ScriptC_infiniteloop(rs);
32
33    // Test is designed to loop forever, waits for two seconds
34    // between each invocation of the kernel
35    bool forever = true;
36    while(forever)
37    {
38        s->forEach_simple_kernel(a, b);
39        sleep(2);
40    }
41
42    uint32_t * output = new uint32_t[size*size];
43    b->copy2DRangeTo(0, 0, size, size, output);
44    delete [] output;
45}
46
47