blob: bbf5e7e39ec78169006fd8a311b77b516612143f [file] [log] [blame]
Jason Sams69f0d312009-08-03 18:11:17 -07001/*
Stephen Hinesadeb8092012-04-20 14:26:06 -07002 * Copyright (C) 2008-2012 The Android Open Source Project
Jason Sams69f0d312009-08-03 18:11:17 -07003 *
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
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070019/**
Jason Samsa23d4e72011-01-04 18:59:12 -080020 *
Jason Sams69f0d312009-08-03 18:11:17 -070021 **/
22public class Script extends BaseObj {
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070023 /**
Jason Sams67e3d202011-01-09 13:49:01 -080024 * Only intended for use by generated reflected code.
25 *
26 * @param slot
27 */
Jason Sams2d71bc72010-03-26 16:06:43 -070028 protected void invoke(int slot) {
Jason Samse07694b2012-04-03 15:36:36 -070029 mRS.nScriptInvoke(getID(mRS), slot);
Jason Sams2d71bc72010-03-26 16:06:43 -070030 }
31
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070032 /**
Jason Sams67e3d202011-01-09 13:49:01 -080033 * Only intended for use by generated reflected code.
34 *
35 * @param slot
36 * @param v
37 */
Jason Sams96ed4cf2010-06-15 12:15:57 -070038 protected void invoke(int slot, FieldPacker v) {
39 if (v != null) {
Jason Samse07694b2012-04-03 15:36:36 -070040 mRS.nScriptInvokeV(getID(mRS), slot, v.getData());
Jason Sams96ed4cf2010-06-15 12:15:57 -070041 } else {
Jason Samse07694b2012-04-03 15:36:36 -070042 mRS.nScriptInvoke(getID(mRS), slot);
Jason Sams96ed4cf2010-06-15 12:15:57 -070043 }
Jason Sams4d339932010-05-11 14:03:58 -070044 }
45
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070046 /**
Jason Sams6e494d32011-04-27 16:33:11 -070047 * Only intended for use by generated reflected code.
48 *
49 * @param slot
50 * @param ain
51 * @param aout
52 * @param v
53 */
54 protected void forEach(int slot, Allocation ain, Allocation aout, FieldPacker v) {
55 if (ain == null && aout == null) {
56 throw new RSIllegalArgumentException(
57 "At least one of ain or aout is required to be non-null.");
58 }
59 int in_id = 0;
60 if (ain != null) {
Jason Samse07694b2012-04-03 15:36:36 -070061 in_id = ain.getID(mRS);
Jason Sams6e494d32011-04-27 16:33:11 -070062 }
63 int out_id = 0;
64 if (aout != null) {
Jason Samse07694b2012-04-03 15:36:36 -070065 out_id = aout.getID(mRS);
Jason Sams6e494d32011-04-27 16:33:11 -070066 }
67 byte[] params = null;
68 if (v != null) {
69 params = v.getData();
70 }
Jason Samse07694b2012-04-03 15:36:36 -070071 mRS.nScriptForEach(getID(mRS), slot, in_id, out_id, params);
Jason Sams6e494d32011-04-27 16:33:11 -070072 }
73
Jason Sams4d339932010-05-11 14:03:58 -070074
Jason Sams69f0d312009-08-03 18:11:17 -070075 Script(int id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -070076 super(id, rs);
Jason Sams69f0d312009-08-03 18:11:17 -070077 }
78
Jason Sams67e3d202011-01-09 13:49:01 -080079
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070080 /**
Jason Sams67e3d202011-01-09 13:49:01 -080081 * Only intended for use by generated reflected code.
82 *
83 * @param va
84 * @param slot
85 */
Jason Sams69f0d312009-08-03 18:11:17 -070086 public void bindAllocation(Allocation va, int slot) {
Jason Sams771bebb2009-12-07 12:40:12 -080087 mRS.validate();
Jason Sams4d339932010-05-11 14:03:58 -070088 if (va != null) {
Jason Samse07694b2012-04-03 15:36:36 -070089 mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot);
Jason Sams4d339932010-05-11 14:03:58 -070090 } else {
Jason Samse07694b2012-04-03 15:36:36 -070091 mRS.nScriptBindAllocation(getID(mRS), 0, slot);
Jason Sams4d339932010-05-11 14:03:58 -070092 }
93 }
94
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070095 /**
Jason Sams67e3d202011-01-09 13:49:01 -080096 * Only intended for use by generated reflected code.
97 *
98 * @param index
99 * @param v
100 */
Jason Sams4d339932010-05-11 14:03:58 -0700101 public void setVar(int index, float v) {
Jason Samse07694b2012-04-03 15:36:36 -0700102 mRS.nScriptSetVarF(getID(mRS), index, v);
Jason Sams4d339932010-05-11 14:03:58 -0700103 }
104
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700105 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800106 * Only intended for use by generated reflected code.
107 *
108 * @param index
109 * @param v
110 */
Stephen Hinesca54ec32010-09-20 17:20:30 -0700111 public void setVar(int index, double v) {
Jason Samse07694b2012-04-03 15:36:36 -0700112 mRS.nScriptSetVarD(getID(mRS), index, v);
Stephen Hinesca54ec32010-09-20 17:20:30 -0700113 }
114
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700115 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800116 * Only intended for use by generated reflected code.
117 *
118 * @param index
119 * @param v
120 */
Jason Sams4d339932010-05-11 14:03:58 -0700121 public void setVar(int index, int v) {
Jason Samse07694b2012-04-03 15:36:36 -0700122 mRS.nScriptSetVarI(getID(mRS), index, v);
Jason Sams4d339932010-05-11 14:03:58 -0700123 }
124
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700125 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800126 * Only intended for use by generated reflected code.
127 *
128 * @param index
129 * @param v
130 */
Stephen Hines031ec58c2010-10-11 10:54:21 -0700131 public void setVar(int index, long v) {
Jason Samse07694b2012-04-03 15:36:36 -0700132 mRS.nScriptSetVarJ(getID(mRS), index, v);
Stephen Hines031ec58c2010-10-11 10:54:21 -0700133 }
134
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700135 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800136 * Only intended for use by generated reflected code.
137 *
138 * @param index
139 * @param v
140 */
Jason Sams0b9a22c2010-07-02 15:35:19 -0700141 public void setVar(int index, boolean v) {
Jason Samse07694b2012-04-03 15:36:36 -0700142 mRS.nScriptSetVarI(getID(mRS), index, v ? 1 : 0);
Jason Sams0b9a22c2010-07-02 15:35:19 -0700143 }
144
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700145 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800146 * Only intended for use by generated reflected code.
147 *
148 * @param index
149 * @param o
150 */
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800151 public void setVar(int index, BaseObj o) {
Jason Samse07694b2012-04-03 15:36:36 -0700152 mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : o.getID(mRS));
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800153 }
154
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700155 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800156 * Only intended for use by generated reflected code.
157 *
158 * @param index
159 * @param v
160 */
Jason Sams4d339932010-05-11 14:03:58 -0700161 public void setVar(int index, FieldPacker v) {
Jason Samse07694b2012-04-03 15:36:36 -0700162 mRS.nScriptSetVarV(getID(mRS), index, v.getData());
Jason Sams69f0d312009-08-03 18:11:17 -0700163 }
164
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700165 /**
Stephen Hinesadeb8092012-04-20 14:26:06 -0700166 * Only intended for use by generated reflected code.
167 *
168 * @param index
169 * @param v
170 * @param e
171 * @param dims
172 */
173 public void setVar(int index, FieldPacker v, Element e, int[] dims) {
174 mRS.nScriptSetVarVE(getID(mRS), index, v.getData(), e.getID(mRS), dims);
175 }
176
Jason Sams22534172009-08-04 16:58:20 -0700177 public void setTimeZone(String timeZone) {
Jason Sams771bebb2009-12-07 12:40:12 -0800178 mRS.validate();
Jason Sams22534172009-08-04 16:58:20 -0700179 try {
Jason Samse07694b2012-04-03 15:36:36 -0700180 mRS.nScriptSetTimeZone(getID(mRS), timeZone.getBytes("UTF-8"));
Jason Sams22534172009-08-04 16:58:20 -0700181 } catch (java.io.UnsupportedEncodingException e) {
182 throw new RuntimeException(e);
183 }
184 }
Jason Sams69f0d312009-08-03 18:11:17 -0700185
186 public static class Builder {
187 RenderScript mRS;
Jason Sams69f0d312009-08-03 18:11:17 -0700188
189 Builder(RenderScript rs) {
190 mRS = rs;
191 }
Jason Sams69f0d312009-08-03 18:11:17 -0700192 }
193
Jason Sams2d71bc72010-03-26 16:06:43 -0700194
195 public static class FieldBase {
196 protected Element mElement;
Jason Sams2d71bc72010-03-26 16:06:43 -0700197 protected Allocation mAllocation;
198
199 protected void init(RenderScript rs, int dimx) {
Jason Sams5476b452010-12-08 16:14:36 -0800200 mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT);
201 }
202
203 protected void init(RenderScript rs, int dimx, int usages) {
204 mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT | usages);
Jason Sams2d71bc72010-03-26 16:06:43 -0700205 }
206
207 protected FieldBase() {
208 }
209
210 public Element getElement() {
211 return mElement;
212 }
213
214 public Type getType() {
Jason Sams31a7e422010-10-26 13:09:17 -0700215 return mAllocation.getType();
Jason Sams2d71bc72010-03-26 16:06:43 -0700216 }
217
218 public Allocation getAllocation() {
219 return mAllocation;
220 }
221
222 //@Override
223 public void updateAllocation() {
224 }
Jason Sams2d71bc72010-03-26 16:06:43 -0700225 }
Jason Sams69f0d312009-08-03 18:11:17 -0700226}
227