RSScript.cpp revision 06731a6150ae8014d37258d5f32ef8bc14a3db63
1/* 2 * Copyright 2012, 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 "bcc/Renderscript/RSScript.h" 18 19#include "bcc/Renderscript/RSInfo.h" 20#include "bcc/Source.h" 21#include "bcc/Support/Log.h" 22 23using namespace bcc; 24 25bool RSScript::LinkRuntime(RSScript &pScript, const char *rt_path) { 26 // Using the same context with the source in pScript. 27 BCCContext &context = pScript.getSource().getContext(); 28 const char* core_lib = RSInfo::LibCLCorePath; 29 30 // NEON-capable devices can use an accelerated math library for all 31 // reduced precision scripts. 32#if defined(ARCH_ARM_HAVE_NEON) 33 const RSInfo* info = pScript.getInfo(); 34 if ((info != NULL) && 35 (info->getFloatPrecisionRequirement() != RSInfo::FP_Full)) { 36 core_lib = RSInfo::LibCLCoreNEONPath; 37 } 38#endif 39 40 if (rt_path != NULL) { 41 core_lib = rt_path; 42 } 43 44 Source *libclcore_source = Source::CreateFromFile(context, core_lib); 45 if (libclcore_source == NULL) { 46 ALOGE("Failed to load Renderscript library '%s' to link!", core_lib); 47 return false; 48 } 49 50 if (NULL != pScript.mLinkRuntimeCallback) { 51 pScript.mLinkRuntimeCallback(&pScript, 52 &pScript.getSource().getModule(), &libclcore_source->getModule()); 53 } 54 55 if (!pScript.getSource().merge(*libclcore_source, 56 /* pPreserveSource */false)) { 57 ALOGE("Failed to link Renderscript library '%s'!", core_lib); 58 delete libclcore_source; 59 return false; 60 } 61 62 return true; 63} 64 65RSScript::RSScript(Source &pSource) 66 : Script(pSource), mInfo(NULL), mCompilerVersion(0), 67 mOptimizationLevel(kOptLvl3), mLinkRuntimeCallback(NULL), 68 mEmbedInfo(false) { } 69 70bool RSScript::doReset() { 71 mInfo = NULL; 72 mCompilerVersion = 0; 73 mOptimizationLevel = kOptLvl3; 74 return true; 75} 76