jninodebugwaitattach.cpp revision 5bbcc3861c44435f89481f80946ef5c9c49968f2
1/* 2* Copyright (C) 2016 The Android Open Source Project 3* 4* Licensed under the Apache License, Version 2.0 (the "License"); 5* you may not use this file except in compliance with the License. 6* You may obtain a copy of the License at 7* 8* http://www.apache.org/licenses/LICENSE-2.0 9* 10* Unless required by applicable law or agreed to in writing, software 11* distributed under the License is distributed on an "AS IS" BASIS, 12* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13* See the License for the specific language governing permissions and 14* limitations under the License. 15*/ 16 17#include <memory> 18 19#include <jni.h> 20#include <RenderScript.h> 21 22#include "ScriptC_simple.h" 23 24using namespace android; 25using namespace RSC; 26 27extern "C" void JNICALL 28Java_com_android_rs_jninodebugwaitattach_MainActivity_nativeRS( 29 JNIEnv * env, 30 jclass, 31 jstring pathObj) 32{ 33 static const int size = 8; 34 sp<RS> rs = new RS(); 35 36 const char * path = env->GetStringUTFChars(pathObj, nullptr); 37 rs->init(path, RS_INIT_LOW_LATENCY | RS_INIT_WAIT_FOR_ATTACH); 38 env->ReleaseStringUTFChars(pathObj, path); 39 40 auto e = Element::RGBA_8888(rs); 41 Type::Builder tb(rs, e); 42 tb.setX(size); 43 tb.setY(size); 44 auto t = tb.create(); 45 46 auto a = Allocation::createTyped(rs, t); 47 auto b = Allocation::createTyped(rs, t); 48 49 // Script is executed once, then the data is copied back when finished 50 sp<ScriptC_simple> s = new ScriptC_simple(rs); 51 s->forEach_simple_kernel(a, b); 52 uint32_t * output = new uint32_t[size*size]; 53 b->copy2DRangeTo(0, 0, size, size, output); 54 delete [] output; 55 56 rs->finish(); 57} 58 59