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