| 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 | |
| Andreas Gampe | ad555f9 | 2015-03-17 20:05:46 -0700 | [diff] [blame] | 254 | 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 Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 262 | } |
| 263 | |
| 264 | long out_id = 0; |
| 265 | if (aout != null) { |
| 266 | out_id = aout.getID(mRS); |
| 267 | } |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 268 | |
| Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 269 | byte[] params = null; |
| 270 | if (v != null) { |
| 271 | params = v.getData(); |
| 272 | } |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 273 | |
| 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 Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 287 | } |
| 288 | |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 289 | long[] mInIdsBuffer; |
| 290 | |
| Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 291 | Script(long id, RenderScript rs) { |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 292 | super(id, rs); |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 293 | |
| 294 | mInIdsBuffer = new long[1]; |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 295 | } |
| 296 | |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 297 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 298 | /** |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 299 | * Only intended for use by generated reflected code. |
| 300 | * |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 301 | */ |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 302 | public void bindAllocation(Allocation va, int slot) { |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 303 | mRS.validate(); |
| Jason Sams | 678cc7f | 2014-03-05 16:09:02 -0800 | [diff] [blame] | 304 | mRS.validateObject(va); |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 305 | if (va != null) { |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 306 | |
| 307 | android.content.Context context = mRS.getApplicationContext(); |
| 308 | |
| 309 | if (context.getApplicationInfo().targetSdkVersion >= 20) { |
| Jason Sams | cf9c894 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 310 | final Type t = va.mType; |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 311 | if (t.hasMipmaps() || t.hasFaces() || (t.getY() != 0) || |
| 312 | (t.getZ() != 0)) { |
| 313 | |
| Jason Sams | cf9c894 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 314 | throw new RSIllegalArgumentException( |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 315 | "API 20+ only allows simple 1D allocations to be " + |
| 316 | "used with bind."); |
| Jason Sams | cf9c894 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 317 | } |
| 318 | } |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 319 | mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot); |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 320 | } else { |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 321 | mRS.nScriptBindAllocation(getID(mRS), 0, slot); |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 322 | } |
| 323 | } |
| 324 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 325 | /** |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 326 | * Only intended for use by generated reflected code. |
| 327 | * |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 328 | */ |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 329 | public void setVar(int index, float v) { |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 330 | mRS.nScriptSetVarF(getID(mRS), index, v); |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 331 | } |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 332 | public float getVarF(int index) { |
| 333 | return mRS.nScriptGetVarF(getID(mRS), index); |
| 334 | } |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 335 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 336 | /** |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 337 | * Only intended for use by generated reflected code. |
| 338 | * |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 339 | */ |
| Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 340 | public void setVar(int index, double v) { |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 341 | mRS.nScriptSetVarD(getID(mRS), index, v); |
| Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 342 | } |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 343 | public double getVarD(int index) { |
| 344 | return mRS.nScriptGetVarD(getID(mRS), index); |
| 345 | } |
| Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 346 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 347 | /** |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 348 | * Only intended for use by generated reflected code. |
| 349 | * |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 350 | */ |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 351 | public void setVar(int index, int v) { |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 352 | mRS.nScriptSetVarI(getID(mRS), index, v); |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 353 | } |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 354 | public int getVarI(int index) { |
| 355 | return mRS.nScriptGetVarI(getID(mRS), index); |
| 356 | } |
| 357 | |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 358 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 359 | /** |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 360 | * Only intended for use by generated reflected code. |
| 361 | * |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 362 | */ |
| Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 363 | public void setVar(int index, long v) { |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 364 | mRS.nScriptSetVarJ(getID(mRS), index, v); |
| Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 365 | } |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 366 | public long getVarJ(int index) { |
| 367 | return mRS.nScriptGetVarJ(getID(mRS), index); |
| 368 | } |
| 369 | |
| Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 370 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 371 | /** |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 372 | * Only intended for use by generated reflected code. |
| 373 | * |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 374 | */ |
| Jason Sams | 0b9a22c | 2010-07-02 15:35:19 -0700 | [diff] [blame] | 375 | public void setVar(int index, boolean v) { |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 376 | mRS.nScriptSetVarI(getID(mRS), index, v ? 1 : 0); |
| Jason Sams | 0b9a22c | 2010-07-02 15:35:19 -0700 | [diff] [blame] | 377 | } |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 378 | public boolean getVarB(int index) { |
| 379 | return mRS.nScriptGetVarI(getID(mRS), index) > 0 ? true : false; |
| 380 | } |
| Jason Sams | 0b9a22c | 2010-07-02 15:35:19 -0700 | [diff] [blame] | 381 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 382 | /** |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 383 | * Only intended for use by generated reflected code. |
| 384 | * |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 385 | */ |
| Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 386 | public void setVar(int index, BaseObj o) { |
| Jason Sams | 678cc7f | 2014-03-05 16:09:02 -0800 | [diff] [blame] | 387 | mRS.validate(); |
| 388 | mRS.validateObject(o); |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 389 | mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : o.getID(mRS)); |
| Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 390 | } |
| 391 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 392 | /** |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 393 | * Only intended for use by generated reflected code. |
| 394 | * |
| Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 395 | */ |
| Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 396 | public void setVar(int index, FieldPacker v) { |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 397 | mRS.nScriptSetVarV(getID(mRS), index, v.getData()); |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 398 | } |
| 399 | |
| Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 400 | /** |
| Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 401 | * Only intended for use by generated reflected code. |
| 402 | * |
| Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 403 | */ |
| 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 Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 408 | /** |
| 409 | * Only intended for use by generated reflected code. |
| 410 | * |
| Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 411 | */ |
| Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 412 | public void getVarV(int index, FieldPacker v) { |
| 413 | mRS.nScriptGetVarV(getID(mRS), index, v.getData()); |
| 414 | } |
| 415 | |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 416 | public void setTimeZone(String timeZone) { |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 417 | mRS.validate(); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 418 | try { |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 419 | mRS.nScriptSetTimeZone(getID(mRS), timeZone.getBytes("UTF-8")); |
| Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 420 | } catch (java.io.UnsupportedEncodingException e) { |
| 421 | throw new RuntimeException(e); |
| 422 | } |
| 423 | } |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 424 | |
| Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 425 | /** |
| 426 | * Only intended for use by generated reflected code. |
| 427 | * |
| 428 | */ |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 429 | public static class Builder { |
| 430 | RenderScript mRS; |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 431 | |
| 432 | Builder(RenderScript rs) { |
| 433 | mRS = rs; |
| 434 | } |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 437 | |
| Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 438 | /** |
| 439 | * Only intended for use by generated reflected code. |
| 440 | * |
| 441 | */ |
| Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 442 | public static class FieldBase { |
| 443 | protected Element mElement; |
| Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 444 | protected Allocation mAllocation; |
| 445 | |
| 446 | protected void init(RenderScript rs, int dimx) { |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 447 | mAllocation = Allocation.createSized(rs, mElement, dimx, |
| 448 | Allocation.USAGE_SCRIPT); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 449 | } |
| 450 | |
| 451 | protected void init(RenderScript rs, int dimx, int usages) { |
| Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 452 | mAllocation = |
| 453 | Allocation.createSized(rs, mElement, dimx, |
| 454 | Allocation.USAGE_SCRIPT | usages); |
| Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | protected FieldBase() { |
| 458 | } |
| 459 | |
| 460 | public Element getElement() { |
| 461 | return mElement; |
| 462 | } |
| 463 | |
| 464 | public Type getType() { |
| Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 465 | return mAllocation.getType(); |
| Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | public Allocation getAllocation() { |
| 469 | return mAllocation; |
| 470 | } |
| 471 | |
| 472 | //@Override |
| 473 | public void updateAllocation() { |
| 474 | } |
| Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 475 | } |
| Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 476 | |
| Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 477 | |
| 478 | /** |
| 479 | * Class used to specify clipping for a kernel launch. |
| 480 | * |
| 481 | */ |
| Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 482 | public static final class LaunchOptions { |
| Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 483 | 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 Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 490 | |
| Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 491 | /** |
| 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 Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 500 | public LaunchOptions setX(int xstartArg, int xendArg) { |
| Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 501 | if (xstartArg < 0 || xendArg <= xstartArg) { |
| 502 | throw new RSIllegalArgumentException("Invalid dimensions"); |
| 503 | } |
| 504 | xstart = xstartArg; |
| 505 | xend = xendArg; |
| Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 506 | return this; |
| Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 507 | } |
| 508 | |
| Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 509 | /** |
| 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 Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 518 | public LaunchOptions setY(int ystartArg, int yendArg) { |
| Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 519 | if (ystartArg < 0 || yendArg <= ystartArg) { |
| 520 | throw new RSIllegalArgumentException("Invalid dimensions"); |
| 521 | } |
| 522 | ystart = ystartArg; |
| 523 | yend = yendArg; |
| Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 524 | return this; |
| Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 525 | } |
| 526 | |
| Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 527 | /** |
| 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 Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 536 | 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 Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 546 | /** |
| 547 | * Returns the current X start |
| 548 | * |
| 549 | * @return int current value |
| 550 | */ |
| Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 551 | public int getXStart() { |
| 552 | return xstart; |
| 553 | } |
| Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 554 | /** |
| 555 | * Returns the current X end |
| 556 | * |
| 557 | * @return int current value |
| 558 | */ |
| Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 559 | public int getXEnd() { |
| 560 | return xend; |
| 561 | } |
| Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 562 | /** |
| 563 | * Returns the current Y start |
| 564 | * |
| 565 | * @return int current value |
| 566 | */ |
| Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 567 | public int getYStart() { |
| 568 | return ystart; |
| 569 | } |
| Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 570 | /** |
| 571 | * Returns the current Y end |
| 572 | * |
| 573 | * @return int current value |
| 574 | */ |
| Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 575 | public int getYEnd() { |
| 576 | return yend; |
| 577 | } |
| Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 578 | /** |
| 579 | * Returns the current Z start |
| 580 | * |
| 581 | * @return int current value |
| 582 | */ |
| Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 583 | public int getZStart() { |
| 584 | return zstart; |
| 585 | } |
| Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 586 | /** |
| 587 | * Returns the current Z end |
| 588 | * |
| 589 | * @return int current value |
| 590 | */ |
| Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 591 | public int getZEnd() { |
| 592 | return zend; |
| 593 | } |
| Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 594 | |
| 595 | } |
| Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 596 | } |