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/Assert.h" 20 #include "bcc/Renderscript/RSInfo.h" 21 #include "bcc/Source.h" 22 #include "bcc/Support/Log.h" 23 24 using namespace bcc; 25 26 bool RSScript::LinkRuntime(RSScript &pScript, const char *core_lib) { 27 bccAssert(core_lib != NULL); 28 29 // Using the same context with the source in pScript. 30 BCCContext &context = pScript.getSource().getContext(); 31 32 Source *libclcore_source = Source::CreateFromFile(context, core_lib); 33 if (libclcore_source == NULL) { 34 ALOGE("Failed to load Renderscript library '%s' to link!", core_lib); 35 return false; 36 } 37 38 if (NULL != pScript.mLinkRuntimeCallback) { 39 pScript.mLinkRuntimeCallback(&pScript, 40 &pScript.getSource().getModule(), &libclcore_source->getModule()); 41 } 42 43 if (!pScript.getSource().merge(*libclcore_source, 44 /* pPreserveSource */false)) { 45 ALOGE("Failed to link Renderscript library '%s'!", core_lib); 46 delete libclcore_source; 47 return false; 48 } 49 50 return true; 51 } 52 53 RSScript::RSScript(Source &pSource) 54 : Script(pSource), mInfo(NULL), mCompilerVersion(0), 55 mOptimizationLevel(kOptLvl3), mLinkRuntimeCallback(NULL), 56 mEmbedInfo(false) { } 57 58 bool RSScript::doReset() { 59 mInfo = NULL; 60 mCompilerVersion = 0; 61 mOptimizationLevel = kOptLvl3; 62 return true; 63 } 64