1*e1eccf28SAndroid Build Coastguard Worker /*
2*e1eccf28SAndroid Build Coastguard Worker * Copyright (C) 2008-2012 The Android Open Source Project
3*e1eccf28SAndroid Build Coastguard Worker *
4*e1eccf28SAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License");
5*e1eccf28SAndroid Build Coastguard Worker * you may not use this file except in compliance with the License.
6*e1eccf28SAndroid Build Coastguard Worker * You may obtain a copy of the License at
7*e1eccf28SAndroid Build Coastguard Worker *
8*e1eccf28SAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0
9*e1eccf28SAndroid Build Coastguard Worker *
10*e1eccf28SAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software
11*e1eccf28SAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS,
12*e1eccf28SAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*e1eccf28SAndroid Build Coastguard Worker * See the License for the specific language governing permissions and
14*e1eccf28SAndroid Build Coastguard Worker * limitations under the License.
15*e1eccf28SAndroid Build Coastguard Worker */
16*e1eccf28SAndroid Build Coastguard Worker
17*e1eccf28SAndroid Build Coastguard Worker #include <malloc.h>
18*e1eccf28SAndroid Build Coastguard Worker
19*e1eccf28SAndroid Build Coastguard Worker #include "RenderScript.h"
20*e1eccf28SAndroid Build Coastguard Worker #include "rsCppInternal.h"
21*e1eccf28SAndroid Build Coastguard Worker
22*e1eccf28SAndroid Build Coastguard Worker using android::RSC::Script;
23*e1eccf28SAndroid Build Coastguard Worker
invoke(uint32_t slot,const void * v,size_t len) const24*e1eccf28SAndroid Build Coastguard Worker void Script::invoke(uint32_t slot, const void *v, size_t len) const {
25*e1eccf28SAndroid Build Coastguard Worker tryDispatch(mRS, RS::dispatch->ScriptInvokeV(mRS->getContext(), getID(), slot, v, len));
26*e1eccf28SAndroid Build Coastguard Worker }
27*e1eccf28SAndroid Build Coastguard Worker
forEach(uint32_t slot,const sp<const Allocation> & ain,const sp<const Allocation> & aout,const void * usr,size_t usrLen) const28*e1eccf28SAndroid Build Coastguard Worker void Script::forEach(uint32_t slot, const sp<const Allocation>& ain, const sp<const Allocation>& aout,
29*e1eccf28SAndroid Build Coastguard Worker const void *usr, size_t usrLen) const {
30*e1eccf28SAndroid Build Coastguard Worker if ((ain == nullptr) && (aout == nullptr)) {
31*e1eccf28SAndroid Build Coastguard Worker mRS->throwError(RS_ERROR_INVALID_PARAMETER, "At least one of ain or aout is required to be non-null.");
32*e1eccf28SAndroid Build Coastguard Worker }
33*e1eccf28SAndroid Build Coastguard Worker void *in_id = BaseObj::getObjID(ain);
34*e1eccf28SAndroid Build Coastguard Worker void *out_id = BaseObj::getObjID(aout);
35*e1eccf28SAndroid Build Coastguard Worker tryDispatch(mRS, RS::dispatch->ScriptForEach(mRS->getContext(), getID(), slot, in_id, out_id, usr, usrLen, nullptr, 0));
36*e1eccf28SAndroid Build Coastguard Worker }
37*e1eccf28SAndroid Build Coastguard Worker
Script(void * id,sp<RS> rs)38*e1eccf28SAndroid Build Coastguard Worker Script::Script(void *id, sp<RS> rs) : BaseObj(id, rs) {
39*e1eccf28SAndroid Build Coastguard Worker }
40*e1eccf28SAndroid Build Coastguard Worker
41*e1eccf28SAndroid Build Coastguard Worker
bindAllocation(const sp<Allocation> & va,uint32_t slot) const42*e1eccf28SAndroid Build Coastguard Worker void Script::bindAllocation(const sp<Allocation>& va, uint32_t slot) const {
43*e1eccf28SAndroid Build Coastguard Worker tryDispatch(mRS, RS::dispatch->ScriptBindAllocation(mRS->getContext(), getID(), BaseObj::getObjID(va), slot));
44*e1eccf28SAndroid Build Coastguard Worker }
45*e1eccf28SAndroid Build Coastguard Worker
46*e1eccf28SAndroid Build Coastguard Worker
setVar(uint32_t index,const sp<const BaseObj> & o) const47*e1eccf28SAndroid Build Coastguard Worker void Script::setVar(uint32_t index, const sp<const BaseObj>& o) const {
48*e1eccf28SAndroid Build Coastguard Worker tryDispatch(mRS, RS::dispatch->ScriptSetVarObj(mRS->getContext(), getID(), index, (o == nullptr) ? 0 : o->getID()));
49*e1eccf28SAndroid Build Coastguard Worker }
50*e1eccf28SAndroid Build Coastguard Worker
setVar(uint32_t index,const void * v,size_t len) const51*e1eccf28SAndroid Build Coastguard Worker void Script::setVar(uint32_t index, const void *v, size_t len) const {
52*e1eccf28SAndroid Build Coastguard Worker tryDispatch(mRS, RS::dispatch->ScriptSetVarV(mRS->getContext(), getID(), index, v, len));
53*e1eccf28SAndroid Build Coastguard Worker }
54*e1eccf28SAndroid Build Coastguard Worker
init(const sp<RS> & rs,uint32_t dimx,uint32_t usages)55*e1eccf28SAndroid Build Coastguard Worker void Script::FieldBase::init(const sp<RS>& rs, uint32_t dimx, uint32_t usages) {
56*e1eccf28SAndroid Build Coastguard Worker mAllocation = Allocation::createSized(rs, mElement, dimx, RS_ALLOCATION_USAGE_SCRIPT | usages);
57*e1eccf28SAndroid Build Coastguard Worker }
58