blob: f9526fe0bfdf0c723537efa0a2dc66560513cc4c [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));
25 mEnviroment.mClearColor[0] = 0;
26 mEnviroment.mClearColor[1] = 0;
27 mEnviroment.mClearColor[2] = 0;
28 mEnviroment.mClearColor[3] = 1;
29 mEnviroment.mClearDepth = 1;
Jason Sams8c6bc692009-09-16 15:04:38 -070030 mEnviroment.mClearStencil = 0;
31 mEnviroment.mIsRoot = false;
Jason Sams326e0dd2009-05-22 14:03:28 -070032}
33
34Script::~Script()
35{
36}
37
38namespace android {
39namespace renderscript {
40
41
Jason Sams326e0dd2009-05-22 14:03:28 -070042void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot)
43{
44 Script *s = static_cast<Script *>(vs);
45 s->mSlots[slot].set(static_cast<Allocation *>(va));
46}
47
Jason Samsd34b7252009-08-04 16:58:20 -070048void rsi_ScriptSetClearColor(Context * rsc, RsScript vs, float r, float g, float b, float a)
49{
50 Script *s = static_cast<Script *>(vs);
51 s->mEnviroment.mClearColor[0] = r;
52 s->mEnviroment.mClearColor[1] = g;
53 s->mEnviroment.mClearColor[2] = b;
54 s->mEnviroment.mClearColor[3] = a;
55}
56
57void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, uint32_t length)
58{
59 Script *s = static_cast<Script *>(vs);
60 s->mEnviroment.mTimeZone = timeZone;
61}
62
63void rsi_ScriptSetClearDepth(Context * rsc, RsScript vs, float v)
64{
65 Script *s = static_cast<Script *>(vs);
66 s->mEnviroment.mClearDepth = v;
67}
68
69void rsi_ScriptSetClearStencil(Context * rsc, RsScript vs, uint32_t v)
70{
71 Script *s = static_cast<Script *>(vs);
72 s->mEnviroment.mClearStencil = v;
73}
Jason Sams326e0dd2009-05-22 14:03:28 -070074
Jason Sams90b36a82009-08-17 13:56:09 -070075void rsi_ScriptSetType(Context * rsc, RsType vt, uint32_t slot, bool writable, const char *name)
Jason Samsfa517192009-08-13 12:59:04 -070076{
77 ScriptCState *ss = &rsc->mScriptC;
78 const Type *t = static_cast<const Type *>(vt);
79 ss->mConstantBufferTypes[slot].set(t);
Jason Sams90b36a82009-08-17 13:56:09 -070080 ss->mSlotWritable[slot] = writable;
Jason Samsfa517192009-08-13 12:59:04 -070081 if (name) {
82 ss->mSlotNames[slot].setTo(name);
83 } else {
84 ss->mSlotNames[slot].setTo("");
85 }
86}
87
Jason Sams8c6bc692009-09-16 15:04:38 -070088void rsi_ScriptSetInvoke(Context *rsc, const char *name, uint32_t slot)
89{
90 ScriptCState *ss = &rsc->mScriptC;
91 ss->mInvokableNames[slot] = name;
92}
93
94void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot)
95{
96 Script *s = static_cast<Script *>(vs);
Jason Samsada7f272009-09-24 14:55:38 -070097 s->setupScript();
Jason Sams8c6bc692009-09-16 15:04:38 -070098 s->mEnviroment.mInvokables[slot]();
99}
100
101
Jason Samsfa517192009-08-13 12:59:04 -0700102void rsi_ScriptSetRoot(Context * rsc, bool isRoot)
103{
104 ScriptCState *ss = &rsc->mScriptC;
Jason Sams8c6bc692009-09-16 15:04:38 -0700105 ss->mScript->mEnviroment.mIsRoot = isRoot;
Jason Samsfa517192009-08-13 12:59:04 -0700106}
107
108
Jason Sams326e0dd2009-05-22 14:03:28 -0700109}
110}
111