blob: 757d3ca3a21dd247ae3224cd7eb345e3efb8e35c [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"
Joe Onorato9c4e4ca2009-08-09 11:39:02 -070019#include "utils/Timers.h"
Alex Sakhartchoukb26fb042010-09-24 15:18:12 -070020#include "utils/StopWatch.h"
Jack Palevich1ef8b802009-05-28 15:53:04 -070021
Jason Sams93eacc72012-12-18 14:26:57 -080022#ifndef RS_COMPATIBILITY_LIB
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070023#ifndef ANDROID_RS_SERIALIZE
24#include <bcinfo/BitcodeTranslator.h>
Stephen Hinesf8d44692011-11-22 19:43:58 -080025#include <bcinfo/BitcodeWrapper.h>
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070026#endif
Jason Sams93eacc72012-12-18 14:26:57 -080027#endif
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070028
Tim Murraye78c14b2012-10-01 15:27:18 -070029#include <sys/stat.h>
30
Jason Sams326e0dd2009-05-22 14:03:28 -070031using namespace android;
32using namespace android::renderscript;
33
Jason Samse5769102009-06-19 16:03:18 -070034#define GET_TLS() Context::ScriptTLSStruct * tls = \
35 (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
36 Context * rsc = tls->mContext; \
37 ScriptC * sc = (ScriptC *) tls->mScript
38
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080039ScriptC::ScriptC(Context *rsc) : Script(rsc) {
Jason Sams93eacc72012-12-18 14:26:57 -080040#ifndef RS_COMPATIBILITY_LIB
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070041#ifndef ANDROID_RS_SERIALIZE
42 BT = NULL;
43#endif
Jason Sams93eacc72012-12-18 14:26:57 -080044#endif
Jason Sams326e0dd2009-05-22 14:03:28 -070045}
46
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080047ScriptC::~ScriptC() {
Jason Sams93eacc72012-12-18 14:26:57 -080048#ifndef RS_COMPATIBILITY_LIB
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070049#ifndef ANDROID_RS_SERIALIZE
50 if (BT) {
51 delete BT;
52 BT = NULL;
53 }
54#endif
Jason Sams93eacc72012-12-18 14:26:57 -080055#endif
Jason Sams77020c52011-11-22 12:49:11 -080056 if (mInitialized) {
57 mRSC->mHal.funcs.script.invokeFreeChildren(mRSC, this);
58 mRSC->mHal.funcs.script.destroy(mRSC, this);
59 }
Jason Sams326e0dd2009-05-22 14:03:28 -070060}
61
Jason Sams93eacc72012-12-18 14:26:57 -080062#ifndef RS_COMPATIBILITY_LIB
Tim Murraye78c14b2012-10-01 15:27:18 -070063bool ScriptC::createCacheDir(const char *cacheDir) {
64 String8 cacheDirString, currentDir;
65 struct stat statBuf;
66 int statReturn = stat(cacheDir, &statBuf);
67 if (!statReturn) {
68 return true;
69 }
70
71 // String8 path functions strip leading /'s
72 // insert if necessary
73 if (cacheDir[0] == '/') {
74 currentDir += "/";
75 }
76
77 cacheDirString.setPathName(cacheDir);
78
79 while (cacheDirString.length()) {
80 currentDir += (cacheDirString.walkPath(&cacheDirString));
81 statReturn = stat(currentDir.string(), &statBuf);
82 if (statReturn) {
83 if (errno == ENOENT) {
84 if (mkdir(currentDir.string(), S_IRUSR | S_IWUSR | S_IXUSR)) {
85 ALOGE("Couldn't create cache directory: %s",
86 currentDir.string());
87 ALOGE("Error: %s", strerror(errno));
88 return false;
89 }
90 } else {
91 ALOGE("Stat error: %s", strerror(errno));
92 return false;
93 }
94 }
95 currentDir += "/";
96 }
97 return true;
98}
Jason Sams93eacc72012-12-18 14:26:57 -080099#endif
Tim Murraye78c14b2012-10-01 15:27:18 -0700100
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800101void ScriptC::setupScript(Context *rsc) {
Jason Samsc61346b2010-05-28 18:23:22 -0700102 mEnviroment.mStartTimeMillis
103 = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
104
Jason Samsbad80742011-03-16 16:29:28 -0700105 for (uint32_t ct=0; ct < mHal.info.exportedVariableCount; ct++) {
Jason Sams900f1612010-09-16 18:18:29 -0700106 if (mSlots[ct].get() && !mTypes[ct].get()) {
107 mTypes[ct].set(mSlots[ct]->getType());
108 }
109
110 if (!mTypes[ct].get())
Jason Samsbe36bf32010-05-11 14:03:58 -0700111 continue;
Jason Sams807fdc42012-07-25 17:55:39 -0700112 rsc->mHal.funcs.script.setGlobalBind(rsc, this, ct, mSlots[ct].get());
Jason Samsada7f272009-09-24 14:55:38 -0700113 }
114}
115
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800116void ScriptC::setupGLState(Context *rsc) {
Jason Sams93eacc72012-12-18 14:26:57 -0800117#ifndef RS_COMPATIBILITY_LIB
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700118 if (mEnviroment.mFragmentStore.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800119 rsc->setProgramStore(mEnviroment.mFragmentStore.get());
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700120 }
121 if (mEnviroment.mFragment.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800122 rsc->setProgramFragment(mEnviroment.mFragment.get());
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700123 }
Jason Sams8ce125b2009-06-17 16:52:59 -0700124 if (mEnviroment.mVertex.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800125 rsc->setProgramVertex(mEnviroment.mVertex.get());
Jason Sams8ce125b2009-06-17 16:52:59 -0700126 }
Jason Samsb681c8a2009-09-28 18:12:56 -0700127 if (mEnviroment.mRaster.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800128 rsc->setProgramRaster(mEnviroment.mRaster.get());
Jason Samsb681c8a2009-09-28 18:12:56 -0700129 }
Jason Sams93eacc72012-12-18 14:26:57 -0800130#endif
Jason Samsc61346b2010-05-28 18:23:22 -0700131}
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700132
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800133uint32_t ScriptC::run(Context *rsc) {
Jason Samsbad80742011-03-16 16:29:28 -0700134 if (mHal.info.root == NULL) {
Jason Samsc61346b2010-05-28 18:23:22 -0700135 rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script");
136 return 0;
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700137 }
Jason Samsc61346b2010-05-28 18:23:22 -0700138
Jason Sams1f24db42010-12-11 17:42:30 -0800139 setupGLState(rsc);
Jason Samsc61346b2010-05-28 18:23:22 -0700140 setupScript(rsc);
Jason Sams1d54f102009-09-03 15:43:13 -0700141
Jason Sams2dca84d2009-12-09 11:05:45 -0800142 uint32_t ret = 0;
Jason Samsb9077f42010-09-22 15:57:41 -0700143
144 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100145 ALOGV("%p ScriptC::run invoking root, ptr %p", rsc, mHal.info.root);
Jason Samsb9077f42010-09-22 15:57:41 -0700146 }
147
Jason Samscdfdb8f2011-03-17 16:12:47 -0700148 ret = rsc->mHal.funcs.script.invokeRoot(rsc, this);
Jason Samsb9077f42010-09-22 15:57:41 -0700149
150 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100151 ALOGV("%p ScriptC::run invoking complete, ret=%i", rsc, ret);
Jason Samsb9077f42010-09-22 15:57:41 -0700152 }
153
Jason Samse45ac6e2009-07-20 14:31:06 -0700154 return ret;
Jason Sams326e0dd2009-05-22 14:03:28 -0700155}
156
Jason Sams177f8442010-10-29 10:19:21 -0700157
Jason Samsace3e012010-07-15 17:11:13 -0700158void ScriptC::runForEach(Context *rsc,
Stephen Hines44199772012-02-21 20:13:12 -0800159 uint32_t slot,
Jason Samsace3e012010-07-15 17:11:13 -0700160 const Allocation * ain,
161 Allocation * aout,
162 const void * usr,
Jason Sams87fe59a2011-04-20 15:09:01 -0700163 size_t usrBytes,
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800164 const RsScriptCall *sc) {
Jason Samscdfdb8f2011-03-17 16:12:47 -0700165
Jason Sams60709252010-11-17 15:29:32 -0800166 Context::PushState ps(rsc);
Jason Samsc61346b2010-05-28 18:23:22 -0700167
Jason Sams1f24db42010-12-11 17:42:30 -0800168 setupGLState(rsc);
Jason Samsc61346b2010-05-28 18:23:22 -0700169 setupScript(rsc);
Stephen Hines44199772012-02-21 20:13:12 -0800170 rsc->mHal.funcs.script.invokeForEach(rsc, this, slot, ain, aout, usr, usrBytes, sc);
Jason Samsc61346b2010-05-28 18:23:22 -0700171}
172
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700173void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) {
Jason Samsbad80742011-03-16 16:29:28 -0700174 if (slot >= mHal.info.exportedFunctionCount) {
Jason Sams22fa3712010-05-19 17:22:57 -0700175 rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script");
176 return;
177 }
Jason Samsc61346b2010-05-28 18:23:22 -0700178 setupScript(rsc);
Jason Sams22fa3712010-05-19 17:22:57 -0700179
Jason Samsb9077f42010-09-22 15:57:41 -0700180 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100181 ALOGV("%p ScriptC::Invoke invoking slot %i, ptr %p", rsc, slot, this);
Jason Samsb9077f42010-09-22 15:57:41 -0700182 }
Jason Samsbad80742011-03-16 16:29:28 -0700183 rsc->mHal.funcs.script.invokeFunction(rsc, this, slot, data, len);
Jason Sams22fa3712010-05-19 17:22:57 -0700184}
185
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800186ScriptCState::ScriptCState() {
Jason Sams326e0dd2009-05-22 14:03:28 -0700187}
188
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800189ScriptCState::~ScriptCState() {
Jason Sams1f526332009-06-05 17:35:09 -0700190}
191
Jason Sams87fe59a2011-04-20 15:09:01 -0700192/*
Shih-wei Liao2b2e6212011-01-14 06:21:28 -0800193static void* symbolLookup(void* pContext, char const* name) {
Jason Samsaeb094b2010-05-18 13:35:45 -0700194 const ScriptCState::SymbolTable_t *sym;
Jason Samsdd663fa2010-08-11 13:26:28 -0700195 ScriptC *s = (ScriptC *)pContext;
Shih-wei Liaof17b13b2010-12-07 13:44:10 -0800196 if (!strcmp(name, "__isThreadable")) {
Jason Samsbad80742011-03-16 16:29:28 -0700197 return (void*) s->mHal.info.isThreadable;
Shih-wei Liaof17b13b2010-12-07 13:44:10 -0800198 } else if (!strcmp(name, "__clearThreadable")) {
Jason Samsbad80742011-03-16 16:29:28 -0700199 s->mHal.info.isThreadable = false;
Shih-wei Liaof17b13b2010-12-07 13:44:10 -0800200 return NULL;
201 }
Jason Samsaeb094b2010-05-18 13:35:45 -0700202 sym = ScriptCState::lookupSymbol(name);
Jason Sams6bfc1b92010-11-01 14:26:30 -0700203 if (!sym) {
204 sym = ScriptCState::lookupSymbolCL(name);
Jason Samsaeb094b2010-05-18 13:35:45 -0700205 }
Jason Sams6bfc1b92010-11-01 14:26:30 -0700206 if (!sym) {
207 sym = ScriptCState::lookupSymbolGL(name);
Jason Samsaeb094b2010-05-18 13:35:45 -0700208 }
Jason Sams29df66f2009-07-16 15:08:06 -0700209 if (sym) {
Jason Samsbad80742011-03-16 16:29:28 -0700210 s->mHal.info.isThreadable &= sym->threadable;
Jason Sams29df66f2009-07-16 15:08:06 -0700211 return sym->mPtr;
212 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000213 ALOGE("ScriptC sym lookup failed for %s", name);
Jason Sams29df66f2009-07-16 15:08:06 -0700214 return NULL;
215}
Jason Sams87fe59a2011-04-20 15:09:01 -0700216*/
Jason Samsa4a54e42009-06-10 18:39:40 -0700217
Shih-wei Liao80761ec2011-01-16 02:23:04 -0800218#if 0
Shih-wei Liao1f9ba732010-10-23 02:15:57 -0700219extern const char rs_runtime_lib_bc[];
220extern unsigned rs_runtime_lib_bc_size;
Shih-wei Liao80761ec2011-01-16 02:23:04 -0800221#endif
Shih-wei Liao1f9ba732010-10-23 02:15:57 -0700222
Jason Samsbad80742011-03-16 16:29:28 -0700223bool ScriptC::runCompiler(Context *rsc,
224 const char *resName,
225 const char *cacheDir,
226 const uint8_t *bitcode,
227 size_t bitcodeLen) {
Shih-wei Liao37150de2011-01-07 18:17:07 -0800228
Steve Blockaf12ac62012-01-06 19:20:56 +0000229 //ALOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen);
Jason Sams93eacc72012-12-18 14:26:57 -0800230#ifndef RS_COMPATIBILITY_LIB
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700231#ifndef ANDROID_RS_SERIALIZE
Stephen Hinesf8d44692011-11-22 19:43:58 -0800232 uint32_t sdkVersion = 0;
233 bcinfo::BitcodeWrapper bcWrapper((const char *)bitcode, bitcodeLen);
234 if (!bcWrapper.unwrap()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000235 ALOGE("Bitcode is not in proper container format (raw or wrapper)");
Stephen Hinesf8d44692011-11-22 19:43:58 -0800236 return false;
237 }
238
Stephen Hinesf8d44692011-11-22 19:43:58 -0800239 if (bcWrapper.getBCFileType() == bcinfo::BC_WRAPPER) {
240 sdkVersion = bcWrapper.getTargetAPI();
241 }
242
243 if (sdkVersion == 0) {
244 // This signals that we didn't have a wrapper containing information
245 // about the bitcode.
246 sdkVersion = rsc->getTargetSdkVersion();
247 }
248
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700249 if (BT) {
250 delete BT;
251 }
252 BT = new bcinfo::BitcodeTranslator((const char *)bitcode, bitcodeLen,
253 sdkVersion);
254 if (!BT->translate()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000255 ALOGE("Failed to translate bitcode from version: %u", sdkVersion);
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700256 delete BT;
257 BT = NULL;
258 return false;
259 }
260 bitcode = (const uint8_t *) BT->getTranslatedBitcode();
261 bitcodeLen = BT->getTranslatedBitcodeSize();
262#endif
Shih-wei Liao37150de2011-01-07 18:17:07 -0800263
Tim Murray84bf2b82012-10-31 16:03:16 -0700264 if (!cacheDir) {
265 // MUST BE FIXED BEFORE ANYTHING USING C++ API IS RELEASED
266 cacheDir = getenv("EXTERNAL_STORAGE");
267 ALOGV("Cache dir changed to %s", cacheDir);
268 }
269
Tim Murraye78c14b2012-10-01 15:27:18 -0700270 // ensure that cache dir exists
Tim Murray84bf2b82012-10-31 16:03:16 -0700271 if (cacheDir && !createCacheDir(cacheDir)) {
Tim Murraye78c14b2012-10-01 15:27:18 -0700272 return false;
273 }
Jason Sams93eacc72012-12-18 14:26:57 -0800274#endif
Tim Murraye78c14b2012-10-01 15:27:18 -0700275
Jason Sams77020c52011-11-22 12:49:11 -0800276 if (!rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0)) {
277 return false;
278 }
Shih-wei Liao37150de2011-01-07 18:17:07 -0800279
Jason Sams77020c52011-11-22 12:49:11 -0800280 mInitialized = true;
Jason Sams93eacc72012-12-18 14:26:57 -0800281#ifndef RS_COMPATIBILITY_LIB
Jason Samsbad80742011-03-16 16:29:28 -0700282 mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
283 mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
284 mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore());
285 mEnviroment.mRaster.set(rsc->getDefaultProgramRaster());
Jason Sams93eacc72012-12-18 14:26:57 -0800286#endif
Shih-wei Liao37150de2011-01-07 18:17:07 -0800287
Jason Samsbad80742011-03-16 16:29:28 -0700288 rsc->mHal.funcs.script.invokeInit(rsc, this);
Stephen Hines7b337b12011-01-17 17:31:58 -0800289
Jason Samsbad80742011-03-16 16:29:28 -0700290 for (size_t i=0; i < mHal.info.exportedPragmaCount; ++i) {
291 const char * key = mHal.info.exportedPragmaKeyList[i];
292 const char * value = mHal.info.exportedPragmaValueList[i];
Steve Blockaf12ac62012-01-06 19:20:56 +0000293 //ALOGE("pragma %s %s", keys[i], values[i]);
Jason Samsbad80742011-03-16 16:29:28 -0700294 if (!strcmp(key, "version")) {
295 if (!strcmp(value, "1")) {
Stephen Hinesb5dc6af2011-01-18 14:10:44 -0800296 continue;
297 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000298 ALOGE("Invalid version pragma value: %s\n", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800299 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800300 }
301
Jason Sams93eacc72012-12-18 14:26:57 -0800302#ifndef RS_COMPATIBILITY_LIB
Jason Samsbad80742011-03-16 16:29:28 -0700303 if (!strcmp(key, "stateVertex")) {
304 if (!strcmp(value, "default")) {
Jason Sams10308932009-06-09 12:15:30 -0700305 continue;
Jason Sams10308932009-06-09 12:15:30 -0700306 }
Jason Samsbad80742011-03-16 16:29:28 -0700307 if (!strcmp(value, "parent")) {
308 mEnviroment.mVertex.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800309 continue;
Jason Sams10308932009-06-09 12:15:30 -0700310 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000311 ALOGE("Unrecognized value %s passed to stateVertex", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800312 return false;
Jason Sams10308932009-06-09 12:15:30 -0700313 }
Stephen Hines7b337b12011-01-17 17:31:58 -0800314
Jason Samsbad80742011-03-16 16:29:28 -0700315 if (!strcmp(key, "stateRaster")) {
316 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800317 continue;
318 }
Jason Samsbad80742011-03-16 16:29:28 -0700319 if (!strcmp(value, "parent")) {
320 mEnviroment.mRaster.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800321 continue;
322 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000323 ALOGE("Unrecognized value %s passed to stateRaster", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800324 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800325 }
326
Jason Samsbad80742011-03-16 16:29:28 -0700327 if (!strcmp(key, "stateFragment")) {
328 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800329 continue;
330 }
Jason Samsbad80742011-03-16 16:29:28 -0700331 if (!strcmp(value, "parent")) {
332 mEnviroment.mFragment.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800333 continue;
334 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000335 ALOGE("Unrecognized value %s passed to stateFragment", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800336 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800337 }
338
Jason Samsbad80742011-03-16 16:29:28 -0700339 if (!strcmp(key, "stateStore")) {
340 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800341 continue;
342 }
Jason Samsbad80742011-03-16 16:29:28 -0700343 if (!strcmp(value, "parent")) {
344 mEnviroment.mFragmentStore.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800345 continue;
346 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000347 ALOGE("Unrecognized value %s passed to stateStore", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800348 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800349 }
Jason Sams93eacc72012-12-18 14:26:57 -0800350#endif
351
Jason Sams10308932009-06-09 12:15:30 -0700352 }
Jason Sams2e8665d2011-01-27 00:14:13 -0800353
Jason Samsbad80742011-03-16 16:29:28 -0700354 mSlots = new ObjectBaseRef<Allocation>[mHal.info.exportedVariableCount];
355 mTypes = new ObjectBaseRef<const Type>[mHal.info.exportedVariableCount];
Jason Sams2e8665d2011-01-27 00:14:13 -0800356
Jason Sams26b2c9f2011-01-19 16:14:21 -0800357 return true;
Jason Sams326e0dd2009-05-22 14:03:28 -0700358}
359
360namespace android {
361namespace renderscript {
362
Shih-wei Liaoce8a0792010-12-20 20:45:56 +0800363RsScript rsi_ScriptCCreate(Context *rsc,
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700364 const char *resName, size_t resName_length,
365 const char *cacheDir, size_t cacheDir_length,
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700366 const char *text, size_t text_length)
Shih-wei Liao9503b662010-11-08 01:33:59 -0800367{
Jason Sams249d4532011-01-23 17:48:45 -0800368 ScriptC *s = new ScriptC(rsc);
Jason Sams1f526332009-06-05 17:35:09 -0700369
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700370 if (!s->runCompiler(rsc, resName, cacheDir, (uint8_t *)text, text_length)) {
Jason Sams26b2c9f2011-01-19 16:14:21 -0800371 // Error during compile, destroy s and return null.
Stephen Hines4769d682012-02-02 13:23:20 -0800372 ObjectBase::checkDelete(s);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800373 return NULL;
374 }
Jason Samsbad80742011-03-16 16:29:28 -0700375
376 s->incUserRef();
Jason Sams249d4532011-01-23 17:48:45 -0800377 return s;
Jason Sams326e0dd2009-05-22 14:03:28 -0700378}
379
Jason Sams326e0dd2009-05-22 14:03:28 -0700380}
381}