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