Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 19 | using namespace android; |
| 20 | using namespace android::renderscript; |
| 21 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 22 | Script::Script(Context *rsc) : ObjectBase(rsc) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 23 | { |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame^] | 24 | mAllocFile = __FILE__; |
| 25 | mAllocLine = __LINE__; |
Jason Sams | 928f5cf | 2009-06-08 18:50:13 -0700 | [diff] [blame] | 26 | memset(&mEnviroment, 0, sizeof(mEnviroment)); |
| 27 | mEnviroment.mClearColor[0] = 0; |
| 28 | mEnviroment.mClearColor[1] = 0; |
| 29 | mEnviroment.mClearColor[2] = 0; |
| 30 | mEnviroment.mClearColor[3] = 1; |
| 31 | mEnviroment.mClearDepth = 1; |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 32 | mEnviroment.mClearStencil = 0; |
| 33 | mEnviroment.mIsRoot = false; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | Script::~Script() |
| 37 | { |
| 38 | } |
| 39 | |
| 40 | namespace android { |
| 41 | namespace renderscript { |
| 42 | |
| 43 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 44 | void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot) |
| 45 | { |
| 46 | Script *s = static_cast<Script *>(vs); |
| 47 | s->mSlots[slot].set(static_cast<Allocation *>(va)); |
| 48 | } |
| 49 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 50 | void rsi_ScriptSetClearColor(Context * rsc, RsScript vs, float r, float g, float b, float a) |
| 51 | { |
| 52 | Script *s = static_cast<Script *>(vs); |
| 53 | s->mEnviroment.mClearColor[0] = r; |
| 54 | s->mEnviroment.mClearColor[1] = g; |
| 55 | s->mEnviroment.mClearColor[2] = b; |
| 56 | s->mEnviroment.mClearColor[3] = a; |
| 57 | } |
| 58 | |
| 59 | void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, uint32_t length) |
| 60 | { |
| 61 | Script *s = static_cast<Script *>(vs); |
| 62 | s->mEnviroment.mTimeZone = timeZone; |
| 63 | } |
| 64 | |
| 65 | void rsi_ScriptSetClearDepth(Context * rsc, RsScript vs, float v) |
| 66 | { |
| 67 | Script *s = static_cast<Script *>(vs); |
| 68 | s->mEnviroment.mClearDepth = v; |
| 69 | } |
| 70 | |
| 71 | void rsi_ScriptSetClearStencil(Context * rsc, RsScript vs, uint32_t v) |
| 72 | { |
| 73 | Script *s = static_cast<Script *>(vs); |
| 74 | s->mEnviroment.mClearStencil = v; |
| 75 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 76 | |
Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 77 | void rsi_ScriptSetType(Context * rsc, RsType vt, uint32_t slot, bool writable, const char *name) |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 78 | { |
| 79 | ScriptCState *ss = &rsc->mScriptC; |
| 80 | const Type *t = static_cast<const Type *>(vt); |
| 81 | ss->mConstantBufferTypes[slot].set(t); |
Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 82 | ss->mSlotWritable[slot] = writable; |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 83 | if (name) { |
| 84 | ss->mSlotNames[slot].setTo(name); |
| 85 | } else { |
| 86 | ss->mSlotNames[slot].setTo(""); |
| 87 | } |
| 88 | } |
| 89 | |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 90 | void rsi_ScriptSetInvoke(Context *rsc, const char *name, uint32_t slot) |
| 91 | { |
| 92 | ScriptCState *ss = &rsc->mScriptC; |
| 93 | ss->mInvokableNames[slot] = name; |
| 94 | } |
| 95 | |
| 96 | void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot) |
| 97 | { |
| 98 | Script *s = static_cast<Script *>(vs); |
Jason Sams | e60446b | 2009-09-24 14:55:38 -0700 | [diff] [blame] | 99 | s->setupScript(); |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 100 | s->mEnviroment.mInvokables[slot](); |
| 101 | } |
| 102 | |
| 103 | |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 104 | void rsi_ScriptSetRoot(Context * rsc, bool isRoot) |
| 105 | { |
| 106 | ScriptCState *ss = &rsc->mScriptC; |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 107 | ss->mScript->mEnviroment.mIsRoot = isRoot; |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | |