blob: 53c8946b28ef94b7cf9c59195969da8683a72aaf [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
Stephen Hinese198abe2012-07-27 18:05:41 -070019#include "bcc/Renderscript/RSInfo.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
Stephen Hines331310e2012-10-26 19:27:55 -070025bool RSScript::LinkRuntime(RSScript &pScript, const char *rt_path) {
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070026 // Using the same context with the source in pScript.
27 BCCContext &context = pScript.getSource().getContext();
Shih-wei Liaob8f9fb12012-06-30 11:28:25 -070028 const char* core_lib = RSInfo::LibCLCorePath;
29
30 // NEON-capable devices can use an accelerated math library for all
31 // reduced precision scripts.
32#if defined(ARCH_ARM_HAVE_NEON)
33 const RSInfo* info = pScript.getInfo();
34 if ((info != NULL) &&
35 (info->getFloatPrecisionRequirement() != RSInfo::FP_Full)) {
36 core_lib = RSInfo::LibCLCoreNEONPath;
37 }
38#endif
39
Stephen Hines331310e2012-10-26 19:27:55 -070040 if (rt_path != NULL) {
41 core_lib = rt_path;
42 }
43
Shih-wei Liaob8f9fb12012-06-30 11:28:25 -070044 Source *libclcore_source = Source::CreateFromFile(context, core_lib);
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070045 if (libclcore_source == NULL) {
Shih-wei Liaob8f9fb12012-06-30 11:28:25 -070046 ALOGE("Failed to load Renderscript library '%s' to link!", core_lib);
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070047 return false;
48 }
49
50 if (!pScript.getSource().merge(*libclcore_source,
51 /* pPreserveSource */false)) {
Stephen Hinese198abe2012-07-27 18:05:41 -070052 ALOGE("Failed to link Renderscript library '%s'!", core_lib);
Shih-wei Liao2665c2f2012-04-25 04:06:52 -070053 delete libclcore_source;
54 return false;
55 }
56
57 return true;
58}
59
Zonr Changccc39a82012-04-05 10:44:53 +080060RSScript::RSScript(Source &pSource)
Zonr Changade92772012-04-13 15:58:24 +080061 : Script(pSource), mInfo(NULL), mCompilerVersion(0),
62 mOptimizationLevel(kOptLvl3) { }
Zonr Changccc39a82012-04-05 10:44:53 +080063
Zonr Changccc39a82012-04-05 10:44:53 +080064bool RSScript::doReset() {
Zonr Changade92772012-04-13 15:58:24 +080065 mInfo = NULL;
66 mCompilerVersion = 0;
67 mOptimizationLevel = kOptLvl3;
Zonr Changccc39a82012-04-05 10:44:53 +080068 return true;
69}