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