blob: 65056ac5c22d9491954f599ba4c6105fe7189f0c [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
Andreas Gampead555f92015-03-17 20:05:46 -0700254 long[] in_ids;
255 if (ains != null) {
256 in_ids = new long[ains.length];
257 for (int index = 0; index < ains.length; ++index) {
258 in_ids[index] = ains[index].getID(mRS);
259 }
260 } else {
261 in_ids = null;
Chris Wailes94961062014-06-11 12:01:28 -0700262 }
263
264 long out_id = 0;
265 if (aout != null) {
266 out_id = aout.getID(mRS);
267 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700268
Chris Wailes94961062014-06-11 12:01:28 -0700269 byte[] params = null;
270 if (v != null) {
271 params = v.getData();
272 }
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700273
274 int[] limits = null;
275 if (sc != null) {
276 limits = new int[6];
277
278 limits[0] = sc.xstart;
279 limits[1] = sc.xend;
280 limits[2] = sc.ystart;
281 limits[3] = sc.yend;
282 limits[4] = sc.zstart;
283 limits[5] = sc.zend;
284 }
285
286 mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits);
Chris Wailes94961062014-06-11 12:01:28 -0700287 }
288
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700289 long[] mInIdsBuffer;
290
Tim Murray7a629fa2013-11-19 12:45:54 -0800291 Script(long id, RenderScript rs) {
Alex Sakhartchouk0de94442010-08-11 14:41:28 -0700292 super(id, rs);
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700293
294 mInIdsBuffer = new long[1];
Jason Sams69f0d312009-08-03 18:11:17 -0700295 }
296
Jason Sams67e3d202011-01-09 13:49:01 -0800297
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700298 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800299 * Only intended for use by generated reflected code.
300 *
Jason Sams67e3d202011-01-09 13:49:01 -0800301 */
Jason Sams69f0d312009-08-03 18:11:17 -0700302 public void bindAllocation(Allocation va, int slot) {
Jason Sams771bebb2009-12-07 12:40:12 -0800303 mRS.validate();
Jason Sams678cc7f2014-03-05 16:09:02 -0800304 mRS.validateObject(va);
Jason Sams4d339932010-05-11 14:03:58 -0700305 if (va != null) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700306
307 android.content.Context context = mRS.getApplicationContext();
308
309 if (context.getApplicationInfo().targetSdkVersion >= 20) {
Jason Samscf9c8942014-01-14 16:18:14 -0800310 final Type t = va.mType;
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700311 if (t.hasMipmaps() || t.hasFaces() || (t.getY() != 0) ||
312 (t.getZ() != 0)) {
313
Jason Samscf9c8942014-01-14 16:18:14 -0800314 throw new RSIllegalArgumentException(
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700315 "API 20+ only allows simple 1D allocations to be " +
316 "used with bind.");
Jason Samscf9c8942014-01-14 16:18:14 -0800317 }
318 }
Jason Samse07694b2012-04-03 15:36:36 -0700319 mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot);
Jason Sams4d339932010-05-11 14:03:58 -0700320 } else {
Jason Samse07694b2012-04-03 15:36:36 -0700321 mRS.nScriptBindAllocation(getID(mRS), 0, slot);
Jason Sams4d339932010-05-11 14:03:58 -0700322 }
323 }
324
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700325 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800326 * Only intended for use by generated reflected code.
327 *
Jason Sams67e3d202011-01-09 13:49:01 -0800328 */
Jason Sams4d339932010-05-11 14:03:58 -0700329 public void setVar(int index, float v) {
Jason Samse07694b2012-04-03 15:36:36 -0700330 mRS.nScriptSetVarF(getID(mRS), index, v);
Jason Sams4d339932010-05-11 14:03:58 -0700331 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700332 public float getVarF(int index) {
333 return mRS.nScriptGetVarF(getID(mRS), index);
334 }
Jason Sams4d339932010-05-11 14:03:58 -0700335
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700336 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800337 * Only intended for use by generated reflected code.
338 *
Jason Sams67e3d202011-01-09 13:49:01 -0800339 */
Stephen Hinesca54ec32010-09-20 17:20:30 -0700340 public void setVar(int index, double v) {
Jason Samse07694b2012-04-03 15:36:36 -0700341 mRS.nScriptSetVarD(getID(mRS), index, v);
Stephen Hinesca54ec32010-09-20 17:20:30 -0700342 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700343 public double getVarD(int index) {
344 return mRS.nScriptGetVarD(getID(mRS), index);
345 }
Stephen Hinesca54ec32010-09-20 17:20:30 -0700346
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 Sams4d339932010-05-11 14:03:58 -0700351 public void setVar(int index, int v) {
Jason Samse07694b2012-04-03 15:36:36 -0700352 mRS.nScriptSetVarI(getID(mRS), index, v);
Jason Sams4d339932010-05-11 14:03:58 -0700353 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700354 public int getVarI(int index) {
355 return mRS.nScriptGetVarI(getID(mRS), index);
356 }
357
Jason Sams4d339932010-05-11 14:03:58 -0700358
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700359 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800360 * Only intended for use by generated reflected code.
361 *
Jason Sams67e3d202011-01-09 13:49:01 -0800362 */
Stephen Hines031ec58c2010-10-11 10:54:21 -0700363 public void setVar(int index, long v) {
Jason Samse07694b2012-04-03 15:36:36 -0700364 mRS.nScriptSetVarJ(getID(mRS), index, v);
Stephen Hines031ec58c2010-10-11 10:54:21 -0700365 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700366 public long getVarJ(int index) {
367 return mRS.nScriptGetVarJ(getID(mRS), index);
368 }
369
Stephen Hines031ec58c2010-10-11 10:54:21 -0700370
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700371 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800372 * Only intended for use by generated reflected code.
373 *
Jason Sams67e3d202011-01-09 13:49:01 -0800374 */
Jason Sams0b9a22c2010-07-02 15:35:19 -0700375 public void setVar(int index, boolean v) {
Jason Samse07694b2012-04-03 15:36:36 -0700376 mRS.nScriptSetVarI(getID(mRS), index, v ? 1 : 0);
Jason Sams0b9a22c2010-07-02 15:35:19 -0700377 }
Tim Murray7c4caad2013-04-10 16:21:40 -0700378 public boolean getVarB(int index) {
379 return mRS.nScriptGetVarI(getID(mRS), index) > 0 ? true : false;
380 }
Jason Sams0b9a22c2010-07-02 15:35:19 -0700381
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700382 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800383 * Only intended for use by generated reflected code.
384 *
Jason Sams67e3d202011-01-09 13:49:01 -0800385 */
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800386 public void setVar(int index, BaseObj o) {
Jason Sams678cc7f2014-03-05 16:09:02 -0800387 mRS.validate();
388 mRS.validateObject(o);
Jason Samse07694b2012-04-03 15:36:36 -0700389 mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : o.getID(mRS));
Jason Sams6f4cf0b2010-11-16 17:37:02 -0800390 }
391
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700392 /**
Jason Sams67e3d202011-01-09 13:49:01 -0800393 * Only intended for use by generated reflected code.
394 *
Jason Sams67e3d202011-01-09 13:49:01 -0800395 */
Jason Sams4d339932010-05-11 14:03:58 -0700396 public void setVar(int index, FieldPacker v) {
Jason Samse07694b2012-04-03 15:36:36 -0700397 mRS.nScriptSetVarV(getID(mRS), index, v.getData());
Jason Sams69f0d312009-08-03 18:11:17 -0700398 }
399
Stephen Hines9c9ad3f8c22012-05-07 15:34:29 -0700400 /**
Stephen Hinesadeb8092012-04-20 14:26:06 -0700401 * Only intended for use by generated reflected code.
402 *
Stephen Hinesadeb8092012-04-20 14:26:06 -0700403 */
404 public void setVar(int index, FieldPacker v, Element e, int[] dims) {
405 mRS.nScriptSetVarVE(getID(mRS), index, v.getData(), e.getID(mRS), dims);
406 }
407
Jason Samsf64cca92013-04-19 12:56:37 -0700408 /**
409 * Only intended for use by generated reflected code.
410 *
Jason Samsf64cca92013-04-19 12:56:37 -0700411 */
Tim Murray7c4caad2013-04-10 16:21:40 -0700412 public void getVarV(int index, FieldPacker v) {
413 mRS.nScriptGetVarV(getID(mRS), index, v.getData());
414 }
415
Jason Sams22534172009-08-04 16:58:20 -0700416 public void setTimeZone(String timeZone) {
Jason Sams771bebb2009-12-07 12:40:12 -0800417 mRS.validate();
Jason Sams22534172009-08-04 16:58:20 -0700418 try {
Jason Samse07694b2012-04-03 15:36:36 -0700419 mRS.nScriptSetTimeZone(getID(mRS), timeZone.getBytes("UTF-8"));
Jason Sams22534172009-08-04 16:58:20 -0700420 } catch (java.io.UnsupportedEncodingException e) {
421 throw new RuntimeException(e);
422 }
423 }
Jason Sams69f0d312009-08-03 18:11:17 -0700424
Tim Murrayc11e25c2013-04-09 11:01:01 -0700425 /**
426 * Only intended for use by generated reflected code.
427 *
428 */
Jason Sams69f0d312009-08-03 18:11:17 -0700429 public static class Builder {
430 RenderScript mRS;
Jason Sams69f0d312009-08-03 18:11:17 -0700431
432 Builder(RenderScript rs) {
433 mRS = rs;
434 }
Jason Sams69f0d312009-08-03 18:11:17 -0700435 }
436
Jason Sams2d71bc72010-03-26 16:06:43 -0700437
Jason Samsf64cca92013-04-19 12:56:37 -0700438 /**
439 * Only intended for use by generated reflected code.
440 *
441 */
Jason Sams2d71bc72010-03-26 16:06:43 -0700442 public static class FieldBase {
443 protected Element mElement;
Jason Sams2d71bc72010-03-26 16:06:43 -0700444 protected Allocation mAllocation;
445
446 protected void init(RenderScript rs, int dimx) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700447 mAllocation = Allocation.createSized(rs, mElement, dimx,
448 Allocation.USAGE_SCRIPT);
Jason Sams5476b452010-12-08 16:14:36 -0800449 }
450
451 protected void init(RenderScript rs, int dimx, int usages) {
Chris Wailesbe7b1de2014-07-15 10:56:14 -0700452 mAllocation =
453 Allocation.createSized(rs, mElement, dimx,
454 Allocation.USAGE_SCRIPT | usages);
Jason Sams2d71bc72010-03-26 16:06:43 -0700455 }
456
457 protected FieldBase() {
458 }
459
460 public Element getElement() {
461 return mElement;
462 }
463
464 public Type getType() {
Jason Sams31a7e422010-10-26 13:09:17 -0700465 return mAllocation.getType();
Jason Sams2d71bc72010-03-26 16:06:43 -0700466 }
467
468 public Allocation getAllocation() {
469 return mAllocation;
470 }
471
472 //@Override
473 public void updateAllocation() {
474 }
Jason Sams2d71bc72010-03-26 16:06:43 -0700475 }
Tim Murrayfbfaa852012-12-14 16:01:58 -0800476
Jason Samsf64cca92013-04-19 12:56:37 -0700477
478 /**
479 * Class used to specify clipping for a kernel launch.
480 *
481 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800482 public static final class LaunchOptions {
Jason Samsf64cca92013-04-19 12:56:37 -0700483 private int xstart = 0;
484 private int ystart = 0;
485 private int xend = 0;
486 private int yend = 0;
487 private int zstart = 0;
488 private int zend = 0;
489 private int strategy;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800490
Jason Samsf64cca92013-04-19 12:56:37 -0700491 /**
492 * Set the X range. If the end value is set to 0 the X dimension is not
493 * clipped.
494 *
495 * @param xstartArg Must be >= 0
496 * @param xendArg Must be >= xstartArg
497 *
498 * @return LaunchOptions
499 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800500 public LaunchOptions setX(int xstartArg, int xendArg) {
Tim Murrayfbfaa852012-12-14 16:01:58 -0800501 if (xstartArg < 0 || xendArg <= xstartArg) {
502 throw new RSIllegalArgumentException("Invalid dimensions");
503 }
504 xstart = xstartArg;
505 xend = xendArg;
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800506 return this;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800507 }
508
Jason Samsf64cca92013-04-19 12:56:37 -0700509 /**
510 * Set the Y range. If the end value is set to 0 the Y dimension is not
511 * clipped.
512 *
513 * @param ystartArg Must be >= 0
514 * @param yendArg Must be >= ystartArg
515 *
516 * @return LaunchOptions
517 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800518 public LaunchOptions setY(int ystartArg, int yendArg) {
Tim Murrayfbfaa852012-12-14 16:01:58 -0800519 if (ystartArg < 0 || yendArg <= ystartArg) {
520 throw new RSIllegalArgumentException("Invalid dimensions");
521 }
522 ystart = ystartArg;
523 yend = yendArg;
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800524 return this;
Tim Murrayfbfaa852012-12-14 16:01:58 -0800525 }
526
Jason Samsf64cca92013-04-19 12:56:37 -0700527 /**
528 * Set the Z range. If the end value is set to 0 the Z dimension is not
529 * clipped.
530 *
531 * @param zstartArg Must be >= 0
532 * @param zendArg Must be >= zstartArg
533 *
534 * @return LaunchOptions
535 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800536 public LaunchOptions setZ(int zstartArg, int zendArg) {
537 if (zstartArg < 0 || zendArg <= zstartArg) {
538 throw new RSIllegalArgumentException("Invalid dimensions");
539 }
540 zstart = zstartArg;
541 zend = zendArg;
542 return this;
543 }
544
545
Jason Samsf64cca92013-04-19 12:56:37 -0700546 /**
547 * Returns the current X start
548 *
549 * @return int current value
550 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800551 public int getXStart() {
552 return xstart;
553 }
Jason Samsf64cca92013-04-19 12:56:37 -0700554 /**
555 * Returns the current X end
556 *
557 * @return int current value
558 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800559 public int getXEnd() {
560 return xend;
561 }
Jason Samsf64cca92013-04-19 12:56:37 -0700562 /**
563 * Returns the current Y start
564 *
565 * @return int current value
566 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800567 public int getYStart() {
568 return ystart;
569 }
Jason Samsf64cca92013-04-19 12:56:37 -0700570 /**
571 * Returns the current Y end
572 *
573 * @return int current value
574 */
Tim Murrayfbfaa852012-12-14 16:01:58 -0800575 public int getYEnd() {
576 return yend;
577 }
Jason Samsf64cca92013-04-19 12:56:37 -0700578 /**
579 * Returns the current Z start
580 *
581 * @return int current value
582 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800583 public int getZStart() {
584 return zstart;
585 }
Jason Samsf64cca92013-04-19 12:56:37 -0700586 /**
587 * Returns the current Z end
588 *
589 * @return int current value
590 */
Tim Murrayeb8c29c2013-02-07 12:16:41 -0800591 public int getZEnd() {
592 return zend;
593 }
Tim Murrayfbfaa852012-12-14 16:01:58 -0800594
595 }
Jason Sams69f0d312009-08-03 18:11:17 -0700596}