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; |
| 39 | KernelID(int id, RenderScript rs, Script s, int slot, int sig) { |
| 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 | |
| 57 | int id = mRS.nScriptKernelIDCreate(getID(mRS), slot, sig); |
| 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; |
| 78 | FieldID(int id, RenderScript rs, Script s, int slot) { |
| 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 | |
| 95 | int id = mRS.nScriptFieldIDCreate(getID(mRS), slot); |
| 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) { |
| 131 | if (ain == null && aout == null) { |
| 132 | throw new RSIllegalArgumentException( |
| 133 | "At least one of ain or aout is required to be non-null."); |
| 134 | } |
| 135 | int in_id = 0; |
| 136 | if (ain != null) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 137 | in_id = ain.getID(mRS); |
Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 138 | } |
| 139 | int out_id = 0; |
| 140 | if (aout != null) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 141 | out_id = aout.getID(mRS); |
Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 142 | } |
| 143 | byte[] params = null; |
| 144 | if (v != null) { |
| 145 | params = v.getData(); |
| 146 | } |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 147 | mRS.nScriptForEach(getID(mRS), slot, in_id, out_id, params); |
Jason Sams | 6e494d3 | 2011-04-27 16:33:11 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 150 | /** |
| 151 | * Only intended for use by generated reflected code. |
| 152 | * |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 153 | */ |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 154 | protected void forEach(int slot, Allocation ain, Allocation aout, FieldPacker v, LaunchOptions sc) { |
| 155 | if (ain == null && aout == null) { |
| 156 | throw new RSIllegalArgumentException( |
| 157 | "At least one of ain or aout is required to be non-null."); |
| 158 | } |
Tim Murray | ba9dd06 | 2013-02-12 16:22:34 -0800 | [diff] [blame] | 159 | |
| 160 | if (sc == null) { |
| 161 | forEach(slot, ain, aout, v); |
| 162 | return; |
| 163 | } |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 164 | int in_id = 0; |
| 165 | if (ain != null) { |
| 166 | in_id = ain.getID(mRS); |
| 167 | } |
| 168 | int out_id = 0; |
| 169 | if (aout != null) { |
| 170 | out_id = aout.getID(mRS); |
| 171 | } |
| 172 | byte[] params = null; |
| 173 | if (v != null) { |
| 174 | params = v.getData(); |
| 175 | } |
| 176 | mRS.nScriptForEachClipped(getID(mRS), slot, in_id, out_id, params, sc.xstart, sc.xend, sc.ystart, sc.yend, sc.zstart, sc.zend); |
| 177 | } |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 178 | |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 179 | Script(int id, RenderScript rs) { |
Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 180 | super(id, rs); |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 181 | } |
| 182 | |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 183 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 184 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 185 | * Only intended for use by generated reflected code. |
| 186 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 187 | */ |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 188 | public void bindAllocation(Allocation va, int slot) { |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 189 | mRS.validate(); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 190 | if (va != null) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 191 | mRS.nScriptBindAllocation(getID(mRS), va.getID(mRS), slot); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 192 | } else { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 193 | mRS.nScriptBindAllocation(getID(mRS), 0, slot); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 194 | } |
| 195 | } |
| 196 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 197 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 198 | * Only intended for use by generated reflected code. |
| 199 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 200 | */ |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 201 | public void setVar(int index, float v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 202 | mRS.nScriptSetVarF(getID(mRS), index, v); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 203 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 204 | public float getVarF(int index) { |
| 205 | return mRS.nScriptGetVarF(getID(mRS), index); |
| 206 | } |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 207 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 208 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 209 | * Only intended for use by generated reflected code. |
| 210 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 211 | */ |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 212 | public void setVar(int index, double v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 213 | mRS.nScriptSetVarD(getID(mRS), index, v); |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 214 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 215 | public double getVarD(int index) { |
| 216 | return mRS.nScriptGetVarD(getID(mRS), index); |
| 217 | } |
Stephen Hines | ca54ec3 | 2010-09-20 17:20:30 -0700 | [diff] [blame] | 218 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 219 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 220 | * Only intended for use by generated reflected code. |
| 221 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 222 | */ |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 223 | public void setVar(int index, int v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 224 | mRS.nScriptSetVarI(getID(mRS), index, v); |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 225 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 226 | public int getVarI(int index) { |
| 227 | return mRS.nScriptGetVarI(getID(mRS), index); |
| 228 | } |
| 229 | |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 230 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 231 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 232 | * Only intended for use by generated reflected code. |
| 233 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 234 | */ |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 235 | public void setVar(int index, long v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 236 | mRS.nScriptSetVarJ(getID(mRS), index, v); |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 237 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 238 | public long getVarJ(int index) { |
| 239 | return mRS.nScriptGetVarJ(getID(mRS), index); |
| 240 | } |
| 241 | |
Stephen Hines | 031ec58c | 2010-10-11 10:54:21 -0700 | [diff] [blame] | 242 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 243 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 244 | * Only intended for use by generated reflected code. |
| 245 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 246 | */ |
Jason Sams | 0b9a22c | 2010-07-02 15:35:19 -0700 | [diff] [blame] | 247 | public void setVar(int index, boolean v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 248 | mRS.nScriptSetVarI(getID(mRS), index, v ? 1 : 0); |
Jason Sams | 0b9a22c | 2010-07-02 15:35:19 -0700 | [diff] [blame] | 249 | } |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 250 | public boolean getVarB(int index) { |
| 251 | return mRS.nScriptGetVarI(getID(mRS), index) > 0 ? true : false; |
| 252 | } |
Jason Sams | 0b9a22c | 2010-07-02 15:35:19 -0700 | [diff] [blame] | 253 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 254 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 255 | * Only intended for use by generated reflected code. |
| 256 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 257 | */ |
Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 258 | public void setVar(int index, BaseObj o) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 259 | mRS.nScriptSetVarObj(getID(mRS), index, (o == null) ? 0 : o.getID(mRS)); |
Jason Sams | 6f4cf0b | 2010-11-16 17:37:02 -0800 | [diff] [blame] | 260 | } |
| 261 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 262 | /** |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 263 | * Only intended for use by generated reflected code. |
| 264 | * |
Jason Sams | 67e3d20 | 2011-01-09 13:49:01 -0800 | [diff] [blame] | 265 | */ |
Jason Sams | 4d33993 | 2010-05-11 14:03:58 -0700 | [diff] [blame] | 266 | public void setVar(int index, FieldPacker v) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 267 | mRS.nScriptSetVarV(getID(mRS), index, v.getData()); |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 270 | /** |
Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 271 | * Only intended for use by generated reflected code. |
| 272 | * |
Stephen Hines | adeb809 | 2012-04-20 14:26:06 -0700 | [diff] [blame] | 273 | */ |
| 274 | public void setVar(int index, FieldPacker v, Element e, int[] dims) { |
| 275 | mRS.nScriptSetVarVE(getID(mRS), index, v.getData(), e.getID(mRS), dims); |
| 276 | } |
| 277 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 278 | /** |
| 279 | * Only intended for use by generated reflected code. |
| 280 | * |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 281 | */ |
Tim Murray | 7c4caad | 2013-04-10 16:21:40 -0700 | [diff] [blame] | 282 | public void getVarV(int index, FieldPacker v) { |
| 283 | mRS.nScriptGetVarV(getID(mRS), index, v.getData()); |
| 284 | } |
| 285 | |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 286 | public void setTimeZone(String timeZone) { |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 287 | mRS.validate(); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 288 | try { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 289 | mRS.nScriptSetTimeZone(getID(mRS), timeZone.getBytes("UTF-8")); |
Jason Sams | 2253417 | 2009-08-04 16:58:20 -0700 | [diff] [blame] | 290 | } catch (java.io.UnsupportedEncodingException e) { |
| 291 | throw new RuntimeException(e); |
| 292 | } |
| 293 | } |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 294 | |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame^] | 295 | /** |
| 296 | * Only intended for use by generated reflected code. |
| 297 | * |
| 298 | */ |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 299 | public static class Builder { |
| 300 | RenderScript mRS; |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 301 | |
| 302 | Builder(RenderScript rs) { |
| 303 | mRS = rs; |
| 304 | } |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 307 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 308 | /** |
| 309 | * Only intended for use by generated reflected code. |
| 310 | * |
| 311 | */ |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 312 | public static class FieldBase { |
| 313 | protected Element mElement; |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 314 | protected Allocation mAllocation; |
| 315 | |
| 316 | protected void init(RenderScript rs, int dimx) { |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 317 | mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT); |
| 318 | } |
| 319 | |
| 320 | protected void init(RenderScript rs, int dimx, int usages) { |
| 321 | mAllocation = Allocation.createSized(rs, mElement, dimx, Allocation.USAGE_SCRIPT | usages); |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | protected FieldBase() { |
| 325 | } |
| 326 | |
| 327 | public Element getElement() { |
| 328 | return mElement; |
| 329 | } |
| 330 | |
| 331 | public Type getType() { |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 332 | return mAllocation.getType(); |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | public Allocation getAllocation() { |
| 336 | return mAllocation; |
| 337 | } |
| 338 | |
| 339 | //@Override |
| 340 | public void updateAllocation() { |
| 341 | } |
Jason Sams | 2d71bc7 | 2010-03-26 16:06:43 -0700 | [diff] [blame] | 342 | } |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 343 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 344 | |
| 345 | /** |
| 346 | * Class used to specify clipping for a kernel launch. |
| 347 | * |
| 348 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 349 | public static final class LaunchOptions { |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 350 | private int xstart = 0; |
| 351 | private int ystart = 0; |
| 352 | private int xend = 0; |
| 353 | private int yend = 0; |
| 354 | private int zstart = 0; |
| 355 | private int zend = 0; |
| 356 | private int strategy; |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 357 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 358 | /** |
| 359 | * Set the X range. If the end value is set to 0 the X dimension is not |
| 360 | * clipped. |
| 361 | * |
| 362 | * @param xstartArg Must be >= 0 |
| 363 | * @param xendArg Must be >= xstartArg |
| 364 | * |
| 365 | * @return LaunchOptions |
| 366 | */ |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 367 | public LaunchOptions setX(int xstartArg, int xendArg) { |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 368 | if (xstartArg < 0 || xendArg <= xstartArg) { |
| 369 | throw new RSIllegalArgumentException("Invalid dimensions"); |
| 370 | } |
| 371 | xstart = xstartArg; |
| 372 | xend = xendArg; |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 373 | return this; |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 374 | } |
| 375 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 376 | /** |
| 377 | * Set the Y range. If the end value is set to 0 the Y dimension is not |
| 378 | * clipped. |
| 379 | * |
| 380 | * @param ystartArg Must be >= 0 |
| 381 | * @param yendArg Must be >= ystartArg |
| 382 | * |
| 383 | * @return LaunchOptions |
| 384 | */ |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 385 | public LaunchOptions setY(int ystartArg, int yendArg) { |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 386 | if (ystartArg < 0 || yendArg <= ystartArg) { |
| 387 | throw new RSIllegalArgumentException("Invalid dimensions"); |
| 388 | } |
| 389 | ystart = ystartArg; |
| 390 | yend = yendArg; |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 391 | return this; |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 392 | } |
| 393 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 394 | /** |
| 395 | * Set the Z range. If the end value is set to 0 the Z dimension is not |
| 396 | * clipped. |
| 397 | * |
| 398 | * @param zstartArg Must be >= 0 |
| 399 | * @param zendArg Must be >= zstartArg |
| 400 | * |
| 401 | * @return LaunchOptions |
| 402 | */ |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 403 | public LaunchOptions setZ(int zstartArg, int zendArg) { |
| 404 | if (zstartArg < 0 || zendArg <= zstartArg) { |
| 405 | throw new RSIllegalArgumentException("Invalid dimensions"); |
| 406 | } |
| 407 | zstart = zstartArg; |
| 408 | zend = zendArg; |
| 409 | return this; |
| 410 | } |
| 411 | |
| 412 | |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 413 | /** |
| 414 | * Returns the current X start |
| 415 | * |
| 416 | * @return int current value |
| 417 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 418 | public int getXStart() { |
| 419 | return xstart; |
| 420 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 421 | /** |
| 422 | * Returns the current X end |
| 423 | * |
| 424 | * @return int current value |
| 425 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 426 | public int getXEnd() { |
| 427 | return xend; |
| 428 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 429 | /** |
| 430 | * Returns the current Y start |
| 431 | * |
| 432 | * @return int current value |
| 433 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 434 | public int getYStart() { |
| 435 | return ystart; |
| 436 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 437 | /** |
| 438 | * Returns the current Y end |
| 439 | * |
| 440 | * @return int current value |
| 441 | */ |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 442 | public int getYEnd() { |
| 443 | return yend; |
| 444 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 445 | /** |
| 446 | * Returns the current Z start |
| 447 | * |
| 448 | * @return int current value |
| 449 | */ |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 450 | public int getZStart() { |
| 451 | return zstart; |
| 452 | } |
Jason Sams | f64cca9 | 2013-04-19 12:56:37 -0700 | [diff] [blame] | 453 | /** |
| 454 | * Returns the current Z end |
| 455 | * |
| 456 | * @return int current value |
| 457 | */ |
Tim Murray | eb8c29c | 2013-02-07 12:16:41 -0800 | [diff] [blame] | 458 | public int getZEnd() { |
| 459 | return zend; |
| 460 | } |
Tim Murray | fbfaa85 | 2012-12-14 16:01:58 -0800 | [diff] [blame] | 461 | |
| 462 | } |
Jason Sams | 69f0d31 | 2009-08-03 18:11:17 -0700 | [diff] [blame] | 463 | } |
| 464 | |