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