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