blob: 83aeedd9540edb8a5b38fff359ed3cec736cf1ca [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 * @hide Pending API review
70 * 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 /**
89 * @hide Pending API review
90 * Only to be used by generated reflected classes.
91 */
92 protected InvokeID createInvokeID(int slot) {
93 InvokeID i = mIIDs.get(slot);
94 if (i != null) {
95 return i;
96 }
97
98 long id = mRS.nScriptInvokeIDCreate(getID(mRS), slot);
99 if (id == 0) {
100 throw new RSDriverException("Failed to create KernelID");
101 }
102
103 i = new InvokeID(id, mRS, this, slot);
104 mIIDs.put(slot, i);
105 return i;
106 }
107
108 /**
Jason Sams08a81582012-09-18 12:32:10 -0700109 * FieldID is an identifier for a Script + exported field pair. It is used
110 * as an identifier for ScriptGroup creation.
111 *
112 * This class should not be directly created. Instead use the method in the
113 * reflected or intrinsic code "getFieldID_funcname()".
114 *
115 */
116 public static final class FieldID extends BaseObj {
117 Script mScript;
118 int mSlot;
Tim Murray7a629fa2013-11-19 12:45:54 -0800119 FieldID(long id, RenderScript rs, Script s, int slot) {
Jason Sams08a81582012-09-18 12:32:10 -0700120 super(id, rs);
121 mScript = s;
122 mSlot = slot;
123 }
124 }
125
126 private final SparseArray<FieldID> mFIDs = new SparseArray();
127 /**
128 * Only to be used by generated reflected classes.
Jason Sams08a81582012-09-18 12:32:10 -0700129 */
130 protected FieldID createFieldID(int slot, Element e) {
131 FieldID f = mFIDs.get(slot);
132 if (f != null) {
133 return f;
134 }
135
Tim Murray7a629fa2013-11-19 12:45:54 -0800136 long id = mRS.nScriptFieldIDCreate(getID(mRS), slot);
Jason Sams08a81582012-09-18 12:32:10 -0700137 if (id == 0) {
138 throw new RSDriverException("Failed to create FieldID");
139 }
140
141 f = new FieldID(id, mRS, this, slot);
142 mFIDs.put(slot, f);
143 return f;
144 }
145
146
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700147 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800148 * Only intended for use by generated reflected code.
149 *
Jason Sams67e3d202011-01-09 13:49:01 -0800150 */
Jason Sams2d71bc72010-03-26 16:06:43 -0700151 protected void invoke(int slot) {
Jason Samse07694b2012-04-03 15:36:36 -0700152 mRS.nScriptInvoke(getID(mRS), slot);
Jason Sams2d71bc72010-03-26 16:06:43 -0700153 }
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 *
Jason Sams67e3d202011-01-09 13:49:01 -0800158 */
Jason Sams96ed4cf2010-06-15 12:15:57 -0700159 protected void invoke(int slot, FieldPacker v) {
160 if (v != null) {
Jason Samse07694b2012-04-03 15:36:36 -0700161 mRS.nScriptInvokeV(getID(mRS), slot, v.getData());
Jason Sams96ed4cf2010-06-15 12:15:57 -0700162 } else {
Jason Samse07694b2012-04-03 15:36:36 -0700163 mRS.nScriptInvoke(getID(mRS), slot);
Jason Sams96ed4cf2010-06-15 12:15:57 -0700164 }
Jason Sams4d339932010-05-11 14:03:58 -0700165 }
166
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700167 /**
Jason Sams6e494d32011-04-27 16:33:11 -0700168 * Only intended for use by generated reflected code.
169 *
Jason Sams6e494d32011-04-27 16:33:11 -0700170 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700171 protected void forEach(int slot, Allocation ain, Allocation aout,
172 FieldPacker v) {
173 forEach(slot, ain, aout, v, null);
Jason Sams6e494d32011-04-27 16:33:11 -0700174 }
175
Jason Samsf64cca92013-04-19 12:56:37 -0700176 /**
177 * Only intended for use by generated reflected code.
178 *
Jason Samsf64cca92013-04-19 12:56:37 -0700179 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700180 protected void forEach(int slot, Allocation ain, Allocation aout,
181 FieldPacker v, LaunchOptions sc) {
182 // TODO: Is this necessary if nScriptForEach calls validate as well?
Jason Sams678cc7f2014-03-05 16:09:02 -0800183 mRS.validate();
184 mRS.validateObject(ain);
185 mRS.validateObject(aout);
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700186
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800187 if (ain == null && aout == null) {
188 throw new RSIllegalArgumentException(
189 "At least one of ain or aout is required to be non-null.");
190 }
Tim Murrayba9dd062013-02-12 16:22:34 -0800191
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700192 long[] in_ids = null;
Stephen Hinesc9c7daf2014-08-13 17:32:19 +0000193 if (ain != null) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700194 in_ids = mInIdsBuffer;
195 in_ids[0] = ain.getID(mRS);
Stephen Hinesc9c7daf2014-08-13 17:32:19 +0000196 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700197
Tim Murray7a629fa2013-11-19 12:45:54 -0800198 long out_id = 0;
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800199 if (aout != null) {
200 out_id = aout.getID(mRS);
201 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700202
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800203 byte[] params = null;
204 if (v != null) {
205 params = v.getData();
206 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700207
208 int[] limits = null;
209 if (sc != null) {
210 limits = new int[6];
211
212 limits[0] = sc.xstart;
213 limits[1] = sc.xend;
214 limits[2] = sc.ystart;
215 limits[3] = sc.yend;
216 limits[4] = sc.zstart;
217 limits[5] = sc.zend;
218 }
219
220 mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits);
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800221 }
Jason Sams4d339932010-05-11 14:03:58 -0700222
Chris Wailes94961062014-06-11 12:01:28 -0700223 /**
224 * Only intended for use by generated reflected code.
225 *
226 * @hide
227 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700228 protected void forEach(int slot, Allocation[] ains, Allocation aout,
229 FieldPacker v) {
230 forEach(slot, ains, aout, v, null);
Chris Wailes94961062014-06-11 12:01:28 -0700231 }
232
233 /**
234 * Only intended for use by generated reflected code.
235 *
236 * @hide
237 */
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700238 protected void forEach(int slot, Allocation[] ains, Allocation aout,
239 FieldPacker v, LaunchOptions sc) {
240 // TODO: Is this necessary if nScriptForEach calls validate as well?
Chris Wailes94961062014-06-11 12:01:28 -0700241 mRS.validate();
Andreas Gampec8ddcdd2015-03-15 15:57:30 -0700242 if (ains != null) {
243 for (Allocation ain : ains) {
244 mRS.validateObject(ain);
245 }
Chris Wailes94961062014-06-11 12:01:28 -0700246 }
Stephen Hinesc9c7daf2014-08-13 17:32:19 +0000247 mRS.validateObject(aout);
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700248
Chris Wailes94961062014-06-11 12:01:28 -0700249 if (ains == null && aout == null) {
250 throw new RSIllegalArgumentException(
251 "At least one of ain or aout is required to be non-null.");
252 }
253
Chris Wailes94961062014-06-11 12:01:28 -0700254 long[] 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
259 long out_id = 0;
260 if (aout != null) {
261 out_id = aout.getID(mRS);
262 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700263
Chris Wailes94961062014-06-11 12:01:28 -0700264 byte[] params = null;
265 if (v != null) {
266 params = v.getData();
267 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700268
269 int[] limits = null;
270 if (sc != null) {
271 limits = new int[6];
272
273 limits[0] = sc.xstart;
274 limits[1] = sc.xend;
275 limits[2] = sc.ystart;
276 limits[3] = sc.yend;
277 limits[4] = sc.zstart;
278 limits[5] = sc.zend;
279 }
280
281 mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits);
Chris Wailes94961062014-06-11 12:01:28 -0700282 }
283
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700284 long[] mInIdsBuffer;
285
Tim Murray7a629fa2013-11-19 12:45:54 -0800286 Script(long id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -0700287 super(id, rs);
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700288
289 mInIdsBuffer = new long[1];
Jason Sams69f0d312009-08-03 18:11:17 -0700290 }
291
Jason Sams67e3d202011-01-09 13:49:01 -0800292
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700293 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800294 * Only intended for use by generated reflected code.
295 *
Jason Sams67e3d202011-01-09 13:49:01 -0800296 */
Jason Sams69f0d312009-08-03 18:11:17 -0700297 public void bindAllocation(Allocation va, int slot) {
Jason Sams771bebb2009-12-07 12:40:12 -0800298 mRS.validate();
Jason Sams678cc7f2014-03-05 16:09:02 -0800299 mRS.validateObject(va);
Jason Sams4d339932010-05-11 14:03:58 -0700300 if (va != null) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700301
302 android.content.Context context = mRS.getApplicationContext();
303
304 if (context.getApplicationInfo().targetSdkVersion >= 20) {
Jason Samscf9c8942014-01-14 16:18:14 -0800305 final Type t = va.mType;
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700306 if (t.hasMipmaps() || t.hasFaces() || (t.getY() != 0) ||
307 (t.getZ() != 0)) {
308
Jason Samscf9c8942014-01-14 16:18:14 -0800309 throw new RSIllegalArgumentException(
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700310 "API 20+ only allows simple 1D allocations to be " +
311 "used with bind.");
Jason Samscf9c8942014-01-14 16:18:14 -0800312 }
313 }
Jason Samse07694b2012-04-03 15:36:36 -0700314 mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot);
Jason Sams4d339932010-05-11 14:03:58 -0700315 } else {
Jason Samse07694b2012-04-03 15:36:36 -0700316 mRS.nScriptBindAllocation(getID(mRS), 0, slot);
Jason Sams4d339932010-05-11 14:03:58 -0700317 }
318 }
319
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700320 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800321 * Only intended for use by generated reflected code.
322 *
Jason Sams67e3d202011-01-09 13:49:01 -0800323 */
Jason Sams4d339932010-05-11 14:03:58 -0700324 public void setVar(int index, float v) {
Jason Samse07694b2012-04-03 15:36:36 -0700325 mRS.nScriptSetVarF(getID(mRS), index, v);
Jason Sams4d339932010-05-11 14:03:58 -0700326 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700327 public float getVarF(int index) {
328 return mRS.nScriptGetVarF(getID(mRS), index);
329 }
Jason Sams4d339932010-05-11 14:03:58 -0700330
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700331 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800332 * Only intended for use by generated reflected code.
333 *
Jason Sams67e3d202011-01-09 13:49:01 -0800334 */
Stephen Hinesca54ec32010-09-20 17:20:30 -0700335 public void setVar(int index, double v) {
Jason Samse07694b2012-04-03 15:36:36 -0700336 mRS.nScriptSetVarD(getID(mRS), index, v);
Stephen Hinesca54ec32010-09-20 17:20:30 -0700337 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700338 public double getVarD(int index) {
339 return mRS.nScriptGetVarD(getID(mRS), index);
340 }
Stephen Hinesca54ec32010-09-20 17:20:30 -0700341
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700342 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800343 * Only intended for use by generated reflected code.
344 *
Jason Sams67e3d202011-01-09 13:49:01 -0800345 */
Jason Sams4d339932010-05-11 14:03:58 -0700346 public void setVar(int index, int v) {
Jason Samse07694b2012-04-03 15:36:36 -0700347 mRS.nScriptSetVarI(getID(mRS), index, v);
Jason Sams4d339932010-05-11 14:03:58 -0700348 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700349 public int getVarI(int index) {
350 return mRS.nScriptGetVarI(getID(mRS), index);
351 }
352
Jason Sams4d339932010-05-11 14:03:58 -0700353
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700354 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800355 * Only intended for use by generated reflected code.
356 *
Jason Sams67e3d202011-01-09 13:49:01 -0800357 */
Stephen Hines031ec58c2010-10-11 10:54:21 -0700358 public void setVar(int index, long v) {
Jason Samse07694b2012-04-03 15:36:36 -0700359 mRS.nScriptSetVarJ(getID(mRS), index, v);
Stephen Hines031ec58c2010-10-11 10:54:21 -0700360 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700361 public long getVarJ(int index) {
362 return mRS.nScriptGetVarJ(getID(mRS), index);
363 }
364
Stephen Hines031ec58c2010-10-11 10:54:21 -0700365
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700366 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800367 * Only intended for use by generated reflected code.
368 *
Jason Sams67e3d202011-01-09 13:49:01 -0800369 */
Jason Sams0b9a22c2010-07-02 15:35:19 -0700370 public void setVar(int index, boolean v) {
Jason Samse07694b2012-04-03 15:36:36 -0700371 mRS.nScriptSetVarI(getID(mRS), index, v ? 1 : 0);
Jason Sams0b9a22c2010-07-02 15:35:19 -0700372 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700373 public boolean getVarB(int index) {
374 return mRS.nScriptGetVarI(getID(mRS), index) > 0 ? true : false;
375 }
Jason Sams0b9a22c2010-07-02 15:35:19 -0700376
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700377 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800378 * Only intended for use by generated reflected code.
379 *
Jason Sams67e3d202011-01-09 13:49:01 -0800380 */
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800381 public void setVar(int index, BaseObj o) {
Jason Sams678cc7f2014-03-05 16:09:02 -0800382 mRS.validate();
383 mRS.validateObject(o);
Jason Samse07694b2012-04-03 15:36:36 -0700384 mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : o.getID(mRS));
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800385 }
386
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700387 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800388 * Only intended for use by generated reflected code.
389 *
Jason Sams67e3d202011-01-09 13:49:01 -0800390 */
Jason Sams4d339932010-05-11 14:03:58 -0700391 public void setVar(int index, FieldPacker v) {
Jason Samse07694b2012-04-03 15:36:36 -0700392 mRS.nScriptSetVarV(getID(mRS), index, v.getData());
Jason Sams69f0d312009-08-03 18:11:17 -0700393 }
394
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700395 /**
Stephen Hinesadeb8092012-04-20 14:26:06 -0700396 * Only intended for use by generated reflected code.
397 *
Stephen Hinesadeb8092012-04-20 14:26:06 -0700398 */
399 public void setVar(int index, FieldPacker v, Element e, int[] dims) {
400 mRS.nScriptSetVarVE(getID(mRS), index, v.getData(), e.getID(mRS), dims);
401 }
402
Jason Samsf64cca92013-04-19 12:56:37 -0700403 /**
404 * Only intended for use by generated reflected code.
405 *
Jason Samsf64cca92013-04-19 12:56:37 -0700406 */
Tim Murray7c4caad2013-04-10 16:21:40 -0700407 public void getVarV(int index, FieldPacker v) {
408 mRS.nScriptGetVarV(getID(mRS), index, v.getData());
409 }
410
Jason Sams22534172009-08-04 16:58:20 -0700411 public void setTimeZone(String timeZone) {
Jason Sams771bebb2009-12-07 12:40:12 -0800412 mRS.validate();
Jason Sams22534172009-08-04 16:58:20 -0700413 try {
Jason Samse07694b2012-04-03 15:36:36 -0700414 mRS.nScriptSetTimeZone(getID(mRS), timeZone.getBytes("UTF-8"));
Jason Sams22534172009-08-04 16:58:20 -0700415 } catch (java.io.UnsupportedEncodingException e) {
416 throw new RuntimeException(e);
417 }
418 }
Jason Sams69f0d312009-08-03 18:11:17 -0700419
Tim Murrayc11e25c2013-04-09 11:01:01 -0700420 /**
421 * Only intended for use by generated reflected code.
422 *
423 */
Jason Sams69f0d312009-08-03 18:11:17 -0700424 public static class Builder {
425 RenderScript mRS;
Jason Sams69f0d312009-08-03 18:11:17 -0700426
427 Builder(RenderScript rs) {
428 mRS = rs;
429 }
Jason Sams69f0d312009-08-03 18:11:17 -0700430 }
431
Jason Sams2d71bc72010-03-26 16:06:43 -0700432
Jason Samsf64cca92013-04-19 12:56:37 -0700433 /**
434 * Only intended for use by generated reflected code.
435 *
436 */
Jason Sams2d71bc72010-03-26 16:06:43 -0700437 public static class FieldBase {
438 protected Element mElement;
Jason Sams2d71bc72010-03-26 16:06:43 -0700439 protected Allocation mAllocation;
440
441 protected void init(RenderScript rs, int dimx) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700442 mAllocation = Allocation.createSized(rs, mElement, dimx,
443 Allocation.USAGE_SCRIPT);
Jason Sams5476b452010-12-08 16:14:36 -0800444 }
445
446 protected void init(RenderScript rs, int dimx, int usages) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700447 mAllocation =
448 Allocation.createSized(rs, mElement, dimx,
449 Allocation.USAGE_SCRIPT | usages);
Jason Sams2d71bc72010-03-26 16:06:43 -0700450 }
451
452 protected FieldBase() {
453 }
454
455 public Element getElement() {
456 return mElement;
457 }
458
459 public Type getType() {
Jason Sams31a7e422010-10-26 13:09:17 -0700460 return mAllocation.getType();
Jason Sams2d71bc72010-03-26 16:06:43 -0700461 }
462
463 public Allocation getAllocation() {
464 return mAllocation;
465 }
466
467 //@Override
468 public void updateAllocation() {
469 }
Jason Sams2d71bc72010-03-26 16:06:43 -0700470 }
Tim Murrayfbfaa852012-12-14 16:01:58 -0800471
Jason Samsf64cca92013-04-19 12:56:37 -0700472
473 /**
474 * Class used to specify clipping for a kernel launch.
475 *
476 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800477 public static final class LaunchOptions {
Jason Samsf64cca92013-04-19 12:56:37 -0700478 private int xstart = 0;
479 private int ystart = 0;
480 private int xend = 0;
481 private int yend = 0;
482 private int zstart = 0;
483 private int zend = 0;
484 private int strategy;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800485
Jason Samsf64cca92013-04-19 12:56:37 -0700486 /**
487 * Set the X range. If the end value is set to 0 the X dimension is not
488 * clipped.
489 *
490 * @param xstartArg Must be >= 0
491 * @param xendArg Must be >= xstartArg
492 *
493 * @return LaunchOptions
494 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800495 public LaunchOptions setX(int xstartArg, int xendArg) {
Tim Murrayfbfaa852012-12-14 16:01:58 -0800496 if (xstartArg < 0 || xendArg <= xstartArg) {
497 throw new RSIllegalArgumentException("Invalid dimensions");
498 }
499 xstart = xstartArg;
500 xend = xendArg;
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800501 return this;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800502 }
503
Jason Samsf64cca92013-04-19 12:56:37 -0700504 /**
505 * Set the Y range. If the end value is set to 0 the Y dimension is not
506 * clipped.
507 *
508 * @param ystartArg Must be >= 0
509 * @param yendArg Must be >= ystartArg
510 *
511 * @return LaunchOptions
512 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800513 public LaunchOptions setY(int ystartArg, int yendArg) {
Tim Murrayfbfaa852012-12-14 16:01:58 -0800514 if (ystartArg < 0 || yendArg <= ystartArg) {
515 throw new RSIllegalArgumentException("Invalid dimensions");
516 }
517 ystart = ystartArg;
518 yend = yendArg;
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800519 return this;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800520 }
521
Jason Samsf64cca92013-04-19 12:56:37 -0700522 /**
523 * Set the Z range. If the end value is set to 0 the Z dimension is not
524 * clipped.
525 *
526 * @param zstartArg Must be >= 0
527 * @param zendArg Must be >= zstartArg
528 *
529 * @return LaunchOptions
530 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800531 public LaunchOptions setZ(int zstartArg, int zendArg) {
532 if (zstartArg < 0 || zendArg <= zstartArg) {
533 throw new RSIllegalArgumentException("Invalid dimensions");
534 }
535 zstart = zstartArg;
536 zend = zendArg;
537 return this;
538 }
539
540
Jason Samsf64cca92013-04-19 12:56:37 -0700541 /**
542 * Returns the current X start
543 *
544 * @return int current value
545 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800546 public int getXStart() {
547 return xstart;
548 }
Jason Samsf64cca92013-04-19 12:56:37 -0700549 /**
550 * Returns the current X end
551 *
552 * @return int current value
553 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800554 public int getXEnd() {
555 return xend;
556 }
Jason Samsf64cca92013-04-19 12:56:37 -0700557 /**
558 * Returns the current Y start
559 *
560 * @return int current value
561 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800562 public int getYStart() {
563 return ystart;
564 }
Jason Samsf64cca92013-04-19 12:56:37 -0700565 /**
566 * Returns the current Y end
567 *
568 * @return int current value
569 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800570 public int getYEnd() {
571 return yend;
572 }
Jason Samsf64cca92013-04-19 12:56:37 -0700573 /**
574 * Returns the current Z start
575 *
576 * @return int current value
577 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800578 public int getZStart() {
579 return zstart;
580 }
Jason Samsf64cca92013-04-19 12:56:37 -0700581 /**
582 * Returns the current Z end
583 *
584 * @return int current value
585 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800586 public int getZEnd() {
587 return zend;
588 }
Tim Murrayfbfaa852012-12-14 16:01:58 -0800589
590 }
Jason Sams69f0d312009-08-03 18:11:17 -0700591}