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