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 | /** |
| 69 | * FieldID is an identifier for a Script + exported field pair. It is used |
| 70 | * as an identifier for ScriptGroup creation. |
| 71 | * |
| 72 | * This class should not be directly created. Instead use the method in the |
| 73 | * reflected or intrinsic code "getFieldID_funcname()". |
| 74 | * |
| 75 | */ |
| 76 | public static final class FieldID extends BaseObj { |
| 77 | Script mScript; |
| 78 | int mSlot; |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 79 | FieldID(long id, RenderScript rs, Script s, int slot) { |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 80 | super(id, rs); |
| 81 | mScript = s; |
| 82 | mSlot = slot; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | private final SparseArray<FieldID> mFIDs = new SparseArray(); |
| 87 | /** |
| 88 | * Only to be used by generated reflected classes. |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 89 | */ |
| 90 | protected FieldID createFieldID(int slot, Element e) { |
| 91 | FieldID f = mFIDs.get(slot); |
| 92 | if (f != null) { |
| 93 | return f; |
| 94 | } |
| 95 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 96 | long id = mRS.nScriptFieldIDCreate(getID(mRS), slot); |
Jason Sams | 08a8158 | 2012-09-18 12:32:10 -0700 | [diff] [blame] | 97 | if (id == 0) { |
| 98 | throw new RSDriverException("Failed to create FieldID"); |
| 99 | } |
| 100 | |
| 101 | f = new FieldID(id, mRS, this, slot); |
| 102 | mFIDs.put(slot, f); |
| 103 | return f; |
| 104 | } |
| 105 | |
| 106 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 107 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 108 | * Only intended for use by generated reflected code. |
| 109 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 110 | */ |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 111 | protected void invoke(int slot) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 112 | mRS.nScriptInvoke(getID(mRS), slot); |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 115 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 116 | * Only intended for use by generated reflected code. |
| 117 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 118 | */ |
Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 119 | protected void invoke(int slot, FieldPacker v) { |
| 120 | if (v != null) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 121 | mRS.nScriptInvokeV(getID(mRS), slot, v.getData()); |
Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 122 | } else { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 123 | mRS.nScriptInvoke(getID(mRS), slot); |
Jason Sams | 96ed4cf | 2010-06-15 12:15:57 -0700 | [diff] [blame] | 124 | } |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 125 | } |
| 126 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 127 | /** |
Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 128 | * Only intended for use by generated reflected code. |
| 129 | * |
Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 130 | */ |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 131 | protected void forEach(int slot, Allocation ain, Allocation aout, |
| 132 | FieldPacker v) { |
| 133 | forEach(slot, ain, aout, v, null); |
Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 134 | } |
| 135 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 136 | /** |
| 137 | * Only intended for use by generated reflected code. |
| 138 | * |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 139 | */ |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 140 | protected void forEach(int slot, Allocation ain, Allocation aout, |
| 141 | FieldPacker v, LaunchOptions sc) { |
| 142 | // TODO: Is this necessary if nScriptForEach calls validate as well? |
Jason Sams | 678cc7f | 2014-03-05 16:09:02 -0800 | [diff] [blame] | 143 | mRS.validate(); |
| 144 | mRS.validateObject(ain); |
| 145 | mRS.validateObject(aout); |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 146 | |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 147 | if (ain == null && aout == null) { |
| 148 | throw new RSIllegalArgumentException( |
| 149 | "At least one of ain or aout is required to be non-null."); |
| 150 | } |
Tim Murray | ba9dd06 | 2013-02-12 16:22:34 -0800 | [diff] [blame] | 151 | |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 152 | long[] in_ids = null; |
Stephen Hines | c9c7daf | 2014-08-13 17:32:19 +0000 | [diff] [blame] | 153 | if (ain != null) { |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 154 | in_ids = mInIdsBuffer; |
| 155 | in_ids[0] = ain.getID(mRS); |
Stephen Hines | c9c7daf | 2014-08-13 17:32:19 +0000 | [diff] [blame] | 156 | } |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 157 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 158 | long out_id = 0; |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 159 | if (aout != null) { |
| 160 | out_id = aout.getID(mRS); |
| 161 | } |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 162 | |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 163 | byte[] params = null; |
| 164 | if (v != null) { |
| 165 | params = v.getData(); |
| 166 | } |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 167 | |
| 168 | int[] limits = null; |
| 169 | if (sc != null) { |
| 170 | limits = new int[6]; |
| 171 | |
| 172 | limits[0] = sc.xstart; |
| 173 | limits[1] = sc.xend; |
| 174 | limits[2] = sc.ystart; |
| 175 | limits[3] = sc.yend; |
| 176 | limits[4] = sc.zstart; |
| 177 | limits[5] = sc.zend; |
| 178 | } |
| 179 | |
| 180 | mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits); |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 181 | } |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 182 | |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 183 | /** |
| 184 | * Only intended for use by generated reflected code. |
| 185 | * |
| 186 | * @hide |
| 187 | */ |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 188 | protected void forEach(int slot, Allocation[] ains, Allocation aout, |
| 189 | FieldPacker v) { |
| 190 | forEach(slot, ains, aout, v, null); |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | /** |
| 194 | * Only intended for use by generated reflected code. |
| 195 | * |
| 196 | * @hide |
| 197 | */ |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 198 | protected void forEach(int slot, Allocation[] ains, Allocation aout, |
| 199 | FieldPacker v, LaunchOptions sc) { |
| 200 | // TODO: Is this necessary if nScriptForEach calls validate as well? |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 201 | mRS.validate(); |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 202 | for (Allocation ain : ains) { |
| 203 | mRS.validateObject(ain); |
| 204 | } |
Stephen Hines | c9c7daf | 2014-08-13 17:32:19 +0000 | [diff] [blame] | 205 | mRS.validateObject(aout); |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 206 | |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 207 | if (ains == null && aout == null) { |
| 208 | throw new RSIllegalArgumentException( |
| 209 | "At least one of ain or aout is required to be non-null."); |
| 210 | } |
| 211 | |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 212 | long[] in_ids = new long[ains.length]; |
| 213 | for (int index = 0; index < ains.length; ++index) { |
| 214 | in_ids[index] = ains[index].getID(mRS); |
| 215 | } |
| 216 | |
| 217 | long out_id = 0; |
| 218 | if (aout != null) { |
| 219 | out_id = aout.getID(mRS); |
| 220 | } |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 221 | |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 222 | byte[] params = null; |
| 223 | if (v != null) { |
| 224 | params = v.getData(); |
| 225 | } |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 226 | |
| 227 | int[] limits = null; |
| 228 | if (sc != null) { |
| 229 | limits = new int[6]; |
| 230 | |
| 231 | limits[0] = sc.xstart; |
| 232 | limits[1] = sc.xend; |
| 233 | limits[2] = sc.ystart; |
| 234 | limits[3] = sc.yend; |
| 235 | limits[4] = sc.zstart; |
| 236 | limits[5] = sc.zend; |
| 237 | } |
| 238 | |
| 239 | mRS.nScriptForEach(getID(mRS), slot, in_ids, out_id, params, limits); |
Chris Wailes | 9496106 | 2014-06-11 12:01:28 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 242 | long[] mInIdsBuffer; |
| 243 | |
Tim Murray | 7a629fa | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 244 | Script(long id, RenderScript rs) { |
Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 245 | super(id, rs); |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 246 | |
| 247 | mInIdsBuffer = new long[1]; |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 250 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 251 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 252 | * Only intended for use by generated reflected code. |
| 253 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 254 | */ |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 255 | public void bindAllocation(Allocation va, int slot) { |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 256 | mRS.validate(); |
Jason Sams | 678cc7f | 2014-03-05 16:09:02 -0800 | [diff] [blame] | 257 | mRS.validateObject(va); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 258 | if (va != null) { |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 259 | |
| 260 | android.content.Context context = mRS.getApplicationContext(); |
| 261 | |
| 262 | if (context.getApplicationInfo().targetSdkVersion >= 20) { |
Jason Sams | cf9c894 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 263 | final Type t = va.mType; |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 264 | if (t.hasMipmaps() || t.hasFaces() || (t.getY() != 0) || |
| 265 | (t.getZ() != 0)) { |
| 266 | |
Jason Sams | cf9c894 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 267 | throw new RSIllegalArgumentException( |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 268 | "API 20+ only allows simple 1D allocations to be " + |
| 269 | "used with bind."); |
Jason Sams | cf9c894 | 2014-01-14 16:18:14 -0800 | [diff] [blame] | 270 | } |
| 271 | } |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 272 | mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 273 | } else { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 274 | mRS.nScriptBindAllocation(getID(mRS), 0, slot); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 275 | } |
| 276 | } |
| 277 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 278 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 279 | * Only intended for use by generated reflected code. |
| 280 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 281 | */ |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 282 | public void setVar(int index, float v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 283 | mRS.nScriptSetVarF(getID(mRS), index, v); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 284 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 285 | public float getVarF(int index) { |
| 286 | return mRS.nScriptGetVarF(getID(mRS), index); |
| 287 | } |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 288 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 289 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 290 | * Only intended for use by generated reflected code. |
| 291 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 292 | */ |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 293 | public void setVar(int index, double v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 294 | mRS.nScriptSetVarD(getID(mRS), index, v); |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 295 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 296 | public double getVarD(int index) { |
| 297 | return mRS.nScriptGetVarD(getID(mRS), index); |
| 298 | } |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 299 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 300 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 301 | * Only intended for use by generated reflected code. |
| 302 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 303 | */ |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 304 | public void setVar(int index, int v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 305 | mRS.nScriptSetVarI(getID(mRS), index, v); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 306 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 307 | public int getVarI(int index) { |
| 308 | return mRS.nScriptGetVarI(getID(mRS), index); |
| 309 | } |
| 310 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 311 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 312 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 313 | * Only intended for use by generated reflected code. |
| 314 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 315 | */ |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 316 | public void setVar(int index, long v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 317 | mRS.nScriptSetVarJ(getID(mRS), index, v); |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 318 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 319 | public long getVarJ(int index) { |
| 320 | return mRS.nScriptGetVarJ(getID(mRS), index); |
| 321 | } |
| 322 | |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 323 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 324 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 325 | * Only intended for use by generated reflected code. |
| 326 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 327 | */ |
Jason Sams | 0b9a22c | 2010-07-02 15:35:19 -0700 | [diff] [blame] | 328 | public void setVar(int index, boolean v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 329 | mRS.nScriptSetVarI(getID(mRS), index, v ? 1 : 0); |
Jason Sams | 0b9a22c | 2010-07-02 15:35:19 -0700 | [diff] [blame] | 330 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 331 | public boolean getVarB(int index) { |
| 332 | return mRS.nScriptGetVarI(getID(mRS), index) > 0 ? true : false; |
| 333 | } |
Jason Sams | 0b9a22c | 2010-07-02 15:35:19 -0700 | [diff] [blame] | 334 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 335 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 336 | * Only intended for use by generated reflected code. |
| 337 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 338 | */ |
Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 339 | public void setVar(int index, BaseObj o) { |
Jason Sams | 678cc7f | 2014-03-05 16:09:02 -0800 | [diff] [blame] | 340 | mRS.validate(); |
| 341 | mRS.validateObject(o); |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 342 | mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : o.getID(mRS)); |
Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 343 | } |
| 344 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 345 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 346 | * Only intended for use by generated reflected code. |
| 347 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 348 | */ |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 349 | public void setVar(int index, FieldPacker v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 350 | mRS.nScriptSetVarV(getID(mRS), index, v.getData()); |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 353 | /** |
Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 354 | * Only intended for use by generated reflected code. |
| 355 | * |
Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 356 | */ |
| 357 | public void setVar(int index, FieldPacker v, Element e, int[] dims) { |
| 358 | mRS.nScriptSetVarVE(getID(mRS), index, v.getData(), e.getID(mRS), dims); |
| 359 | } |
| 360 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 361 | /** |
| 362 | * Only intended for use by generated reflected code. |
| 363 | * |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 364 | */ |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 365 | public void getVarV(int index, FieldPacker v) { |
| 366 | mRS.nScriptGetVarV(getID(mRS), index, v.getData()); |
| 367 | } |
| 368 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 369 | public void setTimeZone(String timeZone) { |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 370 | mRS.validate(); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 371 | try { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 372 | mRS.nScriptSetTimeZone(getID(mRS), timeZone.getBytes("UTF-8")); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 373 | } catch (java.io.UnsupportedEncodingException e) { |
| 374 | throw new RuntimeException(e); |
| 375 | } |
| 376 | } |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 377 | |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 378 | /** |
| 379 | * Only intended for use by generated reflected code. |
| 380 | * |
| 381 | */ |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 382 | public static class Builder { |
| 383 | RenderScript mRS; |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 384 | |
| 385 | Builder(RenderScript rs) { |
| 386 | mRS = rs; |
| 387 | } |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 388 | } |
| 389 | |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 390 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 391 | /** |
| 392 | * Only intended for use by generated reflected code. |
| 393 | * |
| 394 | */ |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 395 | public static class FieldBase { |
| 396 | protected Element mElement; |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 397 | protected Allocation mAllocation; |
| 398 | |
| 399 | protected void init(RenderScript rs, int dimx) { |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 400 | mAllocation = Allocation.createSized(rs, mElement, dimx, |
| 401 | Allocation.USAGE_SCRIPT); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 402 | } |
| 403 | |
| 404 | protected void init(RenderScript rs, int dimx, int usages) { |
Chris Wailes | be7b1de | 2014-07-15 10:56:14 -0700 | [diff] [blame] | 405 | mAllocation = |
| 406 | Allocation.createSized(rs, mElement, dimx, |
| 407 | Allocation.USAGE_SCRIPT | usages); |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | protected FieldBase() { |
| 411 | } |
| 412 | |
| 413 | public Element getElement() { |
| 414 | return mElement; |
| 415 | } |
| 416 | |
| 417 | public Type getType() { |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 418 | return mAllocation.getType(); |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 419 | } |
| 420 | |
| 421 | public Allocation getAllocation() { |
| 422 | return mAllocation; |
| 423 | } |
| 424 | |
| 425 | //@Override |
| 426 | public void updateAllocation() { |
| 427 | } |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 428 | } |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 429 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 430 | |
| 431 | /** |
| 432 | * Class used to specify clipping for a kernel launch. |
| 433 | * |
| 434 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 435 | public static final class LaunchOptions { |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 436 | private int xstart = 0; |
| 437 | private int ystart = 0; |
| 438 | private int xend = 0; |
| 439 | private int yend = 0; |
| 440 | private int zstart = 0; |
| 441 | private int zend = 0; |
| 442 | private int strategy; |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 443 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 444 | /** |
| 445 | * Set the X range. If the end value is set to 0 the X dimension is not |
| 446 | * clipped. |
| 447 | * |
| 448 | * @param xstartArg Must be >= 0 |
| 449 | * @param xendArg Must be >= xstartArg |
| 450 | * |
| 451 | * @return LaunchOptions |
| 452 | */ |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 453 | public LaunchOptions setX(int xstartArg, int xendArg) { |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 454 | if (xstartArg < 0 || xendArg <= xstartArg) { |
| 455 | throw new RSIllegalArgumentException("Invalid dimensions"); |
| 456 | } |
| 457 | xstart = xstartArg; |
| 458 | xend = xendArg; |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 459 | return this; |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 460 | } |
| 461 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 462 | /** |
| 463 | * Set the Y range. If the end value is set to 0 the Y dimension is not |
| 464 | * clipped. |
| 465 | * |
| 466 | * @param ystartArg Must be >= 0 |
| 467 | * @param yendArg Must be >= ystartArg |
| 468 | * |
| 469 | * @return LaunchOptions |
| 470 | */ |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 471 | public LaunchOptions setY(int ystartArg, int yendArg) { |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 472 | if (ystartArg < 0 || yendArg <= ystartArg) { |
| 473 | throw new RSIllegalArgumentException("Invalid dimensions"); |
| 474 | } |
| 475 | ystart = ystartArg; |
| 476 | yend = yendArg; |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 477 | return this; |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 478 | } |
| 479 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 480 | /** |
| 481 | * Set the Z range. If the end value is set to 0 the Z dimension is not |
| 482 | * clipped. |
| 483 | * |
| 484 | * @param zstartArg Must be >= 0 |
| 485 | * @param zendArg Must be >= zstartArg |
| 486 | * |
| 487 | * @return LaunchOptions |
| 488 | */ |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 489 | public LaunchOptions setZ(int zstartArg, int zendArg) { |
| 490 | if (zstartArg < 0 || zendArg <= zstartArg) { |
| 491 | throw new RSIllegalArgumentException("Invalid dimensions"); |
| 492 | } |
| 493 | zstart = zstartArg; |
| 494 | zend = zendArg; |
| 495 | return this; |
| 496 | } |
| 497 | |
| 498 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 499 | /** |
| 500 | * Returns the current X start |
| 501 | * |
| 502 | * @return int current value |
| 503 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 504 | public int getXStart() { |
| 505 | return xstart; |
| 506 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 507 | /** |
| 508 | * Returns the current X end |
| 509 | * |
| 510 | * @return int current value |
| 511 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 512 | public int getXEnd() { |
| 513 | return xend; |
| 514 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 515 | /** |
| 516 | * Returns the current Y start |
| 517 | * |
| 518 | * @return int current value |
| 519 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 520 | public int getYStart() { |
| 521 | return ystart; |
| 522 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 523 | /** |
| 524 | * Returns the current Y end |
| 525 | * |
| 526 | * @return int current value |
| 527 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 528 | public int getYEnd() { |
| 529 | return yend; |
| 530 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 531 | /** |
| 532 | * Returns the current Z start |
| 533 | * |
| 534 | * @return int current value |
| 535 | */ |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 536 | public int getZStart() { |
| 537 | return zstart; |
| 538 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 539 | /** |
| 540 | * Returns the current Z end |
| 541 | * |
| 542 | * @return int current value |
| 543 | */ |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 544 | public int getZEnd() { |
| 545 | return zend; |
| 546 | } |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 547 | |
| 548 | } |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 549 | } |