Jason Sams | d19f10d | 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" |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 19 | #include "utils/Timers.h" |
Alex Sakhartchouk | eb1a73c | 2010-09-24 15:18:12 -0700 | [diff] [blame] | 20 | #include "utils/StopWatch.h" |
Jack Palevich | ec5a20b | 2009-05-28 15:53:04 -0700 | [diff] [blame] | 21 | |
Stephen Hines | 4382467a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 22 | #ifndef ANDROID_RS_SERIALIZE |
| 23 | #include <bcinfo/BitcodeTranslator.h> |
| 24 | #endif |
| 25 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 26 | using namespace android; |
| 27 | using namespace android::renderscript; |
| 28 | |
Jason Sams | 462d11b | 2009-06-19 16:03:18 -0700 | [diff] [blame] | 29 | #define GET_TLS() Context::ScriptTLSStruct * tls = \ |
| 30 | (Context::ScriptTLSStruct *)pthread_getspecific(Context::gThreadTLSKey); \ |
| 31 | Context * rsc = tls->mContext; \ |
| 32 | ScriptC * sc = (ScriptC *) tls->mScript |
| 33 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 34 | ScriptC::ScriptC(Context *rsc) : Script(rsc) { |
Stephen Hines | 4382467a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 35 | #ifndef ANDROID_RS_SERIALIZE |
| 36 | BT = NULL; |
| 37 | #endif |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 40 | ScriptC::~ScriptC() { |
Stephen Hines | 4382467a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 41 | #ifndef ANDROID_RS_SERIALIZE |
| 42 | if (BT) { |
| 43 | delete BT; |
| 44 | BT = NULL; |
| 45 | } |
| 46 | #endif |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 47 | mRSC->mHal.funcs.script.destroy(mRSC, this); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 50 | void ScriptC::setupScript(Context *rsc) { |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 51 | mEnviroment.mStartTimeMillis |
| 52 | = nanoseconds_to_milliseconds(systemTime(SYSTEM_TIME_MONOTONIC)); |
| 53 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 54 | for (uint32_t ct=0; ct < mHal.info.exportedVariableCount; ct++) { |
Jason Sams | d081fff | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 55 | if (mSlots[ct].get() && !mTypes[ct].get()) { |
| 56 | mTypes[ct].set(mSlots[ct]->getType()); |
| 57 | } |
| 58 | |
| 59 | if (!mTypes[ct].get()) |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 60 | continue; |
Jason Sams | d081fff | 2010-09-16 18:18:29 -0700 | [diff] [blame] | 61 | void *ptr = NULL; |
| 62 | if (mSlots[ct].get()) { |
| 63 | ptr = mSlots[ct]->getPtr(); |
| 64 | } |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 65 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 66 | rsc->mHal.funcs.script.setGlobalBind(rsc, this, ct, ptr); |
Jason Sams | e60446b | 2009-09-24 14:55:38 -0700 | [diff] [blame] | 67 | } |
| 68 | } |
| 69 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 70 | const Allocation *ScriptC::ptrToAllocation(const void *ptr) const { |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 71 | //LOGE("ptr to alloc %p", ptr); |
Jason Sams | 1de0b87 | 2010-05-17 14:55:34 -0700 | [diff] [blame] | 72 | if (!ptr) { |
| 73 | return NULL; |
| 74 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 75 | for (uint32_t ct=0; ct < mHal.info.exportedVariableCount; ct++) { |
Jason Sams | 1de0b87 | 2010-05-17 14:55:34 -0700 | [diff] [blame] | 76 | if (!mSlots[ct].get()) |
| 77 | continue; |
| 78 | if (mSlots[ct]->getPtr() == ptr) { |
| 79 | return mSlots[ct].get(); |
| 80 | } |
| 81 | } |
| 82 | LOGE("ScriptC::ptrToAllocation, failed to find %p", ptr); |
| 83 | return NULL; |
| 84 | } |
| 85 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 86 | void ScriptC::setupGLState(Context *rsc) { |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 87 | if (mEnviroment.mFragmentStore.get()) { |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 88 | rsc->setProgramStore(mEnviroment.mFragmentStore.get()); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 89 | } |
| 90 | if (mEnviroment.mFragment.get()) { |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 91 | rsc->setProgramFragment(mEnviroment.mFragment.get()); |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 92 | } |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 93 | if (mEnviroment.mVertex.get()) { |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 94 | rsc->setProgramVertex(mEnviroment.mVertex.get()); |
Jason Sams | 9c54bdb | 2009-06-17 16:52:59 -0700 | [diff] [blame] | 95 | } |
Jason Sams | 5235cf3 | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 96 | if (mEnviroment.mRaster.get()) { |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 97 | rsc->setProgramRaster(mEnviroment.mRaster.get()); |
Jason Sams | 5235cf3 | 2009-09-28 18:12:56 -0700 | [diff] [blame] | 98 | } |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 99 | } |
Jason Sams | 3eaa338 | 2009-06-10 15:04:38 -0700 | [diff] [blame] | 100 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 101 | uint32_t ScriptC::run(Context *rsc) { |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 102 | if (mHal.info.root == NULL) { |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 103 | rsc->setError(RS_ERROR_BAD_SCRIPT, "Attempted to run bad script"); |
| 104 | return 0; |
Joe Onorato | 3370ec9 | 2009-08-09 11:39:02 -0700 | [diff] [blame] | 105 | } |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 106 | |
Jason Sams | 4859f52 | 2010-12-11 17:42:30 -0800 | [diff] [blame] | 107 | setupGLState(rsc); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 108 | setupScript(rsc); |
Jason Sams | 2525a81 | 2009-09-03 15:43:13 -0700 | [diff] [blame] | 109 | |
Jason Sams | b9d5c57 | 2009-12-09 11:05:45 -0800 | [diff] [blame] | 110 | uint32_t ret = 0; |
Jason Sams | f119b91 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 111 | |
| 112 | if (rsc->props.mLogScripts) { |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 113 | LOGV("%p ScriptC::run invoking root, ptr %p", rsc, mHal.info.root); |
Jason Sams | f119b91 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 116 | ret = rsc->mHal.funcs.script.invokeRoot(rsc, this); |
Jason Sams | f119b91 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 117 | |
| 118 | if (rsc->props.mLogScripts) { |
| 119 | LOGV("%p ScriptC::run invoking complete, ret=%i", rsc, ret); |
| 120 | } |
| 121 | |
Jason Sams | c97bb88 | 2009-07-20 14:31:06 -0700 | [diff] [blame] | 122 | return ret; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 123 | } |
| 124 | |
Jason Sams | 5585e36 | 2010-10-29 10:19:21 -0700 | [diff] [blame] | 125 | |
Jason Sams | 8f8a572 | 2010-07-15 17:11:13 -0700 | [diff] [blame] | 126 | void ScriptC::runForEach(Context *rsc, |
| 127 | const Allocation * ain, |
| 128 | Allocation * aout, |
| 129 | const void * usr, |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 130 | size_t usrBytes, |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 131 | const RsScriptCall *sc) { |
Jason Sams | 55d2a25 | 2011-03-17 16:12:47 -0700 | [diff] [blame] | 132 | |
Jason Sams | a17af04 | 2010-11-17 15:29:32 -0800 | [diff] [blame] | 133 | Context::PushState ps(rsc); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 134 | |
Jason Sams | 4859f52 | 2010-12-11 17:42:30 -0800 | [diff] [blame] | 135 | setupGLState(rsc); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 136 | setupScript(rsc); |
Jason Sams | 92b0eab | 2011-07-13 11:26:26 -0700 | [diff] [blame] | 137 | rsc->mHal.funcs.script.invokeForEach(rsc, this, 0, ain, aout, usr, usrBytes, sc); |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 138 | } |
| 139 | |
Alex Sakhartchouk | 17a8a19 | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 140 | void ScriptC::Invoke(Context *rsc, uint32_t slot, const void *data, size_t len) { |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 141 | if (slot >= mHal.info.exportedFunctionCount) { |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 142 | rsc->setError(RS_ERROR_BAD_SCRIPT, "Calling invoke on bad script"); |
| 143 | return; |
| 144 | } |
Jason Sams | f17bccc | 2010-05-28 18:23:22 -0700 | [diff] [blame] | 145 | setupScript(rsc); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 146 | |
Jason Sams | f119b91 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 147 | if (rsc->props.mLogScripts) { |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 148 | LOGV("%p ScriptC::Invoke invoking slot %i, ptr %p", rsc, slot, this); |
Jason Sams | f119b91 | 2010-09-22 15:57:41 -0700 | [diff] [blame] | 149 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 150 | rsc->mHal.funcs.script.invokeFunction(rsc, this, slot, data, len); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 153 | ScriptCState::ScriptCState() { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 154 | } |
| 155 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 156 | ScriptCState::~ScriptCState() { |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 157 | } |
| 158 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 159 | /* |
Shih-wei Liao | 076b770 | 2011-01-14 06:21:28 -0800 | [diff] [blame] | 160 | static void* symbolLookup(void* pContext, char const* name) { |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 161 | const ScriptCState::SymbolTable_t *sym; |
Jason Sams | 2cbd298 | 2010-08-11 13:26:28 -0700 | [diff] [blame] | 162 | ScriptC *s = (ScriptC *)pContext; |
Shih-wei Liao | b7282bd | 2010-12-07 13:44:10 -0800 | [diff] [blame] | 163 | if (!strcmp(name, "__isThreadable")) { |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 164 | return (void*) s->mHal.info.isThreadable; |
Shih-wei Liao | b7282bd | 2010-12-07 13:44:10 -0800 | [diff] [blame] | 165 | } else if (!strcmp(name, "__clearThreadable")) { |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 166 | s->mHal.info.isThreadable = false; |
Shih-wei Liao | b7282bd | 2010-12-07 13:44:10 -0800 | [diff] [blame] | 167 | return NULL; |
| 168 | } |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 169 | sym = ScriptCState::lookupSymbol(name); |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 170 | if (!sym) { |
| 171 | sym = ScriptCState::lookupSymbolCL(name); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 172 | } |
Jason Sams | 8f0adba | 2010-11-01 14:26:30 -0700 | [diff] [blame] | 173 | if (!sym) { |
| 174 | sym = ScriptCState::lookupSymbolGL(name); |
Jason Sams | 536923d | 2010-05-18 13:35:45 -0700 | [diff] [blame] | 175 | } |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 176 | if (sym) { |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 177 | s->mHal.info.isThreadable &= sym->threadable; |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 178 | return sym->mPtr; |
| 179 | } |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 180 | LOGE("ScriptC sym lookup failed for %s", name); |
Jason Sams | 54440a0 | 2009-07-16 15:08:06 -0700 | [diff] [blame] | 181 | return NULL; |
| 182 | } |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 183 | */ |
Jason Sams | d5680f9 | 2009-06-10 18:39:40 -0700 | [diff] [blame] | 184 | |
Shih-wei Liao | 71a2e13 | 2011-01-16 02:23:04 -0800 | [diff] [blame] | 185 | #if 0 |
Shih-wei Liao | 0175e01 | 2010-10-23 02:15:57 -0700 | [diff] [blame] | 186 | extern const char rs_runtime_lib_bc[]; |
| 187 | extern unsigned rs_runtime_lib_bc_size; |
Shih-wei Liao | 71a2e13 | 2011-01-16 02:23:04 -0800 | [diff] [blame] | 188 | #endif |
Shih-wei Liao | 0175e01 | 2010-10-23 02:15:57 -0700 | [diff] [blame] | 189 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 190 | bool ScriptC::runCompiler(Context *rsc, |
| 191 | const char *resName, |
| 192 | const char *cacheDir, |
| 193 | const uint8_t *bitcode, |
| 194 | size_t bitcodeLen) { |
Shih-wei Liao | 9d4024d | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 195 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 196 | //LOGE("runCompiler %p %p %p %p %p %i", rsc, this, resName, cacheDir, bitcode, bitcodeLen); |
Stephen Hines | 4382467a | 2011-08-01 15:02:34 -0700 | [diff] [blame] | 197 | #ifndef ANDROID_RS_SERIALIZE |
| 198 | uint32_t sdkVersion = rsc->getTargetSdkVersion(); |
| 199 | if (BT) { |
| 200 | delete BT; |
| 201 | } |
| 202 | BT = new bcinfo::BitcodeTranslator((const char *)bitcode, bitcodeLen, |
| 203 | sdkVersion); |
| 204 | if (!BT->translate()) { |
| 205 | LOGE("Failed to translate bitcode from version: %u", sdkVersion); |
| 206 | delete BT; |
| 207 | BT = NULL; |
| 208 | return false; |
| 209 | } |
| 210 | bitcode = (const uint8_t *) BT->getTranslatedBitcode(); |
| 211 | bitcodeLen = BT->getTranslatedBitcodeSize(); |
| 212 | #endif |
Shih-wei Liao | 9d4024d | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 213 | |
Jason Sams | fcf7231 | 2011-04-20 15:09:01 -0700 | [diff] [blame] | 214 | rsc->mHal.funcs.script.init(rsc, this, resName, cacheDir, bitcode, bitcodeLen, 0); |
Shih-wei Liao | 9d4024d | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 215 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 216 | mEnviroment.mFragment.set(rsc->getDefaultProgramFragment()); |
| 217 | mEnviroment.mVertex.set(rsc->getDefaultProgramVertex()); |
| 218 | mEnviroment.mFragmentStore.set(rsc->getDefaultProgramStore()); |
| 219 | mEnviroment.mRaster.set(rsc->getDefaultProgramRaster()); |
Shih-wei Liao | 9d4024d | 2011-01-07 18:17:07 -0800 | [diff] [blame] | 220 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 221 | rsc->mHal.funcs.script.invokeInit(rsc, this); |
Stephen Hines | 5ef3ddd | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 222 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 223 | for (size_t i=0; i < mHal.info.exportedPragmaCount; ++i) { |
| 224 | const char * key = mHal.info.exportedPragmaKeyList[i]; |
| 225 | const char * value = mHal.info.exportedPragmaValueList[i]; |
Stephen Hines | 5ef3ddd | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 226 | //LOGE("pragma %s %s", keys[i], values[i]); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 227 | if (!strcmp(key, "version")) { |
| 228 | if (!strcmp(value, "1")) { |
Stephen Hines | 5dd60be | 2011-01-18 14:10:44 -0800 | [diff] [blame] | 229 | continue; |
| 230 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 231 | LOGE("Invalid version pragma value: %s\n", value); |
Jason Sams | fdc54a9 | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 232 | return false; |
Stephen Hines | 5ef3ddd | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 233 | } |
| 234 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 235 | if (!strcmp(key, "stateVertex")) { |
| 236 | if (!strcmp(value, "default")) { |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 237 | continue; |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 238 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 239 | if (!strcmp(value, "parent")) { |
| 240 | mEnviroment.mVertex.clear(); |
Stephen Hines | 5ef3ddd | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 241 | continue; |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 242 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 243 | LOGE("Unrecognized value %s passed to stateVertex", value); |
Jason Sams | fdc54a9 | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 244 | return false; |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 245 | } |
Stephen Hines | 5ef3ddd | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 246 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 247 | if (!strcmp(key, "stateRaster")) { |
| 248 | if (!strcmp(value, "default")) { |
Stephen Hines | 5ef3ddd | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 249 | continue; |
| 250 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 251 | if (!strcmp(value, "parent")) { |
| 252 | mEnviroment.mRaster.clear(); |
Stephen Hines | 5ef3ddd | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 253 | continue; |
| 254 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 255 | LOGE("Unrecognized value %s passed to stateRaster", value); |
Jason Sams | fdc54a9 | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 256 | return false; |
Stephen Hines | 5ef3ddd | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 257 | } |
| 258 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 259 | if (!strcmp(key, "stateFragment")) { |
| 260 | if (!strcmp(value, "default")) { |
Stephen Hines | 5ef3ddd | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 261 | continue; |
| 262 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 263 | if (!strcmp(value, "parent")) { |
| 264 | mEnviroment.mFragment.clear(); |
Stephen Hines | 5ef3ddd | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 265 | continue; |
| 266 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 267 | LOGE("Unrecognized value %s passed to stateFragment", value); |
Jason Sams | fdc54a9 | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 268 | return false; |
Stephen Hines | 5ef3ddd | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 271 | if (!strcmp(key, "stateStore")) { |
| 272 | if (!strcmp(value, "default")) { |
Stephen Hines | 5ef3ddd | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 273 | continue; |
| 274 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 275 | if (!strcmp(value, "parent")) { |
| 276 | mEnviroment.mFragmentStore.clear(); |
Stephen Hines | 5ef3ddd | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 277 | continue; |
| 278 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 279 | LOGE("Unrecognized value %s passed to stateStore", value); |
Jason Sams | fdc54a9 | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 280 | return false; |
Stephen Hines | 5ef3ddd | 2011-01-17 17:31:58 -0800 | [diff] [blame] | 281 | } |
Jason Sams | da423d8 | 2009-06-09 12:15:30 -0700 | [diff] [blame] | 282 | } |
Jason Sams | 38f8d9d | 2011-01-27 00:14:13 -0800 | [diff] [blame] | 283 | |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 284 | mSlots = new ObjectBaseRef<Allocation>[mHal.info.exportedVariableCount]; |
| 285 | mTypes = new ObjectBaseRef<const Type>[mHal.info.exportedVariableCount]; |
Jason Sams | 38f8d9d | 2011-01-27 00:14:13 -0800 | [diff] [blame] | 286 | |
Jason Sams | fdc54a9 | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 287 | return true; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | namespace android { |
| 291 | namespace renderscript { |
| 292 | |
Shih-wei Liao | eeca435 | 2010-12-20 20:45:56 +0800 | [diff] [blame] | 293 | RsScript rsi_ScriptCCreate(Context *rsc, |
Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 294 | const char *resName, size_t resName_length, |
| 295 | const char *cacheDir, size_t cacheDir_length, |
Alex Sakhartchouk | 17a8a19 | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 296 | const char *text, size_t text_length) |
Shih-wei Liao | a914f34 | 2010-11-08 01:33:59 -0800 | [diff] [blame] | 297 | { |
Jason Sams | c55de66 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 298 | ScriptC *s = new ScriptC(rsc); |
Jason Sams | 39ddc950 | 2009-06-05 17:35:09 -0700 | [diff] [blame] | 299 | |
Alex Sakhartchouk | e7c4a75 | 2011-04-06 10:57:51 -0700 | [diff] [blame] | 300 | if (!s->runCompiler(rsc, resName, cacheDir, (uint8_t *)text, text_length)) { |
Jason Sams | fdc54a9 | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 301 | // Error during compile, destroy s and return null. |
Jason Sams | c55de66 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 302 | delete s; |
Jason Sams | fdc54a9 | 2011-01-19 16:14:21 -0800 | [diff] [blame] | 303 | return NULL; |
| 304 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 305 | |
| 306 | s->incUserRef(); |
Jason Sams | c55de66 | 2011-01-23 17:48:45 -0800 | [diff] [blame] | 307 | return s; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 310 | } |
| 311 | } |