blob: ef380d26b9a6b7d0b889f93e4a236cb4b0f66a72 [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
Jason Samse514b452009-09-25 14:51:22 -070022Script::Script(Context *rsc) : ObjectBase(rsc)
Jason Sams326e0dd2009-05-22 14:03:28 -070023{
Jason Sams928b7342009-06-08 18:50:13 -070024 memset(&mEnviroment, 0, sizeof(mEnviroment));
Alex Sakhartchouk700ba382010-10-08 15:00:05 -070025
26 mSlots = NULL;
27 mTypes = NULL;
Jason Sams326e0dd2009-05-22 14:03:28 -070028}
29
30Script::~Script()
31{
Alex Sakhartchouk700ba382010-10-08 15:00:05 -070032 if(mSlots) {
33 delete [] mSlots;
34 mSlots = NULL;
35 }
36 if(mTypes) {
37 delete [] mTypes;
38 mTypes = NULL;
39 }
40}
41
42void Script::initSlots() {
43 if(mEnviroment.mFieldCount > 0) {
44 mSlots = new ObjectBaseRef<Allocation>[mEnviroment.mFieldCount];
45 mTypes = new ObjectBaseRef<const Type>[mEnviroment.mFieldCount];
46 }
47}
48
49void Script::setSlot(uint32_t slot, Allocation *a) {
50 if(slot >= mEnviroment.mFieldCount) {
51 LOGE("Script::setSlot unable to set allocation, invalid slot index");
52 return;
53 }
54
55 mSlots[slot].set(a);
Jason Sams326e0dd2009-05-22 14:03:28 -070056}
57
Jason Samsbe36bf32010-05-11 14:03:58 -070058void Script::setVar(uint32_t slot, const void *val, uint32_t len)
59{
60 int32_t *destPtr = ((int32_t **)mEnviroment.mFieldAddress)[slot];
61 if (destPtr) {
62 //LOGE("setVar f1 %f", ((const float *)destPtr)[0]);
63 //LOGE("setVar %p %i", destPtr, len);
64 memcpy(destPtr, val, len);
65 //LOGE("setVar f2 %f", ((const float *)destPtr)[0]);
66 } else {
Jason Samsd7e54812010-10-10 17:58:25 -070067 //if (rsc->props.mLogScripts) {
68 LOGV("Calling setVar on slot = %i which is null", slot);
69 //}
Jason Samsbe36bf32010-05-11 14:03:58 -070070 }
71}
72
Jason Sams326e0dd2009-05-22 14:03:28 -070073namespace android {
74namespace renderscript {
75
76
Jason Sams326e0dd2009-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 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
Jason Samsd34b7252009-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 Sams8c6bc692009-09-16 15:04:38 -070091void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot)
92{
93 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -070094 s->Invoke(rsc, slot, NULL, 0);
Jason Sams8c6bc692009-09-16 15:04:38 -070095}
96
97
Jason Samsbe36bf32010-05-11 14:03:58 -070098void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data)
99{
Jason Samsbe36bf32010-05-11 14:03:58 -0700100 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -0700101 s->Invoke(rsc, slot, NULL, 0);
Jason Samsbe36bf32010-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 Samsbe36bf32010-05-11 14:03:58 -0700106 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -0700107 s->Invoke(rsc, slot, data, len);
Jason Samsbe36bf32010-05-11 14:03:58 -0700108}
109
Jason Samsbe36bf32010-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
Stephen Hines0977c942010-10-11 10:54:21 -0700116void rsi_ScriptSetVarJ(Context *rsc, RsScript vs, uint32_t slot, long long value)
117{
118 Script *s = static_cast<Script *>(vs);
119 s->setVar(slot, &value, sizeof(value));
120}
121
Jason Samsbe36bf32010-05-11 14:03:58 -0700122void rsi_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value)
123{
124 Script *s = static_cast<Script *>(vs);
125 s->setVar(slot, &value, sizeof(value));
126}
127
Stephen Hines6d0a0742010-09-20 17:20:30 -0700128void rsi_ScriptSetVarD(Context *rsc, RsScript vs, uint32_t slot, double value)
129{
130 Script *s = static_cast<Script *>(vs);
131 s->setVar(slot, &value, sizeof(value));
132}
133
Jason Samsbe36bf32010-05-11 14:03:58 -0700134void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len)
135{
136 const float *fp = (const float *)data;
137 Script *s = static_cast<Script *>(vs);
138 s->setVar(slot, data, len);
Jason Samsfa517192009-08-13 12:59:04 -0700139}
140
141
Jason Sams326e0dd2009-05-22 14:03:28 -0700142}
143}
144