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