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