blob: 0e76daef1c2751f952ca0eacee263015c3ff8deb [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
Jason Samsa9e7a052009-09-25 14:51:22 -070022Script::Script(Context *rsc) : ObjectBase(rsc)
Jason Samsd19f10d2009-05-22 14:03:28 -070023{
Jason Sams61f08d62009-09-25 16:37:33 -070024 mAllocFile = __FILE__;
25 mAllocLine = __LINE__;
Jason Sams928f5cf2009-06-08 18:50:13 -070026 memset(&mEnviroment, 0, sizeof(mEnviroment));
Alex Sakhartchouk6f91cb62010-10-08 15:00:05 -070027
28 mSlots = NULL;
29 mTypes = NULL;
Jason Samsd19f10d2009-05-22 14:03:28 -070030}
31
32Script::~Script()
33{
Alex Sakhartchouk6f91cb62010-10-08 15:00:05 -070034 if(mSlots) {
35 delete [] mSlots;
36 mSlots = NULL;
37 }
38 if(mTypes) {
39 delete [] mTypes;
40 mTypes = NULL;
41 }
42}
43
44void Script::initSlots() {
45 if(mEnviroment.mFieldCount > 0) {
46 mSlots = new ObjectBaseRef<Allocation>[mEnviroment.mFieldCount];
47 mTypes = new ObjectBaseRef<const Type>[mEnviroment.mFieldCount];
48 }
49}
50
51void Script::setSlot(uint32_t slot, Allocation *a) {
52 if(slot >= mEnviroment.mFieldCount) {
53 LOGE("Script::setSlot unable to set allocation, invalid slot index");
54 return;
55 }
56
57 mSlots[slot].set(a);
Jason Samsd19f10d2009-05-22 14:03:28 -070058}
59
Jason Sams4d339932010-05-11 14:03:58 -070060void Script::setVar(uint32_t slot, const void *val, uint32_t len)
61{
62 int32_t *destPtr = ((int32_t **)mEnviroment.mFieldAddress)[slot];
63 if (destPtr) {
64 //LOGE("setVar f1 %f", ((const float *)destPtr)[0]);
65 //LOGE("setVar %p %i", destPtr, len);
66 memcpy(destPtr, val, len);
67 //LOGE("setVar f2 %f", ((const float *)destPtr)[0]);
68 } else {
69 LOGE("Calling setVar on slot = %i which is null", slot);
70 }
71}
72
Jason Samsd19f10d2009-05-22 14:03:28 -070073namespace android {
74namespace renderscript {
75
76
Jason Samsd19f10d2009-05-22 14:03:28 -070077void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot)
78{
79 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
Jason Sams22534172009-08-04 16:58:20 -070085void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, uint32_t length)
86{
87 Script *s = static_cast<Script *>(vs);
88 s->mEnviroment.mTimeZone = timeZone;
89}
90
Jason Samsbe2e8412009-09-16 15:04:38 -070091void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot)
92{
93 Script *s = static_cast<Script *>(vs);
Jason Samsd79b2e92010-05-19 17:22:57 -070094 s->Invoke(rsc, slot, NULL, 0);
Jason Samsbe2e8412009-09-16 15:04:38 -070095}
96
97
Jason Sams4d339932010-05-11 14:03:58 -070098void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data)
99{
Jason Sams4d339932010-05-11 14:03:58 -0700100 Script *s = static_cast<Script *>(vs);
Jason Samsd79b2e92010-05-19 17:22:57 -0700101 s->Invoke(rsc, slot, NULL, 0);
Jason Sams4d339932010-05-11 14:03:58 -0700102}
103
104void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len)
105{
Jason Sams4d339932010-05-11 14:03:58 -0700106 Script *s = static_cast<Script *>(vs);
Jason Samsd79b2e92010-05-19 17:22:57 -0700107 s->Invoke(rsc, slot, data, len);
Jason Sams4d339932010-05-11 14:03:58 -0700108}
109
Jason Sams4d339932010-05-11 14:03:58 -0700110void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value)
111{
112 Script *s = static_cast<Script *>(vs);
113 s->setVar(slot, &value, sizeof(value));
114}
115
116void rsi_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value)
117{
118 Script *s = static_cast<Script *>(vs);
119 s->setVar(slot, &value, sizeof(value));
120}
121
Stephen Hinesca54ec32010-09-20 17:20:30 -0700122void rsi_ScriptSetVarD(Context *rsc, RsScript vs, uint32_t slot, double value)
123{
124 Script *s = static_cast<Script *>(vs);
125 s->setVar(slot, &value, sizeof(value));
126}
127
Jason Sams4d339932010-05-11 14:03:58 -0700128void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len)
129{
130 const float *fp = (const float *)data;
131 Script *s = static_cast<Script *>(vs);
132 s->setVar(slot, data, len);
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700133}
134
135
Jason Samsd19f10d2009-05-22 14:03:28 -0700136}
137}
138