blob: f62c72edfe212e794c1c358b99446dbd5740e443 [file] [log] [blame]
Jason Samsd19f10d2009-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 Sakhartchouked9f2102010-11-09 17:00:54 -080022Script::Script(Context *rsc) : ObjectBase(rsc) {
Jason Sams928f5cf2009-06-08 18:50:13 -070023 memset(&mEnviroment, 0, sizeof(mEnviroment));
Jason Samse4a06c52011-03-16 16:29:28 -070024 memset(&mHal, 0, sizeof(mHal));
Alex Sakhartchouk6f91cb62010-10-08 15:00:05 -070025
26 mSlots = NULL;
27 mTypes = NULL;
Jason Samsd19f10d2009-05-22 14:03:28 -070028}
29
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080030Script::~Script() {
31 if (mSlots) {
Alex Sakhartchouk6f91cb62010-10-08 15:00:05 -070032 delete [] mSlots;
33 mSlots = NULL;
34 }
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080035 if (mTypes) {
Alex Sakhartchouk6f91cb62010-10-08 15:00:05 -070036 delete [] mTypes;
37 mTypes = NULL;
38 }
39}
40
Alex Sakhartchouk6f91cb62010-10-08 15:00:05 -070041void Script::setSlot(uint32_t slot, Allocation *a) {
Jason Samse4a06c52011-03-16 16:29:28 -070042 //LOGE("setSlot %i %p", slot, a);
43 if (slot >= mHal.info.exportedVariableCount) {
Alex Sakhartchouk6f91cb62010-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 Samse4a06c52011-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 Samsd19f10d2009-05-22 14:03:28 -070054}
55
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -070056void Script::setVar(uint32_t slot, const void *val, size_t len) {
Jason Samse4a06c52011-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 Sams4d339932010-05-11 14:03:58 -070061 }
Jason Samse4a06c52011-03-16 16:29:28 -070062 mRSC->mHal.funcs.script.setGlobalVar(mRSC, this, slot, (void *)val, len);
Jason Sams4d339932010-05-11 14:03:58 -070063}
64
Jason Sams6f4cf0b2010-11-16 17:37:02 -080065void Script::setVarObj(uint32_t slot, ObjectBase *val) {
Jason Samse4a06c52011-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 Sams6f4cf0b2010-11-16 17:37:02 -080070 }
Jason Samse4a06c52011-03-16 16:29:28 -070071 //LOGE("setvarobj %i %p", slot, val);
72 mRSC->mHal.funcs.script.setGlobalObj(mRSC, this, slot, val);
Jason Sams6f4cf0b2010-11-16 17:37:02 -080073}
74
Jason Samsd19f10d2009-05-22 14:03:28 -070075namespace android {
76namespace renderscript {
77
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080078void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot) {
Jason Samsd19f10d2009-05-22 14:03:28 -070079 Script *s = static_cast<Script *>(vs);
Jason Sams4d339932010-05-11 14:03:58 -070080 Allocation *a = static_cast<Allocation *>(va);
Alex Sakhartchouk6f91cb62010-10-08 15:00:05 -070081 s->setSlot(slot, a);
Jason Sams4d339932010-05-11 14:03:58 -070082 //LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr());
Jason Samsd19f10d2009-05-22 14:03:28 -070083}
84
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -070085void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, size_t length) {
Jason Sams22534172009-08-04 16:58:20 -070086 Script *s = static_cast<Script *>(vs);
87 s->mEnviroment.mTimeZone = timeZone;
88}
89
Jason Samsa08526a2011-04-27 15:12:49 -070090void rsi_ScriptForEach(Context *rsc, RsScript vs, uint32_t slot,
91 RsAllocation vain, RsAllocation vaout,
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -070092 const void *params, size_t paramLen) {
Jason Samsa08526a2011-04-27 15:12:49 -070093 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
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800100void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot) {
Jason Samsbe2e8412009-09-16 15:04:38 -0700101 Script *s = static_cast<Script *>(vs);
Jason Samsd79b2e92010-05-19 17:22:57 -0700102 s->Invoke(rsc, slot, NULL, 0);
Jason Samsbe2e8412009-09-16 15:04:38 -0700103}
104
105
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800106void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data) {
Jason Sams4d339932010-05-11 14:03:58 -0700107 Script *s = static_cast<Script *>(vs);
Jason Samsd79b2e92010-05-19 17:22:57 -0700108 s->Invoke(rsc, slot, NULL, 0);
Jason Sams4d339932010-05-11 14:03:58 -0700109}
110
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -0700111void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) {
Jason Sams4d339932010-05-11 14:03:58 -0700112 Script *s = static_cast<Script *>(vs);
Jason Samsd79b2e92010-05-19 17:22:57 -0700113 s->Invoke(rsc, slot, data, len);
Jason Sams4d339932010-05-11 14:03:58 -0700114}
115
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800116void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value) {
Jason Sams4d339932010-05-11 14:03:58 -0700117 Script *s = static_cast<Script *>(vs);
118 s->setVar(slot, &value, sizeof(value));
119}
120
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800121void 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
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800127void rsi_ScriptSetVarJ(Context *rsc, RsScript vs, uint32_t slot, long long value) {
Stephen Hines031ec58c2010-10-11 10:54:21 -0700128 Script *s = static_cast<Script *>(vs);
129 s->setVar(slot, &value, sizeof(value));
130}
131
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800132void rsi_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value) {
Jason Sams4d339932010-05-11 14:03:58 -0700133 Script *s = static_cast<Script *>(vs);
134 s->setVar(slot, &value, sizeof(value));
135}
136
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800137void rsi_ScriptSetVarD(Context *rsc, RsScript vs, uint32_t slot, double value) {
Stephen Hinesca54ec32010-09-20 17:20:30 -0700138 Script *s = static_cast<Script *>(vs);
139 s->setVar(slot, &value, sizeof(value));
140}
141
Alex Sakhartchouk17a8a192011-06-03 10:18:01 -0700142void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) {
Jason Sams4d339932010-05-11 14:03:58 -0700143 Script *s = static_cast<Script *>(vs);
144 s->setVar(slot, data, len);
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700145}
146
Jason Samsd19f10d2009-05-22 14:03:28 -0700147}
148}
149