blob: df0a79ee687816045fbdd15521097e128e69ff77 [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
Stephen Hines6ae039b2012-01-18 18:46:27 -08002 * Copyright (C) 2009-2012 The Android Open Source Project
Jason Sams326e0dd2009-05-22 14:03:28 -07003 *
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 Sams326e0dd2009-05-22 14:03:28 -070016
Alex Sakhartchouk77d9f4b2011-01-31 14:53:24 -080017#include "rsContext.h"
Alex Sakhartchouk4edf0302012-03-09 10:47:27 -080018#include "rsAllocation.h"
19#include "rsAdapter.h"
Jason Samseb4fe182011-05-26 16:33:01 -070020#include "rs_hal.h"
21
Jason Sams7ac2a4d2012-02-15 12:04:24 -080022#include "system/window.h"
Jason Sams3522f402012-03-23 11:47:26 -070023#include "gui/SurfaceTexture.h"
Alex Sakhartchouk39f2ef62010-10-11 12:35:15 -070024
Jason Sams326e0dd2009-05-22 14:03:28 -070025using namespace android;
26using namespace android::renderscript;
27
Alex Sakhartchouka2aab8b2010-12-15 09:59:58 -080028Allocation::Allocation(Context *rsc, const Type *type, uint32_t usages,
Jason Sams179e9a42011-11-23 15:02:15 -080029 RsAllocationMipmapControl mc, void * ptr)
Alex Sakhartchouka2aab8b2010-12-15 09:59:58 -080030 : ObjectBase(rsc) {
Jason Samsfa84da22010-03-01 15:31:04 -080031
Jason Samseb4fe182011-05-26 16:33:01 -070032 memset(&mHal, 0, sizeof(mHal));
33 mHal.state.mipmapControl = RS_ALLOCATION_MIPMAP_NONE;
Jason Samsbad80742011-03-16 16:29:28 -070034 mHal.state.usageFlags = usages;
35 mHal.state.mipmapControl = mc;
Jason Sams366c9c82010-12-08 16:14:36 -080036
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070037 setType(type);
Jason Samsbad80742011-03-16 16:29:28 -070038 updateCache();
39}
Jason Samsfa84da22010-03-01 15:31:04 -080040
Jason Samseb4fe182011-05-26 16:33:01 -070041Allocation * Allocation::createAllocation(Context *rsc, const Type *type, uint32_t usages,
Jason Sams179e9a42011-11-23 15:02:15 -080042 RsAllocationMipmapControl mc, void * ptr) {
43 Allocation *a = new Allocation(rsc, type, usages, mc, ptr);
Jason Samseb4fe182011-05-26 16:33:01 -070044
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 Sams7ac2a4d2012-02-15 12:04:24 -080050
Jason Samseb4fe182011-05-26 16:33:01 -070051 return a;
52}
53
Jason Samsbad80742011-03-16 16:29:28 -070054void Allocation::updateCache() {
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070055 const Type *type = mHal.state.type;
Jason Samsbad80742011-03-16 16:29:28 -070056 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 Sams61462382012-08-29 11:57:40 -070063 mHal.state.eType = mHal.state.type->getElement()->getType();
Jason Sams326e0dd2009-05-22 14:03:28 -070064}
65
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080066Allocation::~Allocation() {
Jason Samsc7cec1e2011-08-18 18:01:33 -070067 freeChildrenUnlocked();
Jason Sams3522f402012-03-23 11:47:26 -070068 setSurfaceTexture(mRSC, NULL);
Jason Samseb4fe182011-05-26 16:33:01 -070069 mRSC->mHal.funcs.allocation.destroy(mRSC, this);
Jason Sams326e0dd2009-05-22 14:03:28 -070070}
71
Jason Sams366c9c82010-12-08 16:14:36 -080072void Allocation::syncAll(Context *rsc, RsAllocationUsageType src) {
Jason Samseb4fe182011-05-26 16:33:01 -070073 rsc->mHal.funcs.allocation.syncAll(rsc, this, src);
Jason Samscf4c7c92009-12-14 12:57:40 -080074}
75
Jason Sams4b45b892010-12-29 14:31:29 -080076void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod,
Stephen Hines6ae039b2012-01-18 18:46:27 -080077 uint32_t count, const void *data, size_t sizeBytes) {
78 const size_t eSize = mHal.state.type->getElementSizeBytes();
Jason Sams9397e302009-08-27 20:23:34 -070079
Jason Samseb4fe182011-05-26 16:33:01 -070080 if ((count * eSize) != sizeBytes) {
Stephen Hines6ae039b2012-01-18 18:46:27 -080081 ALOGE("Allocation::subData called with mismatched size expected %zu, got %zu",
Jason Samseb4fe182011-05-26 16:33:01 -070082 (count * eSize), sizeBytes);
Jason Samsbad80742011-03-16 16:29:28 -070083 mHal.state.type->dumpLOGV("type info");
Jason Sams9397e302009-08-27 20:23:34 -070084 return;
85 }
Jason Samse3929c92010-08-09 18:13:33 -070086
Jason Samseb4fe182011-05-26 16:33:01 -070087 rsc->mHal.funcs.allocation.data1D(rsc, this, xoff, lod, count, data, sizeBytes);
88 sendDirty(rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -070089}
90
Jason Sams4b45b892010-12-29 14:31:29 -080091void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
Tim Murray358747a2012-11-26 13:52:04 -080092 uint32_t w, uint32_t h, const void *data, size_t sizeBytes) {
93
Stephen Hines6ae039b2012-01-18 18:46:27 -080094 const size_t eSize = mHal.state.elementSizeBytes;
95 const size_t lineSize = eSize * w;
Jason Sams326e0dd2009-05-22 14:03:28 -070096
Jason Samsa2371512011-01-12 13:28:37 -080097 if ((lineSize * h) != sizeBytes) {
Stephen Hines6ae039b2012-01-18 18:46:27 -080098 ALOGE("Allocation size mismatch, expected %zu, got %zu", (lineSize * h), sizeBytes);
Jason Sams9397e302009-08-27 20:23:34 -070099 rsAssert(!"Allocation::subData called with mismatched size");
100 return;
101 }
102
Tim Murray358747a2012-11-26 13:52:04 -0800103 this->data(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, lineSize);
104}
105
106void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
107 uint32_t w, uint32_t h, const void *data, size_t sizeBytes, size_t stride) {
108 const size_t eSize = mHal.state.elementSizeBytes;
109 const size_t lineSize = eSize * w;
110
111 //ALOGE("data2d %p, %i %i %i %i %i %i %p %i", this, xoff, yoff, lod, face, w, h, data, sizeBytes);
112
113 rsc->mHal.funcs.allocation.data2D(rsc, this, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700114 sendDirty(rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -0700115}
116
Jason Sams236385b2011-01-12 14:53:25 -0800117void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff,
118 uint32_t lod, RsAllocationCubemapFace face,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800119 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700120}
121
Jason Sams807fdc42012-07-25 17:55:39 -0700122void Allocation::read(Context *rsc, uint32_t xoff, uint32_t lod,
Tim Murray358747a2012-11-26 13:52:04 -0800123 uint32_t count, void *data, size_t sizeBytes) {
Jason Sams807fdc42012-07-25 17:55:39 -0700124 const size_t eSize = mHal.state.type->getElementSizeBytes();
125
126 if ((count * eSize) != sizeBytes) {
127 ALOGE("Allocation::read called with mismatched size expected %zu, got %zu",
128 (count * eSize), sizeBytes);
129 mHal.state.type->dumpLOGV("type info");
130 return;
131 }
132
133 rsc->mHal.funcs.allocation.read1D(rsc, this, xoff, lod, count, data, sizeBytes);
134}
135
Tim Murray509ea5c2012-11-13 11:56:40 -0800136void Allocation::readUnchecked(Context *rsc, uint32_t xoff, uint32_t lod,
137 uint32_t count, void *data, size_t sizeBytes) {
138 rsc->mHal.funcs.allocation.read1D(rsc, this, xoff, lod, count, data, sizeBytes);
139}
140
141
Jason Sams807fdc42012-07-25 17:55:39 -0700142void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
Tim Murray358747a2012-11-26 13:52:04 -0800143 uint32_t w, uint32_t h, void *data, size_t sizeBytes) {
Jason Sams807fdc42012-07-25 17:55:39 -0700144 const size_t eSize = mHal.state.elementSizeBytes;
145 const size_t lineSize = eSize * w;
146
147 if ((lineSize * h) != sizeBytes) {
148 ALOGE("Allocation size mismatch, expected %zu, got %zu", (lineSize * h), sizeBytes);
149 rsAssert(!"Allocation::read called with mismatched size");
150 return;
151 }
152
Tim Murray358747a2012-11-26 13:52:04 -0800153 read(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, lineSize);
154}
155
156void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
157 uint32_t w, uint32_t h, 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.read2D(rsc, this, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700165}
166
167void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff,
168 uint32_t lod, RsAllocationCubemapFace face,
169 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes) {
170}
171
Jason Sams4b45b892010-12-29 14:31:29 -0800172void Allocation::elementData(Context *rsc, uint32_t x, const void *data,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800173 uint32_t cIdx, size_t sizeBytes) {
174 size_t eSize = mHal.state.elementSizeBytes;
Jason Sams5f0c84c2010-08-31 13:50:42 -0700175
Jason Samsbad80742011-03-16 16:29:28 -0700176 if (cIdx >= mHal.state.type->getElement()->getFieldCount()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000177 ALOGE("Error Allocation::subElementData component %i out of range.", cIdx);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700178 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range.");
179 return;
180 }
181
Jason Samsbad80742011-03-16 16:29:28 -0700182 if (x >= mHal.state.dimensionX) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000183 ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700184 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
185 return;
186 }
187
Jason Samsbad80742011-03-16 16:29:28 -0700188 const Element * e = mHal.state.type->getElement()->getField(cIdx);
Alex Sakhartchouk76946322012-02-02 09:47:26 -0800189 uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx);
190 if (sizeBytes != e->getSizeBytes() * elemArraySize) {
Stephen Hines6ae039b2012-01-18 18:46:27 -0800191 ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes());
Jason Sams5f0c84c2010-08-31 13:50:42 -0700192 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
193 return;
194 }
195
Jason Samseb4fe182011-05-26 16:33:01 -0700196 rsc->mHal.funcs.allocation.elementData1D(rsc, this, x, data, cIdx, sizeBytes);
197 sendDirty(rsc);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700198}
199
Jason Sams4b45b892010-12-29 14:31:29 -0800200void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800201 const void *data, uint32_t cIdx, size_t sizeBytes) {
202 size_t eSize = mHal.state.elementSizeBytes;
Jason Sams5f0c84c2010-08-31 13:50:42 -0700203
Jason Samsbad80742011-03-16 16:29:28 -0700204 if (x >= mHal.state.dimensionX) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000205 ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700206 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
207 return;
208 }
209
Jason Samsbad80742011-03-16 16:29:28 -0700210 if (y >= mHal.state.dimensionY) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000211 ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700212 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
213 return;
214 }
215
Jason Samsbad80742011-03-16 16:29:28 -0700216 if (cIdx >= mHal.state.type->getElement()->getFieldCount()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000217 ALOGE("Error Allocation::subElementData component %i out of range.", cIdx);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700218 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range.");
219 return;
220 }
221
Jason Samsbad80742011-03-16 16:29:28 -0700222 const Element * e = mHal.state.type->getElement()->getField(cIdx);
Alex Sakhartchouk76946322012-02-02 09:47:26 -0800223 uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx);
224 if (sizeBytes != e->getSizeBytes() * elemArraySize) {
Stephen Hines6ae039b2012-01-18 18:46:27 -0800225 ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes());
Jason Sams5f0c84c2010-08-31 13:50:42 -0700226 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
227 return;
228 }
229
Jason Samseb4fe182011-05-26 16:33:01 -0700230 rsc->mHal.funcs.allocation.elementData2D(rsc, this, x, y, data, cIdx, sizeBytes);
231 sendDirty(rsc);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700232}
233
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800234void Allocation::addProgramToDirty(const Program *p) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700235 mToDirtyList.push(p);
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700236}
Jason Sams326e0dd2009-05-22 14:03:28 -0700237
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800238void Allocation::removeProgramToDirty(const Program *p) {
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700239 for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
240 if (mToDirtyList[ct] == p) {
241 mToDirtyList.removeAt(ct);
242 return;
243 }
244 }
245 rsAssert(0);
246}
247
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800248void Allocation::dumpLOGV(const char *prefix) const {
Jason Samsc21cf402009-11-17 17:26:46 -0800249 ObjectBase::dumpLOGV(prefix);
250
251 String8 s(prefix);
252 s.append(" type ");
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -0700253 if (mHal.state.type) {
Jason Samsbad80742011-03-16 16:29:28 -0700254 mHal.state.type->dumpLOGV(s.string());
Jason Samsc21cf402009-11-17 17:26:46 -0800255 }
256
Steve Block65982012011-10-20 11:56:00 +0100257 ALOGV("%s allocation ptr=%p mUsageFlags=0x04%x, mMipmapControl=0x%04x",
Jason Sams709a0972012-11-15 18:18:04 -0800258 prefix, mHal.drvState.lod[0].mallocPtr, mHal.state.usageFlags, mHal.state.mipmapControl);
Jason Samsc21cf402009-11-17 17:26:46 -0800259}
Jason Sams326e0dd2009-05-22 14:03:28 -0700260
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800261uint32_t Allocation::getPackedSize() const {
262 uint32_t numItems = mHal.state.type->getSizeBytes() / mHal.state.type->getElementSizeBytes();
263 return numItems * mHal.state.type->getElement()->getSizeBytesUnpadded();
264}
265
Jason Samse3150cf2012-07-24 18:10:20 -0700266void Allocation::writePackedData(Context *rsc, const Type *type,
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800267 uint8_t *dst, const uint8_t *src, bool dstPadded) {
268 const Element *elem = type->getElement();
269 uint32_t unpaddedBytes = elem->getSizeBytesUnpadded();
270 uint32_t paddedBytes = elem->getSizeBytes();
271 uint32_t numItems = type->getSizeBytes() / paddedBytes;
272
273 uint32_t srcInc = !dstPadded ? paddedBytes : unpaddedBytes;
274 uint32_t dstInc = dstPadded ? paddedBytes : unpaddedBytes;
275
276 // no sub-elements
277 uint32_t fieldCount = elem->getFieldCount();
278 if (fieldCount == 0) {
279 for (uint32_t i = 0; i < numItems; i ++) {
280 memcpy(dst, src, unpaddedBytes);
281 src += srcInc;
282 dst += dstInc;
283 }
284 return;
285 }
286
287 // Cache offsets
288 uint32_t *offsetsPadded = new uint32_t[fieldCount];
289 uint32_t *offsetsUnpadded = new uint32_t[fieldCount];
290 uint32_t *sizeUnpadded = new uint32_t[fieldCount];
291
292 for (uint32_t i = 0; i < fieldCount; i++) {
293 offsetsPadded[i] = elem->getFieldOffsetBytes(i);
294 offsetsUnpadded[i] = elem->getFieldOffsetBytesUnpadded(i);
295 sizeUnpadded[i] = elem->getField(i)->getSizeBytesUnpadded();
296 }
297
298 uint32_t *srcOffsets = !dstPadded ? offsetsPadded : offsetsUnpadded;
299 uint32_t *dstOffsets = dstPadded ? offsetsPadded : offsetsUnpadded;
300
301 // complex elements, need to copy subelem after subelem
302 for (uint32_t i = 0; i < numItems; i ++) {
303 for (uint32_t fI = 0; fI < fieldCount; fI++) {
304 memcpy(dst + dstOffsets[fI], src + srcOffsets[fI], sizeUnpadded[fI]);
305 }
306 src += srcInc;
307 dst += dstInc;
308 }
309
310 delete[] offsetsPadded;
311 delete[] offsetsUnpadded;
312 delete[] sizeUnpadded;
313}
314
Jason Samse3150cf2012-07-24 18:10:20 -0700315void Allocation::unpackVec3Allocation(Context *rsc, const void *data, size_t dataSize) {
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800316 const uint8_t *src = (const uint8_t*)data;
Jason Sams61a4bb72012-07-25 19:33:43 -0700317 uint8_t *dst = (uint8_t *)rsc->mHal.funcs.allocation.lock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800318
Jason Samse3150cf2012-07-24 18:10:20 -0700319 writePackedData(rsc, getType(), dst, src, true);
Jason Sams61a4bb72012-07-25 19:33:43 -0700320 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800321}
322
Jason Samse3150cf2012-07-24 18:10:20 -0700323void Allocation::packVec3Allocation(Context *rsc, OStream *stream) const {
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800324 uint32_t paddedBytes = getType()->getElement()->getSizeBytes();
325 uint32_t unpaddedBytes = getType()->getElement()->getSizeBytesUnpadded();
326 uint32_t numItems = mHal.state.type->getSizeBytes() / paddedBytes;
327
Jason Sams61a4bb72012-07-25 19:33:43 -0700328 const uint8_t *src = (const uint8_t*)rsc->mHal.funcs.allocation.lock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800329 uint8_t *dst = new uint8_t[numItems * unpaddedBytes];
330
Jason Samse3150cf2012-07-24 18:10:20 -0700331 writePackedData(rsc, getType(), dst, src, false);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800332 stream->addByteArray(dst, getPackedSize());
333
334 delete[] dst;
Jason Sams61a4bb72012-07-25 19:33:43 -0700335 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800336}
337
Jason Samse3150cf2012-07-24 18:10:20 -0700338void Allocation::serialize(Context *rsc, OStream *stream) const {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700339 // Need to identify ourselves
340 stream->addU32((uint32_t)getClassId());
341
342 String8 name(getName());
343 stream->addString(&name);
344
345 // First thing we need to serialize is the type object since it will be needed
346 // to initialize the class
Jason Samse3150cf2012-07-24 18:10:20 -0700347 mHal.state.type->serialize(rsc, stream);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700348
Jason Samsbad80742011-03-16 16:29:28 -0700349 uint32_t dataSize = mHal.state.type->getSizeBytes();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800350 // 3 element vectors are padded to 4 in memory, but padding isn't serialized
351 uint32_t packedSize = getPackedSize();
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700352 // Write how much data we are storing
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800353 stream->addU32(packedSize);
354 if (dataSize == packedSize) {
355 // Now write the data
Jason Sams61a4bb72012-07-25 19:33:43 -0700356 stream->addByteArray(rsc->mHal.funcs.allocation.lock1D(rsc, this), dataSize);
357 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800358 } else {
359 // Now write the data
Jason Samse3150cf2012-07-24 18:10:20 -0700360 packVec3Allocation(rsc, stream);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800361 }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700362}
363
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800364Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700365 // First make sure we are reading the correct object
Alex Sakhartchoukb825f672010-06-04 10:06:50 -0700366 RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800367 if (classID != RS_A3D_CLASS_ID_ALLOCATION) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000368 ALOGE("allocation loading skipped due to invalid class id\n");
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700369 return NULL;
370 }
371
372 String8 name;
373 stream->loadString(&name);
374
375 Type *type = Type::createFromStream(rsc, stream);
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800376 if (!type) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700377 return NULL;
378 }
379 type->compute();
380
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800381 Allocation *alloc = Allocation::createAllocation(rsc, type, RS_ALLOCATION_USAGE_SCRIPT);
382 type->decUserRef();
383
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700384 // Number of bytes we wrote out for this allocation
385 uint32_t dataSize = stream->loadU32();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800386 // 3 element vectors are padded to 4 in memory, but padding isn't serialized
387 uint32_t packedSize = alloc->getPackedSize();
388 if (dataSize != type->getSizeBytes() &&
389 dataSize != packedSize) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000390 ALOGE("failed to read allocation because numbytes written is not the same loaded type wants\n");
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800391 ObjectBase::checkDelete(alloc);
Jason Sams225afd32010-10-21 14:06:55 -0700392 ObjectBase::checkDelete(type);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700393 return NULL;
394 }
395
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700396 alloc->setName(name.string(), name.size());
397
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800398 if (dataSize == type->getSizeBytes()) {
399 uint32_t count = dataSize / type->getElementSizeBytes();
400 // Read in all of our allocation data
401 alloc->data(rsc, 0, 0, count, stream->getPtr() + stream->getPos(), dataSize);
402 } else {
Jason Samse3150cf2012-07-24 18:10:20 -0700403 alloc->unpackVec3Allocation(rsc, stream->getPtr() + stream->getPos(), dataSize);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800404 }
Alex Sakhartchouke6d9fbc2010-08-11 10:30:44 -0700405 stream->reset(stream->getPos() + dataSize);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700406
407 return alloc;
408}
409
Jason Samseb4fe182011-05-26 16:33:01 -0700410void Allocation::sendDirty(const Context *rsc) const {
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700411 for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
412 mToDirtyList[ct]->forceDirty();
413 }
Jason Samseb4fe182011-05-26 16:33:01 -0700414 mRSC->mHal.funcs.allocation.markDirty(rsc, this);
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700415}
Jason Sams326e0dd2009-05-22 14:03:28 -0700416
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800417void Allocation::incRefs(const void *ptr, size_t ct, size_t startOff) const {
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700418 mHal.state.type->incRefs(ptr, ct, startOff);
Jason Samse3929c92010-08-09 18:13:33 -0700419}
420
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800421void Allocation::decRefs(const void *ptr, size_t ct, size_t startOff) const {
Alex Sakhartchouk5c4369a2011-08-12 11:30:30 -0700422 if (!mHal.state.hasReferences || !getIsScript()) {
423 return;
424 }
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700425 mHal.state.type->decRefs(ptr, ct, startOff);
Jason Samse3929c92010-08-09 18:13:33 -0700426}
427
Jason Samsc7cec1e2011-08-18 18:01:33 -0700428void Allocation::freeChildrenUnlocked () {
Jason Sams61a4bb72012-07-25 19:33:43 -0700429 void *ptr = mRSC->mHal.funcs.allocation.lock1D(mRSC, this);
430 decRefs(ptr, mHal.state.type->getSizeBytes() / mHal.state.type->getElementSizeBytes(), 0);
431 mRSC->mHal.funcs.allocation.unlock1D(mRSC, this);
Jason Samsc7cec1e2011-08-18 18:01:33 -0700432}
433
434bool Allocation::freeChildren() {
435 if (mHal.state.hasReferences) {
436 incSysRef();
437 freeChildrenUnlocked();
438 return decSysRef();
439 }
440 return false;
441}
442
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800443void Allocation::copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len) {
Jason Sams96abf812010-10-05 13:32:49 -0700444}
445
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800446void Allocation::resize1D(Context *rsc, uint32_t dimX) {
Jason Samsbad80742011-03-16 16:29:28 -0700447 uint32_t oldDimX = mHal.state.dimensionX;
Jason Sams96abf812010-10-05 13:32:49 -0700448 if (dimX == oldDimX) {
449 return;
450 }
451
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700452 ObjectBaseRef<Type> t = mHal.state.type->cloneAndResize1D(rsc, dimX);
Jason Sams96abf812010-10-05 13:32:49 -0700453 if (dimX < oldDimX) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700454 decRefs(rsc->mHal.funcs.allocation.lock1D(rsc, this), oldDimX - dimX, dimX);
455 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Jason Sams96abf812010-10-05 13:32:49 -0700456 }
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700457 rsc->mHal.funcs.allocation.resize(rsc, this, t.get(), mHal.state.hasReferences);
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -0700458 setType(t.get());
Jason Samsbad80742011-03-16 16:29:28 -0700459 updateCache();
Jason Sams96abf812010-10-05 13:32:49 -0700460}
461
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800462void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000463 ALOGE("not implemented");
Jason Sams96abf812010-10-05 13:32:49 -0700464}
465
Jason Sams41e373d2012-01-13 14:01:20 -0800466int32_t Allocation::getSurfaceTextureID(const Context *rsc) {
467 int32_t id = rsc->mHal.funcs.allocation.initSurfaceTexture(rsc, this);
468 mHal.state.surfaceTextureID = id;
469 return id;
470}
471
Jason Sams3522f402012-03-23 11:47:26 -0700472void Allocation::setSurfaceTexture(const Context *rsc, SurfaceTexture *st) {
473 if(st != mHal.state.surfaceTexture) {
474 if(mHal.state.surfaceTexture != NULL) {
475 mHal.state.surfaceTexture->decStrong(NULL);
476 }
477 mHal.state.surfaceTexture = st;
478 if(mHal.state.surfaceTexture != NULL) {
479 mHal.state.surfaceTexture->incStrong(NULL);
480 }
481 }
482}
483
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800484void Allocation::setSurface(const Context *rsc, RsNativeWindow sur) {
485 ANativeWindow *nw = (ANativeWindow *)sur;
486 ANativeWindow *old = mHal.state.wndSurface;
487 if (nw) {
488 nw->incStrong(NULL);
489 }
490 rsc->mHal.funcs.allocation.setSurfaceTexture(rsc, this, nw);
491 mHal.state.wndSurface = nw;
492 if (old) {
493 old->decStrong(NULL);
494 }
495}
496
497void Allocation::ioSend(const Context *rsc) {
498 rsc->mHal.funcs.allocation.ioSend(rsc, this);
499}
500
501void Allocation::ioReceive(const Context *rsc) {
502 rsc->mHal.funcs.allocation.ioReceive(rsc, this);
503}
504
505
Jason Sams326e0dd2009-05-22 14:03:28 -0700506/////////////////
Jason Sams565ac362009-06-03 16:04:54 -0700507//
Stephen Hines6a121812011-03-01 17:34:59 -0800508
Jason Sams326e0dd2009-05-22 14:03:28 -0700509namespace android {
510namespace renderscript {
511
Jason Sams366c9c82010-12-08 16:14:36 -0800512void rsi_AllocationSyncAll(Context *rsc, RsAllocation va, RsAllocationUsageType src) {
513 Allocation *a = static_cast<Allocation *>(va);
Jason Samseb4fe182011-05-26 16:33:01 -0700514 a->sendDirty(rsc);
Jason Sams366c9c82010-12-08 16:14:36 -0800515 a->syncAll(rsc, src);
516}
517
Jason Samsa2371512011-01-12 13:28:37 -0800518void rsi_AllocationGenerateMipmaps(Context *rsc, RsAllocation va) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700519 Allocation *alloc = static_cast<Allocation *>(va);
520 rsc->mHal.funcs.allocation.generateMipmaps(rsc, alloc);
Jason Sams837e3882010-12-10 16:03:15 -0800521}
522
Jason Sams807fdc42012-07-25 17:55:39 -0700523void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) {
524 Allocation *a = static_cast<Allocation *>(va);
525 const Type * t = a->getType();
526 a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
527 t->getDimX(), t->getDimY(), data, sizeBytes);
Alex Sakhartchouk39f2ef62010-10-11 12:35:15 -0700528}
529
Jason Sams4b45b892010-12-29 14:31:29 -0800530void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700531 uint32_t count, const void *data, size_t sizeBytes) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700532 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800533 a->data(rsc, xoff, lod, count, data, sizeBytes);
Jason Sams326e0dd2009-05-22 14:03:28 -0700534}
535
Jason Sams4b45b892010-12-29 14:31:29 -0800536void rsi_Allocation2DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t lod, RsAllocationCubemapFace face,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800537 const void *data, size_t sizeBytes, size_t eoff) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700538 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800539 a->elementData(rsc, x, y, data, eoff, sizeBytes);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700540}
541
Jason Sams4b45b892010-12-29 14:31:29 -0800542void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800543 const void *data, size_t sizeBytes, size_t eoff) {
Jason Sams5f0c84c2010-08-31 13:50:42 -0700544 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800545 a->elementData(rsc, x, data, eoff, sizeBytes);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700546}
547
Jason Sams4b45b892010-12-29 14:31:29 -0800548void rsi_Allocation2DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
Tim Murray358747a2012-11-26 13:52:04 -0800549 uint32_t w, uint32_t h, const void *data, size_t sizeBytes, size_t stride) {
Jason Sams5f0c84c2010-08-31 13:50:42 -0700550 Allocation *a = static_cast<Allocation *>(va);
Tim Murray358747a2012-11-26 13:52:04 -0800551 a->data(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Jason Sams326e0dd2009-05-22 14:03:28 -0700552}
553
Jason Sams807fdc42012-07-25 17:55:39 -0700554void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) {
Jason Samse579df42009-08-10 14:55:26 -0700555 Allocation *a = static_cast<Allocation *>(va);
Jason Sams807fdc42012-07-25 17:55:39 -0700556 const Type * t = a->getType();
557 if(t->getDimY()) {
558 a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
559 t->getDimX(), t->getDimY(), data, sizeBytes);
560 } else {
561 a->read(rsc, 0, 0, t->getDimX(), data, sizeBytes);
562 }
563
Jason Samse579df42009-08-10 14:55:26 -0700564}
565
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800566void rsi_AllocationResize1D(Context *rsc, RsAllocation va, uint32_t dimX) {
Jason Sams96abf812010-10-05 13:32:49 -0700567 Allocation *a = static_cast<Allocation *>(va);
568 a->resize1D(rsc, dimX);
569}
570
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800571void rsi_AllocationResize2D(Context *rsc, RsAllocation va, uint32_t dimX, uint32_t dimY) {
Jason Sams96abf812010-10-05 13:32:49 -0700572 Allocation *a = static_cast<Allocation *>(va);
573 a->resize2D(rsc, dimX, dimY);
574}
575
Jason Samsc975cf42011-04-28 18:26:48 -0700576RsAllocation rsi_AllocationCreateTyped(Context *rsc, RsType vtype,
577 RsAllocationMipmapControl mips,
Jason Sams179e9a42011-11-23 15:02:15 -0800578 uint32_t usages, uint32_t ptr) {
579 Allocation * alloc = Allocation::createAllocation(rsc, static_cast<Type *>(vtype), usages, mips, (void *)ptr);
Jason Samseb4fe182011-05-26 16:33:01 -0700580 if (!alloc) {
581 return NULL;
582 }
Jason Samsf0c1df42010-10-26 13:09:17 -0700583 alloc->incUserRef();
584 return alloc;
585}
586
Jason Samsc975cf42011-04-28 18:26:48 -0700587RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, RsType vtype,
588 RsAllocationMipmapControl mips,
Jason Sams807fdc42012-07-25 17:55:39 -0700589 const void *data, size_t sizeBytes, uint32_t usages) {
Jason Sams366c9c82010-12-08 16:14:36 -0800590 Type *t = static_cast<Type *>(vtype);
Jason Samsf0c1df42010-10-26 13:09:17 -0700591
Jason Sams179e9a42011-11-23 15:02:15 -0800592 RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0);
Jason Samsf0c1df42010-10-26 13:09:17 -0700593 Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
594 if (texAlloc == NULL) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000595 ALOGE("Memory allocation failure");
Jason Samsf0c1df42010-10-26 13:09:17 -0700596 return NULL;
597 }
598
Jason Sams807fdc42012-07-25 17:55:39 -0700599 texAlloc->data(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
600 t->getDimX(), t->getDimY(), data, sizeBytes);
Jason Samsebc50192010-12-13 15:32:35 -0800601 if (mips == RS_ALLOCATION_MIPMAP_FULL) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700602 rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc);
Jason Samsf0c1df42010-10-26 13:09:17 -0700603 }
604
Jason Samseb4fe182011-05-26 16:33:01 -0700605 texAlloc->sendDirty(rsc);
Jason Samsf0c1df42010-10-26 13:09:17 -0700606 return texAlloc;
607}
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800608
Jason Samsc975cf42011-04-28 18:26:48 -0700609RsAllocation rsi_AllocationCubeCreateFromBitmap(Context *rsc, RsType vtype,
610 RsAllocationMipmapControl mips,
Jason Sams807fdc42012-07-25 17:55:39 -0700611 const void *data, size_t sizeBytes, uint32_t usages) {
Jason Sams366c9c82010-12-08 16:14:36 -0800612 Type *t = static_cast<Type *>(vtype);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800613
614 // Cubemap allocation's faces should be Width by Width each.
615 // Source data should have 6 * Width by Width pixels
616 // Error checking is done in the java layer
Jason Sams179e9a42011-11-23 15:02:15 -0800617 RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800618 Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
619 if (texAlloc == NULL) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000620 ALOGE("Memory allocation failure");
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800621 return NULL;
622 }
623
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800624 uint32_t faceSize = t->getDimX();
625 uint32_t strideBytes = faceSize * 6 * t->getElementSizeBytes();
626 uint32_t copySize = faceSize * t->getElementSizeBytes();
627
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800628 uint8_t *sourcePtr = (uint8_t*)data;
Jason Sams366c9c82010-12-08 16:14:36 -0800629 for (uint32_t face = 0; face < 6; face ++) {
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800630 for (uint32_t dI = 0; dI < faceSize; dI ++) {
Jason Sams807fdc42012-07-25 17:55:39 -0700631 texAlloc->data(rsc, 0, dI, 0, (RsAllocationCubemapFace)face,
632 t->getDimX(), 1, sourcePtr + strideBytes * dI, copySize);
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800633 }
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800634
Jason Sams366c9c82010-12-08 16:14:36 -0800635 // Move the data pointer to the next cube face
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800636 sourcePtr += copySize;
Alex Sakhartchoukf8aafcf2011-01-11 14:47:44 -0800637 }
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800638
Alex Sakhartchoukf8aafcf2011-01-11 14:47:44 -0800639 if (mips == RS_ALLOCATION_MIPMAP_FULL) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700640 rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800641 }
642
Jason Samseb4fe182011-05-26 16:33:01 -0700643 texAlloc->sendDirty(rsc);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800644 return texAlloc;
645}
Alex Sakhartchouk099d7d32011-01-28 09:31:47 -0800646
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700647void rsi_AllocationCopy2DRange(Context *rsc,
648 RsAllocation dstAlloc,
649 uint32_t dstXoff, uint32_t dstYoff,
650 uint32_t dstMip, uint32_t dstFace,
651 uint32_t width, uint32_t height,
652 RsAllocation srcAlloc,
653 uint32_t srcXoff, uint32_t srcYoff,
654 uint32_t srcMip, uint32_t srcFace) {
655 Allocation *dst = static_cast<Allocation *>(dstAlloc);
656 Allocation *src= static_cast<Allocation *>(srcAlloc);
657 rsc->mHal.funcs.allocation.allocData2D(rsc, dst, dstXoff, dstYoff, dstMip,
658 (RsAllocationCubemapFace)dstFace,
659 width, height,
660 src, srcXoff, srcYoff,srcMip,
661 (RsAllocationCubemapFace)srcFace);
662}
663
Jason Sams41e373d2012-01-13 14:01:20 -0800664int32_t rsi_AllocationGetSurfaceTextureID(Context *rsc, RsAllocation valloc) {
665 Allocation *alloc = static_cast<Allocation *>(valloc);
666 return alloc->getSurfaceTextureID(rsc);
667}
668
Jason Sams3522f402012-03-23 11:47:26 -0700669void rsi_AllocationGetSurfaceTextureID2(Context *rsc, RsAllocation valloc, void *vst, size_t len) {
670 Allocation *alloc = static_cast<Allocation *>(valloc);
671 alloc->setSurfaceTexture(rsc, static_cast<SurfaceTexture *>(vst));
672}
673
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800674void rsi_AllocationSetSurface(Context *rsc, RsAllocation valloc, RsNativeWindow sur) {
675 Allocation *alloc = static_cast<Allocation *>(valloc);
676 alloc->setSurface(rsc, sur);
677}
678
679void rsi_AllocationIoSend(Context *rsc, RsAllocation valloc) {
680 Allocation *alloc = static_cast<Allocation *>(valloc);
681 alloc->ioSend(rsc);
682}
683
684void rsi_AllocationIoReceive(Context *rsc, RsAllocation valloc) {
685 Allocation *alloc = static_cast<Allocation *>(valloc);
686 alloc->ioReceive(rsc);
687}
688
Tim Murray509ea5c2012-11-13 11:56:40 -0800689void rsi_Allocation1DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
690 uint32_t count, void *data, size_t sizeBytes) {
691 Allocation *a = static_cast<Allocation *>(va);
692 a->readUnchecked(rsc, xoff, lod, count, data, sizeBytes);
693}
694
Tim Murray7b3e3092012-11-16 13:32:24 -0800695void rsi_Allocation2DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff,
696 uint32_t lod, RsAllocationCubemapFace face, uint32_t w,
Tim Murray358747a2012-11-26 13:52:04 -0800697 uint32_t h, void *data, size_t sizeBytes, size_t stride) {
Tim Murray7b3e3092012-11-16 13:32:24 -0800698 Allocation *a = static_cast<Allocation *>(va);
Tim Murray358747a2012-11-26 13:52:04 -0800699 a->read(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Tim Murray7b3e3092012-11-16 13:32:24 -0800700}
701
Jason Samsc975cf42011-04-28 18:26:48 -0700702}
703}
704
705const void * rsaAllocationGetType(RsContext con, RsAllocation va) {
706 Allocation *a = static_cast<Allocation *>(va);
707 a->getType()->incUserRef();
708
709 return a->getType();
710}