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 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 66 | if (t != NULL) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 67 | updateCacheInfo(t); |
| 68 | } |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 69 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 72 | |
| 73 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 74 | void Allocation::validateIsInt32() { |
| 75 | RsDataType dt = mType->getElement()->getDataType(); |
| 76 | if ((dt == RS_TYPE_SIGNED_32) || (dt == RS_TYPE_UNSIGNED_32)) { |
| 77 | return; |
| 78 | } |
| 79 | ALOGE("32 bit integer source does not match allocation type %i", dt); |
| 80 | } |
| 81 | |
| 82 | void Allocation::validateIsInt16() { |
| 83 | RsDataType dt = mType->getElement()->getDataType(); |
| 84 | if ((dt == RS_TYPE_SIGNED_16) || (dt == RS_TYPE_UNSIGNED_16)) { |
| 85 | return; |
| 86 | } |
| 87 | ALOGE("16 bit integer source does not match allocation type %i", dt); |
| 88 | } |
| 89 | |
| 90 | void Allocation::validateIsInt8() { |
| 91 | RsDataType dt = mType->getElement()->getDataType(); |
| 92 | if ((dt == RS_TYPE_SIGNED_8) || (dt == RS_TYPE_UNSIGNED_8)) { |
| 93 | return; |
| 94 | } |
| 95 | ALOGE("8 bit integer source does not match allocation type %i", dt); |
| 96 | } |
| 97 | |
| 98 | void Allocation::validateIsFloat32() { |
| 99 | RsDataType dt = mType->getElement()->getDataType(); |
| 100 | if (dt == RS_TYPE_FLOAT_32) { |
| 101 | return; |
| 102 | } |
| 103 | ALOGE("32 bit float source does not match allocation type %i", dt); |
| 104 | } |
| 105 | |
| 106 | void Allocation::validateIsObject() { |
| 107 | RsDataType dt = mType->getElement()->getDataType(); |
| 108 | if ((dt == RS_TYPE_ELEMENT) || |
| 109 | (dt == RS_TYPE_TYPE) || |
| 110 | (dt == RS_TYPE_ALLOCATION) || |
| 111 | (dt == RS_TYPE_SAMPLER) || |
| 112 | (dt == RS_TYPE_SCRIPT) || |
| 113 | (dt == RS_TYPE_MESH) || |
| 114 | (dt == RS_TYPE_PROGRAM_FRAGMENT) || |
| 115 | (dt == RS_TYPE_PROGRAM_VERTEX) || |
| 116 | (dt == RS_TYPE_PROGRAM_RASTER) || |
| 117 | (dt == RS_TYPE_PROGRAM_STORE)) { |
| 118 | return; |
| 119 | } |
| 120 | ALOGE("Object source does not match allocation type %i", dt); |
| 121 | } |
| 122 | |
| 123 | void Allocation::updateFromNative() { |
| 124 | BaseObj::updateFromNative(); |
| 125 | |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 126 | const void *typeID = RS::dispatch->AllocationGetType(mRS->getContext(), getID()); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 127 | if(typeID != NULL) { |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 128 | sp<const Type> old = mType; |
| 129 | sp<Type> t = new Type((void *)typeID, mRS); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 130 | t->updateFromNative(); |
| 131 | updateCacheInfo(t); |
| 132 | mType = t; |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 133 | } |
| 134 | } |
| 135 | |
| 136 | void Allocation::syncAll(RsAllocationUsageType srcLocation) { |
| 137 | switch (srcLocation) { |
| 138 | case RS_ALLOCATION_USAGE_SCRIPT: |
| 139 | case RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS: |
| 140 | case RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE: |
| 141 | case RS_ALLOCATION_USAGE_GRAPHICS_VERTEX: |
| 142 | break; |
| 143 | default: |
| 144 | ALOGE("Source must be exactly one usage type."); |
| 145 | } |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 146 | RS::dispatch->AllocationSyncAll(mRS->getContext(), getIDSafe(), srcLocation); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | void Allocation::ioSendOutput() { |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 150 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 151 | if ((mUsage & RS_ALLOCATION_USAGE_IO_OUTPUT) == 0) { |
| 152 | ALOGE("Can only send buffer if IO_OUTPUT usage specified."); |
| 153 | } |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 154 | RS::dispatch->AllocationIoSend(mRS->getContext(), getID()); |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 155 | #endif |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | void Allocation::ioGetInput() { |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 159 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 160 | if ((mUsage & RS_ALLOCATION_USAGE_IO_INPUT) == 0) { |
| 161 | ALOGE("Can only send buffer if IO_OUTPUT usage specified."); |
| 162 | } |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 163 | RS::dispatch->AllocationIoReceive(mRS->getContext(), getID()); |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 164 | #endif |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 165 | } |
| 166 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 167 | void Allocation::generateMipmaps() { |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 168 | RS::dispatch->AllocationGenerateMipmaps(mRS->getContext(), getID()); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 171 | void Allocation::copy1DRangeFrom(uint32_t off, size_t count, const void *data) { |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 172 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 173 | if(count < 1) { |
| 174 | ALOGE("Count must be >= 1."); |
| 175 | return; |
| 176 | } |
| 177 | if((off + count) > mCurrentCount) { |
| 178 | ALOGE("Overflow, Available count %zu, got %zu at offset %zu.", mCurrentCount, count, off); |
| 179 | return; |
| 180 | } |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 181 | |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 182 | RS::dispatch->Allocation1DData(mRS->getContext(), getIDSafe(), off, mSelectedLOD, count, data, |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 183 | count * mType->getElement()->getSizeBytes()); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 184 | } |
| 185 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 186 | void Allocation::copy1DRangeTo(uint32_t off, size_t count, void *data) { |
Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 187 | if(count < 1) { |
| 188 | ALOGE("Count must be >= 1."); |
| 189 | return; |
| 190 | } |
| 191 | if((off + count) > mCurrentCount) { |
| 192 | ALOGE("Overflow, Available count %zu, got %zu at offset %zu.", mCurrentCount, count, off); |
| 193 | return; |
| 194 | } |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 195 | |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 196 | RS::dispatch->Allocation1DRead(mRS->getContext(), getIDSafe(), off, mSelectedLOD, count, data, |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 197 | count * mType->getElement()->getSizeBytes()); |
Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 198 | } |
| 199 | |
Tim Murray | a4cbc2b | 2012-11-14 17:18:08 -0800 | [diff] [blame] | 200 | void Allocation::copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, |
| 201 | uint32_t dataOff) { |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 202 | |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 203 | RS::dispatch->AllocationCopy2DRange(mRS->getContext(), getIDSafe(), off, 0, |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 204 | mSelectedLOD, mSelectedFace, |
| 205 | count, 1, data->getIDSafe(), dataOff, 0, |
| 206 | data->mSelectedLOD, data->mSelectedFace); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 207 | } |
| 208 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 209 | void Allocation::copy1DFrom(const void* data) { |
| 210 | copy1DRangeFrom(0, mCurrentCount, data); |
| 211 | } |
| 212 | |
| 213 | void Allocation::copy1DTo(void* data) { |
| 214 | copy1DRangeTo(0, mCurrentCount, data); |
| 215 | } |
| 216 | |
| 217 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 218 | void Allocation::validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h) { |
| 219 | if (mAdaptedAllocation != NULL) { |
| 220 | |
| 221 | } else { |
| 222 | if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY)) { |
| 223 | ALOGE("Updated region larger than allocation."); |
| 224 | } |
| 225 | } |
| 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 | const void *data) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 230 | validate2DRange(xoff, yoff, w, h); |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 231 | RS::dispatch->Allocation2DData(mRS->getContext(), getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace, |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 232 | w, h, data, w * h * mType->getElement()->getSizeBytes(), w * mType->getElement()->getSizeBytes()); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | 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] | 236 | sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 237 | validate2DRange(xoff, yoff, w, h); |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 238 | RS::dispatch->AllocationCopy2DRange(mRS->getContext(), getIDSafe(), xoff, yoff, |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 239 | mSelectedLOD, mSelectedFace, |
| 240 | w, h, data->getIDSafe(), dataXoff, dataYoff, |
| 241 | data->mSelectedLOD, data->mSelectedFace); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 244 | void Allocation::copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 245 | void* data) { |
| 246 | validate2DRange(xoff, yoff, w, h); |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 247 | RS::dispatch->Allocation2DRead(mRS->getContext(), getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace, |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 248 | w, h, data, w * h * mType->getElement()->getSizeBytes(), w * mType->getElement()->getSizeBytes()); |
Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 249 | } |
| 250 | |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 251 | void Allocation::copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 252 | const void *data, size_t stride) { |
| 253 | validate2DRange(xoff, yoff, w, h); |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 254 | RS::dispatch->Allocation2DData(mRS->getContext(), getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace, |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 255 | w, h, data, w * h * mType->getElement()->getSizeBytes(), stride); |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | void Allocation::copy2DStridedFrom(const void* data, size_t stride) { |
| 259 | copy2DStridedFrom(0, 0, mCurrentDimX, mCurrentDimY, data, stride); |
| 260 | } |
| 261 | |
| 262 | void Allocation::copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 263 | void *data, size_t stride) { |
| 264 | validate2DRange(xoff, yoff, w, h); |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 265 | RS::dispatch->Allocation2DRead(mRS->getContext(), getIDSafe(), xoff, yoff, mSelectedLOD, mSelectedFace, |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 266 | w, h, data, w * h * mType->getElement()->getSizeBytes(), stride); |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 267 | } |
| 268 | |
| 269 | void Allocation::copy2DStridedTo(void* data, size_t stride) { |
| 270 | copy2DStridedTo(0, 0, mCurrentDimX, mCurrentDimY, data, stride); |
| 271 | } |
| 272 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 273 | sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type, |
| 274 | RsAllocationMipmapControl mips, uint32_t usage) { |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 275 | void *id = RS::dispatch->AllocationCreateTyped(rs->getContext(), type->getID(), mips, usage, 0); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 276 | if (id == 0) { |
| 277 | ALOGE("Allocation creation failed."); |
| 278 | return NULL; |
| 279 | } |
| 280 | return new Allocation(id, rs, type, usage); |
| 281 | } |
| 282 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 283 | sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type, |
| 284 | RsAllocationMipmapControl mips, uint32_t usage, |
| 285 | void *pointer) { |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 286 | void *id = RS::dispatch->AllocationCreateTyped(rs->getContext(), type->getID(), mips, usage, |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 287 | (uintptr_t)pointer); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 288 | if (id == 0) { |
| 289 | ALOGE("Allocation creation failed."); |
| 290 | } |
| 291 | return new Allocation(id, rs, type, usage); |
| 292 | } |
| 293 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 294 | sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type, |
| 295 | uint32_t usage) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 296 | return createTyped(rs, type, RS_ALLOCATION_MIPMAP_NONE, usage); |
| 297 | } |
| 298 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 299 | sp<Allocation> Allocation::createSized(sp<RS> rs, sp<const Element> e, |
| 300 | size_t count, uint32_t usage) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 301 | Type::Builder b(rs, e); |
| 302 | b.setX(count); |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 303 | sp<const Type> t = b.create(); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 304 | |
Tim Murray | 684726c | 2012-11-14 11:57:42 -0800 | [diff] [blame] | 305 | return createTyped(rs, t, usage); |
| 306 | } |
| 307 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 308 | sp<Allocation> Allocation::createSized2D(sp<RS> rs, sp<const Element> e, |
| 309 | size_t x, size_t y, uint32_t usage) { |
Tim Murray | 684726c | 2012-11-14 11:57:42 -0800 | [diff] [blame] | 310 | Type::Builder b(rs, e); |
| 311 | b.setX(x); |
| 312 | b.setY(y); |
| 313 | sp<const Type> t = b.create(); |
| 314 | |
| 315 | return createTyped(rs, t, usage); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 316 | } |