Script.cpp revision b206acefa7ef03e02d3e8e161f8a1493329246b3
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 <utils/Log.h>
18#include <malloc.h>
19
20#include "RenderScript.h"
21#include <rs.h>
22
23using namespace android;
24using namespace RSC;
25
26void Script::invoke(uint32_t slot, const void *v, size_t len) const {
27    rsScriptInvokeV(mRS->getContext(), getID(), slot, v, len);
28}
29
30void Script::forEach(uint32_t slot, sp<const Allocation> ain, sp<const Allocation> aout,
31                       const void *usr, size_t usrLen) const {
32    if ((ain == NULL) && (aout == NULL)) {
33        mRS->throwError("At least one of ain or aout is required to be non-null.");
34    }
35    void *in_id = BaseObj::getObjID(ain);
36    void *out_id = BaseObj::getObjID(aout);
37    rsScriptForEach(mRS->getContext(), getID(), slot, in_id, out_id, usr, usrLen, NULL, 0);
38}
39
40
41Script::Script(void *id, sp<RS> rs) : BaseObj(id, rs) {
42}
43
44
45void Script::bindAllocation(sp<Allocation> va, uint32_t slot) const {
46    rsScriptBindAllocation(mRS->getContext(), getID(), BaseObj::getObjID(va), slot);
47}
48
49
50void Script::setVar(uint32_t index, sp<const BaseObj> o) const {
51    rsScriptSetVarObj(mRS->getContext(), getID(), index, (o == NULL) ? 0 : o->getID());
52}
53
54void Script::setVar(uint32_t index, const void *v, size_t len) const {
55    rsScriptSetVarV(mRS->getContext(), getID(), index, v, len);
56}
57
58void Script::FieldBase::init(sp<RS> rs, uint32_t dimx, uint32_t usages) {
59    mAllocation = Allocation::createSized(rs, mElement, dimx, RS_ALLOCATION_USAGE_SCRIPT | usages);
60}
61
62