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 | 928f5cf | 2009-06-08 18:50:13 -0700 | [diff] [blame] | 24 | memset(&mEnviroment, 0, sizeof(mEnviroment)); |
Alex Sakhartchouk | 6f91cb6 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 25 | |
| 26 | mSlots = NULL; |
| 27 | mTypes = NULL; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | Script::~Script() |
| 31 | { |
Alex Sakhartchouk | 6f91cb6 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 32 | if(mSlots) { |
| 33 | delete [] mSlots; |
| 34 | mSlots = NULL; |
| 35 | } |
| 36 | if(mTypes) { |
| 37 | delete [] mTypes; |
| 38 | mTypes = NULL; |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | void Script::initSlots() { |
| 43 | if(mEnviroment.mFieldCount > 0) { |
| 44 | mSlots = new ObjectBaseRef<Allocation>[mEnviroment.mFieldCount]; |
| 45 | mTypes = new ObjectBaseRef<const Type>[mEnviroment.mFieldCount]; |
| 46 | } |
| 47 | } |
| 48 | |
| 49 | void Script::setSlot(uint32_t slot, Allocation *a) { |
| 50 | if(slot >= mEnviroment.mFieldCount) { |
| 51 | LOGE("Script::setSlot unable to set allocation, invalid slot index"); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | mSlots[slot].set(a); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 56 | } |
| 57 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 58 | void Script::setVar(uint32_t slot, const void *val, uint32_t len) |
| 59 | { |
| 60 | int32_t *destPtr = ((int32_t **)mEnviroment.mFieldAddress)[slot]; |
| 61 | if (destPtr) { |
| 62 | //LOGE("setVar f1 %f", ((const float *)destPtr)[0]); |
| 63 | //LOGE("setVar %p %i", destPtr, len); |
| 64 | memcpy(destPtr, val, len); |
| 65 | //LOGE("setVar f2 %f", ((const float *)destPtr)[0]); |
| 66 | } else { |
Jason Sams | 2222aa9 | 2010-10-10 17:58:25 -0700 | [diff] [blame] | 67 | //if (rsc->props.mLogScripts) { |
| 68 | LOGV("Calling setVar on slot = %i which is null", slot); |
| 69 | //} |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 73 | namespace android { |
| 74 | namespace renderscript { |
| 75 | |
| 76 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 77 | void rsi_ScriptBindAllocation(Context * rsc, RsScript vs, RsAllocation va, uint32_t slot) |
| 78 | { |
| 79 | Script *s = static_cast<Script *>(vs); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 80 | Allocation *a = static_cast<Allocation *>(va); |
Alex Sakhartchouk | 6f91cb6 | 2010-10-08 15:00:05 -0700 | [diff] [blame] | 81 | s->setSlot(slot, a); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 82 | //LOGE("rsi_ScriptBindAllocation %i %p %p", slot, a, a->getPtr()); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 83 | } |
| 84 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 85 | void rsi_ScriptSetTimeZone(Context * rsc, RsScript vs, const char * timeZone, uint32_t length) |
| 86 | { |
| 87 | Script *s = static_cast<Script *>(vs); |
| 88 | s->mEnviroment.mTimeZone = timeZone; |
| 89 | } |
| 90 | |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 91 | void rsi_ScriptInvoke(Context *rsc, RsScript vs, uint32_t slot) |
| 92 | { |
| 93 | Script *s = static_cast<Script *>(vs); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 94 | s->Invoke(rsc, slot, NULL, 0); |
Jason Sams | be2e841 | 2009-09-16 15:04:38 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 98 | void rsi_ScriptInvokeData(Context *rsc, RsScript vs, uint32_t slot, void *data) |
| 99 | { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 100 | Script *s = static_cast<Script *>(vs); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 101 | s->Invoke(rsc, slot, NULL, 0); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | void rsi_ScriptInvokeV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) |
| 105 | { |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 106 | Script *s = static_cast<Script *>(vs); |
Jason Sams | d79b2e9 | 2010-05-19 17:22:57 -0700 | [diff] [blame] | 107 | s->Invoke(rsc, slot, data, len); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 108 | } |
| 109 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 110 | void rsi_ScriptSetVarI(Context *rsc, RsScript vs, uint32_t slot, int value) |
| 111 | { |
| 112 | Script *s = static_cast<Script *>(vs); |
| 113 | s->setVar(slot, &value, sizeof(value)); |
| 114 | } |
| 115 | |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 116 | void rsi_ScriptSetVarJ(Context *rsc, RsScript vs, uint32_t slot, long long value) |
| 117 | { |
| 118 | Script *s = static_cast<Script *>(vs); |
| 119 | s->setVar(slot, &value, sizeof(value)); |
| 120 | } |
| 121 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 122 | void rsi_ScriptSetVarF(Context *rsc, RsScript vs, uint32_t slot, float value) |
| 123 | { |
| 124 | Script *s = static_cast<Script *>(vs); |
| 125 | s->setVar(slot, &value, sizeof(value)); |
| 126 | } |
| 127 | |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 128 | void rsi_ScriptSetVarD(Context *rsc, RsScript vs, uint32_t slot, double value) |
| 129 | { |
| 130 | Script *s = static_cast<Script *>(vs); |
| 131 | s->setVar(slot, &value, sizeof(value)); |
| 132 | } |
| 133 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 134 | void rsi_ScriptSetVarV(Context *rsc, RsScript vs, uint32_t slot, const void *data, uint32_t len) |
| 135 | { |
| 136 | const float *fp = (const float *)data; |
| 137 | Script *s = static_cast<Script *>(vs); |
| 138 | s->setVar(slot, data, len); |
Jason Sams | fbf0b9e | 2009-08-13 12:59:04 -0700 | [diff] [blame] | 139 | } |
| 140 | |
| 141 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 142 | } |
| 143 | } |
| 144 | |