blob: 2dadc6616aa3a8cca5b0a2f35eaf854dd487dfae [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"
Stephen Hinese198abe2012-07-27 18:05:41 -070020#include "bcc/Renderscript/RSInfo.h"
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070021#include "bcc/Source.h"
Zonr Changef73a242012-04-12 16:44:01 +080022#include "bcc/Support/Log.h"
Zonr Changccc39a82012-04-05 10:44:53 +080023
Zonr Changade92772012-04-13 15:58:24 +080024using namespace bcc;
Zonr Changccc39a82012-04-05 10:44:53 +080025
Jean-Luc Brouilletc5e607a2014-06-18 18:14:02 -070026bool RSScript::LinkRuntime(RSScript &pScript, const char *core_lib) {
Chris Wailes900c6c12014-08-13 15:40:00 -070027 bccAssert(core_lib != nullptr);
Jean-Luc Brouilletc5e607a2014-06-18 18:14:02 -070028
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070029 // Using the same context with the source in pScript.
30 BCCContext &context = pScript.getSource().getContext();
Stephen Hines331310e2012-10-26 19:27:55 -070031
Shih-wei Liaob8f9fb12012-06-30 11:28:25 -070032 Source *libclcore_source = Source::CreateFromFile(context, core_lib);
Chris Wailes900c6c12014-08-13 15:40:00 -070033 if (libclcore_source == nullptr) {
Shih-wei Liaob8f9fb12012-06-30 11:28:25 -070034 ALOGE("Failed to load Renderscript library '%s' to link!", core_lib);
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070035 return false;
36 }
37
Chris Wailes900c6c12014-08-13 15:40:00 -070038 if (pScript.mLinkRuntimeCallback != nullptr) {
Stephen Hines06731a62013-02-12 19:29:42 -080039 pScript.mLinkRuntimeCallback(&pScript,
40 &pScript.getSource().getModule(), &libclcore_source->getModule());
41 }
42
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070043 if (!pScript.getSource().merge(*libclcore_source,
44 /* pPreserveSource */false)) {
Stephen Hinese198abe2012-07-27 18:05:41 -070045 ALOGE("Failed to link Renderscript library '%s'!", core_lib);
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070046 delete libclcore_source;
47 return false;
48 }
49
50 return true;
51}
52
Zonr Changccc39a82012-04-05 10:44:53 +080053RSScript::RSScript(Source &pSource)
Chris Wailes900c6c12014-08-13 15:40:00 -070054 : Script(pSource), mInfo(nullptr), mCompilerVersion(0),
55 mOptimizationLevel(kOptLvl3), mLinkRuntimeCallback(nullptr),
Stephen Hines06731a62013-02-12 19:29:42 -080056 mEmbedInfo(false) { }
Zonr Changccc39a82012-04-05 10:44:53 +080057
Zonr Changccc39a82012-04-05 10:44:53 +080058bool RSScript::doReset() {
Chris Wailes900c6c12014-08-13 15:40:00 -070059 mInfo = nullptr;
Zonr Changade92772012-04-13 15:58:24 +080060 mCompilerVersion = 0;
61 mOptimizationLevel = kOptLvl3;
Zonr Changccc39a82012-04-05 10:44:53 +080062 return true;
63}