blob: ee03aafac3ec402dd6a0886cbf358ccc2f8a0ebc [file] [log] [blame]
Jason Samsb2e3dc52012-02-23 17:14:39 -08001/*
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 Samsb2e3dc52012-02-23 17:14:39 -080017#include <utils/Log.h>
18#include <malloc.h>
19
20#include "RenderScript.h"
Tim Murrayb206ace2013-02-13 14:52:20 -080021#include <rs.h>
Jason Samsb2e3dc52012-02-23 17:14:39 -080022
Jason Sams69cccdf2012-04-02 19:11:49 -070023using namespace android;
Tim Murray9eb7f4b2012-11-16 14:02:18 -080024using namespace RSC;
Jason Sams69cccdf2012-04-02 19:11:49 -070025
Jason Sams1fc02012012-03-14 15:36:02 -070026void Script::invoke(uint32_t slot, const void *v, size_t len) const {
Tim Murray84bf2b82012-10-31 16:03:16 -070027 rsScriptInvokeV(mRS->getContext(), getID(), slot, v, len);
Jason Samsb2e3dc52012-02-23 17:14:39 -080028}
29
Jason Sams69cccdf2012-04-02 19:11:49 -070030void Script::forEach(uint32_t slot, sp<const Allocation> ain, sp<const Allocation> aout,
Jason Sams1fc02012012-03-14 15:36:02 -070031 const void *usr, size_t usrLen) const {
Jason Samsb2e3dc52012-02-23 17:14:39 -080032 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);
Tim Murrayd4ecb172013-02-07 12:17:03 -080037 rsScriptForEach(mRS->getContext(), getID(), slot, in_id, out_id, usr, usrLen, NULL, 0);
Jason Samsb2e3dc52012-02-23 17:14:39 -080038}
39
40
Tim Murray84bf2b82012-10-31 16:03:16 -070041Script::Script(void *id, sp<RS> rs) : BaseObj(id, rs) {
Jason Samsb2e3dc52012-02-23 17:14:39 -080042}
43
44
Jason Sams69cccdf2012-04-02 19:11:49 -070045void Script::bindAllocation(sp<Allocation> va, uint32_t slot) const {
Tim Murray84bf2b82012-10-31 16:03:16 -070046 rsScriptBindAllocation(mRS->getContext(), getID(), BaseObj::getObjID(va), slot);
Jason Samsb2e3dc52012-02-23 17:14:39 -080047}
48
49
Jason Sams69cccdf2012-04-02 19:11:49 -070050void Script::setVar(uint32_t index, sp<const BaseObj> o) const {
Tim Murray84bf2b82012-10-31 16:03:16 -070051 rsScriptSetVarObj(mRS->getContext(), getID(), index, (o == NULL) ? 0 : o->getID());
Jason Samsb2e3dc52012-02-23 17:14:39 -080052}
53
Jason Sams1fc02012012-03-14 15:36:02 -070054void Script::setVar(uint32_t index, const void *v, size_t len) const {
Tim Murray84bf2b82012-10-31 16:03:16 -070055 rsScriptSetVarV(mRS->getContext(), getID(), index, v, len);
Jason Samsb2e3dc52012-02-23 17:14:39 -080056}
57
Tim Murray84bf2b82012-10-31 16:03:16 -070058void Script::FieldBase::init(sp<RS> rs, uint32_t dimx, uint32_t usages) {
Jason Samsb2e3dc52012-02-23 17:14:39 -080059 mAllocation = Allocation::createSized(rs, mElement, dimx, RS_ALLOCATION_USAGE_SCRIPT | usages);
60}
61