blob: 93513fe3e6a53aac276e68061fe93e87c12c3782 [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
Stephen Hines4ee16ff2011-08-31 17:41:39 -070075bool Script::freeChildren() {
76 incSysRef();
77 mRSC->mHal.funcs.script.invokeFreeChildren(mRSC, this);
78 return decSysRef();
79}
80
Jason Sams326e0dd2009-05-22 14:03:28 -070081namespace android {
82namespace renderscript {
83
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080084void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot) {
Jason Sams326e0dd2009-05-22 14:03:28 -070085 Script *s = static_cast<Script *>(vs);
Jason Samsbe36bf32010-05-11 14:03:58 -070086 Allocation *a = static_cast<Allocation *>(va);
Alex Sakhartchouk700ba382010-10-08 15:00:05 -070087 s->setSlot(slot, a);
Jason Samsbe36bf32010-05-11 14:03:58 -070088 //LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr());
Jason Sams326e0dd2009-05-22 14:03:28 -070089}
90
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -070091void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, size_t length) {
Jason Samsd34b7252009-08-04 16:58:20 -070092 Script *s = static_cast<Script *>(vs);
93 s->mEnviroment.mTimeZone = timeZone;
94}
95
Jason Sams5fb1aeb2011-04-27 15:12:49 -070096void rsi_ScriptForEach(Context *rsc, RsScript vs, uint32_t slot,
97 RsAllocation vain, RsAllocation vaout,
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -070098 const void *params, size_t paramLen) {
Jason Sams5fb1aeb2011-04-27 15:12:49 -070099 Script *s = static_cast<Script *>(vs);
100 s->runForEach(rsc,
101 static_cast<const Allocation *>(vain), static_cast<Allocation *>(vaout),
102 params, paramLen);
103
104}
105
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800106void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot) {
Jason Sams8c6bc692009-09-16 15:04:38 -0700107 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -0700108 s->Invoke(rsc, slot, NULL, 0);
Jason Sams8c6bc692009-09-16 15:04:38 -0700109}
110
111
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800112void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700113 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -0700114 s->Invoke(rsc, slot, NULL, 0);
Jason Samsbe36bf32010-05-11 14:03:58 -0700115}
116
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700117void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700118 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -0700119 s->Invoke(rsc, slot, data, len);
Jason Samsbe36bf32010-05-11 14:03:58 -0700120}
121
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800122void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700123 Script *s = static_cast<Script *>(vs);
124 s->setVar(slot, &value, sizeof(value));
125}
126
Jason Samsa5eb6e12010-11-16 17:37:02 -0800127void rsi_ScriptSetVarObj(Context *rsc, RsScript vs, uint32_t slot, RsObjectBase value) {
128 Script *s = static_cast<Script *>(vs);
129 ObjectBase *o = static_cast<ObjectBase *>(value);
130 s->setVarObj(slot, o);
131}
132
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800133void rsi_ScriptSetVarJ(Context *rsc, RsScript vs, uint32_t slot, long long value) {
Stephen Hines0977c942010-10-11 10:54:21 -0700134 Script *s = static_cast<Script *>(vs);
135 s->setVar(slot, &value, sizeof(value));
136}
137
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800138void rsi_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700139 Script *s = static_cast<Script *>(vs);
140 s->setVar(slot, &value, sizeof(value));
141}
142
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800143void rsi_ScriptSetVarD(Context *rsc, RsScript vs, uint32_t slot, double value) {
Stephen Hines6d0a0742010-09-20 17:20:30 -0700144 Script *s = static_cast<Script *>(vs);
145 s->setVar(slot, &value, sizeof(value));
146}
147
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700148void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, size_t len) {
Jason Samsbe36bf32010-05-11 14:03:58 -0700149 Script *s = static_cast<Script *>(vs);
150 s->setVar(slot, data, len);
Jason Samsfa517192009-08-13 12:59:04 -0700151}
152
Jason Sams326e0dd2009-05-22 14:03:28 -0700153}
154}
155