2009-08-03 18:11:17 -07:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2008 The Android Open Source Project
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package android.renderscript;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @hide
|
|
|
|
**/
|
|
|
|
public class Script extends BaseObj {
|
2009-08-13 12:59:04 -07:00
|
|
|
public static final int MAX_SLOT = 16;
|
|
|
|
|
2009-08-03 18:11:17 -07:00
|
|
|
boolean mIsRoot;
|
2009-08-12 17:54:11 -07:00
|
|
|
Type[] mTypes;
|
2009-08-17 13:56:09 -07:00
|
|
|
boolean[] mWritable;
|
2009-09-16 15:04:38 -07:00
|
|
|
Invokable[] mInvokables;
|
|
|
|
|
|
|
|
public static class Invokable {
|
|
|
|
RenderScript mRS;
|
|
|
|
Script mScript;
|
|
|
|
int mSlot;
|
|
|
|
String mName;
|
|
|
|
|
|
|
|
Invokable() {
|
|
|
|
mSlot = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void execute() {
|
|
|
|
mRS.nScriptInvoke(mScript.mID, mSlot);
|
|
|
|
}
|
|
|
|
}
|
2009-08-03 18:11:17 -07:00
|
|
|
|
2010-03-26 16:06:43 -07:00
|
|
|
protected void invoke(int slot) {
|
|
|
|
mRS.nScriptInvoke(mID, slot);
|
|
|
|
}
|
|
|
|
|
2010-06-15 12:15:57 -07:00
|
|
|
protected void invoke(int slot, FieldPacker v) {
|
|
|
|
if (v != null) {
|
|
|
|
mRS.nScriptInvokeV(mID, slot, v.getData());
|
|
|
|
} else {
|
|
|
|
mRS.nScriptInvoke(mID, slot);
|
|
|
|
}
|
2010-05-11 14:03:58 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-03 18:11:17 -07:00
|
|
|
Script(int id, RenderScript rs) {
|
2010-08-11 14:41:28 -07:00
|
|
|
super(id, rs);
|
2009-08-03 18:11:17 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
public void bindAllocation(Allocation va, int slot) {
|
2009-12-07 12:40:12 -08:00
|
|
|
mRS.validate();
|
2010-05-11 14:03:58 -07:00
|
|
|
if (va != null) {
|
|
|
|
mRS.nScriptBindAllocation(mID, va.mID, slot);
|
|
|
|
} else {
|
|
|
|
mRS.nScriptBindAllocation(mID, 0, slot);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setVar(int index, float v) {
|
|
|
|
mRS.nScriptSetVarF(mID, index, v);
|
|
|
|
}
|
|
|
|
|
2010-09-20 17:20:30 -07:00
|
|
|
public void setVar(int index, double v) {
|
|
|
|
mRS.nScriptSetVarD(mID, index, v);
|
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
public void setVar(int index, int v) {
|
|
|
|
mRS.nScriptSetVarI(mID, index, v);
|
|
|
|
}
|
|
|
|
|
2010-07-02 15:35:19 -07:00
|
|
|
public void setVar(int index, boolean v) {
|
|
|
|
mRS.nScriptSetVarI(mID, index, v ? 1 : 0);
|
|
|
|
}
|
|
|
|
|
2010-05-11 14:03:58 -07:00
|
|
|
public void setVar(int index, FieldPacker v) {
|
|
|
|
mRS.nScriptSetVarV(mID, index, v.getData());
|
2009-08-03 18:11:17 -07:00
|
|
|
}
|
|
|
|
|
2009-08-04 16:58:20 -07:00
|
|
|
public void setTimeZone(String timeZone) {
|
2009-12-07 12:40:12 -08:00
|
|
|
mRS.validate();
|
2009-08-04 16:58:20 -07:00
|
|
|
try {
|
|
|
|
mRS.nScriptSetTimeZone(mID, timeZone.getBytes("UTF-8"));
|
|
|
|
} catch (java.io.UnsupportedEncodingException e) {
|
|
|
|
throw new RuntimeException(e);
|
|
|
|
}
|
|
|
|
}
|
2009-08-03 18:11:17 -07:00
|
|
|
|
|
|
|
public static class Builder {
|
|
|
|
RenderScript mRS;
|
|
|
|
|
|
|
|
Builder(RenderScript rs) {
|
|
|
|
mRS = rs;
|
2009-08-13 12:59:04 -07:00
|
|
|
}
|
2009-08-03 18:11:17 -07:00
|
|
|
}
|
|
|
|
|
2010-03-26 16:06:43 -07:00
|
|
|
|
|
|
|
public static class FieldBase {
|
|
|
|
protected Element mElement;
|
|
|
|
protected Type mType;
|
|
|
|
protected Allocation mAllocation;
|
|
|
|
|
|
|
|
protected void init(RenderScript rs, int dimx) {
|
|
|
|
mAllocation = Allocation.createSized(rs, mElement, dimx);
|
|
|
|
mType = mAllocation.getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected FieldBase() {
|
|
|
|
}
|
|
|
|
|
|
|
|
public Element getElement() {
|
|
|
|
return mElement;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Type getType() {
|
|
|
|
return mType;
|
|
|
|
}
|
|
|
|
|
|
|
|
public Allocation getAllocation() {
|
|
|
|
return mAllocation;
|
|
|
|
}
|
|
|
|
|
|
|
|
//@Override
|
|
|
|
public void updateAllocation() {
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
/*
|
|
|
|
public class ScriptField_UserField
|
|
|
|
extends android.renderscript.Script.FieldBase {
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
2009-08-03 18:11:17 -07:00
|
|
|
}
|
|
|
|
|