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 #include <unistd.h> 19 20 #include <jni.h> 21 #include <RenderScript.h> 22 23 #include "ScriptC_infiniteloop.h" 24 25 extern "C" void JNICALL 26 Java_com_android_rs_jniinfiniteloop_MainActivity_nativeRS( 27 JNIEnv * env, 28 jclass, 29 jstring pathObj) 30 { 31 static const int size = 64; 32 sp<RS> rs = new RS(); 33 34 const char * path = env->GetStringUTFChars(pathObj, nullptr); 35 rs->init(path, RS_INIT_LOW_LATENCY); 36 env->ReleaseStringUTFChars(pathObj, path); 37 38 auto e = Element::RGBA_8888(rs); 39 Type::Builder tb(rs, e); 40 tb.setX(size); 41 tb.setY(size); 42 auto t = tb.create(); 43 44 auto a = Allocation::createTyped(rs, t); 45 auto b = Allocation::createTyped(rs, t); 46 47 sp<ScriptC_infiniteloop> s = new ScriptC_infiniteloop(rs); 48 49 // Test is designed to loop forever, waits for two seconds 50 // between each invocation of the kernel 51 bool forever = true; 52 while(forever) 53 { 54 s->forEach_simple_kernel(a, b); 55 sleep(2); 56 } 57 58 uint32_t * output = new uint32_t[size*size]; 59 b->copy2DRangeTo(0, 0, size, size, output); 60 delete [] output; 61 } 62 63