blob: f32a2f7ef48266460ac9507c0d9ccfcf9512a360 [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
Artur Satayev2ebb31c2020-01-08 12:24:36 +000019import android.compat.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.
Xusong Wang8b4548c2021-01-05 10:09:52 -080025 *
26 * @deprecated Renderscript has been deprecated in API level 31. Please refer to the <a
27 * href="https://developer.android.com/guide/topics/renderscript/migration-guide">migration
28 * guide</a> for the proposed alternatives.
Jason Sams69f0d312009-08-03 18:11:17 -070029 **/
Xusong Wang8b4548c2021-01-05 10:09:52 -080030@Deprecated
Jason Sams69f0d312009-08-03 18:11:17 -070031public class Script extends BaseObj {
Jason Sams08a81582012-09-18 12:32:10 -070032
33 /**
34 * KernelID is an identifier for a Script + root function pair. It is used
35 * as an identifier for ScriptGroup creation.
36 *
37 * This class should not be directly created. Instead use the method in the
38 * reflected or intrinsic code "getKernelID_funcname()".
39 *
40 */
41 public static final class KernelID extends BaseObj {
42 Script mScript;
43 int mSlot;
44 int mSig;
Tim Murray7a629fa2013-11-19 12:45:54 -080045 KernelID(long id, RenderScript rs, Script s, int slot, int sig) {
Jason Sams08a81582012-09-18 12:32:10 -070046 super(id, rs);
47 mScript = s;
48 mSlot = slot;
49 mSig = sig;
50 }
51 }
52
53 private final SparseArray<KernelID> mKIDs = new SparseArray<KernelID>();
54 /**
55 * Only to be used by generated reflected classes.
Jason Sams08a81582012-09-18 12:32:10 -070056 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -070057 protected KernelID createKernelID(int slot, int sig, Element ein,
58 Element eout) {
Jason Sams08a81582012-09-18 12:32:10 -070059 KernelID k = mKIDs.get(slot);
60 if (k != null) {
61 return k;
62 }
63
Tim Murray7a629fa2013-11-19 12:45:54 -080064 long id = mRS.nScriptKernelIDCreate(getID(mRS), slot, sig);
Jason Sams08a81582012-09-18 12:32:10 -070065 if (id == 0) {
66 throw new RSDriverException("Failed to create KernelID");
67 }
68
69 k = new KernelID(id, mRS, this, slot, sig);
70 mKIDs.put(slot, k);
71 return k;
72 }
73
74 /**
Yang Nibe392ad2015-01-23 17:16:02 -080075 * InvokeID is an identifier for an invoke function. It is used
76 * as an identifier for ScriptGroup creation.
77 *
78 * This class should not be directly created. Instead use the method in the
79 * reflected or intrinsic code "getInvokeID_funcname()".
80 *
81 */
82 public static final class InvokeID extends BaseObj {
83 Script mScript;
84 int mSlot;
85 InvokeID(long id, RenderScript rs, Script s, int slot) {
86 super(id, rs);
87 mScript = s;
88 mSlot = slot;
89 }
90 }
91
92 private final SparseArray<InvokeID> mIIDs = new SparseArray<InvokeID>();
93 /**
Yang Nibe392ad2015-01-23 17:16:02 -080094 * Only to be used by generated reflected classes.
95 */
96 protected InvokeID createInvokeID(int slot) {
97 InvokeID i = mIIDs.get(slot);
98 if (i != null) {
99 return i;
100 }
101
102 long id = mRS.nScriptInvokeIDCreate(getID(mRS), slot);
103 if (id == 0) {
104 throw new RSDriverException("Failed to create KernelID");
105 }
106
107 i = new InvokeID(id, mRS, this, slot);
108 mIIDs.put(slot, i);
109 return i;
110 }
111
112 /**
Jason Sams08a81582012-09-18 12:32:10 -0700113 * FieldID is an identifier for a Script + exported field pair. It is used
114 * as an identifier for ScriptGroup creation.
115 *
116 * This class should not be directly created. Instead use the method in the
117 * reflected or intrinsic code "getFieldID_funcname()".
118 *
119 */
120 public static final class FieldID extends BaseObj {
121 Script mScript;
122 int mSlot;
Tim Murray7a629fa2013-11-19 12:45:54 -0800123 FieldID(long id, RenderScript rs, Script s, int slot) {
Jason Sams08a81582012-09-18 12:32:10 -0700124 super(id, rs);
125 mScript = s;
126 mSlot = slot;
127 }
128 }
129
130 private final SparseArray<FieldID> mFIDs = new SparseArray();
131 /**
132 * Only to be used by generated reflected classes.
Jason Sams08a81582012-09-18 12:32:10 -0700133 */
134 protected FieldID createFieldID(int slot, Element e) {
135 FieldID f = mFIDs.get(slot);
136 if (f != null) {
137 return f;
138 }
139
Tim Murray7a629fa2013-11-19 12:45:54 -0800140 long id = mRS.nScriptFieldIDCreate(getID(mRS), slot);
Jason Sams08a81582012-09-18 12:32:10 -0700141 if (id == 0) {
142 throw new RSDriverException("Failed to create FieldID");
143 }
144
145 f = new FieldID(id, mRS, this, slot);
146 mFIDs.put(slot, f);
147 return f;
148 }
149
150
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700151 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800152 * Only intended for use by generated reflected code.
153 *
Jason Sams67e3d202011-01-09 13:49:01 -0800154 */
Jason Sams2d71bc72010-03-26 16:06:43 -0700155 protected void invoke(int slot) {
Jason Samse07694b2012-04-03 15:36:36 -0700156 mRS.nScriptInvoke(getID(mRS), slot);
Jason Sams2d71bc72010-03-26 16:06:43 -0700157 }
158
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700159 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800160 * Only intended for use by generated reflected code.
161 *
Jason Sams67e3d202011-01-09 13:49:01 -0800162 */
Jason Sams96ed4cf2010-06-15 12:15:57 -0700163 protected void invoke(int slot, FieldPacker v) {
164 if (v != null) {
Jason Samse07694b2012-04-03 15:36:36 -0700165 mRS.nScriptInvokeV(getID(mRS), slot, v.getData());
Jason Sams96ed4cf2010-06-15 12:15:57 -0700166 } else {
Jason Samse07694b2012-04-03 15:36:36 -0700167 mRS.nScriptInvoke(getID(mRS), slot);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700168 }
Jason Sams4d339932010-05-11 14:03:58 -0700169 }
170
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700171 /**
Jason Sams6e494d32011-04-27 16:33:11 -0700172 * Only intended for use by generated reflected code.
173 *
Jason Sams6e494d32011-04-27 16:33:11 -0700174 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700175 protected void forEach(int slot, Allocation ain, Allocation aout,
176 FieldPacker v) {
177 forEach(slot, ain, aout, v, null);
Jason Sams6e494d32011-04-27 16:33:11 -0700178 }
179
Jason Samsf64cca92013-04-19 12:56:37 -0700180 /**
181 * Only intended for use by generated reflected code.
182 *
Jason Samsf64cca92013-04-19 12:56:37 -0700183 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700184 protected void forEach(int slot, Allocation ain, Allocation aout,
185 FieldPacker v, LaunchOptions sc) {
186 // TODO: Is this necessary if nScriptForEach calls validate as well?
Jason Sams678cc7f2014-03-05 16:09:02 -0800187 mRS.validate();
188 mRS.validateObject(ain);
189 mRS.validateObject(aout);
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700190
Jason Samsd1516df2015-05-05 18:00:34 -0700191 if (ain == null && aout == null && sc == null) {
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800192 throw new RSIllegalArgumentException(
Jason Samsd1516df2015-05-05 18:00:34 -0700193 "At least one of input allocation, output allocation, or LaunchOptions is required to be non-null.");
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800194 }
Tim Murrayba9dd062013-02-12 16:22:34 -0800195
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700196 long[] in_ids = null;
Stephen Hinesc9c7daf2014-08-13 17:32:19 +0000197 if (ain != null) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700198 in_ids = mInIdsBuffer;
199 in_ids[0] = ain.getID(mRS);
Stephen Hinesc9c7daf2014-08-13 17:32:19 +0000200 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700201
Tim Murray7a629fa2013-11-19 12:45:54 -0800202 long out_id = 0;
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800203 if (aout != null) {
204 out_id = aout.getID(mRS);
205 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700206
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800207 byte[] params = null;
208 if (v != null) {
209 params = v.getData();
210 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700211
212 int[] limits = null;
213 if (sc != null) {
214 limits = new int[6];
215
216 limits[0] = sc.xstart;
217 limits[1] = sc.xend;
218 limits[2] = sc.ystart;
219 limits[3] = sc.yend;
220 limits[4] = sc.zstart;
221 limits[5] = sc.zend;
222 }
223
224 mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits);
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800225 }
Jason Sams4d339932010-05-11 14:03:58 -0700226
Chris Wailes94961062014-06-11 12:01:28 -0700227 /**
228 * Only intended for use by generated reflected code.
Chris Wailes94961062014-06-11 12:01:28 -0700229 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700230 protected void forEach(int slot, Allocation[] ains, Allocation aout,
231 FieldPacker v) {
Jason Sams6a420b52015-03-30 15:31:26 -0700232
233 // FieldPacker is kept here to support regular params in the future.
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700234 forEach(slot, ains, aout, v, null);
Chris Wailes94961062014-06-11 12:01:28 -0700235 }
236
237 /**
238 * Only intended for use by generated reflected code.
Chris Wailes94961062014-06-11 12:01:28 -0700239 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700240 protected void forEach(int slot, Allocation[] ains, Allocation aout,
241 FieldPacker v, LaunchOptions sc) {
242 // TODO: Is this necessary if nScriptForEach calls validate as well?
Jason Sams6a420b52015-03-30 15:31:26 -0700243 // FieldPacker is kept here to support regular params in the future.
Chris Wailes94961062014-06-11 12:01:28 -0700244 mRS.validate();
Andreas Gampec8ddcdd2015-03-15 15:57:30 -0700245 if (ains != null) {
246 for (Allocation ain : ains) {
247 mRS.validateObject(ain);
248 }
Chris Wailes94961062014-06-11 12:01:28 -0700249 }
Stephen Hinesc9c7daf2014-08-13 17:32:19 +0000250 mRS.validateObject(aout);
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700251
Chris Wailes94961062014-06-11 12:01:28 -0700252 if (ains == null && aout == null) {
253 throw new RSIllegalArgumentException(
254 "At least one of ain or aout is required to be non-null.");
255 }
256
Andreas Gampead555f92015-03-17 20:05:46 -0700257 long[] in_ids;
258 if (ains != null) {
259 in_ids = new long[ains.length];
260 for (int index = 0; index < ains.length; ++index) {
261 in_ids[index] = ains[index].getID(mRS);
262 }
263 } else {
264 in_ids = null;
Chris Wailes94961062014-06-11 12:01:28 -0700265 }
266
267 long out_id = 0;
268 if (aout != null) {
269 out_id = aout.getID(mRS);
270 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700271
Chris Wailes94961062014-06-11 12:01:28 -0700272 byte[] params = null;
273 if (v != null) {
274 params = v.getData();
275 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700276
277 int[] limits = null;
278 if (sc != null) {
279 limits = new int[6];
280
281 limits[0] = sc.xstart;
282 limits[1] = sc.xend;
283 limits[2] = sc.ystart;
284 limits[3] = sc.yend;
285 limits[4] = sc.zstart;
286 limits[5] = sc.zend;
287 }
288
289 mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits);
Chris Wailes94961062014-06-11 12:01:28 -0700290 }
291
Matt Wala36eb1f72015-07-20 15:35:27 -0700292 /**
David Gross26ef7a732016-01-12 12:19:15 -0800293 * Only intended for use by generated reflected code. (General reduction)
294 *
David Gross26ef7a732016-01-12 12:19:15 -0800295 */
296 protected void reduce(int slot, Allocation[] ains, Allocation aout, LaunchOptions sc) {
297 mRS.validate();
298 if (ains == null || ains.length < 1) {
299 throw new RSIllegalArgumentException(
300 "At least one input is required.");
301 }
302 if (aout == null) {
303 throw new RSIllegalArgumentException(
304 "aout is required to be non-null.");
305 }
306 for (Allocation ain : ains) {
307 mRS.validateObject(ain);
308 }
309
310 long[] in_ids = new long[ains.length];
311 for (int index = 0; index < ains.length; ++index) {
312 in_ids[index] = ains[index].getID(mRS);
313 }
314 long out_id = aout.getID(mRS);
315
316 int[] limits = null;
317 if (sc != null) {
318 limits = new int[6];
319
320 limits[0] = sc.xstart;
321 limits[1] = sc.xend;
322 limits[2] = sc.ystart;
323 limits[3] = sc.yend;
324 limits[4] = sc.zstart;
325 limits[5] = sc.zend;
326 }
327
David Gross4a457852016-06-02 14:46:55 -0700328 mRS.nScriptReduce(getID(mRS), slot, in_ids, out_id, limits);
David Gross26ef7a732016-01-12 12:19:15 -0800329 }
330
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700331 long[] mInIdsBuffer;
332
Tim Murray7a629fa2013-11-19 12:45:54 -0800333 Script(long id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -0700334 super(id, rs);
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700335
336 mInIdsBuffer = new long[1];
Yang Ni6484b6b2016-03-24 09:40:32 -0700337
338 /* The constructors for the derived classes (including ScriptIntrinsic
339 * derived classes and ScriptC derived classes generated by Slang
340 * reflection) seem to be simple enough, so we just put the guard.open()
341 * call here, rather than in the end of the constructor for the derived
342 * class. This, of course, assumes the derived constructor would not
343 * throw any exception after calling this constructor.
344 *
345 * If new derived classes are added with more complicated constructors
346 * that throw exceptions, this call has to be (duplicated and) moved
347 * to the end of each derived class constructor.
348 */
349 guard.open("destroy");
Jason Sams69f0d312009-08-03 18:11:17 -0700350 }
351
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700352 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800353 * Only intended for use by generated reflected code.
354 *
Jason Sams67e3d202011-01-09 13:49:01 -0800355 */
Jason Sams69f0d312009-08-03 18:11:17 -0700356 public void bindAllocation(Allocation va, int slot) {
Jason Sams771bebb2009-12-07 12:40:12 -0800357 mRS.validate();
Jason Sams678cc7f2014-03-05 16:09:02 -0800358 mRS.validateObject(va);
Jason Sams4d339932010-05-11 14:03:58 -0700359 if (va != null) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700360
361 android.content.Context context = mRS.getApplicationContext();
362
363 if (context.getApplicationInfo().targetSdkVersion >= 20) {
Jason Samscf9c8942014-01-14 16:18:14 -0800364 final Type t = va.mType;
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700365 if (t.hasMipmaps() || t.hasFaces() || (t.getY() != 0) ||
366 (t.getZ() != 0)) {
367
Jason Samscf9c8942014-01-14 16:18:14 -0800368 throw new RSIllegalArgumentException(
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700369 "API 20+ only allows simple 1D allocations to be " +
370 "used with bind.");
Jason Samscf9c8942014-01-14 16:18:14 -0800371 }
372 }
Jason Samse07694b2012-04-03 15:36:36 -0700373 mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot);
Jason Sams4d339932010-05-11 14:03:58 -0700374 } else {
Jason Samse07694b2012-04-03 15:36:36 -0700375 mRS.nScriptBindAllocation(getID(mRS), 0, slot);
Jason Sams4d339932010-05-11 14:03:58 -0700376 }
377 }
378
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700379 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800380 * Only intended for use by generated reflected code.
381 *
Jason Sams67e3d202011-01-09 13:49:01 -0800382 */
Jason Sams4d339932010-05-11 14:03:58 -0700383 public void setVar(int index, float v) {
Jason Samse07694b2012-04-03 15:36:36 -0700384 mRS.nScriptSetVarF(getID(mRS), index, v);
Jason Sams4d339932010-05-11 14:03:58 -0700385 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700386 public float getVarF(int index) {
387 return mRS.nScriptGetVarF(getID(mRS), index);
388 }
Jason Sams4d339932010-05-11 14:03:58 -0700389
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700390 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800391 * Only intended for use by generated reflected code.
392 *
Jason Sams67e3d202011-01-09 13:49:01 -0800393 */
Stephen Hinesca54ec32010-09-20 17:20:30 -0700394 public void setVar(int index, double v) {
Jason Samse07694b2012-04-03 15:36:36 -0700395 mRS.nScriptSetVarD(getID(mRS), index, v);
Stephen Hinesca54ec32010-09-20 17:20:30 -0700396 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700397 public double getVarD(int index) {
398 return mRS.nScriptGetVarD(getID(mRS), index);
399 }
Stephen Hinesca54ec32010-09-20 17:20:30 -0700400
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700401 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800402 * Only intended for use by generated reflected code.
403 *
Jason Sams67e3d202011-01-09 13:49:01 -0800404 */
Jason Sams4d339932010-05-11 14:03:58 -0700405 public void setVar(int index, int v) {
Jason Samse07694b2012-04-03 15:36:36 -0700406 mRS.nScriptSetVarI(getID(mRS), index, v);
Jason Sams4d339932010-05-11 14:03:58 -0700407 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700408 public int getVarI(int index) {
409 return mRS.nScriptGetVarI(getID(mRS), index);
410 }
411
Jason Sams4d339932010-05-11 14:03:58 -0700412
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700413 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800414 * Only intended for use by generated reflected code.
415 *
Jason Sams67e3d202011-01-09 13:49:01 -0800416 */
Stephen Hines031ec58c2010-10-11 10:54:21 -0700417 public void setVar(int index, long v) {
Jason Samse07694b2012-04-03 15:36:36 -0700418 mRS.nScriptSetVarJ(getID(mRS), index, v);
Stephen Hines031ec58c2010-10-11 10:54:21 -0700419 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700420 public long getVarJ(int index) {
421 return mRS.nScriptGetVarJ(getID(mRS), index);
422 }
423
Stephen Hines031ec58c2010-10-11 10:54:21 -0700424
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700425 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800426 * Only intended for use by generated reflected code.
427 *
Jason Sams67e3d202011-01-09 13:49:01 -0800428 */
Jason Sams0b9a22c2010-07-02 15:35:19 -0700429 public void setVar(int index, boolean v) {
Jason Samse07694b2012-04-03 15:36:36 -0700430 mRS.nScriptSetVarI(getID(mRS), index, v ? 1 : 0);
Jason Sams0b9a22c2010-07-02 15:35:19 -0700431 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700432 public boolean getVarB(int index) {
433 return mRS.nScriptGetVarI(getID(mRS), index) > 0 ? true : false;
434 }
Jason Sams0b9a22c2010-07-02 15:35:19 -0700435
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700436 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800437 * Only intended for use by generated reflected code.
438 *
Jason Sams67e3d202011-01-09 13:49:01 -0800439 */
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800440 public void setVar(int index, BaseObj o) {
Jason Sams678cc7f2014-03-05 16:09:02 -0800441 mRS.validate();
442 mRS.validateObject(o);
Jason Samse07694b2012-04-03 15:36:36 -0700443 mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : o.getID(mRS));
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800444 }
445
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 Sams4d339932010-05-11 14:03:58 -0700450 public void setVar(int index, FieldPacker v) {
Jason Samse07694b2012-04-03 15:36:36 -0700451 mRS.nScriptSetVarV(getID(mRS), index, v.getData());
Jason Sams69f0d312009-08-03 18:11:17 -0700452 }
453
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700454 /**
Stephen Hinesadeb8092012-04-20 14:26:06 -0700455 * Only intended for use by generated reflected code.
456 *
Stephen Hinesadeb8092012-04-20 14:26:06 -0700457 */
458 public void setVar(int index, FieldPacker v, Element e, int[] dims) {
459 mRS.nScriptSetVarVE(getID(mRS), index, v.getData(), e.getID(mRS), dims);
460 }
461
Jason Samsf64cca92013-04-19 12:56:37 -0700462 /**
463 * Only intended for use by generated reflected code.
464 *
Jason Samsf64cca92013-04-19 12:56:37 -0700465 */
Tim Murray7c4caad2013-04-10 16:21:40 -0700466 public void getVarV(int index, FieldPacker v) {
467 mRS.nScriptGetVarV(getID(mRS), index, v.getData());
468 }
469
Jason Sams22534172009-08-04 16:58:20 -0700470 public void setTimeZone(String timeZone) {
Jason Sams771bebb2009-12-07 12:40:12 -0800471 mRS.validate();
Jason Sams22534172009-08-04 16:58:20 -0700472 try {
Jason Samse07694b2012-04-03 15:36:36 -0700473 mRS.nScriptSetTimeZone(getID(mRS), timeZone.getBytes("UTF-8"));
Jason Sams22534172009-08-04 16:58:20 -0700474 } catch (java.io.UnsupportedEncodingException e) {
475 throw new RuntimeException(e);
476 }
477 }
Jason Sams69f0d312009-08-03 18:11:17 -0700478
Tim Murrayc11e25c2013-04-09 11:01:01 -0700479 /**
480 * Only intended for use by generated reflected code.
481 *
482 */
Jason Sams69f0d312009-08-03 18:11:17 -0700483 public static class Builder {
Mathew Inwood15324472018-08-06 11:18:49 +0100484 @UnsupportedAppUsage
Jason Sams69f0d312009-08-03 18:11:17 -0700485 RenderScript mRS;
Jason Sams69f0d312009-08-03 18:11:17 -0700486
Mathew Inwood15324472018-08-06 11:18:49 +0100487 @UnsupportedAppUsage
Jason Sams69f0d312009-08-03 18:11:17 -0700488 Builder(RenderScript rs) {
489 mRS = rs;
490 }
Jason Sams69f0d312009-08-03 18:11:17 -0700491 }
492
Jason Sams2d71bc72010-03-26 16:06:43 -0700493
Jason Samsf64cca92013-04-19 12:56:37 -0700494 /**
495 * Only intended for use by generated reflected code.
496 *
497 */
Jason Sams2d71bc72010-03-26 16:06:43 -0700498 public static class FieldBase {
499 protected Element mElement;
Jason Sams2d71bc72010-03-26 16:06:43 -0700500 protected Allocation mAllocation;
501
502 protected void init(RenderScript rs, int dimx) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700503 mAllocation = Allocation.createSized(rs, mElement, dimx,
504 Allocation.USAGE_SCRIPT);
Jason Sams5476b452010-12-08 16:14:36 -0800505 }
506
507 protected void init(RenderScript rs, int dimx, int usages) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700508 mAllocation =
509 Allocation.createSized(rs, mElement, dimx,
510 Allocation.USAGE_SCRIPT | usages);
Jason Sams2d71bc72010-03-26 16:06:43 -0700511 }
512
513 protected FieldBase() {
514 }
515
516 public Element getElement() {
517 return mElement;
518 }
519
520 public Type getType() {
Jason Sams31a7e422010-10-26 13:09:17 -0700521 return mAllocation.getType();
Jason Sams2d71bc72010-03-26 16:06:43 -0700522 }
523
524 public Allocation getAllocation() {
525 return mAllocation;
526 }
527
528 //@Override
529 public void updateAllocation() {
530 }
Jason Sams2d71bc72010-03-26 16:06:43 -0700531 }
Tim Murrayfbfaa852012-12-14 16:01:58 -0800532
Jason Samsf64cca92013-04-19 12:56:37 -0700533
534 /**
Jason Sams8610f832015-03-30 17:01:10 -0700535 * Class for specifying the specifics about how a kernel will be
Miao Wang53fdcfb2016-03-29 15:14:21 -0700536 * launched.
Jason Sams8610f832015-03-30 17:01:10 -0700537 *
538 * This class can specify a potential range of cells on which to
539 * run a kernel. If no set is called for a dimension then this
540 * class will have no impact on that dimension when the kernel
541 * is executed.
542 *
Miao Wang53fdcfb2016-03-29 15:14:21 -0700543 * The forEach kernel launch will operate over the intersection of
544 * the dimensions.
Jason Sams8610f832015-03-30 17:01:10 -0700545 *
546 * Example:
547 * LaunchOptions with setX(5, 15)
548 * Allocation with dimension X=10, Y=10
Miao Wang53fdcfb2016-03-29 15:14:21 -0700549 * The resulting forEach run would execute over:
550 * x = 5 to 9 (inclusive) and
551 * y = 0 to 9 (inclusive).
Jason Sams8610f832015-03-30 17:01:10 -0700552 *
Jason Samsf64cca92013-04-19 12:56:37 -0700553 *
554 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800555 public static final class LaunchOptions {
Jason Samsf64cca92013-04-19 12:56:37 -0700556 private int xstart = 0;
557 private int ystart = 0;
558 private int xend = 0;
559 private int yend = 0;
560 private int zstart = 0;
561 private int zend = 0;
562 private int strategy;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800563
Jason Samsf64cca92013-04-19 12:56:37 -0700564 /**
Miao Wang53fdcfb2016-03-29 15:14:21 -0700565 * Set the X range. xstartArg is the lowest coordinate of the range,
566 * and xendArg-1 is the highest coordinate of the range.
Jason Samsf64cca92013-04-19 12:56:37 -0700567 *
568 * @param xstartArg Must be >= 0
Miao Wang53fdcfb2016-03-29 15:14:21 -0700569 * @param xendArg Must be > xstartArg
Jason Samsf64cca92013-04-19 12:56:37 -0700570 *
571 * @return LaunchOptions
572 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800573 public LaunchOptions setX(int xstartArg, int xendArg) {
Tim Murrayfbfaa852012-12-14 16:01:58 -0800574 if (xstartArg < 0 || xendArg <= xstartArg) {
575 throw new RSIllegalArgumentException("Invalid dimensions");
576 }
577 xstart = xstartArg;
578 xend = xendArg;
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800579 return this;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800580 }
581
Jason Samsf64cca92013-04-19 12:56:37 -0700582 /**
Miao Wang53fdcfb2016-03-29 15:14:21 -0700583 * Set the Y range. ystartArg is the lowest coordinate of the range,
584 * and yendArg-1 is the highest coordinate of the range.
Jason Samsf64cca92013-04-19 12:56:37 -0700585 *
586 * @param ystartArg Must be >= 0
Miao Wang53fdcfb2016-03-29 15:14:21 -0700587 * @param yendArg Must be > ystartArg
Jason Samsf64cca92013-04-19 12:56:37 -0700588 *
589 * @return LaunchOptions
590 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800591 public LaunchOptions setY(int ystartArg, int yendArg) {
Tim Murrayfbfaa852012-12-14 16:01:58 -0800592 if (ystartArg < 0 || yendArg <= ystartArg) {
593 throw new RSIllegalArgumentException("Invalid dimensions");
594 }
595 ystart = ystartArg;
596 yend = yendArg;
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800597 return this;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800598 }
599
Jason Samsf64cca92013-04-19 12:56:37 -0700600 /**
Miao Wang53fdcfb2016-03-29 15:14:21 -0700601 * Set the Z range. zstartArg is the lowest coordinate of the range,
602 * and zendArg-1 is the highest coordinate of the range.
Jason Samsf64cca92013-04-19 12:56:37 -0700603 *
604 * @param zstartArg Must be >= 0
Miao Wang53fdcfb2016-03-29 15:14:21 -0700605 * @param zendArg Must be > zstartArg
Jason Samsf64cca92013-04-19 12:56:37 -0700606 *
607 * @return LaunchOptions
608 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800609 public LaunchOptions setZ(int zstartArg, int zendArg) {
610 if (zstartArg < 0 || zendArg <= zstartArg) {
611 throw new RSIllegalArgumentException("Invalid dimensions");
612 }
613 zstart = zstartArg;
614 zend = zendArg;
615 return this;
616 }
617
618
Jason Samsf64cca92013-04-19 12:56:37 -0700619 /**
620 * Returns the current X start
621 *
622 * @return int current value
623 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800624 public int getXStart() {
625 return xstart;
626 }
Jason Samsf64cca92013-04-19 12:56:37 -0700627 /**
628 * Returns the current X end
629 *
630 * @return int current value
631 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800632 public int getXEnd() {
633 return xend;
634 }
Jason Samsf64cca92013-04-19 12:56:37 -0700635 /**
636 * Returns the current Y start
637 *
638 * @return int current value
639 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800640 public int getYStart() {
641 return ystart;
642 }
Jason Samsf64cca92013-04-19 12:56:37 -0700643 /**
644 * Returns the current Y end
645 *
646 * @return int current value
647 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800648 public int getYEnd() {
649 return yend;
650 }
Jason Samsf64cca92013-04-19 12:56:37 -0700651 /**
652 * Returns the current Z start
653 *
654 * @return int current value
655 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800656 public int getZStart() {
657 return zstart;
658 }
Jason Samsf64cca92013-04-19 12:56:37 -0700659 /**
660 * Returns the current Z end
661 *
662 * @return int current value
663 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800664 public int getZEnd() {
665 return zend;
666 }
Tim Murrayfbfaa852012-12-14 16:01:58 -0800667
668 }
Jason Sams69f0d312009-08-03 18:11:17 -0700669}