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