Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 1 | /* |
Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 2 | * Copyright (C) 2008-2012 The Android Open Source Project |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 3 | * |
| 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 | |
| 17 | package android.renderscript; |
| 18 | |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 19 | import android.util.SparseArray; |
| 20 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 21 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 22 | * The parent class for all executable scripts. This should not be used by |
| 23 | * applications. |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 24 | **/ |
| 25 | public class Script extends BaseObj { |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 26 | |
| 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 Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 39 | KernelID(long id, RenderScript rs, Script s, int slot, int sig) { |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 40 | 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 Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 50 | */ |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 51 | protected KernelID createKernelID(int slot, int sig, Element ein, |
| 52 | Element eout) { |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 53 | KernelID k = mKIDs.get(slot); |
| 54 | if (k != null) { |
| 55 | return k; |
| 56 | } |
| 57 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 58 | long id = mRS.nScriptKernelIDCreate(getID(mRS), slot, sig); |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 59 | 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 Ni | be392ad | 2015-01-23 17:16:02 -0800 | [diff] [blame] | 69 | * @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 Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 109 | * 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 Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 119 | FieldID(long id, RenderScript rs, Script s, int slot) { |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 120 | 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 Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 129 | */ |
| 130 | protected FieldID createFieldID(int slot, Element e) { |
| 131 | FieldID f = mFIDs.get(slot); |
| 132 | if (f != null) { |
| 133 | return f; |
| 134 | } |
| 135 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 136 | long id = mRS.nScriptFieldIDCreate(getID(mRS), slot); |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 137 | 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 Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 147 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 148 | * Only intended for use by generated reflected code. |
| 149 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 150 | */ |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 151 | protected void invoke(int slot) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 152 | mRS.nScriptInvoke(getID(mRS), slot); |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 153 | } |
| 154 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 155 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 156 | * Only intended for use by generated reflected code. |
| 157 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 158 | */ |
Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 159 | protected void invoke(int slot, FieldPacker v) { |
| 160 | if (v != null) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 161 | mRS.nScriptInvokeV(getID(mRS), slot, v.getData()); |
Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 162 | } else { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 163 | mRS.nScriptInvoke(getID(mRS), slot); |
Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 164 | } |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 167 | /** |
Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 168 | * Only intended for use by generated reflected code. |
| 169 | * |
Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 170 | */ |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 171 | protected void forEach(int slot, Allocation ain, Allocation aout, |
| 172 | FieldPacker v) { |
| 173 | forEach(slot, ain, aout, v, null); |
Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 176 | /** |
| 177 | * Only intended for use by generated reflected code. |
| 178 | * |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 179 | */ |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 180 | 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 Sams | 678cc7f | 2014-03-05 16:09:02 -0800 | [diff] [blame] | 183 | mRS.validate(); |
| 184 | mRS.validateObject(ain); |
| 185 | mRS.validateObject(aout); |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 186 | |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 187 | 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 Murray | ba9dd06 | 2013-02-12 16:22:34 -0800 | [diff] [blame] | 191 | |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 192 | long[] in_ids = null; |
Stephen Hines | c9c7daf | 2014-08-13 17:32:19 +0000 | [diff] [blame] | 193 | if (ain != null) { |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 194 | in_ids = mInIdsBuffer; |
| 195 | in_ids[0] = ain.getID(mRS); |
Stephen Hines | c9c7daf | 2014-08-13 17:32:19 +0000 | [diff] [blame] | 196 | } |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 197 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 198 | long out_id = 0; |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 199 | if (aout != null) { |
| 200 | out_id = aout.getID(mRS); |
| 201 | } |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 202 | |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 203 | byte[] params = null; |
| 204 | if (v != null) { |
| 205 | params = v.getData(); |
| 206 | } |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 207 | |
| 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 Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 221 | } |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 222 | |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 223 | /** |
| 224 | * Only intended for use by generated reflected code. |
| 225 | * |
| 226 | * @hide |
| 227 | */ |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 228 | protected void forEach(int slot, Allocation[] ains, Allocation aout, |
| 229 | FieldPacker v) { |
| 230 | forEach(slot, ains, aout, v, null); |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Only intended for use by generated reflected code. |
| 235 | * |
| 236 | * @hide |
| 237 | */ |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 238 | 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 Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 241 | mRS.validate(); |
Andreas Gampe | c8ddcdd | 2015-03-15 15:57:30 -0700 | [diff] [blame^] | 242 | if (ains != null) { |
| 243 | for (Allocation ain : ains) { |
| 244 | mRS.validateObject(ain); |
| 245 | } |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 246 | } |
Stephen Hines | c9c7daf | 2014-08-13 17:32:19 +0000 | [diff] [blame] | 247 | mRS.validateObject(aout); |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 248 | |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 249 | 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 Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 254 | 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 Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 263 | |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 264 | byte[] params = null; |
| 265 | if (v != null) { |
| 266 | params = v.getData(); |
| 267 | } |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 268 | |
| 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 Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 284 | long[] mInIdsBuffer; |
| 285 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 286 | Script(long id, RenderScript rs) { |
Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 287 | super(id, rs); |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 288 | |
| 289 | mInIdsBuffer = new long[1]; |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 292 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 293 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 294 | * Only intended for use by generated reflected code. |
| 295 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 296 | */ |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 297 | public void bindAllocation(Allocation va, int slot) { |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 298 | mRS.validate(); |
Jason Sams | 678cc7f | 2014-03-05 16:09:02 -0800 | [diff] [blame] | 299 | mRS.validateObject(va); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 300 | if (va != null) { |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 301 | |
| 302 | android.content.Context context = mRS.getApplicationContext(); |
| 303 | |
| 304 | if (context.getApplicationInfo().targetSdkVersion >= 20) { |
Jason Sams | cf9c894 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 305 | final Type t = va.mType; |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 306 | if (t.hasMipmaps() || t.hasFaces() || (t.getY() != 0) || |
| 307 | (t.getZ() != 0)) { |
| 308 | |
Jason Sams | cf9c894 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 309 | throw new RSIllegalArgumentException( |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 310 | "API 20+ only allows simple 1D allocations to be " + |
| 311 | "used with bind."); |
Jason Sams | cf9c894 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 312 | } |
| 313 | } |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 314 | mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 315 | } else { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 316 | mRS.nScriptBindAllocation(getID(mRS), 0, slot); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 317 | } |
| 318 | } |
| 319 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 320 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 321 | * Only intended for use by generated reflected code. |
| 322 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 323 | */ |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 324 | public void setVar(int index, float v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 325 | mRS.nScriptSetVarF(getID(mRS), index, v); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 326 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 327 | public float getVarF(int index) { |
| 328 | return mRS.nScriptGetVarF(getID(mRS), index); |
| 329 | } |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 330 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 331 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 332 | * Only intended for use by generated reflected code. |
| 333 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 334 | */ |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 335 | public void setVar(int index, double v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 336 | mRS.nScriptSetVarD(getID(mRS), index, v); |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 337 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 338 | public double getVarD(int index) { |
| 339 | return mRS.nScriptGetVarD(getID(mRS), index); |
| 340 | } |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 341 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 342 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 343 | * Only intended for use by generated reflected code. |
| 344 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 345 | */ |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 346 | public void setVar(int index, int v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 347 | mRS.nScriptSetVarI(getID(mRS), index, v); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 348 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 349 | public int getVarI(int index) { |
| 350 | return mRS.nScriptGetVarI(getID(mRS), index); |
| 351 | } |
| 352 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 353 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 354 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 355 | * Only intended for use by generated reflected code. |
| 356 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 357 | */ |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 358 | public void setVar(int index, long v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 359 | mRS.nScriptSetVarJ(getID(mRS), index, v); |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 360 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 361 | public long getVarJ(int index) { |
| 362 | return mRS.nScriptGetVarJ(getID(mRS), index); |
| 363 | } |
| 364 | |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 365 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 366 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 367 | * Only intended for use by generated reflected code. |
| 368 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 369 | */ |
Jason Sams | 0b9a22c | 2010-07-02 15:35:19 -0700 | [diff] [blame] | 370 | public void setVar(int index, boolean v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 371 | mRS.nScriptSetVarI(getID(mRS), index, v ? 1 : 0); |
Jason Sams | 0b9a22c | 2010-07-02 15:35:19 -0700 | [diff] [blame] | 372 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 373 | public boolean getVarB(int index) { |
| 374 | return mRS.nScriptGetVarI(getID(mRS), index) > 0 ? true : false; |
| 375 | } |
Jason Sams | 0b9a22c | 2010-07-02 15:35:19 -0700 | [diff] [blame] | 376 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 377 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 378 | * Only intended for use by generated reflected code. |
| 379 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 380 | */ |
Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 381 | public void setVar(int index, BaseObj o) { |
Jason Sams | 678cc7f | 2014-03-05 16:09:02 -0800 | [diff] [blame] | 382 | mRS.validate(); |
| 383 | mRS.validateObject(o); |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 384 | mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : o.getID(mRS)); |
Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 385 | } |
| 386 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 387 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 388 | * Only intended for use by generated reflected code. |
| 389 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 390 | */ |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 391 | public void setVar(int index, FieldPacker v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 392 | mRS.nScriptSetVarV(getID(mRS), index, v.getData()); |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 393 | } |
| 394 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 395 | /** |
Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 396 | * Only intended for use by generated reflected code. |
| 397 | * |
Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 398 | */ |
| 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 Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 403 | /** |
| 404 | * Only intended for use by generated reflected code. |
| 405 | * |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 406 | */ |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 407 | public void getVarV(int index, FieldPacker v) { |
| 408 | mRS.nScriptGetVarV(getID(mRS), index, v.getData()); |
| 409 | } |
| 410 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 411 | public void setTimeZone(String timeZone) { |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 412 | mRS.validate(); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 413 | try { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 414 | mRS.nScriptSetTimeZone(getID(mRS), timeZone.getBytes("UTF-8")); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 415 | } catch (java.io.UnsupportedEncodingException e) { |
| 416 | throw new RuntimeException(e); |
| 417 | } |
| 418 | } |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 419 | |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 420 | /** |
| 421 | * Only intended for use by generated reflected code. |
| 422 | * |
| 423 | */ |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 424 | public static class Builder { |
| 425 | RenderScript mRS; |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 426 | |
| 427 | Builder(RenderScript rs) { |
| 428 | mRS = rs; |
| 429 | } |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 432 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 433 | /** |
| 434 | * Only intended for use by generated reflected code. |
| 435 | * |
| 436 | */ |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 437 | public static class FieldBase { |
| 438 | protected Element mElement; |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 439 | protected Allocation mAllocation; |
| 440 | |
| 441 | protected void init(RenderScript rs, int dimx) { |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 442 | mAllocation = Allocation.createSized(rs, mElement, dimx, |
| 443 | Allocation.USAGE_SCRIPT); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 444 | } |
| 445 | |
| 446 | protected void init(RenderScript rs, int dimx, int usages) { |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 447 | mAllocation = |
| 448 | Allocation.createSized(rs, mElement, dimx, |
| 449 | Allocation.USAGE_SCRIPT | usages); |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | protected FieldBase() { |
| 453 | } |
| 454 | |
| 455 | public Element getElement() { |
| 456 | return mElement; |
| 457 | } |
| 458 | |
| 459 | public Type getType() { |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 460 | return mAllocation.getType(); |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 461 | } |
| 462 | |
| 463 | public Allocation getAllocation() { |
| 464 | return mAllocation; |
| 465 | } |
| 466 | |
| 467 | //@Override |
| 468 | public void updateAllocation() { |
| 469 | } |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 470 | } |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 471 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 472 | |
| 473 | /** |
| 474 | * Class used to specify clipping for a kernel launch. |
| 475 | * |
| 476 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 477 | public static final class LaunchOptions { |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 478 | 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 Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 485 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 486 | /** |
| 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 Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 495 | public LaunchOptions setX(int xstartArg, int xendArg) { |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 496 | if (xstartArg < 0 || xendArg <= xstartArg) { |
| 497 | throw new RSIllegalArgumentException("Invalid dimensions"); |
| 498 | } |
| 499 | xstart = xstartArg; |
| 500 | xend = xendArg; |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 501 | return this; |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 504 | /** |
| 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 Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 513 | public LaunchOptions setY(int ystartArg, int yendArg) { |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 514 | if (ystartArg < 0 || yendArg <= ystartArg) { |
| 515 | throw new RSIllegalArgumentException("Invalid dimensions"); |
| 516 | } |
| 517 | ystart = ystartArg; |
| 518 | yend = yendArg; |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 519 | return this; |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 520 | } |
| 521 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 522 | /** |
| 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 Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 531 | 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 Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 541 | /** |
| 542 | * Returns the current X start |
| 543 | * |
| 544 | * @return int current value |
| 545 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 546 | public int getXStart() { |
| 547 | return xstart; |
| 548 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 549 | /** |
| 550 | * Returns the current X end |
| 551 | * |
| 552 | * @return int current value |
| 553 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 554 | public int getXEnd() { |
| 555 | return xend; |
| 556 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 557 | /** |
| 558 | * Returns the current Y start |
| 559 | * |
| 560 | * @return int current value |
| 561 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 562 | public int getYStart() { |
| 563 | return ystart; |
| 564 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 565 | /** |
| 566 | * Returns the current Y end |
| 567 | * |
| 568 | * @return int current value |
| 569 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 570 | public int getYEnd() { |
| 571 | return yend; |
| 572 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 573 | /** |
| 574 | * Returns the current Z start |
| 575 | * |
| 576 | * @return int current value |
| 577 | */ |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 578 | public int getZStart() { |
| 579 | return zstart; |
| 580 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 581 | /** |
| 582 | * Returns the current Z end |
| 583 | * |
| 584 | * @return int current value |
| 585 | */ |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 586 | public int getZEnd() { |
| 587 | return zend; |
| 588 | } |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 589 | |
| 590 | } |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 591 | } |