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 22 Script::Script(Context *rsc) : ObjectBase(rsc) { 23 memset(&mEnviroment, 0, sizeof(mEnviroment)); 24 memset(&mHal, 0, sizeof(mHal)); 25 26 mSlots = NULL; 27 mTypes = NULL; 28 } 29 30 Script::~Script() { 31 if (mSlots) { 32 delete [] mSlots; 33 mSlots = NULL; 34 } 35 if (mTypes) { 36 delete [] mTypes; 37 mTypes = NULL; 38 } 39 } 40 41 void Script::setSlot(uint32_t slot, Allocation *a) { 42 //LOGE("setSlot %i %p", slot, a); 43 if (slot >= mHal.info.exportedVariableCount) { 44 LOGE("Script::setSlot unable to set allocation, invalid slot index"); 45 return; 46 } 47 48 mSlots[slot].set(a); 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 } 54 } 55 56 void Script::setVar(uint32_t slot, const void *val, size_t len) { 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; 61 } 62 mRSC->mHal.funcs.script.setGlobalVar(mRSC, this, slot, (void *)val, len); 63 } 64 65 void Script::setVarObj(uint32_t slot, ObjectBase *val) { 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; 70 } 71 //LOGE("setvarobj %i %p", slot, val); 72 mRSC->mHal.funcs.script.setGlobalObj(mRSC, this, slot, val); 73 } 74 75 bool Script::freeChildren() { 76 incSysRef(); 77 mRSC->mHal.funcs.script.invokeFreeChildren(mRSC, this); 78 return decSysRef(); 79 } 80 81 namespace android { 82 namespace renderscript { 83 84 void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot) { 85 Script *s = static_cast<Script *>(vs); 86 Allocation *a = static_cast<Allocation *>(va); 87 s->setSlot(slot, a); 88 //LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr()); 89 } 90 91 void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, size_t length) { 92 Script *s = static_cast<Script *>(vs); 93 s->mEnviroment.mTimeZone = timeZone; 94 } 95 96 void rsi_ScriptForEach(Context *rsc, RsScript vs, uint32_t slot, 97 RsAllocation vain, RsAllocation vaout, 98 const void *params, size_t paramLen) { 99 Script *s = static_cast<Script *>(vs); 100 s->runForEach(rsc, 101 static_cast<const Allocation *>(vain), static_cast<Allocation *>(vaout), 102 params, paramLen); 103 104 } 105 106 void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot) { 107 Script *s = static_cast<Script *>(vs); 108 s->Invoke(rsc, slot, NULL, 0); 109 } 110 111 112 void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data) { 113 Script *s = static_cast<Script *>(vs); 114 s->Invoke(rsc, slot, NULL, 0); 115 } 116 117 void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) { 118 Script *s = static_cast<Script *>(vs); 119 s->Invoke(rsc, slot, data, len); 120 } 121 122 void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value) { 123 Script *s = static_cast<Script *>(vs); 124 s->setVar(slot, &value, sizeof(value)); 125 } 126 127 void rsi_ScriptSetVarObj(Context *rsc, RsScript vs, uint32_t slot, RsObjectBase value) { 128 Script *s = static_cast<Script *>(vs); 129 ObjectBase *o = static_cast<ObjectBase *>(value); 130 s->setVarObj(slot, o); 131 } 132 133 void rsi_ScriptSetVarJ(Context *rsc, RsScript vs, uint32_t slot, long long value) { 134 Script *s = static_cast<Script *>(vs); 135 s->setVar(slot, &value, sizeof(value)); 136 } 137 138 void rsi_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value) { 139 Script *s = static_cast<Script *>(vs); 140 s->setVar(slot, &value, sizeof(value)); 141 } 142 143 void rsi_ScriptSetVarD(Context *rsc, RsScript vs, uint32_t slot, double value) { 144 Script *s = static_cast<Script *>(vs); 145 s->setVar(slot, &value, sizeof(value)); 146 } 147 148 void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) { 149 Script *s = static_cast<Script *>(vs); 150 s->setVar(slot, data, len); 151 } 152 153 } 154 } 155 156