Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
Jason Sams | bc0ca6b | 2013-02-15 18:13:43 -0800 | [diff] [blame] | 2 | * Copyright (C) 2013 The Android Open Source Project |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -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 | */ |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 16 | |
Alex Sakhartchouk | 77d9f4b | 2011-01-31 14:53:24 -0800 | [diff] [blame] | 17 | #include "rsContext.h" |
Alex Sakhartchouk | 4edf030 | 2012-03-09 10:47:27 -0800 | [diff] [blame] | 18 | #include "rsAllocation.h" |
| 19 | #include "rsAdapter.h" |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 20 | #include "rs_hal.h" |
| 21 | |
Stephen Hines | b0934b6 | 2013-07-03 17:27:38 -0700 | [diff] [blame] | 22 | #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB) |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 23 | #include "system/window.h" |
Andy McFadden | 58fd6a5 | 2012-12-18 09:50:03 -0800 | [diff] [blame] | 24 | #include "gui/GLConsumer.h" |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 25 | #endif |
Alex Sakhartchouk | 39f2ef6 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 26 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 27 | using namespace android; |
| 28 | using namespace android::renderscript; |
| 29 | |
Alex Sakhartchouk | a2aab8b | 2010-12-15 09:59:58 -0800 | [diff] [blame] | 30 | Allocation::Allocation(Context *rsc, const Type *type, uint32_t usages, |
Jason Sams | 179e9a4 | 2011-11-23 15:02:15 -0800 | [diff] [blame] | 31 | RsAllocationMipmapControl mc, void * ptr) |
Alex Sakhartchouk | a2aab8b | 2010-12-15 09:59:58 -0800 | [diff] [blame] | 32 | : ObjectBase(rsc) { |
Jason Sams | fa84da2 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 33 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 34 | memset(&mHal, 0, sizeof(mHal)); |
| 35 | mHal.state.mipmapControl = RS_ALLOCATION_MIPMAP_NONE; |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 36 | mHal.state.usageFlags = usages; |
| 37 | mHal.state.mipmapControl = mc; |
Tim Murray | 2e1a94d | 2012-11-29 13:12:25 -0800 | [diff] [blame] | 38 | mHal.state.userProvidedPtr = ptr; |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 39 | |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 40 | setType(type); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 41 | updateCache(); |
| 42 | } |
Jason Sams | fa84da2 | 2010-03-01 15:31:04 -0800 | [diff] [blame] | 43 | |
Jason Sams | cfea6c1 | 2015-02-09 12:50:22 -0800 | [diff] [blame] | 44 | Allocation::Allocation(Context *rsc, const Allocation *alloc, const Type *type) |
| 45 | : ObjectBase(rsc) { |
| 46 | |
| 47 | memset(&mHal, 0, sizeof(mHal)); |
| 48 | |
| 49 | |
| 50 | mHal.state.baseAlloc = alloc; |
| 51 | mHal.state.type = type; |
| 52 | mHal.state.usageFlags = alloc->mHal.state.usageFlags; |
| 53 | mHal.state.mipmapControl = RS_ALLOCATION_MIPMAP_NONE; |
| 54 | |
| 55 | setType(type); |
| 56 | updateCache(); |
| 57 | |
| 58 | |
| 59 | |
| 60 | |
| 61 | struct Hal { |
| 62 | void * drv; |
| 63 | |
| 64 | struct DrvState { |
| 65 | struct LodState { |
| 66 | void * mallocPtr; |
| 67 | size_t stride; |
| 68 | uint32_t dimX; |
| 69 | uint32_t dimY; |
| 70 | uint32_t dimZ; |
| 71 | } lod[android::renderscript::Allocation::MAX_LOD]; |
| 72 | size_t faceOffset; |
| 73 | uint32_t lodCount; |
| 74 | uint32_t faceCount; |
| 75 | |
| 76 | struct YuvState { |
| 77 | uint32_t shift; |
| 78 | uint32_t step; |
| 79 | } yuv; |
| 80 | |
| 81 | int grallocFlags; |
| 82 | uint32_t dimArray[Type::mMaxArrays]; |
| 83 | }; |
| 84 | mutable DrvState drvState; |
| 85 | |
| 86 | }; |
| 87 | Hal mHal; |
| 88 | |
| 89 | } |
| 90 | |
Tim Murray | 3468938 | 2013-03-11 12:12:03 -0700 | [diff] [blame] | 91 | void Allocation::operator delete(void* ptr) { |
| 92 | if (ptr) { |
| 93 | Allocation *a = (Allocation*) ptr; |
| 94 | a->getContext()->mHal.funcs.freeRuntimeMem(ptr); |
| 95 | } |
| 96 | } |
| 97 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 98 | Allocation * Allocation::createAllocation(Context *rsc, const Type *type, uint32_t usages, |
Jason Sams | 179e9a4 | 2011-11-23 15:02:15 -0800 | [diff] [blame] | 99 | RsAllocationMipmapControl mc, void * ptr) { |
Tim Murray | 3468938 | 2013-03-11 12:12:03 -0700 | [diff] [blame] | 100 | // Allocation objects must use allocator specified by the driver |
| 101 | void* allocMem = rsc->mHal.funcs.allocRuntimeMem(sizeof(Allocation), 0); |
| 102 | |
| 103 | if (!allocMem) { |
| 104 | rsc->setError(RS_ERROR_FATAL_DRIVER, "Couldn't allocate memory for Allocation"); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 105 | return nullptr; |
Tim Murray | 3468938 | 2013-03-11 12:12:03 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | Allocation *a = new (allocMem) Allocation(rsc, type, usages, mc, ptr); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 109 | |
| 110 | if (!rsc->mHal.funcs.allocation.init(rsc, a, type->getElement()->getHasReferences())) { |
| 111 | rsc->setError(RS_ERROR_FATAL_DRIVER, "Allocation::Allocation, alloc failure"); |
| 112 | delete a; |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 113 | return nullptr; |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 114 | } |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 115 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 116 | return a; |
| 117 | } |
| 118 | |
Jason Sams | cfea6c1 | 2015-02-09 12:50:22 -0800 | [diff] [blame] | 119 | Allocation * Allocation::createAdapter(Context *rsc, const Allocation *alloc, const Type *type) { |
| 120 | // Allocation objects must use allocator specified by the driver |
| 121 | void* allocMem = rsc->mHal.funcs.allocRuntimeMem(sizeof(Allocation), 0); |
| 122 | |
| 123 | if (!allocMem) { |
| 124 | rsc->setError(RS_ERROR_FATAL_DRIVER, "Couldn't allocate memory for Allocation"); |
| 125 | return nullptr; |
| 126 | } |
| 127 | |
| 128 | Allocation *a = new (allocMem) Allocation(rsc, alloc, type); |
| 129 | |
| 130 | if (!rsc->mHal.funcs.allocation.initAdapter(rsc, a)) { |
| 131 | rsc->setError(RS_ERROR_FATAL_DRIVER, "Allocation::Allocation, alloc failure"); |
| 132 | delete a; |
| 133 | return nullptr; |
| 134 | } |
| 135 | |
| 136 | return a; |
| 137 | } |
| 138 | |
Jason Sams | 442b7ff | 2015-03-06 16:50:11 -0800 | [diff] [blame] | 139 | void Allocation::adapterOffset(Context *rsc, const uint32_t *offsets, size_t len) { |
| 140 | if (len >= sizeof(uint32_t) * 9) { |
| 141 | mHal.state.originX = offsets[0]; |
| 142 | mHal.state.originY = offsets[1]; |
| 143 | mHal.state.originZ = offsets[2]; |
| 144 | mHal.state.originLOD = offsets[3]; |
| 145 | mHal.state.originFace = offsets[4]; |
| 146 | mHal.state.originArray[0] = offsets[5]; |
| 147 | mHal.state.originArray[1] = offsets[6]; |
| 148 | mHal.state.originArray[2] = offsets[7]; |
| 149 | mHal.state.originArray[3] = offsets[8]; |
| 150 | } |
| 151 | |
| 152 | rsc->mHal.funcs.allocation.adapterOffset(rsc, this); |
| 153 | } |
| 154 | |
| 155 | |
Jason Sams | cfea6c1 | 2015-02-09 12:50:22 -0800 | [diff] [blame] | 156 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 157 | void Allocation::updateCache() { |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 158 | const Type *type = mHal.state.type; |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 159 | mHal.state.yuv = type->getDimYuv(); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 160 | mHal.state.hasFaces = type->getDimFaces(); |
| 161 | mHal.state.hasMipmaps = type->getDimLOD(); |
| 162 | mHal.state.elementSizeBytes = type->getElementSizeBytes(); |
| 163 | mHal.state.hasReferences = mHal.state.type->getElement()->getHasReferences(); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 166 | Allocation::~Allocation() { |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 167 | #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB) |
| 168 | if (mGrallocConsumer.get()) { |
| 169 | mGrallocConsumer->unlockBuffer(); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 170 | mGrallocConsumer = nullptr; |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 171 | } |
| 172 | #endif |
| 173 | |
Jason Sams | c7cec1e | 2011-08-18 18:01:33 -0700 | [diff] [blame] | 174 | freeChildrenUnlocked(); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 175 | mRSC->mHal.funcs.allocation.destroy(mRSC, this); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 176 | } |
| 177 | |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 178 | void Allocation::syncAll(Context *rsc, RsAllocationUsageType src) { |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 179 | rsc->mHal.funcs.allocation.syncAll(rsc, this, src); |
Jason Sams | cf4c7c9 | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 180 | } |
| 181 | |
Jason Sams | b8a94e2 | 2014-02-24 17:52:32 -0800 | [diff] [blame] | 182 | void * Allocation::getPointer(const Context *rsc, uint32_t lod, RsAllocationCubemapFace face, |
| 183 | uint32_t z, uint32_t array, size_t *stride) { |
| 184 | |
| 185 | if ((lod >= mHal.drvState.lodCount) || |
| 186 | (z && (z >= mHal.drvState.lod[lod].dimZ)) || |
| 187 | ((face != RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X) && !mHal.state.hasFaces) || |
| 188 | (array != 0)) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 189 | return nullptr; |
Jason Sams | b8a94e2 | 2014-02-24 17:52:32 -0800 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | size_t s = 0; |
| 193 | //void *ptr = mRSC->mHal.funcs.allocation.lock1D(rsc, this); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 194 | if ((stride != nullptr) && mHal.drvState.lod[0].dimY) { |
Jason Sams | b8a94e2 | 2014-02-24 17:52:32 -0800 | [diff] [blame] | 195 | *stride = mHal.drvState.lod[lod].stride; |
| 196 | } |
| 197 | return mHal.drvState.lod[lod].mallocPtr; |
| 198 | } |
| 199 | |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 200 | void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod, |
Stephen Hines | 6ae039b | 2012-01-18 18:46:27 -0800 | [diff] [blame] | 201 | uint32_t count, const void *data, size_t sizeBytes) { |
| 202 | const size_t eSize = mHal.state.type->getElementSizeBytes(); |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 203 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 204 | if ((count * eSize) != sizeBytes) { |
Jason Sams | a273793 | 2014-01-14 12:28:33 -0800 | [diff] [blame] | 205 | char buf[1024]; |
| 206 | sprintf(buf, "Allocation::subData called with mismatched size expected %zu, got %zu", |
| 207 | (count * eSize), sizeBytes); |
| 208 | rsc->setError(RS_ERROR_BAD_VALUE, buf); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 209 | mHal.state.type->dumpLOGV("type info"); |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 210 | return; |
| 211 | } |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 212 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 213 | rsc->mHal.funcs.allocation.data1D(rsc, this, xoff, lod, count, data, sizeBytes); |
| 214 | sendDirty(rsc); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 217 | void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 218 | uint32_t w, uint32_t h, const void *data, size_t sizeBytes, size_t stride) { |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 219 | rsc->mHal.funcs.allocation.data2D(rsc, this, xoff, yoff, lod, face, w, h, data, sizeBytes, stride); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 220 | sendDirty(rsc); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Jason Sams | 236385b | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 223 | void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 224 | uint32_t lod, |
| 225 | uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, size_t stride) { |
| 226 | rsc->mHal.funcs.allocation.data3D(rsc, this, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride); |
| 227 | sendDirty(rsc); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 228 | } |
| 229 | |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 230 | void Allocation::read(Context *rsc, uint32_t xoff, uint32_t lod, |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 231 | uint32_t count, void *data, size_t sizeBytes) { |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 232 | const size_t eSize = mHal.state.type->getElementSizeBytes(); |
| 233 | |
| 234 | if ((count * eSize) != sizeBytes) { |
Jason Sams | a273793 | 2014-01-14 12:28:33 -0800 | [diff] [blame] | 235 | char buf[1024]; |
| 236 | sprintf(buf, "Allocation::read called with mismatched size expected %zu, got %zu", |
| 237 | (count * eSize), sizeBytes); |
| 238 | rsc->setError(RS_ERROR_BAD_VALUE, buf); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 239 | mHal.state.type->dumpLOGV("type info"); |
| 240 | return; |
| 241 | } |
| 242 | |
| 243 | rsc->mHal.funcs.allocation.read1D(rsc, this, xoff, lod, count, data, sizeBytes); |
| 244 | } |
| 245 | |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 246 | void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, |
| 247 | uint32_t w, uint32_t h, void *data, size_t sizeBytes, size_t stride) { |
| 248 | const size_t eSize = mHal.state.elementSizeBytes; |
| 249 | const size_t lineSize = eSize * w; |
| 250 | if (!stride) { |
| 251 | stride = lineSize; |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 252 | } else { |
| 253 | if ((lineSize * h) != sizeBytes) { |
Jason Sams | a273793 | 2014-01-14 12:28:33 -0800 | [diff] [blame] | 254 | char buf[1024]; |
| 255 | sprintf(buf, "Allocation size mismatch, expected %zu, got %zu", (lineSize * h), sizeBytes); |
| 256 | rsc->setError(RS_ERROR_BAD_VALUE, buf); |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 257 | return; |
| 258 | } |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | rsc->mHal.funcs.allocation.read2D(rsc, this, xoff, yoff, lod, face, w, h, data, sizeBytes, stride); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 264 | void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, |
| 265 | uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes, size_t stride) { |
| 266 | const size_t eSize = mHal.state.elementSizeBytes; |
| 267 | const size_t lineSize = eSize * w; |
| 268 | if (!stride) { |
| 269 | stride = lineSize; |
| 270 | } |
| 271 | |
| 272 | rsc->mHal.funcs.allocation.read3D(rsc, this, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride); |
| 273 | |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Miao Wang | cc8cea7 | 2015-02-19 18:14:46 -0800 | [diff] [blame] | 276 | void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y, uint32_t z, |
| 277 | const void *data, uint32_t cIdx, size_t sizeBytes) { |
Stephen Hines | 6ae039b | 2012-01-18 18:46:27 -0800 | [diff] [blame] | 278 | size_t eSize = mHal.state.elementSizeBytes; |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 279 | |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 280 | if (x >= mHal.drvState.lod[0].dimX) { |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 281 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); |
| 282 | return; |
| 283 | } |
| 284 | |
Miao Wang | cc8cea7 | 2015-02-19 18:14:46 -0800 | [diff] [blame] | 285 | if (y > 0 && y >= mHal.drvState.lod[0].dimY) { |
| 286 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData Y offset out of range."); |
| 287 | return; |
| 288 | } |
| 289 | |
| 290 | if (z > 0 && z >= mHal.drvState.lod[0].dimZ) { |
| 291 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData Z offset out of range."); |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | if (cIdx >= mHal.state.type->getElement()->getFieldCount()) { |
| 296 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range."); |
| 297 | return; |
| 298 | } |
| 299 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 300 | const Element * e = mHal.state.type->getElement()->getField(cIdx); |
Alex Sakhartchouk | 7694632 | 2012-02-02 09:47:26 -0800 | [diff] [blame] | 301 | uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx); |
| 302 | if (sizeBytes != e->getSizeBytes() * elemArraySize) { |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 303 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size."); |
| 304 | return; |
| 305 | } |
| 306 | |
Miao Wang | cc8cea7 | 2015-02-19 18:14:46 -0800 | [diff] [blame] | 307 | rsc->mHal.funcs.allocation.elementData(rsc, this, x, y, z, data, cIdx, sizeBytes); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 308 | sendDirty(rsc); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 309 | } |
| 310 | |
Miao Wang | cc8cea7 | 2015-02-19 18:14:46 -0800 | [diff] [blame] | 311 | void Allocation::elementRead(Context *rsc, uint32_t x, uint32_t y, uint32_t z, |
| 312 | void *data, uint32_t cIdx, size_t sizeBytes) { |
Stephen Hines | 6ae039b | 2012-01-18 18:46:27 -0800 | [diff] [blame] | 313 | size_t eSize = mHal.state.elementSizeBytes; |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 314 | |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 315 | if (x >= mHal.drvState.lod[0].dimX) { |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 316 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); |
| 317 | return; |
| 318 | } |
| 319 | |
Miao Wang | cc8cea7 | 2015-02-19 18:14:46 -0800 | [diff] [blame] | 320 | if (y > 0 && y >= mHal.drvState.lod[0].dimY) { |
| 321 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData Y offset out of range."); |
| 322 | return; |
| 323 | } |
| 324 | |
| 325 | if (z > 0 && z >= mHal.drvState.lod[0].dimZ) { |
| 326 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData Z offset out of range."); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 327 | return; |
| 328 | } |
| 329 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 330 | if (cIdx >= mHal.state.type->getElement()->getFieldCount()) { |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 331 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range."); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 332 | return; |
| 333 | } |
| 334 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 335 | const Element * e = mHal.state.type->getElement()->getField(cIdx); |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 336 | uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx); |
Alex Sakhartchouk | 7694632 | 2012-02-02 09:47:26 -0800 | [diff] [blame] | 337 | if (sizeBytes != e->getSizeBytes() * elemArraySize) { |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 338 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size."); |
| 339 | return; |
| 340 | } |
| 341 | |
Miao Wang | cc8cea7 | 2015-02-19 18:14:46 -0800 | [diff] [blame] | 342 | rsc->mHal.funcs.allocation.elementRead(rsc, this, x, y, z, data, cIdx, sizeBytes); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 345 | void Allocation::addProgramToDirty(const Program *p) { |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 346 | mToDirtyList.push(p); |
Jason Sams | 5c3e3bc | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 347 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 348 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 349 | void Allocation::removeProgramToDirty(const Program *p) { |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 350 | for (size_t ct=0; ct < mToDirtyList.size(); ct++) { |
| 351 | if (mToDirtyList[ct] == p) { |
| 352 | mToDirtyList.removeAt(ct); |
Jason Sams | 5c3e3bc | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 353 | return; |
| 354 | } |
| 355 | } |
| 356 | rsAssert(0); |
| 357 | } |
| 358 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 359 | void Allocation::dumpLOGV(const char *prefix) const { |
Jason Sams | c21cf40 | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 360 | ObjectBase::dumpLOGV(prefix); |
Jason Sams | 48ecf6a | 2013-07-09 15:35:29 -0700 | [diff] [blame] | 361 | char buf[1024]; |
Jason Sams | c21cf40 | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 362 | |
Jason Sams | 48ecf6a | 2013-07-09 15:35:29 -0700 | [diff] [blame] | 363 | if ((strlen(prefix) + 10) < sizeof(buf)) { |
| 364 | sprintf(buf, "%s type ", prefix); |
| 365 | if (mHal.state.type) { |
| 366 | mHal.state.type->dumpLOGV(buf); |
| 367 | } |
Jason Sams | c21cf40 | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 368 | } |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 369 | ALOGV("%s allocation ptr=%p mUsageFlags=0x04%x, mMipmapControl=0x%04x", |
Yang Ni | b8353c5 | 2015-02-14 18:00:59 -0800 | [diff] [blame] | 370 | prefix, mHal.drvState.lod[0].mallocPtr, mHal.state.usageFlags, mHal.state.mipmapControl); |
Jason Sams | c21cf40 | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 371 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 372 | |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 373 | uint32_t Allocation::getPackedSize() const { |
Jason Sams | 61656a7 | 2013-09-03 16:21:18 -0700 | [diff] [blame] | 374 | uint32_t numItems = mHal.state.type->getCellCount(); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 375 | return numItems * mHal.state.type->getElement()->getSizeBytesUnpadded(); |
| 376 | } |
| 377 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 378 | void Allocation::writePackedData(Context *rsc, const Type *type, |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 379 | uint8_t *dst, const uint8_t *src, bool dstPadded) { |
| 380 | const Element *elem = type->getElement(); |
| 381 | uint32_t unpaddedBytes = elem->getSizeBytesUnpadded(); |
| 382 | uint32_t paddedBytes = elem->getSizeBytes(); |
Jason Sams | 61656a7 | 2013-09-03 16:21:18 -0700 | [diff] [blame] | 383 | uint32_t numItems = type->getPackedSizeBytes() / paddedBytes; |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 384 | |
| 385 | uint32_t srcInc = !dstPadded ? paddedBytes : unpaddedBytes; |
| 386 | uint32_t dstInc = dstPadded ? paddedBytes : unpaddedBytes; |
| 387 | |
| 388 | // no sub-elements |
| 389 | uint32_t fieldCount = elem->getFieldCount(); |
| 390 | if (fieldCount == 0) { |
| 391 | for (uint32_t i = 0; i < numItems; i ++) { |
| 392 | memcpy(dst, src, unpaddedBytes); |
| 393 | src += srcInc; |
| 394 | dst += dstInc; |
| 395 | } |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | // Cache offsets |
| 400 | uint32_t *offsetsPadded = new uint32_t[fieldCount]; |
| 401 | uint32_t *offsetsUnpadded = new uint32_t[fieldCount]; |
| 402 | uint32_t *sizeUnpadded = new uint32_t[fieldCount]; |
| 403 | |
| 404 | for (uint32_t i = 0; i < fieldCount; i++) { |
| 405 | offsetsPadded[i] = elem->getFieldOffsetBytes(i); |
| 406 | offsetsUnpadded[i] = elem->getFieldOffsetBytesUnpadded(i); |
| 407 | sizeUnpadded[i] = elem->getField(i)->getSizeBytesUnpadded(); |
| 408 | } |
| 409 | |
| 410 | uint32_t *srcOffsets = !dstPadded ? offsetsPadded : offsetsUnpadded; |
| 411 | uint32_t *dstOffsets = dstPadded ? offsetsPadded : offsetsUnpadded; |
| 412 | |
| 413 | // complex elements, need to copy subelem after subelem |
| 414 | for (uint32_t i = 0; i < numItems; i ++) { |
| 415 | for (uint32_t fI = 0; fI < fieldCount; fI++) { |
| 416 | memcpy(dst + dstOffsets[fI], src + srcOffsets[fI], sizeUnpadded[fI]); |
| 417 | } |
| 418 | src += srcInc; |
| 419 | dst += dstInc; |
| 420 | } |
| 421 | |
| 422 | delete[] offsetsPadded; |
| 423 | delete[] offsetsUnpadded; |
| 424 | delete[] sizeUnpadded; |
| 425 | } |
| 426 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 427 | void Allocation::unpackVec3Allocation(Context *rsc, const void *data, size_t dataSize) { |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 428 | const uint8_t *src = (const uint8_t*)data; |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 429 | uint8_t *dst = (uint8_t *)rsc->mHal.funcs.allocation.lock1D(rsc, this); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 430 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 431 | writePackedData(rsc, getType(), dst, src, true); |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 432 | rsc->mHal.funcs.allocation.unlock1D(rsc, this); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 433 | } |
| 434 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 435 | void Allocation::packVec3Allocation(Context *rsc, OStream *stream) const { |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 436 | uint32_t paddedBytes = getType()->getElement()->getSizeBytes(); |
| 437 | uint32_t unpaddedBytes = getType()->getElement()->getSizeBytesUnpadded(); |
Jason Sams | 61656a7 | 2013-09-03 16:21:18 -0700 | [diff] [blame] | 438 | uint32_t numItems = mHal.state.type->getCellCount(); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 439 | |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 440 | const uint8_t *src = (const uint8_t*)rsc->mHal.funcs.allocation.lock1D(rsc, this); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 441 | uint8_t *dst = new uint8_t[numItems * unpaddedBytes]; |
| 442 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 443 | writePackedData(rsc, getType(), dst, src, false); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 444 | stream->addByteArray(dst, getPackedSize()); |
| 445 | |
| 446 | delete[] dst; |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 447 | rsc->mHal.funcs.allocation.unlock1D(rsc, this); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 448 | } |
| 449 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 450 | void Allocation::serialize(Context *rsc, OStream *stream) const { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 451 | // Need to identify ourselves |
| 452 | stream->addU32((uint32_t)getClassId()); |
Jason Sams | 48ecf6a | 2013-07-09 15:35:29 -0700 | [diff] [blame] | 453 | stream->addString(getName()); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 454 | |
| 455 | // First thing we need to serialize is the type object since it will be needed |
| 456 | // to initialize the class |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 457 | mHal.state.type->serialize(rsc, stream); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 458 | |
Jason Sams | 61656a7 | 2013-09-03 16:21:18 -0700 | [diff] [blame] | 459 | uint32_t dataSize = mHal.state.type->getPackedSizeBytes(); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 460 | // 3 element vectors are padded to 4 in memory, but padding isn't serialized |
| 461 | uint32_t packedSize = getPackedSize(); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 462 | // Write how much data we are storing |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 463 | stream->addU32(packedSize); |
| 464 | if (dataSize == packedSize) { |
| 465 | // Now write the data |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 466 | stream->addByteArray(rsc->mHal.funcs.allocation.lock1D(rsc, this), dataSize); |
| 467 | rsc->mHal.funcs.allocation.unlock1D(rsc, this); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 468 | } else { |
| 469 | // Now write the data |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 470 | packVec3Allocation(rsc, stream); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 471 | } |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 474 | Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 475 | // First make sure we are reading the correct object |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 476 | RsA3DClassID classID = (RsA3DClassID)stream->loadU32(); |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 477 | if (classID != RS_A3D_CLASS_ID_ALLOCATION) { |
Jason Sams | a273793 | 2014-01-14 12:28:33 -0800 | [diff] [blame] | 478 | rsc->setError(RS_ERROR_FATAL_DRIVER, |
| 479 | "allocation loading failed due to corrupt file. (invalid id)\n"); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 480 | return nullptr; |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Jason Sams | 48ecf6a | 2013-07-09 15:35:29 -0700 | [diff] [blame] | 483 | const char *name = stream->loadString(); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 484 | |
| 485 | Type *type = Type::createFromStream(rsc, stream); |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 486 | if (!type) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 487 | return nullptr; |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 488 | } |
| 489 | type->compute(); |
| 490 | |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 491 | Allocation *alloc = Allocation::createAllocation(rsc, type, RS_ALLOCATION_USAGE_SCRIPT); |
| 492 | type->decUserRef(); |
| 493 | |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 494 | // Number of bytes we wrote out for this allocation |
| 495 | uint32_t dataSize = stream->loadU32(); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 496 | // 3 element vectors are padded to 4 in memory, but padding isn't serialized |
| 497 | uint32_t packedSize = alloc->getPackedSize(); |
Jason Sams | 61656a7 | 2013-09-03 16:21:18 -0700 | [diff] [blame] | 498 | if (dataSize != type->getPackedSizeBytes() && |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 499 | dataSize != packedSize) { |
Jason Sams | a273793 | 2014-01-14 12:28:33 -0800 | [diff] [blame] | 500 | rsc->setError(RS_ERROR_FATAL_DRIVER, |
| 501 | "allocation loading failed due to corrupt file. (invalid size)\n"); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 502 | ObjectBase::checkDelete(alloc); |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 503 | ObjectBase::checkDelete(type); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 504 | return nullptr; |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 505 | } |
| 506 | |
Jason Sams | 48ecf6a | 2013-07-09 15:35:29 -0700 | [diff] [blame] | 507 | alloc->assignName(name); |
Jason Sams | 61656a7 | 2013-09-03 16:21:18 -0700 | [diff] [blame] | 508 | if (dataSize == type->getPackedSizeBytes()) { |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 509 | uint32_t count = dataSize / type->getElementSizeBytes(); |
| 510 | // Read in all of our allocation data |
| 511 | alloc->data(rsc, 0, 0, count, stream->getPtr() + stream->getPos(), dataSize); |
| 512 | } else { |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 513 | alloc->unpackVec3Allocation(rsc, stream->getPtr() + stream->getPos(), dataSize); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 514 | } |
Alex Sakhartchouk | e6d9fbc | 2010-08-11 10:30:44 -0700 | [diff] [blame] | 515 | stream->reset(stream->getPos() + dataSize); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 516 | |
| 517 | return alloc; |
| 518 | } |
| 519 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 520 | void Allocation::sendDirty(const Context *rsc) const { |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 521 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 5c3e3bc | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 522 | for (size_t ct=0; ct < mToDirtyList.size(); ct++) { |
| 523 | mToDirtyList[ct]->forceDirty(); |
| 524 | } |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 525 | #endif |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 526 | mRSC->mHal.funcs.allocation.markDirty(rsc, this); |
Jason Sams | 5c3e3bc | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 527 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 528 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 529 | void Allocation::incRefs(const void *ptr, size_t ct, size_t startOff) const { |
Stephen Hines | 9f70a4e | 2012-04-02 20:18:48 -0700 | [diff] [blame] | 530 | mHal.state.type->incRefs(ptr, ct, startOff); |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 531 | } |
| 532 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 533 | void Allocation::decRefs(const void *ptr, size_t ct, size_t startOff) const { |
Alex Sakhartchouk | 5c4369a | 2011-08-12 11:30:30 -0700 | [diff] [blame] | 534 | if (!mHal.state.hasReferences || !getIsScript()) { |
| 535 | return; |
| 536 | } |
Stephen Hines | 9f70a4e | 2012-04-02 20:18:48 -0700 | [diff] [blame] | 537 | mHal.state.type->decRefs(ptr, ct, startOff); |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 538 | } |
| 539 | |
Jason Sams | a36c50a | 2014-06-17 12:06:06 -0700 | [diff] [blame] | 540 | void Allocation::callUpdateCacheObject(const Context *rsc, void *dstObj) const { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 541 | if (rsc->mHal.funcs.allocation.updateCachedObject != nullptr) { |
Jason Sams | a36c50a | 2014-06-17 12:06:06 -0700 | [diff] [blame] | 542 | rsc->mHal.funcs.allocation.updateCachedObject(rsc, this, (rs_allocation *)dstObj); |
| 543 | } else { |
| 544 | *((const void **)dstObj) = this; |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | |
Jason Sams | c7cec1e | 2011-08-18 18:01:33 -0700 | [diff] [blame] | 549 | void Allocation::freeChildrenUnlocked () { |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 550 | void *ptr = mRSC->mHal.funcs.allocation.lock1D(mRSC, this); |
Jason Sams | 61656a7 | 2013-09-03 16:21:18 -0700 | [diff] [blame] | 551 | decRefs(ptr, mHal.state.type->getCellCount(), 0); |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 552 | mRSC->mHal.funcs.allocation.unlock1D(mRSC, this); |
Jason Sams | c7cec1e | 2011-08-18 18:01:33 -0700 | [diff] [blame] | 553 | } |
| 554 | |
| 555 | bool Allocation::freeChildren() { |
| 556 | if (mHal.state.hasReferences) { |
| 557 | incSysRef(); |
| 558 | freeChildrenUnlocked(); |
| 559 | return decSysRef(); |
| 560 | } |
| 561 | return false; |
| 562 | } |
| 563 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 564 | void Allocation::copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len) { |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 565 | } |
| 566 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 567 | void Allocation::resize1D(Context *rsc, uint32_t dimX) { |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 568 | uint32_t oldDimX = mHal.drvState.lod[0].dimX; |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 569 | if (dimX == oldDimX) { |
| 570 | return; |
| 571 | } |
| 572 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 573 | ObjectBaseRef<Type> t = mHal.state.type->cloneAndResize1D(rsc, dimX); |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 574 | if (dimX < oldDimX) { |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 575 | decRefs(rsc->mHal.funcs.allocation.lock1D(rsc, this), oldDimX - dimX, dimX); |
| 576 | rsc->mHal.funcs.allocation.unlock1D(rsc, this); |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 577 | } |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 578 | rsc->mHal.funcs.allocation.resize(rsc, this, t.get(), mHal.state.hasReferences); |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 579 | setType(t.get()); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 580 | updateCache(); |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 581 | } |
| 582 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 583 | void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY) { |
Jason Sams | a273793 | 2014-01-14 12:28:33 -0800 | [diff] [blame] | 584 | rsc->setError(RS_ERROR_FATAL_DRIVER, "resize2d not implemented"); |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 585 | } |
| 586 | |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 587 | #ifndef RS_COMPATIBILITY_LIB |
Dan Stoza | f0d7aa2 | 2014-11-04 11:38:47 -0800 | [diff] [blame] | 588 | void Allocation::NewBufferListener::onFrameAvailable(const BufferItem& /* item */) { |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 589 | intptr_t ip = (intptr_t)alloc; |
Tim Murray | e4ed087 | 2014-08-18 16:13:08 -0700 | [diff] [blame] | 590 | rsc->sendMessageToClient(&ip, RS_MESSAGE_TO_CLIENT_NEW_BUFFER, 0, sizeof(ip), true); |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 591 | } |
| 592 | #endif |
| 593 | |
Jason Sams | 733396b | 2013-02-22 12:46:18 -0800 | [diff] [blame] | 594 | void * Allocation::getSurface(const Context *rsc) { |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 595 | #ifndef RS_COMPATIBILITY_LIB |
| 596 | // Configure GrallocConsumer to be in asynchronous mode |
Dan Stoza | 03c155b | 2014-03-12 12:06:18 -0700 | [diff] [blame] | 597 | sp<IGraphicBufferProducer> bp; |
| 598 | sp<IGraphicBufferConsumer> bc; |
| 599 | BufferQueue::createBufferQueue(&bp, &bc); |
Jason Sams | e49da13 | 2014-10-23 17:32:27 -0700 | [diff] [blame] | 600 | mGrallocConsumer = new GrallocConsumer(this, bc, mHal.drvState.grallocFlags); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 601 | bp->incStrong(nullptr); |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 602 | |
| 603 | mBufferListener = new NewBufferListener(); |
| 604 | mBufferListener->rsc = rsc; |
| 605 | mBufferListener->alloc = this; |
| 606 | |
| 607 | mGrallocConsumer->setFrameAvailableListener(mBufferListener); |
| 608 | return bp.get(); |
| 609 | #else |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 610 | return nullptr; |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 611 | #endif |
| 612 | //return rsc->mHal.funcs.allocation.getSurface(rsc, this); |
Jason Sams | 41e373d | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 613 | } |
| 614 | |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 615 | void Allocation::setSurface(const Context *rsc, RsNativeWindow sur) { |
| 616 | ANativeWindow *nw = (ANativeWindow *)sur; |
Jason Sams | 733396b | 2013-02-22 12:46:18 -0800 | [diff] [blame] | 617 | rsc->mHal.funcs.allocation.setSurface(rsc, this, nw); |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 618 | } |
| 619 | |
| 620 | void Allocation::ioSend(const Context *rsc) { |
| 621 | rsc->mHal.funcs.allocation.ioSend(rsc, this); |
| 622 | } |
| 623 | |
| 624 | void Allocation::ioReceive(const Context *rsc) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 625 | void *ptr = nullptr; |
Jason Sams | ddceab9 | 2013-08-07 13:02:32 -0700 | [diff] [blame] | 626 | size_t stride = 0; |
| 627 | #ifndef RS_COMPATIBILITY_LIB |
| 628 | if (mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT) { |
| 629 | status_t ret = mGrallocConsumer->lockNextBuffer(); |
| 630 | |
| 631 | if (ret == OK) { |
| 632 | rsc->mHal.funcs.allocation.ioReceive(rsc, this); |
| 633 | } else if (ret == BAD_VALUE) { |
| 634 | // No new frame, don't do anything |
| 635 | } else { |
| 636 | rsc->setError(RS_ERROR_DRIVER, "Error receiving IO input buffer."); |
| 637 | } |
| 638 | |
| 639 | } |
| 640 | #endif |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 641 | } |
| 642 | |
Chris Wailes | 4b3c34e | 2014-06-11 12:00:29 -0700 | [diff] [blame] | 643 | bool Allocation::hasSameDims(const Allocation *other) const { |
| 644 | const Type *type0 = this->getType(), |
| 645 | *type1 = other->getType(); |
| 646 | |
| 647 | return (type0->getCellCount() == type1->getCellCount()) && |
| 648 | (type0->getDimLOD() == type1->getDimLOD()) && |
| 649 | (type0->getDimFaces() == type1->getDimFaces()) && |
| 650 | (type0->getDimYuv() == type1->getDimYuv()) && |
| 651 | (type0->getDimX() == type1->getDimX()) && |
| 652 | (type0->getDimY() == type1->getDimY()) && |
| 653 | (type0->getDimZ() == type1->getDimZ()); |
| 654 | } |
| 655 | |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 656 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 657 | ///////////////// |
Jason Sams | 565ac36 | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 658 | // |
Stephen Hines | 6a12181 | 2011-03-01 17:34:59 -0800 | [diff] [blame] | 659 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 660 | namespace android { |
| 661 | namespace renderscript { |
| 662 | |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 663 | void rsi_AllocationSyncAll(Context *rsc, RsAllocation va, RsAllocationUsageType src) { |
| 664 | Allocation *a = static_cast<Allocation *>(va); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 665 | a->sendDirty(rsc); |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 666 | a->syncAll(rsc, src); |
| 667 | } |
| 668 | |
Jason Sams | a237151 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 669 | void rsi_AllocationGenerateMipmaps(Context *rsc, RsAllocation va) { |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 670 | Allocation *alloc = static_cast<Allocation *>(va); |
| 671 | rsc->mHal.funcs.allocation.generateMipmaps(rsc, alloc); |
Jason Sams | 837e388 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 672 | } |
| 673 | |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 674 | void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) { |
| 675 | Allocation *a = static_cast<Allocation *>(va); |
| 676 | const Type * t = a->getType(); |
| 677 | a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 678 | t->getDimX(), t->getDimY(), data, sizeBytes, 0); |
Alex Sakhartchouk | 39f2ef6 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 681 | void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod, |
Alex Sakhartchouk | b81a0eb | 2011-06-03 10:18:01 -0700 | [diff] [blame] | 682 | uint32_t count, const void *data, size_t sizeBytes) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 683 | Allocation *a = static_cast<Allocation *>(va); |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 684 | a->data(rsc, xoff, lod, count, data, sizeBytes); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 685 | } |
| 686 | |
Miao Wang | cc8cea7 | 2015-02-19 18:14:46 -0800 | [diff] [blame] | 687 | void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, |
| 688 | uint32_t lod, const void *data, size_t sizeBytes, size_t eoff) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 689 | Allocation *a = static_cast<Allocation *>(va); |
Miao Wang | cc8cea7 | 2015-02-19 18:14:46 -0800 | [diff] [blame] | 690 | a->elementData(rsc, x, 0, 0, data, eoff, sizeBytes); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 691 | } |
| 692 | |
Miao Wang | cc8cea7 | 2015-02-19 18:14:46 -0800 | [diff] [blame] | 693 | void rsi_AllocationElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t z, |
| 694 | uint32_t lod, const void *data, size_t sizeBytes, size_t eoff) { |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 695 | Allocation *a = static_cast<Allocation *>(va); |
Miao Wang | cc8cea7 | 2015-02-19 18:14:46 -0800 | [diff] [blame] | 696 | a->elementData(rsc, x, y, z, data, eoff, sizeBytes); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 697 | } |
| 698 | |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 699 | void rsi_Allocation2DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 700 | uint32_t w, uint32_t h, const void *data, size_t sizeBytes, size_t stride) { |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 701 | Allocation *a = static_cast<Allocation *>(va); |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 702 | a->data(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 703 | } |
| 704 | |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 705 | void rsi_Allocation3DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, |
| 706 | uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, size_t stride) { |
| 707 | Allocation *a = static_cast<Allocation *>(va); |
| 708 | a->data(rsc, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride); |
| 709 | } |
| 710 | |
| 711 | |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 712 | void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) { |
Jason Sams | e579df4 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 713 | Allocation *a = static_cast<Allocation *>(va); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 714 | const Type * t = a->getType(); |
Miao Wang | cc8cea7 | 2015-02-19 18:14:46 -0800 | [diff] [blame] | 715 | if(t->getDimZ()) { |
| 716 | a->read(rsc, 0, 0, 0, 0, t->getDimX(), t->getDimY(), t->getDimZ(), |
| 717 | data, sizeBytes, 0); |
| 718 | } else if(t->getDimY()) { |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 719 | a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 720 | t->getDimX(), t->getDimY(), data, sizeBytes, 0); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 721 | } else { |
| 722 | a->read(rsc, 0, 0, t->getDimX(), data, sizeBytes); |
| 723 | } |
| 724 | |
Jason Sams | e579df4 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 727 | void rsi_AllocationResize1D(Context *rsc, RsAllocation va, uint32_t dimX) { |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 728 | Allocation *a = static_cast<Allocation *>(va); |
| 729 | a->resize1D(rsc, dimX); |
| 730 | } |
| 731 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 732 | void rsi_AllocationResize2D(Context *rsc, RsAllocation va, uint32_t dimX, uint32_t dimY) { |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 733 | Allocation *a = static_cast<Allocation *>(va); |
| 734 | a->resize2D(rsc, dimX, dimY); |
| 735 | } |
| 736 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 737 | RsAllocation rsi_AllocationCreateTyped(Context *rsc, RsType vtype, |
Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 738 | RsAllocationMipmapControl mipmaps, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 739 | uint32_t usages, uintptr_t ptr) { |
Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 740 | Allocation * alloc = Allocation::createAllocation(rsc, static_cast<Type *>(vtype), usages, mipmaps, (void*)ptr); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 741 | if (!alloc) { |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 742 | return nullptr; |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 743 | } |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 744 | alloc->incUserRef(); |
| 745 | return alloc; |
| 746 | } |
| 747 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 748 | RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, RsType vtype, |
Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 749 | RsAllocationMipmapControl mipmaps, |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 750 | const void *data, size_t sizeBytes, uint32_t usages) { |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 751 | Type *t = static_cast<Type *>(vtype); |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 752 | |
Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 753 | RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mipmaps, usages, 0); |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 754 | Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 755 | if (texAlloc == nullptr) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 756 | ALOGE("Memory allocation failure"); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 757 | return nullptr; |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 758 | } |
| 759 | |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 760 | texAlloc->data(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, |
Tim Murray | 60c2796 | 2013-02-07 16:15:23 -0800 | [diff] [blame] | 761 | t->getDimX(), t->getDimY(), data, sizeBytes, 0); |
Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 762 | if (mipmaps == RS_ALLOCATION_MIPMAP_FULL) { |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 763 | rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc); |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 766 | texAlloc->sendDirty(rsc); |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 767 | return texAlloc; |
| 768 | } |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 769 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 770 | RsAllocation rsi_AllocationCubeCreateFromBitmap(Context *rsc, RsType vtype, |
Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 771 | RsAllocationMipmapControl mipmaps, |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 772 | const void *data, size_t sizeBytes, uint32_t usages) { |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 773 | Type *t = static_cast<Type *>(vtype); |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 774 | |
| 775 | // Cubemap allocation's faces should be Width by Width each. |
| 776 | // Source data should have 6 * Width by Width pixels |
| 777 | // Error checking is done in the java layer |
Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 778 | RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mipmaps, usages, 0); |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 779 | Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 780 | if (texAlloc == nullptr) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 781 | ALOGE("Memory allocation failure"); |
Chris Wailes | 44bef6f | 2014-08-12 13:51:10 -0700 | [diff] [blame] | 782 | return nullptr; |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 783 | } |
| 784 | |
Alex Sakhartchouk | 9f8bc4f | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 785 | uint32_t faceSize = t->getDimX(); |
| 786 | uint32_t strideBytes = faceSize * 6 * t->getElementSizeBytes(); |
| 787 | uint32_t copySize = faceSize * t->getElementSizeBytes(); |
| 788 | |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 789 | uint8_t *sourcePtr = (uint8_t*)data; |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 790 | for (uint32_t face = 0; face < 6; face ++) { |
Alex Sakhartchouk | 9f8bc4f | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 791 | for (uint32_t dI = 0; dI < faceSize; dI ++) { |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 792 | texAlloc->data(rsc, 0, dI, 0, (RsAllocationCubemapFace)face, |
Tim Murray | 60c2796 | 2013-02-07 16:15:23 -0800 | [diff] [blame] | 793 | t->getDimX(), 1, sourcePtr + strideBytes * dI, copySize, 0); |
Alex Sakhartchouk | 9f8bc4f | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 794 | } |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 795 | |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 796 | // Move the data pointer to the next cube face |
Alex Sakhartchouk | 9f8bc4f | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 797 | sourcePtr += copySize; |
Alex Sakhartchouk | f8aafcf | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 798 | } |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 799 | |
Stephen Hines | 8f615d6 | 2013-12-20 12:23:32 -0800 | [diff] [blame] | 800 | if (mipmaps == RS_ALLOCATION_MIPMAP_FULL) { |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 801 | rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc); |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 802 | } |
| 803 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 804 | texAlloc->sendDirty(rsc); |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 805 | return texAlloc; |
| 806 | } |
Alex Sakhartchouk | 099d7d3 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 807 | |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 808 | void rsi_AllocationCopy2DRange(Context *rsc, |
| 809 | RsAllocation dstAlloc, |
| 810 | uint32_t dstXoff, uint32_t dstYoff, |
| 811 | uint32_t dstMip, uint32_t dstFace, |
| 812 | uint32_t width, uint32_t height, |
| 813 | RsAllocation srcAlloc, |
| 814 | uint32_t srcXoff, uint32_t srcYoff, |
| 815 | uint32_t srcMip, uint32_t srcFace) { |
| 816 | Allocation *dst = static_cast<Allocation *>(dstAlloc); |
| 817 | Allocation *src= static_cast<Allocation *>(srcAlloc); |
| 818 | rsc->mHal.funcs.allocation.allocData2D(rsc, dst, dstXoff, dstYoff, dstMip, |
| 819 | (RsAllocationCubemapFace)dstFace, |
| 820 | width, height, |
| 821 | src, srcXoff, srcYoff,srcMip, |
| 822 | (RsAllocationCubemapFace)srcFace); |
| 823 | } |
| 824 | |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 825 | void rsi_AllocationCopy3DRange(Context *rsc, |
| 826 | RsAllocation dstAlloc, |
| 827 | uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff, |
| 828 | uint32_t dstMip, |
| 829 | uint32_t width, uint32_t height, uint32_t depth, |
| 830 | RsAllocation srcAlloc, |
| 831 | uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, |
| 832 | uint32_t srcMip) { |
| 833 | Allocation *dst = static_cast<Allocation *>(dstAlloc); |
| 834 | Allocation *src= static_cast<Allocation *>(srcAlloc); |
| 835 | rsc->mHal.funcs.allocation.allocData3D(rsc, dst, dstXoff, dstYoff, dstZoff, dstMip, |
| 836 | width, height, depth, |
| 837 | src, srcXoff, srcYoff, srcZoff, srcMip); |
| 838 | } |
| 839 | |
| 840 | |
Jason Sams | 733396b | 2013-02-22 12:46:18 -0800 | [diff] [blame] | 841 | void * rsi_AllocationGetSurface(Context *rsc, RsAllocation valloc) { |
Jason Sams | 41e373d | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 842 | Allocation *alloc = static_cast<Allocation *>(valloc); |
Jason Sams | 733396b | 2013-02-22 12:46:18 -0800 | [diff] [blame] | 843 | void *s = alloc->getSurface(rsc); |
| 844 | return s; |
Jason Sams | 3522f40 | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 845 | } |
| 846 | |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 847 | void rsi_AllocationSetSurface(Context *rsc, RsAllocation valloc, RsNativeWindow sur) { |
| 848 | Allocation *alloc = static_cast<Allocation *>(valloc); |
| 849 | alloc->setSurface(rsc, sur); |
| 850 | } |
| 851 | |
| 852 | void rsi_AllocationIoSend(Context *rsc, RsAllocation valloc) { |
| 853 | Allocation *alloc = static_cast<Allocation *>(valloc); |
| 854 | alloc->ioSend(rsc); |
| 855 | } |
| 856 | |
| 857 | void rsi_AllocationIoReceive(Context *rsc, RsAllocation valloc) { |
| 858 | Allocation *alloc = static_cast<Allocation *>(valloc); |
| 859 | alloc->ioReceive(rsc); |
| 860 | } |
| 861 | |
Stephen Hines | af7373f | 2014-09-11 00:58:18 -0700 | [diff] [blame] | 862 | void *rsi_AllocationGetPointer(Context *rsc, RsAllocation valloc, |
Jason Sams | b8a94e2 | 2014-02-24 17:52:32 -0800 | [diff] [blame] | 863 | uint32_t lod, RsAllocationCubemapFace face, |
| 864 | uint32_t z, uint32_t array, size_t *stride, size_t strideLen) { |
| 865 | Allocation *alloc = static_cast<Allocation *>(valloc); |
Tim Murray | 0e61af9 | 2014-02-26 13:28:52 -0800 | [diff] [blame] | 866 | rsAssert(strideLen == sizeof(size_t)); |
Jason Sams | b8a94e2 | 2014-02-24 17:52:32 -0800 | [diff] [blame] | 867 | |
Stephen Hines | af7373f | 2014-09-11 00:58:18 -0700 | [diff] [blame] | 868 | return alloc->getPointer(rsc, lod, face, z, array, stride); |
Jason Sams | b8a94e2 | 2014-02-24 17:52:32 -0800 | [diff] [blame] | 869 | } |
| 870 | |
Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 871 | void rsi_Allocation1DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod, |
| 872 | uint32_t count, void *data, size_t sizeBytes) { |
| 873 | Allocation *a = static_cast<Allocation *>(va); |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame] | 874 | rsc->mHal.funcs.allocation.read1D(rsc, a, xoff, lod, count, data, sizeBytes); |
Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 875 | } |
| 876 | |
Miao Wang | cc8cea7 | 2015-02-19 18:14:46 -0800 | [diff] [blame] | 877 | void rsi_AllocationElementRead(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t z, |
| 878 | uint32_t lod, void *data, size_t sizeBytes, size_t eoff) { |
| 879 | Allocation *a = static_cast<Allocation *>(va); |
| 880 | a->elementRead(rsc, x, y, z, data, eoff, sizeBytes); |
| 881 | } |
| 882 | |
Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 883 | void rsi_Allocation2DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, |
| 884 | uint32_t lod, RsAllocationCubemapFace face, uint32_t w, |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 885 | uint32_t h, void *data, size_t sizeBytes, size_t stride) { |
Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 886 | Allocation *a = static_cast<Allocation *>(va); |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 887 | a->read(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride); |
Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 888 | } |
| 889 | |
Miao Wang | cc8cea7 | 2015-02-19 18:14:46 -0800 | [diff] [blame] | 890 | void rsi_Allocation3DRead(Context *rsc, RsAllocation va, |
| 891 | uint32_t xoff, uint32_t yoff, uint32_t zoff, |
| 892 | uint32_t lod, uint32_t w, uint32_t h, uint32_t d, |
| 893 | void *data, size_t sizeBytes, size_t stride) { |
| 894 | Allocation *a = static_cast<Allocation *>(va); |
| 895 | a->read(rsc, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride); |
| 896 | } |
| 897 | |
Jason Sams | cfea6c1 | 2015-02-09 12:50:22 -0800 | [diff] [blame] | 898 | RsAllocation rsi_AllocationAdapterCreate(Context *rsc, RsType vwindow, RsAllocation vbase) { |
| 899 | |
| 900 | |
| 901 | Allocation * alloc = Allocation::createAdapter(rsc, |
| 902 | static_cast<Allocation *>(vbase), static_cast<Type *>(vwindow)); |
| 903 | if (!alloc) { |
| 904 | return nullptr; |
| 905 | } |
| 906 | alloc->incUserRef(); |
| 907 | return alloc; |
| 908 | } |
| 909 | |
| 910 | void rsi_AllocationAdapterOffset(Context *rsc, RsAllocation va, const uint32_t *offsets, size_t len) { |
Jason Sams | 442b7ff | 2015-03-06 16:50:11 -0800 | [diff] [blame] | 911 | Allocation *a = static_cast<Allocation *>(va); |
| 912 | a->adapterOffset(rsc, offsets, len); |
Jason Sams | cfea6c1 | 2015-02-09 12:50:22 -0800 | [diff] [blame] | 913 | } |
| 914 | |
| 915 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 916 | } |
| 917 | } |
| 918 | |
Tim Murray | c2ce707 | 2013-07-17 18:38:53 -0700 | [diff] [blame] | 919 | extern "C" const void * rsaAllocationGetType(RsContext con, RsAllocation va) { |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 920 | Allocation *a = static_cast<Allocation *>(va); |
| 921 | a->getType()->incUserRef(); |
| 922 | |
| 923 | return a->getType(); |
| 924 | } |