blob: f6430934d8a8db012e1550ace76a42be0270d18b [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
Yang Nib8353c52015-02-14 18:00:59 -080032#include <string>
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) {
Jason Sams326e0dd2009-05-22 14:03:28 -070056}
57
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080058ScriptC::~ScriptC() {
Jason Sams77020c52011-11-22 12:49:11 -080059 if (mInitialized) {
60 mRSC->mHal.funcs.script.invokeFreeChildren(mRSC, this);
61 mRSC->mHal.funcs.script.destroy(mRSC, this);
62 }
Jason Sams326e0dd2009-05-22 14:03:28 -070063}
64
Jason Sams93eacc72012-12-18 14:26:57 -080065#ifndef RS_COMPATIBILITY_LIB
Tim Murraye78c14b2012-10-01 15:27:18 -070066bool ScriptC::createCacheDir(const char *cacheDir) {
Chris Wailes6847e732014-08-11 17:30:51 -070067 std::string currentDir;
68 const std::string cacheDirString(cacheDir);
69
Tim Murraye78c14b2012-10-01 15:27:18 -070070 struct stat statBuf;
71 int statReturn = stat(cacheDir, &statBuf);
72 if (!statReturn) {
73 return true;
74 }
75
Chris Wailes6847e732014-08-11 17:30:51 -070076 // Start from the beginning of the cacheDirString.
77 int currPos = 0;
Tim Murraye78c14b2012-10-01 15:27:18 -070078
Chris Wailes6847e732014-08-11 17:30:51 -070079 // Reserve space in currentDir for the entire cacheDir path.
80 currentDir.reserve(cacheDirString.length());
Tim Murraye78c14b2012-10-01 15:27:18 -070081
Chris Wailes6847e732014-08-11 17:30:51 -070082 while (currPos >= 0) {
83 /*
84 * The character at currPos should be a path separator. We need to look
85 * for the next one.
86 */
87 int nextPos = cacheDirString.find(OS_PATH_SEPARATOR_STR, currPos + 1);
88
89 if (nextPos > 0) {
90 // A new path separator has been found.
91 currentDir += cacheDirString.substr(currPos, nextPos - currPos);
92 } else {
93 // There are no more path separators.
94 currentDir += cacheDirString.substr(currPos);
95 }
96
97 currPos = nextPos;
98
99 statReturn = stat(currentDir.c_str(), &statBuf);
100
Tim Murraye78c14b2012-10-01 15:27:18 -0700101 if (statReturn) {
102 if (errno == ENOENT) {
Chris Wailes6847e732014-08-11 17:30:51 -0700103 if (mkdir(currentDir.c_str(), S_IRUSR | S_IWUSR | S_IXUSR)) {
Tim Murraye78c14b2012-10-01 15:27:18 -0700104 ALOGE("Couldn't create cache directory: %s",
Chris Wailes6847e732014-08-11 17:30:51 -0700105 currentDir.c_str());
Tim Murraye78c14b2012-10-01 15:27:18 -0700106 ALOGE("Error: %s", strerror(errno));
107 return false;
108 }
109 } else {
110 ALOGE("Stat error: %s", strerror(errno));
111 return false;
112 }
113 }
Tim Murraye78c14b2012-10-01 15:27:18 -0700114 }
115 return true;
116}
Jason Sams93eacc72012-12-18 14:26:57 -0800117#endif
Tim Murraye78c14b2012-10-01 15:27:18 -0700118
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800119void ScriptC::setupScript(Context *rsc) {
Tim Murray0b575de2013-03-15 15:56:43 -0700120#ifndef RS_SERVER
Jason Samsc61346b2010-05-28 18:23:22 -0700121 mEnviroment.mStartTimeMillis
122 = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC));
Tim Murray0b575de2013-03-15 15:56:43 -0700123#endif
Jason Samsc61346b2010-05-28 18:23:22 -0700124
Jason Samsbad80742011-03-16 16:29:28 -0700125 for (uint32_t ct=0; ct < mHal.info.exportedVariableCount; ct++) {
Jason Sams900f1612010-09-16 18:18:29 -0700126 if (mSlots[ct].get() && !mTypes[ct].get()) {
127 mTypes[ct].set(mSlots[ct]->getType());
128 }
129
130 if (!mTypes[ct].get())
Jason Samsbe36bf32010-05-11 14:03:58 -0700131 continue;
Jason Sams807fdc42012-07-25 17:55:39 -0700132 rsc->mHal.funcs.script.setGlobalBind(rsc, this, ct, mSlots[ct].get());
Jason Samsada7f272009-09-24 14:55:38 -0700133 }
134}
135
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800136void ScriptC::setupGLState(Context *rsc) {
Jason Sams93eacc72012-12-18 14:26:57 -0800137#ifndef RS_COMPATIBILITY_LIB
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700138 if (mEnviroment.mFragmentStore.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800139 rsc->setProgramStore(mEnviroment.mFragmentStore.get());
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700140 }
141 if (mEnviroment.mFragment.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800142 rsc->setProgramFragment(mEnviroment.mFragment.get());
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700143 }
Jason Sams8ce125b2009-06-17 16:52:59 -0700144 if (mEnviroment.mVertex.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800145 rsc->setProgramVertex(mEnviroment.mVertex.get());
Jason Sams8ce125b2009-06-17 16:52:59 -0700146 }
Jason Samsb681c8a2009-09-28 18:12:56 -0700147 if (mEnviroment.mRaster.get()) {
Jason Sams60709252010-11-17 15:29:32 -0800148 rsc->setProgramRaster(mEnviroment.mRaster.get());
Jason Samsb681c8a2009-09-28 18:12:56 -0700149 }
Jason Sams93eacc72012-12-18 14:26:57 -0800150#endif
Jason Samsc61346b2010-05-28 18:23:22 -0700151}
Jason Samsa0a1b6f2009-06-10 15:04:38 -0700152
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800153uint32_t ScriptC::run(Context *rsc) {
Chris Wailes44bef6f2014-08-12 13:51:10 -0700154 if (mHal.info.root == nullptr) {
Jason Samsc61346b2010-05-28 18:23:22 -0700155 rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script");
156 return 0;
Joe Onorato9c4e4ca2009-08-09 11:39:02 -0700157 }
Jason Samsc61346b2010-05-28 18:23:22 -0700158
Jason Sams1f24db42010-12-11 17:42:30 -0800159 setupGLState(rsc);
Jason Samsc61346b2010-05-28 18:23:22 -0700160 setupScript(rsc);
Jason Sams1d54f102009-09-03 15:43:13 -0700161
Jason Sams2dca84d2009-12-09 11:05:45 -0800162 uint32_t ret = 0;
Jason Samsb9077f42010-09-22 15:57:41 -0700163
164 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100165 ALOGV("%p ScriptC::run invoking root, ptr %p", rsc, mHal.info.root);
Jason Samsb9077f42010-09-22 15:57:41 -0700166 }
167
Jason Samscdfdb8f2011-03-17 16:12:47 -0700168 ret = rsc->mHal.funcs.script.invokeRoot(rsc, this);
Jason Samsb9077f42010-09-22 15:57:41 -0700169
170 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100171 ALOGV("%p ScriptC::run invoking complete, ret=%i", rsc, ret);
Jason Samsb9077f42010-09-22 15:57:41 -0700172 }
173
Jason Samse45ac6e2009-07-20 14:31:06 -0700174 return ret;
Jason Sams326e0dd2009-05-22 14:03:28 -0700175}
176
Jason Sams177f8442010-10-29 10:19:21 -0700177
Jason Samsace3e012010-07-15 17:11:13 -0700178void ScriptC::runForEach(Context *rsc,
Stephen Hines44199772012-02-21 20:13:12 -0800179 uint32_t slot,
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700180 const Allocation ** ains,
181 size_t inLen,
182 Allocation * aout,
183 const void * usr,
184 size_t usrBytes,
185 const RsScriptCall *sc) {
Pirama Arumuga Nainar9479e5b2015-04-28 14:40:45 -0700186 // Make a copy of RsScriptCall and zero out extra fields that are absent
187 // in API levels below 23.
188 RsScriptCall sc_copy;
189 if (sc != nullptr && getApiLevel() < 23) {
190 memset(&sc_copy, 0, sizeof(sc_copy));
191 memcpy(&sc_copy, sc, 7*4);
192 sc = &sc_copy;
193 }
194
Matt Wala14ce0072015-07-30 17:30:25 -0700195 if (slot >= mHal.info.exportedForEachCount) {
196 rsc->setError(RS_ERROR_BAD_SCRIPT,
197 "The forEach kernel index is out of bounds");
198 return;
199 }
200
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700201 // Trace this function call.
202 // To avoid overhead we only build the string if tracing is actually
203 // enabled.
Yang Nib8353c52015-02-14 18:00:59 -0800204 String8 *AString = NULL;
205 const char *String = "";
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700206 if (ATRACE_ENABLED()) {
Yang Nib8353c52015-02-14 18:00:59 -0800207 AString = new String8("runForEach_");
208 AString->append(mHal.info.exportedForeachFuncList[slot].first);
209 String = AString->string();
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700210 }
Yang Nib8353c52015-02-14 18:00:59 -0800211 ATRACE_NAME(String);
212 (void)String;
Jason Sams4efe3d32015-03-18 18:28:06 -0700213 if (mRSC->hadFatalError()) return;
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700214
215 Context::PushState ps(rsc);
216
217 setupGLState(rsc);
218 setupScript(rsc);
219
Matt Wala14ce0072015-07-30 17:30:25 -0700220 if (rsc->props.mLogScripts) {
221 ALOGV("%p ScriptC::runForEach invoking slot %i, ptr %p", rsc, slot, this);
222 }
223
Chris Wailes44bef6f2014-08-12 13:51:10 -0700224 if (rsc->mHal.funcs.script.invokeForEachMulti != nullptr) {
Chris Wailesf3712132014-07-16 15:18:30 -0700225 rsc->mHal.funcs.script.invokeForEachMulti(rsc, this, slot, ains, inLen,
226 aout, usr, usrBytes, sc);
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700227
Chris Wailesf3712132014-07-16 15:18:30 -0700228 } else if (inLen == 1) {
229 rsc->mHal.funcs.script.invokeForEach(rsc, this, slot, ains[0], aout,
230 usr, usrBytes, sc);
231
232 } else {
233 rsc->setError(RS_ERROR_FATAL_DRIVER,
234 "Driver support for multi-input not present");
235 }
236
Yang Nib8353c52015-02-14 18:00:59 -0800237 if (AString) {
238 delete AString;
Chris Wailesf3712132014-07-16 15:18:30 -0700239 }
Chris Wailes4b3c34e2014-06-11 12:00:29 -0700240}
241
Matt Wala14ce0072015-07-30 17:30:25 -0700242void ScriptC::runReduce(Context *rsc, uint32_t slot, const Allocation *ain,
243 Allocation *aout, const RsScriptCall *sc) {
244 // TODO: Record the name of the kernel in the tracing information.
245 ATRACE_CALL();
246
247 if (slot >= mHal.info.exportedReduceCount) {
David Gross6c1876b2016-01-15 11:52:14 -0800248 rsc->setError(RS_ERROR_BAD_SCRIPT, "The simple reduce kernel index is out of bounds");
Matt Wala14ce0072015-07-30 17:30:25 -0700249 return;
250 }
251 if (mRSC->hadFatalError()) return;
252
253 setupScript(rsc);
254
255 if (rsc->props.mLogScripts) {
256 ALOGV("%p ScriptC::runReduce invoking slot %i, ptr %p", rsc, slot, this);
257 }
258
259 rsc->mHal.funcs.script.invokeReduce(rsc, this, slot, ain, aout, sc);
260}
261
David Gross6c1876b2016-01-15 11:52:14 -0800262void ScriptC::runReduceNew(Context *rsc, uint32_t slot,
263 const Allocation ** ains, size_t inLen,
264 Allocation *aout, const RsScriptCall *sc) {
265 // TODO: Record the name of the kernel in the tracing information.
266 ATRACE_CALL();
267
268 if (slot >= mHal.info.exportedReduceNewCount) {
269 rsc->setError(RS_ERROR_BAD_SCRIPT, "The general reduce kernel index is out of bounds");
270 return;
271 }
272 if (mRSC->hadFatalError()) return;
273
274 setupScript(rsc);
275
276 if (rsc->props.mLogScripts) {
277 ALOGV("%p ScriptC::runReduceNew invoking slot %i, ptr %p", rsc, slot, this);
278 }
279
280 rsc->mHal.funcs.script.invokeReduceNew(rsc, this, slot, ains, inLen, aout, sc);
281}
282
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700283void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) {
Tim Murrayfa85e912013-05-23 13:19:36 -0700284 ATRACE_CALL();
285
Jason Samsbad80742011-03-16 16:29:28 -0700286 if (slot >= mHal.info.exportedFunctionCount) {
Matt Wala14ce0072015-07-30 17:30:25 -0700287 rsc->setError(RS_ERROR_BAD_SCRIPT, "The invokable index is out of bounds");
Jason Sams22fa3712010-05-19 17:22:57 -0700288 return;
289 }
Jason Sams4efe3d32015-03-18 18:28:06 -0700290 if (mRSC->hadFatalError()) return;
291
Jason Samsc61346b2010-05-28 18:23:22 -0700292 setupScript(rsc);
Jason Sams22fa3712010-05-19 17:22:57 -0700293
Jason Samsb9077f42010-09-22 15:57:41 -0700294 if (rsc->props.mLogScripts) {
Steve Block65982012011-10-20 11:56:00 +0100295 ALOGV("%p ScriptC::Invoke invoking slot %i, ptr %p", rsc, slot, this);
Jason Samsb9077f42010-09-22 15:57:41 -0700296 }
Jason Samsbad80742011-03-16 16:29:28 -0700297 rsc->mHal.funcs.script.invokeFunction(rsc, this, slot, data, len);
Jason Sams22fa3712010-05-19 17:22:57 -0700298}
299
Stephen Hinesf6af3bd2014-12-23 17:47:43 -0800300static const bool kDebugBitcode = false;
301
302#ifndef RS_COMPATIBILITY_LIB
303#ifndef ANDROID_RS_SERIALIZE
304
305static bool dumpBitcodeFile(const char *cacheDir, const char *resName,
306 const char *suffix, const uint8_t *bitcode,
307 size_t bitcodeLen) {
308 std::string f(cacheDir);
309 f.append("/");
310 f.append(resName);
311 f.append("#");
312 f.append(suffix);
313 f.append(".bc");
314
315 if (!ScriptC::createCacheDir(cacheDir)) {
316 return false;
317 }
318
319 FILE *fp = fopen(f.c_str(), "w");
320 if (!fp) {
321 ALOGE("Could not open %s", f.c_str());
322 return false;
323 }
324
325 size_t nWritten = fwrite(bitcode, 1, bitcodeLen, fp);
326 fclose(fp);
327 if (nWritten != bitcodeLen) {
328 ALOGE("Could not write %s", f.c_str());
329 return false;
330 }
331 return true;
332}
333
334#endif // !ANDROID_RS_SERIALIZE
335#endif // !RS_COMPATIBILITY_LIB
336
337
Jason Samsbad80742011-03-16 16:29:28 -0700338bool ScriptC::runCompiler(Context *rsc,
339 const char *resName,
340 const char *cacheDir,
341 const uint8_t *bitcode,
342 size_t bitcodeLen) {
Tim Murrayfa85e912013-05-23 13:19:36 -0700343 ATRACE_CALL();
Steve Blockaf12ac62012-01-06 19:20:56 +0000344 //ALOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen);
Jason Sams93eacc72012-12-18 14:26:57 -0800345#ifndef RS_COMPATIBILITY_LIB
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700346#ifndef ANDROID_RS_SERIALIZE
Stephen Hinesf8d44692011-11-22 19:43:58 -0800347 uint32_t sdkVersion = 0;
348 bcinfo::BitcodeWrapper bcWrapper((const char *)bitcode, bitcodeLen);
349 if (!bcWrapper.unwrap()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000350 ALOGE("Bitcode is not in proper container format (raw or wrapper)");
Stephen Hinesf8d44692011-11-22 19:43:58 -0800351 return false;
352 }
353
Stephen Hinesf8d44692011-11-22 19:43:58 -0800354 if (bcWrapper.getBCFileType() == bcinfo::BC_WRAPPER) {
355 sdkVersion = bcWrapper.getTargetAPI();
356 }
357
358 if (sdkVersion == 0) {
359 // This signals that we didn't have a wrapper containing information
360 // about the bitcode.
361 sdkVersion = rsc->getTargetSdkVersion();
362 }
363
Stephen Hines5d95a782015-04-13 20:11:48 -0700364 // Save off the sdkVersion, so that we can handle broken cases later.
365 // Bug 19734267
366 mApiLevel = sdkVersion;
367
Stephen Hines98f401d2015-12-03 00:44:46 -0800368 bcinfo::BitcodeTranslator BT((const char *)bitcode, bitcodeLen,
369 sdkVersion);
370 if (!BT.translate()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000371 ALOGE("Failed to translate bitcode from version: %u", sdkVersion);
Stephen Hinescbb0b8a2011-08-01 15:02:34 -0700372 return false;
373 }
Stephen Hines98f401d2015-12-03 00:44:46 -0800374 bitcode = (const uint8_t *) BT.getTranslatedBitcode();
375 bitcodeLen = BT.getTranslatedBitcodeSize();
Shih-wei Liao37150de2011-01-07 18:17:07 -0800376
Stephen Hinesf6af3bd2014-12-23 17:47:43 -0800377 if (kDebugBitcode) {
378 if (!dumpBitcodeFile(cacheDir, resName, "after", bitcode, bitcodeLen)) {
379 return false;
380 }
381 }
382
Tim Murraye195a3f2014-03-13 15:04:58 -0700383#endif
Tim Murray84bf2b82012-10-31 16:03:16 -0700384 if (!cacheDir) {
385 // MUST BE FIXED BEFORE ANYTHING USING C++ API IS RELEASED
386 cacheDir = getenv("EXTERNAL_STORAGE");
387 ALOGV("Cache dir changed to %s", cacheDir);
388 }
389
Tim Murraye78c14b2012-10-01 15:27:18 -0700390 // ensure that cache dir exists
Tim Murray84bf2b82012-10-31 16:03:16 -0700391 if (cacheDir && !createCacheDir(cacheDir)) {
Tim Murraye78c14b2012-10-01 15:27:18 -0700392 return false;
393 }
Jason Sams93eacc72012-12-18 14:26:57 -0800394#endif
Tim Murraye78c14b2012-10-01 15:27:18 -0700395
Jason Sams77020c52011-11-22 12:49:11 -0800396 if (!rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0)) {
397 return false;
398 }
Shih-wei Liao37150de2011-01-07 18:17:07 -0800399
Jason Sams77020c52011-11-22 12:49:11 -0800400 mInitialized = true;
Jason Sams93eacc72012-12-18 14:26:57 -0800401#ifndef RS_COMPATIBILITY_LIB
Jason Samsbad80742011-03-16 16:29:28 -0700402 mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
403 mEnviroment.mVertex.set(rsc->getDefaultProgramVertex());
404 mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore());
405 mEnviroment.mRaster.set(rsc->getDefaultProgramRaster());
Jason Sams93eacc72012-12-18 14:26:57 -0800406#endif
Shih-wei Liao37150de2011-01-07 18:17:07 -0800407
Jason Samsbad80742011-03-16 16:29:28 -0700408 rsc->mHal.funcs.script.invokeInit(rsc, this);
Stephen Hines7b337b12011-01-17 17:31:58 -0800409
Jason Samsbad80742011-03-16 16:29:28 -0700410 for (size_t i=0; i < mHal.info.exportedPragmaCount; ++i) {
411 const char * key = mHal.info.exportedPragmaKeyList[i];
412 const char * value = mHal.info.exportedPragmaValueList[i];
Steve Blockaf12ac62012-01-06 19:20:56 +0000413 //ALOGE("pragma %s %s", keys[i], values[i]);
Jason Samsbad80742011-03-16 16:29:28 -0700414 if (!strcmp(key, "version")) {
415 if (!strcmp(value, "1")) {
Stephen Hinesb5dc6af2011-01-18 14:10:44 -0800416 continue;
417 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000418 ALOGE("Invalid version pragma value: %s\n", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800419 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800420 }
421
Jason Sams93eacc72012-12-18 14:26:57 -0800422#ifndef RS_COMPATIBILITY_LIB
Jason Samsbad80742011-03-16 16:29:28 -0700423 if (!strcmp(key, "stateVertex")) {
424 if (!strcmp(value, "default")) {
Jason Sams10308932009-06-09 12:15:30 -0700425 continue;
Jason Sams10308932009-06-09 12:15:30 -0700426 }
Jason Samsbad80742011-03-16 16:29:28 -0700427 if (!strcmp(value, "parent")) {
428 mEnviroment.mVertex.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800429 continue;
Jason Sams10308932009-06-09 12:15:30 -0700430 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000431 ALOGE("Unrecognized value %s passed to stateVertex", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800432 return false;
Jason Sams10308932009-06-09 12:15:30 -0700433 }
Stephen Hines7b337b12011-01-17 17:31:58 -0800434
Jason Samsbad80742011-03-16 16:29:28 -0700435 if (!strcmp(key, "stateRaster")) {
436 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800437 continue;
438 }
Jason Samsbad80742011-03-16 16:29:28 -0700439 if (!strcmp(value, "parent")) {
440 mEnviroment.mRaster.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800441 continue;
442 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000443 ALOGE("Unrecognized value %s passed to stateRaster", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800444 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800445 }
446
Jason Samsbad80742011-03-16 16:29:28 -0700447 if (!strcmp(key, "stateFragment")) {
448 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800449 continue;
450 }
Jason Samsbad80742011-03-16 16:29:28 -0700451 if (!strcmp(value, "parent")) {
452 mEnviroment.mFragment.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800453 continue;
454 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000455 ALOGE("Unrecognized value %s passed to stateFragment", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800456 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800457 }
458
Jason Samsbad80742011-03-16 16:29:28 -0700459 if (!strcmp(key, "stateStore")) {
460 if (!strcmp(value, "default")) {
Stephen Hines7b337b12011-01-17 17:31:58 -0800461 continue;
462 }
Jason Samsbad80742011-03-16 16:29:28 -0700463 if (!strcmp(value, "parent")) {
464 mEnviroment.mFragmentStore.clear();
Stephen Hines7b337b12011-01-17 17:31:58 -0800465 continue;
466 }
Steve Blockaf12ac62012-01-06 19:20:56 +0000467 ALOGE("Unrecognized value %s passed to stateStore", value);
Jason Sams26b2c9f2011-01-19 16:14:21 -0800468 return false;
Stephen Hines7b337b12011-01-17 17:31:58 -0800469 }
Jason Sams93eacc72012-12-18 14:26:57 -0800470#endif
471
Jason Sams10308932009-06-09 12:15:30 -0700472 }
Jason Sams2e8665d2011-01-27 00:14:13 -0800473
Jason Samsbad80742011-03-16 16:29:28 -0700474 mSlots = new ObjectBaseRef<Allocation>[mHal.info.exportedVariableCount];
475 mTypes = new ObjectBaseRef<const Type>[mHal.info.exportedVariableCount];
Jason Sams2e8665d2011-01-27 00:14:13 -0800476
Jason Sams26b2c9f2011-01-19 16:14:21 -0800477 return true;
Jason Sams326e0dd2009-05-22 14:03:28 -0700478}
479
480namespace android {
481namespace renderscript {
482
Shih-wei Liaoce8a0792010-12-20 20:45:56 +0800483RsScript rsi_ScriptCCreate(Context *rsc,
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700484 const char *resName, size_t resName_length,
485 const char *cacheDir, size_t cacheDir_length,
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700486 const char *text, size_t text_length)
Shih-wei Liao9503b662010-11-08 01:33:59 -0800487{
Jason Sams249d4532011-01-23 17:48:45 -0800488 ScriptC *s = new ScriptC(rsc);
Jason Sams1f526332009-06-05 17:35:09 -0700489
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700490 if (!s->runCompiler(rsc, resName, cacheDir, (uint8_t *)text, text_length)) {
Jason Sams26b2c9f2011-01-19 16:14:21 -0800491 // Error during compile, destroy s and return null.
Stephen Hines4769d682012-02-02 13:23:20 -0800492 ObjectBase::checkDelete(s);
Chris Wailes44bef6f2014-08-12 13:51:10 -0700493 return nullptr;
Jason Sams26b2c9f2011-01-19 16:14:21 -0800494 }
Jason Samsbad80742011-03-16 16:29:28 -0700495
496 s->incUserRef();
Jason Sams249d4532011-01-23 17:48:45 -0800497 return s;
Jason Sams326e0dd2009-05-22 14:03:28 -0700498}
499
Jason Sams326e0dd2009-05-22 14:03:28 -0700500}
501}