blob: 71761f1c81a06fa588713bc608eb10e7954d9240 [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
Chris Wailes93d6bc82014-07-28 16:54:38 -070017#include <string>
18
Jason Sams326e0dd2009-05-22 14:03:28 -070019#include "rsContext.h"
20#include "rsScriptC.h"
Jack Palevich1ef8b802009-05-28 15:53:04 -070021
Jean-Luc Brouilletf4d216e2014-06-09 18:04:16 -070022#if !defined(RS_COMPATIBILITY_LIB) && !defined(ANDROID_RS_SERIALIZE)
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070023#include <bcinfo/BitcodeTranslator.h>
Stephen Hinesf8d44692011-11-22 19:43:58 -080024#include <bcinfo/BitcodeWrapper.h>
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070025#endif
26
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"
Tobias Grosser47935ac2013-06-17 11:47:26 -070029#include "cutils/trace.h"
Stephen Hines574854b2013-07-10 08:29:51 -070030#endif
Tobias Grosser47935ac2013-06-17 11:47:26 -070031
Tim Murraye78c14b2012-10-01 15:27:18 -070032#include <sys/stat.h>
33
Chris Wailes6847e732014-08-11 17:30:51 -070034#ifdef USE_MINGW
35/* Define the default path separator for the platform. */
36#define OS_PATH_SEPARATOR '\\'
37#define OS_PATH_SEPARATOR_STR "\\"
38
39#else /* not USE_MINGW */
40
41/* Define the default path separator for the platform. */
42#define OS_PATH_SEPARATOR '/'
43#define OS_PATH_SEPARATOR_STR "/"
44
45#endif
46
Jason Sams326e0dd2009-05-22 14:03:28 -070047using namespace android;
48using namespace android::renderscript;
49
Jason Samse5769102009-06-19 16:03:18 -070050#define GET_TLS() Context::ScriptTLSStruct * tls = \
51 (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \
52 Context * rsc = tls->mContext; \
53 ScriptC * sc = (ScriptC *) tls->mScript
54
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080055ScriptC::ScriptC(Context *rsc) : Script(rsc) {
Jean-Luc Brouilletf4d216e2014-06-09 18:04:16 -070056#if !defined(RS_COMPATIBILITY_LIB) && !defined(ANDROID_RS_SERIALIZE)
Chris Wailes44bef6f2014-08-12 13:51:10 -070057 BT = nullptr;
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070058#endif
Jason Sams326e0dd2009-05-22 14:03:28 -070059}
60
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080061ScriptC::~ScriptC() {
Jean-Luc Brouilletf4d216e2014-06-09 18:04:16 -070062#if !defined(RS_COMPATIBILITY_LIB) && !defined(ANDROID_RS_SERIALIZE)
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070063 if (BT) {
64 delete BT;
Chris Wailes44bef6f2014-08-12 13:51:10 -070065 BT = nullptr;
Stephen Hinescbb0b8a2011-08-01 15:02:34 -070066 }
67#endif
Jason Sams77020c52011-11-22 12:49:11 -080068 if (mInitialized) {
69 mRSC->mHal.funcs.script.invokeFreeChildren(mRSC, this);
70 mRSC->mHal.funcs.script.destroy(mRSC, this);
71 }
Jason Sams326e0dd2009-05-22 14:03:28 -070072}
73
Jason Sams93eacc72012-12-18 14:26:57 -080074#ifndef RS_COMPATIBILITY_LIB
Tim Murraye78c14b2012-10-01 15:27:18 -070075bool ScriptC::createCacheDir(const char *cacheDir) {
Chris Wailes6847e732014-08-11 17:30:51 -070076 std::string currentDir;
77 const std::string cacheDirString(cacheDir);
78
Tim Murraye78c14b2012-10-01 15:27:18 -070079 struct stat statBuf;
80 int statReturn = stat(cacheDir, &statBuf);
81 if (!statReturn) {
82 return true;
83 }
84
Chris Wailes6847e732014-08-11 17:30:51 -070085 // Start from the beginning of the cacheDirString.
86 int currPos = 0;
Tim Murraye78c14b2012-10-01 15:27:18 -070087
Chris Wailes6847e732014-08-11 17:30:51 -070088 // Reserve space in currentDir for the entire cacheDir path.
89 currentDir.reserve(cacheDirString.length());
Tim Murraye78c14b2012-10-01 15:27:18 -070090
Chris Wailes6847e732014-08-11 17:30:51 -070091 while (currPos >= 0) {
92 /*
93 * The character at currPos should be a path separator. We need to look
94 * for the next one.
95 */
96 int nextPos = cacheDirString.find(OS_PATH_SEPARATOR_STR, currPos + 1);
97
98 if (nextPos > 0) {
99 // A new path separator has been found.
100 currentDir += cacheDirString.substr(currPos, nextPos - currPos);
101 } else {
102 // There are no more path separators.
103 currentDir += cacheDirString.substr(currPos);
104 }
105
106 currPos = nextPos;
107
108 statReturn = stat(currentDir.c_str(), &statBuf);
109
Tim Murraye78c14b2012-10-01 15:27:18 -0700110 if (statReturn) {
111 if (errno == ENOENT) {
Chris Wailes6847e732014-08-11 17:30:51 -0700112 if (mkdir(currentDir.c_str(), S_IRUSR | S_IWUSR | S_IXUSR)) {
Tim Murraye78c14b2012-10-01 15:27:18 -0700113 ALOGE("Couldn't create cache directory: %s",
Chris Wailes6847e732014-08-11 17:30:51 -0700114 currentDir.c_str());
Tim Murraye78c14b2012-10-01 15:27:18 -0700115 ALOGE("Error: %s", strerror(errno));
116 return false;
117 }
118 } else {
119 ALOGE("Stat error: %s", strerror(errno));
120 return false;
121 }
122 }
Tim Murraye78c14b2012-10-01 15:27:18 -0700123 }
124 return true;
125}
Jason Sams93eacc72012-12-18 14:26:57 -0800126#endif
Tim Murraye78c14b2012-10-01 15:27:18 -0700127
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800128void ScriptC::setupScript(Context *rsc) {
Tim Murray0b575de2013-03-15 15:56:43 -0700129#ifndef RS_SERVER
Jason Samsc61346b2010-05-28 18:23:22 -0700130 mEnviroment.mStartTimeMillis
131 = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
Tim Murray0b575de2013-03-15 15:56:43 -0700132#endif
Jason Samsc61346b2010-05-28 18:23:22 -0700133
Jason Samsbad80742011-03-16 16:29:28 -0700134 for (uint32_t ct=0; ct < mHal.info.exportedVariableCount; ct++) {
Jason Sams900f1612010-09-16 18:18:29 -0700135 if (mSlots[ct].get() && !mTypes[ct].get()) {
136 mTypes[ct].set(mSlots[ct]->getType());
137 }
138
139 if (!mTypes[ct].get())
Jason Samsbe36bf32010-05-11 14:03:58 -0700140 continue;
Jason Sams807fdc42012-07-25 17:55:39 -0700141 rsc->mHal.funcs.script.setGlobalBind(rsc, this, ct, mSlots[ct].get());
Jason Samsada7f272009-09-24 14:55:38 -0700142 }
143}
144
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800145void ScriptC::setupGLState(Context *rsc) {
Jason Sams93eacc72012-12-18 14:26:57 -0800146#ifndef RS_COMPATIBILITY_LIB
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700147 if (mEnviroment.mFragmentStore.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800148 rsc->setProgramStore(mEnviroment.mFragmentStore.get());
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700149 }
150 if (mEnviroment.mFragment.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800151 rsc->setProgramFragment(mEnviroment.mFragment.get());
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700152 }
Jason Sams8ce125b2009-06-17 16:52:59 -0700153 if (mEnviroment.mVertex.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800154 rsc->setProgramVertex(mEnviroment.mVertex.get());
Jason Sams8ce125b2009-06-17 16:52:59 -0700155 }
Jason Samsb681c8a2009-09-28 18:12:56 -0700156 if (mEnviroment.mRaster.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800157 rsc->setProgramRaster(mEnviroment.mRaster.get());
Jason Samsb681c8a2009-09-28 18:12:56 -0700158 }
Jason Sams93eacc72012-12-18 14:26:57 -0800159#endif
Jason Samsc61346b2010-05-28 18:23:22 -0700160}
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700161
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800162uint32_t ScriptC::run(Context *rsc) {
Chris Wailes44bef6f2014-08-12 13:51:10 -0700163 if (mHal.info.root == nullptr) {
Jason Samsc61346b2010-05-28 18:23:22 -0700164 rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script");
165 return 0;
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700166 }
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);
Jason Sams1d54f102009-09-03 15:43:13 -0700170
Jason Sams2dca84d2009-12-09 11:05:45 -0800171 uint32_t ret = 0;
Jason Samsb9077f42010-09-22 15:57:41 -0700172
173 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100174 ALOGV("%p ScriptC::run invoking root, ptr %p", rsc, mHal.info.root);
Jason Samsb9077f42010-09-22 15:57:41 -0700175 }
176
Jason Samscdfdb8f2011-03-17 16:12:47 -0700177 ret = rsc->mHal.funcs.script.invokeRoot(rsc, this);
Jason Samsb9077f42010-09-22 15:57:41 -0700178
179 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100180 ALOGV("%p ScriptC::run invoking complete, ret=%i", rsc, ret);
Jason Samsb9077f42010-09-22 15:57:41 -0700181 }
182
Jason Samse45ac6e2009-07-20 14:31:06 -0700183 return ret;
Jason Sams326e0dd2009-05-22 14:03:28 -0700184}
185
Jason Sams177f8442010-10-29 10:19:21 -0700186
Jason Samsace3e012010-07-15 17:11:13 -0700187void ScriptC::runForEach(Context *rsc,
Stephen Hines44199772012-02-21 20:13:12 -0800188 uint32_t slot,
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700189 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.
Chris Wailes44bef6f2014-08-12 13:51:10 -0700198 std::string *traceString = nullptr;
Chris Wailes93d6bc82014-07-28 16:54:38 -0700199 const char *stringData = "";
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700200 if (ATRACE_ENABLED()) {
Chris Wailes93d6bc82014-07-28 16:54:38 -0700201 traceString = new std::string("runForEach_");
202 traceString->append(mHal.info.exportedForeachFuncList[slot].first);
203 stringData = traceString->c_str();
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700204 }
Chris Wailes93d6bc82014-07-28 16:54:38 -0700205 ATRACE_NAME(stringData);
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700206
207 Context::PushState ps(rsc);
208
209 setupGLState(rsc);
210 setupScript(rsc);
211
Chris Wailes44bef6f2014-08-12 13:51:10 -0700212 if (rsc->mHal.funcs.script.invokeForEachMulti != nullptr) {
Chris Wailesf3712132014-07-16 15:18:30 -0700213 rsc->mHal.funcs.script.invokeForEachMulti(rsc, this, slot, ains, inLen,
214 aout, usr, usrBytes, sc);
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700215
Chris Wailesf3712132014-07-16 15:18:30 -0700216 } else if (inLen == 1) {
217 rsc->mHal.funcs.script.invokeForEach(rsc, this, slot, ains[0], aout,
218 usr, usrBytes, sc);
219
220 } else {
221 rsc->setError(RS_ERROR_FATAL_DRIVER,
222 "Driver support for multi-input not present");
223 }
224
Chris Wailes93d6bc82014-07-28 16:54:38 -0700225 if (traceString) {
226 delete traceString;
Chris Wailesf3712132014-07-16 15:18:30 -0700227 }
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700228}
229
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700230void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) {
Tim Murrayfa85e912013-05-23 13:19:36 -0700231 ATRACE_CALL();
232
Jason Samsbad80742011-03-16 16:29:28 -0700233 if (slot >= mHal.info.exportedFunctionCount) {
Jason Sams22fa3712010-05-19 17:22:57 -0700234 rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script");
235 return;
236 }
Jason Samsc61346b2010-05-28 18:23:22 -0700237 setupScript(rsc);
Jason Sams22fa3712010-05-19 17:22:57 -0700238
Jason Samsb9077f42010-09-22 15:57:41 -0700239 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100240 ALOGV("%p ScriptC::Invoke invoking slot %i, ptr %p", rsc, slot, this);
Jason Samsb9077f42010-09-22 15:57:41 -0700241 }
Jason Samsbad80742011-03-16 16:29:28 -0700242 rsc->mHal.funcs.script.invokeFunction(rsc, this, slot, data, len);
Jason Sams22fa3712010-05-19 17:22:57 -0700243}
244
Stephen Hinesf6af3bd2014-12-23 17:47:43 -0800245static const bool kDebugBitcode = false;
246
247#ifndef RS_COMPATIBILITY_LIB
248#ifndef ANDROID_RS_SERIALIZE
249
250static bool dumpBitcodeFile(const char *cacheDir, const char *resName,
251 const char *suffix, const uint8_t *bitcode,
252 size_t bitcodeLen) {
253 std::string f(cacheDir);
254 f.append("/");
255 f.append(resName);
256 f.append("#");
257 f.append(suffix);
258 f.append(".bc");
259
260 if (!ScriptC::createCacheDir(cacheDir)) {
261 return false;
262 }
263
264 FILE *fp = fopen(f.c_str(), "w");
265 if (!fp) {
266 ALOGE("Could not open %s", f.c_str());
267 return false;
268 }
269
270 size_t nWritten = fwrite(bitcode, 1, bitcodeLen, fp);
271 fclose(fp);
272 if (nWritten != bitcodeLen) {
273 ALOGE("Could not write %s", f.c_str());
274 return false;
275 }
276 return true;
277}
278
279#endif // !ANDROID_RS_SERIALIZE
280#endif // !RS_COMPATIBILITY_LIB
281
282
Jason Samsbad80742011-03-16 16:29:28 -0700283bool ScriptC::runCompiler(Context *rsc,
284 const char *resName,
285 const char *cacheDir,
286 const uint8_t *bitcode,
287 size_t bitcodeLen) {
Tim Murrayfa85e912013-05-23 13:19:36 -0700288 ATRACE_CALL();
Steve Blockaf12ac62012-01-06 19:20:56 +0000289 //ALOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen);
Jason Sams93eacc72012-12-18 14:26:57 -0800290#ifndef RS_COMPATIBILITY_LIB
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700291#ifndef ANDROID_RS_SERIALIZE
Stephen Hinesf8d44692011-11-22 19:43:58 -0800292 uint32_t sdkVersion = 0;
293 bcinfo::BitcodeWrapper bcWrapper((const char *)bitcode, bitcodeLen);
294 if (!bcWrapper.unwrap()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000295 ALOGE("Bitcode is not in proper container format (raw or wrapper)");
Stephen Hinesf8d44692011-11-22 19:43:58 -0800296 return false;
297 }
298
Stephen Hinesf8d44692011-11-22 19:43:58 -0800299 if (bcWrapper.getBCFileType() == bcinfo::BC_WRAPPER) {
300 sdkVersion = bcWrapper.getTargetAPI();
301 }
302
303 if (sdkVersion == 0) {
304 // This signals that we didn't have a wrapper containing information
305 // about the bitcode.
306 sdkVersion = rsc->getTargetSdkVersion();
307 }
308
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700309 if (BT) {
310 delete BT;
311 }
312 BT = new bcinfo::BitcodeTranslator((const char *)bitcode, bitcodeLen,
313 sdkVersion);
314 if (!BT->translate()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000315 ALOGE("Failed to translate bitcode from version: %u", sdkVersion);
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700316 delete BT;
Chris Wailes44bef6f2014-08-12 13:51:10 -0700317 BT = nullptr;
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700318 return false;
319 }
320 bitcode = (const uint8_t *) BT->getTranslatedBitcode();
321 bitcodeLen = BT->getTranslatedBitcodeSize();
Shih-wei Liao37150de2011-01-07 18:17:07 -0800322
Stephen Hinesf6af3bd2014-12-23 17:47:43 -0800323 if (kDebugBitcode) {
324 if (!dumpBitcodeFile(cacheDir, resName, "after", bitcode, bitcodeLen)) {
325 return false;
326 }
327 }
328
Tim Murraye195a3f2014-03-13 15:04:58 -0700329#endif
Tim Murray84bf2b82012-10-31 16:03:16 -0700330 if (!cacheDir) {
331 // MUST BE FIXED BEFORE ANYTHING USING C++ API IS RELEASED
332 cacheDir = getenv("EXTERNAL_STORAGE");
333 ALOGV("Cache dir changed to %s", cacheDir);
334 }
335
Tim Murraye78c14b2012-10-01 15:27:18 -0700336 // ensure that cache dir exists
Tim Murray84bf2b82012-10-31 16:03:16 -0700337 if (cacheDir && !createCacheDir(cacheDir)) {
Tim Murraye78c14b2012-10-01 15:27:18 -0700338 return false;
339 }
Jason Sams93eacc72012-12-18 14:26:57 -0800340#endif
Tim Murraye78c14b2012-10-01 15:27:18 -0700341
Jason Sams77020c52011-11-22 12:49:11 -0800342 if (!rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0)) {
343 return false;
344 }
Shih-wei Liao37150de2011-01-07 18:17:07 -0800345
Jason Sams77020c52011-11-22 12:49:11 -0800346 mInitialized = true;
Jason Sams93eacc72012-12-18 14:26:57 -0800347#ifndef RS_COMPATIBILITY_LIB
Jason Samsbad80742011-03-16 16:29:28 -0700348 mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
349 mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
350 mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore());
351 mEnviroment.mRaster.set(rsc->getDefaultProgramRaster());
Jason Sams93eacc72012-12-18 14:26:57 -0800352#endif
Shih-wei Liao37150de2011-01-07 18:17:07 -0800353
Jason Samsbad80742011-03-16 16:29:28 -0700354 rsc->mHal.funcs.script.invokeInit(rsc, this);
Stephen Hines7b337b12011-01-17 17:31:58 -0800355
Jason Samsbad80742011-03-16 16:29:28 -0700356 for (size_t i=0; i < mHal.info.exportedPragmaCount; ++i) {
357 const char * key = mHal.info.exportedPragmaKeyList[i];
358 const char * value = mHal.info.exportedPragmaValueList[i];
Steve Blockaf12ac62012-01-06 19:20:56 +0000359 //ALOGE("pragma %s %s", keys[i], values[i]);
Jason Samsbad80742011-03-16 16:29:28 -0700360 if (!strcmp(key, "version")) {
361 if (!strcmp(value, "1")) {
Stephen Hinesb5dc6af2011-01-18 14:10:44 -0800362 continue;
363 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000364 ALOGE("Invalid version pragma value: %s\n", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800365 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800366 }
367
Jason Sams93eacc72012-12-18 14:26:57 -0800368#ifndef RS_COMPATIBILITY_LIB
Jason Samsbad80742011-03-16 16:29:28 -0700369 if (!strcmp(key, "stateVertex")) {
370 if (!strcmp(value, "default")) {
Jason Sams10308932009-06-09 12:15:30 -0700371 continue;
Jason Sams10308932009-06-09 12:15:30 -0700372 }
Jason Samsbad80742011-03-16 16:29:28 -0700373 if (!strcmp(value, "parent")) {
374 mEnviroment.mVertex.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800375 continue;
Jason Sams10308932009-06-09 12:15:30 -0700376 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000377 ALOGE("Unrecognized value %s passed to stateVertex", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800378 return false;
Jason Sams10308932009-06-09 12:15:30 -0700379 }
Stephen Hines7b337b12011-01-17 17:31:58 -0800380
Jason Samsbad80742011-03-16 16:29:28 -0700381 if (!strcmp(key, "stateRaster")) {
382 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800383 continue;
384 }
Jason Samsbad80742011-03-16 16:29:28 -0700385 if (!strcmp(value, "parent")) {
386 mEnviroment.mRaster.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800387 continue;
388 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000389 ALOGE("Unrecognized value %s passed to stateRaster", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800390 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800391 }
392
Jason Samsbad80742011-03-16 16:29:28 -0700393 if (!strcmp(key, "stateFragment")) {
394 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800395 continue;
396 }
Jason Samsbad80742011-03-16 16:29:28 -0700397 if (!strcmp(value, "parent")) {
398 mEnviroment.mFragment.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800399 continue;
400 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000401 ALOGE("Unrecognized value %s passed to stateFragment", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800402 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800403 }
404
Jason Samsbad80742011-03-16 16:29:28 -0700405 if (!strcmp(key, "stateStore")) {
406 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800407 continue;
408 }
Jason Samsbad80742011-03-16 16:29:28 -0700409 if (!strcmp(value, "parent")) {
410 mEnviroment.mFragmentStore.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800411 continue;
412 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000413 ALOGE("Unrecognized value %s passed to stateStore", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800414 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800415 }
Jason Sams93eacc72012-12-18 14:26:57 -0800416#endif
417
Jason Sams10308932009-06-09 12:15:30 -0700418 }
Jason Sams2e8665d2011-01-27 00:14:13 -0800419
Jason Samsbad80742011-03-16 16:29:28 -0700420 mSlots = new ObjectBaseRef<Allocation>[mHal.info.exportedVariableCount];
421 mTypes = new ObjectBaseRef<const Type>[mHal.info.exportedVariableCount];
Jason Sams2e8665d2011-01-27 00:14:13 -0800422
Jason Sams26b2c9f2011-01-19 16:14:21 -0800423 return true;
Jason Sams326e0dd2009-05-22 14:03:28 -0700424}
425
426namespace android {
427namespace renderscript {
428
Shih-wei Liaoce8a0792010-12-20 20:45:56 +0800429RsScript rsi_ScriptCCreate(Context *rsc,
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700430 const char *resName, size_t resName_length,
431 const char *cacheDir, size_t cacheDir_length,
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700432 const char *text, size_t text_length)
Shih-wei Liao9503b662010-11-08 01:33:59 -0800433{
Jason Sams249d4532011-01-23 17:48:45 -0800434 ScriptC *s = new ScriptC(rsc);
Jason Sams1f526332009-06-05 17:35:09 -0700435
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700436 if (!s->runCompiler(rsc, resName, cacheDir, (uint8_t *)text, text_length)) {
Jason Sams26b2c9f2011-01-19 16:14:21 -0800437 // Error during compile, destroy s and return null.
Stephen Hines4769d682012-02-02 13:23:20 -0800438 ObjectBase::checkDelete(s);
Chris Wailes44bef6f2014-08-12 13:51:10 -0700439 return nullptr;
Jason Sams26b2c9f2011-01-19 16:14:21 -0800440 }
Jason Samsbad80742011-03-16 16:29:28 -0700441
442 s->incUserRef();
Jason Sams249d4532011-01-23 17:48:45 -0800443 return s;
Jason Sams326e0dd2009-05-22 14:03:28 -0700444}
445
Jason Sams326e0dd2009-05-22 14:03:28 -0700446}
447}