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