Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1 | /* |
Stephen Hines | 9069ee8 | 2012-02-13 18:25:54 -0800 | [diff] [blame] | 2 | * Copyright (C) 2008-2012 The Android Open Source Project |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -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 | 739c826 | 2013-04-11 18:07:52 -0700 | [diff] [blame] | 19 | import java.util.HashMap; |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 20 | import android.content.res.Resources; |
| 21 | import android.graphics.Bitmap; |
| 22 | import android.graphics.BitmapFactory; |
Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 23 | import android.view.Surface; |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 24 | import android.util.Log; |
Tim Murray | abd5db9 | 2013-02-28 11:45:22 -0800 | [diff] [blame] | 25 | import android.graphics.Canvas; |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 26 | import android.os.Trace; |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 27 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 28 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 29 | * <p> This class provides the primary method through which data is passed to |
| 30 | * and from RenderScript kernels. An Allocation provides the backing store for |
| 31 | * a given {@link android.renderscript.Type}. </p> |
Jason Sams | a23d4e7 | 2011-01-04 18:59:12 -0800 | [diff] [blame] | 32 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 33 | * <p>An Allocation also contains a set of usage flags that denote how the |
| 34 | * Allocation could be used. For example, an Allocation may have usage flags |
| 35 | * specifying that it can be used from a script as well as input to a {@link |
| 36 | * android.renderscript.Sampler}. A developer must synchronize across these |
| 37 | * different usages using {@link android.renderscript.Allocation#syncAll} in |
| 38 | * order to ensure that different users of the Allocation have a consistent view |
| 39 | * of memory. For example, in the case where an Allocation is used as the output |
| 40 | * of one kernel and as Sampler input in a later kernel, a developer must call |
| 41 | * {@link #syncAll syncAll(Allocation.USAGE_SCRIPT)} prior to launching the |
| 42 | * second kernel to ensure correctness. |
Jason Sams | a23d4e7 | 2011-01-04 18:59:12 -0800 | [diff] [blame] | 43 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 44 | * <p>An Allocation can be populated with the {@link #copyFrom} routines. For |
| 45 | * more complex Element types, the {@link #copyFromUnchecked} methods can be |
| 46 | * used to copy from byte arrays or similar constructs.</p> |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 47 | * |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 48 | * <div class="special reference"> |
| 49 | * <h3>Developer Guides</h3> |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 50 | * <p>For more information about creating an application that uses RenderScript, read the |
| 51 | * <a href="{@docRoot}guide/topics/renderscript/index.html">RenderScript</a> developer guide.</p> |
Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 52 | * </div> |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 53 | **/ |
| 54 | public class Allocation extends BaseObj { |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 55 | Type mType; |
Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 56 | Bitmap mBitmap; |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 57 | int mUsage; |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 58 | Allocation mAdaptedAllocation; |
Tim Murray | 2f2472c | 2013-08-22 14:55:26 -0700 | [diff] [blame] | 59 | int mSize; |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 60 | |
| 61 | boolean mConstrainedLOD; |
| 62 | boolean mConstrainedFace; |
| 63 | boolean mConstrainedY; |
| 64 | boolean mConstrainedZ; |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 65 | boolean mReadAllowed = true; |
| 66 | boolean mWriteAllowed = true; |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 67 | int mSelectedY; |
| 68 | int mSelectedZ; |
| 69 | int mSelectedLOD; |
| 70 | Type.CubemapFace mSelectedFace = Type.CubemapFace.POSITIVE_X; |
| 71 | |
| 72 | int mCurrentDimX; |
| 73 | int mCurrentDimY; |
| 74 | int mCurrentDimZ; |
| 75 | int mCurrentCount; |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 76 | static HashMap<Long, Allocation> mAllocationMap = |
| 77 | new HashMap<Long, Allocation>(); |
Jason Sams | 42ef238 | 2013-08-29 13:30:59 -0700 | [diff] [blame] | 78 | OnBufferAvailableListener mBufferNotifier; |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 79 | |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 80 | private Element.DataType validateObjectIsPrimitiveArray(Object d, boolean checkType) { |
| 81 | final Class c = d.getClass(); |
| 82 | if (!c.isArray()) { |
| 83 | throw new RSIllegalArgumentException("Object passed is not an array of primitives."); |
| 84 | } |
| 85 | final Class cmp = c.getComponentType(); |
| 86 | if (!cmp.isPrimitive()) { |
| 87 | throw new RSIllegalArgumentException("Object passed is not an Array of primitives."); |
| 88 | } |
| 89 | |
| 90 | if (cmp == Long.TYPE) { |
| 91 | if (checkType) { |
| 92 | validateIsInt64(); |
| 93 | return mType.mElement.mType; |
| 94 | } |
| 95 | return Element.DataType.SIGNED_64; |
| 96 | } |
| 97 | |
| 98 | if (cmp == Integer.TYPE) { |
| 99 | if (checkType) { |
| 100 | validateIsInt32(); |
| 101 | return mType.mElement.mType; |
| 102 | } |
| 103 | return Element.DataType.SIGNED_32; |
| 104 | } |
| 105 | |
| 106 | if (cmp == Short.TYPE) { |
| 107 | if (checkType) { |
| 108 | validateIsInt16(); |
| 109 | return mType.mElement.mType; |
| 110 | } |
| 111 | return Element.DataType.SIGNED_16; |
| 112 | } |
| 113 | |
| 114 | if (cmp == Byte.TYPE) { |
| 115 | if (checkType) { |
| 116 | validateIsInt8(); |
| 117 | return mType.mElement.mType; |
| 118 | } |
| 119 | return Element.DataType.SIGNED_8; |
| 120 | } |
| 121 | |
| 122 | if (cmp == Float.TYPE) { |
| 123 | if (checkType) { |
| 124 | validateIsFloat32(); |
| 125 | } |
| 126 | return Element.DataType.FLOAT_32; |
| 127 | } |
| 128 | |
| 129 | if (cmp == Double.TYPE) { |
| 130 | if (checkType) { |
| 131 | validateIsFloat64(); |
| 132 | } |
| 133 | return Element.DataType.FLOAT_64; |
| 134 | } |
| 135 | return null; |
| 136 | } |
| 137 | |
| 138 | |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 139 | /** |
| 140 | * The usage of the Allocation. These signal to RenderScript where to place |
| 141 | * the Allocation in memory. |
| 142 | * |
| 143 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 144 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 145 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 146 | * The Allocation will be bound to and accessed by scripts. |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 147 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 148 | public static final int USAGE_SCRIPT = 0x0001; |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 149 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 150 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 151 | * The Allocation will be used as a texture source by one or more graphics |
| 152 | * programs. |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 153 | * |
| 154 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 155 | public static final int USAGE_GRAPHICS_TEXTURE = 0x0002; |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 156 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 157 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 158 | * The Allocation will be used as a graphics mesh. |
| 159 | * |
| 160 | * This was deprecated in API level 16. |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 161 | * |
| 162 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 163 | public static final int USAGE_GRAPHICS_VERTEX = 0x0004; |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 164 | |
| 165 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 166 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 167 | * The Allocation will be used as the source of shader constants by one or |
| 168 | * more programs. |
| 169 | * |
| 170 | * This was deprecated in API level 16. |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 171 | * |
| 172 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 173 | public static final int USAGE_GRAPHICS_CONSTANTS = 0x0008; |
| 174 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 175 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 176 | * The Allocation will be used as a target for offscreen rendering |
| 177 | * |
| 178 | * This was deprecated in API level 16. |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 179 | * |
| 180 | */ |
| 181 | public static final int USAGE_GRAPHICS_RENDER_TARGET = 0x0010; |
| 182 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 183 | /** |
Jason Sams | 3a1b8e4 | 2013-09-24 15:18:52 -0700 | [diff] [blame] | 184 | * The Allocation will be used as a {@link android.view.Surface} |
| 185 | * consumer. This usage will cause the Allocation to be created |
| 186 | * as read-only. |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 187 | * |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 188 | */ |
Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 189 | public static final int USAGE_IO_INPUT = 0x0020; |
Stephen Hines | 9069ee8 | 2012-02-13 18:25:54 -0800 | [diff] [blame] | 190 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 191 | /** |
Jason Sams | 3a1b8e4 | 2013-09-24 15:18:52 -0700 | [diff] [blame] | 192 | * The Allocation will be used as a {@link android.view.Surface} |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 193 | * producer. The dimensions and format of the {@link |
Jason Sams | 3a1b8e4 | 2013-09-24 15:18:52 -0700 | [diff] [blame] | 194 | * android.view.Surface} will be forced to those of the |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 195 | * Allocation. |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 196 | * |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 197 | */ |
Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 198 | public static final int USAGE_IO_OUTPUT = 0x0040; |
Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 199 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 200 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 201 | * The Allocation's backing store will be inherited from another object |
| 202 | * (usually a {@link android.graphics.Bitmap}); copying to or from the |
| 203 | * original source Bitmap will cause a synchronization rather than a full |
| 204 | * copy. {@link #syncAll} may also be used to synchronize the Allocation |
| 205 | * and the source Bitmap. |
Tim Murray | 00bb454 | 2012-12-17 16:35:06 -0800 | [diff] [blame] | 206 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 207 | * <p>This is set by default for allocations created with {@link |
| 208 | * #createFromBitmap} in API version 18 and higher.</p> |
Tim Murray | 00bb454 | 2012-12-17 16:35:06 -0800 | [diff] [blame] | 209 | * |
| 210 | */ |
| 211 | public static final int USAGE_SHARED = 0x0080; |
| 212 | |
| 213 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 214 | * Controls mipmap behavior when using the bitmap creation and update |
| 215 | * functions. |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 216 | */ |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 217 | public enum MipmapControl { |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 218 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 219 | * No mipmaps will be generated and the type generated from the incoming |
| 220 | * bitmap will not contain additional LODs. |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 221 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 222 | MIPMAP_NONE(0), |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 223 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 224 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 225 | * A full mipmap chain will be created in script memory. The Type of |
| 226 | * the Allocation will contain a full mipmap chain. On upload, the full |
| 227 | * chain will be transferred. |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 228 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 229 | MIPMAP_FULL(1), |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 230 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 231 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 232 | * The Type of the Allocation will be the same as MIPMAP_NONE. It will |
| 233 | * not contain mipmaps. On upload, the allocation data will contain a |
| 234 | * full mipmap chain generated from the top level in script memory. |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 235 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 236 | MIPMAP_ON_SYNC_TO_TEXTURE(2); |
| 237 | |
| 238 | int mID; |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 239 | MipmapControl(int id) { |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 240 | mID = id; |
| 241 | } |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 242 | } |
| 243 | |
Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 244 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 245 | private long getIDSafe() { |
Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 246 | if (mAdaptedAllocation != null) { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 247 | return mAdaptedAllocation.getID(mRS); |
Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 248 | } |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 249 | return getID(mRS); |
Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 252 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 253 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 254 | * Get the {@link android.renderscript.Element} of the {@link |
| 255 | * android.renderscript.Type} of the Allocation. |
Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 256 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 257 | * @return Element |
Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 258 | * |
| 259 | */ |
| 260 | public Element getElement() { |
| 261 | return mType.getElement(); |
| 262 | } |
| 263 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 264 | /** |
Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 265 | * Get the usage flags of the Allocation. |
| 266 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 267 | * @return usage this Allocation's set of the USAGE_* flags OR'd together |
Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 268 | * |
| 269 | */ |
| 270 | public int getUsage() { |
| 271 | return mUsage; |
| 272 | } |
| 273 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 274 | /** |
Jason Sams | 36c0f64 | 2012-03-23 15:48:37 -0700 | [diff] [blame] | 275 | * Get the size of the Allocation in bytes. |
| 276 | * |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 277 | * @return size of the Allocation in bytes. |
Jason Sams | 36c0f64 | 2012-03-23 15:48:37 -0700 | [diff] [blame] | 278 | * |
| 279 | */ |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 280 | public int getBytesSize() { |
Tim Murray | 04f0d6e | 2013-12-17 17:15:25 -0800 | [diff] [blame] | 281 | if (mType.mDimYuv != 0) { |
| 282 | return (int)Math.ceil(mType.getCount() * mType.getElement().getBytesSize() * 1.5); |
| 283 | } |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 284 | return mType.getCount() * mType.getElement().getBytesSize(); |
Jason Sams | 36c0f64 | 2012-03-23 15:48:37 -0700 | [diff] [blame] | 285 | } |
| 286 | |
Jason Sams | 452a766 | 2011-07-07 16:05:18 -0700 | [diff] [blame] | 287 | private void updateCacheInfo(Type t) { |
| 288 | mCurrentDimX = t.getX(); |
| 289 | mCurrentDimY = t.getY(); |
| 290 | mCurrentDimZ = t.getZ(); |
| 291 | mCurrentCount = mCurrentDimX; |
| 292 | if (mCurrentDimY > 1) { |
| 293 | mCurrentCount *= mCurrentDimY; |
| 294 | } |
| 295 | if (mCurrentDimZ > 1) { |
| 296 | mCurrentCount *= mCurrentDimZ; |
| 297 | } |
| 298 | } |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 299 | |
Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 300 | private void setBitmap(Bitmap b) { |
| 301 | mBitmap = b; |
| 302 | } |
| 303 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 304 | Allocation(long id, RenderScript rs, Type t, int usage) { |
Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 305 | super(id, rs); |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 306 | if ((usage & ~(USAGE_SCRIPT | |
| 307 | USAGE_GRAPHICS_TEXTURE | |
| 308 | USAGE_GRAPHICS_VERTEX | |
Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 309 | USAGE_GRAPHICS_CONSTANTS | |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 310 | USAGE_GRAPHICS_RENDER_TARGET | |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 311 | USAGE_IO_INPUT | |
Tim Murray | 00bb454 | 2012-12-17 16:35:06 -0800 | [diff] [blame] | 312 | USAGE_IO_OUTPUT | |
| 313 | USAGE_SHARED)) != 0) { |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 314 | throw new RSIllegalArgumentException("Unknown usage specified."); |
| 315 | } |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 316 | |
Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 317 | if ((usage & USAGE_IO_INPUT) != 0) { |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 318 | mWriteAllowed = false; |
| 319 | |
Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 320 | if ((usage & ~(USAGE_IO_INPUT | |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 321 | USAGE_GRAPHICS_TEXTURE | |
| 322 | USAGE_SCRIPT)) != 0) { |
| 323 | throw new RSIllegalArgumentException("Invalid usage combination."); |
| 324 | } |
| 325 | } |
Jason Sams | 9bf1892 | 2013-04-13 19:48:36 -0700 | [diff] [blame] | 326 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 327 | mType = t; |
Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 328 | mUsage = usage; |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 329 | |
Jason Sams | 452a766 | 2011-07-07 16:05:18 -0700 | [diff] [blame] | 330 | if (t != null) { |
Stephen Hines | 88990da | 2013-09-09 17:56:07 -0700 | [diff] [blame] | 331 | // TODO: A3D doesn't have Type info during creation, so we can't |
| 332 | // calculate the size ahead of time. We can possibly add a method |
| 333 | // to update the size in the future if it seems reasonable. |
| 334 | mSize = mType.getCount() * mType.getElement().getBytesSize(); |
Jason Sams | 452a766 | 2011-07-07 16:05:18 -0700 | [diff] [blame] | 335 | updateCacheInfo(t); |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 336 | } |
Tim Murray | 2f2472c | 2013-08-22 14:55:26 -0700 | [diff] [blame] | 337 | try { |
| 338 | RenderScript.registerNativeAllocation.invoke(RenderScript.sRuntime, mSize); |
| 339 | } catch (Exception e) { |
| 340 | Log.e(RenderScript.LOG_TAG, "Couldn't invoke registerNativeAllocation:" + e); |
| 341 | throw new RSRuntimeException("Couldn't invoke registerNativeAllocation:" + e); |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | protected void finalize() throws Throwable { |
| 346 | RenderScript.registerNativeFree.invoke(RenderScript.sRuntime, mSize); |
| 347 | super.finalize(); |
Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 350 | private void validateIsInt64() { |
| 351 | if ((mType.mElement.mType == Element.DataType.SIGNED_64) || |
| 352 | (mType.mElement.mType == Element.DataType.UNSIGNED_64)) { |
| 353 | return; |
| 354 | } |
| 355 | throw new RSIllegalArgumentException( |
| 356 | "64 bit integer source does not match allocation type " + mType.mElement.mType); |
| 357 | } |
| 358 | |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 359 | private void validateIsInt32() { |
| 360 | if ((mType.mElement.mType == Element.DataType.SIGNED_32) || |
| 361 | (mType.mElement.mType == Element.DataType.UNSIGNED_32)) { |
| 362 | return; |
| 363 | } |
| 364 | throw new RSIllegalArgumentException( |
| 365 | "32 bit integer source does not match allocation type " + mType.mElement.mType); |
| 366 | } |
| 367 | |
| 368 | private void validateIsInt16() { |
| 369 | if ((mType.mElement.mType == Element.DataType.SIGNED_16) || |
| 370 | (mType.mElement.mType == Element.DataType.UNSIGNED_16)) { |
| 371 | return; |
| 372 | } |
| 373 | throw new RSIllegalArgumentException( |
| 374 | "16 bit integer source does not match allocation type " + mType.mElement.mType); |
| 375 | } |
| 376 | |
| 377 | private void validateIsInt8() { |
| 378 | if ((mType.mElement.mType == Element.DataType.SIGNED_8) || |
| 379 | (mType.mElement.mType == Element.DataType.UNSIGNED_8)) { |
| 380 | return; |
| 381 | } |
| 382 | throw new RSIllegalArgumentException( |
| 383 | "8 bit integer source does not match allocation type " + mType.mElement.mType); |
| 384 | } |
| 385 | |
| 386 | private void validateIsFloat32() { |
| 387 | if (mType.mElement.mType == Element.DataType.FLOAT_32) { |
| 388 | return; |
| 389 | } |
| 390 | throw new RSIllegalArgumentException( |
| 391 | "32 bit float source does not match allocation type " + mType.mElement.mType); |
| 392 | } |
| 393 | |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 394 | private void validateIsFloat64() { |
| 395 | if (mType.mElement.mType == Element.DataType.FLOAT_64) { |
| 396 | return; |
| 397 | } |
| 398 | throw new RSIllegalArgumentException( |
| 399 | "64 bit float source does not match allocation type " + mType.mElement.mType); |
| 400 | } |
| 401 | |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 402 | private void validateIsObject() { |
| 403 | if ((mType.mElement.mType == Element.DataType.RS_ELEMENT) || |
| 404 | (mType.mElement.mType == Element.DataType.RS_TYPE) || |
| 405 | (mType.mElement.mType == Element.DataType.RS_ALLOCATION) || |
| 406 | (mType.mElement.mType == Element.DataType.RS_SAMPLER) || |
| 407 | (mType.mElement.mType == Element.DataType.RS_SCRIPT) || |
| 408 | (mType.mElement.mType == Element.DataType.RS_MESH) || |
| 409 | (mType.mElement.mType == Element.DataType.RS_PROGRAM_FRAGMENT) || |
| 410 | (mType.mElement.mType == Element.DataType.RS_PROGRAM_VERTEX) || |
| 411 | (mType.mElement.mType == Element.DataType.RS_PROGRAM_RASTER) || |
| 412 | (mType.mElement.mType == Element.DataType.RS_PROGRAM_STORE)) { |
| 413 | return; |
| 414 | } |
| 415 | throw new RSIllegalArgumentException( |
| 416 | "Object source does not match allocation type " + mType.mElement.mType); |
| 417 | } |
| 418 | |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 419 | @Override |
| 420 | void updateFromNative() { |
Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 421 | super.updateFromNative(); |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 422 | long typeID = mRS.nAllocationGetType(getID(mRS)); |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 423 | if(typeID != 0) { |
| 424 | mType = new Type(typeID, mRS); |
| 425 | mType.updateFromNative(); |
Jason Sams | ad37cb2 | 2011-07-07 16:17:36 -0700 | [diff] [blame] | 426 | updateCacheInfo(mType); |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 430 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 431 | * Get the {@link android.renderscript.Type} of the Allocation. |
Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 432 | * |
| 433 | * @return Type |
| 434 | * |
| 435 | */ |
Jason Sams | ea87e96 | 2010-01-12 12:12:28 -0800 | [diff] [blame] | 436 | public Type getType() { |
| 437 | return mType; |
| 438 | } |
| 439 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 440 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 441 | * Propagate changes from one usage of the Allocation to the |
| 442 | * other usages of the Allocation. |
Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 443 | * |
| 444 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 445 | public void syncAll(int srcLocation) { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 446 | Trace.traceBegin(RenderScript.TRACE_TAG, "syncAll"); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 447 | switch (srcLocation) { |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 448 | case USAGE_GRAPHICS_TEXTURE: |
Tim Murray | 78e6494 | 2013-04-09 17:28:56 -0700 | [diff] [blame] | 449 | case USAGE_SCRIPT: |
| 450 | if ((mUsage & USAGE_SHARED) != 0) { |
| 451 | copyFrom(mBitmap); |
| 452 | } |
| 453 | break; |
| 454 | case USAGE_GRAPHICS_CONSTANTS: |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 455 | case USAGE_GRAPHICS_VERTEX: |
| 456 | break; |
Tim Murray | 78e6494 | 2013-04-09 17:28:56 -0700 | [diff] [blame] | 457 | case USAGE_SHARED: |
| 458 | if ((mUsage & USAGE_SHARED) != 0) { |
| 459 | copyTo(mBitmap); |
| 460 | } |
| 461 | break; |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 462 | default: |
| 463 | throw new RSIllegalArgumentException("Source must be exactly one usage type."); |
| 464 | } |
| 465 | mRS.validate(); |
Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 466 | mRS.nAllocationSyncAll(getIDSafe(), srcLocation); |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 467 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 468 | } |
| 469 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 470 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 471 | * Send a buffer to the output stream. The contents of the Allocation will |
| 472 | * be undefined after this operation. This operation is only valid if {@link |
| 473 | * #USAGE_IO_OUTPUT} is set on the Allocation. |
| 474 | * |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 475 | * |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 476 | */ |
Jason Sams | c5f519c | 2012-03-29 17:58:15 -0700 | [diff] [blame] | 477 | public void ioSend() { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 478 | Trace.traceBegin(RenderScript.TRACE_TAG, "ioSend"); |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 479 | if ((mUsage & USAGE_IO_OUTPUT) == 0) { |
| 480 | throw new RSIllegalArgumentException( |
| 481 | "Can only send buffer if IO_OUTPUT usage specified."); |
| 482 | } |
| 483 | mRS.validate(); |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 484 | mRS.nAllocationIoSend(getID(mRS)); |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 485 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 486 | } |
| 487 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 488 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 489 | * Receive the latest input into the Allocation. This operation |
| 490 | * is only valid if {@link #USAGE_IO_INPUT} is set on the Allocation. |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 491 | * |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 492 | */ |
Jason Sams | c5f519c | 2012-03-29 17:58:15 -0700 | [diff] [blame] | 493 | public void ioReceive() { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 494 | Trace.traceBegin(RenderScript.TRACE_TAG, "ioReceive"); |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 495 | if ((mUsage & USAGE_IO_INPUT) == 0) { |
| 496 | throw new RSIllegalArgumentException( |
Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 497 | "Can only receive if IO_INPUT usage specified."); |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 498 | } |
| 499 | mRS.validate(); |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 500 | mRS.nAllocationIoReceive(getID(mRS)); |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 501 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 504 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 505 | * Copy an array of RS objects to the Allocation. |
Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 506 | * |
| 507 | * @param d Source array. |
| 508 | */ |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 509 | public void copyFrom(BaseObj[] d) { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 510 | Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom"); |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 511 | mRS.validate(); |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 512 | validateIsObject(); |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 513 | if (d.length != mCurrentCount) { |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 514 | throw new RSIllegalArgumentException("Array size mismatch, allocation sizeX = " + |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 515 | mCurrentCount + ", array length = " + d.length); |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 516 | } |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 517 | // FIXME: requires 64-bit path |
| 518 | |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 519 | int i[] = new int[d.length]; |
| 520 | for (int ct=0; ct < d.length; ct++) { |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 521 | i[ct] = (int)d[ct].getID(mRS); |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 522 | } |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 523 | copy1DRangeFromUnchecked(0, mCurrentCount, i); |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 524 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 525 | } |
| 526 | |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 527 | private void validateBitmapFormat(Bitmap b) { |
Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 528 | Bitmap.Config bc = b.getConfig(); |
Tim Murray | abd5db9 | 2013-02-28 11:45:22 -0800 | [diff] [blame] | 529 | if (bc == null) { |
| 530 | throw new RSIllegalArgumentException("Bitmap has an unsupported format for this operation"); |
| 531 | } |
Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 532 | switch (bc) { |
| 533 | case ALPHA_8: |
| 534 | if (mType.getElement().mKind != Element.DataKind.PIXEL_A) { |
| 535 | throw new RSIllegalArgumentException("Allocation kind is " + |
| 536 | mType.getElement().mKind + ", type " + |
| 537 | mType.getElement().mType + |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 538 | " of " + mType.getElement().getBytesSize() + |
Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 539 | " bytes, passed bitmap was " + bc); |
| 540 | } |
| 541 | break; |
| 542 | case ARGB_8888: |
| 543 | if ((mType.getElement().mKind != Element.DataKind.PIXEL_RGBA) || |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 544 | (mType.getElement().getBytesSize() != 4)) { |
Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 545 | throw new RSIllegalArgumentException("Allocation kind is " + |
| 546 | mType.getElement().mKind + ", type " + |
| 547 | mType.getElement().mType + |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 548 | " of " + mType.getElement().getBytesSize() + |
Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 549 | " bytes, passed bitmap was " + bc); |
| 550 | } |
| 551 | break; |
| 552 | case RGB_565: |
| 553 | if ((mType.getElement().mKind != Element.DataKind.PIXEL_RGB) || |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 554 | (mType.getElement().getBytesSize() != 2)) { |
Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 555 | throw new RSIllegalArgumentException("Allocation kind is " + |
| 556 | mType.getElement().mKind + ", type " + |
| 557 | mType.getElement().mType + |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 558 | " of " + mType.getElement().getBytesSize() + |
Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 559 | " bytes, passed bitmap was " + bc); |
| 560 | } |
| 561 | break; |
| 562 | case ARGB_4444: |
| 563 | if ((mType.getElement().mKind != Element.DataKind.PIXEL_RGBA) || |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 564 | (mType.getElement().getBytesSize() != 2)) { |
Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 565 | throw new RSIllegalArgumentException("Allocation kind is " + |
| 566 | mType.getElement().mKind + ", type " + |
| 567 | mType.getElement().mType + |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 568 | " of " + mType.getElement().getBytesSize() + |
Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 569 | " bytes, passed bitmap was " + bc); |
| 570 | } |
| 571 | break; |
| 572 | |
| 573 | } |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 574 | } |
| 575 | |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 576 | private void validateBitmapSize(Bitmap b) { |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 577 | if((mCurrentDimX != b.getWidth()) || (mCurrentDimY != b.getHeight())) { |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 578 | throw new RSIllegalArgumentException("Cannot update allocation from bitmap, sizes mismatch"); |
| 579 | } |
| 580 | } |
| 581 | |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 582 | private void copyFromUnchecked(Object array, Element.DataType dt, int arrayLen) { |
| 583 | Trace.traceBegin(RenderScript.TRACE_TAG, "copyFromUnchecked"); |
| 584 | mRS.validate(); |
| 585 | if (mCurrentDimZ > 0) { |
| 586 | copy3DRangeFromUnchecked(0, 0, 0, mCurrentDimX, mCurrentDimY, mCurrentDimZ, array, dt, arrayLen); |
| 587 | } else if (mCurrentDimY > 0) { |
| 588 | copy2DRangeFromUnchecked(0, 0, mCurrentDimX, mCurrentDimY, array, dt, arrayLen); |
| 589 | } else { |
| 590 | copy1DRangeFromUnchecked(0, mCurrentCount, array, dt, arrayLen); |
| 591 | } |
| 592 | Trace.traceEnd(RenderScript.TRACE_TAG); |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * Copy into this Allocation from an array. This method does not guarantee |
| 597 | * that the Allocation is compatible with the input buffer; it copies memory |
| 598 | * without reinterpretation. |
| 599 | * |
| 600 | * @param array The source data array |
| 601 | */ |
| 602 | public void copyFromUnchecked(Object array) { |
| 603 | Trace.traceBegin(RenderScript.TRACE_TAG, "copyFromUnchecked"); |
| 604 | copyFromUnchecked(array, validateObjectIsPrimitiveArray(array, false), |
| 605 | java.lang.reflect.Array.getLength(array)); |
| 606 | Trace.traceEnd(RenderScript.TRACE_TAG); |
| 607 | } |
| 608 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 609 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 610 | * Copy into this Allocation from an array. This method does not guarantee |
| 611 | * that the Allocation is compatible with the input buffer; it copies memory |
| 612 | * without reinterpretation. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 613 | * |
| 614 | * @param d the source data array |
| 615 | */ |
| 616 | public void copyFromUnchecked(int[] d) { |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 617 | copyFromUnchecked(d, Element.DataType.SIGNED_32, d.length); |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 618 | } |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 619 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 620 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 621 | * Copy into this Allocation from an array. This method does not guarantee |
| 622 | * that the Allocation is compatible with the input buffer; it copies memory |
| 623 | * without reinterpretation. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 624 | * |
| 625 | * @param d the source data array |
| 626 | */ |
| 627 | public void copyFromUnchecked(short[] d) { |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 628 | copyFromUnchecked(d, Element.DataType.SIGNED_16, d.length); |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 629 | } |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 630 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 631 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 632 | * Copy into this Allocation from an array. This method does not guarantee |
| 633 | * that the Allocation is compatible with the input buffer; it copies memory |
| 634 | * without reinterpretation. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 635 | * |
| 636 | * @param d the source data array |
| 637 | */ |
| 638 | public void copyFromUnchecked(byte[] d) { |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 639 | copyFromUnchecked(d, Element.DataType.SIGNED_8, d.length); |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 640 | } |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 641 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 642 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 643 | * Copy into this Allocation from an array. This method does not guarantee |
| 644 | * that the Allocation is compatible with the input buffer; it copies memory |
| 645 | * without reinterpretation. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 646 | * |
| 647 | * @param d the source data array |
| 648 | */ |
| 649 | public void copyFromUnchecked(float[] d) { |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 650 | copyFromUnchecked(d, Element.DataType.FLOAT_32, d.length); |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 651 | } |
| 652 | |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 653 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 654 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 655 | * Copy into this Allocation from an array. This variant is type checked |
| 656 | * and will generate exceptions if the Allocation's {@link |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 657 | * android.renderscript.Element} does not match the array's |
| 658 | * primitive type. |
| 659 | * |
Ying Wang | 1622981 | 2013-11-26 15:45:12 -0800 | [diff] [blame] | 660 | * @param array The source data array |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 661 | */ |
| 662 | public void copyFrom(Object array) { |
| 663 | Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom"); |
| 664 | copyFromUnchecked(array, validateObjectIsPrimitiveArray(array, true), |
| 665 | java.lang.reflect.Array.getLength(array)); |
| 666 | Trace.traceEnd(RenderScript.TRACE_TAG); |
| 667 | } |
| 668 | |
| 669 | /** |
| 670 | * Copy into this Allocation from an array. This variant is type checked |
| 671 | * and will generate exceptions if the Allocation's {@link |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 672 | * android.renderscript.Element} is not a 32 bit integer type. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 673 | * |
| 674 | * @param d the source data array |
| 675 | */ |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 676 | public void copyFrom(int[] d) { |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 677 | validateIsInt32(); |
| 678 | copyFromUnchecked(d, Element.DataType.SIGNED_32, d.length); |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 679 | } |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 680 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 681 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 682 | * Copy into this Allocation from an array. This variant is type checked |
| 683 | * and will generate exceptions if the Allocation's {@link |
| 684 | * android.renderscript.Element} is not a 16 bit integer type. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 685 | * |
| 686 | * @param d the source data array |
| 687 | */ |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 688 | public void copyFrom(short[] d) { |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 689 | validateIsInt16(); |
| 690 | copyFromUnchecked(d, Element.DataType.SIGNED_16, d.length); |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 691 | } |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 692 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 693 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 694 | * Copy into this Allocation from an array. This variant is type checked |
| 695 | * and will generate exceptions if the Allocation's {@link |
| 696 | * android.renderscript.Element} is not an 8 bit integer type. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 697 | * |
| 698 | * @param d the source data array |
| 699 | */ |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 700 | public void copyFrom(byte[] d) { |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 701 | validateIsInt8(); |
| 702 | copyFromUnchecked(d, Element.DataType.SIGNED_8, d.length); |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 703 | } |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 704 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 705 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 706 | * Copy into this Allocation from an array. This variant is type checked |
| 707 | * and will generate exceptions if the Allocation's {@link |
| 708 | * android.renderscript.Element} is not a 32 bit float type. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 709 | * |
| 710 | * @param d the source data array |
| 711 | */ |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 712 | public void copyFrom(float[] d) { |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 713 | validateIsFloat32(); |
| 714 | copyFromUnchecked(d, Element.DataType.FLOAT_32, d.length); |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 715 | } |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 716 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 717 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 718 | * Copy into an Allocation from a {@link android.graphics.Bitmap}. The |
| 719 | * height, width, and format of the bitmap must match the existing |
| 720 | * allocation. |
| 721 | * |
| 722 | * <p>If the {@link android.graphics.Bitmap} is the same as the {@link |
| 723 | * android.graphics.Bitmap} used to create the Allocation with {@link |
| 724 | * #createFromBitmap} and {@link #USAGE_SHARED} is set on the Allocation, |
| 725 | * this will synchronize the Allocation with the latest data from the {@link |
| 726 | * android.graphics.Bitmap}, potentially avoiding the actual copy.</p> |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 727 | * |
| 728 | * @param b the source bitmap |
| 729 | */ |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 730 | public void copyFrom(Bitmap b) { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 731 | Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom"); |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 732 | mRS.validate(); |
Tim Murray | abd5db9 | 2013-02-28 11:45:22 -0800 | [diff] [blame] | 733 | if (b.getConfig() == null) { |
| 734 | Bitmap newBitmap = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ARGB_8888); |
| 735 | Canvas c = new Canvas(newBitmap); |
| 736 | c.drawBitmap(b, 0, 0, null); |
| 737 | copyFrom(newBitmap); |
| 738 | return; |
| 739 | } |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 740 | validateBitmapSize(b); |
| 741 | validateBitmapFormat(b); |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 742 | mRS.nAllocationCopyFromBitmap(getID(mRS), b); |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 743 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 744 | } |
| 745 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 746 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 747 | * Copy an Allocation from an Allocation. The types of both allocations |
Tim Murray | f671fb0 | 2012-10-03 13:50:05 -0700 | [diff] [blame] | 748 | * must be identical. |
| 749 | * |
| 750 | * @param a the source allocation |
| 751 | */ |
| 752 | public void copyFrom(Allocation a) { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 753 | Trace.traceBegin(RenderScript.TRACE_TAG, "copyFrom"); |
Tim Murray | f671fb0 | 2012-10-03 13:50:05 -0700 | [diff] [blame] | 754 | mRS.validate(); |
| 755 | if (!mType.equals(a.getType())) { |
| 756 | throw new RSIllegalArgumentException("Types of allocations must match."); |
| 757 | } |
| 758 | copy2DRangeFrom(0, 0, mCurrentDimX, mCurrentDimY, a, 0, 0); |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 759 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Tim Murray | f671fb0 | 2012-10-03 13:50:05 -0700 | [diff] [blame] | 760 | } |
| 761 | |
Tim Murray | f671fb0 | 2012-10-03 13:50:05 -0700 | [diff] [blame] | 762 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 763 | * This is only intended to be used by auto-generated code reflected from |
| 764 | * the RenderScript script files and should not be used by developers. |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 765 | * |
| 766 | * @param xoff |
| 767 | * @param fp |
| 768 | */ |
Jason Sams | 21b4103 | 2011-01-16 15:05:41 -0800 | [diff] [blame] | 769 | public void setFromFieldPacker(int xoff, FieldPacker fp) { |
Jason Sams | f70b0fc8 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 770 | mRS.validate(); |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 771 | int eSize = mType.mElement.getBytesSize(); |
Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 772 | final byte[] data = fp.getData(); |
| 773 | |
| 774 | int count = data.length / eSize; |
| 775 | if ((eSize * count) != data.length) { |
Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 776 | throw new RSIllegalArgumentException("Field packer length " + data.length + |
Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 777 | " not divisible by element size " + eSize + "."); |
| 778 | } |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 779 | copy1DRangeFromUnchecked(xoff, count, data); |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 782 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 783 | * This is only intended to be used by auto-generated code reflected from |
| 784 | * the RenderScript script files. |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 785 | * |
| 786 | * @param xoff |
| 787 | * @param component_number |
| 788 | * @param fp |
| 789 | */ |
Jason Sams | 21b4103 | 2011-01-16 15:05:41 -0800 | [diff] [blame] | 790 | public void setFromFieldPacker(int xoff, int component_number, FieldPacker fp) { |
Jason Sams | f70b0fc8 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 791 | mRS.validate(); |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 792 | if (component_number >= mType.mElement.mElements.length) { |
Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 793 | throw new RSIllegalArgumentException("Component_number " + component_number + " out of range."); |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 794 | } |
| 795 | if(xoff < 0) { |
Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 796 | throw new RSIllegalArgumentException("Offset must be >= 0."); |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 797 | } |
| 798 | |
| 799 | final byte[] data = fp.getData(); |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 800 | int eSize = mType.mElement.mElements[component_number].getBytesSize(); |
Alex Sakhartchouk | bf3c3f2 | 2012-02-02 09:47:26 -0800 | [diff] [blame] | 801 | eSize *= mType.mElement.mArraySizes[component_number]; |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 802 | |
| 803 | if (data.length != eSize) { |
Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 804 | throw new RSIllegalArgumentException("Field packer sizelength " + data.length + |
Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 805 | " does not match component size " + eSize + "."); |
| 806 | } |
| 807 | |
Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 808 | mRS.nAllocationElementData1D(getIDSafe(), xoff, mSelectedLOD, |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 809 | component_number, data, data.length); |
Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 810 | } |
| 811 | |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 812 | private void data1DChecks(int off, int count, int len, int dataSize) { |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 813 | mRS.validate(); |
Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 814 | if(off < 0) { |
Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 815 | throw new RSIllegalArgumentException("Offset must be >= 0."); |
Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 816 | } |
| 817 | if(count < 1) { |
Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 818 | throw new RSIllegalArgumentException("Count must be >= 1."); |
Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 819 | } |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 820 | if((off + count) > mCurrentCount) { |
| 821 | throw new RSIllegalArgumentException("Overflow, Available count " + mCurrentCount + |
Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 822 | ", got " + count + " at offset " + off + "."); |
Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 823 | } |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 824 | if(len < dataSize) { |
Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 825 | throw new RSIllegalArgumentException("Array too small for allocation type."); |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 826 | } |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 827 | } |
| 828 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 829 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 830 | * Generate a mipmap chain. This is only valid if the Type of the Allocation |
| 831 | * includes mipmaps. |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 832 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 833 | * <p>This function will generate a complete set of mipmaps from the top |
| 834 | * level LOD and place them into the script memory space.</p> |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 835 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 836 | * <p>If the Allocation is also using other memory spaces, a call to {@link |
| 837 | * #syncAll syncAll(Allocation.USAGE_SCRIPT)} is required.</p> |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 838 | */ |
| 839 | public void generateMipmaps() { |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 840 | mRS.nAllocationGenerateMipmaps(getID(mRS)); |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 841 | } |
| 842 | |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 843 | private void copy1DRangeFromUnchecked(int off, int count, Object array, |
| 844 | Element.DataType dt, int arrayLen) { |
| 845 | Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFromUnchecked"); |
| 846 | final int dataSize = mType.mElement.getBytesSize() * count; |
| 847 | data1DChecks(off, count, arrayLen * dt.mSize, dataSize); |
| 848 | mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, array, dataSize, dt); |
| 849 | Trace.traceEnd(RenderScript.TRACE_TAG); |
| 850 | } |
| 851 | |
| 852 | /** |
| 853 | * Copy an array into part of this Allocation. This method does not |
| 854 | * guarantee that the Allocation is compatible with the input buffer. |
| 855 | * |
| 856 | * @param off The offset of the first element to be copied. |
| 857 | * @param count The number of elements to be copied. |
| 858 | * @param array The source data array |
| 859 | */ |
| 860 | public void copy1DRangeFromUnchecked(int off, int count, Object array) { |
| 861 | copy1DRangeFromUnchecked(off, count, array, |
| 862 | validateObjectIsPrimitiveArray(array, false), |
| 863 | java.lang.reflect.Array.getLength(array)); |
| 864 | } |
| 865 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 866 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 867 | * Copy an array into part of this Allocation. This method does not |
| 868 | * guarantee that the Allocation is compatible with the input buffer. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 869 | * |
| 870 | * @param off The offset of the first element to be copied. |
| 871 | * @param count The number of elements to be copied. |
| 872 | * @param d the source data array |
| 873 | */ |
| 874 | public void copy1DRangeFromUnchecked(int off, int count, int[] d) { |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 875 | copy1DRangeFromUnchecked(off, count, (Object)d, Element.DataType.SIGNED_32, d.length); |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 876 | } |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 877 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 878 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 879 | * Copy an array into part of this Allocation. This method does not |
| 880 | * guarantee that the Allocation is compatible with the input buffer. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 881 | * |
| 882 | * @param off The offset of the first element to be copied. |
| 883 | * @param count The number of elements to be copied. |
| 884 | * @param d the source data array |
| 885 | */ |
| 886 | public void copy1DRangeFromUnchecked(int off, int count, short[] d) { |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 887 | copy1DRangeFromUnchecked(off, count, (Object)d, Element.DataType.SIGNED_16, d.length); |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 888 | } |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 889 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 890 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 891 | * Copy an array into part of this Allocation. This method does not |
| 892 | * guarantee that the Allocation is compatible with the input buffer. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 893 | * |
| 894 | * @param off The offset of the first element to be copied. |
| 895 | * @param count The number of elements to be copied. |
| 896 | * @param d the source data array |
| 897 | */ |
| 898 | public void copy1DRangeFromUnchecked(int off, int count, byte[] d) { |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 899 | copy1DRangeFromUnchecked(off, count, (Object)d, Element.DataType.SIGNED_8, d.length); |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 900 | } |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 901 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 902 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 903 | * Copy an array into part of this Allocation. This method does not |
| 904 | * guarantee that the Allocation is compatible with the input buffer. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 905 | * |
| 906 | * @param off The offset of the first element to be copied. |
| 907 | * @param count The number of elements to be copied. |
| 908 | * @param d the source data array |
| 909 | */ |
| 910 | public void copy1DRangeFromUnchecked(int off, int count, float[] d) { |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 911 | copy1DRangeFromUnchecked(off, count, (Object)d, Element.DataType.FLOAT_32, d.length); |
| 912 | } |
| 913 | |
| 914 | |
| 915 | /** |
| 916 | * Copy an array into part of this Allocation. This variant is type checked |
| 917 | * and will generate exceptions if the Allocation type does not |
| 918 | * match the component type of the array passed in. |
| 919 | * |
| 920 | * @param off The offset of the first element to be copied. |
| 921 | * @param count The number of elements to be copied. |
| 922 | * @param array The source data array. |
| 923 | */ |
| 924 | public void copy1DRangeFrom(int off, int count, Object array) { |
| 925 | copy1DRangeFromUnchecked(off, count, array, |
| 926 | validateObjectIsPrimitiveArray(array, true), |
| 927 | java.lang.reflect.Array.getLength(array)); |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 928 | } |
| 929 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 930 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 931 | * Copy an array into part of this Allocation. This variant is type checked |
| 932 | * and will generate exceptions if the Allocation type is not a 32 bit |
| 933 | * integer type. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 934 | * |
| 935 | * @param off The offset of the first element to be copied. |
| 936 | * @param count The number of elements to be copied. |
| 937 | * @param d the source data array |
| 938 | */ |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 939 | public void copy1DRangeFrom(int off, int count, int[] d) { |
| 940 | validateIsInt32(); |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 941 | copy1DRangeFromUnchecked(off, count, d, Element.DataType.SIGNED_32, d.length); |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 942 | } |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 943 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 944 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 945 | * Copy an array into part of this Allocation. This variant is type checked |
| 946 | * and will generate exceptions if the Allocation type is not a 16 bit |
| 947 | * integer type. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 948 | * |
| 949 | * @param off The offset of the first element to be copied. |
| 950 | * @param count The number of elements to be copied. |
| 951 | * @param d the source data array |
| 952 | */ |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 953 | public void copy1DRangeFrom(int off, int count, short[] d) { |
| 954 | validateIsInt16(); |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 955 | copy1DRangeFromUnchecked(off, count, d, Element.DataType.SIGNED_16, d.length); |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 956 | } |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 957 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 958 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 959 | * Copy an array into part of this Allocation. This variant is type checked |
| 960 | * and will generate exceptions if the Allocation type is not an 8 bit |
| 961 | * integer type. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 962 | * |
| 963 | * @param off The offset of the first element to be copied. |
| 964 | * @param count The number of elements to be copied. |
| 965 | * @param d the source data array |
| 966 | */ |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 967 | public void copy1DRangeFrom(int off, int count, byte[] d) { |
| 968 | validateIsInt8(); |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 969 | copy1DRangeFromUnchecked(off, count, d, Element.DataType.SIGNED_8, d.length); |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 970 | } |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 971 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 972 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 973 | * Copy an array into part of this Allocation. This variant is type checked |
| 974 | * and will generate exceptions if the Allocation type is not a 32 bit float |
| 975 | * type. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 976 | * |
| 977 | * @param off The offset of the first element to be copied. |
| 978 | * @param count The number of elements to be copied. |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 979 | * @param d the source data array. |
Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 980 | */ |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 981 | public void copy1DRangeFrom(int off, int count, float[] d) { |
| 982 | validateIsFloat32(); |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 983 | copy1DRangeFromUnchecked(off, count, d, Element.DataType.FLOAT_32, d.length); |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 984 | } |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 985 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 986 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 987 | * Copy part of an Allocation into this Allocation. |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 988 | * |
| 989 | * @param off The offset of the first element to be copied. |
| 990 | * @param count The number of elements to be copied. |
| 991 | * @param data the source data allocation. |
| 992 | * @param dataOff off The offset of the first element in data to |
| 993 | * be copied. |
| 994 | */ |
| 995 | public void copy1DRangeFrom(int off, int count, Allocation data, int dataOff) { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 996 | Trace.traceBegin(RenderScript.TRACE_TAG, "copy1DRangeFrom"); |
Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 997 | mRS.nAllocationData2D(getIDSafe(), off, 0, |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 998 | mSelectedLOD, mSelectedFace.mID, |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 999 | count, 1, data.getID(mRS), dataOff, 0, |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 1000 | data.mSelectedLOD, data.mSelectedFace.mID); |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 1001 | } |
| 1002 | |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 1003 | private void validate2DRange(int xoff, int yoff, int w, int h) { |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 1004 | if (mAdaptedAllocation != null) { |
| 1005 | |
| 1006 | } else { |
| 1007 | |
| 1008 | if (xoff < 0 || yoff < 0) { |
| 1009 | throw new RSIllegalArgumentException("Offset cannot be negative."); |
| 1010 | } |
| 1011 | if (h < 0 || w < 0) { |
| 1012 | throw new RSIllegalArgumentException("Height or width cannot be negative."); |
| 1013 | } |
| 1014 | if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY)) { |
| 1015 | throw new RSIllegalArgumentException("Updated region larger than allocation."); |
| 1016 | } |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 1017 | } |
| 1018 | } |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 1019 | |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1020 | void copy2DRangeFromUnchecked(int xoff, int yoff, int w, int h, Object array, |
| 1021 | Element.DataType dt, int arrayLen) { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1022 | Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFromUnchecked"); |
Stephen Hines | a9a7b37 | 2013-02-08 17:11:31 -0800 | [diff] [blame] | 1023 | mRS.validate(); |
| 1024 | validate2DRange(xoff, yoff, w, h); |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1025 | mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, w, h, |
| 1026 | array, arrayLen * dt.mSize, dt); |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1027 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Stephen Hines | a9a7b37 | 2013-02-08 17:11:31 -0800 | [diff] [blame] | 1028 | } |
| 1029 | |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1030 | /** |
| 1031 | * Copy from an array into a rectangular region in this Allocation. The |
| 1032 | * array is assumed to be tightly packed. |
| 1033 | * |
| 1034 | * @param xoff X offset of the region to update in this Allocation |
| 1035 | * @param yoff Y offset of the region to update in this Allocation |
| 1036 | * @param w Width of the region to update |
| 1037 | * @param h Height of the region to update |
Ying Wang | 1622981 | 2013-11-26 15:45:12 -0800 | [diff] [blame] | 1038 | * @param array Data to be placed into the Allocation |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1039 | */ |
| 1040 | public void copy2DRangeFrom(int xoff, int yoff, int w, int h, Object array) { |
| 1041 | Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFrom"); |
| 1042 | copy2DRangeFromUnchecked(xoff, yoff, w, h, array, |
| 1043 | validateObjectIsPrimitiveArray(array, true), |
| 1044 | java.lang.reflect.Array.getLength(array)); |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1045 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Stephen Hines | a9a7b37 | 2013-02-08 17:11:31 -0800 | [diff] [blame] | 1046 | } |
| 1047 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1048 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1049 | * Copy from an array into a rectangular region in this Allocation. The |
| 1050 | * array is assumed to be tightly packed. |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1051 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1052 | * @param xoff X offset of the region to update in this Allocation |
| 1053 | * @param yoff Y offset of the region to update in this Allocation |
| 1054 | * @param w Width of the region to update |
| 1055 | * @param h Height of the region to update |
| 1056 | * @param data to be placed into the Allocation |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1057 | */ |
| 1058 | public void copy2DRangeFrom(int xoff, int yoff, int w, int h, byte[] data) { |
Stephen Hines | 5f528be | 2013-02-08 21:03:51 -0800 | [diff] [blame] | 1059 | validateIsInt8(); |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1060 | copy2DRangeFromUnchecked(xoff, yoff, w, h, data, |
| 1061 | Element.DataType.SIGNED_8, data.length); |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 1062 | } |
| 1063 | |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1064 | /** |
| 1065 | * Copy from an array into a rectangular region in this Allocation. The |
| 1066 | * array is assumed to be tightly packed. |
| 1067 | * |
| 1068 | * @param xoff X offset of the region to update in this Allocation |
| 1069 | * @param yoff Y offset of the region to update in this Allocation |
| 1070 | * @param w Width of the region to update |
| 1071 | * @param h Height of the region to update |
| 1072 | * @param data to be placed into the Allocation |
| 1073 | */ |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1074 | public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data) { |
Stephen Hines | 5f528be | 2013-02-08 21:03:51 -0800 | [diff] [blame] | 1075 | validateIsInt16(); |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1076 | copy2DRangeFromUnchecked(xoff, yoff, w, h, data, |
| 1077 | Element.DataType.SIGNED_16, data.length); |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 1078 | } |
| 1079 | |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1080 | /** |
| 1081 | * Copy from an array into a rectangular region in this Allocation. The |
| 1082 | * array is assumed to be tightly packed. |
| 1083 | * |
| 1084 | * @param xoff X offset of the region to update in this Allocation |
| 1085 | * @param yoff Y offset of the region to update in this Allocation |
| 1086 | * @param w Width of the region to update |
| 1087 | * @param h Height of the region to update |
| 1088 | * @param data to be placed into the Allocation |
| 1089 | */ |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1090 | public void copy2DRangeFrom(int xoff, int yoff, int w, int h, int[] data) { |
Stephen Hines | 5f528be | 2013-02-08 21:03:51 -0800 | [diff] [blame] | 1091 | validateIsInt32(); |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1092 | copy2DRangeFromUnchecked(xoff, yoff, w, h, data, |
| 1093 | Element.DataType.SIGNED_32, data.length); |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1094 | } |
| 1095 | |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1096 | /** |
| 1097 | * Copy from an array into a rectangular region in this Allocation. The |
| 1098 | * array is assumed to be tightly packed. |
| 1099 | * |
| 1100 | * @param xoff X offset of the region to update in this Allocation |
| 1101 | * @param yoff Y offset of the region to update in this Allocation |
| 1102 | * @param w Width of the region to update |
| 1103 | * @param h Height of the region to update |
| 1104 | * @param data to be placed into the Allocation |
| 1105 | */ |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1106 | public void copy2DRangeFrom(int xoff, int yoff, int w, int h, float[] data) { |
Stephen Hines | 5f528be | 2013-02-08 21:03:51 -0800 | [diff] [blame] | 1107 | validateIsFloat32(); |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1108 | copy2DRangeFromUnchecked(xoff, yoff, w, h, data, |
| 1109 | Element.DataType.FLOAT_32, data.length); |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1110 | } |
| 1111 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1112 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1113 | * Copy a rectangular region from an Allocation into a rectangular region in |
| 1114 | * this Allocation. |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 1115 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1116 | * @param xoff X offset of the region in this Allocation |
| 1117 | * @param yoff Y offset of the region in this Allocation |
| 1118 | * @param w Width of the region to update. |
| 1119 | * @param h Height of the region to update. |
| 1120 | * @param data source Allocation. |
| 1121 | * @param dataXoff X offset in source Allocation |
| 1122 | * @param dataYoff Y offset in source Allocation |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 1123 | */ |
| 1124 | public void copy2DRangeFrom(int xoff, int yoff, int w, int h, |
| 1125 | Allocation data, int dataXoff, int dataYoff) { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1126 | Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFrom"); |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 1127 | mRS.validate(); |
| 1128 | validate2DRange(xoff, yoff, w, h); |
Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 1129 | mRS.nAllocationData2D(getIDSafe(), xoff, yoff, |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 1130 | mSelectedLOD, mSelectedFace.mID, |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1131 | w, h, data.getID(mRS), dataXoff, dataYoff, |
Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 1132 | data.mSelectedLOD, data.mSelectedFace.mID); |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1133 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 1134 | } |
| 1135 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1136 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1137 | * Copy a {@link android.graphics.Bitmap} into an Allocation. The height |
| 1138 | * and width of the update will use the height and width of the {@link |
| 1139 | * android.graphics.Bitmap}. |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1140 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1141 | * @param xoff X offset of the region to update in this Allocation |
| 1142 | * @param yoff Y offset of the region to update in this Allocation |
| 1143 | * @param data the Bitmap to be copied |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1144 | */ |
| 1145 | public void copy2DRangeFrom(int xoff, int yoff, Bitmap data) { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1146 | Trace.traceBegin(RenderScript.TRACE_TAG, "copy2DRangeFrom"); |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 1147 | mRS.validate(); |
Tim Murray | abd5db9 | 2013-02-28 11:45:22 -0800 | [diff] [blame] | 1148 | if (data.getConfig() == null) { |
| 1149 | Bitmap newBitmap = Bitmap.createBitmap(data.getWidth(), data.getHeight(), Bitmap.Config.ARGB_8888); |
| 1150 | Canvas c = new Canvas(newBitmap); |
| 1151 | c.drawBitmap(data, 0, 0, null); |
| 1152 | copy2DRangeFrom(xoff, yoff, newBitmap); |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1153 | return; |
Tim Murray | abd5db9 | 2013-02-28 11:45:22 -0800 | [diff] [blame] | 1154 | } |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 1155 | validateBitmapFormat(data); |
| 1156 | validate2DRange(xoff, yoff, data.getWidth(), data.getHeight()); |
Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 1157 | mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, data); |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1158 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 1159 | } |
| 1160 | |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1161 | private void validate3DRange(int xoff, int yoff, int zoff, int w, int h, int d) { |
| 1162 | if (mAdaptedAllocation != null) { |
| 1163 | |
| 1164 | } else { |
| 1165 | |
| 1166 | if (xoff < 0 || yoff < 0 || zoff < 0) { |
| 1167 | throw new RSIllegalArgumentException("Offset cannot be negative."); |
| 1168 | } |
| 1169 | if (h < 0 || w < 0 || d < 0) { |
| 1170 | throw new RSIllegalArgumentException("Height or width cannot be negative."); |
| 1171 | } |
| 1172 | if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY) || ((zoff + d) > mCurrentDimZ)) { |
| 1173 | throw new RSIllegalArgumentException("Updated region larger than allocation."); |
| 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | |
| 1178 | /** |
| 1179 | * @hide |
| 1180 | * |
| 1181 | */ |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1182 | private void copy3DRangeFromUnchecked(int xoff, int yoff, int zoff, int w, int h, int d, |
| 1183 | Object array, Element.DataType dt, int arrayLen) { |
| 1184 | Trace.traceBegin(RenderScript.TRACE_TAG, "copy3DRangeFromUnchecked"); |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1185 | mRS.validate(); |
| 1186 | validate3DRange(xoff, yoff, zoff, w, h, d); |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1187 | mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, w, h, d, |
| 1188 | array, arrayLen * dt.mSize, dt); |
| 1189 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1190 | } |
| 1191 | |
| 1192 | /** |
| 1193 | * @hide |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1194 | * Copy a rectangular region from the array into the allocation. |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1195 | * The array is assumed to be tightly packed. |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1196 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1197 | * @param xoff X offset of the region to update in this Allocation |
| 1198 | * @param yoff Y offset of the region to update in this Allocation |
| 1199 | * @param zoff Z offset of the region to update in this Allocation |
| 1200 | * @param w Width of the region to update |
| 1201 | * @param h Height of the region to update |
| 1202 | * @param d Depth of the region to update |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1203 | * @param data to be placed into the allocation |
| 1204 | */ |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1205 | public void copy3DRangeFrom(int xoff, int yoff, int zoff, int w, int h, int d, Object array) { |
| 1206 | Trace.traceBegin(RenderScript.TRACE_TAG, "copy3DRangeFrom"); |
| 1207 | copy3DRangeFromUnchecked(xoff, yoff, zoff, w, h, d, array, |
| 1208 | validateObjectIsPrimitiveArray(array, true), |
| 1209 | java.lang.reflect.Array.getLength(array)); |
| 1210 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1211 | } |
| 1212 | |
| 1213 | /** |
| 1214 | * @hide |
| 1215 | * Copy a rectangular region into the allocation from another |
| 1216 | * allocation. |
| 1217 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1218 | * @param xoff X offset of the region to update in this Allocation |
| 1219 | * @param yoff Y offset of the region to update in this Allocation |
| 1220 | * @param zoff Z offset of the region to update in this Allocation |
| 1221 | * @param w Width of the region to update. |
| 1222 | * @param h Height of the region to update. |
| 1223 | * @param d Depth of the region to update. |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1224 | * @param data source allocation. |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1225 | * @param dataXoff X offset of the region in the source Allocation |
| 1226 | * @param dataYoff Y offset of the region in the source Allocation |
| 1227 | * @param dataZoff Z offset of the region in the source Allocation |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1228 | */ |
| 1229 | public void copy3DRangeFrom(int xoff, int yoff, int zoff, int w, int h, int d, |
| 1230 | Allocation data, int dataXoff, int dataYoff, int dataZoff) { |
| 1231 | mRS.validate(); |
| 1232 | validate3DRange(xoff, yoff, zoff, w, h, d); |
| 1233 | mRS.nAllocationData3D(getIDSafe(), xoff, yoff, zoff, mSelectedLOD, |
| 1234 | w, h, d, data.getID(mRS), dataXoff, dataYoff, dataZoff, |
| 1235 | data.mSelectedLOD); |
| 1236 | } |
| 1237 | |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 1238 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1239 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1240 | * Copy from the Allocation into a {@link android.graphics.Bitmap}. The |
| 1241 | * bitmap must match the dimensions of the Allocation. |
Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 1242 | * |
| 1243 | * @param b The bitmap to be set from the Allocation. |
| 1244 | */ |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 1245 | public void copyTo(Bitmap b) { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1246 | Trace.traceBegin(RenderScript.TRACE_TAG, "copyTo"); |
Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 1247 | mRS.validate(); |
| 1248 | validateBitmapFormat(b); |
| 1249 | validateBitmapSize(b); |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1250 | mRS.nAllocationCopyToBitmap(getID(mRS), b); |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1251 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 1252 | } |
| 1253 | |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1254 | private void copyTo(Object array, Element.DataType dt, int arrayLen) { |
| 1255 | Trace.traceBegin(RenderScript.TRACE_TAG, "copyTo"); |
| 1256 | mRS.validate(); |
| 1257 | mRS.nAllocationRead(getID(mRS), array, dt); |
| 1258 | Trace.traceEnd(RenderScript.TRACE_TAG); |
| 1259 | } |
| 1260 | |
| 1261 | /** |
| 1262 | * Copy from the Allocation into an array. The array must be at |
| 1263 | * least as large as the Allocation. The |
| 1264 | * {@link android.renderscript.Element} must match the component |
| 1265 | * type of the array passed in. |
| 1266 | * |
| 1267 | * @param array The array to be set from the Allocation. |
| 1268 | */ |
| 1269 | public void copyTo(Object array) { |
| 1270 | copyTo(array, validateObjectIsPrimitiveArray(array, true), |
| 1271 | java.lang.reflect.Array.getLength(array)); |
| 1272 | } |
| 1273 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1274 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1275 | * Copy from the Allocation into a byte array. The array must be at least |
| 1276 | * as large as the Allocation. The allocation must be of an 8 bit integer |
| 1277 | * {@link android.renderscript.Element} type. |
Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 1278 | * |
| 1279 | * @param d The array to be set from the Allocation. |
| 1280 | */ |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 1281 | public void copyTo(byte[] d) { |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 1282 | validateIsInt8(); |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1283 | copyTo(d, Element.DataType.SIGNED_8, d.length); |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 1284 | } |
| 1285 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1286 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1287 | * Copy from the Allocation into a short array. The array must be at least |
| 1288 | * as large as the Allocation. The allocation must be of an 16 bit integer |
| 1289 | * {@link android.renderscript.Element} type. |
Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 1290 | * |
| 1291 | * @param d The array to be set from the Allocation. |
| 1292 | */ |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 1293 | public void copyTo(short[] d) { |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 1294 | validateIsInt16(); |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1295 | copyTo(d, Element.DataType.SIGNED_16, d.length); |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 1296 | } |
| 1297 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1298 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1299 | * Copy from the Allocation into a int array. The array must be at least as |
| 1300 | * large as the Allocation. The allocation must be of an 32 bit integer |
| 1301 | * {@link android.renderscript.Element} type. |
Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 1302 | * |
| 1303 | * @param d The array to be set from the Allocation. |
| 1304 | */ |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 1305 | public void copyTo(int[] d) { |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 1306 | validateIsInt32(); |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1307 | copyTo(d, Element.DataType.SIGNED_32, d.length); |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 1308 | } |
| 1309 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1310 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1311 | * Copy from the Allocation into a float array. The array must be at least |
| 1312 | * as large as the Allocation. The allocation must be of an 32 bit float |
| 1313 | * {@link android.renderscript.Element} type. |
Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 1314 | * |
| 1315 | * @param d The array to be set from the Allocation. |
| 1316 | */ |
Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 1317 | public void copyTo(float[] d) { |
Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 1318 | validateIsFloat32(); |
Jason Sams | 3042d26 | 2013-11-25 18:28:33 -0800 | [diff] [blame] | 1319 | copyTo(d, Element.DataType.FLOAT_32, d.length); |
Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 1320 | } |
| 1321 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1322 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1323 | * Resize a 1D allocation. The contents of the allocation are preserved. |
| 1324 | * If new elements are allocated objects are created with null contents and |
| 1325 | * the new region is otherwise undefined. |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1326 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1327 | * <p>If the new region is smaller the references of any objects outside the |
| 1328 | * new region will be released.</p> |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1329 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1330 | * <p>A new type will be created with the new dimension.</p> |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1331 | * |
| 1332 | * @param dimX The new size of the allocation. |
Jason Sams | b05d689 | 2013-04-09 15:59:24 -0700 | [diff] [blame] | 1333 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1334 | * @deprecated RenderScript objects should be immutable once created. The |
| 1335 | * replacement is to create a new allocation and copy the contents. |
Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 1336 | */ |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 1337 | public synchronized void resize(int dimX) { |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1338 | if ((mType.getY() > 0)|| (mType.getZ() > 0) || mType.hasFaces() || mType.hasMipmaps()) { |
Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 1339 | throw new RSInvalidStateException("Resize only support for 1D allocations at this time."); |
Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 1340 | } |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1341 | mRS.nAllocationResize1D(getID(mRS), dimX); |
Jason Sams | d26297f | 2010-11-01 16:08:59 -0700 | [diff] [blame] | 1342 | mRS.finish(); // Necessary because resize is fifoed and update is async. |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 1343 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1344 | long typeID = mRS.nAllocationGetType(getID(mRS)); |
Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 1345 | mType = new Type(typeID, mRS); |
| 1346 | mType.updateFromNative(); |
Jason Sams | 452a766 | 2011-07-07 16:05:18 -0700 | [diff] [blame] | 1347 | updateCacheInfo(mType); |
Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 1348 | } |
| 1349 | |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1350 | |
| 1351 | // creation |
| 1352 | |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 1353 | static BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options(); |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1354 | static { |
| 1355 | mBitmapOptions.inScaled = false; |
| 1356 | } |
| 1357 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1358 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1359 | * Creates a new Allocation with the given {@link |
| 1360 | * android.renderscript.Type}, mipmap flag, and usage flags. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1361 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1362 | * @param type RenderScript type describing data layout |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1363 | * @param mips specifies desired mipmap behaviour for the |
| 1364 | * allocation |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1365 | * @param usage bit field specifying how the Allocation is |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1366 | * utilized |
| 1367 | */ |
| 1368 | static public Allocation createTyped(RenderScript rs, Type type, MipmapControl mips, int usage) { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1369 | Trace.traceBegin(RenderScript.TRACE_TAG, "createTyped"); |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 1370 | rs.validate(); |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1371 | if (type.getID(rs) == 0) { |
Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 1372 | throw new RSInvalidStateException("Bad Type"); |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 1373 | } |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1374 | long id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, 0); |
Jason Sams | 857d0c7 | 2011-11-23 15:02:15 -0800 | [diff] [blame] | 1375 | if (id == 0) { |
| 1376 | throw new RSRuntimeException("Allocation creation failed."); |
| 1377 | } |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1378 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Jason Sams | 857d0c7 | 2011-11-23 15:02:15 -0800 | [diff] [blame] | 1379 | return new Allocation(id, rs, type, usage); |
| 1380 | } |
| 1381 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1382 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1383 | * Creates an Allocation with the size specified by the type and no mipmaps |
| 1384 | * generated by default |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1385 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1386 | * @param rs Context to which the allocation will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1387 | * @param type renderscript type describing data layout |
| 1388 | * @param usage bit field specifying how the allocation is |
| 1389 | * utilized |
| 1390 | * |
| 1391 | * @return allocation |
| 1392 | */ |
Jason Sams | e5d3712 | 2010-12-16 00:33:33 -0800 | [diff] [blame] | 1393 | static public Allocation createTyped(RenderScript rs, Type type, int usage) { |
| 1394 | return createTyped(rs, type, MipmapControl.MIPMAP_NONE, usage); |
| 1395 | } |
| 1396 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1397 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1398 | * Creates an Allocation for use by scripts with a given {@link |
| 1399 | * android.renderscript.Type} and no mipmaps |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1400 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1401 | * @param rs Context to which the Allocation will belong. |
| 1402 | * @param type RenderScript Type describing data layout |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1403 | * |
| 1404 | * @return allocation |
| 1405 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1406 | static public Allocation createTyped(RenderScript rs, Type type) { |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 1407 | return createTyped(rs, type, MipmapControl.MIPMAP_NONE, USAGE_SCRIPT); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1408 | } |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 1409 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1410 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1411 | * Creates an Allocation with a specified number of given elements |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1412 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1413 | * @param rs Context to which the Allocation will belong. |
| 1414 | * @param e Element to use in the Allocation |
| 1415 | * @param count the number of Elements in the Allocation |
| 1416 | * @param usage bit field specifying how the Allocation is |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1417 | * utilized |
| 1418 | * |
| 1419 | * @return allocation |
| 1420 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1421 | static public Allocation createSized(RenderScript rs, Element e, |
| 1422 | int count, int usage) { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1423 | Trace.traceBegin(RenderScript.TRACE_TAG, "createSized"); |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 1424 | rs.validate(); |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 1425 | Type.Builder b = new Type.Builder(rs, e); |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1426 | b.setX(count); |
Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 1427 | Type t = b.create(); |
| 1428 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1429 | long id = rs.nAllocationCreateTyped(t.getID(rs), MipmapControl.MIPMAP_NONE.mID, usage, 0); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1430 | if (id == 0) { |
Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 1431 | throw new RSRuntimeException("Allocation creation failed."); |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1432 | } |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1433 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1434 | return new Allocation(id, rs, t, usage); |
| 1435 | } |
| 1436 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1437 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1438 | * Creates an Allocation with a specified number of given elements |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1439 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1440 | * @param rs Context to which the Allocation will belong. |
| 1441 | * @param e Element to use in the Allocation |
| 1442 | * @param count the number of Elements in the Allocation |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1443 | * |
| 1444 | * @return allocation |
| 1445 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1446 | static public Allocation createSized(RenderScript rs, Element e, int count) { |
Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 1447 | return createSized(rs, e, count, USAGE_SCRIPT); |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1448 | } |
| 1449 | |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 1450 | static Element elementFromBitmap(RenderScript rs, Bitmap b) { |
Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 1451 | final Bitmap.Config bc = b.getConfig(); |
| 1452 | if (bc == Bitmap.Config.ALPHA_8) { |
| 1453 | return Element.A_8(rs); |
| 1454 | } |
| 1455 | if (bc == Bitmap.Config.ARGB_4444) { |
| 1456 | return Element.RGBA_4444(rs); |
| 1457 | } |
| 1458 | if (bc == Bitmap.Config.ARGB_8888) { |
| 1459 | return Element.RGBA_8888(rs); |
| 1460 | } |
| 1461 | if (bc == Bitmap.Config.RGB_565) { |
| 1462 | return Element.RGB_565(rs); |
| 1463 | } |
Jeff Sharkey | 4bd1a3d | 2010-11-16 13:46:34 -0800 | [diff] [blame] | 1464 | throw new RSInvalidStateException("Bad bitmap type: " + bc); |
Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 1465 | } |
| 1466 | |
Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 1467 | static Type typeFromBitmap(RenderScript rs, Bitmap b, |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1468 | MipmapControl mip) { |
Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 1469 | Element e = elementFromBitmap(rs, b); |
| 1470 | Type.Builder tb = new Type.Builder(rs, e); |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1471 | tb.setX(b.getWidth()); |
| 1472 | tb.setY(b.getHeight()); |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1473 | tb.setMipmaps(mip == MipmapControl.MIPMAP_FULL); |
Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 1474 | return tb.create(); |
| 1475 | } |
| 1476 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1477 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1478 | * Creates an Allocation from a {@link android.graphics.Bitmap}. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1479 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1480 | * @param rs Context to which the allocation will belong. |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1481 | * @param b Bitmap source for the allocation data |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1482 | * @param mips specifies desired mipmap behaviour for the |
| 1483 | * allocation |
| 1484 | * @param usage bit field specifying how the allocation is |
| 1485 | * utilized |
| 1486 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1487 | * @return Allocation containing bitmap data |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1488 | * |
| 1489 | */ |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1490 | static public Allocation createFromBitmap(RenderScript rs, Bitmap b, |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1491 | MipmapControl mips, |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1492 | int usage) { |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1493 | Trace.traceBegin(RenderScript.TRACE_TAG, "createFromBitmap"); |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 1494 | rs.validate(); |
Tim Murray | abd5db9 | 2013-02-28 11:45:22 -0800 | [diff] [blame] | 1495 | |
| 1496 | // WAR undocumented color formats |
| 1497 | if (b.getConfig() == null) { |
| 1498 | if ((usage & USAGE_SHARED) != 0) { |
| 1499 | throw new RSIllegalArgumentException("USAGE_SHARED cannot be used with a Bitmap that has a null config."); |
| 1500 | } |
| 1501 | Bitmap newBitmap = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ARGB_8888); |
| 1502 | Canvas c = new Canvas(newBitmap); |
| 1503 | c.drawBitmap(b, 0, 0, null); |
| 1504 | return createFromBitmap(rs, newBitmap, mips, usage); |
| 1505 | } |
| 1506 | |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1507 | Type t = typeFromBitmap(rs, b, mips); |
Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 1508 | |
Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 1509 | // enable optimized bitmap path only with no mipmap and script-only usage |
| 1510 | if (mips == MipmapControl.MIPMAP_NONE && |
| 1511 | t.getElement().isCompatible(Element.RGBA_8888(rs)) && |
Tim Murray | 78e6494 | 2013-04-09 17:28:56 -0700 | [diff] [blame] | 1512 | usage == (USAGE_SHARED | USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE)) { |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1513 | long id = rs.nAllocationCreateBitmapBackedAllocation(t.getID(rs), mips.mID, b, usage); |
Tim Murray | a314551 | 2012-12-04 17:59:29 -0800 | [diff] [blame] | 1514 | if (id == 0) { |
| 1515 | throw new RSRuntimeException("Load failed."); |
| 1516 | } |
| 1517 | |
| 1518 | // keep a reference to the Bitmap around to prevent GC |
| 1519 | Allocation alloc = new Allocation(id, rs, t, usage); |
| 1520 | alloc.setBitmap(b); |
| 1521 | return alloc; |
| 1522 | } |
| 1523 | |
Jason Sams | 9bf1892 | 2013-04-13 19:48:36 -0700 | [diff] [blame] | 1524 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1525 | long id = rs.nAllocationCreateFromBitmap(t.getID(rs), mips.mID, b, usage); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1526 | if (id == 0) { |
Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 1527 | throw new RSRuntimeException("Load failed."); |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 1528 | } |
Tim Murray | 6d7a53c | 2013-05-23 16:59:23 -0700 | [diff] [blame] | 1529 | Trace.traceEnd(RenderScript.TRACE_TAG); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1530 | return new Allocation(id, rs, t, usage); |
| 1531 | } |
| 1532 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1533 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1534 | * Returns the handle to a raw buffer that is being managed by the screen |
| 1535 | * compositor. This operation is only valid for Allocations with {@link |
| 1536 | * #USAGE_IO_INPUT}. |
Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 1537 | * |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 1538 | * @return Surface object associated with allocation |
Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 1539 | * |
| 1540 | */ |
| 1541 | public Surface getSurface() { |
Jason Sams | 72226e0 | 2013-02-22 12:45:54 -0800 | [diff] [blame] | 1542 | if ((mUsage & USAGE_IO_INPUT) == 0) { |
| 1543 | throw new RSInvalidStateException("Allocation is not a surface texture."); |
| 1544 | } |
| 1545 | return mRS.nAllocationGetSurface(getID(mRS)); |
Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1548 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1549 | * Associate a {@link android.view.Surface} with this Allocation. This |
| 1550 | * operation is only valid for Allocations with {@link #USAGE_IO_OUTPUT}. |
Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 1551 | * |
| 1552 | * @param sur Surface to associate with allocation |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1553 | */ |
Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 1554 | public void setSurface(Surface sur) { |
| 1555 | mRS.validate(); |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1556 | if ((mUsage & USAGE_IO_OUTPUT) == 0) { |
| 1557 | throw new RSInvalidStateException("Allocation is not USAGE_IO_OUTPUT."); |
| 1558 | } |
| 1559 | |
Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1560 | mRS.nAllocationSetSurface(getID(mRS), sur); |
Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1561 | } |
| 1562 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1563 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1564 | * Creates an Allocation from a {@link android.graphics.Bitmap}. |
Tim Murray | 00bb454 | 2012-12-17 16:35:06 -0800 | [diff] [blame] | 1565 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1566 | * <p>With target API version 18 or greater, this Allocation will be created |
| 1567 | * with {@link #USAGE_SHARED}, {@link #USAGE_SCRIPT}, and {@link |
| 1568 | * #USAGE_GRAPHICS_TEXTURE}. With target API version 17 or lower, this |
| 1569 | * Allocation will be created with {@link #USAGE_GRAPHICS_TEXTURE}.</p> |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1570 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1571 | * @param rs Context to which the allocation will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1572 | * @param b bitmap source for the allocation data |
| 1573 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1574 | * @return Allocation containing bitmap data |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1575 | * |
| 1576 | */ |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 1577 | static public Allocation createFromBitmap(RenderScript rs, Bitmap b) { |
Tim Murray | 00bb454 | 2012-12-17 16:35:06 -0800 | [diff] [blame] | 1578 | if (rs.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) { |
| 1579 | return createFromBitmap(rs, b, MipmapControl.MIPMAP_NONE, |
Tim Murray | 78e6494 | 2013-04-09 17:28:56 -0700 | [diff] [blame] | 1580 | USAGE_SHARED | USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE); |
Tim Murray | 00bb454 | 2012-12-17 16:35:06 -0800 | [diff] [blame] | 1581 | } |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 1582 | return createFromBitmap(rs, b, MipmapControl.MIPMAP_NONE, |
| 1583 | USAGE_GRAPHICS_TEXTURE); |
Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 1584 | } |
| 1585 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1586 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1587 | * Creates a cubemap Allocation from a {@link android.graphics.Bitmap} |
| 1588 | * containing the horizontal list of cube faces. Each face must be a square, |
| 1589 | * have the same size as all other faces, and have a width that is a power |
| 1590 | * of 2. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1591 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1592 | * @param rs Context to which the allocation will belong. |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1593 | * @param b Bitmap with cubemap faces layed out in the following |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1594 | * format: right, left, top, bottom, front, back |
| 1595 | * @param mips specifies desired mipmap behaviour for the cubemap |
| 1596 | * @param usage bit field specifying how the cubemap is utilized |
| 1597 | * |
| 1598 | * @return allocation containing cubemap data |
| 1599 | * |
| 1600 | */ |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1601 | static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b, |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1602 | MipmapControl mips, |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1603 | int usage) { |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1604 | rs.validate(); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1605 | |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1606 | int height = b.getHeight(); |
| 1607 | int width = b.getWidth(); |
| 1608 | |
Alex Sakhartchouk | fe852e2 | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 1609 | if (width % 6 != 0) { |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1610 | throw new RSIllegalArgumentException("Cubemap height must be multiple of 6"); |
| 1611 | } |
Alex Sakhartchouk | fe852e2 | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 1612 | if (width / 6 != height) { |
Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 1613 | throw new RSIllegalArgumentException("Only square cube map faces supported"); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1614 | } |
Alex Sakhartchouk | fe852e2 | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 1615 | boolean isPow2 = (height & (height - 1)) == 0; |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1616 | if (!isPow2) { |
| 1617 | throw new RSIllegalArgumentException("Only power of 2 cube faces supported"); |
| 1618 | } |
| 1619 | |
| 1620 | Element e = elementFromBitmap(rs, b); |
| 1621 | Type.Builder tb = new Type.Builder(rs, e); |
Alex Sakhartchouk | fe852e2 | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 1622 | tb.setX(height); |
| 1623 | tb.setY(height); |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1624 | tb.setFaces(true); |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1625 | tb.setMipmaps(mips == MipmapControl.MIPMAP_FULL); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1626 | Type t = tb.create(); |
| 1627 | |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1628 | long id = rs.nAllocationCubeCreateFromBitmap(t.getID(rs), mips.mID, b, usage); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1629 | if(id == 0) { |
| 1630 | throw new RSRuntimeException("Load failed for bitmap " + b + " element " + e); |
| 1631 | } |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1632 | return new Allocation(id, rs, t, usage); |
Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1633 | } |
| 1634 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1635 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1636 | * Creates a non-mipmapped cubemap Allocation for use as a graphics texture |
| 1637 | * from a {@link android.graphics.Bitmap} containing the horizontal list of |
| 1638 | * cube faces. Each face must be a square, have the same size as all other |
| 1639 | * faces, and have a width that is a power of 2. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1640 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1641 | * @param rs Context to which the allocation will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1642 | * @param b bitmap with cubemap faces layed out in the following |
| 1643 | * format: right, left, top, bottom, front, back |
| 1644 | * |
| 1645 | * @return allocation containing cubemap data |
| 1646 | * |
| 1647 | */ |
Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 1648 | static public Allocation createCubemapFromBitmap(RenderScript rs, |
| 1649 | Bitmap b) { |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 1650 | return createCubemapFromBitmap(rs, b, MipmapControl.MIPMAP_NONE, |
Alex Sakhartchouk | fe852e2 | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 1651 | USAGE_GRAPHICS_TEXTURE); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1652 | } |
| 1653 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1654 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1655 | * Creates a cubemap Allocation from 6 {@link android.graphics.Bitmap} |
| 1656 | * objects containing the cube faces. Each face must be a square, have the |
| 1657 | * same size as all other faces, and have a width that is a power of 2. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1658 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1659 | * @param rs Context to which the allocation will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1660 | * @param xpos cubemap face in the positive x direction |
| 1661 | * @param xneg cubemap face in the negative x direction |
| 1662 | * @param ypos cubemap face in the positive y direction |
| 1663 | * @param yneg cubemap face in the negative y direction |
| 1664 | * @param zpos cubemap face in the positive z direction |
| 1665 | * @param zneg cubemap face in the negative z direction |
| 1666 | * @param mips specifies desired mipmap behaviour for the cubemap |
| 1667 | * @param usage bit field specifying how the cubemap is utilized |
| 1668 | * |
| 1669 | * @return allocation containing cubemap data |
| 1670 | * |
| 1671 | */ |
Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 1672 | static public Allocation createCubemapFromCubeFaces(RenderScript rs, |
| 1673 | Bitmap xpos, |
| 1674 | Bitmap xneg, |
| 1675 | Bitmap ypos, |
| 1676 | Bitmap yneg, |
| 1677 | Bitmap zpos, |
| 1678 | Bitmap zneg, |
| 1679 | MipmapControl mips, |
| 1680 | int usage) { |
| 1681 | int height = xpos.getHeight(); |
| 1682 | if (xpos.getWidth() != height || |
| 1683 | xneg.getWidth() != height || xneg.getHeight() != height || |
| 1684 | ypos.getWidth() != height || ypos.getHeight() != height || |
| 1685 | yneg.getWidth() != height || yneg.getHeight() != height || |
| 1686 | zpos.getWidth() != height || zpos.getHeight() != height || |
| 1687 | zneg.getWidth() != height || zneg.getHeight() != height) { |
| 1688 | throw new RSIllegalArgumentException("Only square cube map faces supported"); |
| 1689 | } |
| 1690 | boolean isPow2 = (height & (height - 1)) == 0; |
| 1691 | if (!isPow2) { |
| 1692 | throw new RSIllegalArgumentException("Only power of 2 cube faces supported"); |
| 1693 | } |
| 1694 | |
| 1695 | Element e = elementFromBitmap(rs, xpos); |
| 1696 | Type.Builder tb = new Type.Builder(rs, e); |
| 1697 | tb.setX(height); |
| 1698 | tb.setY(height); |
| 1699 | tb.setFaces(true); |
| 1700 | tb.setMipmaps(mips == MipmapControl.MIPMAP_FULL); |
| 1701 | Type t = tb.create(); |
| 1702 | Allocation cubemap = Allocation.createTyped(rs, t, mips, usage); |
| 1703 | |
| 1704 | AllocationAdapter adapter = AllocationAdapter.create2D(rs, cubemap); |
Stephen Hines | 20fbd01 | 2011-06-16 17:44:53 -0700 | [diff] [blame] | 1705 | adapter.setFace(Type.CubemapFace.POSITIVE_X); |
Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 1706 | adapter.copyFrom(xpos); |
| 1707 | adapter.setFace(Type.CubemapFace.NEGATIVE_X); |
| 1708 | adapter.copyFrom(xneg); |
Stephen Hines | 20fbd01 | 2011-06-16 17:44:53 -0700 | [diff] [blame] | 1709 | adapter.setFace(Type.CubemapFace.POSITIVE_Y); |
Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 1710 | adapter.copyFrom(ypos); |
| 1711 | adapter.setFace(Type.CubemapFace.NEGATIVE_Y); |
| 1712 | adapter.copyFrom(yneg); |
Stephen Hines | 20fbd01 | 2011-06-16 17:44:53 -0700 | [diff] [blame] | 1713 | adapter.setFace(Type.CubemapFace.POSITIVE_Z); |
Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 1714 | adapter.copyFrom(zpos); |
| 1715 | adapter.setFace(Type.CubemapFace.NEGATIVE_Z); |
| 1716 | adapter.copyFrom(zneg); |
| 1717 | |
| 1718 | return cubemap; |
| 1719 | } |
| 1720 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1721 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1722 | * Creates a non-mipmapped cubemap Allocation for use as a sampler input |
| 1723 | * from 6 {@link android.graphics.Bitmap} objects containing the cube |
| 1724 | * faces. Each face must be a square, have the same size as all other faces, |
| 1725 | * and have a width that is a power of 2. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1726 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1727 | * @param rs Context to which the allocation will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1728 | * @param xpos cubemap face in the positive x direction |
| 1729 | * @param xneg cubemap face in the negative x direction |
| 1730 | * @param ypos cubemap face in the positive y direction |
| 1731 | * @param yneg cubemap face in the negative y direction |
| 1732 | * @param zpos cubemap face in the positive z direction |
| 1733 | * @param zneg cubemap face in the negative z direction |
| 1734 | * |
| 1735 | * @return allocation containing cubemap data |
| 1736 | * |
| 1737 | */ |
Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 1738 | static public Allocation createCubemapFromCubeFaces(RenderScript rs, |
| 1739 | Bitmap xpos, |
| 1740 | Bitmap xneg, |
| 1741 | Bitmap ypos, |
| 1742 | Bitmap yneg, |
| 1743 | Bitmap zpos, |
| 1744 | Bitmap zneg) { |
| 1745 | return createCubemapFromCubeFaces(rs, xpos, xneg, ypos, yneg, |
| 1746 | zpos, zneg, MipmapControl.MIPMAP_NONE, |
| 1747 | USAGE_GRAPHICS_TEXTURE); |
| 1748 | } |
| 1749 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1750 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1751 | * Creates an Allocation from the Bitmap referenced |
| 1752 | * by resource ID. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1753 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1754 | * @param rs Context to which the allocation will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1755 | * @param res application resources |
| 1756 | * @param id resource id to load the data from |
| 1757 | * @param mips specifies desired mipmap behaviour for the |
| 1758 | * allocation |
| 1759 | * @param usage bit field specifying how the allocation is |
| 1760 | * utilized |
| 1761 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1762 | * @return Allocation containing resource data |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1763 | * |
| 1764 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1765 | static public Allocation createFromBitmapResource(RenderScript rs, |
| 1766 | Resources res, |
| 1767 | int id, |
Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1768 | MipmapControl mips, |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1769 | int usage) { |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1770 | |
Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 1771 | rs.validate(); |
Jason Sams | 3ece2f3 | 2013-05-31 14:00:46 -0700 | [diff] [blame] | 1772 | if ((usage & (USAGE_SHARED | USAGE_IO_INPUT | USAGE_IO_OUTPUT)) != 0) { |
| 1773 | throw new RSIllegalArgumentException("Unsupported usage specified."); |
| 1774 | } |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1775 | Bitmap b = BitmapFactory.decodeResource(res, id); |
| 1776 | Allocation alloc = createFromBitmap(rs, b, mips, usage); |
| 1777 | b.recycle(); |
| 1778 | return alloc; |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1781 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1782 | * Creates a non-mipmapped Allocation to use as a graphics texture from the |
| 1783 | * {@link android.graphics.Bitmap} referenced by resource ID. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1784 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1785 | * <p>With target API version 18 or greater, this allocation will be created |
| 1786 | * with {@link #USAGE_SCRIPT} and {@link #USAGE_GRAPHICS_TEXTURE}. With |
| 1787 | * target API version 17 or lower, this allocation will be created with |
| 1788 | * {@link #USAGE_GRAPHICS_TEXTURE}.</p> |
Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 1789 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1790 | * @param rs Context to which the allocation will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1791 | * @param res application resources |
| 1792 | * @param id resource id to load the data from |
| 1793 | * |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1794 | * @return Allocation containing resource data |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1795 | * |
| 1796 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1797 | static public Allocation createFromBitmapResource(RenderScript rs, |
| 1798 | Resources res, |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 1799 | int id) { |
Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 1800 | if (rs.getApplicationContext().getApplicationInfo().targetSdkVersion >= 18) { |
| 1801 | return createFromBitmapResource(rs, res, id, |
| 1802 | MipmapControl.MIPMAP_NONE, |
Jason Sams | 3ece2f3 | 2013-05-31 14:00:46 -0700 | [diff] [blame] | 1803 | USAGE_SCRIPT | USAGE_GRAPHICS_TEXTURE); |
Jason Sams | 455d644 | 2013-02-05 19:20:18 -0800 | [diff] [blame] | 1804 | } |
Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 1805 | return createFromBitmapResource(rs, res, id, |
| 1806 | MipmapControl.MIPMAP_NONE, |
| 1807 | USAGE_GRAPHICS_TEXTURE); |
| 1808 | } |
| 1809 | |
Stephen Hines | 9c9ad3f8c2 | 2012-05-07 15:34:29 -0700 | [diff] [blame] | 1810 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1811 | * Creates an Allocation containing string data encoded in UTF-8 format. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1812 | * |
Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1813 | * @param rs Context to which the allocation will belong. |
Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1814 | * @param str string to create the allocation from |
| 1815 | * @param usage bit field specifying how the allocaiton is |
| 1816 | * utilized |
| 1817 | * |
| 1818 | */ |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1819 | static public Allocation createFromString(RenderScript rs, |
| 1820 | String str, |
| 1821 | int usage) { |
| 1822 | rs.validate(); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1823 | byte[] allocArray = null; |
| 1824 | try { |
| 1825 | allocArray = str.getBytes("UTF-8"); |
Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1826 | Allocation alloc = Allocation.createSized(rs, Element.U8(rs), allocArray.length, usage); |
Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1827 | alloc.copyFrom(allocArray); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1828 | return alloc; |
| 1829 | } |
| 1830 | catch (Exception e) { |
Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 1831 | throw new RSRuntimeException("Could not convert string to utf-8."); |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1832 | } |
Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1833 | } |
Jason Sams | 739c826 | 2013-04-11 18:07:52 -0700 | [diff] [blame] | 1834 | |
| 1835 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1836 | * Interface to handle notification when new buffers are available via |
| 1837 | * {@link #USAGE_IO_INPUT}. An application will receive one notification |
| 1838 | * when a buffer is available. Additional buffers will not trigger new |
| 1839 | * notifications until a buffer is processed. |
Jason Sams | 739c826 | 2013-04-11 18:07:52 -0700 | [diff] [blame] | 1840 | */ |
Jason Sams | 42ef238 | 2013-08-29 13:30:59 -0700 | [diff] [blame] | 1841 | public interface OnBufferAvailableListener { |
Jason Sams | 739c826 | 2013-04-11 18:07:52 -0700 | [diff] [blame] | 1842 | public void onBufferAvailable(Allocation a); |
| 1843 | } |
| 1844 | |
| 1845 | /** |
Tim Murray | c11e25c | 2013-04-09 11:01:01 -0700 | [diff] [blame] | 1846 | * Set a notification handler for {@link #USAGE_IO_INPUT}. |
Jason Sams | 739c826 | 2013-04-11 18:07:52 -0700 | [diff] [blame] | 1847 | * |
Jason Sams | 42ef238 | 2013-08-29 13:30:59 -0700 | [diff] [blame] | 1848 | * @param callback instance of the OnBufferAvailableListener |
| 1849 | * class to be called when buffer arrive. |
Jason Sams | 739c826 | 2013-04-11 18:07:52 -0700 | [diff] [blame] | 1850 | */ |
Jason Sams | 42ef238 | 2013-08-29 13:30:59 -0700 | [diff] [blame] | 1851 | public void setOnBufferAvailableListener(OnBufferAvailableListener callback) { |
Jason Sams | 739c826 | 2013-04-11 18:07:52 -0700 | [diff] [blame] | 1852 | synchronized(mAllocationMap) { |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1853 | mAllocationMap.put(new Long(getID(mRS)), this); |
Jason Sams | 739c826 | 2013-04-11 18:07:52 -0700 | [diff] [blame] | 1854 | mBufferNotifier = callback; |
| 1855 | } |
| 1856 | } |
| 1857 | |
| 1858 | static void sendBufferNotification(int id) { |
| 1859 | synchronized(mAllocationMap) { |
Tim Murray | 460a049 | 2013-11-19 12:45:54 -0800 | [diff] [blame] | 1860 | Allocation a = mAllocationMap.get(new Long(id)); |
Jason Sams | 739c826 | 2013-04-11 18:07:52 -0700 | [diff] [blame] | 1861 | |
| 1862 | if ((a != null) && (a.mBufferNotifier != null)) { |
| 1863 | a.mBufferNotifier.onBufferAvailable(a); |
| 1864 | } |
| 1865 | } |
| 1866 | } |
| 1867 | |
Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1868 | } |