Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 1 | /* |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 2 | * Copyright (C) 2013 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 | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 18 | #include "rsCppInternal.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 | |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame^] | 67 | if (t != nullptr) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 68 | updateCacheInfo(t); |
| 69 | } |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 70 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 71 | } |
| 72 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 73 | |
| 74 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 75 | void Allocation::validateIsInt32() { |
| 76 | RsDataType dt = mType->getElement()->getDataType(); |
| 77 | if ((dt == RS_TYPE_SIGNED_32) || (dt == RS_TYPE_UNSIGNED_32)) { |
| 78 | return; |
| 79 | } |
| 80 | ALOGE("32 bit integer source does not match allocation type %i", dt); |
| 81 | } |
| 82 | |
| 83 | void Allocation::validateIsInt16() { |
| 84 | RsDataType dt = mType->getElement()->getDataType(); |
| 85 | if ((dt == RS_TYPE_SIGNED_16) || (dt == RS_TYPE_UNSIGNED_16)) { |
| 86 | return; |
| 87 | } |
| 88 | ALOGE("16 bit integer source does not match allocation type %i", dt); |
| 89 | } |
| 90 | |
| 91 | void Allocation::validateIsInt8() { |
| 92 | RsDataType dt = mType->getElement()->getDataType(); |
| 93 | if ((dt == RS_TYPE_SIGNED_8) || (dt == RS_TYPE_UNSIGNED_8)) { |
| 94 | return; |
| 95 | } |
| 96 | ALOGE("8 bit integer source does not match allocation type %i", dt); |
| 97 | } |
| 98 | |
| 99 | void Allocation::validateIsFloat32() { |
| 100 | RsDataType dt = mType->getElement()->getDataType(); |
| 101 | if (dt == RS_TYPE_FLOAT_32) { |
| 102 | return; |
| 103 | } |
| 104 | ALOGE("32 bit float source does not match allocation type %i", dt); |
| 105 | } |
| 106 | |
| 107 | void Allocation::validateIsObject() { |
| 108 | RsDataType dt = mType->getElement()->getDataType(); |
| 109 | if ((dt == RS_TYPE_ELEMENT) || |
| 110 | (dt == RS_TYPE_TYPE) || |
| 111 | (dt == RS_TYPE_ALLOCATION) || |
| 112 | (dt == RS_TYPE_SAMPLER) || |
| 113 | (dt == RS_TYPE_SCRIPT) || |
| 114 | (dt == RS_TYPE_MESH) || |
| 115 | (dt == RS_TYPE_PROGRAM_FRAGMENT) || |
| 116 | (dt == RS_TYPE_PROGRAM_VERTEX) || |
| 117 | (dt == RS_TYPE_PROGRAM_RASTER) || |
| 118 | (dt == RS_TYPE_PROGRAM_STORE)) { |
| 119 | return; |
| 120 | } |
| 121 | ALOGE("Object source does not match allocation type %i", dt); |
| 122 | } |
| 123 | |
| 124 | void Allocation::updateFromNative() { |
| 125 | BaseObj::updateFromNative(); |
| 126 | |
Tim Murray | a423096 | 2013-07-17 16:50:10 -0700 | [diff] [blame] | 127 | const void *typeID = RS::dispatch->AllocationGetType(mRS->getContext(), getID()); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame^] | 128 | if(typeID != nullptr) { |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 129 | sp<const Type> old = mType; |
| 130 | sp<Type> t = new Type((void *)typeID, mRS); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 131 | t->updateFromNative(); |
| 132 | updateCacheInfo(t); |
| 133 | mType = t; |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | |
| 137 | void Allocation::syncAll(RsAllocationUsageType srcLocation) { |
| 138 | switch (srcLocation) { |
| 139 | case RS_ALLOCATION_USAGE_SCRIPT: |
| 140 | case RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS: |
| 141 | case RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE: |
| 142 | case RS_ALLOCATION_USAGE_GRAPHICS_VERTEX: |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 143 | case RS_ALLOCATION_USAGE_SHARED: |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 144 | break; |
| 145 | default: |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 146 | mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Source must be exactly one usage type."); |
| 147 | return; |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 148 | } |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 149 | tryDispatch(mRS, RS::dispatch->AllocationSyncAll(mRS->getContext(), getIDSafe(), srcLocation)); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | void Allocation::ioSendOutput() { |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 153 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 154 | if ((mUsage & RS_ALLOCATION_USAGE_IO_OUTPUT) == 0) { |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 155 | mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Can only send buffer if IO_OUTPUT usage specified."); |
| 156 | return; |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 157 | } |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 158 | tryDispatch(mRS, RS::dispatch->AllocationIoSend(mRS->getContext(), getID())); |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 159 | #endif |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | void Allocation::ioGetInput() { |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 163 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 164 | if ((mUsage & RS_ALLOCATION_USAGE_IO_INPUT) == 0) { |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 165 | mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Can only send buffer if IO_OUTPUT usage specified."); |
| 166 | return; |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 167 | } |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 168 | tryDispatch(mRS, RS::dispatch->AllocationIoReceive(mRS->getContext(), getID())); |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 169 | #endif |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 170 | } |
| 171 | |
Jason Sams | b8a94e2 | 2014-02-24 17:52:32 -0800 | [diff] [blame] | 172 | void * Allocation::getPointer(size_t *stride) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame^] | 173 | void *p = nullptr; |
Jason Sams | b8a94e2 | 2014-02-24 17:52:32 -0800 | [diff] [blame] | 174 | if (!(mUsage & RS_ALLOCATION_USAGE_SHARED)) { |
| 175 | mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Allocation does not support USAGE_SHARED."); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame^] | 176 | return nullptr; |
Jason Sams | b8a94e2 | 2014-02-24 17:52:32 -0800 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | // FIXME: decide if lack of getPointer should cause compat mode |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame^] | 180 | if (RS::dispatch->AllocationGetPointer == nullptr) { |
Jason Sams | b8a94e2 | 2014-02-24 17:52:32 -0800 | [diff] [blame] | 181 | mRS->throwError(RS_ERROR_RUNTIME_ERROR, "Can't use getPointer on older APIs"); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame^] | 182 | return nullptr; |
Jason Sams | b8a94e2 | 2014-02-24 17:52:32 -0800 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | p = RS::dispatch->AllocationGetPointer(mRS->getContext(), getIDSafe(), 0, |
| 186 | RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, 0, 0, stride); |
| 187 | if (mRS->getError() != RS_SUCCESS) { |
| 188 | mRS->throwError(RS_ERROR_RUNTIME_ERROR, "Allocation lock failed"); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame^] | 189 | p = nullptr; |
Jason Sams | b8a94e2 | 2014-02-24 17:52:32 -0800 | [diff] [blame] | 190 | } |
| 191 | return p; |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 192 | } |
| 193 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 194 | void Allocation::copy1DRangeFrom(uint32_t off, size_t count, const void *data) { |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 195 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 196 | if(count < 1) { |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 197 | mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Count must be >= 1."); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 198 | return; |
| 199 | } |
| 200 | if((off + count) > mCurrentCount) { |
Tim Murray | e195a3f | 2014-03-13 15:04:58 -0700 | [diff] [blame] | 201 | ALOGE("Overflow, Available count %u, got %zu at offset %u.", mCurrentCount, count, off); |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 202 | mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Invalid copy specified"); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 203 | return; |
| 204 | } |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 205 | |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 206 | tryDispatch(mRS, RS::dispatch->Allocation1DData(mRS->getContext(), getIDSafe(), off, mSelectedLOD, |
| 207 | count, data, count * mType->getElement()->getSizeBytes())); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 208 | } |
| 209 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 210 | void Allocation::copy1DRangeTo(uint32_t off, size_t count, void *data) { |
Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 211 | if(count < 1) { |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 212 | mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Count must be >= 1."); |
Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 213 | return; |
| 214 | } |
| 215 | if((off + count) > mCurrentCount) { |
Tim Murray | e195a3f | 2014-03-13 15:04:58 -0700 | [diff] [blame] | 216 | ALOGE("Overflow, Available count %u, got %zu at offset %u.", mCurrentCount, count, off); |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 217 | mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Invalid copy specified"); |
Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 218 | return; |
| 219 | } |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 220 | |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 221 | tryDispatch(mRS, RS::dispatch->Allocation1DRead(mRS->getContext(), getIDSafe(), off, mSelectedLOD, |
| 222 | count, data, count * mType->getElement()->getSizeBytes())); |
Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 223 | } |
| 224 | |
Tim Murray | a4cbc2b | 2012-11-14 17:18:08 -0800 | [diff] [blame] | 225 | void Allocation::copy1DRangeFrom(uint32_t off, size_t count, sp<const Allocation> data, |
| 226 | uint32_t dataOff) { |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 227 | |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 228 | tryDispatch(mRS, RS::dispatch->AllocationCopy2DRange(mRS->getContext(), getIDSafe(), off, 0, |
| 229 | mSelectedLOD, mSelectedFace, |
| 230 | count, 1, data->getIDSafe(), dataOff, 0, |
| 231 | data->mSelectedLOD, data->mSelectedFace)); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 232 | } |
| 233 | |
Tim Murray | 0b93e30 | 2012-11-15 14:56:54 -0800 | [diff] [blame] | 234 | void Allocation::copy1DFrom(const void* data) { |
| 235 | copy1DRangeFrom(0, mCurrentCount, data); |
| 236 | } |
| 237 | |
| 238 | void Allocation::copy1DTo(void* data) { |
| 239 | copy1DRangeTo(0, mCurrentCount, data); |
| 240 | } |
| 241 | |
| 242 | |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 243 | void Allocation::validate2DRange(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame^] | 244 | if (mAdaptedAllocation != nullptr) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 245 | |
| 246 | } else { |
| 247 | if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY)) { |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 248 | mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Updated region larger than allocation."); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | 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] | 254 | const void *data) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 255 | validate2DRange(xoff, yoff, w, h); |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 256 | tryDispatch(mRS, RS::dispatch->Allocation2DData(mRS->getContext(), getIDSafe(), xoff, |
| 257 | yoff, mSelectedLOD, mSelectedFace, |
| 258 | w, h, data, w * h * mType->getElement()->getSizeBytes(), |
| 259 | w * mType->getElement()->getSizeBytes())); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | 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] | 263 | sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 264 | validate2DRange(xoff, yoff, w, h); |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 265 | tryDispatch(mRS, RS::dispatch->AllocationCopy2DRange(mRS->getContext(), getIDSafe(), xoff, yoff, |
| 266 | mSelectedLOD, mSelectedFace, |
| 267 | w, h, data->getIDSafe(), dataXoff, dataYoff, |
| 268 | data->mSelectedLOD, data->mSelectedFace)); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 269 | } |
| 270 | |
Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 271 | void Allocation::copy2DRangeTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 272 | void* data) { |
| 273 | validate2DRange(xoff, yoff, w, h); |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 274 | tryDispatch(mRS, RS::dispatch->Allocation2DRead(mRS->getContext(), getIDSafe(), xoff, yoff, |
| 275 | mSelectedLOD, mSelectedFace, w, h, data, |
| 276 | w * h * mType->getElement()->getSizeBytes(), |
| 277 | w * mType->getElement()->getSizeBytes())); |
Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 278 | } |
| 279 | |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 280 | void Allocation::copy2DStridedFrom(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 281 | const void *data, size_t stride) { |
| 282 | validate2DRange(xoff, yoff, w, h); |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 283 | tryDispatch(mRS, RS::dispatch->Allocation2DData(mRS->getContext(), getIDSafe(), xoff, yoff, |
| 284 | mSelectedLOD, mSelectedFace, w, h, data, |
| 285 | w * h * mType->getElement()->getSizeBytes(), stride)); |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | void Allocation::copy2DStridedFrom(const void* data, size_t stride) { |
| 289 | copy2DStridedFrom(0, 0, mCurrentDimX, mCurrentDimY, data, stride); |
| 290 | } |
| 291 | |
| 292 | void Allocation::copy2DStridedTo(uint32_t xoff, uint32_t yoff, uint32_t w, uint32_t h, |
| 293 | void *data, size_t stride) { |
| 294 | validate2DRange(xoff, yoff, w, h); |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 295 | tryDispatch(mRS, RS::dispatch->Allocation2DRead(mRS->getContext(), getIDSafe(), xoff, yoff, |
| 296 | mSelectedLOD, mSelectedFace, w, h, data, |
| 297 | w * h * mType->getElement()->getSizeBytes(), stride)); |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 298 | } |
| 299 | |
| 300 | void Allocation::copy2DStridedTo(void* data, size_t stride) { |
| 301 | copy2DStridedTo(0, 0, mCurrentDimX, mCurrentDimY, data, stride); |
| 302 | } |
| 303 | |
Tim Murray | 9d24ae6 | 2013-08-30 12:17:14 -0700 | [diff] [blame] | 304 | void Allocation::validate3DRange(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w, |
| 305 | uint32_t h, uint32_t d) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame^] | 306 | if (mAdaptedAllocation != nullptr) { |
Tim Murray | 9d24ae6 | 2013-08-30 12:17:14 -0700 | [diff] [blame] | 307 | |
| 308 | } else { |
| 309 | if (((xoff + w) > mCurrentDimX) || ((yoff + h) > mCurrentDimY) || ((zoff + d) > mCurrentDimZ)) { |
| 310 | mRS->throwError(RS_ERROR_INVALID_PARAMETER, "Updated region larger than allocation."); |
| 311 | } |
| 312 | } |
| 313 | } |
| 314 | |
| 315 | void Allocation::copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w, |
| 316 | uint32_t h, uint32_t d, const void* data) { |
| 317 | validate3DRange(xoff, yoff, zoff, w, h, d); |
| 318 | tryDispatch(mRS, RS::dispatch->Allocation3DData(mRS->getContext(), getIDSafe(), xoff, yoff, zoff, |
| 319 | mSelectedLOD, w, h, d, data, |
| 320 | w * h * d * mType->getElement()->getSizeBytes(), |
| 321 | w * mType->getElement()->getSizeBytes())); |
| 322 | } |
| 323 | |
| 324 | void Allocation::copy3DRangeFrom(uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t w, uint32_t h, uint32_t d, |
| 325 | sp<const Allocation> data, uint32_t dataXoff, uint32_t dataYoff, uint32_t dataZoff) { |
| 326 | validate3DRange(xoff, yoff, zoff, dataXoff, dataYoff, dataZoff); |
| 327 | tryDispatch(mRS, RS::dispatch->AllocationCopy3DRange(mRS->getContext(), getIDSafe(), xoff, yoff, zoff, |
| 328 | mSelectedLOD, w, h, d, data->getIDSafe(), |
| 329 | dataXoff, dataYoff, dataZoff, data->mSelectedLOD)); |
| 330 | } |
| 331 | |
| 332 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 333 | sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type, |
Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 334 | RsAllocationMipmapControl mipmaps, uint32_t usage) { |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 335 | void *id = 0; |
| 336 | if (rs->getError() == RS_SUCCESS) { |
Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 337 | id = RS::dispatch->AllocationCreateTyped(rs->getContext(), type->getID(), mipmaps, usage, 0); |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 338 | } |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 339 | if (id == 0) { |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 340 | rs->throwError(RS_ERROR_RUNTIME_ERROR, "Allocation creation failed"); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame^] | 341 | return nullptr; |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 342 | } |
| 343 | return new Allocation(id, rs, type, usage); |
| 344 | } |
| 345 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 346 | sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type, |
Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 347 | RsAllocationMipmapControl mipmaps, uint32_t usage, |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 348 | void *pointer) { |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 349 | void *id = 0; |
| 350 | if (rs->getError() == RS_SUCCESS) { |
Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 351 | id = RS::dispatch->AllocationCreateTyped(rs->getContext(), type->getID(), mipmaps, usage, |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 352 | (uintptr_t)pointer); |
| 353 | } |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 354 | if (id == 0) { |
Tim Murray | 10913a5 | 2013-08-20 17:19:47 -0700 | [diff] [blame] | 355 | rs->throwError(RS_ERROR_RUNTIME_ERROR, "Allocation creation failed"); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame^] | 356 | return nullptr; |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 357 | } |
| 358 | return new Allocation(id, rs, type, usage); |
| 359 | } |
| 360 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 361 | sp<Allocation> Allocation::createTyped(sp<RS> rs, sp<const Type> type, |
| 362 | uint32_t usage) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 363 | return createTyped(rs, type, RS_ALLOCATION_MIPMAP_NONE, usage); |
| 364 | } |
| 365 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 366 | sp<Allocation> Allocation::createSized(sp<RS> rs, sp<const Element> e, |
| 367 | size_t count, uint32_t usage) { |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 368 | Type::Builder b(rs, e); |
| 369 | b.setX(count); |
Jason Sams | 69cccdf | 2012-04-02 19:11:49 -0700 | [diff] [blame] | 370 | sp<const Type> t = b.create(); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 371 | |
Tim Murray | 684726c | 2012-11-14 11:57:42 -0800 | [diff] [blame] | 372 | return createTyped(rs, t, usage); |
| 373 | } |
| 374 | |
Tim Murray | 89daad6 | 2013-07-29 14:30:02 -0700 | [diff] [blame] | 375 | sp<Allocation> Allocation::createSized2D(sp<RS> rs, sp<const Element> e, |
| 376 | size_t x, size_t y, uint32_t usage) { |
Tim Murray | 684726c | 2012-11-14 11:57:42 -0800 | [diff] [blame] | 377 | Type::Builder b(rs, e); |
| 378 | b.setX(x); |
| 379 | b.setY(y); |
| 380 | sp<const Type> t = b.create(); |
| 381 | |
| 382 | return createTyped(rs, t, usage); |
Jason Sams | 221a4b1 | 2012-02-22 15:22:41 -0800 | [diff] [blame] | 383 | } |