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
17 #include <malloc.h>
18
19 #include "RenderScript.h"
20 #include "rsCppInternal.h"
21
22 using namespace android;
23 using namespace RSC;
24
invoke(uint32_t slot,const void * v,size_t len) const25 void Script::invoke(uint32_t slot, const void *v, size_t len) const {
26 tryDispatch(mRS, RS::dispatch->ScriptInvokeV(mRS->getContext(), getID(), slot, v, len));
27 }
28
forEach(uint32_t slot,sp<const Allocation> ain,sp<const Allocation> aout,const void * usr,size_t usrLen) const29 void Script::forEach(uint32_t slot, sp<const Allocation> ain, sp<const Allocation> aout,
30 const void *usr, size_t usrLen) const {
31 if ((ain == nullptr) && (aout == nullptr)) {
32 mRS->throwError(RS_ERROR_INVALID_PARAMETER, "At least one of ain or aout is required to be non-null.");
33 }
34 void *in_id = BaseObj::getObjID(ain);
35 void *out_id = BaseObj::getObjID(aout);
36 tryDispatch(mRS, RS::dispatch->ScriptForEach(mRS->getContext(), getID(), slot, in_id, out_id, usr, usrLen, nullptr, 0));
37 }
38
Script(void * id,sp<RS> rs)39 Script::Script(void *id, sp<RS> rs) : BaseObj(id, rs) {
40 }
41
42
bindAllocation(sp<Allocation> va,uint32_t slot) const43 void Script::bindAllocation(sp<Allocation> va, uint32_t slot) const {
44 tryDispatch(mRS, RS::dispatch->ScriptBindAllocation(mRS->getContext(), getID(), BaseObj::getObjID(va), slot));
45 }
46
47
setVar(uint32_t index,sp<const BaseObj> o) const48 void Script::setVar(uint32_t index, sp<const BaseObj> o) const {
49 tryDispatch(mRS, RS::dispatch->ScriptSetVarObj(mRS->getContext(), getID(), index, (o == nullptr) ? 0 : o->getID()));
50 }
51
setVar(uint32_t index,const void * v,size_t len) const52 void Script::setVar(uint32_t index, const void *v, size_t len) const {
53 tryDispatch(mRS, RS::dispatch->ScriptSetVarV(mRS->getContext(), getID(), index, v, len));
54 }
55
init(sp<RS> rs,uint32_t dimx,uint32_t usages)56 void Script::FieldBase::init(sp<RS> rs, uint32_t dimx, uint32_t usages) {
57 mAllocation = Allocation::createSized(rs, mElement, dimx, RS_ALLOCATION_USAGE_SCRIPT | usages);
58 }
59