blob: fc22fc3f39f71dbeddee8c0c47b0f7e68f39fe02 [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 Samsf2649a92009-09-25 16:37:33 -070024 mAllocFile = __FILE__;
25 mAllocLine = __LINE__;
Jason Sams928b7342009-06-08 18:50:13 -070026 memset(&mEnviroment, 0, sizeof(mEnviroment));
Jason Sams326e0dd2009-05-22 14:03:28 -070027}
28
29Script::~Script()
30{
31}
32
Jason Samsbe36bf32010-05-11 14:03:58 -070033void Script::setVar(uint32_t slot, const void *val, uint32_t len)
34{
35 int32_t *destPtr = ((int32_t **)mEnviroment.mFieldAddress)[slot];
36 if (destPtr) {
37 //LOGE("setVar f1 %f", ((const float *)destPtr)[0]);
38 //LOGE("setVar %p %i", destPtr, len);
39 memcpy(destPtr, val, len);
40 //LOGE("setVar f2 %f", ((const float *)destPtr)[0]);
41 } else {
42 LOGE("Calling setVar on slot = %i which is null", slot);
43 }
44}
45
Jason Sams326e0dd2009-05-22 14:03:28 -070046namespace android {
47namespace renderscript {
48
49
Jason Sams326e0dd2009-05-22 14:03:28 -070050void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot)
51{
52 Script *s = static_cast<Script *>(vs);
Jason Samsbe36bf32010-05-11 14:03:58 -070053 Allocation *a = static_cast<Allocation *>(va);
54 s->mSlots[slot].set(a);
55 //LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr());
Jason Sams326e0dd2009-05-22 14:03:28 -070056}
57
Jason Samsd34b7252009-08-04 16:58:20 -070058void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, uint32_t length)
59{
60 Script *s = static_cast<Script *>(vs);
61 s->mEnviroment.mTimeZone = timeZone;
62}
63
Jason Sams90b36a82009-08-17 13:56:09 -070064void rsi_ScriptSetType(Context * rsc, RsType vt, uint32_t slot, bool writable, const char *name)
Jason Samsfa517192009-08-13 12:59:04 -070065{
66 ScriptCState *ss = &rsc->mScriptC;
67 const Type *t = static_cast<const Type *>(vt);
68 ss->mConstantBufferTypes[slot].set(t);
Jason Sams90b36a82009-08-17 13:56:09 -070069 ss->mSlotWritable[slot] = writable;
Jason Samsbe36bf32010-05-11 14:03:58 -070070 LOGE("rsi_ScriptSetType");
Jason Samsfa517192009-08-13 12:59:04 -070071}
72
Jason Sams8c6bc692009-09-16 15:04:38 -070073void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot)
74{
75 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -070076 s->Invoke(rsc, slot, NULL, 0);
Jason Sams8c6bc692009-09-16 15:04:38 -070077}
78
79
Jason Samsbe36bf32010-05-11 14:03:58 -070080void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data)
81{
Jason Samsbe36bf32010-05-11 14:03:58 -070082 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -070083 s->Invoke(rsc, slot, NULL, 0);
Jason Samsbe36bf32010-05-11 14:03:58 -070084}
85
86void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len)
87{
Jason Samsbe36bf32010-05-11 14:03:58 -070088 Script *s = static_cast<Script *>(vs);
Jason Sams22fa3712010-05-19 17:22:57 -070089 s->Invoke(rsc, slot, data, len);
Jason Samsbe36bf32010-05-11 14:03:58 -070090}
91
Jason Samsbe36bf32010-05-11 14:03:58 -070092void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value)
93{
94 Script *s = static_cast<Script *>(vs);
95 s->setVar(slot, &value, sizeof(value));
96}
97
98void rsi_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value)
99{
100 Script *s = static_cast<Script *>(vs);
101 s->setVar(slot, &value, sizeof(value));
102}
103
104void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len)
105{
106 const float *fp = (const float *)data;
107 Script *s = static_cast<Script *>(vs);
108 s->setVar(slot, data, len);
Jason Samsfa517192009-08-13 12:59:04 -0700109}
110
111
Jason Sams326e0dd2009-05-22 14:03:28 -0700112}
113}
114