blob: 0efc43baf95ca5e124acf69791825fb662328050 [file] [log] [blame]
Zonr Chang19218c02012-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
Zonr Chang80232dd2012-04-12 15:38:53 +080017#include "bcc/RenderScript/RSScript.h"
Zonr Chang19218c02012-04-05 10:44:53 +080018
Zonr Chang19218c02012-04-05 10:44:53 +080019#include <cstring>
20
21#include <llvm/ADT/STLExtras.h>
22
Shih-wei Liao0467d9a2012-04-25 04:06:52 -070023#include "bcc/RenderScript/RSInfo.h"
24#include "bcc/Source.h"
Zonr Changb519fe32012-04-12 16:44:01 +080025#include "bcc/Support/Log.h"
Zonr Chang19218c02012-04-05 10:44:53 +080026
Zonr Changfef9a1b2012-04-13 15:58:24 +080027using namespace bcc;
Zonr Chang19218c02012-04-05 10:44:53 +080028
Zonr Chang255cbc82012-04-12 13:29:43 +080029RSScript::SourceDependency::SourceDependency(const std::string &pSourceName,
Zonr Chang19218c02012-04-05 10:44:53 +080030 const uint8_t *pSHA1)
Zonr Chang255cbc82012-04-12 13:29:43 +080031 : mSourceName(pSourceName) {
Zonr Chang19218c02012-04-05 10:44:53 +080032 ::memcpy(mSHA1, pSHA1, sizeof(mSHA1));
33 return;
34}
35
Shih-wei Liao0467d9a2012-04-25 04:06:52 -070036bool RSScript::LinkRuntime(RSScript &pScript) {
37 // Using the same context with the source in pScript.
38 BCCContext &context = pScript.getSource().getContext();
39 Source *libclcore_source = Source::CreateFromFile(context,
40 RSInfo::LibCLCorePath);
41 if (libclcore_source == NULL) {
42 ALOGE("Failed to load Renderscript library '%s' to link!",
43 RSInfo::LibCLCorePath);
44 return false;
45 }
46
47 if (!pScript.getSource().merge(*libclcore_source,
48 /* pPreserveSource */false)) {
49 ALOGE("Failed to link RenderScript library '%s'!", RSInfo::LibCLCorePath);
50 delete libclcore_source;
51 return false;
52 }
53
54 return true;
55}
56
Zonr Chang19218c02012-04-05 10:44:53 +080057RSScript::RSScript(Source &pSource)
Zonr Changfef9a1b2012-04-13 15:58:24 +080058 : Script(pSource), mInfo(NULL), mCompilerVersion(0),
59 mOptimizationLevel(kOptLvl3) { }
Zonr Chang19218c02012-04-05 10:44:53 +080060
61RSScript::~RSScript() {
Zonr Chang19218c02012-04-05 10:44:53 +080062 llvm::DeleteContainerPointers(mSourceDependencies);
63}
64
Zonr Chang19218c02012-04-05 10:44:53 +080065bool RSScript::doReset() {
Zonr Changfef9a1b2012-04-13 15:58:24 +080066 mInfo = NULL;
67 mCompilerVersion = 0;
68 mOptimizationLevel = kOptLvl3;
69 llvm::DeleteContainerPointers(mSourceDependencies);
Zonr Chang19218c02012-04-05 10:44:53 +080070 return true;
71}
72
Zonr Chang255cbc82012-04-12 13:29:43 +080073bool RSScript::addSourceDependency(const std::string &pSourceName,
Zonr Chang19218c02012-04-05 10:44:53 +080074 const uint8_t *pSHA1) {
75 SourceDependency *source_dep =
Zonr Chang255cbc82012-04-12 13:29:43 +080076 new (std::nothrow) SourceDependency(pSourceName, pSHA1);
Zonr Chang19218c02012-04-05 10:44:53 +080077 if (source_dep == NULL) {
78 ALOGE("Out of memory when record dependency information of `%s'!",
79 pSourceName.c_str());
80 return false;
81 }
82
83 mSourceDependencies.push_back(source_dep);
84 return true;
85}