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 | |
Tim Murray | 0b575de | 2013-03-15 15:56:43 -0700 | [diff] [blame] | 22 | #ifndef RS_SERVER |
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 | |
Tim Murray | 3468938 | 2013-03-11 12:12:03 -0700 | [diff] [blame] | 44 | void Allocation::operator delete(void* ptr) { |
| 45 | if (ptr) { |
| 46 | Allocation *a = (Allocation*) ptr; |
| 47 | a->getContext()->mHal.funcs.freeRuntimeMem(ptr); |
| 48 | } |
| 49 | } |
| 50 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 51 | Allocation * Allocation::createAllocation(Context *rsc, const Type *type, uint32_t usages, |
Jason Sams | 179e9a4 | 2011-11-23 15:02:15 -0800 | [diff] [blame] | 52 | RsAllocationMipmapControl mc, void * ptr) { |
Tim Murray | 3468938 | 2013-03-11 12:12:03 -0700 | [diff] [blame] | 53 | // Allocation objects must use allocator specified by the driver |
| 54 | void* allocMem = rsc->mHal.funcs.allocRuntimeMem(sizeof(Allocation), 0); |
| 55 | |
| 56 | if (!allocMem) { |
| 57 | rsc->setError(RS_ERROR_FATAL_DRIVER, "Couldn't allocate memory for Allocation"); |
| 58 | return NULL; |
| 59 | } |
| 60 | |
| 61 | Allocation *a = new (allocMem) Allocation(rsc, type, usages, mc, ptr); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 62 | |
| 63 | if (!rsc->mHal.funcs.allocation.init(rsc, a, type->getElement()->getHasReferences())) { |
| 64 | rsc->setError(RS_ERROR_FATAL_DRIVER, "Allocation::Allocation, alloc failure"); |
| 65 | delete a; |
| 66 | return NULL; |
| 67 | } |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 68 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 69 | return a; |
| 70 | } |
| 71 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 72 | void Allocation::updateCache() { |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 73 | const Type *type = mHal.state.type; |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 74 | mHal.state.yuv = type->getDimYuv(); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 75 | mHal.state.hasFaces = type->getDimFaces(); |
| 76 | mHal.state.hasMipmaps = type->getDimLOD(); |
| 77 | mHal.state.elementSizeBytes = type->getElementSizeBytes(); |
| 78 | mHal.state.hasReferences = mHal.state.type->getElement()->getHasReferences(); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 79 | } |
| 80 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 81 | Allocation::~Allocation() { |
Jason Sams | c7cec1e | 2011-08-18 18:01:33 -0700 | [diff] [blame] | 82 | freeChildrenUnlocked(); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 83 | mRSC->mHal.funcs.allocation.destroy(mRSC, this); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 86 | void Allocation::syncAll(Context *rsc, RsAllocationUsageType src) { |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 87 | rsc->mHal.funcs.allocation.syncAll(rsc, this, src); |
Jason Sams | cf4c7c9 | 2009-12-14 12:57:40 -0800 | [diff] [blame] | 88 | } |
| 89 | |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 90 | void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod, |
Stephen Hines | 6ae039b | 2012-01-18 18:46:27 -0800 | [diff] [blame] | 91 | uint32_t count, const void *data, size_t sizeBytes) { |
| 92 | const size_t eSize = mHal.state.type->getElementSizeBytes(); |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 93 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 94 | if ((count * eSize) != sizeBytes) { |
Stephen Hines | 6ae039b | 2012-01-18 18:46:27 -0800 | [diff] [blame] | 95 | ALOGE("Allocation::subData called with mismatched size expected %zu, got %zu", |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 96 | (count * eSize), sizeBytes); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 97 | mHal.state.type->dumpLOGV("type info"); |
Jason Sams | 9397e30 | 2009-08-27 20:23:34 -0700 | [diff] [blame] | 98 | return; |
| 99 | } |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 100 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 101 | rsc->mHal.funcs.allocation.data1D(rsc, this, xoff, lod, count, data, sizeBytes); |
| 102 | sendDirty(rsc); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 105 | 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] | 106 | 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] | 107 | 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] | 108 | sendDirty(rsc); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Jason Sams | 236385b | 2011-01-12 14:53:25 -0800 | [diff] [blame] | 111 | 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^] | 112 | uint32_t lod, |
| 113 | uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, size_t stride) { |
| 114 | rsc->mHal.funcs.allocation.data3D(rsc, this, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride); |
| 115 | sendDirty(rsc); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 116 | } |
| 117 | |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 118 | void Allocation::read(Context *rsc, uint32_t xoff, uint32_t lod, |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 119 | uint32_t count, void *data, size_t sizeBytes) { |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 120 | const size_t eSize = mHal.state.type->getElementSizeBytes(); |
| 121 | |
| 122 | if ((count * eSize) != sizeBytes) { |
| 123 | ALOGE("Allocation::read called with mismatched size expected %zu, got %zu", |
| 124 | (count * eSize), sizeBytes); |
| 125 | mHal.state.type->dumpLOGV("type info"); |
| 126 | return; |
| 127 | } |
| 128 | |
| 129 | rsc->mHal.funcs.allocation.read1D(rsc, this, xoff, lod, count, data, sizeBytes); |
| 130 | } |
| 131 | |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 132 | void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face, |
| 133 | uint32_t w, uint32_t h, void *data, size_t sizeBytes, size_t stride) { |
| 134 | const size_t eSize = mHal.state.elementSizeBytes; |
| 135 | const size_t lineSize = eSize * w; |
| 136 | if (!stride) { |
| 137 | stride = lineSize; |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame^] | 138 | } else { |
| 139 | if ((lineSize * h) != sizeBytes) { |
| 140 | ALOGE("Allocation size mismatch, expected %zu, got %zu", (lineSize * h), sizeBytes); |
| 141 | rsAssert(!"Allocation::read called with mismatched size"); |
| 142 | return; |
| 143 | } |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | 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] | 147 | } |
| 148 | |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame^] | 149 | void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, |
| 150 | uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes, size_t stride) { |
| 151 | const size_t eSize = mHal.state.elementSizeBytes; |
| 152 | const size_t lineSize = eSize * w; |
| 153 | if (!stride) { |
| 154 | stride = lineSize; |
| 155 | } |
| 156 | |
| 157 | rsc->mHal.funcs.allocation.read3D(rsc, this, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride); |
| 158 | |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 161 | void Allocation::elementData(Context *rsc, uint32_t x, const void *data, |
Stephen Hines | 6ae039b | 2012-01-18 18:46:27 -0800 | [diff] [blame] | 162 | uint32_t cIdx, size_t sizeBytes) { |
| 163 | size_t eSize = mHal.state.elementSizeBytes; |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 164 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 165 | if (cIdx >= mHal.state.type->getElement()->getFieldCount()) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 166 | ALOGE("Error Allocation::subElementData component %i out of range.", cIdx); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 167 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range."); |
| 168 | return; |
| 169 | } |
| 170 | |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 171 | if (x >= mHal.drvState.lod[0].dimX) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 172 | ALOGE("Error Allocation::subElementData X offset %i out of range.", x); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 173 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); |
| 174 | return; |
| 175 | } |
| 176 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 177 | const Element * e = mHal.state.type->getElement()->getField(cIdx); |
Alex Sakhartchouk | 7694632 | 2012-02-02 09:47:26 -0800 | [diff] [blame] | 178 | uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx); |
| 179 | if (sizeBytes != e->getSizeBytes() * elemArraySize) { |
Stephen Hines | 6ae039b | 2012-01-18 18:46:27 -0800 | [diff] [blame] | 180 | ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes()); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 181 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size."); |
| 182 | return; |
| 183 | } |
| 184 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 185 | rsc->mHal.funcs.allocation.elementData1D(rsc, this, x, data, cIdx, sizeBytes); |
| 186 | sendDirty(rsc); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 189 | void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y, |
Stephen Hines | 6ae039b | 2012-01-18 18:46:27 -0800 | [diff] [blame] | 190 | const void *data, uint32_t cIdx, size_t sizeBytes) { |
| 191 | size_t eSize = mHal.state.elementSizeBytes; |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 192 | |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 193 | if (x >= mHal.drvState.lod[0].dimX) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 194 | ALOGE("Error Allocation::subElementData X offset %i out of range.", x); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 195 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); |
| 196 | return; |
| 197 | } |
| 198 | |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 199 | if (y >= mHal.drvState.lod[0].dimY) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 200 | ALOGE("Error Allocation::subElementData X offset %i out of range.", x); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 201 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); |
| 202 | return; |
| 203 | } |
| 204 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 205 | if (cIdx >= mHal.state.type->getElement()->getFieldCount()) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 206 | ALOGE("Error Allocation::subElementData component %i out of range.", cIdx); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 207 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range."); |
| 208 | return; |
| 209 | } |
| 210 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 211 | const Element * e = mHal.state.type->getElement()->getField(cIdx); |
Alex Sakhartchouk | 7694632 | 2012-02-02 09:47:26 -0800 | [diff] [blame] | 212 | uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx); |
| 213 | if (sizeBytes != e->getSizeBytes() * elemArraySize) { |
Stephen Hines | 6ae039b | 2012-01-18 18:46:27 -0800 | [diff] [blame] | 214 | ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes()); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 215 | rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size."); |
| 216 | return; |
| 217 | } |
| 218 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 219 | rsc->mHal.funcs.allocation.elementData2D(rsc, this, x, y, data, cIdx, sizeBytes); |
| 220 | sendDirty(rsc); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 223 | void Allocation::addProgramToDirty(const Program *p) { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 224 | mToDirtyList.push(p); |
Jason Sams | 5c3e3bc | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 225 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 226 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 227 | void Allocation::removeProgramToDirty(const Program *p) { |
Jason Sams | 5c3e3bc | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 228 | for (size_t ct=0; ct < mToDirtyList.size(); ct++) { |
| 229 | if (mToDirtyList[ct] == p) { |
| 230 | mToDirtyList.removeAt(ct); |
| 231 | return; |
| 232 | } |
| 233 | } |
| 234 | rsAssert(0); |
| 235 | } |
| 236 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 237 | void Allocation::dumpLOGV(const char *prefix) const { |
Jason Sams | c21cf40 | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 238 | ObjectBase::dumpLOGV(prefix); |
| 239 | |
| 240 | String8 s(prefix); |
| 241 | s.append(" type "); |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 242 | if (mHal.state.type) { |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 243 | mHal.state.type->dumpLOGV(s.string()); |
Jason Sams | c21cf40 | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 244 | } |
| 245 | |
Steve Block | 6598201 | 2011-10-20 11:56:00 +0100 | [diff] [blame] | 246 | ALOGV("%s allocation ptr=%p mUsageFlags=0x04%x, mMipmapControl=0x%04x", |
Jason Sams | 709a097 | 2012-11-15 18:18:04 -0800 | [diff] [blame] | 247 | prefix, mHal.drvState.lod[0].mallocPtr, mHal.state.usageFlags, mHal.state.mipmapControl); |
Jason Sams | c21cf40 | 2009-11-17 17:26:46 -0800 | [diff] [blame] | 248 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 249 | |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 250 | uint32_t Allocation::getPackedSize() const { |
| 251 | uint32_t numItems = mHal.state.type->getSizeBytes() / mHal.state.type->getElementSizeBytes(); |
| 252 | return numItems * mHal.state.type->getElement()->getSizeBytesUnpadded(); |
| 253 | } |
| 254 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 255 | void Allocation::writePackedData(Context *rsc, const Type *type, |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 256 | uint8_t *dst, const uint8_t *src, bool dstPadded) { |
| 257 | const Element *elem = type->getElement(); |
| 258 | uint32_t unpaddedBytes = elem->getSizeBytesUnpadded(); |
| 259 | uint32_t paddedBytes = elem->getSizeBytes(); |
| 260 | uint32_t numItems = type->getSizeBytes() / paddedBytes; |
| 261 | |
| 262 | uint32_t srcInc = !dstPadded ? paddedBytes : unpaddedBytes; |
| 263 | uint32_t dstInc = dstPadded ? paddedBytes : unpaddedBytes; |
| 264 | |
| 265 | // no sub-elements |
| 266 | uint32_t fieldCount = elem->getFieldCount(); |
| 267 | if (fieldCount == 0) { |
| 268 | for (uint32_t i = 0; i < numItems; i ++) { |
| 269 | memcpy(dst, src, unpaddedBytes); |
| 270 | src += srcInc; |
| 271 | dst += dstInc; |
| 272 | } |
| 273 | return; |
| 274 | } |
| 275 | |
| 276 | // Cache offsets |
| 277 | uint32_t *offsetsPadded = new uint32_t[fieldCount]; |
| 278 | uint32_t *offsetsUnpadded = new uint32_t[fieldCount]; |
| 279 | uint32_t *sizeUnpadded = new uint32_t[fieldCount]; |
| 280 | |
| 281 | for (uint32_t i = 0; i < fieldCount; i++) { |
| 282 | offsetsPadded[i] = elem->getFieldOffsetBytes(i); |
| 283 | offsetsUnpadded[i] = elem->getFieldOffsetBytesUnpadded(i); |
| 284 | sizeUnpadded[i] = elem->getField(i)->getSizeBytesUnpadded(); |
| 285 | } |
| 286 | |
| 287 | uint32_t *srcOffsets = !dstPadded ? offsetsPadded : offsetsUnpadded; |
| 288 | uint32_t *dstOffsets = dstPadded ? offsetsPadded : offsetsUnpadded; |
| 289 | |
| 290 | // complex elements, need to copy subelem after subelem |
| 291 | for (uint32_t i = 0; i < numItems; i ++) { |
| 292 | for (uint32_t fI = 0; fI < fieldCount; fI++) { |
| 293 | memcpy(dst + dstOffsets[fI], src + srcOffsets[fI], sizeUnpadded[fI]); |
| 294 | } |
| 295 | src += srcInc; |
| 296 | dst += dstInc; |
| 297 | } |
| 298 | |
| 299 | delete[] offsetsPadded; |
| 300 | delete[] offsetsUnpadded; |
| 301 | delete[] sizeUnpadded; |
| 302 | } |
| 303 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 304 | void Allocation::unpackVec3Allocation(Context *rsc, const void *data, size_t dataSize) { |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 305 | const uint8_t *src = (const uint8_t*)data; |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 306 | uint8_t *dst = (uint8_t *)rsc->mHal.funcs.allocation.lock1D(rsc, this); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 307 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 308 | writePackedData(rsc, getType(), dst, src, true); |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 309 | rsc->mHal.funcs.allocation.unlock1D(rsc, this); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 310 | } |
| 311 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 312 | void Allocation::packVec3Allocation(Context *rsc, OStream *stream) const { |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 313 | uint32_t paddedBytes = getType()->getElement()->getSizeBytes(); |
| 314 | uint32_t unpaddedBytes = getType()->getElement()->getSizeBytesUnpadded(); |
| 315 | uint32_t numItems = mHal.state.type->getSizeBytes() / paddedBytes; |
| 316 | |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 317 | 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] | 318 | uint8_t *dst = new uint8_t[numItems * unpaddedBytes]; |
| 319 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 320 | writePackedData(rsc, getType(), dst, src, false); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 321 | stream->addByteArray(dst, getPackedSize()); |
| 322 | |
| 323 | delete[] dst; |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 324 | rsc->mHal.funcs.allocation.unlock1D(rsc, this); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 325 | } |
| 326 | |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 327 | void Allocation::serialize(Context *rsc, OStream *stream) const { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 328 | // Need to identify ourselves |
| 329 | stream->addU32((uint32_t)getClassId()); |
| 330 | |
| 331 | String8 name(getName()); |
| 332 | stream->addString(&name); |
| 333 | |
| 334 | // First thing we need to serialize is the type object since it will be needed |
| 335 | // to initialize the class |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 336 | mHal.state.type->serialize(rsc, stream); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 337 | |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 338 | uint32_t dataSize = mHal.state.type->getSizeBytes(); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 339 | // 3 element vectors are padded to 4 in memory, but padding isn't serialized |
| 340 | uint32_t packedSize = getPackedSize(); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 341 | // Write how much data we are storing |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 342 | stream->addU32(packedSize); |
| 343 | if (dataSize == packedSize) { |
| 344 | // Now write the data |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 345 | stream->addByteArray(rsc->mHal.funcs.allocation.lock1D(rsc, this), dataSize); |
| 346 | rsc->mHal.funcs.allocation.unlock1D(rsc, this); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 347 | } else { |
| 348 | // Now write the data |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 349 | packVec3Allocation(rsc, stream); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 350 | } |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 353 | Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 354 | // First make sure we are reading the correct object |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 355 | RsA3DClassID classID = (RsA3DClassID)stream->loadU32(); |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 356 | if (classID != RS_A3D_CLASS_ID_ALLOCATION) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 357 | ALOGE("allocation loading skipped due to invalid class id\n"); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 358 | return NULL; |
| 359 | } |
| 360 | |
| 361 | String8 name; |
| 362 | stream->loadString(&name); |
| 363 | |
| 364 | Type *type = Type::createFromStream(rsc, stream); |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 365 | if (!type) { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 366 | return NULL; |
| 367 | } |
| 368 | type->compute(); |
| 369 | |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 370 | Allocation *alloc = Allocation::createAllocation(rsc, type, RS_ALLOCATION_USAGE_SCRIPT); |
| 371 | type->decUserRef(); |
| 372 | |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 373 | // Number of bytes we wrote out for this allocation |
| 374 | uint32_t dataSize = stream->loadU32(); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 375 | // 3 element vectors are padded to 4 in memory, but padding isn't serialized |
| 376 | uint32_t packedSize = alloc->getPackedSize(); |
| 377 | if (dataSize != type->getSizeBytes() && |
| 378 | dataSize != packedSize) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 379 | ALOGE("failed to read allocation because numbytes written is not the same loaded type wants\n"); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 380 | ObjectBase::checkDelete(alloc); |
Jason Sams | 225afd3 | 2010-10-21 14:06:55 -0700 | [diff] [blame] | 381 | ObjectBase::checkDelete(type); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 382 | return NULL; |
| 383 | } |
| 384 | |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 385 | alloc->setName(name.string(), name.size()); |
| 386 | |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 387 | if (dataSize == type->getSizeBytes()) { |
| 388 | uint32_t count = dataSize / type->getElementSizeBytes(); |
| 389 | // Read in all of our allocation data |
| 390 | alloc->data(rsc, 0, 0, count, stream->getPtr() + stream->getPos(), dataSize); |
| 391 | } else { |
Jason Sams | e3150cf | 2012-07-24 18:10:20 -0700 | [diff] [blame] | 392 | alloc->unpackVec3Allocation(rsc, stream->getPtr() + stream->getPos(), dataSize); |
Alex Sakhartchouk | 2d1220c | 2011-11-15 15:15:21 -0800 | [diff] [blame] | 393 | } |
Alex Sakhartchouk | e6d9fbc | 2010-08-11 10:30:44 -0700 | [diff] [blame] | 394 | stream->reset(stream->getPos() + dataSize); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 395 | |
| 396 | return alloc; |
| 397 | } |
| 398 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 399 | void Allocation::sendDirty(const Context *rsc) const { |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 400 | #ifndef RS_COMPATIBILITY_LIB |
Jason Sams | 5c3e3bc | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 401 | for (size_t ct=0; ct < mToDirtyList.size(); ct++) { |
| 402 | mToDirtyList[ct]->forceDirty(); |
| 403 | } |
Jason Sams | 93eacc7 | 2012-12-18 14:26:57 -0800 | [diff] [blame] | 404 | #endif |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 405 | mRSC->mHal.funcs.allocation.markDirty(rsc, this); |
Jason Sams | 5c3e3bc | 2009-10-26 15:19:28 -0700 | [diff] [blame] | 406 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 407 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 408 | 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] | 409 | mHal.state.type->incRefs(ptr, ct, startOff); |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 412 | 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] | 413 | if (!mHal.state.hasReferences || !getIsScript()) { |
| 414 | return; |
| 415 | } |
Stephen Hines | 9f70a4e | 2012-04-02 20:18:48 -0700 | [diff] [blame] | 416 | mHal.state.type->decRefs(ptr, ct, startOff); |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Jason Sams | c7cec1e | 2011-08-18 18:01:33 -0700 | [diff] [blame] | 419 | void Allocation::freeChildrenUnlocked () { |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 420 | void *ptr = mRSC->mHal.funcs.allocation.lock1D(mRSC, this); |
| 421 | decRefs(ptr, mHal.state.type->getSizeBytes() / mHal.state.type->getElementSizeBytes(), 0); |
| 422 | mRSC->mHal.funcs.allocation.unlock1D(mRSC, this); |
Jason Sams | c7cec1e | 2011-08-18 18:01:33 -0700 | [diff] [blame] | 423 | } |
| 424 | |
| 425 | bool Allocation::freeChildren() { |
| 426 | if (mHal.state.hasReferences) { |
| 427 | incSysRef(); |
| 428 | freeChildrenUnlocked(); |
| 429 | return decSysRef(); |
| 430 | } |
| 431 | return false; |
| 432 | } |
| 433 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 434 | 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] | 435 | } |
| 436 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 437 | void Allocation::resize1D(Context *rsc, uint32_t dimX) { |
Jason Sams | a572aca | 2013-01-09 11:52:26 -0800 | [diff] [blame] | 438 | uint32_t oldDimX = mHal.drvState.lod[0].dimX; |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 439 | if (dimX == oldDimX) { |
| 440 | return; |
| 441 | } |
| 442 | |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 443 | ObjectBaseRef<Type> t = mHal.state.type->cloneAndResize1D(rsc, dimX); |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 444 | if (dimX < oldDimX) { |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 445 | decRefs(rsc->mHal.funcs.allocation.lock1D(rsc, this), oldDimX - dimX, dimX); |
| 446 | rsc->mHal.funcs.allocation.unlock1D(rsc, this); |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 447 | } |
Alex Sakhartchouk | c700e64 | 2011-08-16 13:09:46 -0700 | [diff] [blame] | 448 | rsc->mHal.funcs.allocation.resize(rsc, this, t.get(), mHal.state.hasReferences); |
Alex Sakhartchouk | 064aa7e | 2011-10-18 10:54:29 -0700 | [diff] [blame] | 449 | setType(t.get()); |
Jason Sams | bad8074 | 2011-03-16 16:29:28 -0700 | [diff] [blame] | 450 | updateCache(); |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 451 | } |
| 452 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 453 | void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 454 | ALOGE("not implemented"); |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Jason Sams | 733396b | 2013-02-22 12:46:18 -0800 | [diff] [blame] | 457 | void * Allocation::getSurface(const Context *rsc) { |
| 458 | return rsc->mHal.funcs.allocation.getSurface(rsc, this); |
Jason Sams | 41e373d | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 459 | } |
| 460 | |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 461 | void Allocation::setSurface(const Context *rsc, RsNativeWindow sur) { |
| 462 | ANativeWindow *nw = (ANativeWindow *)sur; |
Jason Sams | 733396b | 2013-02-22 12:46:18 -0800 | [diff] [blame] | 463 | rsc->mHal.funcs.allocation.setSurface(rsc, this, nw); |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | void Allocation::ioSend(const Context *rsc) { |
| 467 | rsc->mHal.funcs.allocation.ioSend(rsc, this); |
| 468 | } |
| 469 | |
| 470 | void Allocation::ioReceive(const Context *rsc) { |
| 471 | rsc->mHal.funcs.allocation.ioReceive(rsc, this); |
| 472 | } |
| 473 | |
| 474 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 475 | ///////////////// |
Jason Sams | 565ac36 | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 476 | // |
Stephen Hines | 6a12181 | 2011-03-01 17:34:59 -0800 | [diff] [blame] | 477 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 478 | namespace android { |
| 479 | namespace renderscript { |
| 480 | |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 481 | void rsi_AllocationSyncAll(Context *rsc, RsAllocation va, RsAllocationUsageType src) { |
| 482 | Allocation *a = static_cast<Allocation *>(va); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 483 | a->sendDirty(rsc); |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 484 | a->syncAll(rsc, src); |
| 485 | } |
| 486 | |
Jason Sams | a237151 | 2011-01-12 13:28:37 -0800 | [diff] [blame] | 487 | void rsi_AllocationGenerateMipmaps(Context *rsc, RsAllocation va) { |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 488 | Allocation *alloc = static_cast<Allocation *>(va); |
| 489 | rsc->mHal.funcs.allocation.generateMipmaps(rsc, alloc); |
Jason Sams | 837e388 | 2010-12-10 16:03:15 -0800 | [diff] [blame] | 490 | } |
| 491 | |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 492 | void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) { |
| 493 | Allocation *a = static_cast<Allocation *>(va); |
| 494 | const Type * t = a->getType(); |
| 495 | a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame^] | 496 | t->getDimX(), t->getDimY(), data, sizeBytes, 0); |
Alex Sakhartchouk | 39f2ef6 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 497 | } |
| 498 | |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 499 | 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] | 500 | uint32_t count, const void *data, size_t sizeBytes) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 501 | Allocation *a = static_cast<Allocation *>(va); |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 502 | a->data(rsc, xoff, lod, count, data, sizeBytes); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 505 | void rsi_Allocation2DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t lod, RsAllocationCubemapFace face, |
Stephen Hines | 6ae039b | 2012-01-18 18:46:27 -0800 | [diff] [blame] | 506 | const void *data, size_t sizeBytes, size_t eoff) { |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 507 | Allocation *a = static_cast<Allocation *>(va); |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 508 | a->elementData(rsc, x, y, data, eoff, sizeBytes); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 511 | void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod, |
Stephen Hines | 6ae039b | 2012-01-18 18:46:27 -0800 | [diff] [blame] | 512 | const void *data, size_t sizeBytes, size_t eoff) { |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 513 | Allocation *a = static_cast<Allocation *>(va); |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 514 | a->elementData(rsc, x, data, eoff, sizeBytes); |
Jason Sams | 5f0c84c | 2010-08-31 13:50:42 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Jason Sams | 4b45b89 | 2010-12-29 14:31:29 -0800 | [diff] [blame] | 517 | 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] | 518 | 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] | 519 | Allocation *a = static_cast<Allocation *>(va); |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 520 | a->data(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 521 | } |
| 522 | |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame^] | 523 | void rsi_Allocation3DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod, |
| 524 | uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, size_t stride) { |
| 525 | Allocation *a = static_cast<Allocation *>(va); |
| 526 | a->data(rsc, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride); |
| 527 | } |
| 528 | |
| 529 | |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 530 | void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) { |
Jason Sams | e579df4 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 531 | Allocation *a = static_cast<Allocation *>(va); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 532 | const Type * t = a->getType(); |
| 533 | if(t->getDimY()) { |
| 534 | a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame^] | 535 | t->getDimX(), t->getDimY(), data, sizeBytes, 0); |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 536 | } else { |
| 537 | a->read(rsc, 0, 0, t->getDimX(), data, sizeBytes); |
| 538 | } |
| 539 | |
Jason Sams | e579df4 | 2009-08-10 14:55:26 -0700 | [diff] [blame] | 540 | } |
| 541 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 542 | void rsi_AllocationResize1D(Context *rsc, RsAllocation va, uint32_t dimX) { |
Jason Sams | 96abf81 | 2010-10-05 13:32:49 -0700 | [diff] [blame] | 543 | Allocation *a = static_cast<Allocation *>(va); |
| 544 | a->resize1D(rsc, dimX); |
| 545 | } |
| 546 | |
Alex Sakhartchouk | afb743a | 2010-11-09 17:00:54 -0800 | [diff] [blame] | 547 | 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] | 548 | Allocation *a = static_cast<Allocation *>(va); |
| 549 | a->resize2D(rsc, dimX, dimY); |
| 550 | } |
| 551 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 552 | RsAllocation rsi_AllocationCreateTyped(Context *rsc, RsType vtype, |
| 553 | RsAllocationMipmapControl mips, |
Tim Murray | 099bc26 | 2013-03-20 16:54:03 -0700 | [diff] [blame] | 554 | uint32_t usages, uintptr_t ptr) { |
| 555 | Allocation * alloc = Allocation::createAllocation(rsc, static_cast<Type *>(vtype), usages, mips, (void*)ptr); |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 556 | if (!alloc) { |
| 557 | return NULL; |
| 558 | } |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 559 | alloc->incUserRef(); |
| 560 | return alloc; |
| 561 | } |
| 562 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 563 | RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, RsType vtype, |
| 564 | RsAllocationMipmapControl mips, |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 565 | const void *data, size_t sizeBytes, uint32_t usages) { |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 566 | Type *t = static_cast<Type *>(vtype); |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 567 | |
Jason Sams | 179e9a4 | 2011-11-23 15:02:15 -0800 | [diff] [blame] | 568 | RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0); |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 569 | Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc); |
| 570 | if (texAlloc == NULL) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 571 | ALOGE("Memory allocation failure"); |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 572 | return NULL; |
| 573 | } |
| 574 | |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 575 | texAlloc->data(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X, |
Tim Murray | 60c2796 | 2013-02-07 16:15:23 -0800 | [diff] [blame] | 576 | t->getDimX(), t->getDimY(), data, sizeBytes, 0); |
Jason Sams | ebc5019 | 2010-12-13 15:32:35 -0800 | [diff] [blame] | 577 | if (mips == RS_ALLOCATION_MIPMAP_FULL) { |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 578 | rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc); |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 579 | } |
| 580 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 581 | texAlloc->sendDirty(rsc); |
Jason Sams | f0c1df4 | 2010-10-26 13:09:17 -0700 | [diff] [blame] | 582 | return texAlloc; |
| 583 | } |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 584 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 585 | RsAllocation rsi_AllocationCubeCreateFromBitmap(Context *rsc, RsType vtype, |
| 586 | RsAllocationMipmapControl mips, |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 587 | const void *data, size_t sizeBytes, uint32_t usages) { |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 588 | Type *t = static_cast<Type *>(vtype); |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 589 | |
| 590 | // Cubemap allocation's faces should be Width by Width each. |
| 591 | // Source data should have 6 * Width by Width pixels |
| 592 | // Error checking is done in the java layer |
Jason Sams | 179e9a4 | 2011-11-23 15:02:15 -0800 | [diff] [blame] | 593 | RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0); |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 594 | Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc); |
| 595 | if (texAlloc == NULL) { |
Steve Block | af12ac6 | 2012-01-06 19:20:56 +0000 | [diff] [blame] | 596 | ALOGE("Memory allocation failure"); |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 597 | return NULL; |
| 598 | } |
| 599 | |
Alex Sakhartchouk | 9f8bc4f | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 600 | uint32_t faceSize = t->getDimX(); |
| 601 | uint32_t strideBytes = faceSize * 6 * t->getElementSizeBytes(); |
| 602 | uint32_t copySize = faceSize * t->getElementSizeBytes(); |
| 603 | |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 604 | uint8_t *sourcePtr = (uint8_t*)data; |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 605 | for (uint32_t face = 0; face < 6; face ++) { |
Alex Sakhartchouk | 9f8bc4f | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 606 | for (uint32_t dI = 0; dI < faceSize; dI ++) { |
Jason Sams | 807fdc4 | 2012-07-25 17:55:39 -0700 | [diff] [blame] | 607 | texAlloc->data(rsc, 0, dI, 0, (RsAllocationCubemapFace)face, |
Tim Murray | 60c2796 | 2013-02-07 16:15:23 -0800 | [diff] [blame] | 608 | t->getDimX(), 1, sourcePtr + strideBytes * dI, copySize, 0); |
Alex Sakhartchouk | 9f8bc4f | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 609 | } |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 610 | |
Jason Sams | 366c9c8 | 2010-12-08 16:14:36 -0800 | [diff] [blame] | 611 | // Move the data pointer to the next cube face |
Alex Sakhartchouk | 9f8bc4f | 2011-01-10 15:57:57 -0800 | [diff] [blame] | 612 | sourcePtr += copySize; |
Alex Sakhartchouk | f8aafcf | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 613 | } |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 614 | |
Alex Sakhartchouk | f8aafcf | 2011-01-11 14:47:44 -0800 | [diff] [blame] | 615 | if (mips == RS_ALLOCATION_MIPMAP_FULL) { |
Jason Sams | 61a4bb7 | 2012-07-25 19:33:43 -0700 | [diff] [blame] | 616 | rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc); |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 617 | } |
| 618 | |
Jason Sams | eb4fe18 | 2011-05-26 16:33:01 -0700 | [diff] [blame] | 619 | texAlloc->sendDirty(rsc); |
Alex Sakhartchouk | 84e4027 | 2010-11-18 15:22:43 -0800 | [diff] [blame] | 620 | return texAlloc; |
| 621 | } |
Alex Sakhartchouk | 099d7d3 | 2011-01-28 09:31:47 -0800 | [diff] [blame] | 622 | |
Alex Sakhartchouk | 74a8279 | 2011-06-14 11:13:19 -0700 | [diff] [blame] | 623 | void rsi_AllocationCopy2DRange(Context *rsc, |
| 624 | RsAllocation dstAlloc, |
| 625 | uint32_t dstXoff, uint32_t dstYoff, |
| 626 | uint32_t dstMip, uint32_t dstFace, |
| 627 | uint32_t width, uint32_t height, |
| 628 | RsAllocation srcAlloc, |
| 629 | uint32_t srcXoff, uint32_t srcYoff, |
| 630 | uint32_t srcMip, uint32_t srcFace) { |
| 631 | Allocation *dst = static_cast<Allocation *>(dstAlloc); |
| 632 | Allocation *src= static_cast<Allocation *>(srcAlloc); |
| 633 | rsc->mHal.funcs.allocation.allocData2D(rsc, dst, dstXoff, dstYoff, dstMip, |
| 634 | (RsAllocationCubemapFace)dstFace, |
| 635 | width, height, |
| 636 | src, srcXoff, srcYoff,srcMip, |
| 637 | (RsAllocationCubemapFace)srcFace); |
| 638 | } |
| 639 | |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame^] | 640 | void rsi_AllocationCopy3DRange(Context *rsc, |
| 641 | RsAllocation dstAlloc, |
| 642 | uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff, |
| 643 | uint32_t dstMip, |
| 644 | uint32_t width, uint32_t height, uint32_t depth, |
| 645 | RsAllocation srcAlloc, |
| 646 | uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff, |
| 647 | uint32_t srcMip) { |
| 648 | Allocation *dst = static_cast<Allocation *>(dstAlloc); |
| 649 | Allocation *src= static_cast<Allocation *>(srcAlloc); |
| 650 | rsc->mHal.funcs.allocation.allocData3D(rsc, dst, dstXoff, dstYoff, dstZoff, dstMip, |
| 651 | width, height, depth, |
| 652 | src, srcXoff, srcYoff, srcZoff, srcMip); |
| 653 | } |
| 654 | |
| 655 | |
Jason Sams | 733396b | 2013-02-22 12:46:18 -0800 | [diff] [blame] | 656 | void * rsi_AllocationGetSurface(Context *rsc, RsAllocation valloc) { |
Jason Sams | 41e373d | 2012-01-13 14:01:20 -0800 | [diff] [blame] | 657 | Allocation *alloc = static_cast<Allocation *>(valloc); |
Jason Sams | 733396b | 2013-02-22 12:46:18 -0800 | [diff] [blame] | 658 | void *s = alloc->getSurface(rsc); |
| 659 | return s; |
Jason Sams | 3522f40 | 2012-03-23 11:47:26 -0700 | [diff] [blame] | 660 | } |
| 661 | |
Jason Sams | 7ac2a4d | 2012-02-15 12:04:24 -0800 | [diff] [blame] | 662 | void rsi_AllocationSetSurface(Context *rsc, RsAllocation valloc, RsNativeWindow sur) { |
| 663 | Allocation *alloc = static_cast<Allocation *>(valloc); |
| 664 | alloc->setSurface(rsc, sur); |
| 665 | } |
| 666 | |
| 667 | void rsi_AllocationIoSend(Context *rsc, RsAllocation valloc) { |
| 668 | Allocation *alloc = static_cast<Allocation *>(valloc); |
| 669 | alloc->ioSend(rsc); |
| 670 | } |
| 671 | |
| 672 | void rsi_AllocationIoReceive(Context *rsc, RsAllocation valloc) { |
| 673 | Allocation *alloc = static_cast<Allocation *>(valloc); |
| 674 | alloc->ioReceive(rsc); |
| 675 | } |
| 676 | |
Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 677 | void rsi_Allocation1DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod, |
| 678 | uint32_t count, void *data, size_t sizeBytes) { |
| 679 | Allocation *a = static_cast<Allocation *>(va); |
Jason Sams | 3bbc0fd | 2013-04-09 14:16:13 -0700 | [diff] [blame^] | 680 | rsc->mHal.funcs.allocation.read1D(rsc, a, xoff, lod, count, data, sizeBytes); |
Tim Murray | 509ea5c | 2012-11-13 11:56:40 -0800 | [diff] [blame] | 681 | } |
| 682 | |
Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 683 | void rsi_Allocation2DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, |
| 684 | uint32_t lod, RsAllocationCubemapFace face, uint32_t w, |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 685 | uint32_t h, void *data, size_t sizeBytes, size_t stride) { |
Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 686 | Allocation *a = static_cast<Allocation *>(va); |
Tim Murray | 358747a | 2012-11-26 13:52:04 -0800 | [diff] [blame] | 687 | a->read(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride); |
Tim Murray | 7b3e309 | 2012-11-16 13:32:24 -0800 | [diff] [blame] | 688 | } |
| 689 | |
Jason Sams | c975cf4 | 2011-04-28 18:26:48 -0700 | [diff] [blame] | 690 | } |
| 691 | } |
| 692 | |
| 693 | const void * rsaAllocationGetType(RsContext con, RsAllocation va) { |
| 694 | Allocation *a = static_cast<Allocation *>(va); |
| 695 | a->getType()->incUserRef(); |
| 696 | |
| 697 | return a->getType(); |
| 698 | } |