blob: 53a33e4ca74aea346562455f96b03357486ae9a7 [file] [log] [blame]
Jason Sams69f0d312009-08-03 18:11:17 -07001/*
2 * Copyright (C) 2008 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
17package android.renderscript;
18
19/**
20 * @hide
21 **/
22public class Script extends BaseObj {
Jason Samsfbf0b9e2009-08-13 12:59:04 -070023 public static final int MAX_SLOT = 16;
24
Jason Sams69f0d312009-08-03 18:11:17 -070025 boolean mIsRoot;
Jason Sams43ee06852009-08-12 17:54:11 -070026 Type[] mTypes;
Jason Sams334ea0c2009-08-17 13:56:09 -070027 boolean[] mWritable;
Jason Samsbe2e8412009-09-16 15:04:38 -070028 Invokable[] mInvokables;
29
30 public static class Invokable {
31 RenderScript mRS;
32 Script mScript;
33 int mSlot;
34 String mName;
35
36 Invokable() {
37 mSlot = -1;
38 }
39
40 public void execute() {
41 mRS.nScriptInvoke(mScript.mID, mSlot);
42 }
43 }
Jason Sams69f0d312009-08-03 18:11:17 -070044
Jason Sams2d71bc72010-03-26 16:06:43 -070045 protected void invoke(int slot) {
46 mRS.nScriptInvoke(mID, slot);
47 }
48
Jason Sams96ed4cf2010-06-15 12:15:57 -070049 protected void invoke(int slot, FieldPacker v) {
50 if (v != null) {
51 mRS.nScriptInvokeV(mID, slot, v.getData());
52 } else {
53 mRS.nScriptInvoke(mID, slot);
54 }
Jason Sams4d339932010-05-11 14:03:58 -070055 }
56
57
Jason Sams69f0d312009-08-03 18:11:17 -070058 Script(int id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -070059 super(id, rs);
Jason Sams69f0d312009-08-03 18:11:17 -070060 }
61
Jason Sams69f0d312009-08-03 18:11:17 -070062 public void bindAllocation(Allocation va, int slot) {
Jason Sams771bebb2009-12-07 12:40:12 -080063 mRS.validate();
Jason Sams4d339932010-05-11 14:03:58 -070064 if (va != null) {
65 mRS.nScriptBindAllocation(mID, va.mID, slot);
66 } else {
67 mRS.nScriptBindAllocation(mID, 0, slot);
68 }
69 }
70
71 public void setVar(int index, float v) {
72 mRS.nScriptSetVarF(mID, index, v);
73 }
74
Stephen Hinesca54ec32010-09-20 17:20:30 -070075 public void setVar(int index, double v) {
76 mRS.nScriptSetVarD(mID, index, v);
77 }
78
Jason Sams4d339932010-05-11 14:03:58 -070079 public void setVar(int index, int v) {
80 mRS.nScriptSetVarI(mID, index, v);
81 }
82
Stephen Hines031ec58c2010-10-11 10:54:21 -070083 public void setVar(int index, long v) {
84 mRS.nScriptSetVarJ(mID, index, v);
85 }
86
Jason Sams0b9a22c2010-07-02 15:35:19 -070087 public void setVar(int index, boolean v) {
88 mRS.nScriptSetVarI(mID, index, v ? 1 : 0);
89 }
90
Jason Sams4d339932010-05-11 14:03:58 -070091 public void setVar(int index, FieldPacker v) {
92 mRS.nScriptSetVarV(mID, index, v.getData());
Jason Sams69f0d312009-08-03 18:11:17 -070093 }
94
Jason Sams22534172009-08-04 16:58:20 -070095 public void setTimeZone(String timeZone) {
Jason Sams771bebb2009-12-07 12:40:12 -080096 mRS.validate();
Jason Sams22534172009-08-04 16:58:20 -070097 try {
98 mRS.nScriptSetTimeZone(mID, timeZone.getBytes("UTF-8"));
99 } catch (java.io.UnsupportedEncodingException e) {
100 throw new RuntimeException(e);
101 }
102 }
Jason Sams69f0d312009-08-03 18:11:17 -0700103
104 public static class Builder {
105 RenderScript mRS;
Jason Sams69f0d312009-08-03 18:11:17 -0700106
107 Builder(RenderScript rs) {
108 mRS = rs;
109 }
Jason Sams69f0d312009-08-03 18:11:17 -0700110 }
111
Jason Sams2d71bc72010-03-26 16:06:43 -0700112
113 public static class FieldBase {
114 protected Element mElement;
115 protected Type mType;
116 protected Allocation mAllocation;
117
118 protected void init(RenderScript rs, int dimx) {
119 mAllocation = Allocation.createSized(rs, mElement, dimx);
120 mType = mAllocation.getType();
121 }
122
123 protected FieldBase() {
124 }
125
126 public Element getElement() {
127 return mElement;
128 }
129
130 public Type getType() {
131 return mType;
132 }
133
134 public Allocation getAllocation() {
135 return mAllocation;
136 }
137
138 //@Override
139 public void updateAllocation() {
140 }
141
142
143 //
144 /*
145 public class ScriptField_UserField
146 extends android.renderscript.Script.FieldBase {
147
148 protected
149
150 }
151
152 */
153
154 }
Jason Sams69f0d312009-08-03 18:11:17 -0700155}
156