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)); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 27 | } |
| 28 | |
| 29 | Script::~Script() |
| 30 | { |
| 31 | } |
| 32 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 33 | void 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 Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 46 | namespace android { |
| 47 | namespace renderscript { |
| 48 | |
| 49 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 50 | void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot) |
| 51 | { |
| 52 | Script *s = static_cast<Script *>(vs); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 53 | Allocation *a = static_cast<Allocation *>(va); |
| 54 | s->mSlots[slot].set(a); |
| 55 | //LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr()); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 58 | void 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 Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 64 | 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] | 65 | { |
| 66 | ScriptCState *ss = &rsc->mScriptC; |
| 67 | const Type *t = static_cast<const Type *>(vt); |
| 68 | ss->mConstantBufferTypes[slot].set(t); |
Jason Sams | 334ea0c | 2009-08-17 13:56:09 -0700 | [diff] [blame] | 69 | ss->mSlotWritable[slot] = writable; |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 70 | LOGE("rsi_ScriptSetType"); |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 71 | } |
| 72 | |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 73 | void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot) |
| 74 | { |
| 75 | Script *s = static_cast<Script *>(vs); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 76 | s->Invoke(rsc, slot, NULL, 0); |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 80 | void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data) |
| 81 | { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 82 | Script *s = static_cast<Script *>(vs); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 83 | s->Invoke(rsc, slot, NULL, 0); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) |
| 87 | { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 88 | Script *s = static_cast<Script *>(vs); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 89 | s->Invoke(rsc, slot, data, len); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 92 | void 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 | |
| 98 | void 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 | |
| 104 | void 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 Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 112 | } |
| 113 | } |
| 114 | |