blob: 396b47d93de3b9dec44face6d58c469da278f5f5 [file] [log] [blame]
Zonr Changccc39a82012-04-05 10:44:53 +08001/*
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
Stephen Hinese198abe2012-07-27 18:05:41 -070017#include "bcc/Renderscript/RSScript.h"
Zonr Changccc39a82012-04-05 10:44:53 +080018
Jean-Luc Brouilletc5e607a2014-06-18 18:14:02 -070019#include "bcc/Assert.h"
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070020#include "bcc/Source.h"
Zonr Changef73a242012-04-12 16:44:01 +080021#include "bcc/Support/Log.h"
Zonr Changccc39a82012-04-05 10:44:53 +080022
Zonr Changade92772012-04-13 15:58:24 +080023using namespace bcc;
Zonr Changccc39a82012-04-05 10:44:53 +080024
Jean-Luc Brouilletc5e607a2014-06-18 18:14:02 -070025bool RSScript::LinkRuntime(RSScript &pScript, const char *core_lib) {
Chris Wailes900c6c12014-08-13 15:40:00 -070026 bccAssert(core_lib != nullptr);
Jean-Luc Brouilletc5e607a2014-06-18 18:14:02 -070027
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070028 // Using the same context with the source in pScript.
29 BCCContext &context = pScript.getSource().getContext();
Stephen Hines331310e2012-10-26 19:27:55 -070030
Shih-wei Liaob8f9fb12012-06-30 11:28:25 -070031 Source *libclcore_source = Source::CreateFromFile(context, core_lib);
Chris Wailes900c6c12014-08-13 15:40:00 -070032 if (libclcore_source == nullptr) {
Shih-wei Liaob8f9fb12012-06-30 11:28:25 -070033 ALOGE("Failed to load Renderscript library '%s' to link!", core_lib);
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070034 return false;
35 }
36
Chris Wailes900c6c12014-08-13 15:40:00 -070037 if (pScript.mLinkRuntimeCallback != nullptr) {
Stephen Hines06731a62013-02-12 19:29:42 -080038 pScript.mLinkRuntimeCallback(&pScript,
39 &pScript.getSource().getModule(), &libclcore_source->getModule());
40 }
41
Stephen Hines57936132014-11-25 17:54:59 -080042 if (!pScript.getSource().merge(*libclcore_source)) {
Stephen Hinese198abe2012-07-27 18:05:41 -070043 ALOGE("Failed to link Renderscript library '%s'!", core_lib);
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070044 delete libclcore_source;
45 return false;
46 }
47
48 return true;
49}
50
Zonr Changccc39a82012-04-05 10:44:53 +080051RSScript::RSScript(Source &pSource)
Pirama Arumuga Nainara65fba62015-02-19 11:01:30 -080052 : Script(pSource), mCompilerVersion(0),
Chris Wailes900c6c12014-08-13 15:40:00 -070053 mOptimizationLevel(kOptLvl3), mLinkRuntimeCallback(nullptr),
Stephen Hines06731a62013-02-12 19:29:42 -080054 mEmbedInfo(false) { }
Zonr Changccc39a82012-04-05 10:44:53 +080055
Zonr Changccc39a82012-04-05 10:44:53 +080056bool RSScript::doReset() {
Zonr Changade92772012-04-13 15:58:24 +080057 mCompilerVersion = 0;
58 mOptimizationLevel = kOptLvl3;
Zonr Changccc39a82012-04-05 10:44:53 +080059 return true;
60}