2009-05-22 14:03:28 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "rsContext.h"
|
|
|
|
|
|
|
|
using namespace android;
|
|
|
|
using namespace android::renderscript;
|
|
|
|
|
2010-11-09 17:00:54 -08:00
|
|
|
Script::Script(Context *rsc) : ObjectBase(rsc) {
|
2009-06-08 18:50:13 -07:00
|
|
|
memset(&mEnviroment, 0, sizeof(mEnviroment));
|
2011-03-16 16:29:28 -07:00
|
|
|
memset(&mHal, 0, sizeof(mHal));
|
2010-10-08 15:00:05 -07:00
|
|
|
|
|
|
|
mSlots = NULL;
|
|
|
|
mTypes = NULL;
|
2009-05-22 14:03:28 -07:00
|
|
|
}
|
|
|
|
|
2010-11-09 17:00:54 -08:00
|
|
|
Script::~Script() {
|
|
|
|
if (mSlots) {
|
2010-10-08 15:00:05 -07:00
|
|
|
delete [] mSlots;
|
|
|
|
mSlots = NULL;
|
|
|
|
}
|
2010-11-09 17:00:54 -08:00
|
|
|
if (mTypes) {
|
2010-10-08 15:00:05 -07:00
|
|
|
delete [] mTypes;
|
|
|
|
mTypes = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Script::setSlot(uint32_t slot, Allocation *a) {
|
2011-03-16 16:29:28 -07:00
|
|
|
//LOGE("setSlot %i %p", slot, a);
|
|
|
|
if (slot >= mHal.info.exportedVariableCount) {
|
2010-10-08 15:00:05 -07:00
|
|
|
LOGE("Script::setSlot unable to set allocation, invalid slot index");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mSlots[slot].set(a);
|
2011-03-16 16:29:28 -07:00
|
|
|
if (a != NULL) {
|
|
|
|
mRSC->mHal.funcs.script.setGlobalBind(mRSC, this, slot, a->getPtr());
|
|
|
|
} else {
|
|
|
|
mRSC->mHal.funcs.script.setGlobalBind(mRSC, this, slot, NULL);
|
|
|
|
}
|
2009-05-22 14:03:28 -07:00
|
|
|
}
|
|
|
|
|
2011-06-03 10:18:01 -07:00
|
|
|
void Script::setVar(uint32_t slot, const void *val, size_t len) {
|
2011-03-16 16:29:28 -07:00
|
|
|
//LOGE("setVar %i %p %i", slot, val, len);
|
|
|
|
if (slot >= mHal.info.exportedVariableCount) {
|
|
|
|
LOGE("Script::setVar unable to set allocation, invalid slot index");
|
|
|
|
return;
|
2010-05-11 14:03:58 -07:00
|
|
|
}
|
2011-03-16 16:29:28 -07:00
|
|
|
mRSC->mHal.funcs.script.setGlobalVar(mRSC, this, slot, (void *)val, len);
|
2010-05-11 14:03:58 -07:00
|
|
|
}
|
|
|
|
|
2010-11-16 17:37:02 -08:00
|
|
|
void Script::setVarObj(uint32_t slot, ObjectBase *val) {
|
2011-03-16 16:29:28 -07:00
|
|
|
//LOGE("setVarObj %i %p", slot, val);
|
|
|
|
if (slot >= mHal.info.exportedVariableCount) {
|
|
|
|
LOGE("Script::setVarObj unable to set allocation, invalid slot index");
|
|
|
|
return;
|
2010-11-16 17:37:02 -08:00
|
|
|
}
|
2011-03-16 16:29:28 -07:00
|
|
|
//LOGE("setvarobj %i %p", slot, val);
|
|
|
|
mRSC->mHal.funcs.script.setGlobalObj(mRSC, this, slot, val);
|
2010-11-16 17:37:02 -08:00
|
|
|
}
|
|
|
|
|
2011-08-31 17:41:39 -07:00
|
|
|
bool Script::freeChildren() {
|
|
|
|
incSysRef();
|
|
|
|
mRSC->mHal.funcs.script.invokeFreeChildren(mRSC, this);
|
|
|
|
return decSysRef();
|
|
|
|
}
|
|
|
|
|
2009-05-22 14:03:28 -07:00
|
|
|
namespace android {
|
|
|
|
namespace renderscript {
|
|
|
|
|
2010-11-09 17:00:54 -08:00
|
|
|
void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot) {
|
2009-05-22 14:03:28 -07:00
|
|
|
Script *s = static_cast<Script *>(vs);
|
2010-05-11 14:03:58 -07:00
|
|
|
Allocation *a = static_cast<Allocation *>(va);
|
2010-10-08 15:00:05 -07:00
|
|
|
s->setSlot(slot, a);
|
2010-05-11 14:03:58 -07:00
|
|
|
//LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr());
|
2009-05-22 14:03:28 -07:00
|
|
|
}
|
|
|
|
|
2011-06-03 10:18:01 -07:00
|
|
|
void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, size_t length) {
|
2009-08-04 16:58:20 -07:00
|
|
|
Script *s = static_cast<Script *>(vs);
|
|
|
|
s->mEnviroment.mTimeZone = timeZone;
|
|
|
|
}
|
|
|
|
|
2011-04-27 15:12:49 -07:00
|
|
|
void rsi_ScriptForEach(Context *rsc, RsScript vs, uint32_t slot,
|
|
|
|
RsAllocation vain, RsAllocation vaout,
|
2011-06-03 10:18:01 -07:00
|
|
|
const void *params, size_t paramLen) {
|
2011-04-27 15:12:49 -07:00
|
|
|
Script *s = static_cast<Script *>(vs);
|
|
|
|
s->runForEach(rsc,
|
|
|
|
static_cast<const Allocation *>(vain), static_cast<Allocation *>(vaout),
|
|
|
|
params, paramLen);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-11-09 17:00:54 -08:00
|
|
|
void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot) {
|
2009-09-16 15:04:38 -07:00
|
|
|
Script *s = static_cast<Script *>(vs);
|
2010-05-19 17:22:57 -07:00
|
|
|
s->Invoke(rsc, slot, NULL, 0);
|
2009-09-16 15:04:38 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-09 17:00:54 -08:00
|
|
|
void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data) {
|
2010-05-11 14:03:58 -07:00
|
|
|
Script *s = static_cast<Script *>(vs);
|
2010-05-19 17:22:57 -07:00
|
|
|
s->Invoke(rsc, slot, NULL, 0);
|
2010-05-11 14:03:58 -07:00
|
|
|
}
|
|
|
|
|
2011-06-03 10:18:01 -07:00
|
|
|
void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) {
|
2010-05-11 14:03:58 -07:00
|
|
|
Script *s = static_cast<Script *>(vs);
|
2010-05-19 17:22:57 -07:00
|
|
|
s->Invoke(rsc, slot, data, len);
|
2010-05-11 14:03:58 -07:00
|
|
|
}
|
|
|
|
|
2010-11-09 17:00:54 -08:00
|
|
|
void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value) {
|
2010-05-11 14:03:58 -07:00
|
|
|
Script *s = static_cast<Script *>(vs);
|
|
|
|
s->setVar(slot, &value, sizeof(value));
|
|
|
|
}
|
|
|
|
|
2010-11-16 17:37:02 -08:00
|
|
|
void rsi_ScriptSetVarObj(Context *rsc, RsScript vs, uint32_t slot, RsObjectBase value) {
|
|
|
|
Script *s = static_cast<Script *>(vs);
|
|
|
|
ObjectBase *o = static_cast<ObjectBase *>(value);
|
|
|
|
s->setVarObj(slot, o);
|
|
|
|
}
|
|
|
|
|
2010-11-09 17:00:54 -08:00
|
|
|
void rsi_ScriptSetVarJ(Context *rsc, RsScript vs, uint32_t slot, long long value) {
|
2010-10-11 10:54:21 -07:00
|
|
|
Script *s = static_cast<Script *>(vs);
|
|
|
|
s->setVar(slot, &value, sizeof(value));
|
|
|
|
}
|
|
|
|
|
2010-11-09 17:00:54 -08:00
|
|
|
void rsi_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value) {
|
2010-05-11 14:03:58 -07:00
|
|
|
Script *s = static_cast<Script *>(vs);
|
|
|
|
s->setVar(slot, &value, sizeof(value));
|
|
|
|
}
|
|
|
|
|
2010-11-09 17:00:54 -08:00
|
|
|
void rsi_ScriptSetVarD(Context *rsc, RsScript vs, uint32_t slot, double value) {
|
2010-09-20 17:20:30 -07:00
|
|
|
Script *s = static_cast<Script *>(vs);
|
|
|
|
s->setVar(slot, &value, sizeof(value));
|
|
|
|
}
|
|
|
|
|
2011-06-03 10:18:01 -07:00
|
|
|
void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) {
|
2010-05-11 14:03:58 -07:00
|
|
|
Script *s = static_cast<Script *>(vs);
|
|
|
|
s->setVar(slot, data, len);
|
2009-08-13 12:59:04 -07:00
|
|
|
}
|
|
|
|
|
2009-05-22 14:03:28 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|