rsScript.cpp revision afb743aca56c18beb7ab924e75cb6e070ef3e55a
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 25 mSlots = NULL; 26 mTypes = NULL; 27} 28 29Script::~Script() { 30 if (mSlots) { 31 delete [] mSlots; 32 mSlots = NULL; 33 } 34 if (mTypes) { 35 delete [] mTypes; 36 mTypes = NULL; 37 } 38} 39 40void Script::initSlots() { 41 if (mEnviroment.mFieldCount > 0) { 42 mSlots = new ObjectBaseRef<Allocation>[mEnviroment.mFieldCount]; 43 mTypes = new ObjectBaseRef<const Type>[mEnviroment.mFieldCount]; 44 } 45} 46 47void Script::setSlot(uint32_t slot, Allocation *a) { 48 if (slot >= mEnviroment.mFieldCount) { 49 LOGE("Script::setSlot unable to set allocation, invalid slot index"); 50 return; 51 } 52 53 mSlots[slot].set(a); 54} 55 56void Script::setVar(uint32_t slot, const void *val, uint32_t len) { 57 int32_t *destPtr = ((int32_t **)mEnviroment.mFieldAddress)[slot]; 58 if (destPtr) { 59 //LOGE("setVar f1 %f", ((const float *)destPtr)[0]); 60 //LOGE("setVar %p %i", destPtr, len); 61 memcpy(destPtr, val, len); 62 //LOGE("setVar f2 %f", ((const float *)destPtr)[0]); 63 } else { 64 //if (rsc->props.mLogScripts) { 65 LOGV("Calling setVar on slot = %i which is null", slot); 66 //} 67 } 68} 69 70namespace android { 71namespace renderscript { 72 73void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot) { 74 Script *s = static_cast<Script *>(vs); 75 Allocation *a = static_cast<Allocation *>(va); 76 s->setSlot(slot, a); 77 //LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr()); 78} 79 80void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, uint32_t length) { 81 Script *s = static_cast<Script *>(vs); 82 s->mEnviroment.mTimeZone = timeZone; 83} 84 85void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot) { 86 Script *s = static_cast<Script *>(vs); 87 s->Invoke(rsc, slot, NULL, 0); 88} 89 90 91void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data) { 92 Script *s = static_cast<Script *>(vs); 93 s->Invoke(rsc, slot, NULL, 0); 94} 95 96void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) { 97 Script *s = static_cast<Script *>(vs); 98 s->Invoke(rsc, slot, data, len); 99} 100 101void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value) { 102 Script *s = static_cast<Script *>(vs); 103 s->setVar(slot, &value, sizeof(value)); 104} 105 106void rsi_ScriptSetVarJ(Context *rsc, RsScript vs, uint32_t slot, long long value) { 107 Script *s = static_cast<Script *>(vs); 108 s->setVar(slot, &value, sizeof(value)); 109} 110 111void rsi_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value) { 112 Script *s = static_cast<Script *>(vs); 113 s->setVar(slot, &value, sizeof(value)); 114} 115 116void rsi_ScriptSetVarD(Context *rsc, RsScript vs, uint32_t slot, double value) { 117 Script *s = static_cast<Script *>(vs); 118 s->setVar(slot, &value, sizeof(value)); 119} 120 121void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) { 122 const float *fp = (const float *)data; 123 Script *s = static_cast<Script *>(vs); 124 s->setVar(slot, data, len); 125} 126 127} 128} 129 130