blob: 4ffdbfdcf60b68fd655c3eaecb8a94c83e6c5e18 [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));
Alex Sakhartchouk6f91cb62010-10-08 15:00:05 -070024
25 mSlots = NULL;
26 mTypes = NULL;
Jason Samsd19f10d2009-05-22 14:03:28 -070027}
28
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080029Script::~Script() {
30 if (mSlots) {
Alex Sakhartchouk6f91cb62010-10-08 15:00:05 -070031 delete [] mSlots;
32 mSlots = NULL;
33 }
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080034 if (mTypes) {
Alex Sakhartchouk6f91cb62010-10-08 15:00:05 -070035 delete [] mTypes;
36 mTypes = NULL;
37 }
38}
39
40void Script::initSlots() {
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080041 if (mEnviroment.mFieldCount > 0) {
Alex Sakhartchouk6f91cb62010-10-08 15:00:05 -070042 mSlots = new ObjectBaseRef<Allocation>[mEnviroment.mFieldCount];
43 mTypes = new ObjectBaseRef<const Type>[mEnviroment.mFieldCount];
44 }
45}
46
47void Script::setSlot(uint32_t slot, Allocation *a) {
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080048 if (slot >= mEnviroment.mFieldCount) {
Alex Sakhartchouk6f91cb62010-10-08 15:00:05 -070049 LOGE("Script::setSlot unable to set allocation, invalid slot index");
50 return;
51 }
52
53 mSlots[slot].set(a);
Jason Samsd19f10d2009-05-22 14:03:28 -070054}
55
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080056void Script::setVar(uint32_t slot, const void *val, uint32_t len) {
Jason Sams4d339932010-05-11 14:03:58 -070057 int32_t *destPtr = ((int32_t **)mEnviroment.mFieldAddress)[slot];
58 if (destPtr) {
59 //LOGE("setVar f1 %f", ((const float *)destPtr)[0]);
60 //LOGE("setVar %p %i", destPtr, len);
61 memcpy(destPtr, val, len);
62 //LOGE("setVar f2 %f", ((const float *)destPtr)[0]);
63 } else {
Jason Sams2222aa92010-10-10 17:58:25 -070064 //if (rsc->props.mLogScripts) {
65 LOGV("Calling setVar on slot = %i which is null", slot);
66 //}
Jason Sams4d339932010-05-11 14:03:58 -070067 }
68}
69
Jason Samsd19f10d2009-05-22 14:03:28 -070070namespace android {
71namespace renderscript {
72
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080073void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot) {
Jason Samsd19f10d2009-05-22 14:03:28 -070074 Script *s = static_cast<Script *>(vs);
Jason Sams4d339932010-05-11 14:03:58 -070075 Allocation *a = static_cast<Allocation *>(va);
Alex Sakhartchouk6f91cb62010-10-08 15:00:05 -070076 s->setSlot(slot, a);
Jason Sams4d339932010-05-11 14:03:58 -070077 //LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr());
Jason Samsd19f10d2009-05-22 14:03:28 -070078}
79
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080080void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, uint32_t length) {
Jason Sams22534172009-08-04 16:58:20 -070081 Script *s = static_cast<Script *>(vs);
82 s->mEnviroment.mTimeZone = timeZone;
83}
84
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080085void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot) {
Jason Samsbe2e8412009-09-16 15:04:38 -070086 Script *s = static_cast<Script *>(vs);
Jason Samsd79b2e92010-05-19 17:22:57 -070087 s->Invoke(rsc, slot, NULL, 0);
Jason Samsbe2e8412009-09-16 15:04:38 -070088}
89
90
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080091void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data) {
Jason Sams4d339932010-05-11 14:03:58 -070092 Script *s = static_cast<Script *>(vs);
Jason Samsd79b2e92010-05-19 17:22:57 -070093 s->Invoke(rsc, slot, NULL, 0);
Jason Sams4d339932010-05-11 14:03:58 -070094}
95
Alex Sakhartchouked9f2102010-11-09 17:00:54 -080096void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) {
Jason Sams4d339932010-05-11 14:03:58 -070097 Script *s = static_cast<Script *>(vs);
Jason Samsd79b2e92010-05-19 17:22:57 -070098 s->Invoke(rsc, slot, data, len);
Jason Sams4d339932010-05-11 14:03:58 -070099}
100
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800101void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value) {
Jason Sams4d339932010-05-11 14:03:58 -0700102 Script *s = static_cast<Script *>(vs);
103 s->setVar(slot, &value, sizeof(value));
104}
105
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800106void rsi_ScriptSetVarJ(Context *rsc, RsScript vs, uint32_t slot, long long value) {
Stephen Hines031ec58c2010-10-11 10:54:21 -0700107 Script *s = static_cast<Script *>(vs);
108 s->setVar(slot, &value, sizeof(value));
109}
110
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800111void rsi_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value) {
Jason Sams4d339932010-05-11 14:03:58 -0700112 Script *s = static_cast<Script *>(vs);
113 s->setVar(slot, &value, sizeof(value));
114}
115
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800116void rsi_ScriptSetVarD(Context *rsc, RsScript vs, uint32_t slot, double value) {
Stephen Hinesca54ec32010-09-20 17:20:30 -0700117 Script *s = static_cast<Script *>(vs);
118 s->setVar(slot, &value, sizeof(value));
119}
120
Alex Sakhartchouked9f2102010-11-09 17:00:54 -0800121void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) {
Jason Sams4d339932010-05-11 14:03:58 -0700122 const float *fp = (const float *)data;
123 Script *s = static_cast<Script *>(vs);
124 s->setVar(slot, data, len);
Jason Samsfbf0b9e2009-08-13 12:59:04 -0700125}
126
Jason Samsd19f10d2009-05-22 14:03:28 -0700127}
128}
129