blob: b84014fa31d47ada96b15667451ab57da2ecc32a [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
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
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080022Script::Script(Context *rsc) : ObjectBase(rsc) {
Jason Sams928b7342009-06-08 18:50:13 -070023 memset(&mEnviroment, 0, sizeof(mEnviroment));
Jason Samsbad80742011-03-16 16:29:28 -070024 memset(&mHal, 0, sizeof(mHal));
Alex Sakhartchouk700ba382010-10-08 15:00:05 -070025
26 mSlots = NULL;
27 mTypes = NULL;
Jason Sams326e0dd2009-05-22 14:03:28 -070028}
29
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080030Script::~Script() {
31 if (mSlots) {
Alex Sakhartchouk700ba382010-10-08 15:00:05 -070032 delete [] mSlots;
33 mSlots = NULL;
34 }
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080035 if (mTypes) {
Alex Sakhartchouk700ba382010-10-08 15:00:05 -070036 delete [] mTypes;
37 mTypes = NULL;
38 }
39}
40
Alex Sakhartchouk700ba382010-10-08 15:00:05 -070041void Script::setSlot(uint32_t slot, Allocation *a) {
Jason Samsbad80742011-03-16 16:29:28 -070042 //LOGE("setSlot %i %p", slot, a);
43 if (slot >= mHal.info.exportedVariableCount) {
Alex Sakhartchouk700ba382010-10-08 15:00:05 -070044 LOGE("Script::setSlot unable to set allocation, invalid slot index");
45 return;
46 }
47
48 mSlots[slot].set(a);
Jason Samsbad80742011-03-16 16:29:28 -070049 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 Sams326e0dd2009-05-22 14:03:28 -070054}
55
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080056void Script::setVar(uint32_t slot, const void *val, uint32_t len) {
Jason Samsbad80742011-03-16 16:29:28 -070057 //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 Samsbe36bf32010-05-11 14:03:58 -070061 }
Jason Samsbad80742011-03-16 16:29:28 -070062 mRSC->mHal.funcs.script.setGlobalVar(mRSC, this, slot, (void *)val, len);
Jason Samsbe36bf32010-05-11 14:03:58 -070063}
64
Jason Samsa5eb6e12010-11-16 17:37:02 -080065void Script::setVarObj(uint32_t slot, ObjectBase *val) {
Jason Samsbad80742011-03-16 16:29:28 -070066 //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 Samsa5eb6e12010-11-16 17:37:02 -080070 }
Jason Samsbad80742011-03-16 16:29:28 -070071 //LOGE("setvarobj %i %p", slot, val);
72 mRSC->mHal.funcs.script.setGlobalObj(mRSC, this, slot, val);
Jason Samsa5eb6e12010-11-16 17:37:02 -080073}
74
Jason Sams326e0dd2009-05-22 14:03:28 -070075namespace android {
76namespace renderscript {
77
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080078void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot) {
Jason Sams326e0dd2009-05-22 14:03:28 -070079 Script *s = static_cast<Script *>(vs);
Jason Samsbe36bf32010-05-11 14:03:58 -070080 Allocation *a = static_cast<Allocation *>(va);
Alex Sakhartchouk700ba382010-10-08 15:00:05 -070081 s->setSlot(slot, a);
Jason Samsbe36bf32010-05-11 14:03:58 -070082 //LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr());
Jason Sams326e0dd2009-05-22 14:03:28 -070083}
84
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080085void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, uint32_t length) {
Jason Samsd34b7252009-08-04 16:58:20 -070086 Script *s = static_cast<Script *>(vs);
87 s->mEnviroment.mTimeZone = timeZone;
88}
89
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080090void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot) {
Jason Sams8c6bc692009-09-16 15:04:38 -070091 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -070092 s->Invoke(rsc, slot, NULL, 0);
Jason Sams8c6bc692009-09-16 15:04:38 -070093}
94
95
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080096void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data) {
Jason Samsbe36bf32010-05-11 14:03:58 -070097 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -070098 s->Invoke(rsc, slot, NULL, 0);
Jason Samsbe36bf32010-05-11 14:03:58 -070099}
100
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800101void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700102 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -0700103 s->Invoke(rsc, slot, data, len);
Jason Samsbe36bf32010-05-11 14:03:58 -0700104}
105
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800106void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700107 Script *s = static_cast<Script *>(vs);
108 s->setVar(slot, &value, sizeof(value));
109}
110
Jason Samsa5eb6e12010-11-16 17:37:02 -0800111void rsi_ScriptSetVarObj(Context *rsc, RsScript vs, uint32_t slot, RsObjectBase value) {
112 Script *s = static_cast<Script *>(vs);
113 ObjectBase *o = static_cast<ObjectBase *>(value);
114 s->setVarObj(slot, o);
115}
116
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800117void rsi_ScriptSetVarJ(Context *rsc, RsScript vs, uint32_t slot, long long value) {
Stephen Hines0977c942010-10-11 10:54:21 -0700118 Script *s = static_cast<Script *>(vs);
119 s->setVar(slot, &value, sizeof(value));
120}
121
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800122void rsi_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700123 Script *s = static_cast<Script *>(vs);
124 s->setVar(slot, &value, sizeof(value));
125}
126
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800127void rsi_ScriptSetVarD(Context *rsc, RsScript vs, uint32_t slot, double value) {
Stephen Hines6d0a0742010-09-20 17:20:30 -0700128 Script *s = static_cast<Script *>(vs);
129 s->setVar(slot, &value, sizeof(value));
130}
131
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800132void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700133 Script *s = static_cast<Script *>(vs);
134 s->setVar(slot, data, len);
Jason Samsfa517192009-08-13 12:59:04 -0700135}
136
Jason Sams326e0dd2009-05-22 14:03:28 -0700137}
138}
139