blob: d8f356c87194ac9429e16cf7c02f00a2182e36f3 [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
Stephen Hines44199772012-02-21 20:13:12 -08002 * Copyright (C) 2009-2012 The Android Open Source Project
Jason Sams326e0dd2009-05-22 14:03:28 -07003 *
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
17#include "rsContext.h"
18#include "rsScriptC.h"
Jack Palevich1ef8b802009-05-28 15:53:04 -070019
Jason Sams93eacc72012-12-18 14:26:57 -080020#ifndef RS_COMPATIBILITY_LIB
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070021#ifndef ANDROID_RS_SERIALIZE
22#include <bcinfo/BitcodeTranslator.h>
Stephen Hinesf8d44692011-11-22 19:43:58 -080023#include <bcinfo/BitcodeWrapper.h>
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070024#endif
Jason Sams93eacc72012-12-18 14:26:57 -080025#endif
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070026
Stephen Hinesb0934b62013-07-03 17:27:38 -070027#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
Tim Murray0b575de2013-03-15 15:56:43 -070028#include "utils/Timers.h"
Tim Murray0b575de2013-03-15 15:56:43 -070029#endif
30
Tim Murraye78c14b2012-10-01 15:27:18 -070031#include <sys/stat.h>
32
Jason Sams326e0dd2009-05-22 14:03:28 -070033using namespace android;
34using namespace android::renderscript;
35
Jason Samse5769102009-06-19 16:03:18 -070036#define GET_TLS() Context::ScriptTLSStruct * tls = \
37 (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
38 Context * rsc = tls->mContext; \
39 ScriptC * sc = (ScriptC *) tls->mScript
40
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080041ScriptC::ScriptC(Context *rsc) : Script(rsc) {
Jason Sams93eacc72012-12-18 14:26:57 -080042#ifndef RS_COMPATIBILITY_LIB
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070043#ifndef ANDROID_RS_SERIALIZE
44 BT = NULL;
45#endif
Jason Sams93eacc72012-12-18 14:26:57 -080046#endif
Jason Sams326e0dd2009-05-22 14:03:28 -070047}
48
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080049ScriptC::~ScriptC() {
Jason Sams93eacc72012-12-18 14:26:57 -080050#ifndef RS_COMPATIBILITY_LIB
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070051#ifndef ANDROID_RS_SERIALIZE
52 if (BT) {
53 delete BT;
54 BT = NULL;
55 }
56#endif
Jason Sams93eacc72012-12-18 14:26:57 -080057#endif
Jason Sams77020c52011-11-22 12:49:11 -080058 if (mInitialized) {
59 mRSC->mHal.funcs.script.invokeFreeChildren(mRSC, this);
60 mRSC->mHal.funcs.script.destroy(mRSC, this);
61 }
Jason Sams326e0dd2009-05-22 14:03:28 -070062}
63
Jason Sams93eacc72012-12-18 14:26:57 -080064#ifndef RS_COMPATIBILITY_LIB
Tim Murraye78c14b2012-10-01 15:27:18 -070065bool ScriptC::createCacheDir(const char *cacheDir) {
66 String8 cacheDirString, currentDir;
67 struct stat statBuf;
68 int statReturn = stat(cacheDir, &statBuf);
69 if (!statReturn) {
70 return true;
71 }
72
73 // String8 path functions strip leading /'s
74 // insert if necessary
75 if (cacheDir[0] == '/') {
76 currentDir += "/";
77 }
78
79 cacheDirString.setPathName(cacheDir);
80
81 while (cacheDirString.length()) {
82 currentDir += (cacheDirString.walkPath(&cacheDirString));
83 statReturn = stat(currentDir.string(), &statBuf);
84 if (statReturn) {
85 if (errno == ENOENT) {
86 if (mkdir(currentDir.string(), S_IRUSR | S_IWUSR | S_IXUSR)) {
87 ALOGE("Couldn't create cache directory: %s",
88 currentDir.string());
89 ALOGE("Error: %s", strerror(errno));
90 return false;
91 }
92 } else {
93 ALOGE("Stat error: %s", strerror(errno));
94 return false;
95 }
96 }
97 currentDir += "/";
98 }
99 return true;
100}
Jason Sams93eacc72012-12-18 14:26:57 -0800101#endif
Tim Murraye78c14b2012-10-01 15:27:18 -0700102
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800103void ScriptC::setupScript(Context *rsc) {
Tim Murray0b575de2013-03-15 15:56:43 -0700104#ifndef RS_SERVER
Jason Samsc61346b2010-05-28 18:23:22 -0700105 mEnviroment.mStartTimeMillis
106 = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
Tim Murray0b575de2013-03-15 15:56:43 -0700107#endif
Jason Samsc61346b2010-05-28 18:23:22 -0700108
Jason Samsbad80742011-03-16 16:29:28 -0700109 for (uint32_t ct=0; ct < mHal.info.exportedVariableCount; ct++) {
Jason Sams900f1612010-09-16 18:18:29 -0700110 if (mSlots[ct].get() && !mTypes[ct].get()) {
111 mTypes[ct].set(mSlots[ct]->getType());
112 }
113
114 if (!mTypes[ct].get())
Jason Samsbe36bf32010-05-11 14:03:58 -0700115 continue;
Jason Sams807fdc42012-07-25 17:55:39 -0700116 rsc->mHal.funcs.script.setGlobalBind(rsc, this, ct, mSlots[ct].get());
Jason Samsada7f272009-09-24 14:55:38 -0700117 }
118}
119
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800120void ScriptC::setupGLState(Context *rsc) {
Jason Sams93eacc72012-12-18 14:26:57 -0800121#ifndef RS_COMPATIBILITY_LIB
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700122 if (mEnviroment.mFragmentStore.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800123 rsc->setProgramStore(mEnviroment.mFragmentStore.get());
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700124 }
125 if (mEnviroment.mFragment.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800126 rsc->setProgramFragment(mEnviroment.mFragment.get());
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700127 }
Jason Sams8ce125b2009-06-17 16:52:59 -0700128 if (mEnviroment.mVertex.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800129 rsc->setProgramVertex(mEnviroment.mVertex.get());
Jason Sams8ce125b2009-06-17 16:52:59 -0700130 }
Jason Samsb681c8a2009-09-28 18:12:56 -0700131 if (mEnviroment.mRaster.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800132 rsc->setProgramRaster(mEnviroment.mRaster.get());
Jason Samsb681c8a2009-09-28 18:12:56 -0700133 }
Jason Sams93eacc72012-12-18 14:26:57 -0800134#endif
Jason Samsc61346b2010-05-28 18:23:22 -0700135}
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700136
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800137uint32_t ScriptC::run(Context *rsc) {
Jason Samsbad80742011-03-16 16:29:28 -0700138 if (mHal.info.root == NULL) {
Jason Samsc61346b2010-05-28 18:23:22 -0700139 rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script");
140 return 0;
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700141 }
Jason Samsc61346b2010-05-28 18:23:22 -0700142
Jason Sams1f24db42010-12-11 17:42:30 -0800143 setupGLState(rsc);
Jason Samsc61346b2010-05-28 18:23:22 -0700144 setupScript(rsc);
Jason Sams1d54f102009-09-03 15:43:13 -0700145
Jason Sams2dca84d2009-12-09 11:05:45 -0800146 uint32_t ret = 0;
Jason Samsb9077f42010-09-22 15:57:41 -0700147
148 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100149 ALOGV("%p ScriptC::run invoking root, ptr %p", rsc, mHal.info.root);
Jason Samsb9077f42010-09-22 15:57:41 -0700150 }
151
Jason Samscdfdb8f2011-03-17 16:12:47 -0700152 ret = rsc->mHal.funcs.script.invokeRoot(rsc, this);
Jason Samsb9077f42010-09-22 15:57:41 -0700153
154 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100155 ALOGV("%p ScriptC::run invoking complete, ret=%i", rsc, ret);
Jason Samsb9077f42010-09-22 15:57:41 -0700156 }
157
Jason Samse45ac6e2009-07-20 14:31:06 -0700158 return ret;
Jason Sams326e0dd2009-05-22 14:03:28 -0700159}
160
Jason Sams177f8442010-10-29 10:19:21 -0700161
Jason Samsace3e012010-07-15 17:11:13 -0700162void ScriptC::runForEach(Context *rsc,
Stephen Hines44199772012-02-21 20:13:12 -0800163 uint32_t slot,
Jason Samsace3e012010-07-15 17:11:13 -0700164 const Allocation * ain,
165 Allocation * aout,
166 const void * usr,
Jason Sams87fe59a2011-04-20 15:09:01 -0700167 size_t usrBytes,
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800168 const RsScriptCall *sc) {
Jason Samscdfdb8f2011-03-17 16:12:47 -0700169
Jason Sams60709252010-11-17 15:29:32 -0800170 Context::PushState ps(rsc);
Jason Samsc61346b2010-05-28 18:23:22 -0700171
Jason Sams1f24db42010-12-11 17:42:30 -0800172 setupGLState(rsc);
Jason Samsc61346b2010-05-28 18:23:22 -0700173 setupScript(rsc);
Stephen Hines44199772012-02-21 20:13:12 -0800174 rsc->mHal.funcs.script.invokeForEach(rsc, this, slot, ain, aout, usr, usrBytes, sc);
Jason Samsc61346b2010-05-28 18:23:22 -0700175}
176
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700177void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) {
Jason Samsbad80742011-03-16 16:29:28 -0700178 if (slot >= mHal.info.exportedFunctionCount) {
Jason Sams22fa3712010-05-19 17:22:57 -0700179 rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script");
180 return;
181 }
Jason Samsc61346b2010-05-28 18:23:22 -0700182 setupScript(rsc);
Jason Sams22fa3712010-05-19 17:22:57 -0700183
Jason Samsb9077f42010-09-22 15:57:41 -0700184 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100185 ALOGV("%p ScriptC::Invoke invoking slot %i, ptr %p", rsc, slot, this);
Jason Samsb9077f42010-09-22 15:57:41 -0700186 }
Jason Samsbad80742011-03-16 16:29:28 -0700187 rsc->mHal.funcs.script.invokeFunction(rsc, this, slot, data, len);
Jason Sams22fa3712010-05-19 17:22:57 -0700188}
189
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800190ScriptCState::ScriptCState() {
Jason Sams326e0dd2009-05-22 14:03:28 -0700191}
192
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800193ScriptCState::~ScriptCState() {
Jason Sams1f526332009-06-05 17:35:09 -0700194}
195
Jason Sams87fe59a2011-04-20 15:09:01 -0700196/*
Shih-wei Liao2b2e6212011-01-14 06:21:28 -0800197static void* symbolLookup(void* pContext, char const* name) {
Jason Samsaeb094b2010-05-18 13:35:45 -0700198 const ScriptCState::SymbolTable_t *sym;
Jason Samsdd663fa2010-08-11 13:26:28 -0700199 ScriptC *s = (ScriptC *)pContext;
Shih-wei Liaof17b13b2010-12-07 13:44:10 -0800200 if (!strcmp(name, "__isThreadable")) {
Jason Samsbad80742011-03-16 16:29:28 -0700201 return (void*) s->mHal.info.isThreadable;
Shih-wei Liaof17b13b2010-12-07 13:44:10 -0800202 } else if (!strcmp(name, "__clearThreadable")) {
Jason Samsbad80742011-03-16 16:29:28 -0700203 s->mHal.info.isThreadable = false;
Shih-wei Liaof17b13b2010-12-07 13:44:10 -0800204 return NULL;
205 }
Jason Samsaeb094b2010-05-18 13:35:45 -0700206 sym = ScriptCState::lookupSymbol(name);
Jason Sams6bfc1b92010-11-01 14:26:30 -0700207 if (!sym) {
208 sym = ScriptCState::lookupSymbolCL(name);
Jason Samsaeb094b2010-05-18 13:35:45 -0700209 }
Jason Sams6bfc1b92010-11-01 14:26:30 -0700210 if (!sym) {
211 sym = ScriptCState::lookupSymbolGL(name);
Jason Samsaeb094b2010-05-18 13:35:45 -0700212 }
Jason Sams29df66f2009-07-16 15:08:06 -0700213 if (sym) {
Jason Samsbad80742011-03-16 16:29:28 -0700214 s->mHal.info.isThreadable &= sym->threadable;
Jason Sams29df66f2009-07-16 15:08:06 -0700215 return sym->mPtr;
216 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000217 ALOGE("ScriptC sym lookup failed for %s", name);
Jason Sams29df66f2009-07-16 15:08:06 -0700218 return NULL;
219}
Jason Sams87fe59a2011-04-20 15:09:01 -0700220*/
Jason Samsa4a54e42009-06-10 18:39:40 -0700221
Shih-wei Liao80761ec2011-01-16 02:23:04 -0800222#if 0
Shih-wei Liao1f9ba732010-10-23 02:15:57 -0700223extern const char rs_runtime_lib_bc[];
224extern unsigned rs_runtime_lib_bc_size;
Shih-wei Liao80761ec2011-01-16 02:23:04 -0800225#endif
Shih-wei Liao1f9ba732010-10-23 02:15:57 -0700226
Jason Samsbad80742011-03-16 16:29:28 -0700227bool ScriptC::runCompiler(Context *rsc,
228 const char *resName,
229 const char *cacheDir,
230 const uint8_t *bitcode,
231 size_t bitcodeLen) {
Shih-wei Liao37150de2011-01-07 18:17:07 -0800232
Steve Blockaf12ac62012-01-06 19:20:56 +0000233 //ALOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen);
Jason Sams93eacc72012-12-18 14:26:57 -0800234#ifndef RS_COMPATIBILITY_LIB
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700235#ifndef ANDROID_RS_SERIALIZE
Stephen Hinesf8d44692011-11-22 19:43:58 -0800236 uint32_t sdkVersion = 0;
237 bcinfo::BitcodeWrapper bcWrapper((const char *)bitcode, bitcodeLen);
238 if (!bcWrapper.unwrap()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000239 ALOGE("Bitcode is not in proper container format (raw or wrapper)");
Stephen Hinesf8d44692011-11-22 19:43:58 -0800240 return false;
241 }
242
Stephen Hinesf8d44692011-11-22 19:43:58 -0800243 if (bcWrapper.getBCFileType() == bcinfo::BC_WRAPPER) {
244 sdkVersion = bcWrapper.getTargetAPI();
245 }
246
247 if (sdkVersion == 0) {
248 // This signals that we didn't have a wrapper containing information
249 // about the bitcode.
250 sdkVersion = rsc->getTargetSdkVersion();
251 }
252
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700253 if (BT) {
254 delete BT;
255 }
256 BT = new bcinfo::BitcodeTranslator((const char *)bitcode, bitcodeLen,
257 sdkVersion);
258 if (!BT->translate()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000259 ALOGE("Failed to translate bitcode from version: %u", sdkVersion);
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700260 delete BT;
261 BT = NULL;
262 return false;
263 }
264 bitcode = (const uint8_t *) BT->getTranslatedBitcode();
265 bitcodeLen = BT->getTranslatedBitcodeSize();
266#endif
Shih-wei Liao37150de2011-01-07 18:17:07 -0800267
Tim Murray84bf2b82012-10-31 16:03:16 -0700268 if (!cacheDir) {
269 // MUST BE FIXED BEFORE ANYTHING USING C++ API IS RELEASED
270 cacheDir = getenv("EXTERNAL_STORAGE");
271 ALOGV("Cache dir changed to %s", cacheDir);
272 }
273
Tim Murraye78c14b2012-10-01 15:27:18 -0700274 // ensure that cache dir exists
Tim Murray84bf2b82012-10-31 16:03:16 -0700275 if (cacheDir && !createCacheDir(cacheDir)) {
Tim Murraye78c14b2012-10-01 15:27:18 -0700276 return false;
277 }
Jason Sams93eacc72012-12-18 14:26:57 -0800278#endif
Tim Murraye78c14b2012-10-01 15:27:18 -0700279
Jason Sams77020c52011-11-22 12:49:11 -0800280 if (!rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0)) {
281 return false;
282 }
Shih-wei Liao37150de2011-01-07 18:17:07 -0800283
Jason Sams77020c52011-11-22 12:49:11 -0800284 mInitialized = true;
Jason Sams93eacc72012-12-18 14:26:57 -0800285#ifndef RS_COMPATIBILITY_LIB
Jason Samsbad80742011-03-16 16:29:28 -0700286 mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
287 mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
288 mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore());
289 mEnviroment.mRaster.set(rsc->getDefaultProgramRaster());
Jason Sams93eacc72012-12-18 14:26:57 -0800290#endif
Shih-wei Liao37150de2011-01-07 18:17:07 -0800291
Jason Samsbad80742011-03-16 16:29:28 -0700292 rsc->mHal.funcs.script.invokeInit(rsc, this);
Stephen Hines7b337b12011-01-17 17:31:58 -0800293
Jason Samsbad80742011-03-16 16:29:28 -0700294 for (size_t i=0; i < mHal.info.exportedPragmaCount; ++i) {
295 const char * key = mHal.info.exportedPragmaKeyList[i];
296 const char * value = mHal.info.exportedPragmaValueList[i];
Steve Blockaf12ac62012-01-06 19:20:56 +0000297 //ALOGE("pragma %s %s", keys[i], values[i]);
Jason Samsbad80742011-03-16 16:29:28 -0700298 if (!strcmp(key, "version")) {
299 if (!strcmp(value, "1")) {
Stephen Hinesb5dc6af2011-01-18 14:10:44 -0800300 continue;
301 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000302 ALOGE("Invalid version pragma value: %s\n", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800303 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800304 }
305
Jason Sams93eacc72012-12-18 14:26:57 -0800306#ifndef RS_COMPATIBILITY_LIB
Jason Samsbad80742011-03-16 16:29:28 -0700307 if (!strcmp(key, "stateVertex")) {
308 if (!strcmp(value, "default")) {
Jason Sams10308932009-06-09 12:15:30 -0700309 continue;
Jason Sams10308932009-06-09 12:15:30 -0700310 }
Jason Samsbad80742011-03-16 16:29:28 -0700311 if (!strcmp(value, "parent")) {
312 mEnviroment.mVertex.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800313 continue;
Jason Sams10308932009-06-09 12:15:30 -0700314 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000315 ALOGE("Unrecognized value %s passed to stateVertex", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800316 return false;
Jason Sams10308932009-06-09 12:15:30 -0700317 }
Stephen Hines7b337b12011-01-17 17:31:58 -0800318
Jason Samsbad80742011-03-16 16:29:28 -0700319 if (!strcmp(key, "stateRaster")) {
320 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800321 continue;
322 }
Jason Samsbad80742011-03-16 16:29:28 -0700323 if (!strcmp(value, "parent")) {
324 mEnviroment.mRaster.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800325 continue;
326 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000327 ALOGE("Unrecognized value %s passed to stateRaster", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800328 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800329 }
330
Jason Samsbad80742011-03-16 16:29:28 -0700331 if (!strcmp(key, "stateFragment")) {
332 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800333 continue;
334 }
Jason Samsbad80742011-03-16 16:29:28 -0700335 if (!strcmp(value, "parent")) {
336 mEnviroment.mFragment.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800337 continue;
338 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000339 ALOGE("Unrecognized value %s passed to stateFragment", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800340 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800341 }
342
Jason Samsbad80742011-03-16 16:29:28 -0700343 if (!strcmp(key, "stateStore")) {
344 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800345 continue;
346 }
Jason Samsbad80742011-03-16 16:29:28 -0700347 if (!strcmp(value, "parent")) {
348 mEnviroment.mFragmentStore.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800349 continue;
350 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000351 ALOGE("Unrecognized value %s passed to stateStore", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800352 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800353 }
Jason Sams93eacc72012-12-18 14:26:57 -0800354#endif
355
Jason Sams10308932009-06-09 12:15:30 -0700356 }
Jason Sams2e8665d2011-01-27 00:14:13 -0800357
Jason Samsbad80742011-03-16 16:29:28 -0700358 mSlots = new ObjectBaseRef<Allocation>[mHal.info.exportedVariableCount];
359 mTypes = new ObjectBaseRef<const Type>[mHal.info.exportedVariableCount];
Jason Sams2e8665d2011-01-27 00:14:13 -0800360
Jason Sams26b2c9f2011-01-19 16:14:21 -0800361 return true;
Jason Sams326e0dd2009-05-22 14:03:28 -0700362}
363
364namespace android {
365namespace renderscript {
366
Shih-wei Liaoce8a0792010-12-20 20:45:56 +0800367RsScript rsi_ScriptCCreate(Context *rsc,
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700368 const char *resName, size_t resName_length,
369 const char *cacheDir, size_t cacheDir_length,
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700370 const char *text, size_t text_length)
Shih-wei Liao9503b662010-11-08 01:33:59 -0800371{
Jason Sams249d4532011-01-23 17:48:45 -0800372 ScriptC *s = new ScriptC(rsc);
Jason Sams1f526332009-06-05 17:35:09 -0700373
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700374 if (!s->runCompiler(rsc, resName, cacheDir, (uint8_t *)text, text_length)) {
Jason Sams26b2c9f2011-01-19 16:14:21 -0800375 // Error during compile, destroy s and return null.
Stephen Hines4769d682012-02-02 13:23:20 -0800376 ObjectBase::checkDelete(s);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800377 return NULL;
378 }
Jason Samsbad80742011-03-16 16:29:28 -0700379
380 s->incUserRef();
Jason Sams249d4532011-01-23 17:48:45 -0800381 return s;
Jason Sams326e0dd2009-05-22 14:03:28 -0700382}
383
Jason Sams326e0dd2009-05-22 14:03:28 -0700384}
385}