| Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 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 | |
| Stephen Hines | e198abe | 2012-07-27 18:05:41 -0700 | [diff] [blame] | 17 | #include "bcc/Renderscript/RSScript.h" |
| Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 18 | |
| Jean-Luc Brouillet | c5e607a | 2014-06-18 18:14:02 -0700 | [diff] [blame] | 19 | #include "bcc/Assert.h" |
| Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 20 | #include "bcc/Source.h" |
| Zonr Chang | ef73a24 | 2012-04-12 16:44:01 +0800 | [diff] [blame] | 21 | #include "bcc/Support/Log.h" |
| Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 22 | |
| Zonr Chang | ade9277 | 2012-04-13 15:58:24 +0800 | [diff] [blame] | 23 | using namespace bcc; |
| Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 24 | |
| Jean-Luc Brouillet | c5e607a | 2014-06-18 18:14:02 -0700 | [diff] [blame] | 25 | bool RSScript::LinkRuntime(RSScript &pScript, const char *core_lib) { |
| Chris Wailes | 900c6c1 | 2014-08-13 15:40:00 -0700 | [diff] [blame] | 26 | bccAssert(core_lib != nullptr); |
| Jean-Luc Brouillet | c5e607a | 2014-06-18 18:14:02 -0700 | [diff] [blame] | 27 | |
| Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 28 | // Using the same context with the source in pScript. |
| 29 | BCCContext &context = pScript.getSource().getContext(); |
| Stephen Hines | 331310e | 2012-10-26 19:27:55 -0700 | [diff] [blame] | 30 | |
| Shih-wei Liao | b8f9fb1 | 2012-06-30 11:28:25 -0700 | [diff] [blame] | 31 | Source *libclcore_source = Source::CreateFromFile(context, core_lib); |
| Chris Wailes | 900c6c1 | 2014-08-13 15:40:00 -0700 | [diff] [blame] | 32 | if (libclcore_source == nullptr) { |
| Shih-wei Liao | b8f9fb1 | 2012-06-30 11:28:25 -0700 | [diff] [blame] | 33 | ALOGE("Failed to load Renderscript library '%s' to link!", core_lib); |
| Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 34 | return false; |
| 35 | } |
| 36 | |
| Chris Wailes | 900c6c1 | 2014-08-13 15:40:00 -0700 | [diff] [blame] | 37 | if (pScript.mLinkRuntimeCallback != nullptr) { |
| Stephen Hines | 06731a6 | 2013-02-12 19:29:42 -0800 | [diff] [blame] | 38 | pScript.mLinkRuntimeCallback(&pScript, |
| 39 | &pScript.getSource().getModule(), &libclcore_source->getModule()); |
| 40 | } |
| 41 | |
| Stephen Hines | 5793613 | 2014-11-25 17:54:59 -0800 | [diff] [blame] | 42 | if (!pScript.getSource().merge(*libclcore_source)) { |
| Stephen Hines | e198abe | 2012-07-27 18:05:41 -0700 | [diff] [blame] | 43 | ALOGE("Failed to link Renderscript library '%s'!", core_lib); |
| Shih-wei Liao | 2665c2f | 2012-04-25 04:06:52 -0700 | [diff] [blame] | 44 | delete libclcore_source; |
| 45 | return false; |
| 46 | } |
| 47 | |
| 48 | return true; |
| 49 | } |
| 50 | |
| Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 51 | RSScript::RSScript(Source &pSource) |
| Pirama Arumuga Nainar | a65fba6 | 2015-02-19 11:01:30 -0800 | [diff] [blame] | 52 | : Script(pSource), mCompilerVersion(0), |
| Chris Wailes | 900c6c1 | 2014-08-13 15:40:00 -0700 | [diff] [blame] | 53 | mOptimizationLevel(kOptLvl3), mLinkRuntimeCallback(nullptr), |
| Stephen Hines | 06731a6 | 2013-02-12 19:29:42 -0800 | [diff] [blame] | 54 | mEmbedInfo(false) { } |
| Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 55 | |
| Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 56 | bool RSScript::doReset() { |
| Zonr Chang | ade9277 | 2012-04-13 15:58:24 +0800 | [diff] [blame] | 57 | mCompilerVersion = 0; |
| 58 | mOptimizationLevel = kOptLvl3; |
| Zonr Chang | ccc39a8 | 2012-04-05 10:44:53 +0800 | [diff] [blame] | 59 | return true; |
| 60 | } |