blob: f6f93cb7b964760aa2074f1fc3f3eeb6971c3a78 [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
Jason Sams08a81582012-09-18 12:32:10 -070019import android.util.SparseArray;
20
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070021/**
Tim Murrayc11e25c2013-04-09 11:01:01 -070022 * The parent class for all executable scripts. This should not be used by
23 * applications.
Jason Sams69f0d312009-08-03 18:11:17 -070024 **/
25public class Script extends BaseObj {
Jason Sams08a81582012-09-18 12:32:10 -070026
27 /**
28 * KernelID is an identifier for a Script + root function pair. It is used
29 * as an identifier for ScriptGroup creation.
30 *
31 * This class should not be directly created. Instead use the method in the
32 * reflected or intrinsic code "getKernelID_funcname()".
33 *
34 */
35 public static final class KernelID extends BaseObj {
36 Script mScript;
37 int mSlot;
38 int mSig;
Tim Murray7a629fa2013-11-19 12:45:54 -080039 KernelID(long id, RenderScript rs, Script s, int slot, int sig) {
Jason Sams08a81582012-09-18 12:32:10 -070040 super(id, rs);
41 mScript = s;
42 mSlot = slot;
43 mSig = sig;
44 }
45 }
46
47 private final SparseArray<KernelID> mKIDs = new SparseArray<KernelID>();
48 /**
49 * Only to be used by generated reflected classes.
Jason Sams08a81582012-09-18 12:32:10 -070050 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -070051 protected KernelID createKernelID(int slot, int sig, Element ein,
52 Element eout) {
Jason Sams08a81582012-09-18 12:32:10 -070053 KernelID k = mKIDs.get(slot);
54 if (k != null) {
55 return k;
56 }
57
Tim Murray7a629fa2013-11-19 12:45:54 -080058 long id = mRS.nScriptKernelIDCreate(getID(mRS), slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -070059 if (id == 0) {
60 throw new RSDriverException("Failed to create KernelID");
61 }
62
63 k = new KernelID(id, mRS, this, slot, sig);
64 mKIDs.put(slot, k);
65 return k;
66 }
67
68 /**
Yang Nibe392ad2015-01-23 17:16:02 -080069 * InvokeID is an identifier for an invoke function. It is used
70 * as an identifier for ScriptGroup creation.
71 *
72 * This class should not be directly created. Instead use the method in the
73 * reflected or intrinsic code "getInvokeID_funcname()".
74 *
75 */
76 public static final class InvokeID extends BaseObj {
77 Script mScript;
78 int mSlot;
79 InvokeID(long id, RenderScript rs, Script s, int slot) {
80 super(id, rs);
81 mScript = s;
82 mSlot = slot;
83 }
84 }
85
86 private final SparseArray<InvokeID> mIIDs = new SparseArray<InvokeID>();
87 /**
Yang Nibe392ad2015-01-23 17:16:02 -080088 * Only to be used by generated reflected classes.
89 */
90 protected InvokeID createInvokeID(int slot) {
91 InvokeID i = mIIDs.get(slot);
92 if (i != null) {
93 return i;
94 }
95
96 long id = mRS.nScriptInvokeIDCreate(getID(mRS), slot);
97 if (id == 0) {
98 throw new RSDriverException("Failed to create KernelID");
99 }
100
101 i = new InvokeID(id, mRS, this, slot);
102 mIIDs.put(slot, i);
103 return i;
104 }
105
106 /**
Jason Sams08a81582012-09-18 12:32:10 -0700107 * FieldID is an identifier for a Script + exported field pair. It is used
108 * as an identifier for ScriptGroup creation.
109 *
110 * This class should not be directly created. Instead use the method in the
111 * reflected or intrinsic code "getFieldID_funcname()".
112 *
113 */
114 public static final class FieldID extends BaseObj {
115 Script mScript;
116 int mSlot;
Tim Murray7a629fa2013-11-19 12:45:54 -0800117 FieldID(long id, RenderScript rs, Script s, int slot) {
Jason Sams08a81582012-09-18 12:32:10 -0700118 super(id, rs);
119 mScript = s;
120 mSlot = slot;
121 }
122 }
123
124 private final SparseArray<FieldID> mFIDs = new SparseArray();
125 /**
126 * Only to be used by generated reflected classes.
Jason Sams08a81582012-09-18 12:32:10 -0700127 */
128 protected FieldID createFieldID(int slot, Element e) {
129 FieldID f = mFIDs.get(slot);
130 if (f != null) {
131 return f;
132 }
133
Tim Murray7a629fa2013-11-19 12:45:54 -0800134 long id = mRS.nScriptFieldIDCreate(getID(mRS), slot);
Jason Sams08a81582012-09-18 12:32:10 -0700135 if (id == 0) {
136 throw new RSDriverException("Failed to create FieldID");
137 }
138
139 f = new FieldID(id, mRS, this, slot);
140 mFIDs.put(slot, f);
141 return f;
142 }
143
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 *
Jason Sams67e3d202011-01-09 13:49:01 -0800148 */
Jason Sams2d71bc72010-03-26 16:06:43 -0700149 protected void invoke(int slot) {
Jason Samse07694b2012-04-03 15:36:36 -0700150 mRS.nScriptInvoke(getID(mRS), slot);
Jason Sams2d71bc72010-03-26 16:06:43 -0700151 }
152
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700153 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800154 * Only intended for use by generated reflected code.
155 *
Jason Sams67e3d202011-01-09 13:49:01 -0800156 */
Jason Sams96ed4cf2010-06-15 12:15:57 -0700157 protected void invoke(int slot, FieldPacker v) {
158 if (v != null) {
Jason Samse07694b2012-04-03 15:36:36 -0700159 mRS.nScriptInvokeV(getID(mRS), slot, v.getData());
Jason Sams96ed4cf2010-06-15 12:15:57 -0700160 } else {
Jason Samse07694b2012-04-03 15:36:36 -0700161 mRS.nScriptInvoke(getID(mRS), slot);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700162 }
Jason Sams4d339932010-05-11 14:03:58 -0700163 }
164
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700165 /**
Jason Sams6e494d32011-04-27 16:33:11 -0700166 * Only intended for use by generated reflected code.
167 *
Jason Sams6e494d32011-04-27 16:33:11 -0700168 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700169 protected void forEach(int slot, Allocation ain, Allocation aout,
170 FieldPacker v) {
171 forEach(slot, ain, aout, v, null);
Jason Sams6e494d32011-04-27 16:33:11 -0700172 }
173
Jason Samsf64cca92013-04-19 12:56:37 -0700174 /**
175 * Only intended for use by generated reflected code.
176 *
Jason Samsf64cca92013-04-19 12:56:37 -0700177 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700178 protected void forEach(int slot, Allocation ain, Allocation aout,
179 FieldPacker v, LaunchOptions sc) {
180 // TODO: Is this necessary if nScriptForEach calls validate as well?
Jason Sams678cc7f2014-03-05 16:09:02 -0800181 mRS.validate();
182 mRS.validateObject(ain);
183 mRS.validateObject(aout);
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700184
Jason Samsd1516df2015-05-05 18:00:34 -0700185 if (ain == null && aout == null && sc == null) {
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800186 throw new RSIllegalArgumentException(
Jason Samsd1516df2015-05-05 18:00:34 -0700187 "At least one of input allocation, output allocation, or LaunchOptions is required to be non-null.");
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800188 }
Tim Murrayba9dd062013-02-12 16:22:34 -0800189
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700190 long[] in_ids = null;
Stephen Hinesc9c7daf2014-08-13 17:32:19 +0000191 if (ain != null) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700192 in_ids = mInIdsBuffer;
193 in_ids[0] = ain.getID(mRS);
Stephen Hinesc9c7daf2014-08-13 17:32:19 +0000194 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700195
Tim Murray7a629fa2013-11-19 12:45:54 -0800196 long out_id = 0;
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800197 if (aout != null) {
198 out_id = aout.getID(mRS);
199 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700200
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800201 byte[] params = null;
202 if (v != null) {
203 params = v.getData();
204 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700205
206 int[] limits = null;
207 if (sc != null) {
208 limits = new int[6];
209
210 limits[0] = sc.xstart;
211 limits[1] = sc.xend;
212 limits[2] = sc.ystart;
213 limits[3] = sc.yend;
214 limits[4] = sc.zstart;
215 limits[5] = sc.zend;
216 }
217
218 mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits);
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800219 }
Jason Sams4d339932010-05-11 14:03:58 -0700220
Chris Wailes94961062014-06-11 12:01:28 -0700221 /**
222 * Only intended for use by generated reflected code.
Chris Wailes94961062014-06-11 12:01:28 -0700223 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700224 protected void forEach(int slot, Allocation[] ains, Allocation aout,
225 FieldPacker v) {
Jason Sams6a420b52015-03-30 15:31:26 -0700226
227 // FieldPacker is kept here to support regular params in the future.
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700228 forEach(slot, ains, aout, v, null);
Chris Wailes94961062014-06-11 12:01:28 -0700229 }
230
231 /**
232 * Only intended for use by generated reflected code.
Chris Wailes94961062014-06-11 12:01:28 -0700233 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700234 protected void forEach(int slot, Allocation[] ains, Allocation aout,
235 FieldPacker v, LaunchOptions sc) {
236 // TODO: Is this necessary if nScriptForEach calls validate as well?
Jason Sams6a420b52015-03-30 15:31:26 -0700237 // FieldPacker is kept here to support regular params in the future.
Chris Wailes94961062014-06-11 12:01:28 -0700238 mRS.validate();
Andreas Gampec8ddcdd2015-03-15 15:57:30 -0700239 if (ains != null) {
240 for (Allocation ain : ains) {
241 mRS.validateObject(ain);
242 }
Chris Wailes94961062014-06-11 12:01:28 -0700243 }
Stephen Hinesc9c7daf2014-08-13 17:32:19 +0000244 mRS.validateObject(aout);
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700245
Chris Wailes94961062014-06-11 12:01:28 -0700246 if (ains == null && aout == null) {
247 throw new RSIllegalArgumentException(
248 "At least one of ain or aout is required to be non-null.");
249 }
250
Andreas Gampead555f92015-03-17 20:05:46 -0700251 long[] in_ids;
252 if (ains != null) {
253 in_ids = new long[ains.length];
254 for (int index = 0; index < ains.length; ++index) {
255 in_ids[index] = ains[index].getID(mRS);
256 }
257 } else {
258 in_ids = null;
Chris Wailes94961062014-06-11 12:01:28 -0700259 }
260
261 long out_id = 0;
262 if (aout != null) {
263 out_id = aout.getID(mRS);
264 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700265
Chris Wailes94961062014-06-11 12:01:28 -0700266 byte[] params = null;
267 if (v != null) {
268 params = v.getData();
269 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700270
271 int[] limits = null;
272 if (sc != null) {
273 limits = new int[6];
274
275 limits[0] = sc.xstart;
276 limits[1] = sc.xend;
277 limits[2] = sc.ystart;
278 limits[3] = sc.yend;
279 limits[4] = sc.zstart;
280 limits[5] = sc.zend;
281 }
282
283 mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits);
Chris Wailes94961062014-06-11 12:01:28 -0700284 }
285
Matt Wala36eb1f72015-07-20 15:35:27 -0700286 /**
David Gross26ef7a732016-01-12 12:19:15 -0800287 * Only intended for use by generated reflected code. (Simple reduction)
Matt Wala36eb1f72015-07-20 15:35:27 -0700288 *
289 * @hide
290 */
291 protected void reduce(int slot, Allocation ain, Allocation aout, LaunchOptions sc) {
292 mRS.validate();
293 mRS.validateObject(ain);
294 mRS.validateObject(aout);
295
296 if (ain == null || aout == null) {
297 throw new RSIllegalArgumentException(
298 "Both ain and aout are required to be non-null.");
299 }
300
301 long in_id = ain.getID(mRS);
302 long out_id = aout.getID(mRS);
303
304 int[] limits = null;
305 if (sc != null) {
306 limits = new int[2];
307
308 limits[0] = sc.xstart;
309 limits[1] = sc.xend;
310 }
311
312 mRS.nScriptReduce(getID(mRS), slot, in_id, out_id, limits);
313 }
314
David Gross26ef7a732016-01-12 12:19:15 -0800315 /**
316 * Only intended for use by generated reflected code. (General reduction)
317 *
David Gross26ef7a732016-01-12 12:19:15 -0800318 */
319 protected void reduce(int slot, Allocation[] ains, Allocation aout, LaunchOptions sc) {
320 mRS.validate();
321 if (ains == null || ains.length < 1) {
322 throw new RSIllegalArgumentException(
323 "At least one input is required.");
324 }
325 if (aout == null) {
326 throw new RSIllegalArgumentException(
327 "aout is required to be non-null.");
328 }
329 for (Allocation ain : ains) {
330 mRS.validateObject(ain);
331 }
332
333 long[] in_ids = new long[ains.length];
334 for (int index = 0; index < ains.length; ++index) {
335 in_ids[index] = ains[index].getID(mRS);
336 }
337 long out_id = aout.getID(mRS);
338
339 int[] limits = null;
340 if (sc != null) {
341 limits = new int[6];
342
343 limits[0] = sc.xstart;
344 limits[1] = sc.xend;
345 limits[2] = sc.ystart;
346 limits[3] = sc.yend;
347 limits[4] = sc.zstart;
348 limits[5] = sc.zend;
349 }
350
351 mRS.nScriptReduceNew(getID(mRS), slot, in_ids, out_id, limits);
352 }
353
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700354 long[] mInIdsBuffer;
355
Tim Murray7a629fa2013-11-19 12:45:54 -0800356 Script(long id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -0700357 super(id, rs);
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700358
359 mInIdsBuffer = new long[1];
Jason Sams69f0d312009-08-03 18:11:17 -0700360 }
361
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700362 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800363 * Only intended for use by generated reflected code.
364 *
Jason Sams67e3d202011-01-09 13:49:01 -0800365 */
Jason Sams69f0d312009-08-03 18:11:17 -0700366 public void bindAllocation(Allocation va, int slot) {
Jason Sams771bebb2009-12-07 12:40:12 -0800367 mRS.validate();
Jason Sams678cc7f2014-03-05 16:09:02 -0800368 mRS.validateObject(va);
Jason Sams4d339932010-05-11 14:03:58 -0700369 if (va != null) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700370
371 android.content.Context context = mRS.getApplicationContext();
372
373 if (context.getApplicationInfo().targetSdkVersion >= 20) {
Jason Samscf9c8942014-01-14 16:18:14 -0800374 final Type t = va.mType;
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700375 if (t.hasMipmaps() || t.hasFaces() || (t.getY() != 0) ||
376 (t.getZ() != 0)) {
377
Jason Samscf9c8942014-01-14 16:18:14 -0800378 throw new RSIllegalArgumentException(
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700379 "API 20+ only allows simple 1D allocations to be " +
380 "used with bind.");
Jason Samscf9c8942014-01-14 16:18:14 -0800381 }
382 }
Jason Samse07694b2012-04-03 15:36:36 -0700383 mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot);
Jason Sams4d339932010-05-11 14:03:58 -0700384 } else {
Jason Samse07694b2012-04-03 15:36:36 -0700385 mRS.nScriptBindAllocation(getID(mRS), 0, slot);
Jason Sams4d339932010-05-11 14:03:58 -0700386 }
387 }
388
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700389 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800390 * Only intended for use by generated reflected code.
391 *
Jason Sams67e3d202011-01-09 13:49:01 -0800392 */
Jason Sams4d339932010-05-11 14:03:58 -0700393 public void setVar(int index, float v) {
Jason Samse07694b2012-04-03 15:36:36 -0700394 mRS.nScriptSetVarF(getID(mRS), index, v);
Jason Sams4d339932010-05-11 14:03:58 -0700395 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700396 public float getVarF(int index) {
397 return mRS.nScriptGetVarF(getID(mRS), index);
398 }
Jason Sams4d339932010-05-11 14:03:58 -0700399
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700400 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800401 * Only intended for use by generated reflected code.
402 *
Jason Sams67e3d202011-01-09 13:49:01 -0800403 */
Stephen Hinesca54ec32010-09-20 17:20:30 -0700404 public void setVar(int index, double v) {
Jason Samse07694b2012-04-03 15:36:36 -0700405 mRS.nScriptSetVarD(getID(mRS), index, v);
Stephen Hinesca54ec32010-09-20 17:20:30 -0700406 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700407 public double getVarD(int index) {
408 return mRS.nScriptGetVarD(getID(mRS), index);
409 }
Stephen Hinesca54ec32010-09-20 17:20:30 -0700410
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700411 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800412 * Only intended for use by generated reflected code.
413 *
Jason Sams67e3d202011-01-09 13:49:01 -0800414 */
Jason Sams4d339932010-05-11 14:03:58 -0700415 public void setVar(int index, int v) {
Jason Samse07694b2012-04-03 15:36:36 -0700416 mRS.nScriptSetVarI(getID(mRS), index, v);
Jason Sams4d339932010-05-11 14:03:58 -0700417 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700418 public int getVarI(int index) {
419 return mRS.nScriptGetVarI(getID(mRS), index);
420 }
421
Jason Sams4d339932010-05-11 14:03:58 -0700422
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700423 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800424 * Only intended for use by generated reflected code.
425 *
Jason Sams67e3d202011-01-09 13:49:01 -0800426 */
Stephen Hines031ec58c2010-10-11 10:54:21 -0700427 public void setVar(int index, long v) {
Jason Samse07694b2012-04-03 15:36:36 -0700428 mRS.nScriptSetVarJ(getID(mRS), index, v);
Stephen Hines031ec58c2010-10-11 10:54:21 -0700429 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700430 public long getVarJ(int index) {
431 return mRS.nScriptGetVarJ(getID(mRS), index);
432 }
433
Stephen Hines031ec58c2010-10-11 10:54:21 -0700434
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700435 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800436 * Only intended for use by generated reflected code.
437 *
Jason Sams67e3d202011-01-09 13:49:01 -0800438 */
Jason Sams0b9a22c2010-07-02 15:35:19 -0700439 public void setVar(int index, boolean v) {
Jason Samse07694b2012-04-03 15:36:36 -0700440 mRS.nScriptSetVarI(getID(mRS), index, v ? 1 : 0);
Jason Sams0b9a22c2010-07-02 15:35:19 -0700441 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700442 public boolean getVarB(int index) {
443 return mRS.nScriptGetVarI(getID(mRS), index) > 0 ? true : false;
444 }
Jason Sams0b9a22c2010-07-02 15:35:19 -0700445
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700446 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800447 * Only intended for use by generated reflected code.
448 *
Jason Sams67e3d202011-01-09 13:49:01 -0800449 */
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800450 public void setVar(int index, BaseObj o) {
Jason Sams678cc7f2014-03-05 16:09:02 -0800451 mRS.validate();
452 mRS.validateObject(o);
Jason Samse07694b2012-04-03 15:36:36 -0700453 mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : o.getID(mRS));
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800454 }
455
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700456 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800457 * Only intended for use by generated reflected code.
458 *
Jason Sams67e3d202011-01-09 13:49:01 -0800459 */
Jason Sams4d339932010-05-11 14:03:58 -0700460 public void setVar(int index, FieldPacker v) {
Jason Samse07694b2012-04-03 15:36:36 -0700461 mRS.nScriptSetVarV(getID(mRS), index, v.getData());
Jason Sams69f0d312009-08-03 18:11:17 -0700462 }
463
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700464 /**
Stephen Hinesadeb8092012-04-20 14:26:06 -0700465 * Only intended for use by generated reflected code.
466 *
Stephen Hinesadeb8092012-04-20 14:26:06 -0700467 */
468 public void setVar(int index, FieldPacker v, Element e, int[] dims) {
469 mRS.nScriptSetVarVE(getID(mRS), index, v.getData(), e.getID(mRS), dims);
470 }
471
Jason Samsf64cca92013-04-19 12:56:37 -0700472 /**
473 * Only intended for use by generated reflected code.
474 *
Jason Samsf64cca92013-04-19 12:56:37 -0700475 */
Tim Murray7c4caad2013-04-10 16:21:40 -0700476 public void getVarV(int index, FieldPacker v) {
477 mRS.nScriptGetVarV(getID(mRS), index, v.getData());
478 }
479
Jason Sams22534172009-08-04 16:58:20 -0700480 public void setTimeZone(String timeZone) {
Jason Sams771bebb2009-12-07 12:40:12 -0800481 mRS.validate();
Jason Sams22534172009-08-04 16:58:20 -0700482 try {
Jason Samse07694b2012-04-03 15:36:36 -0700483 mRS.nScriptSetTimeZone(getID(mRS), timeZone.getBytes("UTF-8"));
Jason Sams22534172009-08-04 16:58:20 -0700484 } catch (java.io.UnsupportedEncodingException e) {
485 throw new RuntimeException(e);
486 }
487 }
Jason Sams69f0d312009-08-03 18:11:17 -0700488
Tim Murrayc11e25c2013-04-09 11:01:01 -0700489 /**
490 * Only intended for use by generated reflected code.
491 *
492 */
Jason Sams69f0d312009-08-03 18:11:17 -0700493 public static class Builder {
494 RenderScript mRS;
Jason Sams69f0d312009-08-03 18:11:17 -0700495
496 Builder(RenderScript rs) {
497 mRS = rs;
498 }
Jason Sams69f0d312009-08-03 18:11:17 -0700499 }
500
Jason Sams2d71bc72010-03-26 16:06:43 -0700501
Jason Samsf64cca92013-04-19 12:56:37 -0700502 /**
503 * Only intended for use by generated reflected code.
504 *
505 */
Jason Sams2d71bc72010-03-26 16:06:43 -0700506 public static class FieldBase {
507 protected Element mElement;
Jason Sams2d71bc72010-03-26 16:06:43 -0700508 protected Allocation mAllocation;
509
510 protected void init(RenderScript rs, int dimx) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700511 mAllocation = Allocation.createSized(rs, mElement, dimx,
512 Allocation.USAGE_SCRIPT);
Jason Sams5476b452010-12-08 16:14:36 -0800513 }
514
515 protected void init(RenderScript rs, int dimx, int usages) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700516 mAllocation =
517 Allocation.createSized(rs, mElement, dimx,
518 Allocation.USAGE_SCRIPT | usages);
Jason Sams2d71bc72010-03-26 16:06:43 -0700519 }
520
521 protected FieldBase() {
522 }
523
524 public Element getElement() {
525 return mElement;
526 }
527
528 public Type getType() {
Jason Sams31a7e422010-10-26 13:09:17 -0700529 return mAllocation.getType();
Jason Sams2d71bc72010-03-26 16:06:43 -0700530 }
531
532 public Allocation getAllocation() {
533 return mAllocation;
534 }
535
536 //@Override
537 public void updateAllocation() {
538 }
Jason Sams2d71bc72010-03-26 16:06:43 -0700539 }
Tim Murrayfbfaa852012-12-14 16:01:58 -0800540
Jason Samsf64cca92013-04-19 12:56:37 -0700541
542 /**
Jason Sams8610f832015-03-30 17:01:10 -0700543 * Class for specifying the specifics about how a kernel will be
Miao Wang53fdcfb2016-03-29 15:14:21 -0700544 * launched.
Jason Sams8610f832015-03-30 17:01:10 -0700545 *
546 * This class can specify a potential range of cells on which to
547 * run a kernel. If no set is called for a dimension then this
548 * class will have no impact on that dimension when the kernel
549 * is executed.
550 *
Miao Wang53fdcfb2016-03-29 15:14:21 -0700551 * The forEach kernel launch will operate over the intersection of
552 * the dimensions.
Jason Sams8610f832015-03-30 17:01:10 -0700553 *
554 * Example:
555 * LaunchOptions with setX(5, 15)
556 * Allocation with dimension X=10, Y=10
Miao Wang53fdcfb2016-03-29 15:14:21 -0700557 * The resulting forEach run would execute over:
558 * x = 5 to 9 (inclusive) and
559 * y = 0 to 9 (inclusive).
Jason Sams8610f832015-03-30 17:01:10 -0700560 *
Jason Samsf64cca92013-04-19 12:56:37 -0700561 *
562 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800563 public static final class LaunchOptions {
Jason Samsf64cca92013-04-19 12:56:37 -0700564 private int xstart = 0;
565 private int ystart = 0;
566 private int xend = 0;
567 private int yend = 0;
568 private int zstart = 0;
569 private int zend = 0;
570 private int strategy;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800571
Jason Samsf64cca92013-04-19 12:56:37 -0700572 /**
Miao Wang53fdcfb2016-03-29 15:14:21 -0700573 * Set the X range. xstartArg is the lowest coordinate of the range,
574 * and xendArg-1 is the highest coordinate of the range.
Jason Samsf64cca92013-04-19 12:56:37 -0700575 *
576 * @param xstartArg Must be >= 0
Miao Wang53fdcfb2016-03-29 15:14:21 -0700577 * @param xendArg Must be > xstartArg
Jason Samsf64cca92013-04-19 12:56:37 -0700578 *
579 * @return LaunchOptions
580 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800581 public LaunchOptions setX(int xstartArg, int xendArg) {
Tim Murrayfbfaa852012-12-14 16:01:58 -0800582 if (xstartArg < 0 || xendArg <= xstartArg) {
583 throw new RSIllegalArgumentException("Invalid dimensions");
584 }
585 xstart = xstartArg;
586 xend = xendArg;
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800587 return this;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800588 }
589
Jason Samsf64cca92013-04-19 12:56:37 -0700590 /**
Miao Wang53fdcfb2016-03-29 15:14:21 -0700591 * Set the Y range. ystartArg is the lowest coordinate of the range,
592 * and yendArg-1 is the highest coordinate of the range.
Jason Samsf64cca92013-04-19 12:56:37 -0700593 *
594 * @param ystartArg Must be >= 0
Miao Wang53fdcfb2016-03-29 15:14:21 -0700595 * @param yendArg Must be > ystartArg
Jason Samsf64cca92013-04-19 12:56:37 -0700596 *
597 * @return LaunchOptions
598 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800599 public LaunchOptions setY(int ystartArg, int yendArg) {
Tim Murrayfbfaa852012-12-14 16:01:58 -0800600 if (ystartArg < 0 || yendArg <= ystartArg) {
601 throw new RSIllegalArgumentException("Invalid dimensions");
602 }
603 ystart = ystartArg;
604 yend = yendArg;
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800605 return this;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800606 }
607
Jason Samsf64cca92013-04-19 12:56:37 -0700608 /**
Miao Wang53fdcfb2016-03-29 15:14:21 -0700609 * Set the Z range. zstartArg is the lowest coordinate of the range,
610 * and zendArg-1 is the highest coordinate of the range.
Jason Samsf64cca92013-04-19 12:56:37 -0700611 *
612 * @param zstartArg Must be >= 0
Miao Wang53fdcfb2016-03-29 15:14:21 -0700613 * @param zendArg Must be > zstartArg
Jason Samsf64cca92013-04-19 12:56:37 -0700614 *
615 * @return LaunchOptions
616 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800617 public LaunchOptions setZ(int zstartArg, int zendArg) {
618 if (zstartArg < 0 || zendArg <= zstartArg) {
619 throw new RSIllegalArgumentException("Invalid dimensions");
620 }
621 zstart = zstartArg;
622 zend = zendArg;
623 return this;
624 }
625
626
Jason Samsf64cca92013-04-19 12:56:37 -0700627 /**
628 * Returns the current X start
629 *
630 * @return int current value
631 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800632 public int getXStart() {
633 return xstart;
634 }
Jason Samsf64cca92013-04-19 12:56:37 -0700635 /**
636 * Returns the current X end
637 *
638 * @return int current value
639 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800640 public int getXEnd() {
641 return xend;
642 }
Jason Samsf64cca92013-04-19 12:56:37 -0700643 /**
644 * Returns the current Y start
645 *
646 * @return int current value
647 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800648 public int getYStart() {
649 return ystart;
650 }
Jason Samsf64cca92013-04-19 12:56:37 -0700651 /**
652 * Returns the current Y end
653 *
654 * @return int current value
655 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800656 public int getYEnd() {
657 return yend;
658 }
Jason Samsf64cca92013-04-19 12:56:37 -0700659 /**
660 * Returns the current Z start
661 *
662 * @return int current value
663 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800664 public int getZStart() {
665 return zstart;
666 }
Jason Samsf64cca92013-04-19 12:56:37 -0700667 /**
668 * Returns the current Z end
669 *
670 * @return int current value
671 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800672 public int getZEnd() {
673 return zend;
674 }
Tim Murrayfbfaa852012-12-14 16:01:58 -0800675
676 }
Jason Sams69f0d312009-08-03 18:11:17 -0700677}