blob: f62c72edfe212e794c1c358b99446dbd5740e443 [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 Sakhartchoukb81a0eb2011-06-03 10:18:01 -070056void Script::setVar(uint32_t slot, const void *val, size_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 Sakhartchoukb81a0eb2011-06-03 10:18:01 -070085void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, size_t length) {
Jason Samsd34b7252009-08-04 16:58:20 -070086 Script *s = static_cast<Script *>(vs);
87 s->mEnviroment.mTimeZone = timeZone;
88}
89
Jason Sams5fb1aeb2011-04-27 15:12:49 -070090void rsi_ScriptForEach(Context *rsc, RsScript vs, uint32_t slot,
91 RsAllocation vain, RsAllocation vaout,
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -070092 const void *params, size_t paramLen) {
Jason Sams5fb1aeb2011-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 Sakhartchoukafb743a2010-11-09 17:00:54 -0800100void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot) {
Jason Sams8c6bc692009-09-16 15:04:38 -0700101 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -0700102 s->Invoke(rsc, slot, NULL, 0);
Jason Sams8c6bc692009-09-16 15:04:38 -0700103}
104
105
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800106void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700107 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -0700108 s->Invoke(rsc, slot, NULL, 0);
Jason Samsbe36bf32010-05-11 14:03:58 -0700109}
110
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700111void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700112 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -0700113 s->Invoke(rsc, slot, data, len);
Jason Samsbe36bf32010-05-11 14:03:58 -0700114}
115
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800116void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700117 Script *s = static_cast<Script *>(vs);
118 s->setVar(slot, &value, sizeof(value));
119}
120
Jason Samsa5eb6e12010-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 Sakhartchoukafb743a2010-11-09 17:00:54 -0800127void rsi_ScriptSetVarJ(Context *rsc, RsScript vs, uint32_t slot, long long value) {
Stephen Hines0977c942010-10-11 10:54:21 -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_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700133 Script *s = static_cast<Script *>(vs);
134 s->setVar(slot, &value, sizeof(value));
135}
136
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800137void rsi_ScriptSetVarD(Context *rsc, RsScript vs, uint32_t slot, double value) {
Stephen Hines6d0a0742010-09-20 17:20:30 -0700138 Script *s = static_cast<Script *>(vs);
139 s->setVar(slot, &value, sizeof(value));
140}
141
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700142void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700143 Script *s = static_cast<Script *>(vs);
144 s->setVar(slot, data, len);
Jason Samsfa517192009-08-13 12:59:04 -0700145}
146
Jason Sams326e0dd2009-05-22 14:03:28 -0700147}
148}
149