rsScript.cpp revision b81a0eb8180791e4eaab1253b59fa8bd562b046b
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 19using namespace android; 20using namespace android::renderscript; 21 22Script::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 30Script::~Script() { 31 if (mSlots) { 32 delete [] mSlots; 33 mSlots = NULL; 34 } 35 if (mTypes) { 36 delete [] mTypes; 37 mTypes = NULL; 38 } 39} 40 41void 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 56void 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 65void 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 75namespace android { 76namespace renderscript { 77 78void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot) { 79 Script *s = static_cast<Script *>(vs); 80 Allocation *a = static_cast<Allocation *>(va); 81 s->setSlot(slot, a); 82 //LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr()); 83} 84 85void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, size_t length) { 86 Script *s = static_cast<Script *>(vs); 87 s->mEnviroment.mTimeZone = timeZone; 88} 89 90void rsi_ScriptForEach(Context *rsc, RsScript vs, uint32_t slot, 91 RsAllocation vain, RsAllocation vaout, 92 const void *params, size_t paramLen) { 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 100void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot) { 101 Script *s = static_cast<Script *>(vs); 102 s->Invoke(rsc, slot, NULL, 0); 103} 104 105 106void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data) { 107 Script *s = static_cast<Script *>(vs); 108 s->Invoke(rsc, slot, NULL, 0); 109} 110 111void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) { 112 Script *s = static_cast<Script *>(vs); 113 s->Invoke(rsc, slot, data, len); 114} 115 116void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value) { 117 Script *s = static_cast<Script *>(vs); 118 s->setVar(slot, &value, sizeof(value)); 119} 120 121void 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 127void rsi_ScriptSetVarJ(Context *rsc, RsScript vs, uint32_t slot, long long value) { 128 Script *s = static_cast<Script *>(vs); 129 s->setVar(slot, &value, sizeof(value)); 130} 131 132void rsi_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value) { 133 Script *s = static_cast<Script *>(vs); 134 s->setVar(slot, &value, sizeof(value)); 135} 136 137void rsi_ScriptSetVarD(Context *rsc, RsScript vs, uint32_t slot, double value) { 138 Script *s = static_cast<Script *>(vs); 139 s->setVar(slot, &value, sizeof(value)); 140} 141 142void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) { 143 Script *s = static_cast<Script *>(vs); 144 s->setVar(slot, data, len); 145} 146 147} 148} 149 150