Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008-2012 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 | |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 17 | #include <malloc.h> |
| 18 | |
| 19 | #include "RenderScript.h" |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 20 | #include "rsCppInternal.h" |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 21 | |
Chih-Hung Hsieh | dfcfabf | 2016-11-04 15:55:18 -0700 | [diff] [blame] | 22 | using android::RSC::Script; |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 23 | |
Jason Sams | 1fc0201 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 24 | void Script::invoke(uint32_t slot, const void *v, size_t len) const { |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 25 | tryDispatch(mRS, RS::dispatch->ScriptInvokeV(mRS->getContext(), getID(), slot, v, len)); |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 26 | } |
| 27 | |
Chih-Hung Hsieh | 45768e1 | 2016-08-10 12:32:11 -0700 | [diff] [blame] | 28 | void Script::forEach(uint32_t slot, const sp<const Allocation>& ain, const sp<const Allocation>& aout, |
Jason Sams | 1fc0201 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 29 | const void *usr, size_t usrLen) const { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 30 | if ((ain == nullptr) && (aout == nullptr)) { |
Tim Murray | 21fa7a0 | 2013-08-15 16:25:03 -0700 | [diff] [blame] | 31 | mRS->throwError(RS_ERROR_INVALID_PARAMETER, "At least one of ain or aout is required to be non-null."); |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 32 | } |
| 33 | void *in_id = BaseObj::getObjID(ain); |
| 34 | void *out_id = BaseObj::getObjID(aout); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 35 | tryDispatch(mRS, RS::dispatch->ScriptForEach(mRS->getContext(), getID(), slot, in_id, out_id, usr, usrLen, nullptr, 0)); |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 36 | } |
| 37 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 38 | Script::Script(void *id, sp<RS> rs) : BaseObj(id, rs) { |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 39 | } |
| 40 | |
| 41 | |
Chih-Hung Hsieh | 45768e1 | 2016-08-10 12:32:11 -0700 | [diff] [blame] | 42 | void Script::bindAllocation(const sp<Allocation>& va, uint32_t slot) const { |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 43 | tryDispatch(mRS, RS::dispatch->ScriptBindAllocation(mRS->getContext(), getID(), BaseObj::getObjID(va), slot)); |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | |
Chih-Hung Hsieh | 45768e1 | 2016-08-10 12:32:11 -0700 | [diff] [blame] | 47 | void Script::setVar(uint32_t index, const sp<const BaseObj>& o) const { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 48 | tryDispatch(mRS, RS::dispatch->ScriptSetVarObj(mRS->getContext(), getID(), index, (o == nullptr) ? 0 : o->getID())); |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 49 | } |
| 50 | |
Jason Sams | 1fc0201 | 2012-03-14 15:36:02 -0700 | [diff] [blame] | 51 | void Script::setVar(uint32_t index, const void *v, size_t len) const { |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 52 | tryDispatch(mRS, RS::dispatch->ScriptSetVarV(mRS->getContext(), getID(), index, v, len)); |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 53 | } |
| 54 | |
Chih-Hung Hsieh | 45768e1 | 2016-08-10 12:32:11 -0700 | [diff] [blame] | 55 | void Script::FieldBase::init(const sp<RS>& rs, uint32_t dimx, uint32_t usages) { |
Jason Sams | b2e3dc5 | 2012-02-23 17:14:39 -0800 | [diff] [blame] | 56 | mAllocation = Allocation::createSized(rs, mElement, dimx, RS_ALLOCATION_USAGE_SCRIPT | usages); |
| 57 | } |