Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 1 | /* |
Jason Sams | 3522f40 | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 2 | * Copyright (C) 2012 The Android Open Source Project |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [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 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 17 | #include "RenderScript.h" |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 18 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 19 | using namespace android; |
Tim Murray | 9eb7f4b | 2012-11-16 14:02:18 -0800 | [diff] [blame] | 20 | using namespace RSC; |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 21 | |
| 22 | void * Allocation::getIDSafe() const { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 23 | return getID(); |
| 24 | } |
| 25 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 26 | void Allocation::updateCacheInfo(sp<const Type> t) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 27 | mCurrentDimX = t->getX(); |
| 28 | mCurrentDimY = t->getY(); |
| 29 | mCurrentDimZ = t->getZ(); |
| 30 | mCurrentCount = mCurrentDimX; |
| 31 | if (mCurrentDimY > 1) { |
| 32 | mCurrentCount *= mCurrentDimY; |
| 33 | } |
| 34 | if (mCurrentDimZ > 1) { |
| 35 | mCurrentCount *= mCurrentDimZ; |
| 36 | } |
| 37 | } |
| 38 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 39 | Allocation::Allocation(void *id, sp<RS> rs, sp<const Type> t, uint32_t usage) : |
Tim Murray | baca6c3 | 2012-11-14 16:51:46 -0800 | [diff] [blame] | 40 | BaseObj(id, rs), mSelectedY(0), mSelectedZ(0), mSelectedLOD(0), |
| 41 | mSelectedFace(RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X) { |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 42 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 43 | if ((usage & ~(RS_ALLOCATION_USAGE_SCRIPT | |
| 44 | RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE | |
| 45 | RS_ALLOCATION_USAGE_GRAPHICS_VERTEX | |
| 46 | RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS | |
| 47 | RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 48 | RS_ALLOCATION_USAGE_IO_INPUT | |
Tim Murray | 96267c2 | 2013-02-12 11:25:12 -0800 | [diff] [blame^] | 49 | RS_ALLOCATION_USAGE_IO_OUTPUT | |
| 50 | RS_ALLOCATION_USAGE_SHARED)) != 0) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 51 | ALOGE("Unknown usage specified."); |
| 52 | } |
| 53 | |
Jason Sams | 3522f40 | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 54 | if ((usage & RS_ALLOCATION_USAGE_IO_INPUT) != 0) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 55 | mWriteAllowed = false; |
Jason Sams | 3522f40 | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 56 | if ((usage & ~(RS_ALLOCATION_USAGE_IO_INPUT | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 57 | RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE | |
| 58 | RS_ALLOCATION_USAGE_SCRIPT)) != 0) { |
| 59 | ALOGE("Invalid usage combination."); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | mType = t; |
| 64 | mUsage = usage; |
| 65 | |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 66 | if (t.get() != NULL) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 67 | updateCacheInfo(t); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | void Allocation::validateIsInt32() { |
| 72 | RsDataType dt = mType->getElement()->getDataType(); |
| 73 | if ((dt == RS_TYPE_SIGNED_32) || (dt == RS_TYPE_UNSIGNED_32)) { |
| 74 | return; |
| 75 | } |
| 76 | ALOGE("32 bit integer source does not match allocation type %i", dt); |
| 77 | } |
| 78 | |
| 79 | void Allocation::validateIsInt16() { |
| 80 | RsDataType dt = mType->getElement()->getDataType(); |
| 81 | if ((dt == RS_TYPE_SIGNED_16) || (dt == RS_TYPE_UNSIGNED_16)) { |
| 82 | return; |
| 83 | } |
| 84 | ALOGE("16 bit integer source does not match allocation type %i", dt); |
| 85 | } |
| 86 | |
| 87 | void Allocation::validateIsInt8() { |
| 88 | RsDataType dt = mType->getElement()->getDataType(); |
| 89 | if ((dt == RS_TYPE_SIGNED_8) || (dt == RS_TYPE_UNSIGNED_8)) { |
| 90 | return; |
| 91 | } |
| 92 | ALOGE("8 bit integer source does not match allocation type %i", dt); |
| 93 | } |
| 94 | |
| 95 | void Allocation::validateIsFloat32() { |
| 96 | RsDataType dt = mType->getElement()->getDataType(); |
| 97 | if (dt == RS_TYPE_FLOAT_32) { |
| 98 | return; |
| 99 | } |
| 100 | ALOGE("32 bit float source does not match allocation type %i", dt); |
| 101 | } |
| 102 | |
| 103 | void Allocation::validateIsObject() { |
| 104 | RsDataType dt = mType->getElement()->getDataType(); |
| 105 | if ((dt == RS_TYPE_ELEMENT) || |
| 106 | (dt == RS_TYPE_TYPE) || |
| 107 | (dt == RS_TYPE_ALLOCATION) || |
| 108 | (dt == RS_TYPE_SAMPLER) || |
| 109 | (dt == RS_TYPE_SCRIPT) || |
| 110 | (dt == RS_TYPE_MESH) || |
| 111 | (dt == RS_TYPE_PROGRAM_FRAGMENT) || |
| 112 | (dt == RS_TYPE_PROGRAM_VERTEX) || |
| 113 | (dt == RS_TYPE_PROGRAM_RASTER) || |
| 114 | (dt == RS_TYPE_PROGRAM_STORE)) { |
| 115 | return; |
| 116 | } |
| 117 | ALOGE("Object source does not match allocation type %i", dt); |
| 118 | } |
| 119 | |
| 120 | void Allocation::updateFromNative() { |
| 121 | BaseObj::updateFromNative(); |
| 122 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 123 | const void *typeID = rsaAllocationGetType(mRS->getContext(), getID()); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 124 | if(typeID != NULL) { |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 125 | sp<const Type> old = mType; |
| 126 | sp<Type> t = new Type((void *)typeID, mRS); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 127 | t->updateFromNative(); |
| 128 | updateCacheInfo(t); |
| 129 | mType = t; |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 130 | } |
| 131 | } |
| 132 | |
| 133 | void Allocation::syncAll(RsAllocationUsageType srcLocation) { |
| 134 | switch (srcLocation) { |
| 135 | case RS_ALLOCATION_USAGE_SCRIPT: |
| 136 | case RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS: |
| 137 | case RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE: |
| 138 | case RS_ALLOCATION_USAGE_GRAPHICS_VERTEX: |
| 139 | break; |
| 140 | default: |
| 141 | ALOGE("Source must be exactly one usage type."); |
| 142 | } |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 143 | rsAllocationSyncAll(mRS->getContext(), getIDSafe(), srcLocation); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | void Allocation::ioSendOutput() { |
| 147 | if ((mUsage & RS_ALLOCATION_USAGE_IO_OUTPUT) == 0) { |
| 148 | ALOGE("Can only send buffer if IO_OUTPUT usage specified."); |
| 149 | } |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 150 | rsAllocationIoSend(mRS->getContext(), getID()); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | void Allocation::ioGetInput() { |
| 154 | if ((mUsage & RS_ALLOCATION_USAGE_IO_INPUT) == 0) { |
| 155 | ALOGE("Can only send buffer if IO_OUTPUT usage specified."); |
| 156 | } |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 157 | rsAllocationIoReceive(mRS->getContext(), getID()); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 158 | } |
| 159 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 160 | void Allocation::generateMipmaps() { |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 161 | rsAllocationGenerateMipmaps(mRS->getContext(), getID()); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 162 | } |
| 163 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 164 | void Allocation::copy1DRangeFrom(uint32_t off, size_t count, const void *data) { |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 165 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 166 | if(count < 1) { |
| 167 | ALOGE("Count must be >= 1."); |
| 168 | return; |
| 169 | } |
| 170 | if((off + count) > mCurrentCount) { |
| 171 | ALOGE("Overflow, Available count %zu, got %zu at offset %zu.", mCurrentCount, count, off); |
| 172 | return; |
| 173 | } |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 174 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 175 | rsAllocation1DData(mRS->getContext(), getIDSafe(), off, mSelectedLOD, count, data, |
| 176 | count * mType->getElement()->getSizeBytes()); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 177 | } |
| 178 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 179 | void Allocation::copy1DRangeTo(uint32_t off, size_t count, void *data) { |
Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 180 | if(count < 1) { |
| 181 | ALOGE("Count must be >= 1."); |
| 182 | return; |
| 183 | } |
| 184 | if((off + count) > mCurrentCount) { |
| 185 | ALOGE("Overflow, Available count %zu, got %zu at offset %zu.", mCurrentCount, count, off); |
| 186 | return; |
| 187 | } |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 188 | |
| 189 | rsAllocation1DRead(mRS->getContext(), getIDSafe(), off, mSelectedLOD, count, data, |
| 190 | count * mType->getElement()->getSizeBytes()); |
Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 191 | } |
| 192 | |
Tim Murray | a4cbc2b | 2012-11-14 17:18:08 -0800 | [diff] [blame] | 193 | void Allocation::copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, |
| 194 | uint32_t dataOff) { |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 195 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 196 | rsAllocationCopy2DRange(mRS->getContext(), getIDSafe(), off, 0, |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 197 | mSelectedLOD, mSelectedFace, |
| 198 | count, 1, data->getIDSafe(), dataOff, 0, |
| 199 | data->mSelectedLOD, data->mSelectedFace); |
| 200 | } |
| 201 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 202 | void Allocation::copy1DFrom(const void* data) { |
| 203 | copy1DRangeFrom(0, mCurrentCount, data); |
| 204 | } |
| 205 | |
| 206 | void Allocation::copy1DTo(void* data) { |
| 207 | copy1DRangeTo(0, mCurrentCount, data); |
| 208 | } |
| 209 | |
| 210 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 211 | void Allocation::validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h) { |
| 212 | if (mAdaptedAllocation != NULL) { |
| 213 | |
| 214 | } else { |
| 215 | if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY)) { |
| 216 | ALOGE("Updated region larger than allocation."); |
| 217 | } |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | void Allocation::copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 222 | const void *data) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 223 | validate2DRange(xoff, yoff, w, h); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 224 | rsAllocation2DData(mRS->getContext(), getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace, |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 225 | w, h, data, w * h * mType->getElement()->getSizeBytes(), w * mType->getElement()->getSizeBytes()); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | void Allocation::copy2DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 229 | sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 230 | validate2DRange(xoff, yoff, w, h); |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 231 | rsAllocationCopy2DRange(mRS->getContext(), getIDSafe(), xoff, yoff, |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 232 | mSelectedLOD, mSelectedFace, |
| 233 | w, h, data->getIDSafe(), dataXoff, dataYoff, |
| 234 | data->mSelectedLOD, data->mSelectedFace); |
| 235 | } |
| 236 | |
Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 237 | void Allocation::copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 238 | void* data) { |
| 239 | validate2DRange(xoff, yoff, w, h); |
| 240 | rsAllocation2DRead(mRS->getContext(), getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace, |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 241 | w, h, data, w * h * mType->getElement()->getSizeBytes(), w * mType->getElement()->getSizeBytes()); |
Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 244 | void Allocation::copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 245 | const void *data, size_t stride) { |
| 246 | validate2DRange(xoff, yoff, w, h); |
| 247 | rsAllocation2DData(mRS->getContext(), getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace, |
| 248 | w, h, data, w * h * mType->getElement()->getSizeBytes(), stride); |
| 249 | } |
| 250 | |
| 251 | void Allocation::copy2DStridedFrom(const void* data, size_t stride) { |
| 252 | copy2DStridedFrom(0, 0, mCurrentDimX, mCurrentDimY, data, stride); |
| 253 | } |
| 254 | |
| 255 | void Allocation::copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 256 | void *data, size_t stride) { |
| 257 | validate2DRange(xoff, yoff, w, h); |
| 258 | rsAllocation2DRead(mRS->getContext(), getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace, |
| 259 | w, h, data, w * h * mType->getElement()->getSizeBytes(), stride); |
| 260 | } |
| 261 | |
| 262 | void Allocation::copy2DStridedTo(void* data, size_t stride) { |
| 263 | copy2DStridedTo(0, 0, mCurrentDimX, mCurrentDimY, data, stride); |
| 264 | } |
| 265 | |
| 266 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 267 | /* |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 268 | void resize(int dimX) { |
| 269 | if ((mType.getY() > 0)|| (mType.getZ() > 0) || mType.hasFaces() || mType.hasMipmaps()) { |
| 270 | throw new RSInvalidStateException("Resize only support for 1D allocations at this time."); |
| 271 | } |
| 272 | mRS.nAllocationResize1D(getID(), dimX); |
| 273 | mRS.finish(); // Necessary because resize is fifoed and update is async. |
| 274 | |
| 275 | int typeID = mRS.nAllocationGetType(getID()); |
| 276 | mType = new Type(typeID, mRS); |
| 277 | mType.updateFromNative(); |
| 278 | updateCacheInfo(mType); |
| 279 | } |
| 280 | |
| 281 | void resize(int dimX, int dimY) { |
| 282 | if ((mType.getZ() > 0) || mType.hasFaces() || mType.hasMipmaps()) { |
| 283 | throw new RSInvalidStateException( |
| 284 | "Resize only support for 2D allocations at this time."); |
| 285 | } |
| 286 | if (mType.getY() == 0) { |
| 287 | throw new RSInvalidStateException( |
| 288 | "Resize only support for 2D allocations at this time."); |
| 289 | } |
| 290 | mRS.nAllocationResize2D(getID(), dimX, dimY); |
| 291 | mRS.finish(); // Necessary because resize is fifoed and update is async. |
| 292 | |
| 293 | int typeID = mRS.nAllocationGetType(getID()); |
| 294 | mType = new Type(typeID, mRS); |
| 295 | mType.updateFromNative(); |
| 296 | updateCacheInfo(mType); |
| 297 | } |
| 298 | */ |
| 299 | |
| 300 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 301 | android::sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type, |
Tim Murray | 684726c | 2012-11-14 11:57:42 -0800 | [diff] [blame] | 302 | RsAllocationMipmapControl mips, uint32_t usage) { |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 303 | void *id = rsAllocationCreateTyped(rs->getContext(), type->getID(), mips, usage, 0); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 304 | if (id == 0) { |
| 305 | ALOGE("Allocation creation failed."); |
| 306 | return NULL; |
| 307 | } |
| 308 | return new Allocation(id, rs, type, usage); |
| 309 | } |
| 310 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 311 | android::sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type, |
Tim Murray | 684726c | 2012-11-14 11:57:42 -0800 | [diff] [blame] | 312 | RsAllocationMipmapControl mips, uint32_t usage, |
| 313 | void *pointer) { |
| 314 | void *id = rsAllocationCreateTyped(rs->getContext(), type->getID(), mips, usage, |
| 315 | (uint32_t)pointer); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 316 | if (id == 0) { |
| 317 | ALOGE("Allocation creation failed."); |
| 318 | } |
| 319 | return new Allocation(id, rs, type, usage); |
| 320 | } |
| 321 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 322 | android::sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type, |
Tim Murray | 684726c | 2012-11-14 11:57:42 -0800 | [diff] [blame] | 323 | uint32_t usage) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 324 | return createTyped(rs, type, RS_ALLOCATION_MIPMAP_NONE, usage); |
| 325 | } |
| 326 | |
Tim Murray | 84bf2b8 | 2012-10-31 16:03:16 -0700 | [diff] [blame] | 327 | android::sp<Allocation> Allocation::createSized(sp<RS> rs, sp<const Element> e, |
Tim Murray | 684726c | 2012-11-14 11:57:42 -0800 | [diff] [blame] | 328 | size_t count, uint32_t usage) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 329 | Type::Builder b(rs, e); |
| 330 | b.setX(count); |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 331 | sp<const Type> t = b.create(); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 332 | |
Tim Murray | 684726c | 2012-11-14 11:57:42 -0800 | [diff] [blame] | 333 | return createTyped(rs, t, usage); |
| 334 | } |
| 335 | |
| 336 | android::sp<Allocation> Allocation::createSized2D(sp<RS> rs, sp<const Element> e, |
| 337 | size_t x, size_t y, uint32_t usage) { |
| 338 | Type::Builder b(rs, e); |
| 339 | b.setX(x); |
| 340 | b.setY(y); |
| 341 | sp<const Type> t = b.create(); |
| 342 | |
| 343 | return createTyped(rs, t, usage); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 344 | } |