| 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 | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 21 | import android.content.res.Resources; |
| Romain Guy | 650a3eb | 2009-08-31 14:06:43 -0700 | [diff] [blame] | 22 | import android.content.res.AssetManager; |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 23 | import android.graphics.Bitmap; |
| 24 | import android.graphics.BitmapFactory; |
| Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 25 | import android.view.Surface; |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 26 | import android.graphics.SurfaceTexture; |
| 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; |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 29 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 30 | /** @deprecated renderscript is deprecated in J |
| Robert Ly | 11518ac | 2011-02-09 13:57:06 -0800 | [diff] [blame] | 31 | * <p> |
| 32 | * Memory allocation class for renderscript. An allocation combines a |
| 33 | * {@link android.renderscript.Type} with the memory to provide storage for user data and objects. |
| 34 | * This implies that all memory in Renderscript is typed. |
| 35 | * </p> |
| Jason Sams | a23d4e7 | 2011-01-04 18:59:12 -0800 | [diff] [blame] | 36 | * |
| Robert Ly | 11518ac | 2011-02-09 13:57:06 -0800 | [diff] [blame] | 37 | * <p>Allocations are the primary way data moves into and out of scripts. Memory is user |
| 38 | * synchronized and it's possible for allocations to exist in multiple memory spaces |
| 39 | * concurrently. Currently those spaces are:</p> |
| 40 | * <ul> |
| 41 | * <li>Script: accessable by RS scripts.</li> |
| 42 | * <li>Graphics Texture: accessable as a graphics texture.</li> |
| 43 | * <li>Graphics Vertex: accessable as graphical vertex data.</li> |
| 44 | * <li>Graphics Constants: Accessable as constants in user shaders</li> |
| 45 | * </ul> |
| 46 | * </p> |
| 47 | * <p> |
| 48 | * For example, when creating a allocation for a texture, the user can |
| 49 | * specify its memory spaces as both script and textures. This means that it can both |
| 50 | * be used as script binding and as a GPU texture for rendering. To maintain |
| 51 | * synchronization if a script modifies an allocation used by other targets it must |
| 52 | * call a synchronizing function to push the updates to the memory, otherwise the results |
| 53 | * are undefined. |
| 54 | * </p> |
| 55 | * <p>By default, Android system side updates are always applied to the script accessable |
| 56 | * memory. If this is not present, they are then applied to the various HW |
| 57 | * memory types. A {@link android.renderscript.Allocation#syncAll syncAll()} |
| 58 | * call is necessary after the script data is updated to |
| 59 | * keep the other memory spaces in sync.</p> |
| Jason Sams | a23d4e7 | 2011-01-04 18:59:12 -0800 | [diff] [blame] | 60 | * |
| Robert Ly | 11518ac | 2011-02-09 13:57:06 -0800 | [diff] [blame] | 61 | * <p>Allocation data is uploaded in one of two primary ways. For simple |
| 62 | * arrays there are copyFrom() functions that take an array from the control code and |
| 63 | * copy it to the slave memory store. Both type checked and unchecked copies are provided. |
| 64 | * The unchecked variants exist to allow apps to copy over arrays of structures from a |
| 65 | * control language that does not support structures.</p> |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 66 | * |
| Joe Fernandez | 3aef8e1d | 2011-12-20 10:38:34 -0800 | [diff] [blame] | 67 | * <div class="special reference"> |
| 68 | * <h3>Developer Guides</h3> |
| 69 | * <p>For more information about creating an application that uses Renderscript, read the |
| 70 | * <a href="{@docRoot}guide/topics/graphics/renderscript.html">Renderscript</a> developer guide.</p> |
| 71 | * </div> |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 72 | **/ |
| 73 | public class Allocation extends BaseObj { |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 74 | Type mType; |
| Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 75 | Bitmap mBitmap; |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 76 | int mUsage; |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 77 | Allocation mAdaptedAllocation; |
| 78 | |
| 79 | boolean mConstrainedLOD; |
| 80 | boolean mConstrainedFace; |
| 81 | boolean mConstrainedY; |
| 82 | boolean mConstrainedZ; |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 83 | boolean mReadAllowed = true; |
| 84 | boolean mWriteAllowed = true; |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 85 | int mSelectedY; |
| 86 | int mSelectedZ; |
| 87 | int mSelectedLOD; |
| 88 | Type.CubemapFace mSelectedFace = Type.CubemapFace.POSITIVE_X; |
| 89 | |
| 90 | int mCurrentDimX; |
| 91 | int mCurrentDimY; |
| 92 | int mCurrentDimZ; |
| 93 | int mCurrentCount; |
| 94 | |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 95 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 96 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 97 | * The usage of the allocation. These signal to renderscript |
| 98 | * where to place the allocation in memory. |
| 99 | * |
| 100 | * SCRIPT The allocation will be bound to and accessed by |
| 101 | * scripts. |
| 102 | */ |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 103 | public static final int USAGE_SCRIPT = 0x0001; |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 104 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 105 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 106 | * GRAPHICS_TEXTURE The allocation will be used as a texture |
| Stephen Hines | 836c4a5 | 2011-06-01 14:38:10 -0700 | [diff] [blame] | 107 | * source by one or more graphics programs. |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 108 | * |
| 109 | */ |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 110 | public static final int USAGE_GRAPHICS_TEXTURE = 0x0002; |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 111 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 112 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 113 | * GRAPHICS_VERTEX The allocation will be used as a graphics |
| 114 | * mesh. |
| 115 | * |
| 116 | */ |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 117 | public static final int USAGE_GRAPHICS_VERTEX = 0x0004; |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 118 | |
| 119 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 120 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 121 | * GRAPHICS_CONSTANTS The allocation will be used as the source |
| 122 | * of shader constants by one or more programs. |
| 123 | * |
| 124 | */ |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 125 | public static final int USAGE_GRAPHICS_CONSTANTS = 0x0008; |
| 126 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 127 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 128 | * USAGE_GRAPHICS_RENDER_TARGET The allocation will be used as a |
| Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 129 | * target for offscreen rendering |
| 130 | * |
| 131 | */ |
| 132 | public static final int USAGE_GRAPHICS_RENDER_TARGET = 0x0010; |
| 133 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 134 | /** @hide renderscript is deprecated in J |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 135 | * USAGE_IO_INPUT The allocation will be used as SurfaceTexture |
| 136 | * consumer. This usage will cause the allocation to be created |
| 137 | * read only. |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 138 | * |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 139 | */ |
| Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 140 | public static final int USAGE_IO_INPUT = 0x0020; |
| Stephen Hines | 9069ee8 | 2012-02-13 18:25:54 -0800 | [diff] [blame] | 141 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 142 | /** @hide renderscript is deprecated in J |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 143 | * USAGE_IO_OUTPUT The allocation will be used as a |
| 144 | * SurfaceTexture producer. The dimensions and format of the |
| 145 | * SurfaceTexture will be forced to those of the allocation. |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 146 | * |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 147 | */ |
| Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 148 | public static final int USAGE_IO_OUTPUT = 0x0040; |
| Jason Sams | 43ee0685 | 2009-08-12 17:54:11 -0700 | [diff] [blame] | 149 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 150 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 151 | * Controls mipmap behavior when using the bitmap creation and |
| 152 | * update functions. |
| 153 | */ |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 154 | public enum MipmapControl { |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 155 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 156 | * No mipmaps will be generated and the type generated from the |
| 157 | * incoming bitmap will not contain additional LODs. |
| 158 | */ |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 159 | MIPMAP_NONE(0), |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 160 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 161 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 162 | * A Full mipmap chain will be created in script memory. The |
| 163 | * type of the allocation will contain a full mipmap chain. On |
| 164 | * upload to graphics the full chain will be transfered. |
| 165 | */ |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 166 | MIPMAP_FULL(1), |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 167 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 168 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 169 | * The type of the allocation will be the same as MIPMAP_NONE. |
| 170 | * It will not contain mipmaps. On upload to graphics the |
| 171 | * graphics copy of the allocation data will contain a full |
| 172 | * mipmap chain generated from the top level in script memory. |
| 173 | */ |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 174 | MIPMAP_ON_SYNC_TO_TEXTURE(2); |
| 175 | |
| 176 | int mID; |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 177 | MipmapControl(int id) { |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 178 | mID = id; |
| 179 | } |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 180 | } |
| 181 | |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 182 | |
| 183 | private int getIDSafe() { |
| 184 | if (mAdaptedAllocation != null) { |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 185 | return mAdaptedAllocation.getID(mRS); |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 186 | } |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 187 | return getID(mRS); |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 188 | } |
| 189 | |
| Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 190 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 191 | /** @hide renderscript is deprecated in J |
| Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 192 | * Get the element of the type of the Allocation. |
| 193 | * |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 194 | * @return Element that describes the structure of data in the |
| 195 | * allocation |
| Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 196 | * |
| 197 | */ |
| 198 | public Element getElement() { |
| 199 | return mType.getElement(); |
| 200 | } |
| 201 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 202 | /** @hide renderscript is deprecated in J |
| Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 203 | * Get the usage flags of the Allocation. |
| 204 | * |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 205 | * @return usage flags associated with the allocation. e.g. |
| 206 | * script, texture, etc. |
| Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 207 | * |
| 208 | */ |
| 209 | public int getUsage() { |
| 210 | return mUsage; |
| 211 | } |
| 212 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 213 | /** @hide renderscript is deprecated in J |
| Jason Sams | 36c0f64 | 2012-03-23 15:48:37 -0700 | [diff] [blame] | 214 | * Get the size of the Allocation in bytes. |
| 215 | * |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 216 | * @return size of the Allocation in bytes. |
| Jason Sams | 36c0f64 | 2012-03-23 15:48:37 -0700 | [diff] [blame] | 217 | * |
| 218 | */ |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 219 | public int getBytesSize() { |
| 220 | return mType.getCount() * mType.getElement().getBytesSize(); |
| Jason Sams | 36c0f64 | 2012-03-23 15:48:37 -0700 | [diff] [blame] | 221 | } |
| 222 | |
| Jason Sams | 452a766 | 2011-07-07 16:05:18 -0700 | [diff] [blame] | 223 | private void updateCacheInfo(Type t) { |
| 224 | mCurrentDimX = t.getX(); |
| 225 | mCurrentDimY = t.getY(); |
| 226 | mCurrentDimZ = t.getZ(); |
| 227 | mCurrentCount = mCurrentDimX; |
| 228 | if (mCurrentDimY > 1) { |
| 229 | mCurrentCount *= mCurrentDimY; |
| 230 | } |
| 231 | if (mCurrentDimZ > 1) { |
| 232 | mCurrentCount *= mCurrentDimZ; |
| 233 | } |
| 234 | } |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 235 | |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 236 | Allocation(int id, RenderScript rs, Type t, int usage) { |
| Alex Sakhartchouk | 0de9444 | 2010-08-11 14:41:28 -0700 | [diff] [blame] | 237 | super(id, rs); |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 238 | if ((usage & ~(USAGE_SCRIPT | |
| 239 | USAGE_GRAPHICS_TEXTURE | |
| 240 | USAGE_GRAPHICS_VERTEX | |
| Alex Sakhartchouk | 8e90f2b | 2011-04-01 14:19:01 -0700 | [diff] [blame] | 241 | USAGE_GRAPHICS_CONSTANTS | |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 242 | USAGE_GRAPHICS_RENDER_TARGET | |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 243 | USAGE_IO_INPUT | |
| 244 | USAGE_IO_OUTPUT)) != 0) { |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 245 | throw new RSIllegalArgumentException("Unknown usage specified."); |
| 246 | } |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 247 | |
| Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 248 | if ((usage & USAGE_IO_INPUT) != 0) { |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 249 | mWriteAllowed = false; |
| 250 | |
| Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 251 | if ((usage & ~(USAGE_IO_INPUT | |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 252 | USAGE_GRAPHICS_TEXTURE | |
| 253 | USAGE_SCRIPT)) != 0) { |
| 254 | throw new RSIllegalArgumentException("Invalid usage combination."); |
| 255 | } |
| 256 | } |
| 257 | |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 258 | mType = t; |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 259 | mUsage = usage; |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 260 | |
| Jason Sams | 452a766 | 2011-07-07 16:05:18 -0700 | [diff] [blame] | 261 | if (t != null) { |
| 262 | updateCacheInfo(t); |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 263 | } |
| Alex Sakhartchouk | 80a4c2c | 2010-07-12 15:50:32 -0700 | [diff] [blame] | 264 | } |
| 265 | |
| Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 266 | private void validateIsInt32() { |
| 267 | if ((mType.mElement.mType == Element.DataType.SIGNED_32) || |
| 268 | (mType.mElement.mType == Element.DataType.UNSIGNED_32)) { |
| 269 | return; |
| 270 | } |
| 271 | throw new RSIllegalArgumentException( |
| 272 | "32 bit integer source does not match allocation type " + mType.mElement.mType); |
| 273 | } |
| 274 | |
| 275 | private void validateIsInt16() { |
| 276 | if ((mType.mElement.mType == Element.DataType.SIGNED_16) || |
| 277 | (mType.mElement.mType == Element.DataType.UNSIGNED_16)) { |
| 278 | return; |
| 279 | } |
| 280 | throw new RSIllegalArgumentException( |
| 281 | "16 bit integer source does not match allocation type " + mType.mElement.mType); |
| 282 | } |
| 283 | |
| 284 | private void validateIsInt8() { |
| 285 | if ((mType.mElement.mType == Element.DataType.SIGNED_8) || |
| 286 | (mType.mElement.mType == Element.DataType.UNSIGNED_8)) { |
| 287 | return; |
| 288 | } |
| 289 | throw new RSIllegalArgumentException( |
| 290 | "8 bit integer source does not match allocation type " + mType.mElement.mType); |
| 291 | } |
| 292 | |
| 293 | private void validateIsFloat32() { |
| 294 | if (mType.mElement.mType == Element.DataType.FLOAT_32) { |
| 295 | return; |
| 296 | } |
| 297 | throw new RSIllegalArgumentException( |
| 298 | "32 bit float source does not match allocation type " + mType.mElement.mType); |
| 299 | } |
| 300 | |
| 301 | private void validateIsObject() { |
| 302 | if ((mType.mElement.mType == Element.DataType.RS_ELEMENT) || |
| 303 | (mType.mElement.mType == Element.DataType.RS_TYPE) || |
| 304 | (mType.mElement.mType == Element.DataType.RS_ALLOCATION) || |
| 305 | (mType.mElement.mType == Element.DataType.RS_SAMPLER) || |
| 306 | (mType.mElement.mType == Element.DataType.RS_SCRIPT) || |
| 307 | (mType.mElement.mType == Element.DataType.RS_MESH) || |
| 308 | (mType.mElement.mType == Element.DataType.RS_PROGRAM_FRAGMENT) || |
| 309 | (mType.mElement.mType == Element.DataType.RS_PROGRAM_VERTEX) || |
| 310 | (mType.mElement.mType == Element.DataType.RS_PROGRAM_RASTER) || |
| 311 | (mType.mElement.mType == Element.DataType.RS_PROGRAM_STORE)) { |
| 312 | return; |
| 313 | } |
| 314 | throw new RSIllegalArgumentException( |
| 315 | "Object source does not match allocation type " + mType.mElement.mType); |
| 316 | } |
| 317 | |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 318 | @Override |
| 319 | void updateFromNative() { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 320 | super.updateFromNative(); |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 321 | int typeID = mRS.nAllocationGetType(getID(mRS)); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 322 | if(typeID != 0) { |
| 323 | mType = new Type(typeID, mRS); |
| 324 | mType.updateFromNative(); |
| Jason Sams | ad37cb2 | 2011-07-07 16:17:36 -0700 | [diff] [blame] | 325 | updateCacheInfo(mType); |
| Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 329 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 330 | * Get the type of the Allocation. |
| 331 | * |
| 332 | * @return Type |
| 333 | * |
| 334 | */ |
| Jason Sams | ea87e96 | 2010-01-12 12:12:28 -0800 | [diff] [blame] | 335 | public Type getType() { |
| 336 | return mType; |
| 337 | } |
| 338 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 339 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 36c0f64 | 2012-03-23 15:48:37 -0700 | [diff] [blame] | 340 | * Propagate changes from one usage of the allocation to the |
| Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 341 | * remaining usages of the allocation. |
| 342 | * |
| 343 | */ |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 344 | public void syncAll(int srcLocation) { |
| 345 | switch (srcLocation) { |
| 346 | case USAGE_SCRIPT: |
| 347 | case USAGE_GRAPHICS_CONSTANTS: |
| 348 | case USAGE_GRAPHICS_TEXTURE: |
| 349 | case USAGE_GRAPHICS_VERTEX: |
| 350 | break; |
| 351 | default: |
| 352 | throw new RSIllegalArgumentException("Source must be exactly one usage type."); |
| 353 | } |
| 354 | mRS.validate(); |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 355 | mRS.nAllocationSyncAll(getIDSafe(), srcLocation); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 356 | } |
| 357 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 358 | /** @hide renderscript is deprecated in J |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 359 | * Send a buffer to the output stream. The contents of the |
| 360 | * Allocation will be undefined after this operation. |
| 361 | * |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 362 | */ |
| Jason Sams | c5f519c | 2012-03-29 17:58:15 -0700 | [diff] [blame] | 363 | public void ioSend() { |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 364 | if ((mUsage & USAGE_IO_OUTPUT) == 0) { |
| 365 | throw new RSIllegalArgumentException( |
| 366 | "Can only send buffer if IO_OUTPUT usage specified."); |
| 367 | } |
| 368 | mRS.validate(); |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 369 | mRS.nAllocationIoSend(getID(mRS)); |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 370 | } |
| 371 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 372 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | c5f519c | 2012-03-29 17:58:15 -0700 | [diff] [blame] | 373 | * Delete once code is updated. |
| 374 | * @hide |
| 375 | */ |
| 376 | public void ioSendOutput() { |
| 377 | ioSend(); |
| 378 | } |
| 379 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 380 | /** @hide renderscript is deprecated in J |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 381 | * Receive the latest input into the Allocation. |
| 382 | * |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 383 | */ |
| Jason Sams | c5f519c | 2012-03-29 17:58:15 -0700 | [diff] [blame] | 384 | public void ioReceive() { |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 385 | if ((mUsage & USAGE_IO_INPUT) == 0) { |
| 386 | throw new RSIllegalArgumentException( |
| Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 387 | "Can only receive if IO_INPUT usage specified."); |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 388 | } |
| 389 | mRS.validate(); |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 390 | mRS.nAllocationIoReceive(getID(mRS)); |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 391 | } |
| 392 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 393 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 36c0f64 | 2012-03-23 15:48:37 -0700 | [diff] [blame] | 394 | * Copy an array of RS objects to the allocation. |
| Jason Sams | 03d2d00 | 2012-03-23 13:51:56 -0700 | [diff] [blame] | 395 | * |
| 396 | * @param d Source array. |
| 397 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 398 | public void copyFrom(BaseObj[] d) { |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 399 | mRS.validate(); |
| Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 400 | validateIsObject(); |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 401 | if (d.length != mCurrentCount) { |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 402 | throw new RSIllegalArgumentException("Array size mismatch, allocation sizeX = " + |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 403 | mCurrentCount + ", array length = " + d.length); |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 404 | } |
| 405 | int i[] = new int[d.length]; |
| 406 | for (int ct=0; ct < d.length; ct++) { |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 407 | i[ct] = d[ct].getID(mRS); |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 408 | } |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 409 | copy1DRangeFromUnchecked(0, mCurrentCount, i); |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 410 | } |
| 411 | |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 412 | private void validateBitmapFormat(Bitmap b) { |
| Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 413 | Bitmap.Config bc = b.getConfig(); |
| 414 | switch (bc) { |
| 415 | case ALPHA_8: |
| 416 | if (mType.getElement().mKind != Element.DataKind.PIXEL_A) { |
| 417 | throw new RSIllegalArgumentException("Allocation kind is " + |
| 418 | mType.getElement().mKind + ", type " + |
| 419 | mType.getElement().mType + |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 420 | " of " + mType.getElement().getBytesSize() + |
| Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 421 | " bytes, passed bitmap was " + bc); |
| 422 | } |
| 423 | break; |
| 424 | case ARGB_8888: |
| 425 | if ((mType.getElement().mKind != Element.DataKind.PIXEL_RGBA) || |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 426 | (mType.getElement().getBytesSize() != 4)) { |
| Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 427 | throw new RSIllegalArgumentException("Allocation kind is " + |
| 428 | mType.getElement().mKind + ", type " + |
| 429 | mType.getElement().mType + |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 430 | " of " + mType.getElement().getBytesSize() + |
| Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 431 | " bytes, passed bitmap was " + bc); |
| 432 | } |
| 433 | break; |
| 434 | case RGB_565: |
| 435 | if ((mType.getElement().mKind != Element.DataKind.PIXEL_RGB) || |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 436 | (mType.getElement().getBytesSize() != 2)) { |
| Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 437 | throw new RSIllegalArgumentException("Allocation kind is " + |
| 438 | mType.getElement().mKind + ", type " + |
| 439 | mType.getElement().mType + |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 440 | " of " + mType.getElement().getBytesSize() + |
| Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 441 | " bytes, passed bitmap was " + bc); |
| 442 | } |
| 443 | break; |
| 444 | case ARGB_4444: |
| 445 | if ((mType.getElement().mKind != Element.DataKind.PIXEL_RGBA) || |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 446 | (mType.getElement().getBytesSize() != 2)) { |
| Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 447 | throw new RSIllegalArgumentException("Allocation kind is " + |
| 448 | mType.getElement().mKind + ", type " + |
| 449 | mType.getElement().mType + |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 450 | " of " + mType.getElement().getBytesSize() + |
| Jason Sams | 252c078 | 2011-01-11 17:42:52 -0800 | [diff] [blame] | 451 | " bytes, passed bitmap was " + bc); |
| 452 | } |
| 453 | break; |
| 454 | |
| 455 | } |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 456 | } |
| 457 | |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 458 | private void validateBitmapSize(Bitmap b) { |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 459 | if((mCurrentDimX != b.getWidth()) || (mCurrentDimY != b.getHeight())) { |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 460 | throw new RSIllegalArgumentException("Cannot update allocation from bitmap, sizes mismatch"); |
| 461 | } |
| 462 | } |
| 463 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 464 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 465 | * Copy an allocation from an array. This variant is not type |
| 466 | * checked which allows an application to fill in structured |
| 467 | * data from an array. |
| 468 | * |
| 469 | * @param d the source data array |
| 470 | */ |
| 471 | public void copyFromUnchecked(int[] d) { |
| 472 | mRS.validate(); |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 473 | copy1DRangeFromUnchecked(0, mCurrentCount, d); |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 474 | } |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 475 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 476 | * Copy an allocation from an array. This variant is not type |
| 477 | * checked which allows an application to fill in structured |
| 478 | * data from an array. |
| 479 | * |
| 480 | * @param d the source data array |
| 481 | */ |
| 482 | public void copyFromUnchecked(short[] d) { |
| 483 | mRS.validate(); |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 484 | copy1DRangeFromUnchecked(0, mCurrentCount, d); |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 485 | } |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 486 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 487 | * Copy an allocation from an array. This variant is not type |
| 488 | * checked which allows an application to fill in structured |
| 489 | * data from an array. |
| 490 | * |
| 491 | * @param d the source data array |
| 492 | */ |
| 493 | public void copyFromUnchecked(byte[] d) { |
| 494 | mRS.validate(); |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 495 | copy1DRangeFromUnchecked(0, mCurrentCount, d); |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 496 | } |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 497 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 498 | * Copy an allocation from an array. This variant is not type |
| 499 | * checked which allows an application to fill in structured |
| 500 | * data from an array. |
| 501 | * |
| 502 | * @param d the source data array |
| 503 | */ |
| 504 | public void copyFromUnchecked(float[] d) { |
| 505 | mRS.validate(); |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 506 | copy1DRangeFromUnchecked(0, mCurrentCount, d); |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 507 | } |
| 508 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 509 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 510 | * Copy an allocation from an array. This variant is type |
| 511 | * checked and will generate exceptions if the Allocation type |
| 512 | * is not a 32 bit integer type. |
| 513 | * |
| 514 | * @param d the source data array |
| 515 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 516 | public void copyFrom(int[] d) { |
| 517 | mRS.validate(); |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 518 | copy1DRangeFrom(0, mCurrentCount, d); |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 519 | } |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 520 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 521 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 522 | * Copy an allocation from an array. This variant is type |
| 523 | * checked and will generate exceptions if the Allocation type |
| 524 | * is not a 16 bit integer type. |
| 525 | * |
| 526 | * @param d the source data array |
| 527 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 528 | public void copyFrom(short[] d) { |
| 529 | mRS.validate(); |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 530 | copy1DRangeFrom(0, mCurrentCount, d); |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 531 | } |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 532 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 533 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 534 | * Copy an allocation from an array. This variant is type |
| 535 | * checked and will generate exceptions if the Allocation type |
| 536 | * is not a 8 bit integer type. |
| 537 | * |
| 538 | * @param d the source data array |
| 539 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 540 | public void copyFrom(byte[] d) { |
| 541 | mRS.validate(); |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 542 | copy1DRangeFrom(0, mCurrentCount, d); |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 543 | } |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 544 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 545 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 546 | * Copy an allocation from an array. This variant is type |
| 547 | * checked and will generate exceptions if the Allocation type |
| 548 | * is not a 32 bit float type. |
| 549 | * |
| 550 | * @param d the source data array |
| 551 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 552 | public void copyFrom(float[] d) { |
| 553 | mRS.validate(); |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 554 | copy1DRangeFrom(0, mCurrentCount, d); |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 555 | } |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 556 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 557 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 558 | * Copy an allocation from a bitmap. The height, width, and |
| 559 | * format of the bitmap must match the existing allocation. |
| 560 | * |
| 561 | * @param b the source bitmap |
| 562 | */ |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 563 | public void copyFrom(Bitmap b) { |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 564 | mRS.validate(); |
| 565 | validateBitmapSize(b); |
| 566 | validateBitmapFormat(b); |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 567 | mRS.nAllocationCopyFromBitmap(getID(mRS), b); |
| Alex Sakhartchouk | 26ae390 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 568 | } |
| 569 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 570 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 571 | * This is only intended to be used by auto-generate code reflected from the |
| 572 | * renderscript script files. |
| 573 | * |
| 574 | * @param xoff |
| 575 | * @param fp |
| 576 | */ |
| Jason Sams | 21b4103 | 2011-01-16 15:05:41 -0800 | [diff] [blame] | 577 | public void setFromFieldPacker(int xoff, FieldPacker fp) { |
| Jason Sams | f70b0fc8 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 578 | mRS.validate(); |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 579 | int eSize = mType.mElement.getBytesSize(); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 580 | final byte[] data = fp.getData(); |
| 581 | |
| 582 | int count = data.length / eSize; |
| 583 | if ((eSize * count) != data.length) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 584 | throw new RSIllegalArgumentException("Field packer length " + data.length + |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 585 | " not divisible by element size " + eSize + "."); |
| 586 | } |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 587 | copy1DRangeFromUnchecked(xoff, count, data); |
| Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 588 | } |
| 589 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 590 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 591 | * This is only intended to be used by auto-generate code reflected from the |
| 592 | * renderscript script files. |
| 593 | * |
| 594 | * @param xoff |
| 595 | * @param component_number |
| 596 | * @param fp |
| 597 | */ |
| Jason Sams | 21b4103 | 2011-01-16 15:05:41 -0800 | [diff] [blame] | 598 | public void setFromFieldPacker(int xoff, int component_number, FieldPacker fp) { |
| Jason Sams | f70b0fc8 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 599 | mRS.validate(); |
| Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 600 | if (component_number >= mType.mElement.mElements.length) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 601 | throw new RSIllegalArgumentException("Component_number " + component_number + " out of range."); |
| Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 602 | } |
| 603 | if(xoff < 0) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 604 | throw new RSIllegalArgumentException("Offset must be >= 0."); |
| Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | final byte[] data = fp.getData(); |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 608 | int eSize = mType.mElement.mElements[component_number].getBytesSize(); |
| Alex Sakhartchouk | bf3c3f2 | 2012-02-02 09:47:26 -0800 | [diff] [blame] | 609 | eSize *= mType.mElement.mArraySizes[component_number]; |
| Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 610 | |
| 611 | if (data.length != eSize) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 612 | throw new RSIllegalArgumentException("Field packer sizelength " + data.length + |
| Jason Sams | 49bdaf0 | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 613 | " does not match component size " + eSize + "."); |
| 614 | } |
| 615 | |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 616 | mRS.nAllocationElementData1D(getIDSafe(), xoff, mSelectedLOD, |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 617 | component_number, data, data.length); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 618 | } |
| 619 | |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 620 | private void data1DChecks(int off, int count, int len, int dataSize) { |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 621 | mRS.validate(); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 622 | if(off < 0) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 623 | throw new RSIllegalArgumentException("Offset must be >= 0."); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 624 | } |
| 625 | if(count < 1) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 626 | throw new RSIllegalArgumentException("Count must be >= 1."); |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 627 | } |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 628 | if((off + count) > mCurrentCount) { |
| 629 | throw new RSIllegalArgumentException("Overflow, Available count " + mCurrentCount + |
| Jason Sams | a70f416 | 2010-03-26 15:33:42 -0700 | [diff] [blame] | 630 | ", got " + count + " at offset " + off + "."); |
| Jason Sams | 07ae406 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 631 | } |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 632 | if(len < dataSize) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 633 | throw new RSIllegalArgumentException("Array too small for allocation type."); |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 634 | } |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 635 | } |
| 636 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 637 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 638 | * Generate a mipmap chain. Requires the type of the allocation |
| 639 | * include mipmaps. |
| 640 | * |
| 641 | * This function will generate a complete set of mipmaps from |
| 642 | * the top level lod and place them into the script memoryspace. |
| 643 | * |
| 644 | * If the allocation is also using other memory spaces a |
| 645 | * followup sync will be required. |
| 646 | */ |
| 647 | public void generateMipmaps() { |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 648 | mRS.nAllocationGenerateMipmaps(getID(mRS)); |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 649 | } |
| 650 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 651 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 652 | * Copy part of an allocation from an array. This variant is |
| 653 | * not type checked which allows an application to fill in |
| 654 | * structured data from an array. |
| 655 | * |
| 656 | * @param off The offset of the first element to be copied. |
| 657 | * @param count The number of elements to be copied. |
| 658 | * @param d the source data array |
| 659 | */ |
| 660 | public void copy1DRangeFromUnchecked(int off, int count, int[] d) { |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 661 | int dataSize = mType.mElement.getBytesSize() * count; |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 662 | data1DChecks(off, count, d.length * 4, dataSize); |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 663 | mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize); |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 664 | } |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 665 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 666 | * Copy part of an allocation from an array. This variant is |
| 667 | * not type checked which allows an application to fill in |
| 668 | * structured data from an array. |
| 669 | * |
| 670 | * @param off The offset of the first element to be copied. |
| 671 | * @param count The number of elements to be copied. |
| 672 | * @param d the source data array |
| 673 | */ |
| 674 | public void copy1DRangeFromUnchecked(int off, int count, short[] d) { |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 675 | int dataSize = mType.mElement.getBytesSize() * count; |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 676 | data1DChecks(off, count, d.length * 2, dataSize); |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 677 | mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize); |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 678 | } |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 679 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 680 | * Copy part of an allocation from an array. This variant is |
| 681 | * not type checked which allows an application to fill in |
| 682 | * structured data from an array. |
| 683 | * |
| 684 | * @param off The offset of the first element to be copied. |
| 685 | * @param count The number of elements to be copied. |
| 686 | * @param d the source data array |
| 687 | */ |
| 688 | public void copy1DRangeFromUnchecked(int off, int count, byte[] d) { |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 689 | int dataSize = mType.mElement.getBytesSize() * count; |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 690 | data1DChecks(off, count, d.length, dataSize); |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 691 | mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize); |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 692 | } |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 693 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 694 | * Copy part of an allocation from an array. This variant is |
| 695 | * not type checked which allows an application to fill in |
| 696 | * structured data from an array. |
| 697 | * |
| 698 | * @param off The offset of the first element to be copied. |
| 699 | * @param count The number of elements to be copied. |
| 700 | * @param d the source data array |
| 701 | */ |
| 702 | public void copy1DRangeFromUnchecked(int off, int count, float[] d) { |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 703 | int dataSize = mType.mElement.getBytesSize() * count; |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 704 | data1DChecks(off, count, d.length * 4, dataSize); |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 705 | mRS.nAllocationData1D(getIDSafe(), off, mSelectedLOD, count, d, dataSize); |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 706 | } |
| 707 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 708 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 709 | * Copy part of an allocation from an array. This variant is |
| 710 | * type checked and will generate exceptions if the Allocation |
| 711 | * type is not a 32 bit integer type. |
| 712 | * |
| 713 | * @param off The offset of the first element to be copied. |
| 714 | * @param count The number of elements to be copied. |
| 715 | * @param d the source data array |
| 716 | */ |
| Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 717 | public void copy1DRangeFrom(int off, int count, int[] d) { |
| 718 | validateIsInt32(); |
| 719 | copy1DRangeFromUnchecked(off, count, d); |
| 720 | } |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 721 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 722 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 723 | * Copy part of an allocation from an array. This variant is |
| 724 | * type checked and will generate exceptions if the Allocation |
| 725 | * type is not a 16 bit integer type. |
| 726 | * |
| 727 | * @param off The offset of the first element to be copied. |
| 728 | * @param count The number of elements to be copied. |
| 729 | * @param d the source data array |
| 730 | */ |
| Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 731 | public void copy1DRangeFrom(int off, int count, short[] d) { |
| 732 | validateIsInt16(); |
| 733 | copy1DRangeFromUnchecked(off, count, d); |
| 734 | } |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 735 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 736 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 737 | * Copy part of an allocation from an array. This variant is |
| 738 | * type checked and will generate exceptions if the Allocation |
| 739 | * type is not a 8 bit integer type. |
| 740 | * |
| 741 | * @param off The offset of the first element to be copied. |
| 742 | * @param count The number of elements to be copied. |
| 743 | * @param d the source data array |
| 744 | */ |
| Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 745 | public void copy1DRangeFrom(int off, int count, byte[] d) { |
| 746 | validateIsInt8(); |
| 747 | copy1DRangeFromUnchecked(off, count, d); |
| 748 | } |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 749 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 750 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 751 | * Copy part of an allocation from an array. This variant is |
| 752 | * type checked and will generate exceptions if the Allocation |
| 753 | * type is not a 32 bit float type. |
| 754 | * |
| 755 | * @param off The offset of the first element to be copied. |
| 756 | * @param count The number of elements to be copied. |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 757 | * @param d the source data array. |
| Jason Sams | 4fa3eed | 2011-01-19 15:44:38 -0800 | [diff] [blame] | 758 | */ |
| Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 759 | public void copy1DRangeFrom(int off, int count, float[] d) { |
| 760 | validateIsFloat32(); |
| 761 | copy1DRangeFromUnchecked(off, count, d); |
| 762 | } |
| 763 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 764 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 765 | * Copy part of an allocation from another allocation. |
| 766 | * |
| 767 | * @param off The offset of the first element to be copied. |
| 768 | * @param count The number of elements to be copied. |
| 769 | * @param data the source data allocation. |
| 770 | * @param dataOff off The offset of the first element in data to |
| 771 | * be copied. |
| 772 | */ |
| 773 | public void copy1DRangeFrom(int off, int count, Allocation data, int dataOff) { |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 774 | mRS.nAllocationData2D(getIDSafe(), off, 0, |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 775 | mSelectedLOD, mSelectedFace.mID, |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 776 | count, 1, data.getID(mRS), dataOff, 0, |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 777 | data.mSelectedLOD, data.mSelectedFace.mID); |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 778 | } |
| 779 | |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 780 | private void validate2DRange(int xoff, int yoff, int w, int h) { |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 781 | if (mAdaptedAllocation != null) { |
| 782 | |
| 783 | } else { |
| 784 | |
| 785 | if (xoff < 0 || yoff < 0) { |
| 786 | throw new RSIllegalArgumentException("Offset cannot be negative."); |
| 787 | } |
| 788 | if (h < 0 || w < 0) { |
| 789 | throw new RSIllegalArgumentException("Height or width cannot be negative."); |
| 790 | } |
| 791 | if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY)) { |
| 792 | throw new RSIllegalArgumentException("Updated region larger than allocation."); |
| 793 | } |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 794 | } |
| 795 | } |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 796 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 797 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 798 | * Copy a rectangular region from the array into the allocation. |
| 799 | * The incoming array is assumed to be tightly packed. |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 800 | * |
| 801 | * @param xoff X offset of the region to update |
| 802 | * @param yoff Y offset of the region to update |
| 803 | * @param w Width of the incoming region to update |
| 804 | * @param h Height of the incoming region to update |
| 805 | * @param data to be placed into the allocation |
| 806 | */ |
| 807 | public void copy2DRangeFrom(int xoff, int yoff, int w, int h, byte[] data) { |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 808 | mRS.validate(); |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 809 | validate2DRange(xoff, yoff, w, h); |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 810 | mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 811 | w, h, data, data.length); |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 812 | } |
| 813 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 814 | /** @deprecated renderscript is deprecated in J |
| 815 | */ |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 816 | public void copy2DRangeFrom(int xoff, int yoff, int w, int h, short[] data) { |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 817 | mRS.validate(); |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 818 | validate2DRange(xoff, yoff, w, h); |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 819 | mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 820 | w, h, data, data.length * 2); |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 821 | } |
| 822 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 823 | /** @deprecated renderscript is deprecated in J |
| 824 | */ |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 825 | public void copy2DRangeFrom(int xoff, int yoff, int w, int h, int[] data) { |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 826 | mRS.validate(); |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 827 | validate2DRange(xoff, yoff, w, h); |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 828 | mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 829 | w, h, data, data.length * 4); |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 830 | } |
| 831 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 832 | /** @deprecated renderscript is deprecated in J |
| 833 | */ |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 834 | public void copy2DRangeFrom(int xoff, int yoff, int w, int h, float[] data) { |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 835 | mRS.validate(); |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 836 | validate2DRange(xoff, yoff, w, h); |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 837 | mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 838 | w, h, data, data.length * 4); |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 839 | } |
| 840 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 841 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 842 | * Copy a rectangular region into the allocation from another |
| 843 | * allocation. |
| 844 | * |
| 845 | * @param xoff X offset of the region to update. |
| 846 | * @param yoff Y offset of the region to update. |
| 847 | * @param w Width of the incoming region to update. |
| 848 | * @param h Height of the incoming region to update. |
| 849 | * @param data source allocation. |
| 850 | * @param dataXoff X offset in data of the region to update. |
| 851 | * @param dataYoff Y offset in data of the region to update. |
| 852 | */ |
| 853 | public void copy2DRangeFrom(int xoff, int yoff, int w, int h, |
| 854 | Allocation data, int dataXoff, int dataYoff) { |
| 855 | mRS.validate(); |
| 856 | validate2DRange(xoff, yoff, w, h); |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 857 | mRS.nAllocationData2D(getIDSafe(), xoff, yoff, |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 858 | mSelectedLOD, mSelectedFace.mID, |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 859 | w, h, data.getID(mRS), dataXoff, dataYoff, |
| Jason Sams | ba862d1 | 2011-07-07 15:24:42 -0700 | [diff] [blame] | 860 | data.mSelectedLOD, data.mSelectedFace.mID); |
| Alex Sakhartchouk | 304b1f5 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 861 | } |
| 862 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 863 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 864 | * Copy a bitmap into an allocation. The height and width of |
| 865 | * the update will use the height and width of the incoming |
| 866 | * bitmap. |
| 867 | * |
| 868 | * @param xoff X offset of the region to update |
| 869 | * @param yoff Y offset of the region to update |
| 870 | * @param data the bitmap to be copied |
| 871 | */ |
| 872 | public void copy2DRangeFrom(int xoff, int yoff, Bitmap data) { |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 873 | mRS.validate(); |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 874 | validateBitmapFormat(data); |
| 875 | validate2DRange(xoff, yoff, data.getWidth(), data.getHeight()); |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 876 | mRS.nAllocationData2D(getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace.mID, data); |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 877 | } |
| 878 | |
| 879 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 880 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 881 | * Copy from the Allocation into a Bitmap. The bitmap must |
| 882 | * match the dimensions of the Allocation. |
| 883 | * |
| 884 | * @param b The bitmap to be set from the Allocation. |
| 885 | */ |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 886 | public void copyTo(Bitmap b) { |
| Jason Sams | fb9f82c | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 887 | mRS.validate(); |
| 888 | validateBitmapFormat(b); |
| 889 | validateBitmapSize(b); |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 890 | mRS.nAllocationCopyToBitmap(getID(mRS), b); |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 891 | } |
| 892 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 893 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 894 | * Copy from the Allocation into a byte array. The array must |
| 895 | * be at least as large as the Allocation. The allocation must |
| 896 | * be of an 8 bit elemental type. |
| 897 | * |
| 898 | * @param d The array to be set from the Allocation. |
| 899 | */ |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 900 | public void copyTo(byte[] d) { |
| Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 901 | validateIsInt8(); |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 902 | mRS.validate(); |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 903 | mRS.nAllocationRead(getID(mRS), d); |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 904 | } |
| 905 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 906 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 907 | * Copy from the Allocation into a short array. The array must |
| 908 | * be at least as large as the Allocation. The allocation must |
| 909 | * be of an 16 bit elemental type. |
| 910 | * |
| 911 | * @param d The array to be set from the Allocation. |
| 912 | */ |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 913 | public void copyTo(short[] d) { |
| Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 914 | validateIsInt16(); |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 915 | mRS.validate(); |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 916 | mRS.nAllocationRead(getID(mRS), d); |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 917 | } |
| 918 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 919 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 920 | * Copy from the Allocation into a int array. The array must be |
| 921 | * at least as large as the Allocation. The allocation must be |
| 922 | * of an 32 bit elemental type. |
| 923 | * |
| 924 | * @param d The array to be set from the Allocation. |
| 925 | */ |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 926 | public void copyTo(int[] d) { |
| Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 927 | validateIsInt32(); |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 928 | mRS.validate(); |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 929 | mRS.nAllocationRead(getID(mRS), d); |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 930 | } |
| 931 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 932 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 48fe534 | 2011-07-08 13:52:30 -0700 | [diff] [blame] | 933 | * Copy from the Allocation into a float array. The array must |
| 934 | * be at least as large as the Allocation. The allocation must |
| 935 | * be of an 32 bit float elemental type. |
| 936 | * |
| 937 | * @param d The array to be set from the Allocation. |
| 938 | */ |
| Jason Sams | fa445b9 | 2011-01-07 17:00:07 -0800 | [diff] [blame] | 939 | public void copyTo(float[] d) { |
| Jason Sams | b97b251 | 2011-01-16 15:04:08 -0800 | [diff] [blame] | 940 | validateIsFloat32(); |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 941 | mRS.validate(); |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 942 | mRS.nAllocationRead(getID(mRS), d); |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 943 | } |
| 944 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 945 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | f708609 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 946 | * Resize a 1D allocation. The contents of the allocation are |
| 947 | * preserved. If new elements are allocated objects are created |
| 948 | * with null contents and the new region is otherwise undefined. |
| 949 | * |
| 950 | * If the new region is smaller the references of any objects |
| 951 | * outside the new region will be released. |
| 952 | * |
| 953 | * A new type will be created with the new dimension. |
| 954 | * |
| 955 | * @param dimX The new size of the allocation. |
| 956 | */ |
| Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 957 | public synchronized void resize(int dimX) { |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 958 | if ((mType.getY() > 0)|| (mType.getZ() > 0) || mType.hasFaces() || mType.hasMipmaps()) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 959 | throw new RSInvalidStateException("Resize only support for 1D allocations at this time."); |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 960 | } |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 961 | mRS.nAllocationResize1D(getID(mRS), dimX); |
| Jason Sams | d26297f | 2010-11-01 16:08:59 -0700 | [diff] [blame] | 962 | mRS.finish(); // Necessary because resize is fifoed and update is async. |
| Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 963 | |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 964 | int typeID = mRS.nAllocationGetType(getID(mRS)); |
| Jason Sams | 31a7e42 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 965 | mType = new Type(typeID, mRS); |
| 966 | mType.updateFromNative(); |
| Jason Sams | 452a766 | 2011-07-07 16:05:18 -0700 | [diff] [blame] | 967 | updateCacheInfo(mType); |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 968 | } |
| 969 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 970 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 971 | * Resize a 2D allocation. The contents of the allocation are |
| 972 | * preserved. If new elements are allocated objects are created |
| 973 | * with null contents and the new region is otherwise undefined. |
| 974 | * |
| 975 | * If the new region is smaller the references of any objects |
| 976 | * outside the new region will be released. |
| 977 | * |
| 978 | * A new type will be created with the new dimension. |
| 979 | * |
| 980 | * @hide |
| 981 | * @param dimX The new size of the allocation. |
| 982 | * @param dimY The new size of the allocation. |
| 983 | */ |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 984 | public void resize(int dimX, int dimY) { |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 985 | if ((mType.getZ() > 0) || mType.hasFaces() || mType.hasMipmaps()) { |
| 986 | throw new RSInvalidStateException( |
| 987 | "Resize only support for 2D allocations at this time."); |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 988 | } |
| 989 | if (mType.getY() == 0) { |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 990 | throw new RSInvalidStateException( |
| 991 | "Resize only support for 2D allocations at this time."); |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 992 | } |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 993 | mRS.nAllocationResize2D(getID(mRS), dimX, dimY); |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 994 | mRS.finish(); // Necessary because resize is fifoed and update is async. |
| 995 | |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 996 | int typeID = mRS.nAllocationGetType(getID(mRS)); |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 997 | mType = new Type(typeID, mRS); |
| 998 | mType.updateFromNative(); |
| 999 | updateCacheInfo(mType); |
| Jason Sams | 5edc608 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 1000 | } |
| Jason Sams | 40a29e8 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 1001 | |
| Jason Sams | bd1c3ad | 2009-08-03 16:03:08 -0700 | [diff] [blame] | 1002 | |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1003 | |
| 1004 | // creation |
| 1005 | |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 1006 | static BitmapFactory.Options mBitmapOptions = new BitmapFactory.Options(); |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1007 | static { |
| 1008 | mBitmapOptions.inScaled = false; |
| 1009 | } |
| 1010 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1011 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1012 | * |
| 1013 | * @param type renderscript type describing data layout |
| 1014 | * @param mips specifies desired mipmap behaviour for the |
| 1015 | * allocation |
| 1016 | * @param usage bit field specifying how the allocation is |
| 1017 | * utilized |
| 1018 | */ |
| 1019 | static public Allocation createTyped(RenderScript rs, Type type, MipmapControl mips, int usage) { |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 1020 | rs.validate(); |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1021 | if (type.getID(rs) == 0) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 1022 | throw new RSInvalidStateException("Bad Type"); |
| Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 1023 | } |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1024 | int id = rs.nAllocationCreateTyped(type.getID(rs), mips.mID, usage, 0); |
| Jason Sams | 857d0c7 | 2011-11-23 15:02:15 -0800 | [diff] [blame] | 1025 | if (id == 0) { |
| 1026 | throw new RSRuntimeException("Allocation creation failed."); |
| 1027 | } |
| 1028 | return new Allocation(id, rs, type, usage); |
| 1029 | } |
| 1030 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1031 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1032 | * Creates a renderscript allocation with the size specified by |
| 1033 | * the type and no mipmaps generated by default |
| 1034 | * |
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1035 | * @param rs Context to which the allocation will belong. |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1036 | * @param type renderscript type describing data layout |
| 1037 | * @param usage bit field specifying how the allocation is |
| 1038 | * utilized |
| 1039 | * |
| 1040 | * @return allocation |
| 1041 | */ |
| Jason Sams | e5d3712 | 2010-12-16 00:33:33 -0800 | [diff] [blame] | 1042 | static public Allocation createTyped(RenderScript rs, Type type, int usage) { |
| 1043 | return createTyped(rs, type, MipmapControl.MIPMAP_NONE, usage); |
| 1044 | } |
| 1045 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1046 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1047 | * Creates a renderscript allocation for use by the script with |
| 1048 | * the size specified by the type and no mipmaps generated by |
| 1049 | * default |
| 1050 | * |
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1051 | * @param rs Context to which the allocation will belong. |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1052 | * @param type renderscript type describing data layout |
| 1053 | * |
| 1054 | * @return allocation |
| 1055 | */ |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1056 | static public Allocation createTyped(RenderScript rs, Type type) { |
| Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 1057 | return createTyped(rs, type, MipmapControl.MIPMAP_NONE, USAGE_SCRIPT); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1058 | } |
| Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 1059 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1060 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1061 | * Creates a renderscript allocation with a specified number of |
| 1062 | * given elements |
| 1063 | * |
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1064 | * @param rs Context to which the allocation will belong. |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1065 | * @param e describes what each element of an allocation is |
| 1066 | * @param count specifies the number of element in the allocation |
| 1067 | * @param usage bit field specifying how the allocation is |
| 1068 | * utilized |
| 1069 | * |
| 1070 | * @return allocation |
| 1071 | */ |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1072 | static public Allocation createSized(RenderScript rs, Element e, |
| 1073 | int count, int usage) { |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 1074 | rs.validate(); |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 1075 | Type.Builder b = new Type.Builder(rs, e); |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1076 | b.setX(count); |
| Jason Sams | 768bc02 | 2009-09-21 19:41:04 -0700 | [diff] [blame] | 1077 | Type t = b.create(); |
| 1078 | |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1079 | int id = rs.nAllocationCreateTyped(t.getID(rs), MipmapControl.MIPMAP_NONE.mID, usage, 0); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1080 | if (id == 0) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 1081 | throw new RSRuntimeException("Allocation creation failed."); |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1082 | } |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1083 | return new Allocation(id, rs, t, usage); |
| 1084 | } |
| 1085 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1086 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1087 | * Creates a renderscript allocation with a specified number of |
| 1088 | * given elements |
| 1089 | * |
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1090 | * @param rs Context to which the allocation will belong. |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1091 | * @param e describes what each element of an allocation is |
| 1092 | * @param count specifies the number of element in the allocation |
| 1093 | * |
| 1094 | * @return allocation |
| 1095 | */ |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1096 | static public Allocation createSized(RenderScript rs, Element e, int count) { |
| Jason Sams | d4b23b5 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 1097 | return createSized(rs, e, count, USAGE_SCRIPT); |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1098 | } |
| 1099 | |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 1100 | static Element elementFromBitmap(RenderScript rs, Bitmap b) { |
| Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 1101 | final Bitmap.Config bc = b.getConfig(); |
| 1102 | if (bc == Bitmap.Config.ALPHA_8) { |
| 1103 | return Element.A_8(rs); |
| 1104 | } |
| 1105 | if (bc == Bitmap.Config.ARGB_4444) { |
| 1106 | return Element.RGBA_4444(rs); |
| 1107 | } |
| 1108 | if (bc == Bitmap.Config.ARGB_8888) { |
| 1109 | return Element.RGBA_8888(rs); |
| 1110 | } |
| 1111 | if (bc == Bitmap.Config.RGB_565) { |
| 1112 | return Element.RGB_565(rs); |
| 1113 | } |
| Jeff Sharkey | 4bd1a3d | 2010-11-16 13:46:34 -0800 | [diff] [blame] | 1114 | throw new RSInvalidStateException("Bad bitmap type: " + bc); |
| Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 1115 | } |
| 1116 | |
| Jason Sams | 49a05d7 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 1117 | static Type typeFromBitmap(RenderScript rs, Bitmap b, |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1118 | MipmapControl mip) { |
| Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 1119 | Element e = elementFromBitmap(rs, b); |
| 1120 | Type.Builder tb = new Type.Builder(rs, e); |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1121 | tb.setX(b.getWidth()); |
| 1122 | tb.setY(b.getHeight()); |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1123 | tb.setMipmaps(mip == MipmapControl.MIPMAP_FULL); |
| Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 1124 | return tb.create(); |
| 1125 | } |
| 1126 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1127 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1128 | * Creates a renderscript allocation from a bitmap |
| 1129 | * |
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1130 | * @param rs Context to which the allocation will belong. |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1131 | * @param b bitmap source for the allocation data |
| 1132 | * @param mips specifies desired mipmap behaviour for the |
| 1133 | * allocation |
| 1134 | * @param usage bit field specifying how the allocation is |
| 1135 | * utilized |
| 1136 | * |
| 1137 | * @return renderscript allocation containing bitmap data |
| 1138 | * |
| 1139 | */ |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1140 | static public Allocation createFromBitmap(RenderScript rs, Bitmap b, |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1141 | MipmapControl mips, |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1142 | int usage) { |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 1143 | rs.validate(); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1144 | Type t = typeFromBitmap(rs, b, mips); |
| Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 1145 | |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1146 | int id = rs.nAllocationCreateFromBitmap(t.getID(rs), mips.mID, b, usage); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1147 | if (id == 0) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 1148 | throw new RSRuntimeException("Load failed."); |
| Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 1149 | } |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1150 | return new Allocation(id, rs, t, usage); |
| 1151 | } |
| 1152 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1153 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 1154 | * |
| 1155 | * |
| 1156 | * @hide |
| 1157 | * |
| 1158 | */ |
| 1159 | public SurfaceTexture getSurfaceTexture() { |
| Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 1160 | if ((mUsage & USAGE_IO_INPUT) == 0) { |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 1161 | throw new RSInvalidStateException("Allocation is not a surface texture."); |
| 1162 | } |
| 1163 | |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1164 | int id = mRS.nAllocationGetSurfaceTextureID(getID(mRS)); |
| Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 1165 | SurfaceTexture st = new SurfaceTexture(id); |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1166 | mRS.nAllocationGetSurfaceTextureID2(getID(mRS), st); |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 1167 | |
| Jason Sams | fe1d5ff | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 1168 | return st; |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 1169 | } |
| 1170 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1171 | /** @hide renderscript is deprecated in J |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 1172 | * For allocations used with io operations, returns the handle |
| 1173 | * onto a raw buffer that is being managed by the screen |
| 1174 | * compositor. |
| Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 1175 | * |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 1176 | * @return Surface object associated with allocation |
| Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 1177 | * |
| 1178 | */ |
| 1179 | public Surface getSurface() { |
| 1180 | return new Surface(getSurfaceTexture()); |
| 1181 | } |
| 1182 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1183 | /** @hide renderscript is deprecated in J |
| Alex Sakhartchouk | 918e840 | 2012-04-11 14:04:23 -0700 | [diff] [blame] | 1184 | * Associate a surface for io output with this allocation |
| 1185 | * |
| 1186 | * @param sur Surface to associate with allocation |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1187 | */ |
| Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 1188 | public void setSurface(Surface sur) { |
| 1189 | mRS.validate(); |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1190 | if ((mUsage & USAGE_IO_OUTPUT) == 0) { |
| 1191 | throw new RSInvalidStateException("Allocation is not USAGE_IO_OUTPUT."); |
| 1192 | } |
| 1193 | |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1194 | mRS.nAllocationSetSurface(getID(mRS), sur); |
| Jason Sams | 163766c | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 1195 | } |
| 1196 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1197 | /** @deprecated renderscript is deprecated in J |
| Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 1198 | * @hide |
| 1199 | */ |
| 1200 | public void setSurfaceTexture(SurfaceTexture st) { |
| 1201 | mRS.validate(); |
| 1202 | if ((mUsage & USAGE_IO_OUTPUT) == 0) { |
| 1203 | throw new RSInvalidStateException("Allocation is not USAGE_IO_OUTPUT."); |
| 1204 | } |
| 1205 | |
| 1206 | Surface s = new Surface(st); |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1207 | mRS.nAllocationSetSurface(getID(mRS), s); |
| Jason Sams | fb9aa9f | 2012-03-28 15:30:07 -0700 | [diff] [blame] | 1208 | } |
| Jason Sams | 615e7ce | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 1209 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1210 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1211 | * Creates a non-mipmapped renderscript allocation to use as a |
| 1212 | * graphics texture |
| 1213 | * |
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1214 | * @param rs Context to which the allocation will belong. |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1215 | * @param b bitmap source for the allocation data |
| 1216 | * |
| 1217 | * @return renderscript allocation containing bitmap data |
| 1218 | * |
| 1219 | */ |
| Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 1220 | static public Allocation createFromBitmap(RenderScript rs, Bitmap b) { |
| 1221 | return createFromBitmap(rs, b, MipmapControl.MIPMAP_NONE, |
| 1222 | USAGE_GRAPHICS_TEXTURE); |
| Jason Sams | 8a64743 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 1223 | } |
| 1224 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1225 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1226 | * Creates a cubemap allocation from a bitmap containing the |
| 1227 | * horizontal list of cube faces. Each individual face must be |
| 1228 | * the same size and power of 2 |
| 1229 | * |
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1230 | * @param rs Context to which the allocation will belong. |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1231 | * @param b bitmap with cubemap faces layed out in the following |
| 1232 | * format: right, left, top, bottom, front, back |
| 1233 | * @param mips specifies desired mipmap behaviour for the cubemap |
| 1234 | * @param usage bit field specifying how the cubemap is utilized |
| 1235 | * |
| 1236 | * @return allocation containing cubemap data |
| 1237 | * |
| 1238 | */ |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1239 | static public Allocation createCubemapFromBitmap(RenderScript rs, Bitmap b, |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1240 | MipmapControl mips, |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1241 | int usage) { |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1242 | rs.validate(); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1243 | |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1244 | int height = b.getHeight(); |
| 1245 | int width = b.getWidth(); |
| 1246 | |
| Alex Sakhartchouk | fe852e2 | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 1247 | if (width % 6 != 0) { |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1248 | throw new RSIllegalArgumentException("Cubemap height must be multiple of 6"); |
| 1249 | } |
| Alex Sakhartchouk | fe852e2 | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 1250 | if (width / 6 != height) { |
| Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 1251 | throw new RSIllegalArgumentException("Only square cube map faces supported"); |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1252 | } |
| Alex Sakhartchouk | fe852e2 | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 1253 | boolean isPow2 = (height & (height - 1)) == 0; |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1254 | if (!isPow2) { |
| 1255 | throw new RSIllegalArgumentException("Only power of 2 cube faces supported"); |
| 1256 | } |
| 1257 | |
| 1258 | Element e = elementFromBitmap(rs, b); |
| 1259 | Type.Builder tb = new Type.Builder(rs, e); |
| Alex Sakhartchouk | fe852e2 | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 1260 | tb.setX(height); |
| 1261 | tb.setY(height); |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1262 | tb.setFaces(true); |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1263 | tb.setMipmaps(mips == MipmapControl.MIPMAP_FULL); |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1264 | Type t = tb.create(); |
| 1265 | |
| Jason Sams | e07694b | 2012-04-03 15:36:36 -0700 | [diff] [blame] | 1266 | int id = rs.nAllocationCubeCreateFromBitmap(t.getID(rs), mips.mID, b, usage); |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1267 | if(id == 0) { |
| 1268 | throw new RSRuntimeException("Load failed for bitmap " + b + " element " + e); |
| 1269 | } |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1270 | return new Allocation(id, rs, t, usage); |
| Alex Sakhartchouk | 67f2e44 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 1271 | } |
| 1272 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1273 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1274 | * Creates a non-mipmapped cubemap allocation for use as a |
| 1275 | * graphics texture from a bitmap containing the horizontal list |
| 1276 | * of cube faces. Each individual face must be the same size and |
| 1277 | * power of 2 |
| 1278 | * |
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1279 | * @param rs Context to which the allocation will belong. |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1280 | * @param b bitmap with cubemap faces layed out in the following |
| 1281 | * format: right, left, top, bottom, front, back |
| 1282 | * |
| 1283 | * @return allocation containing cubemap data |
| 1284 | * |
| 1285 | */ |
| Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 1286 | static public Allocation createCubemapFromBitmap(RenderScript rs, |
| 1287 | Bitmap b) { |
| Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 1288 | return createCubemapFromBitmap(rs, b, MipmapControl.MIPMAP_NONE, |
| Alex Sakhartchouk | fe852e2 | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 1289 | USAGE_GRAPHICS_TEXTURE); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1290 | } |
| 1291 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1292 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1293 | * Creates a cubemap allocation from 6 bitmaps containing |
| 1294 | * the cube faces. All the faces must be the same size and |
| 1295 | * power of 2 |
| 1296 | * |
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1297 | * @param rs Context to which the allocation will belong. |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1298 | * @param xpos cubemap face in the positive x direction |
| 1299 | * @param xneg cubemap face in the negative x direction |
| 1300 | * @param ypos cubemap face in the positive y direction |
| 1301 | * @param yneg cubemap face in the negative y direction |
| 1302 | * @param zpos cubemap face in the positive z direction |
| 1303 | * @param zneg cubemap face in the negative z direction |
| 1304 | * @param mips specifies desired mipmap behaviour for the cubemap |
| 1305 | * @param usage bit field specifying how the cubemap is utilized |
| 1306 | * |
| 1307 | * @return allocation containing cubemap data |
| 1308 | * |
| 1309 | */ |
| Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 1310 | static public Allocation createCubemapFromCubeFaces(RenderScript rs, |
| 1311 | Bitmap xpos, |
| 1312 | Bitmap xneg, |
| 1313 | Bitmap ypos, |
| 1314 | Bitmap yneg, |
| 1315 | Bitmap zpos, |
| 1316 | Bitmap zneg, |
| 1317 | MipmapControl mips, |
| 1318 | int usage) { |
| 1319 | int height = xpos.getHeight(); |
| 1320 | if (xpos.getWidth() != height || |
| 1321 | xneg.getWidth() != height || xneg.getHeight() != height || |
| 1322 | ypos.getWidth() != height || ypos.getHeight() != height || |
| 1323 | yneg.getWidth() != height || yneg.getHeight() != height || |
| 1324 | zpos.getWidth() != height || zpos.getHeight() != height || |
| 1325 | zneg.getWidth() != height || zneg.getHeight() != height) { |
| 1326 | throw new RSIllegalArgumentException("Only square cube map faces supported"); |
| 1327 | } |
| 1328 | boolean isPow2 = (height & (height - 1)) == 0; |
| 1329 | if (!isPow2) { |
| 1330 | throw new RSIllegalArgumentException("Only power of 2 cube faces supported"); |
| 1331 | } |
| 1332 | |
| 1333 | Element e = elementFromBitmap(rs, xpos); |
| 1334 | Type.Builder tb = new Type.Builder(rs, e); |
| 1335 | tb.setX(height); |
| 1336 | tb.setY(height); |
| 1337 | tb.setFaces(true); |
| 1338 | tb.setMipmaps(mips == MipmapControl.MIPMAP_FULL); |
| 1339 | Type t = tb.create(); |
| 1340 | Allocation cubemap = Allocation.createTyped(rs, t, mips, usage); |
| 1341 | |
| 1342 | AllocationAdapter adapter = AllocationAdapter.create2D(rs, cubemap); |
| Stephen Hines | 20fbd01 | 2011-06-16 17:44:53 -0700 | [diff] [blame] | 1343 | adapter.setFace(Type.CubemapFace.POSITIVE_X); |
| Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 1344 | adapter.copyFrom(xpos); |
| 1345 | adapter.setFace(Type.CubemapFace.NEGATIVE_X); |
| 1346 | adapter.copyFrom(xneg); |
| Stephen Hines | 20fbd01 | 2011-06-16 17:44:53 -0700 | [diff] [blame] | 1347 | adapter.setFace(Type.CubemapFace.POSITIVE_Y); |
| Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 1348 | adapter.copyFrom(ypos); |
| 1349 | adapter.setFace(Type.CubemapFace.NEGATIVE_Y); |
| 1350 | adapter.copyFrom(yneg); |
| Stephen Hines | 20fbd01 | 2011-06-16 17:44:53 -0700 | [diff] [blame] | 1351 | adapter.setFace(Type.CubemapFace.POSITIVE_Z); |
| Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 1352 | adapter.copyFrom(zpos); |
| 1353 | adapter.setFace(Type.CubemapFace.NEGATIVE_Z); |
| 1354 | adapter.copyFrom(zneg); |
| 1355 | |
| 1356 | return cubemap; |
| 1357 | } |
| 1358 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1359 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1360 | * Creates a non-mipmapped cubemap allocation for use as a |
| 1361 | * graphics texture from 6 bitmaps containing |
| 1362 | * the cube faces. All the faces must be the same size and |
| 1363 | * power of 2 |
| 1364 | * |
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1365 | * @param rs Context to which the allocation will belong. |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1366 | * @param xpos cubemap face in the positive x direction |
| 1367 | * @param xneg cubemap face in the negative x direction |
| 1368 | * @param ypos cubemap face in the positive y direction |
| 1369 | * @param yneg cubemap face in the negative y direction |
| 1370 | * @param zpos cubemap face in the positive z direction |
| 1371 | * @param zneg cubemap face in the negative z direction |
| 1372 | * |
| 1373 | * @return allocation containing cubemap data |
| 1374 | * |
| 1375 | */ |
| Alex Sakhartchouk | dcc2319 | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 1376 | static public Allocation createCubemapFromCubeFaces(RenderScript rs, |
| 1377 | Bitmap xpos, |
| 1378 | Bitmap xneg, |
| 1379 | Bitmap ypos, |
| 1380 | Bitmap yneg, |
| 1381 | Bitmap zpos, |
| 1382 | Bitmap zneg) { |
| 1383 | return createCubemapFromCubeFaces(rs, xpos, xneg, ypos, yneg, |
| 1384 | zpos, zneg, MipmapControl.MIPMAP_NONE, |
| 1385 | USAGE_GRAPHICS_TEXTURE); |
| 1386 | } |
| 1387 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1388 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1389 | * Creates a renderscript allocation from the bitmap referenced |
| 1390 | * by resource id |
| 1391 | * |
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1392 | * @param rs Context to which the allocation will belong. |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1393 | * @param res application resources |
| 1394 | * @param id resource id to load the data from |
| 1395 | * @param mips specifies desired mipmap behaviour for the |
| 1396 | * allocation |
| 1397 | * @param usage bit field specifying how the allocation is |
| 1398 | * utilized |
| 1399 | * |
| 1400 | * @return renderscript allocation containing resource data |
| 1401 | * |
| 1402 | */ |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1403 | static public Allocation createFromBitmapResource(RenderScript rs, |
| 1404 | Resources res, |
| 1405 | int id, |
| Jason Sams | 4ef6650 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 1406 | MipmapControl mips, |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1407 | int usage) { |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1408 | |
| Jason Sams | 771bebb | 2009-12-07 12:40:12 -0800 | [diff] [blame] | 1409 | rs.validate(); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1410 | Bitmap b = BitmapFactory.decodeResource(res, id); |
| 1411 | Allocation alloc = createFromBitmap(rs, b, mips, usage); |
| 1412 | b.recycle(); |
| 1413 | return alloc; |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1414 | } |
| 1415 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1416 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1417 | * Creates a non-mipmapped renderscript allocation to use as a |
| 1418 | * graphics texture from the bitmap referenced by resource id |
| 1419 | * |
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1420 | * @param rs Context to which the allocation will belong. |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1421 | * @param res application resources |
| 1422 | * @param id resource id to load the data from |
| 1423 | * |
| 1424 | * @return renderscript allocation containing resource data |
| 1425 | * |
| 1426 | */ |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1427 | static public Allocation createFromBitmapResource(RenderScript rs, |
| 1428 | Resources res, |
| Jason Sams | 6d8eb26 | 2010-12-15 01:41:00 -0800 | [diff] [blame] | 1429 | int id) { |
| 1430 | return createFromBitmapResource(rs, res, id, |
| 1431 | MipmapControl.MIPMAP_NONE, |
| 1432 | USAGE_GRAPHICS_TEXTURE); |
| 1433 | } |
| 1434 | |
| Alex Sakhartchouk | a0c2eb2 | 2012-04-19 16:30:58 -0700 | [diff] [blame^] | 1435 | /** @deprecated renderscript is deprecated in J |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1436 | * Creates a renderscript allocation containing string data |
| 1437 | * encoded in UTF-8 format |
| 1438 | * |
| Alex Sakhartchouk | f5c876e | 2011-01-13 14:53:43 -0800 | [diff] [blame] | 1439 | * @param rs Context to which the allocation will belong. |
| Alex Sakhartchouk | 623c54d | 2011-01-12 17:32:36 -0800 | [diff] [blame] | 1440 | * @param str string to create the allocation from |
| 1441 | * @param usage bit field specifying how the allocaiton is |
| 1442 | * utilized |
| 1443 | * |
| 1444 | */ |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1445 | static public Allocation createFromString(RenderScript rs, |
| 1446 | String str, |
| 1447 | int usage) { |
| 1448 | rs.validate(); |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1449 | byte[] allocArray = null; |
| 1450 | try { |
| 1451 | allocArray = str.getBytes("UTF-8"); |
| Jason Sams | 5476b45 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 1452 | Allocation alloc = Allocation.createSized(rs, Element.U8(rs), allocArray.length, usage); |
| Jason Sams | bf6ef8d7 | 2010-12-06 15:59:59 -0800 | [diff] [blame] | 1453 | alloc.copyFrom(allocArray); |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1454 | return alloc; |
| 1455 | } |
| 1456 | catch (Exception e) { |
| Jason Sams | 06d69de | 2010-11-09 17:11:40 -0800 | [diff] [blame] | 1457 | throw new RSRuntimeException("Could not convert string to utf-8."); |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1458 | } |
| Alex Sakhartchouk | 9b949fc | 2010-06-24 17:15:34 -0700 | [diff] [blame] | 1459 | } |
| Jason Sams | b8c5a84 | 2009-07-31 20:40:47 -0700 | [diff] [blame] | 1460 | } |
| 1461 | |
| 1462 | |