blob: 9ad9aea9d7aa6f8f32805bb45b1116b846a84ad2 [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
Mathew Inwoodf0c90b12018-08-01 10:05:11 +010019import android.annotation.UnsupportedAppUsage;
Jason Sams08a81582012-09-18 12:32:10 -070020import android.util.SparseArray;
21
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -070022/**
Tim Murrayc11e25c2013-04-09 11:01:01 -070023 * The parent class for all executable scripts. This should not be used by
24 * applications.
Jason Sams69f0d312009-08-03 18:11:17 -070025 **/
26public class Script extends BaseObj {
Jason Sams08a81582012-09-18 12:32:10 -070027
28 /**
29 * KernelID is an identifier for a Script + root function pair. It is used
30 * as an identifier for ScriptGroup creation.
31 *
32 * This class should not be directly created. Instead use the method in the
33 * reflected or intrinsic code "getKernelID_funcname()".
34 *
35 */
36 public static final class KernelID extends BaseObj {
37 Script mScript;
38 int mSlot;
39 int mSig;
Tim Murray7a629fa2013-11-19 12:45:54 -080040 KernelID(long id, RenderScript rs, Script s, int slot, int sig) {
Jason Sams08a81582012-09-18 12:32:10 -070041 super(id, rs);
42 mScript = s;
43 mSlot = slot;
44 mSig = sig;
45 }
46 }
47
48 private final SparseArray<KernelID> mKIDs = new SparseArray<KernelID>();
49 /**
50 * Only to be used by generated reflected classes.
Jason Sams08a81582012-09-18 12:32:10 -070051 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -070052 protected KernelID createKernelID(int slot, int sig, Element ein,
53 Element eout) {
Jason Sams08a81582012-09-18 12:32:10 -070054 KernelID k = mKIDs.get(slot);
55 if (k != null) {
56 return k;
57 }
58
Tim Murray7a629fa2013-11-19 12:45:54 -080059 long id = mRS.nScriptKernelIDCreate(getID(mRS), slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -070060 if (id == 0) {
61 throw new RSDriverException("Failed to create KernelID");
62 }
63
64 k = new KernelID(id, mRS, this, slot, sig);
65 mKIDs.put(slot, k);
66 return k;
67 }
68
69 /**
Yang Nibe392ad2015-01-23 17:16:02 -080070 * InvokeID is an identifier for an invoke function. It is used
71 * as an identifier for ScriptGroup creation.
72 *
73 * This class should not be directly created. Instead use the method in the
74 * reflected or intrinsic code "getInvokeID_funcname()".
75 *
76 */
77 public static final class InvokeID extends BaseObj {
78 Script mScript;
79 int mSlot;
80 InvokeID(long id, RenderScript rs, Script s, int slot) {
81 super(id, rs);
82 mScript = s;
83 mSlot = slot;
84 }
85 }
86
87 private final SparseArray<InvokeID> mIIDs = new SparseArray<InvokeID>();
88 /**
Yang Nibe392ad2015-01-23 17:16:02 -080089 * Only to be used by generated reflected classes.
90 */
91 protected InvokeID createInvokeID(int slot) {
92 InvokeID i = mIIDs.get(slot);
93 if (i != null) {
94 return i;
95 }
96
97 long id = mRS.nScriptInvokeIDCreate(getID(mRS), slot);
98 if (id == 0) {
99 throw new RSDriverException("Failed to create KernelID");
100 }
101
102 i = new InvokeID(id, mRS, this, slot);
103 mIIDs.put(slot, i);
104 return i;
105 }
106
107 /**
Jason Sams08a81582012-09-18 12:32:10 -0700108 * FieldID is an identifier for a Script + exported field pair. It is used
109 * as an identifier for ScriptGroup creation.
110 *
111 * This class should not be directly created. Instead use the method in the
112 * reflected or intrinsic code "getFieldID_funcname()".
113 *
114 */
115 public static final class FieldID extends BaseObj {
116 Script mScript;
117 int mSlot;
Tim Murray7a629fa2013-11-19 12:45:54 -0800118 FieldID(long id, RenderScript rs, Script s, int slot) {
Jason Sams08a81582012-09-18 12:32:10 -0700119 super(id, rs);
120 mScript = s;
121 mSlot = slot;
122 }
123 }
124
125 private final SparseArray<FieldID> mFIDs = new SparseArray();
126 /**
127 * Only to be used by generated reflected classes.
Jason Sams08a81582012-09-18 12:32:10 -0700128 */
129 protected FieldID createFieldID(int slot, Element e) {
130 FieldID f = mFIDs.get(slot);
131 if (f != null) {
132 return f;
133 }
134
Tim Murray7a629fa2013-11-19 12:45:54 -0800135 long id = mRS.nScriptFieldIDCreate(getID(mRS), slot);
Jason Sams08a81582012-09-18 12:32:10 -0700136 if (id == 0) {
137 throw new RSDriverException("Failed to create FieldID");
138 }
139
140 f = new FieldID(id, mRS, this, slot);
141 mFIDs.put(slot, f);
142 return f;
143 }
144
145
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700146 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800147 * Only intended for use by generated reflected code.
148 *
Jason Sams67e3d202011-01-09 13:49:01 -0800149 */
Jason Sams2d71bc72010-03-26 16:06:43 -0700150 protected void invoke(int slot) {
Jason Samse07694b2012-04-03 15:36:36 -0700151 mRS.nScriptInvoke(getID(mRS), slot);
Jason Sams2d71bc72010-03-26 16:06:43 -0700152 }
153
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700154 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800155 * Only intended for use by generated reflected code.
156 *
Jason Sams67e3d202011-01-09 13:49:01 -0800157 */
Jason Sams96ed4cf2010-06-15 12:15:57 -0700158 protected void invoke(int slot, FieldPacker v) {
159 if (v != null) {
Jason Samse07694b2012-04-03 15:36:36 -0700160 mRS.nScriptInvokeV(getID(mRS), slot, v.getData());
Jason Sams96ed4cf2010-06-15 12:15:57 -0700161 } else {
Jason Samse07694b2012-04-03 15:36:36 -0700162 mRS.nScriptInvoke(getID(mRS), slot);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700163 }
Jason Sams4d339932010-05-11 14:03:58 -0700164 }
165
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700166 /**
Jason Sams6e494d32011-04-27 16:33:11 -0700167 * Only intended for use by generated reflected code.
168 *
Jason Sams6e494d32011-04-27 16:33:11 -0700169 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700170 protected void forEach(int slot, Allocation ain, Allocation aout,
171 FieldPacker v) {
172 forEach(slot, ain, aout, v, null);
Jason Sams6e494d32011-04-27 16:33:11 -0700173 }
174
Jason Samsf64cca92013-04-19 12:56:37 -0700175 /**
176 * Only intended for use by generated reflected code.
177 *
Jason Samsf64cca92013-04-19 12:56:37 -0700178 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700179 protected void forEach(int slot, Allocation ain, Allocation aout,
180 FieldPacker v, LaunchOptions sc) {
181 // TODO: Is this necessary if nScriptForEach calls validate as well?
Jason Sams678cc7f2014-03-05 16:09:02 -0800182 mRS.validate();
183 mRS.validateObject(ain);
184 mRS.validateObject(aout);
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700185
Jason Samsd1516df2015-05-05 18:00:34 -0700186 if (ain == null && aout == null && sc == null) {
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800187 throw new RSIllegalArgumentException(
Jason Samsd1516df2015-05-05 18:00:34 -0700188 "At least one of input allocation, output allocation, or LaunchOptions is required to be non-null.");
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800189 }
Tim Murrayba9dd062013-02-12 16:22:34 -0800190
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700191 long[] in_ids = null;
Stephen Hinesc9c7daf2014-08-13 17:32:19 +0000192 if (ain != null) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700193 in_ids = mInIdsBuffer;
194 in_ids[0] = ain.getID(mRS);
Stephen Hinesc9c7daf2014-08-13 17:32:19 +0000195 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700196
Tim Murray7a629fa2013-11-19 12:45:54 -0800197 long out_id = 0;
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800198 if (aout != null) {
199 out_id = aout.getID(mRS);
200 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700201
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800202 byte[] params = null;
203 if (v != null) {
204 params = v.getData();
205 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700206
207 int[] limits = null;
208 if (sc != null) {
209 limits = new int[6];
210
211 limits[0] = sc.xstart;
212 limits[1] = sc.xend;
213 limits[2] = sc.ystart;
214 limits[3] = sc.yend;
215 limits[4] = sc.zstart;
216 limits[5] = sc.zend;
217 }
218
219 mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits);
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800220 }
Jason Sams4d339932010-05-11 14:03:58 -0700221
Chris Wailes94961062014-06-11 12:01:28 -0700222 /**
223 * Only intended for use by generated reflected code.
Chris Wailes94961062014-06-11 12:01:28 -0700224 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700225 protected void forEach(int slot, Allocation[] ains, Allocation aout,
226 FieldPacker v) {
Jason Sams6a420b52015-03-30 15:31:26 -0700227
228 // FieldPacker is kept here to support regular params in the future.
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700229 forEach(slot, ains, aout, v, null);
Chris Wailes94961062014-06-11 12:01:28 -0700230 }
231
232 /**
233 * Only intended for use by generated reflected code.
Chris Wailes94961062014-06-11 12:01:28 -0700234 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700235 protected void forEach(int slot, Allocation[] ains, Allocation aout,
236 FieldPacker v, LaunchOptions sc) {
237 // TODO: Is this necessary if nScriptForEach calls validate as well?
Jason Sams6a420b52015-03-30 15:31:26 -0700238 // FieldPacker is kept here to support regular params in the future.
Chris Wailes94961062014-06-11 12:01:28 -0700239 mRS.validate();
Andreas Gampec8ddcdd2015-03-15 15:57:30 -0700240 if (ains != null) {
241 for (Allocation ain : ains) {
242 mRS.validateObject(ain);
243 }
Chris Wailes94961062014-06-11 12:01:28 -0700244 }
Stephen Hinesc9c7daf2014-08-13 17:32:19 +0000245 mRS.validateObject(aout);
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700246
Chris Wailes94961062014-06-11 12:01:28 -0700247 if (ains == null && aout == null) {
248 throw new RSIllegalArgumentException(
249 "At least one of ain or aout is required to be non-null.");
250 }
251
Andreas Gampead555f92015-03-17 20:05:46 -0700252 long[] in_ids;
253 if (ains != null) {
254 in_ids = new long[ains.length];
255 for (int index = 0; index < ains.length; ++index) {
256 in_ids[index] = ains[index].getID(mRS);
257 }
258 } else {
259 in_ids = null;
Chris Wailes94961062014-06-11 12:01:28 -0700260 }
261
262 long out_id = 0;
263 if (aout != null) {
264 out_id = aout.getID(mRS);
265 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700266
Chris Wailes94961062014-06-11 12:01:28 -0700267 byte[] params = null;
268 if (v != null) {
269 params = v.getData();
270 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700271
272 int[] limits = null;
273 if (sc != null) {
274 limits = new int[6];
275
276 limits[0] = sc.xstart;
277 limits[1] = sc.xend;
278 limits[2] = sc.ystart;
279 limits[3] = sc.yend;
280 limits[4] = sc.zstart;
281 limits[5] = sc.zend;
282 }
283
284 mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits);
Chris Wailes94961062014-06-11 12:01:28 -0700285 }
286
Matt Wala36eb1f72015-07-20 15:35:27 -0700287 /**
David Gross26ef7a732016-01-12 12:19:15 -0800288 * Only intended for use by generated reflected code. (General reduction)
289 *
David Gross26ef7a732016-01-12 12:19:15 -0800290 */
291 protected void reduce(int slot, Allocation[] ains, Allocation aout, LaunchOptions sc) {
292 mRS.validate();
293 if (ains == null || ains.length < 1) {
294 throw new RSIllegalArgumentException(
295 "At least one input is required.");
296 }
297 if (aout == null) {
298 throw new RSIllegalArgumentException(
299 "aout is required to be non-null.");
300 }
301 for (Allocation ain : ains) {
302 mRS.validateObject(ain);
303 }
304
305 long[] in_ids = new long[ains.length];
306 for (int index = 0; index < ains.length; ++index) {
307 in_ids[index] = ains[index].getID(mRS);
308 }
309 long out_id = aout.getID(mRS);
310
311 int[] limits = null;
312 if (sc != null) {
313 limits = new int[6];
314
315 limits[0] = sc.xstart;
316 limits[1] = sc.xend;
317 limits[2] = sc.ystart;
318 limits[3] = sc.yend;
319 limits[4] = sc.zstart;
320 limits[5] = sc.zend;
321 }
322
David Gross4a457852016-06-02 14:46:55 -0700323 mRS.nScriptReduce(getID(mRS), slot, in_ids, out_id, limits);
David Gross26ef7a732016-01-12 12:19:15 -0800324 }
325
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700326 long[] mInIdsBuffer;
327
Tim Murray7a629fa2013-11-19 12:45:54 -0800328 Script(long id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -0700329 super(id, rs);
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700330
331 mInIdsBuffer = new long[1];
Yang Ni6484b6b2016-03-24 09:40:32 -0700332
333 /* The constructors for the derived classes (including ScriptIntrinsic
334 * derived classes and ScriptC derived classes generated by Slang
335 * reflection) seem to be simple enough, so we just put the guard.open()
336 * call here, rather than in the end of the constructor for the derived
337 * class. This, of course, assumes the derived constructor would not
338 * throw any exception after calling this constructor.
339 *
340 * If new derived classes are added with more complicated constructors
341 * that throw exceptions, this call has to be (duplicated and) moved
342 * to the end of each derived class constructor.
343 */
344 guard.open("destroy");
Jason Sams69f0d312009-08-03 18:11:17 -0700345 }
346
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700347 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800348 * Only intended for use by generated reflected code.
349 *
Jason Sams67e3d202011-01-09 13:49:01 -0800350 */
Jason Sams69f0d312009-08-03 18:11:17 -0700351 public void bindAllocation(Allocation va, int slot) {
Jason Sams771bebb2009-12-07 12:40:12 -0800352 mRS.validate();
Jason Sams678cc7f2014-03-05 16:09:02 -0800353 mRS.validateObject(va);
Jason Sams4d339932010-05-11 14:03:58 -0700354 if (va != null) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700355
356 android.content.Context context = mRS.getApplicationContext();
357
358 if (context.getApplicationInfo().targetSdkVersion >= 20) {
Jason Samscf9c8942014-01-14 16:18:14 -0800359 final Type t = va.mType;
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700360 if (t.hasMipmaps() || t.hasFaces() || (t.getY() != 0) ||
361 (t.getZ() != 0)) {
362
Jason Samscf9c8942014-01-14 16:18:14 -0800363 throw new RSIllegalArgumentException(
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700364 "API 20+ only allows simple 1D allocations to be " +
365 "used with bind.");
Jason Samscf9c8942014-01-14 16:18:14 -0800366 }
367 }
Jason Samse07694b2012-04-03 15:36:36 -0700368 mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot);
Jason Sams4d339932010-05-11 14:03:58 -0700369 } else {
Jason Samse07694b2012-04-03 15:36:36 -0700370 mRS.nScriptBindAllocation(getID(mRS), 0, slot);
Jason Sams4d339932010-05-11 14:03:58 -0700371 }
372 }
373
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700374 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800375 * Only intended for use by generated reflected code.
376 *
Jason Sams67e3d202011-01-09 13:49:01 -0800377 */
Jason Sams4d339932010-05-11 14:03:58 -0700378 public void setVar(int index, float v) {
Jason Samse07694b2012-04-03 15:36:36 -0700379 mRS.nScriptSetVarF(getID(mRS), index, v);
Jason Sams4d339932010-05-11 14:03:58 -0700380 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700381 public float getVarF(int index) {
382 return mRS.nScriptGetVarF(getID(mRS), index);
383 }
Jason Sams4d339932010-05-11 14:03:58 -0700384
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700385 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800386 * Only intended for use by generated reflected code.
387 *
Jason Sams67e3d202011-01-09 13:49:01 -0800388 */
Stephen Hinesca54ec32010-09-20 17:20:30 -0700389 public void setVar(int index, double v) {
Jason Samse07694b2012-04-03 15:36:36 -0700390 mRS.nScriptSetVarD(getID(mRS), index, v);
Stephen Hinesca54ec32010-09-20 17:20:30 -0700391 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700392 public double getVarD(int index) {
393 return mRS.nScriptGetVarD(getID(mRS), index);
394 }
Stephen Hinesca54ec32010-09-20 17:20:30 -0700395
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700396 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800397 * Only intended for use by generated reflected code.
398 *
Jason Sams67e3d202011-01-09 13:49:01 -0800399 */
Jason Sams4d339932010-05-11 14:03:58 -0700400 public void setVar(int index, int v) {
Jason Samse07694b2012-04-03 15:36:36 -0700401 mRS.nScriptSetVarI(getID(mRS), index, v);
Jason Sams4d339932010-05-11 14:03:58 -0700402 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700403 public int getVarI(int index) {
404 return mRS.nScriptGetVarI(getID(mRS), index);
405 }
406
Jason Sams4d339932010-05-11 14:03:58 -0700407
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700408 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800409 * Only intended for use by generated reflected code.
410 *
Jason Sams67e3d202011-01-09 13:49:01 -0800411 */
Stephen Hines031ec58c2010-10-11 10:54:21 -0700412 public void setVar(int index, long v) {
Jason Samse07694b2012-04-03 15:36:36 -0700413 mRS.nScriptSetVarJ(getID(mRS), index, v);
Stephen Hines031ec58c2010-10-11 10:54:21 -0700414 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700415 public long getVarJ(int index) {
416 return mRS.nScriptGetVarJ(getID(mRS), index);
417 }
418
Stephen Hines031ec58c2010-10-11 10:54:21 -0700419
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700420 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800421 * Only intended for use by generated reflected code.
422 *
Jason Sams67e3d202011-01-09 13:49:01 -0800423 */
Jason Sams0b9a22c2010-07-02 15:35:19 -0700424 public void setVar(int index, boolean v) {
Jason Samse07694b2012-04-03 15:36:36 -0700425 mRS.nScriptSetVarI(getID(mRS), index, v ? 1 : 0);
Jason Sams0b9a22c2010-07-02 15:35:19 -0700426 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700427 public boolean getVarB(int index) {
428 return mRS.nScriptGetVarI(getID(mRS), index) > 0 ? true : false;
429 }
Jason Sams0b9a22c2010-07-02 15:35:19 -0700430
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700431 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800432 * Only intended for use by generated reflected code.
433 *
Jason Sams67e3d202011-01-09 13:49:01 -0800434 */
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800435 public void setVar(int index, BaseObj o) {
Jason Sams678cc7f2014-03-05 16:09:02 -0800436 mRS.validate();
437 mRS.validateObject(o);
Jason Samse07694b2012-04-03 15:36:36 -0700438 mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : o.getID(mRS));
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800439 }
440
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700441 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800442 * Only intended for use by generated reflected code.
443 *
Jason Sams67e3d202011-01-09 13:49:01 -0800444 */
Jason Sams4d339932010-05-11 14:03:58 -0700445 public void setVar(int index, FieldPacker v) {
Jason Samse07694b2012-04-03 15:36:36 -0700446 mRS.nScriptSetVarV(getID(mRS), index, v.getData());
Jason Sams69f0d312009-08-03 18:11:17 -0700447 }
448
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700449 /**
Stephen Hinesadeb8092012-04-20 14:26:06 -0700450 * Only intended for use by generated reflected code.
451 *
Stephen Hinesadeb8092012-04-20 14:26:06 -0700452 */
453 public void setVar(int index, FieldPacker v, Element e, int[] dims) {
454 mRS.nScriptSetVarVE(getID(mRS), index, v.getData(), e.getID(mRS), dims);
455 }
456
Jason Samsf64cca92013-04-19 12:56:37 -0700457 /**
458 * Only intended for use by generated reflected code.
459 *
Jason Samsf64cca92013-04-19 12:56:37 -0700460 */
Tim Murray7c4caad2013-04-10 16:21:40 -0700461 public void getVarV(int index, FieldPacker v) {
462 mRS.nScriptGetVarV(getID(mRS), index, v.getData());
463 }
464
Jason Sams22534172009-08-04 16:58:20 -0700465 public void setTimeZone(String timeZone) {
Jason Sams771bebb2009-12-07 12:40:12 -0800466 mRS.validate();
Jason Sams22534172009-08-04 16:58:20 -0700467 try {
Jason Samse07694b2012-04-03 15:36:36 -0700468 mRS.nScriptSetTimeZone(getID(mRS), timeZone.getBytes("UTF-8"));
Jason Sams22534172009-08-04 16:58:20 -0700469 } catch (java.io.UnsupportedEncodingException e) {
470 throw new RuntimeException(e);
471 }
472 }
Jason Sams69f0d312009-08-03 18:11:17 -0700473
Tim Murrayc11e25c2013-04-09 11:01:01 -0700474 /**
475 * Only intended for use by generated reflected code.
476 *
477 */
Jason Sams69f0d312009-08-03 18:11:17 -0700478 public static class Builder {
Mathew Inwoodf0c90b12018-08-01 10:05:11 +0100479 @UnsupportedAppUsage
Jason Sams69f0d312009-08-03 18:11:17 -0700480 RenderScript mRS;
Jason Sams69f0d312009-08-03 18:11:17 -0700481
Mathew Inwoodf0c90b12018-08-01 10:05:11 +0100482 @UnsupportedAppUsage
Jason Sams69f0d312009-08-03 18:11:17 -0700483 Builder(RenderScript rs) {
484 mRS = rs;
485 }
Jason Sams69f0d312009-08-03 18:11:17 -0700486 }
487
Jason Sams2d71bc72010-03-26 16:06:43 -0700488
Jason Samsf64cca92013-04-19 12:56:37 -0700489 /**
490 * Only intended for use by generated reflected code.
491 *
492 */
Jason Sams2d71bc72010-03-26 16:06:43 -0700493 public static class FieldBase {
494 protected Element mElement;
Jason Sams2d71bc72010-03-26 16:06:43 -0700495 protected Allocation mAllocation;
496
497 protected void init(RenderScript rs, int dimx) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700498 mAllocation = Allocation.createSized(rs, mElement, dimx,
499 Allocation.USAGE_SCRIPT);
Jason Sams5476b452010-12-08 16:14:36 -0800500 }
501
502 protected void init(RenderScript rs, int dimx, int usages) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700503 mAllocation =
504 Allocation.createSized(rs, mElement, dimx,
505 Allocation.USAGE_SCRIPT | usages);
Jason Sams2d71bc72010-03-26 16:06:43 -0700506 }
507
508 protected FieldBase() {
509 }
510
511 public Element getElement() {
512 return mElement;
513 }
514
515 public Type getType() {
Jason Sams31a7e422010-10-26 13:09:17 -0700516 return mAllocation.getType();
Jason Sams2d71bc72010-03-26 16:06:43 -0700517 }
518
519 public Allocation getAllocation() {
520 return mAllocation;
521 }
522
523 //@Override
524 public void updateAllocation() {
525 }
Jason Sams2d71bc72010-03-26 16:06:43 -0700526 }
Tim Murrayfbfaa852012-12-14 16:01:58 -0800527
Jason Samsf64cca92013-04-19 12:56:37 -0700528
529 /**
Jason Sams8610f832015-03-30 17:01:10 -0700530 * Class for specifying the specifics about how a kernel will be
Miao Wang53fdcfb2016-03-29 15:14:21 -0700531 * launched.
Jason Sams8610f832015-03-30 17:01:10 -0700532 *
533 * This class can specify a potential range of cells on which to
534 * run a kernel. If no set is called for a dimension then this
535 * class will have no impact on that dimension when the kernel
536 * is executed.
537 *
Miao Wang53fdcfb2016-03-29 15:14:21 -0700538 * The forEach kernel launch will operate over the intersection of
539 * the dimensions.
Jason Sams8610f832015-03-30 17:01:10 -0700540 *
541 * Example:
542 * LaunchOptions with setX(5, 15)
543 * Allocation with dimension X=10, Y=10
Miao Wang53fdcfb2016-03-29 15:14:21 -0700544 * The resulting forEach run would execute over:
545 * x = 5 to 9 (inclusive) and
546 * y = 0 to 9 (inclusive).
Jason Sams8610f832015-03-30 17:01:10 -0700547 *
Jason Samsf64cca92013-04-19 12:56:37 -0700548 *
549 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800550 public static final class LaunchOptions {
Jason Samsf64cca92013-04-19 12:56:37 -0700551 private int xstart = 0;
552 private int ystart = 0;
553 private int xend = 0;
554 private int yend = 0;
555 private int zstart = 0;
556 private int zend = 0;
557 private int strategy;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800558
Jason Samsf64cca92013-04-19 12:56:37 -0700559 /**
Miao Wang53fdcfb2016-03-29 15:14:21 -0700560 * Set the X range. xstartArg is the lowest coordinate of the range,
561 * and xendArg-1 is the highest coordinate of the range.
Jason Samsf64cca92013-04-19 12:56:37 -0700562 *
563 * @param xstartArg Must be >= 0
Miao Wang53fdcfb2016-03-29 15:14:21 -0700564 * @param xendArg Must be > xstartArg
Jason Samsf64cca92013-04-19 12:56:37 -0700565 *
566 * @return LaunchOptions
567 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800568 public LaunchOptions setX(int xstartArg, int xendArg) {
Tim Murrayfbfaa852012-12-14 16:01:58 -0800569 if (xstartArg < 0 || xendArg <= xstartArg) {
570 throw new RSIllegalArgumentException("Invalid dimensions");
571 }
572 xstart = xstartArg;
573 xend = xendArg;
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800574 return this;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800575 }
576
Jason Samsf64cca92013-04-19 12:56:37 -0700577 /**
Miao Wang53fdcfb2016-03-29 15:14:21 -0700578 * Set the Y range. ystartArg is the lowest coordinate of the range,
579 * and yendArg-1 is the highest coordinate of the range.
Jason Samsf64cca92013-04-19 12:56:37 -0700580 *
581 * @param ystartArg Must be >= 0
Miao Wang53fdcfb2016-03-29 15:14:21 -0700582 * @param yendArg Must be > ystartArg
Jason Samsf64cca92013-04-19 12:56:37 -0700583 *
584 * @return LaunchOptions
585 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800586 public LaunchOptions setY(int ystartArg, int yendArg) {
Tim Murrayfbfaa852012-12-14 16:01:58 -0800587 if (ystartArg < 0 || yendArg <= ystartArg) {
588 throw new RSIllegalArgumentException("Invalid dimensions");
589 }
590 ystart = ystartArg;
591 yend = yendArg;
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800592 return this;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800593 }
594
Jason Samsf64cca92013-04-19 12:56:37 -0700595 /**
Miao Wang53fdcfb2016-03-29 15:14:21 -0700596 * Set the Z range. zstartArg is the lowest coordinate of the range,
597 * and zendArg-1 is the highest coordinate of the range.
Jason Samsf64cca92013-04-19 12:56:37 -0700598 *
599 * @param zstartArg Must be >= 0
Miao Wang53fdcfb2016-03-29 15:14:21 -0700600 * @param zendArg Must be > zstartArg
Jason Samsf64cca92013-04-19 12:56:37 -0700601 *
602 * @return LaunchOptions
603 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800604 public LaunchOptions setZ(int zstartArg, int zendArg) {
605 if (zstartArg < 0 || zendArg <= zstartArg) {
606 throw new RSIllegalArgumentException("Invalid dimensions");
607 }
608 zstart = zstartArg;
609 zend = zendArg;
610 return this;
611 }
612
613
Jason Samsf64cca92013-04-19 12:56:37 -0700614 /**
615 * Returns the current X start
616 *
617 * @return int current value
618 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800619 public int getXStart() {
620 return xstart;
621 }
Jason Samsf64cca92013-04-19 12:56:37 -0700622 /**
623 * Returns the current X end
624 *
625 * @return int current value
626 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800627 public int getXEnd() {
628 return xend;
629 }
Jason Samsf64cca92013-04-19 12:56:37 -0700630 /**
631 * Returns the current Y start
632 *
633 * @return int current value
634 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800635 public int getYStart() {
636 return ystart;
637 }
Jason Samsf64cca92013-04-19 12:56:37 -0700638 /**
639 * Returns the current Y end
640 *
641 * @return int current value
642 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800643 public int getYEnd() {
644 return yend;
645 }
Jason Samsf64cca92013-04-19 12:56:37 -0700646 /**
647 * Returns the current Z start
648 *
649 * @return int current value
650 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800651 public int getZStart() {
652 return zstart;
653 }
Jason Samsf64cca92013-04-19 12:56:37 -0700654 /**
655 * Returns the current Z end
656 *
657 * @return int current value
658 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800659 public int getZEnd() {
660 return zend;
661 }
Tim Murrayfbfaa852012-12-14 16:01:58 -0800662
663 }
Jason Sams69f0d312009-08-03 18:11:17 -0700664}