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 | |
| 19 | using namespace android; |
| 20 | using namespace android::renderscript; |
| 21 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 22 | Script::Script(Context *rsc) : ObjectBase(rsc) { |
Jason Sams | 928f5cf | 2009-06-08 18:50:13 -0700 | [diff] [blame] | 23 | memset(&mEnviroment, 0, sizeof(mEnviroment)); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 24 | memset(&mHal, 0, sizeof(mHal)); |
Alex Sakhartchouk | 6f91cb6 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 25 | |
| 26 | mSlots = NULL; |
| 27 | mTypes = NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 28 | } |
| 29 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 30 | Script::~Script() { |
| 31 | if (mSlots) { |
Alex Sakhartchouk | 6f91cb6 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 32 | delete [] mSlots; |
| 33 | mSlots = NULL; |
| 34 | } |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 35 | if (mTypes) { |
Alex Sakhartchouk | 6f91cb6 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 36 | delete [] mTypes; |
| 37 | mTypes = NULL; |
| 38 | } |
| 39 | } |
| 40 | |
Alex Sakhartchouk | 6f91cb6 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 41 | void Script::setSlot(uint32_t slot, Allocation *a) { |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 42 | //LOGE("setSlot %i %p", slot, a); |
| 43 | if (slot >= mHal.info.exportedVariableCount) { |
Alex Sakhartchouk | 6f91cb6 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 44 | LOGE("Script::setSlot unable to set allocation, invalid slot index"); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | mSlots[slot].set(a); |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 49 | if (a != NULL) { |
| 50 | mRSC->mHal.funcs.script.setGlobalBind(mRSC, this, slot, a->getPtr()); |
| 51 | } else { |
| 52 | mRSC->mHal.funcs.script.setGlobalBind(mRSC, this, slot, NULL); |
| 53 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 54 | } |
| 55 | |
Alex Sakhartchouk | 17a8a19 | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 56 | void Script::setVar(uint32_t slot, const void *val, size_t len) { |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 57 | //LOGE("setVar %i %p %i", slot, val, len); |
| 58 | if (slot >= mHal.info.exportedVariableCount) { |
| 59 | LOGE("Script::setVar unable to set allocation, invalid slot index"); |
| 60 | return; |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 61 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 62 | mRSC->mHal.funcs.script.setGlobalVar(mRSC, this, slot, (void *)val, len); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 65 | void Script::setVarObj(uint32_t slot, ObjectBase *val) { |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 66 | //LOGE("setVarObj %i %p", slot, val); |
| 67 | if (slot >= mHal.info.exportedVariableCount) { |
| 68 | LOGE("Script::setVarObj unable to set allocation, invalid slot index"); |
| 69 | return; |
Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 70 | } |
Jason Sams | e4a06c5 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 71 | //LOGE("setvarobj %i %p", slot, val); |
| 72 | mRSC->mHal.funcs.script.setGlobalObj(mRSC, this, slot, val); |
Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 75 | namespace android { |
| 76 | namespace renderscript { |
| 77 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 78 | void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot) { |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 79 | Script *s = static_cast<Script *>(vs); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 80 | Allocation *a = static_cast<Allocation *>(va); |
Alex Sakhartchouk | 6f91cb6 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 81 | s->setSlot(slot, a); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 82 | //LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr()); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Alex Sakhartchouk | 17a8a19 | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 85 | void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, size_t length) { |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 86 | Script *s = static_cast<Script *>(vs); |
| 87 | s->mEnviroment.mTimeZone = timeZone; |
| 88 | } |
| 89 | |
Jason Sams | a08526a | 2011-04-27 15:12:49 -0700 | [diff] [blame] | 90 | void rsi_ScriptForEach(Context *rsc, RsScript vs, uint32_t slot, |
| 91 | RsAllocation vain, RsAllocation vaout, |
Alex Sakhartchouk | 17a8a19 | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 92 | const void *params, size_t paramLen) { |
Jason Sams | a08526a | 2011-04-27 15:12:49 -0700 | [diff] [blame] | 93 | Script *s = static_cast<Script *>(vs); |
| 94 | s->runForEach(rsc, |
| 95 | static_cast<const Allocation *>(vain), static_cast<Allocation *>(vaout), |
| 96 | params, paramLen); |
| 97 | |
| 98 | } |
| 99 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 100 | void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot) { |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 101 | Script *s = static_cast<Script *>(vs); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 102 | s->Invoke(rsc, slot, NULL, 0); |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 106 | void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data) { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 107 | Script *s = static_cast<Script *>(vs); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 108 | s->Invoke(rsc, slot, NULL, 0); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Alex Sakhartchouk | 17a8a19 | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 111 | void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 112 | Script *s = static_cast<Script *>(vs); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 113 | s->Invoke(rsc, slot, data, len); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 116 | void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value) { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 117 | Script *s = static_cast<Script *>(vs); |
| 118 | s->setVar(slot, &value, sizeof(value)); |
| 119 | } |
| 120 | |
Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 121 | void rsi_ScriptSetVarObj(Context *rsc, RsScript vs, uint32_t slot, RsObjectBase value) { |
| 122 | Script *s = static_cast<Script *>(vs); |
| 123 | ObjectBase *o = static_cast<ObjectBase *>(value); |
| 124 | s->setVarObj(slot, o); |
| 125 | } |
| 126 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 127 | void rsi_ScriptSetVarJ(Context *rsc, RsScript vs, uint32_t slot, long long value) { |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 128 | Script *s = static_cast<Script *>(vs); |
| 129 | s->setVar(slot, &value, sizeof(value)); |
| 130 | } |
| 131 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 132 | void rsi_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value) { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 133 | Script *s = static_cast<Script *>(vs); |
| 134 | s->setVar(slot, &value, sizeof(value)); |
| 135 | } |
| 136 | |
Alex Sakhartchouk | ed9f210 | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 137 | void rsi_ScriptSetVarD(Context *rsc, RsScript vs, uint32_t slot, double value) { |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 138 | Script *s = static_cast<Script *>(vs); |
| 139 | s->setVar(slot, &value, sizeof(value)); |
| 140 | } |
| 141 | |
Alex Sakhartchouk | 17a8a19 | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 142 | void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 143 | Script *s = static_cast<Script *>(vs); |
| 144 | s->setVar(slot, data, len); |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | |