Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2009 The Android Open Source Project |
| 3 | * |
| 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" |
| 19 | #include "rsMatrix.h" |
Joe Onorato | 9c4e4ca | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 20 | #include "utils/Timers.h" |
Alex Sakhartchouk | b26fb04 | 2010-09-24 15:18:12 -0700 | [diff] [blame] | 21 | #include "utils/StopWatch.h" |
Shih-wei Liao | ce8a079 | 2010-12-20 20:45:56 +0800 | [diff] [blame] | 22 | extern "C" { |
| 23 | #include "libdex/ZipArchive.h" |
| 24 | } |
Jack Palevich | 1ef8b80 | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 25 | |
Jason Sams | 1aa5a4e | 2009-06-22 17:15:15 -0700 | [diff] [blame] | 26 | #include <GLES/gl.h> |
| 27 | #include <GLES/glext.h> |
| 28 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 29 | using namespace android; |
| 30 | using namespace android::renderscript; |
| 31 | |
Jason Sams | e576910 | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 32 | #define GET_TLS() Context::ScriptTLSStruct * tls = \ |
| 33 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ |
| 34 | Context * rsc = tls->mContext; \ |
| 35 | ScriptC * sc = (ScriptC *) tls->mScript |
| 36 | |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 37 | // Input: cacheDir |
| 38 | // Input: resName |
| 39 | // Input: extName |
| 40 | // |
| 41 | // Note: cacheFile = resName + extName |
| 42 | // |
| 43 | // Output: Returns cachePath == cacheDir + cacheFile |
| 44 | char *genCacheFileName(const char *cacheDir, |
| 45 | const char *resName, |
| 46 | const char *extName) { |
| 47 | char cachePath[512]; |
| 48 | char cacheFile[sizeof(cachePath)]; |
| 49 | const size_t kBufLen = sizeof(cachePath) - 1; |
| 50 | |
| 51 | cacheFile[0] = '\0'; |
| 52 | // Note: resName today is usually something like |
| 53 | // "/com.android.fountain:raw/fountain" |
| 54 | if (resName[0] != '/') { |
| 55 | // Get the absolute path of the raw/***.bc file. |
| 56 | |
| 57 | // Generate the absolute path. This doesn't do everything it |
| 58 | // should, e.g. if resName is "./out/whatever" it doesn't crunch |
| 59 | // the leading "./" out because this if-block is not triggered, |
| 60 | // but it'll make do. |
| 61 | // |
| 62 | if (getcwd(cacheFile, kBufLen) == NULL) { |
| 63 | LOGE("Can't get CWD while opening raw/***.bc file\n"); |
| 64 | return NULL; |
| 65 | } |
| 66 | // Append "/" at the end of cacheFile so far. |
| 67 | strncat(cacheFile, "/", kBufLen); |
| 68 | } |
| 69 | |
| 70 | // cacheFile = resName + extName |
| 71 | // |
| 72 | strncat(cacheFile, resName, kBufLen); |
| 73 | if (extName != NULL) { |
| 74 | // TODO(srhines): strncat() is a bit dangerous |
| 75 | strncat(cacheFile, extName, kBufLen); |
| 76 | } |
| 77 | |
| 78 | // Turn the path into a flat filename by replacing |
| 79 | // any slashes after the first one with '@' characters. |
| 80 | char *cp = cacheFile + 1; |
| 81 | while (*cp != '\0') { |
| 82 | if (*cp == '/') { |
| 83 | *cp = '@'; |
| 84 | } |
| 85 | cp++; |
| 86 | } |
| 87 | |
| 88 | // Tack on the file name for the actual cache file path. |
| 89 | strncpy(cachePath, cacheDir, kBufLen); |
| 90 | strncat(cachePath, cacheFile, kBufLen); |
| 91 | |
| 92 | LOGV("Cache file for '%s' '%s' is '%s'\n", resName, extName, cachePath); |
| 93 | return strdup(cachePath); |
| 94 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 95 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 96 | ScriptC::ScriptC(Context *rsc) : Script(rsc) { |
Jason Sams | 741aac9 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 97 | LOGD(">>>> ScriptC ctor called, obj=%p", this); |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 98 | mBccScript = NULL; |
Jason Sams | efb8de1 | 2009-06-08 15:20:31 -0700 | [diff] [blame] | 99 | memset(&mProgram, 0, sizeof(mProgram)); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 102 | ScriptC::~ScriptC() { |
Jason Sams | 741aac9 | 2010-12-24 14:38:39 -0800 | [diff] [blame] | 103 | LOGD(">>>> ~ScriptC() mBccScript = %p", mBccScript); |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 104 | if (mBccScript) { |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 105 | bccDisposeScript(mBccScript); |
Shih-wei Liao | a6ebec8 | 2010-12-23 23:04:21 +0800 | [diff] [blame] | 106 | LOGD(">>>> ~ScriptC(mBCCScript)"); |
Jack Palevich | 1ef8b80 | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 107 | } |
Jason Sams | e402ed3 | 2009-11-03 11:25:42 -0800 | [diff] [blame] | 108 | free(mEnviroment.mScriptText); |
| 109 | mEnviroment.mScriptText = NULL; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 110 | } |
| 111 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 112 | void ScriptC::setupScript(Context *rsc) { |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 113 | mEnviroment.mStartTimeMillis |
| 114 | = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); |
| 115 | |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 116 | for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) { |
Jason Sams | 900f161 | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 117 | if (mSlots[ct].get() && !mTypes[ct].get()) { |
| 118 | mTypes[ct].set(mSlots[ct]->getType()); |
| 119 | } |
| 120 | |
| 121 | if (!mTypes[ct].get()) |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 122 | continue; |
Jason Sams | 900f161 | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 123 | void *ptr = NULL; |
| 124 | if (mSlots[ct].get()) { |
| 125 | ptr = mSlots[ct]->getPtr(); |
| 126 | } |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 127 | void **dest = ((void ***)mEnviroment.mFieldAddress)[ct]; |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 128 | |
Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 129 | if (rsc->props.mLogScripts) { |
Jason Sams | 2fad7e4 | 2010-11-16 12:19:26 -0800 | [diff] [blame] | 130 | if (mSlots[ct].get() != NULL) { |
| 131 | LOGV("%p ScriptC::setupScript slot=%i dst=%p src=%p type=%p", rsc, ct, dest, ptr, mSlots[ct]->getType()); |
| 132 | } else { |
| 133 | LOGV("%p ScriptC::setupScript slot=%i dst=%p src=%p type=null", rsc, ct, dest, ptr); |
| 134 | } |
Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 135 | } |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 136 | |
| 137 | if (dest) { |
| 138 | *dest = ptr; |
Jason Sams | ada7f27 | 2009-09-24 14:55:38 -0700 | [diff] [blame] | 139 | } |
| 140 | } |
| 141 | } |
| 142 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 143 | const Allocation *ScriptC::ptrToAllocation(const void *ptr) const { |
Jason Sams | ce92d4b | 2010-05-17 14:55:34 -0700 | [diff] [blame] | 144 | if (!ptr) { |
| 145 | return NULL; |
| 146 | } |
| 147 | for (uint32_t ct=0; ct < mEnviroment.mFieldCount; ct++) { |
| 148 | if (!mSlots[ct].get()) |
| 149 | continue; |
| 150 | if (mSlots[ct]->getPtr() == ptr) { |
| 151 | return mSlots[ct].get(); |
| 152 | } |
| 153 | } |
| 154 | LOGE("ScriptC::ptrToAllocation, failed to find %p", ptr); |
| 155 | return NULL; |
| 156 | } |
| 157 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 158 | Script * ScriptC::setTLS(Script *sc) { |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 159 | Context::ScriptTLSStruct * tls = (Context::ScriptTLSStruct *) |
| 160 | pthread_getspecific(Context::gThreadTLSKey); |
| 161 | rsAssert(tls); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 162 | Script *old = tls->mScript; |
| 163 | tls->mScript = sc; |
| 164 | return old; |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 167 | void ScriptC::setupGLState(Context *rsc) { |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 168 | if (mEnviroment.mFragmentStore.get()) { |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 169 | rsc->setProgramStore(mEnviroment.mFragmentStore.get()); |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 170 | } |
| 171 | if (mEnviroment.mFragment.get()) { |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 172 | rsc->setProgramFragment(mEnviroment.mFragment.get()); |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 173 | } |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 174 | if (mEnviroment.mVertex.get()) { |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 175 | rsc->setProgramVertex(mEnviroment.mVertex.get()); |
Jason Sams | 8ce125b | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 176 | } |
Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 177 | if (mEnviroment.mRaster.get()) { |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 178 | rsc->setProgramRaster(mEnviroment.mRaster.get()); |
Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 179 | } |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 180 | } |
Jason Sams | a0a1b6f | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 181 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 182 | uint32_t ScriptC::run(Context *rsc) { |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 183 | if (mProgram.mRoot == NULL) { |
| 184 | rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script"); |
| 185 | return 0; |
Joe Onorato | 9c4e4ca | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 186 | } |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 187 | |
Jason Sams | 1f24db4 | 2010-12-11 17:42:30 -0800 | [diff] [blame] | 188 | setupGLState(rsc); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 189 | setupScript(rsc); |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 190 | |
Jason Sams | 2dca84d | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 191 | uint32_t ret = 0; |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 192 | Script * oldTLS = setTLS(this); |
Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 193 | |
| 194 | if (rsc->props.mLogScripts) { |
| 195 | LOGV("%p ScriptC::run invoking root, ptr %p", rsc, mProgram.mRoot); |
| 196 | } |
| 197 | |
Jason Sams | be36bf3 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 198 | ret = mProgram.mRoot(); |
Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 199 | |
| 200 | if (rsc->props.mLogScripts) { |
| 201 | LOGV("%p ScriptC::run invoking complete, ret=%i", rsc, ret); |
| 202 | } |
| 203 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 204 | setTLS(oldTLS); |
Jason Sams | e45ac6e | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 205 | return ret; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 206 | } |
| 207 | |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 208 | typedef struct { |
| 209 | Context *rsc; |
| 210 | ScriptC *script; |
| 211 | const Allocation * ain; |
| 212 | Allocation * aout; |
| 213 | const void * usr; |
| 214 | |
| 215 | uint32_t mSliceSize; |
| 216 | volatile int mSliceNum; |
| 217 | |
| 218 | const uint8_t *ptrIn; |
| 219 | uint32_t eStrideIn; |
| 220 | uint8_t *ptrOut; |
| 221 | uint32_t eStrideOut; |
| 222 | |
| 223 | uint32_t xStart; |
| 224 | uint32_t xEnd; |
| 225 | uint32_t yStart; |
| 226 | uint32_t yEnd; |
| 227 | uint32_t zStart; |
| 228 | uint32_t zEnd; |
| 229 | uint32_t arrayStart; |
| 230 | uint32_t arrayEnd; |
| 231 | |
| 232 | uint32_t dimX; |
| 233 | uint32_t dimY; |
| 234 | uint32_t dimZ; |
| 235 | uint32_t dimArray; |
| 236 | } MTLaunchStruct; |
| 237 | typedef int (*rs_t)(const void *, void *, const void *, uint32_t, uint32_t, uint32_t, uint32_t); |
| 238 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 239 | static void wc_xy(void *usr, uint32_t idx) { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 240 | MTLaunchStruct *mtls = (MTLaunchStruct *)usr; |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 241 | |
| 242 | while (1) { |
| 243 | uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum); |
| 244 | uint32_t yStart = mtls->yStart + slice * mtls->mSliceSize; |
| 245 | uint32_t yEnd = yStart + mtls->mSliceSize; |
| 246 | yEnd = rsMin(yEnd, mtls->yEnd); |
| 247 | if (yEnd <= yStart) { |
| 248 | return; |
| 249 | } |
| 250 | |
| 251 | //LOGE("usr idx %i, x %i,%i y %i,%i", idx, mtls->xStart, mtls->xEnd, yStart, yEnd); |
Jason Sams | 8d957fa | 2010-09-28 14:41:22 -0700 | [diff] [blame] | 252 | //LOGE("usr ptr in %p, out %p", mtls->ptrIn, mtls->ptrOut); |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 253 | for (uint32_t y = yStart; y < yEnd; y++) { |
| 254 | uint32_t offset = mtls->dimX * y; |
| 255 | uint8_t *xPtrOut = mtls->ptrOut + (mtls->eStrideOut * offset); |
| 256 | const uint8_t *xPtrIn = mtls->ptrIn + (mtls->eStrideIn * offset); |
| 257 | |
| 258 | for (uint32_t x = mtls->xStart; x < mtls->xEnd; x++) { |
| 259 | ((rs_t)mtls->script->mProgram.mRoot) (xPtrIn, xPtrOut, mtls->usr, x, y, 0, 0); |
| 260 | xPtrIn += mtls->eStrideIn; |
| 261 | xPtrOut += mtls->eStrideOut; |
| 262 | } |
| 263 | } |
| 264 | } |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 265 | } |
| 266 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 267 | static void wc_x(void *usr, uint32_t idx) { |
Jason Sams | 177f844 | 2010-10-29 10:19:21 -0700 | [diff] [blame] | 268 | MTLaunchStruct *mtls = (MTLaunchStruct *)usr; |
| 269 | |
| 270 | while (1) { |
| 271 | uint32_t slice = (uint32_t)android_atomic_inc(&mtls->mSliceNum); |
| 272 | uint32_t xStart = mtls->xStart + slice * mtls->mSliceSize; |
| 273 | uint32_t xEnd = xStart + mtls->mSliceSize; |
| 274 | xEnd = rsMin(xEnd, mtls->xEnd); |
| 275 | if (xEnd <= xStart) { |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | //LOGE("usr idx %i, x %i,%i y %i,%i", idx, mtls->xStart, mtls->xEnd, yStart, yEnd); |
| 280 | //LOGE("usr ptr in %p, out %p", mtls->ptrIn, mtls->ptrOut); |
| 281 | uint8_t *xPtrOut = mtls->ptrOut + (mtls->eStrideOut * xStart); |
| 282 | const uint8_t *xPtrIn = mtls->ptrIn + (mtls->eStrideIn * xStart); |
| 283 | for (uint32_t x = xStart; x < xEnd; x++) { |
| 284 | ((rs_t)mtls->script->mProgram.mRoot) (xPtrIn, xPtrOut, mtls->usr, x, 0, 0, 0); |
| 285 | xPtrIn += mtls->eStrideIn; |
| 286 | xPtrOut += mtls->eStrideOut; |
| 287 | } |
| 288 | } |
Jason Sams | 177f844 | 2010-10-29 10:19:21 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 291 | void ScriptC::runForEach(Context *rsc, |
| 292 | const Allocation * ain, |
| 293 | Allocation * aout, |
| 294 | const void * usr, |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 295 | const RsScriptCall *sc) { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 296 | MTLaunchStruct mtls; |
| 297 | memset(&mtls, 0, sizeof(mtls)); |
Jason Sams | 6070925 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 298 | Context::PushState ps(rsc); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 299 | |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 300 | if (ain) { |
| 301 | mtls.dimX = ain->getType()->getDimX(); |
| 302 | mtls.dimY = ain->getType()->getDimY(); |
| 303 | mtls.dimZ = ain->getType()->getDimZ(); |
| 304 | //mtls.dimArray = ain->getType()->getDimArray(); |
| 305 | } else if (aout) { |
| 306 | mtls.dimX = aout->getType()->getDimX(); |
| 307 | mtls.dimY = aout->getType()->getDimY(); |
| 308 | mtls.dimZ = aout->getType()->getDimZ(); |
| 309 | //mtls.dimArray = aout->getType()->getDimArray(); |
| 310 | } else { |
| 311 | rsc->setError(RS_ERROR_BAD_SCRIPT, "rsForEach called with null allocations"); |
| 312 | return; |
| 313 | } |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 314 | |
| 315 | if (!sc || (sc->xEnd == 0)) { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 316 | mtls.xEnd = mtls.dimX; |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 317 | } else { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 318 | rsAssert(sc->xStart < mtls.dimX); |
| 319 | rsAssert(sc->xEnd <= mtls.dimX); |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 320 | rsAssert(sc->xStart < sc->xEnd); |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 321 | mtls.xStart = rsMin(mtls.dimX, sc->xStart); |
| 322 | mtls.xEnd = rsMin(mtls.dimX, sc->xEnd); |
| 323 | if (mtls.xStart >= mtls.xEnd) return; |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | if (!sc || (sc->yEnd == 0)) { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 327 | mtls.yEnd = mtls.dimY; |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 328 | } else { |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 329 | rsAssert(sc->yStart < mtls.dimY); |
| 330 | rsAssert(sc->yEnd <= mtls.dimY); |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 331 | rsAssert(sc->yStart < sc->yEnd); |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 332 | mtls.yStart = rsMin(mtls.dimY, sc->yStart); |
| 333 | mtls.yEnd = rsMin(mtls.dimY, sc->yEnd); |
| 334 | if (mtls.yStart >= mtls.yEnd) return; |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 337 | mtls.xEnd = rsMax((uint32_t)1, mtls.xEnd); |
| 338 | mtls.yEnd = rsMax((uint32_t)1, mtls.yEnd); |
| 339 | mtls.zEnd = rsMax((uint32_t)1, mtls.zEnd); |
| 340 | mtls.arrayEnd = rsMax((uint32_t)1, mtls.arrayEnd); |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 341 | |
| 342 | rsAssert(ain->getType()->getDimZ() == 0); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 343 | |
Jason Sams | 1f24db4 | 2010-12-11 17:42:30 -0800 | [diff] [blame] | 344 | setupGLState(rsc); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 345 | setupScript(rsc); |
| 346 | Script * oldTLS = setTLS(this); |
| 347 | |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 348 | mtls.rsc = rsc; |
| 349 | mtls.ain = ain; |
| 350 | mtls.aout = aout; |
| 351 | mtls.script = this; |
| 352 | mtls.usr = usr; |
| 353 | mtls.mSliceSize = 10; |
| 354 | mtls.mSliceNum = 0; |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 355 | |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 356 | mtls.ptrIn = NULL; |
| 357 | mtls.eStrideIn = 0; |
| 358 | if (ain) { |
| 359 | mtls.ptrIn = (const uint8_t *)ain->getPtr(); |
| 360 | mtls.eStrideIn = ain->getType()->getElementSizeBytes(); |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 361 | } |
| 362 | |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 363 | mtls.ptrOut = NULL; |
| 364 | mtls.eStrideOut = 0; |
| 365 | if (aout) { |
| 366 | mtls.ptrOut = (uint8_t *)aout->getPtr(); |
| 367 | mtls.eStrideOut = aout->getType()->getElementSizeBytes(); |
| 368 | } |
| 369 | |
Jason Sams | 177f844 | 2010-10-29 10:19:21 -0700 | [diff] [blame] | 370 | if ((rsc->getWorkerPoolSize() > 1) && mEnviroment.mIsThreadable) { |
| 371 | if (mtls.dimY > 1) { |
| 372 | rsc->launchThreads(wc_xy, &mtls); |
| 373 | } else { |
| 374 | rsc->launchThreads(wc_x, &mtls); |
| 375 | } |
Jason Sams | 1813340 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 376 | |
| 377 | //LOGE("launch 1"); |
Jason Sams | 1813340 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 378 | } else { |
Jason Sams | 8d957fa | 2010-09-28 14:41:22 -0700 | [diff] [blame] | 379 | //LOGE("launch 3"); |
Jason Sams | 1813340 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 380 | for (uint32_t ar = mtls.arrayStart; ar < mtls.arrayEnd; ar++) { |
| 381 | for (uint32_t z = mtls.zStart; z < mtls.zEnd; z++) { |
| 382 | for (uint32_t y = mtls.yStart; y < mtls.yEnd; y++) { |
| 383 | uint32_t offset = mtls.dimX * mtls.dimY * mtls.dimZ * ar + |
| 384 | mtls.dimX * mtls.dimY * z + |
| 385 | mtls.dimX * y; |
| 386 | uint8_t *xPtrOut = mtls.ptrOut + (mtls.eStrideOut * offset); |
| 387 | const uint8_t *xPtrIn = mtls.ptrIn + (mtls.eStrideIn * offset); |
Jason Sams | 7bf29dd | 2010-07-19 15:38:19 -0700 | [diff] [blame] | 388 | |
Jason Sams | 1813340 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 389 | for (uint32_t x = mtls.xStart; x < mtls.xEnd; x++) { |
| 390 | ((rs_t)mProgram.mRoot) (xPtrIn, xPtrOut, usr, x, y, z, ar); |
| 391 | xPtrIn += mtls.eStrideIn; |
| 392 | xPtrOut += mtls.eStrideOut; |
| 393 | } |
Jason Sams | ace3e01 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | } |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 397 | } |
Jason Sams | 1813340 | 2010-07-20 15:09:00 -0700 | [diff] [blame] | 398 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 399 | setTLS(oldTLS); |
| 400 | } |
| 401 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 402 | void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, uint32_t len) { |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 403 | if ((slot >= mEnviroment.mInvokeFunctionCount) || |
| 404 | (mEnviroment.mInvokeFunctions[slot] == NULL)) { |
| 405 | rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script"); |
| 406 | return; |
| 407 | } |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 408 | setupScript(rsc); |
| 409 | Script * oldTLS = setTLS(this); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 410 | |
Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 411 | if (rsc->props.mLogScripts) { |
| 412 | LOGV("%p ScriptC::Invoke invoking slot %i, ptr %p", rsc, slot, mEnviroment.mInvokeFunctions[slot]); |
| 413 | } |
Jason Sams | 2a63bf6 | 2010-06-08 15:40:48 -0700 | [diff] [blame] | 414 | ((void (*)(const void *, uint32_t)) |
| 415 | mEnviroment.mInvokeFunctions[slot])(data, len); |
Jason Sams | b9077f4 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 416 | if (rsc->props.mLogScripts) { |
| 417 | LOGV("%p ScriptC::Invoke complete", rsc); |
| 418 | } |
Jason Sams | 2a63bf6 | 2010-06-08 15:40:48 -0700 | [diff] [blame] | 419 | |
Jason Sams | c61346b | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 420 | setTLS(oldTLS); |
Jason Sams | 22fa371 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 421 | } |
| 422 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 423 | ScriptCState::ScriptCState() { |
Stephen Hines | 01b7d29 | 2010-09-28 15:45:45 -0700 | [diff] [blame] | 424 | mScript.clear(); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 425 | } |
| 426 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 427 | ScriptCState::~ScriptCState() { |
Stephen Hines | 01b7d29 | 2010-09-28 15:45:45 -0700 | [diff] [blame] | 428 | mScript.clear(); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 431 | void ScriptCState::init(Context *rsc) { |
Stephen Hines | 01b7d29 | 2010-09-28 15:45:45 -0700 | [diff] [blame] | 432 | clear(rsc); |
| 433 | } |
| 434 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 435 | void ScriptCState::clear(Context *rsc) { |
Stephen Hines | 01b7d29 | 2010-09-28 15:45:45 -0700 | [diff] [blame] | 436 | rsAssert(rsc); |
Stephen Hines | 01b7d29 | 2010-09-28 15:45:45 -0700 | [diff] [blame] | 437 | mScript.clear(); |
| 438 | mScript.set(new ScriptC(rsc)); |
Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 441 | static void* symbolLookup(void* pContext, char const* name) { |
Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 442 | const ScriptCState::SymbolTable_t *sym; |
Jason Sams | dd663fa | 2010-08-11 13:26:28 -0700 | [diff] [blame] | 443 | ScriptC *s = (ScriptC *)pContext; |
Shih-wei Liao | f17b13b | 2010-12-07 13:44:10 -0800 | [diff] [blame] | 444 | if (!strcmp(name, "__isThreadable")) { |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 445 | return (void*) s->mEnviroment.mIsThreadable; |
Shih-wei Liao | f17b13b | 2010-12-07 13:44:10 -0800 | [diff] [blame] | 446 | } else if (!strcmp(name, "__clearThreadable")) { |
| 447 | s->mEnviroment.mIsThreadable = false; |
| 448 | return NULL; |
| 449 | } |
Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 450 | sym = ScriptCState::lookupSymbol(name); |
Jason Sams | 6bfc1b9 | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 451 | if (!sym) { |
| 452 | sym = ScriptCState::lookupSymbolCL(name); |
Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 453 | } |
Jason Sams | 6bfc1b9 | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 454 | if (!sym) { |
| 455 | sym = ScriptCState::lookupSymbolGL(name); |
Jason Sams | aeb094b | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 456 | } |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 457 | if (sym) { |
Jason Sams | 6bfc1b9 | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 458 | s->mEnviroment.mIsThreadable &= sym->threadable; |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 459 | return sym->mPtr; |
| 460 | } |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 461 | LOGE("ScriptC sym lookup failed for %s", name); |
Jason Sams | 29df66f | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 462 | return NULL; |
| 463 | } |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 464 | |
Shih-wei Liao | 80761ec | 2011-01-16 02:23:04 -0800 | [diff] [blame] | 465 | #if 0 |
Shih-wei Liao | 1f9ba73 | 2010-10-23 02:15:57 -0700 | [diff] [blame] | 466 | extern const char rs_runtime_lib_bc[]; |
| 467 | extern unsigned rs_runtime_lib_bc_size; |
Shih-wei Liao | 80761ec | 2011-01-16 02:23:04 -0800 | [diff] [blame] | 468 | #endif |
Shih-wei Liao | 1f9ba73 | 2010-10-23 02:15:57 -0700 | [diff] [blame] | 469 | |
Shih-wei Liao | ce8a079 | 2010-12-20 20:45:56 +0800 | [diff] [blame] | 470 | void ScriptCState::runCompiler(Context *rsc, |
| 471 | ScriptC *s, |
Shih-wei Liao | ce8a079 | 2010-12-20 20:45:56 +0800 | [diff] [blame] | 472 | const char *resName, |
| 473 | const char *cacheDir) { |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 474 | s->mBccScript = bccCreateScript(); |
Shih-wei Liao | 37150de | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 475 | |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 476 | s->mEnviroment.mIsThreadable = true; |
Shih-wei Liao | 37150de | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 477 | |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 478 | bccRegisterSymbolCallback(s->mBccScript, symbolLookup, s); |
Shih-wei Liao | 37150de | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 479 | |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 480 | if (bccReadBC(s->mBccScript, |
| 481 | resName, |
| 482 | s->mEnviroment.mScriptText, |
| 483 | s->mEnviroment.mScriptTextLength, 0) != 0) { |
| 484 | LOGE("bcc: FAILS to read bitcode"); |
| 485 | // Handle Fatal Error |
| 486 | } |
Shih-wei Liao | 37150de | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 487 | |
Shih-wei Liao | 80761ec | 2011-01-16 02:23:04 -0800 | [diff] [blame] | 488 | #if 1 |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 489 | if (bccLinkBC(s->mBccScript, |
| 490 | resName, |
| 491 | NULL /*rs_runtime_lib_bc*/, |
| 492 | 1 /*rs_runtime_lib_bc_size*/ |
| 493 | /*"1" means skip buffer here, and let libbcc decide*/, |
| 494 | 0) != 0) { |
| 495 | LOGE("bcc: FAILS to link bitcode"); |
| 496 | // Handle Fatal Error |
Alex Sakhartchouk | b26fb04 | 2010-09-24 15:18:12 -0700 | [diff] [blame] | 497 | } |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 498 | #endif |
| 499 | char *cachePath = genCacheFileName(cacheDir, resName, ".oBCC"); |
| 500 | |
| 501 | if (bccPrepareExecutable(s->mBccScript, cachePath, 0) != 0) { |
| 502 | LOGE("bcc: FAILS to prepare executable"); |
| 503 | // Handle Fatal Error |
| 504 | } |
| 505 | |
| 506 | free(cachePath); |
| 507 | |
| 508 | s->mProgram.mRoot = reinterpret_cast<int (*)()>(bccGetFuncAddr(s->mBccScript, "root")); |
| 509 | s->mProgram.mInit = reinterpret_cast<void (*)()>(bccGetFuncAddr(s->mBccScript, "init")); |
Jason Sams | f168504 | 2009-07-16 17:47:40 -0700 | [diff] [blame] | 510 | |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 511 | if (s->mProgram.mInit) { |
| 512 | s->mProgram.mInit(); |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 515 | s->mEnviroment.mInvokeFunctionCount = bccGetExportFuncCount(s->mBccScript); |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 516 | if (s->mEnviroment.mInvokeFunctionCount <= 0) |
Jason Sams | 8c88090 | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 517 | s->mEnviroment.mInvokeFunctions = NULL; |
| 518 | else { |
| 519 | s->mEnviroment.mInvokeFunctions = (Script::InvokeFunc_t*) calloc(s->mEnviroment.mInvokeFunctionCount, sizeof(Script::InvokeFunc_t)); |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 520 | bccGetExportFuncList(s->mBccScript, s->mEnviroment.mInvokeFunctionCount, (void **) s->mEnviroment.mInvokeFunctions); |
Jason Sams | 1d54f10 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 523 | s->mEnviroment.mFieldCount = bccGetExportVarCount(s->mBccScript); |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 524 | if (s->mEnviroment.mFieldCount <= 0) |
Shih-wei Liao | a226b16 | 2010-07-20 16:43:25 -0700 | [diff] [blame] | 525 | s->mEnviroment.mFieldAddress = NULL; |
| 526 | else { |
| 527 | s->mEnviroment.mFieldAddress = (void **) calloc(s->mEnviroment.mFieldCount, sizeof(void *)); |
Shih-wei Liao | 2b2e621 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 528 | bccGetExportVarList(s->mBccScript, s->mEnviroment.mFieldCount, (void **) s->mEnviroment.mFieldAddress); |
Alex Sakhartchouk | 700ba38 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 529 | s->initSlots(); |
Shih-wei Liao | a226b16 | 2010-07-20 16:43:25 -0700 | [diff] [blame] | 530 | } |
Jason Sams | a4a54e4 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 531 | |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 532 | s->mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); |
| 533 | s->mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); |
Jason Sams | ccc010b | 2010-05-13 18:30:11 -0700 | [diff] [blame] | 534 | s->mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore()); |
Jason Sams | b681c8a | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 535 | s->mEnviroment.mRaster.set(rsc->getDefaultProgramRaster()); |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 536 | |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 537 | const static int pragmaMax = 16; |
| 538 | size_t pragmaCount = bccGetPragmaCount(s->mBccScript); |
| 539 | char const *keys[pragmaMax]; |
| 540 | char const *values[pragmaMax]; |
| 541 | bccGetPragmaList(s->mBccScript, pragmaMax, keys, values); |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 542 | |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 543 | for (size_t i=0; i < pragmaCount; ++i) { |
| 544 | //LOGE("pragma %s %s", keys[i], values[i]); |
| 545 | if (!strcmp(keys[i], "version")) { |
Stephen Hines | b5dc6af | 2011-01-18 14:10:44 -0800 | [diff] [blame^] | 546 | if (!strcmp(values[i], "1")) { |
| 547 | continue; |
| 548 | } |
| 549 | LOGE("Invalid version pragma value: %s\n", values[i]); |
| 550 | // Handle Fatal Error |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 551 | } |
| 552 | |
| 553 | if (!strcmp(keys[i], "stateVertex")) { |
| 554 | if (!strcmp(values[i], "default")) { |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 555 | continue; |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 556 | } |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 557 | if (!strcmp(values[i], "parent")) { |
| 558 | s->mEnviroment.mVertex.clear(); |
| 559 | continue; |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 560 | } |
Stephen Hines | b5dc6af | 2011-01-18 14:10:44 -0800 | [diff] [blame^] | 561 | LOGE("Unrecognized value %s passed to stateVertex", values[i]); |
| 562 | // Handle Fatal Error |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 563 | } |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 564 | |
| 565 | if (!strcmp(keys[i], "stateRaster")) { |
| 566 | if (!strcmp(values[i], "default")) { |
| 567 | continue; |
| 568 | } |
| 569 | if (!strcmp(values[i], "parent")) { |
| 570 | s->mEnviroment.mRaster.clear(); |
| 571 | continue; |
| 572 | } |
Stephen Hines | b5dc6af | 2011-01-18 14:10:44 -0800 | [diff] [blame^] | 573 | LOGE("Unrecognized value %s passed to stateRaster", values[i]); |
| 574 | // Handle Fatal Error |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | if (!strcmp(keys[i], "stateFragment")) { |
| 578 | if (!strcmp(values[i], "default")) { |
| 579 | continue; |
| 580 | } |
| 581 | if (!strcmp(values[i], "parent")) { |
| 582 | s->mEnviroment.mFragment.clear(); |
| 583 | continue; |
| 584 | } |
Stephen Hines | b5dc6af | 2011-01-18 14:10:44 -0800 | [diff] [blame^] | 585 | LOGE("Unrecognized value %s passed to stateFragment", values[i]); |
| 586 | // Handle Fatal Error |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | if (!strcmp(keys[i], "stateStore")) { |
| 590 | if (!strcmp(values[i], "default")) { |
| 591 | continue; |
| 592 | } |
| 593 | if (!strcmp(values[i], "parent")) { |
| 594 | s->mEnviroment.mFragmentStore.clear(); |
| 595 | continue; |
| 596 | } |
Stephen Hines | b5dc6af | 2011-01-18 14:10:44 -0800 | [diff] [blame^] | 597 | LOGE("Unrecognized value %s passed to stateStore", values[i]); |
| 598 | // Handle Fatal Error |
Stephen Hines | 7b337b1 | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 599 | } |
Jason Sams | 1030893 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 600 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | namespace android { |
| 604 | namespace renderscript { |
| 605 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 606 | void rsi_ScriptCBegin(Context * rsc) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 607 | ScriptCState *ss = &rsc->mScriptC; |
Stephen Hines | 01b7d29 | 2010-09-28 15:45:45 -0700 | [diff] [blame] | 608 | ss->clear(rsc); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 609 | } |
| 610 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 611 | void rsi_ScriptCSetText(Context *rsc, const char *text, uint32_t len) { |
Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 612 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | e402ed3 | 2009-11-03 11:25:42 -0800 | [diff] [blame] | 613 | |
| 614 | char *t = (char *)malloc(len + 1); |
| 615 | memcpy(t, text, len); |
| 616 | t[len] = 0; |
| 617 | ss->mScript->mEnviroment.mScriptText = t; |
Jason Sams | 8c6bc69 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 618 | ss->mScript->mEnviroment.mScriptTextLength = len; |
Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 619 | } |
| 620 | |
Shih-wei Liao | ce8a079 | 2010-12-20 20:45:56 +0800 | [diff] [blame] | 621 | |
| 622 | RsScript rsi_ScriptCCreate(Context *rsc, |
Shih-wei Liao | 37150de | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 623 | const char *packageName /* deprecated */, |
Shih-wei Liao | ce8a079 | 2010-12-20 20:45:56 +0800 | [diff] [blame] | 624 | const char *resName, |
| 625 | const char *cacheDir) |
Shih-wei Liao | 9503b66 | 2010-11-08 01:33:59 -0800 | [diff] [blame] | 626 | { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 627 | ScriptCState *ss = &rsc->mScriptC; |
| 628 | |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 629 | ObjectBaseRef<ScriptC> s(ss->mScript); |
Stephen Hines | 01b7d29 | 2010-09-28 15:45:45 -0700 | [diff] [blame] | 630 | ss->mScript.clear(); |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 631 | s->incUserRef(); |
Jason Sams | 1f52633 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 632 | |
Shih-wei Liao | 37150de | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 633 | ss->runCompiler(rsc, s.get(), resName, cacheDir); |
Stephen Hines | 01b7d29 | 2010-09-28 15:45:45 -0700 | [diff] [blame] | 634 | ss->clear(rsc); |
| 635 | return s.get(); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 636 | } |
| 637 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 638 | } |
| 639 | } |