1 /* 2 * Copyright (C) 2015 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 <jni.h> 18 #include <android/log.h> 19 20 #include <stdio.h> 21 #include <stdlib.h> 22 #include <math.h> 23 24 #include <RenderScript.h> 25 26 #define LOG_TAG "rscpptest" 27 #define LOGI(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) 28 #define LOGE(...) __android_log_print(ANDROID_LOG_ERROR,LOG_TAG,__VA_ARGS__) 29 30 #include <ScriptC_clear_object.h> 31 32 using namespace android::RSC; 33 34 #define ObjectNum 1 35 36 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSObjectTest_testClearObjectElement(JNIEnv * env, 37 jclass obj, 38 jstring pathObj) 39 { 40 const char * path = env->GetStringUTFChars(pathObj, nullptr); 41 sp<RS> mRS = new RS(); 42 mRS->init(path); 43 env->ReleaseStringUTFChars(pathObj, path); 44 45 bool passed = true; 46 47 sp<ScriptC_clear_object> ms_clear = new ScriptC_clear_object(mRS); 48 49 sp<const Element> element = Element::BOOLEAN(mRS); 50 sp<Allocation> mOut = Allocation::createSized(mRS, Element::I32(mRS), ObjectNum); 51 ms_clear->set_element(element); 52 ms_clear->forEach_clear_element(mOut); 53 54 int tmpArray[ObjectNum]; 55 mOut->copy1DTo(tmpArray); 56 57 for(int i = 0; i < ObjectNum; i++) { 58 passed &= (tmpArray[i] == 1); 59 } 60 61 return passed; 62 } 63 64 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSObjectTest_testClearObjectType(JNIEnv * env, 65 jclass obj, 66 jstring pathObj) 67 { 68 const char * path = env->GetStringUTFChars(pathObj, nullptr); 69 sp<RS> mRS = new RS(); 70 mRS->init(path); 71 env->ReleaseStringUTFChars(pathObj, path); 72 73 bool passed = true; 74 75 sp<ScriptC_clear_object> ms_clear = new ScriptC_clear_object(mRS); 76 77 sp<const Type> type= Type::create(mRS, Element::I8(mRS), 1, 0, 0); 78 sp<Allocation> mOut = Allocation::createSized(mRS, Element::I32(mRS), ObjectNum); 79 ms_clear->set_type(type); 80 ms_clear->forEach_clear_type(mOut); 81 82 int tmpArray[ObjectNum]; 83 mOut->copy1DTo(tmpArray); 84 85 for(int i = 0; i < ObjectNum; i++) { 86 passed &= (tmpArray[i] == 1); 87 } 88 89 return passed; 90 } 91 92 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSObjectTest_testClearObjectAllocation(JNIEnv * env, 93 jclass obj, 94 jstring pathObj) 95 { 96 const char * path = env->GetStringUTFChars(pathObj, nullptr); 97 sp<RS> mRS = new RS(); 98 mRS->init(path); 99 env->ReleaseStringUTFChars(pathObj, path); 100 101 bool passed = true; 102 103 sp<ScriptC_clear_object> ms_clear = new ScriptC_clear_object(mRS); 104 105 sp<Allocation> mOut = Allocation::createSized(mRS, Element::I32(mRS), ObjectNum); 106 sp<Allocation> mIn = Allocation::createSized(mRS, Element::I32(mRS), ObjectNum); 107 sp<Allocation> allocation = Allocation::createTyped(mRS, mIn->getType()); 108 ms_clear->set_allocation(allocation); 109 ms_clear->forEach_clear_allocation(mOut); 110 111 int tmpArray[ObjectNum]; 112 mOut->copy1DTo(tmpArray); 113 114 for(int i = 0; i < ObjectNum; i++) { 115 passed &= (tmpArray[i] == 1); 116 } 117 118 return passed; 119 } 120 121 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSObjectTest_testClearObjectSampler(JNIEnv * env, 122 jclass obj, 123 jstring pathObj) 124 { 125 const char * path = env->GetStringUTFChars(pathObj, nullptr); 126 sp<RS> mRS = new RS(); 127 mRS->init(path); 128 env->ReleaseStringUTFChars(pathObj, path); 129 130 bool passed = true; 131 132 sp<ScriptC_clear_object> ms_clear = new ScriptC_clear_object(mRS); 133 134 sp<Sampler> sampler = Sampler::create(mRS, RS_SAMPLER_NEAREST, RS_SAMPLER_NEAREST, 135 RS_SAMPLER_WRAP, RS_SAMPLER_WRAP, 1.0f); 136 sp<Allocation> mOut = Allocation::createSized(mRS, Element::I32(mRS), ObjectNum); 137 ms_clear->set_sampler(sampler); 138 ms_clear->forEach_clear_sampler(mOut); 139 140 int tmpArray[ObjectNum]; 141 mOut->copy1DTo(tmpArray); 142 143 for(int i = 0; i < ObjectNum; i++) { 144 passed &= (tmpArray[i] == 1); 145 } 146 147 148 return passed; 149 } 150 151 extern "C" JNIEXPORT jboolean JNICALL Java_android_cts_rscpp_RSObjectTest_testClearObjectScript(JNIEnv * env, 152 jclass obj, 153 jstring pathObj) 154 { 155 const char * path = env->GetStringUTFChars(pathObj, nullptr); 156 sp<RS> mRS = new RS(); 157 mRS->init(path); 158 env->ReleaseStringUTFChars(pathObj, path); 159 160 bool passed = true; 161 162 sp<ScriptC_clear_object> ms_clear = new ScriptC_clear_object(mRS); 163 164 sp<Script> script = new ScriptC_clear_object(mRS); 165 sp<Allocation> mOut = Allocation::createSized(mRS, Element::I32(mRS), ObjectNum); 166 ms_clear->set_script(script); 167 ms_clear->forEach_clear_script(mOut); 168 169 int tmpArray[ObjectNum]; 170 mOut->copy1DTo(tmpArray); 171 172 for(int i = 0; i < ObjectNum; i++) { 173 passed &= (tmpArray[i] == 1); 174 } 175 176 return passed; 177 } 178