blob: e7ff8c7d50904de288e86c84ffe02c72ce4d98c2 [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
Jean-Luc Brouilletf4d216e2014-06-09 18:04:16 -070020#if !defined(RS_COMPATIBILITY_LIB) && !defined(ANDROID_RS_SERIALIZE)
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070021#include <bcinfo/BitcodeTranslator.h>
Stephen Hinesf8d44692011-11-22 19:43:58 -080022#include <bcinfo/BitcodeWrapper.h>
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070023#endif
24
Stephen Hinesb0934b62013-07-03 17:27:38 -070025#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
Tim Murray0b575de2013-03-15 15:56:43 -070026#include "utils/Timers.h"
Tobias Grosser47935ac2013-06-17 11:47:26 -070027#include "cutils/trace.h"
Stephen Hines574854b2013-07-10 08:29:51 -070028#endif
Tobias Grosser47935ac2013-06-17 11:47:26 -070029
Tim Murraye78c14b2012-10-01 15:27:18 -070030#include <sys/stat.h>
31
Jason Sams326e0dd2009-05-22 14:03:28 -070032using namespace android;
33using namespace android::renderscript;
34
Jason Samse5769102009-06-19 16:03:18 -070035#define GET_TLS() Context::ScriptTLSStruct * tls = \
36 (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
37 Context * rsc = tls->mContext; \
38 ScriptC * sc = (ScriptC *) tls->mScript
39
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080040ScriptC::ScriptC(Context *rsc) : Script(rsc) {
Jean-Luc Brouilletf4d216e2014-06-09 18:04:16 -070041#if !defined(RS_COMPATIBILITY_LIB) && !defined(ANDROID_RS_SERIALIZE)
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070042 BT = NULL;
43#endif
Jason Sams326e0dd2009-05-22 14:03:28 -070044}
45
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080046ScriptC::~ScriptC() {
Jean-Luc Brouilletf4d216e2014-06-09 18:04:16 -070047#if !defined(RS_COMPATIBILITY_LIB) && !defined(ANDROID_RS_SERIALIZE)
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070048 if (BT) {
49 delete BT;
50 BT = NULL;
51 }
52#endif
Jason Sams77020c52011-11-22 12:49:11 -080053 if (mInitialized) {
54 mRSC->mHal.funcs.script.invokeFreeChildren(mRSC, this);
55 mRSC->mHal.funcs.script.destroy(mRSC, this);
56 }
Jason Sams326e0dd2009-05-22 14:03:28 -070057}
58
Jason Sams93eacc72012-12-18 14:26:57 -080059#ifndef RS_COMPATIBILITY_LIB
Tim Murraye78c14b2012-10-01 15:27:18 -070060bool ScriptC::createCacheDir(const char *cacheDir) {
61 String8 cacheDirString, currentDir;
62 struct stat statBuf;
63 int statReturn = stat(cacheDir, &statBuf);
64 if (!statReturn) {
65 return true;
66 }
67
68 // String8 path functions strip leading /'s
69 // insert if necessary
70 if (cacheDir[0] == '/') {
71 currentDir += "/";
72 }
73
74 cacheDirString.setPathName(cacheDir);
75
76 while (cacheDirString.length()) {
77 currentDir += (cacheDirString.walkPath(&cacheDirString));
78 statReturn = stat(currentDir.string(), &statBuf);
79 if (statReturn) {
80 if (errno == ENOENT) {
81 if (mkdir(currentDir.string(), S_IRUSR | S_IWUSR | S_IXUSR)) {
82 ALOGE("Couldn't create cache directory: %s",
83 currentDir.string());
84 ALOGE("Error: %s", strerror(errno));
85 return false;
86 }
87 } else {
88 ALOGE("Stat error: %s", strerror(errno));
89 return false;
90 }
91 }
92 currentDir += "/";
93 }
94 return true;
95}
Jason Sams93eacc72012-12-18 14:26:57 -080096#endif
Tim Murraye78c14b2012-10-01 15:27:18 -070097
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080098void ScriptC::setupScript(Context *rsc) {
Tim Murray0b575de2013-03-15 15:56:43 -070099#ifndef RS_SERVER
Jason Samsc61346b2010-05-28 18:23:22 -0700100 mEnviroment.mStartTimeMillis
101 = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
Tim Murray0b575de2013-03-15 15:56:43 -0700102#endif
Jason Samsc61346b2010-05-28 18:23:22 -0700103
Jason Samsbad80742011-03-16 16:29:28 -0700104 for (uint32_t ct=0; ct < mHal.info.exportedVariableCount; ct++) {
Jason Sams900f1612010-09-16 18:18:29 -0700105 if (mSlots[ct].get() && !mTypes[ct].get()) {
106 mTypes[ct].set(mSlots[ct]->getType());
107 }
108
109 if (!mTypes[ct].get())
Jason Samsbe36bf32010-05-11 14:03:58 -0700110 continue;
Jason Sams807fdc42012-07-25 17:55:39 -0700111 rsc->mHal.funcs.script.setGlobalBind(rsc, this, ct, mSlots[ct].get());
Jason Samsada7f272009-09-24 14:55:38 -0700112 }
113}
114
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800115void ScriptC::setupGLState(Context *rsc) {
Jason Sams93eacc72012-12-18 14:26:57 -0800116#ifndef RS_COMPATIBILITY_LIB
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700117 if (mEnviroment.mFragmentStore.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800118 rsc->setProgramStore(mEnviroment.mFragmentStore.get());
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700119 }
120 if (mEnviroment.mFragment.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800121 rsc->setProgramFragment(mEnviroment.mFragment.get());
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700122 }
Jason Sams8ce125b2009-06-17 16:52:59 -0700123 if (mEnviroment.mVertex.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800124 rsc->setProgramVertex(mEnviroment.mVertex.get());
Jason Sams8ce125b2009-06-17 16:52:59 -0700125 }
Jason Samsb681c8a2009-09-28 18:12:56 -0700126 if (mEnviroment.mRaster.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800127 rsc->setProgramRaster(mEnviroment.mRaster.get());
Jason Samsb681c8a2009-09-28 18:12:56 -0700128 }
Jason Sams93eacc72012-12-18 14:26:57 -0800129#endif
Jason Samsc61346b2010-05-28 18:23:22 -0700130}
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700131
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800132uint32_t ScriptC::run(Context *rsc) {
Jason Samsbad80742011-03-16 16:29:28 -0700133 if (mHal.info.root == NULL) {
Jason Samsc61346b2010-05-28 18:23:22 -0700134 rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script");
135 return 0;
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700136 }
Jason Samsc61346b2010-05-28 18:23:22 -0700137
Jason Sams1f24db42010-12-11 17:42:30 -0800138 setupGLState(rsc);
Jason Samsc61346b2010-05-28 18:23:22 -0700139 setupScript(rsc);
Jason Sams1d54f102009-09-03 15:43:13 -0700140
Jason Sams2dca84d2009-12-09 11:05:45 -0800141 uint32_t ret = 0;
Jason Samsb9077f42010-09-22 15:57:41 -0700142
143 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100144 ALOGV("%p ScriptC::run invoking root, ptr %p", rsc, mHal.info.root);
Jason Samsb9077f42010-09-22 15:57:41 -0700145 }
146
Jason Samscdfdb8f2011-03-17 16:12:47 -0700147 ret = rsc->mHal.funcs.script.invokeRoot(rsc, this);
Jason Samsb9077f42010-09-22 15:57:41 -0700148
149 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100150 ALOGV("%p ScriptC::run invoking complete, ret=%i", rsc, ret);
Jason Samsb9077f42010-09-22 15:57:41 -0700151 }
152
Jason Samse45ac6e2009-07-20 14:31:06 -0700153 return ret;
Jason Sams326e0dd2009-05-22 14:03:28 -0700154}
155
Jason Sams177f8442010-10-29 10:19:21 -0700156
Jason Samsace3e012010-07-15 17:11:13 -0700157void ScriptC::runForEach(Context *rsc,
Stephen Hines44199772012-02-21 20:13:12 -0800158 uint32_t slot,
Jason Samsace3e012010-07-15 17:11:13 -0700159 const Allocation * ain,
160 Allocation * aout,
161 const void * usr,
Jason Sams87fe59a2011-04-20 15:09:01 -0700162 size_t usrBytes,
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800163 const RsScriptCall *sc) {
Tobias Grosser47935ac2013-06-17 11:47:26 -0700164 // Trace this function call.
165 // To avoid overhead, we only build the string, if tracing is actually
166 // enabled.
167 String8 *AString = NULL;
168 const char *String = "";
169 if (ATRACE_ENABLED()) {
170 AString = new String8("runForEach_");
171 AString->append(mHal.info.exportedForeachFuncList[slot].first);
172 String = AString->string();
173 }
174 ATRACE_NAME(String);
175 (void)String;
Tim Murrayfa85e912013-05-23 13:19:36 -0700176
Jason Sams60709252010-11-17 15:29:32 -0800177 Context::PushState ps(rsc);
Jason Samsc61346b2010-05-28 18:23:22 -0700178
Jason Sams1f24db42010-12-11 17:42:30 -0800179 setupGLState(rsc);
Jason Samsc61346b2010-05-28 18:23:22 -0700180 setupScript(rsc);
Stephen Hines44199772012-02-21 20:13:12 -0800181 rsc->mHal.funcs.script.invokeForEach(rsc, this, slot, ain, aout, usr, usrBytes, sc);
Tobias Grosser47935ac2013-06-17 11:47:26 -0700182
183 if (AString)
184 delete AString;
Jason Samsc61346b2010-05-28 18:23:22 -0700185}
186
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700187void ScriptC::runForEach(Context *rsc,
188 uint32_t slot,
189 const Allocation ** ains,
190 size_t inLen,
191 Allocation * aout,
192 const void * usr,
193 size_t usrBytes,
194 const RsScriptCall *sc) {
195 // Trace this function call.
196 // To avoid overhead we only build the string if tracing is actually
197 // enabled.
198 String8 *AString = NULL;
199 const char *String = "";
200 if (ATRACE_ENABLED()) {
201 AString = new String8("runForEach_");
202 AString->append(mHal.info.exportedForeachFuncList[slot].first);
203 String = AString->string();
204 }
205 ATRACE_NAME(String);
206 (void)String;
207
208 Context::PushState ps(rsc);
209
210 setupGLState(rsc);
211 setupScript(rsc);
212
213 rsc->mHal.funcs.script.invokeForEachMulti(rsc, this, slot, ains, inLen, aout, usr, usrBytes, sc);
214
215 if (AString)
216 delete AString;
217}
218
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700219void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) {
Tim Murrayfa85e912013-05-23 13:19:36 -0700220 ATRACE_CALL();
221
Jason Samsbad80742011-03-16 16:29:28 -0700222 if (slot >= mHal.info.exportedFunctionCount) {
Jason Sams22fa3712010-05-19 17:22:57 -0700223 rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script");
224 return;
225 }
Jason Samsc61346b2010-05-28 18:23:22 -0700226 setupScript(rsc);
Jason Sams22fa3712010-05-19 17:22:57 -0700227
Jason Samsb9077f42010-09-22 15:57:41 -0700228 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100229 ALOGV("%p ScriptC::Invoke invoking slot %i, ptr %p", rsc, slot, this);
Jason Samsb9077f42010-09-22 15:57:41 -0700230 }
Jason Samsbad80742011-03-16 16:29:28 -0700231 rsc->mHal.funcs.script.invokeFunction(rsc, this, slot, data, len);
Jason Sams22fa3712010-05-19 17:22:57 -0700232}
233
Jason Samsbad80742011-03-16 16:29:28 -0700234bool ScriptC::runCompiler(Context *rsc,
235 const char *resName,
236 const char *cacheDir,
237 const uint8_t *bitcode,
238 size_t bitcodeLen) {
Tim Murrayfa85e912013-05-23 13:19:36 -0700239 ATRACE_CALL();
Steve Blockaf12ac62012-01-06 19:20:56 +0000240 //ALOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen);
Jason Sams93eacc72012-12-18 14:26:57 -0800241#ifndef RS_COMPATIBILITY_LIB
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700242#ifndef ANDROID_RS_SERIALIZE
Stephen Hinesf8d44692011-11-22 19:43:58 -0800243 uint32_t sdkVersion = 0;
244 bcinfo::BitcodeWrapper bcWrapper((const char *)bitcode, bitcodeLen);
245 if (!bcWrapper.unwrap()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000246 ALOGE("Bitcode is not in proper container format (raw or wrapper)");
Stephen Hinesf8d44692011-11-22 19:43:58 -0800247 return false;
248 }
249
Stephen Hinesf8d44692011-11-22 19:43:58 -0800250 if (bcWrapper.getBCFileType() == bcinfo::BC_WRAPPER) {
251 sdkVersion = bcWrapper.getTargetAPI();
252 }
253
254 if (sdkVersion == 0) {
255 // This signals that we didn't have a wrapper containing information
256 // about the bitcode.
257 sdkVersion = rsc->getTargetSdkVersion();
258 }
259
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700260 if (BT) {
261 delete BT;
262 }
263 BT = new bcinfo::BitcodeTranslator((const char *)bitcode, bitcodeLen,
264 sdkVersion);
265 if (!BT->translate()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000266 ALOGE("Failed to translate bitcode from version: %u", sdkVersion);
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700267 delete BT;
268 BT = NULL;
269 return false;
270 }
271 bitcode = (const uint8_t *) BT->getTranslatedBitcode();
272 bitcodeLen = BT->getTranslatedBitcodeSize();
Shih-wei Liao37150de2011-01-07 18:17:07 -0800273
Tim Murraye195a3f2014-03-13 15:04:58 -0700274#endif
Tim Murray84bf2b82012-10-31 16:03:16 -0700275 if (!cacheDir) {
276 // MUST BE FIXED BEFORE ANYTHING USING C++ API IS RELEASED
277 cacheDir = getenv("EXTERNAL_STORAGE");
278 ALOGV("Cache dir changed to %s", cacheDir);
279 }
280
Tim Murraye78c14b2012-10-01 15:27:18 -0700281 // ensure that cache dir exists
Tim Murray84bf2b82012-10-31 16:03:16 -0700282 if (cacheDir && !createCacheDir(cacheDir)) {
Tim Murraye78c14b2012-10-01 15:27:18 -0700283 return false;
284 }
Jason Sams93eacc72012-12-18 14:26:57 -0800285#endif
Tim Murraye78c14b2012-10-01 15:27:18 -0700286
Jason Sams77020c52011-11-22 12:49:11 -0800287 if (!rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0)) {
288 return false;
289 }
Shih-wei Liao37150de2011-01-07 18:17:07 -0800290
Jason Sams77020c52011-11-22 12:49:11 -0800291 mInitialized = true;
Jason Sams93eacc72012-12-18 14:26:57 -0800292#ifndef RS_COMPATIBILITY_LIB
Jason Samsbad80742011-03-16 16:29:28 -0700293 mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
294 mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
295 mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore());
296 mEnviroment.mRaster.set(rsc->getDefaultProgramRaster());
Jason Sams93eacc72012-12-18 14:26:57 -0800297#endif
Shih-wei Liao37150de2011-01-07 18:17:07 -0800298
Jason Samsbad80742011-03-16 16:29:28 -0700299 rsc->mHal.funcs.script.invokeInit(rsc, this);
Stephen Hines7b337b12011-01-17 17:31:58 -0800300
Jason Samsbad80742011-03-16 16:29:28 -0700301 for (size_t i=0; i < mHal.info.exportedPragmaCount; ++i) {
302 const char * key = mHal.info.exportedPragmaKeyList[i];
303 const char * value = mHal.info.exportedPragmaValueList[i];
Steve Blockaf12ac62012-01-06 19:20:56 +0000304 //ALOGE("pragma %s %s", keys[i], values[i]);
Jason Samsbad80742011-03-16 16:29:28 -0700305 if (!strcmp(key, "version")) {
306 if (!strcmp(value, "1")) {
Stephen Hinesb5dc6af2011-01-18 14:10:44 -0800307 continue;
308 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000309 ALOGE("Invalid version pragma value: %s\n", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800310 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800311 }
312
Jason Sams93eacc72012-12-18 14:26:57 -0800313#ifndef RS_COMPATIBILITY_LIB
Jason Samsbad80742011-03-16 16:29:28 -0700314 if (!strcmp(key, "stateVertex")) {
315 if (!strcmp(value, "default")) {
Jason Sams10308932009-06-09 12:15:30 -0700316 continue;
Jason Sams10308932009-06-09 12:15:30 -0700317 }
Jason Samsbad80742011-03-16 16:29:28 -0700318 if (!strcmp(value, "parent")) {
319 mEnviroment.mVertex.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800320 continue;
Jason Sams10308932009-06-09 12:15:30 -0700321 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000322 ALOGE("Unrecognized value %s passed to stateVertex", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800323 return false;
Jason Sams10308932009-06-09 12:15:30 -0700324 }
Stephen Hines7b337b12011-01-17 17:31:58 -0800325
Jason Samsbad80742011-03-16 16:29:28 -0700326 if (!strcmp(key, "stateRaster")) {
327 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800328 continue;
329 }
Jason Samsbad80742011-03-16 16:29:28 -0700330 if (!strcmp(value, "parent")) {
331 mEnviroment.mRaster.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800332 continue;
333 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000334 ALOGE("Unrecognized value %s passed to stateRaster", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800335 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800336 }
337
Jason Samsbad80742011-03-16 16:29:28 -0700338 if (!strcmp(key, "stateFragment")) {
339 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800340 continue;
341 }
Jason Samsbad80742011-03-16 16:29:28 -0700342 if (!strcmp(value, "parent")) {
343 mEnviroment.mFragment.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800344 continue;
345 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000346 ALOGE("Unrecognized value %s passed to stateFragment", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800347 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800348 }
349
Jason Samsbad80742011-03-16 16:29:28 -0700350 if (!strcmp(key, "stateStore")) {
351 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800352 continue;
353 }
Jason Samsbad80742011-03-16 16:29:28 -0700354 if (!strcmp(value, "parent")) {
355 mEnviroment.mFragmentStore.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800356 continue;
357 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000358 ALOGE("Unrecognized value %s passed to stateStore", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800359 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800360 }
Jason Sams93eacc72012-12-18 14:26:57 -0800361#endif
362
Jason Sams10308932009-06-09 12:15:30 -0700363 }
Jason Sams2e8665d2011-01-27 00:14:13 -0800364
Jason Samsbad80742011-03-16 16:29:28 -0700365 mSlots = new ObjectBaseRef<Allocation>[mHal.info.exportedVariableCount];
366 mTypes = new ObjectBaseRef<const Type>[mHal.info.exportedVariableCount];
Jason Sams2e8665d2011-01-27 00:14:13 -0800367
Jason Sams26b2c9f2011-01-19 16:14:21 -0800368 return true;
Jason Sams326e0dd2009-05-22 14:03:28 -0700369}
370
371namespace android {
372namespace renderscript {
373
Shih-wei Liaoce8a0792010-12-20 20:45:56 +0800374RsScript rsi_ScriptCCreate(Context *rsc,
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700375 const char *resName, size_t resName_length,
376 const char *cacheDir, size_t cacheDir_length,
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700377 const char *text, size_t text_length)
Shih-wei Liao9503b662010-11-08 01:33:59 -0800378{
Jason Sams249d4532011-01-23 17:48:45 -0800379 ScriptC *s = new ScriptC(rsc);
Jason Sams1f526332009-06-05 17:35:09 -0700380
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700381 if (!s->runCompiler(rsc, resName, cacheDir, (uint8_t *)text, text_length)) {
Jason Sams26b2c9f2011-01-19 16:14:21 -0800382 // Error during compile, destroy s and return null.
Stephen Hines4769d682012-02-02 13:23:20 -0800383 ObjectBase::checkDelete(s);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800384 return NULL;
385 }
Jason Samsbad80742011-03-16 16:29:28 -0700386
387 s->incUserRef();
Jason Sams249d4532011-01-23 17:48:45 -0800388 return s;
Jason Sams326e0dd2009-05-22 14:03:28 -0700389}
390
Jason Sams326e0dd2009-05-22 14:03:28 -0700391}
392}