blob: c93ca6482f5db0b7ca68ac6c8627ca5ef74a295d [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
Stephen Hines57936132014-11-25 17:54:59 -080043 if (!pScript.getSource().merge(*libclcore_source)) {
Stephen Hinese198abe2012-07-27 18:05:41 -070044 ALOGE("Failed to link Renderscript library '%s'!", core_lib);
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070045 delete libclcore_source;
46 return false;
47 }
48
49 return true;
50}
51
Zonr Changccc39a82012-04-05 10:44:53 +080052RSScript::RSScript(Source &pSource)
Chris Wailes900c6c12014-08-13 15:40:00 -070053 : Script(pSource), mInfo(nullptr), mCompilerVersion(0),
54 mOptimizationLevel(kOptLvl3), mLinkRuntimeCallback(nullptr),
Stephen Hines06731a62013-02-12 19:29:42 -080055 mEmbedInfo(false) { }
Zonr Changccc39a82012-04-05 10:44:53 +080056
Zonr Changccc39a82012-04-05 10:44:53 +080057bool RSScript::doReset() {
Chris Wailes900c6c12014-08-13 15:40:00 -070058 mInfo = nullptr;
Zonr Changade92772012-04-13 15:58:24 +080059 mCompilerVersion = 0;
60 mOptimizationLevel = kOptLvl3;
Zonr Changccc39a82012-04-05 10:44:53 +080061 return true;
62}