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