blob: 1f360402c8e079bf57f1ccdfb6faeb92695d714e [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
Jason Samsbc0ca6b2013-02-15 18:13:43 -08002 * Copyright (C) 2013 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"
Andy McFadden58fd6a52012-12-18 09:50:03 -080023#include "gui/GLConsumer.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;
Tim Murray2e1a94d2012-11-29 13:12:25 -080036 mHal.state.userProvidedPtr = ptr;
Jason Sams366c9c82010-12-08 16:14:36 -080037
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070038 setType(type);
Jason Samsbad80742011-03-16 16:29:28 -070039 updateCache();
40}
Jason Samsfa84da22010-03-01 15:31:04 -080041
Jason Samseb4fe182011-05-26 16:33:01 -070042Allocation * Allocation::createAllocation(Context *rsc, const Type *type, uint32_t usages,
Jason Sams179e9a42011-11-23 15:02:15 -080043 RsAllocationMipmapControl mc, void * ptr) {
44 Allocation *a = new Allocation(rsc, type, usages, mc, ptr);
Jason Samseb4fe182011-05-26 16:33:01 -070045
46 if (!rsc->mHal.funcs.allocation.init(rsc, a, type->getElement()->getHasReferences())) {
47 rsc->setError(RS_ERROR_FATAL_DRIVER, "Allocation::Allocation, alloc failure");
48 delete a;
49 return NULL;
50 }
Jason Sams7ac2a4d2012-02-15 12:04:24 -080051
Jason Samseb4fe182011-05-26 16:33:01 -070052 return a;
53}
54
Jason Samsbad80742011-03-16 16:29:28 -070055void Allocation::updateCache() {
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070056 const Type *type = mHal.state.type;
Jason Samsa572aca2013-01-09 11:52:26 -080057 mHal.state.yuv = type->getDimYuv();
Jason Samsbad80742011-03-16 16:29:28 -070058 mHal.state.hasFaces = type->getDimFaces();
59 mHal.state.hasMipmaps = type->getDimLOD();
60 mHal.state.elementSizeBytes = type->getElementSizeBytes();
61 mHal.state.hasReferences = mHal.state.type->getElement()->getHasReferences();
Jason Sams326e0dd2009-05-22 14:03:28 -070062}
63
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080064Allocation::~Allocation() {
Jason Samsc7cec1e2011-08-18 18:01:33 -070065 freeChildrenUnlocked();
Jason Sams3522f402012-03-23 11:47:26 -070066 setSurfaceTexture(mRSC, NULL);
Jason Samseb4fe182011-05-26 16:33:01 -070067 mRSC->mHal.funcs.allocation.destroy(mRSC, this);
Jason Sams326e0dd2009-05-22 14:03:28 -070068}
69
Jason Sams366c9c82010-12-08 16:14:36 -080070void Allocation::syncAll(Context *rsc, RsAllocationUsageType src) {
Jason Samseb4fe182011-05-26 16:33:01 -070071 rsc->mHal.funcs.allocation.syncAll(rsc, this, src);
Jason Samscf4c7c92009-12-14 12:57:40 -080072}
73
Jason Sams4b45b892010-12-29 14:31:29 -080074void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod,
Stephen Hines6ae039b2012-01-18 18:46:27 -080075 uint32_t count, const void *data, size_t sizeBytes) {
76 const size_t eSize = mHal.state.type->getElementSizeBytes();
Jason Sams9397e302009-08-27 20:23:34 -070077
Jason Samseb4fe182011-05-26 16:33:01 -070078 if ((count * eSize) != sizeBytes) {
Stephen Hines6ae039b2012-01-18 18:46:27 -080079 ALOGE("Allocation::subData called with mismatched size expected %zu, got %zu",
Jason Samseb4fe182011-05-26 16:33:01 -070080 (count * eSize), sizeBytes);
Jason Samsbad80742011-03-16 16:29:28 -070081 mHal.state.type->dumpLOGV("type info");
Jason Sams9397e302009-08-27 20:23:34 -070082 return;
83 }
Jason Samse3929c92010-08-09 18:13:33 -070084
Jason Samseb4fe182011-05-26 16:33:01 -070085 rsc->mHal.funcs.allocation.data1D(rsc, this, xoff, lod, count, data, sizeBytes);
86 sendDirty(rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -070087}
88
Jason Sams4b45b892010-12-29 14:31:29 -080089void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
Tim Murray358747a2012-11-26 13:52:04 -080090 uint32_t w, uint32_t h, const void *data, size_t sizeBytes, size_t stride) {
Tim Murray358747a2012-11-26 13:52:04 -080091 rsc->mHal.funcs.allocation.data2D(rsc, this, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Jason Samseb4fe182011-05-26 16:33:01 -070092 sendDirty(rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -070093}
94
Jason Sams236385b2011-01-12 14:53:25 -080095void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff,
96 uint32_t lod, RsAllocationCubemapFace face,
Stephen Hines6ae039b2012-01-18 18:46:27 -080097 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes) {
Jason Sams326e0dd2009-05-22 14:03:28 -070098}
99
Jason Sams807fdc42012-07-25 17:55:39 -0700100void Allocation::read(Context *rsc, uint32_t xoff, uint32_t lod,
Tim Murray358747a2012-11-26 13:52:04 -0800101 uint32_t count, void *data, size_t sizeBytes) {
Jason Sams807fdc42012-07-25 17:55:39 -0700102 const size_t eSize = mHal.state.type->getElementSizeBytes();
103
104 if ((count * eSize) != sizeBytes) {
105 ALOGE("Allocation::read called with mismatched size expected %zu, got %zu",
106 (count * eSize), sizeBytes);
107 mHal.state.type->dumpLOGV("type info");
108 return;
109 }
110
111 rsc->mHal.funcs.allocation.read1D(rsc, this, xoff, lod, count, data, sizeBytes);
112}
113
Tim Murray509ea5c2012-11-13 11:56:40 -0800114void Allocation::readUnchecked(Context *rsc, uint32_t xoff, uint32_t lod,
115 uint32_t count, void *data, size_t sizeBytes) {
116 rsc->mHal.funcs.allocation.read1D(rsc, this, xoff, lod, count, data, sizeBytes);
117}
118
119
Jason Sams807fdc42012-07-25 17:55:39 -0700120void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
Tim Murray358747a2012-11-26 13:52:04 -0800121 uint32_t w, uint32_t h, void *data, size_t sizeBytes) {
Jason Sams807fdc42012-07-25 17:55:39 -0700122 const size_t eSize = mHal.state.elementSizeBytes;
123 const size_t lineSize = eSize * w;
124
125 if ((lineSize * h) != sizeBytes) {
126 ALOGE("Allocation size mismatch, expected %zu, got %zu", (lineSize * h), sizeBytes);
127 rsAssert(!"Allocation::read called with mismatched size");
128 return;
129 }
130
Tim Murray358747a2012-11-26 13:52:04 -0800131 read(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, lineSize);
132}
133
134void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
135 uint32_t w, uint32_t h, void *data, size_t sizeBytes, size_t stride) {
136 const size_t eSize = mHal.state.elementSizeBytes;
137 const size_t lineSize = eSize * w;
138 if (!stride) {
139 stride = lineSize;
140 }
141
142 rsc->mHal.funcs.allocation.read2D(rsc, this, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700143}
144
145void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff,
146 uint32_t lod, RsAllocationCubemapFace face,
147 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes) {
148}
149
Jason Sams4b45b892010-12-29 14:31:29 -0800150void Allocation::elementData(Context *rsc, uint32_t x, const void *data,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800151 uint32_t cIdx, size_t sizeBytes) {
152 size_t eSize = mHal.state.elementSizeBytes;
Jason Sams5f0c84c2010-08-31 13:50:42 -0700153
Jason Samsbad80742011-03-16 16:29:28 -0700154 if (cIdx >= mHal.state.type->getElement()->getFieldCount()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000155 ALOGE("Error Allocation::subElementData component %i out of range.", cIdx);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700156 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range.");
157 return;
158 }
159
Jason Samsa572aca2013-01-09 11:52:26 -0800160 if (x >= mHal.drvState.lod[0].dimX) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000161 ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700162 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
163 return;
164 }
165
Jason Samsbad80742011-03-16 16:29:28 -0700166 const Element * e = mHal.state.type->getElement()->getField(cIdx);
Alex Sakhartchouk76946322012-02-02 09:47:26 -0800167 uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx);
168 if (sizeBytes != e->getSizeBytes() * elemArraySize) {
Stephen Hines6ae039b2012-01-18 18:46:27 -0800169 ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes());
Jason Sams5f0c84c2010-08-31 13:50:42 -0700170 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
171 return;
172 }
173
Jason Samseb4fe182011-05-26 16:33:01 -0700174 rsc->mHal.funcs.allocation.elementData1D(rsc, this, x, data, cIdx, sizeBytes);
175 sendDirty(rsc);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700176}
177
Jason Sams4b45b892010-12-29 14:31:29 -0800178void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800179 const void *data, uint32_t cIdx, size_t sizeBytes) {
180 size_t eSize = mHal.state.elementSizeBytes;
Jason Sams5f0c84c2010-08-31 13:50:42 -0700181
Jason Samsa572aca2013-01-09 11:52:26 -0800182 if (x >= mHal.drvState.lod[0].dimX) {
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 Samsa572aca2013-01-09 11:52:26 -0800188 if (y >= mHal.drvState.lod[0].dimY) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000189 ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700190 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
191 return;
192 }
193
Jason Samsbad80742011-03-16 16:29:28 -0700194 if (cIdx >= mHal.state.type->getElement()->getFieldCount()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000195 ALOGE("Error Allocation::subElementData component %i out of range.", cIdx);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700196 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range.");
197 return;
198 }
199
Jason Samsbad80742011-03-16 16:29:28 -0700200 const Element * e = mHal.state.type->getElement()->getField(cIdx);
Alex Sakhartchouk76946322012-02-02 09:47:26 -0800201 uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx);
202 if (sizeBytes != e->getSizeBytes() * elemArraySize) {
Stephen Hines6ae039b2012-01-18 18:46:27 -0800203 ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes());
Jason Sams5f0c84c2010-08-31 13:50:42 -0700204 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
205 return;
206 }
207
Jason Samseb4fe182011-05-26 16:33:01 -0700208 rsc->mHal.funcs.allocation.elementData2D(rsc, this, x, y, data, cIdx, sizeBytes);
209 sendDirty(rsc);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700210}
211
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800212void Allocation::addProgramToDirty(const Program *p) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700213 mToDirtyList.push(p);
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700214}
Jason Sams326e0dd2009-05-22 14:03:28 -0700215
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800216void Allocation::removeProgramToDirty(const Program *p) {
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700217 for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
218 if (mToDirtyList[ct] == p) {
219 mToDirtyList.removeAt(ct);
220 return;
221 }
222 }
223 rsAssert(0);
224}
225
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800226void Allocation::dumpLOGV(const char *prefix) const {
Jason Samsc21cf402009-11-17 17:26:46 -0800227 ObjectBase::dumpLOGV(prefix);
228
229 String8 s(prefix);
230 s.append(" type ");
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -0700231 if (mHal.state.type) {
Jason Samsbad80742011-03-16 16:29:28 -0700232 mHal.state.type->dumpLOGV(s.string());
Jason Samsc21cf402009-11-17 17:26:46 -0800233 }
234
Steve Block65982012011-10-20 11:56:00 +0100235 ALOGV("%s allocation ptr=%p mUsageFlags=0x04%x, mMipmapControl=0x%04x",
Jason Sams709a0972012-11-15 18:18:04 -0800236 prefix, mHal.drvState.lod[0].mallocPtr, mHal.state.usageFlags, mHal.state.mipmapControl);
Jason Samsc21cf402009-11-17 17:26:46 -0800237}
Jason Sams326e0dd2009-05-22 14:03:28 -0700238
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800239uint32_t Allocation::getPackedSize() const {
240 uint32_t numItems = mHal.state.type->getSizeBytes() / mHal.state.type->getElementSizeBytes();
241 return numItems * mHal.state.type->getElement()->getSizeBytesUnpadded();
242}
243
Jason Samse3150cf2012-07-24 18:10:20 -0700244void Allocation::writePackedData(Context *rsc, const Type *type,
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800245 uint8_t *dst, const uint8_t *src, bool dstPadded) {
246 const Element *elem = type->getElement();
247 uint32_t unpaddedBytes = elem->getSizeBytesUnpadded();
248 uint32_t paddedBytes = elem->getSizeBytes();
249 uint32_t numItems = type->getSizeBytes() / paddedBytes;
250
251 uint32_t srcInc = !dstPadded ? paddedBytes : unpaddedBytes;
252 uint32_t dstInc = dstPadded ? paddedBytes : unpaddedBytes;
253
254 // no sub-elements
255 uint32_t fieldCount = elem->getFieldCount();
256 if (fieldCount == 0) {
257 for (uint32_t i = 0; i < numItems; i ++) {
258 memcpy(dst, src, unpaddedBytes);
259 src += srcInc;
260 dst += dstInc;
261 }
262 return;
263 }
264
265 // Cache offsets
266 uint32_t *offsetsPadded = new uint32_t[fieldCount];
267 uint32_t *offsetsUnpadded = new uint32_t[fieldCount];
268 uint32_t *sizeUnpadded = new uint32_t[fieldCount];
269
270 for (uint32_t i = 0; i < fieldCount; i++) {
271 offsetsPadded[i] = elem->getFieldOffsetBytes(i);
272 offsetsUnpadded[i] = elem->getFieldOffsetBytesUnpadded(i);
273 sizeUnpadded[i] = elem->getField(i)->getSizeBytesUnpadded();
274 }
275
276 uint32_t *srcOffsets = !dstPadded ? offsetsPadded : offsetsUnpadded;
277 uint32_t *dstOffsets = dstPadded ? offsetsPadded : offsetsUnpadded;
278
279 // complex elements, need to copy subelem after subelem
280 for (uint32_t i = 0; i < numItems; i ++) {
281 for (uint32_t fI = 0; fI < fieldCount; fI++) {
282 memcpy(dst + dstOffsets[fI], src + srcOffsets[fI], sizeUnpadded[fI]);
283 }
284 src += srcInc;
285 dst += dstInc;
286 }
287
288 delete[] offsetsPadded;
289 delete[] offsetsUnpadded;
290 delete[] sizeUnpadded;
291}
292
Jason Samse3150cf2012-07-24 18:10:20 -0700293void Allocation::unpackVec3Allocation(Context *rsc, const void *data, size_t dataSize) {
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800294 const uint8_t *src = (const uint8_t*)data;
Jason Sams61a4bb72012-07-25 19:33:43 -0700295 uint8_t *dst = (uint8_t *)rsc->mHal.funcs.allocation.lock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800296
Jason Samse3150cf2012-07-24 18:10:20 -0700297 writePackedData(rsc, getType(), dst, src, true);
Jason Sams61a4bb72012-07-25 19:33:43 -0700298 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800299}
300
Jason Samse3150cf2012-07-24 18:10:20 -0700301void Allocation::packVec3Allocation(Context *rsc, OStream *stream) const {
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800302 uint32_t paddedBytes = getType()->getElement()->getSizeBytes();
303 uint32_t unpaddedBytes = getType()->getElement()->getSizeBytesUnpadded();
304 uint32_t numItems = mHal.state.type->getSizeBytes() / paddedBytes;
305
Jason Sams61a4bb72012-07-25 19:33:43 -0700306 const uint8_t *src = (const uint8_t*)rsc->mHal.funcs.allocation.lock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800307 uint8_t *dst = new uint8_t[numItems * unpaddedBytes];
308
Jason Samse3150cf2012-07-24 18:10:20 -0700309 writePackedData(rsc, getType(), dst, src, false);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800310 stream->addByteArray(dst, getPackedSize());
311
312 delete[] dst;
Jason Sams61a4bb72012-07-25 19:33:43 -0700313 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800314}
315
Jason Samse3150cf2012-07-24 18:10:20 -0700316void Allocation::serialize(Context *rsc, OStream *stream) const {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700317 // Need to identify ourselves
318 stream->addU32((uint32_t)getClassId());
319
320 String8 name(getName());
321 stream->addString(&name);
322
323 // First thing we need to serialize is the type object since it will be needed
324 // to initialize the class
Jason Samse3150cf2012-07-24 18:10:20 -0700325 mHal.state.type->serialize(rsc, stream);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700326
Jason Samsbad80742011-03-16 16:29:28 -0700327 uint32_t dataSize = mHal.state.type->getSizeBytes();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800328 // 3 element vectors are padded to 4 in memory, but padding isn't serialized
329 uint32_t packedSize = getPackedSize();
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700330 // Write how much data we are storing
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800331 stream->addU32(packedSize);
332 if (dataSize == packedSize) {
333 // Now write the data
Jason Sams61a4bb72012-07-25 19:33:43 -0700334 stream->addByteArray(rsc->mHal.funcs.allocation.lock1D(rsc, this), dataSize);
335 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800336 } else {
337 // Now write the data
Jason Samse3150cf2012-07-24 18:10:20 -0700338 packVec3Allocation(rsc, stream);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800339 }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700340}
341
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800342Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700343 // First make sure we are reading the correct object
Alex Sakhartchoukb825f672010-06-04 10:06:50 -0700344 RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800345 if (classID != RS_A3D_CLASS_ID_ALLOCATION) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000346 ALOGE("allocation loading skipped due to invalid class id\n");
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700347 return NULL;
348 }
349
350 String8 name;
351 stream->loadString(&name);
352
353 Type *type = Type::createFromStream(rsc, stream);
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800354 if (!type) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700355 return NULL;
356 }
357 type->compute();
358
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800359 Allocation *alloc = Allocation::createAllocation(rsc, type, RS_ALLOCATION_USAGE_SCRIPT);
360 type->decUserRef();
361
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700362 // Number of bytes we wrote out for this allocation
363 uint32_t dataSize = stream->loadU32();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800364 // 3 element vectors are padded to 4 in memory, but padding isn't serialized
365 uint32_t packedSize = alloc->getPackedSize();
366 if (dataSize != type->getSizeBytes() &&
367 dataSize != packedSize) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000368 ALOGE("failed to read allocation because numbytes written is not the same loaded type wants\n");
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800369 ObjectBase::checkDelete(alloc);
Jason Sams225afd32010-10-21 14:06:55 -0700370 ObjectBase::checkDelete(type);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700371 return NULL;
372 }
373
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700374 alloc->setName(name.string(), name.size());
375
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800376 if (dataSize == type->getSizeBytes()) {
377 uint32_t count = dataSize / type->getElementSizeBytes();
378 // Read in all of our allocation data
379 alloc->data(rsc, 0, 0, count, stream->getPtr() + stream->getPos(), dataSize);
380 } else {
Jason Samse3150cf2012-07-24 18:10:20 -0700381 alloc->unpackVec3Allocation(rsc, stream->getPtr() + stream->getPos(), dataSize);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800382 }
Alex Sakhartchouke6d9fbc2010-08-11 10:30:44 -0700383 stream->reset(stream->getPos() + dataSize);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700384
385 return alloc;
386}
387
Jason Samseb4fe182011-05-26 16:33:01 -0700388void Allocation::sendDirty(const Context *rsc) const {
Jason Sams93eacc72012-12-18 14:26:57 -0800389#ifndef RS_COMPATIBILITY_LIB
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700390 for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
391 mToDirtyList[ct]->forceDirty();
392 }
Jason Sams93eacc72012-12-18 14:26:57 -0800393#endif
Jason Samseb4fe182011-05-26 16:33:01 -0700394 mRSC->mHal.funcs.allocation.markDirty(rsc, this);
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700395}
Jason Sams326e0dd2009-05-22 14:03:28 -0700396
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800397void Allocation::incRefs(const void *ptr, size_t ct, size_t startOff) const {
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700398 mHal.state.type->incRefs(ptr, ct, startOff);
Jason Samse3929c92010-08-09 18:13:33 -0700399}
400
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800401void Allocation::decRefs(const void *ptr, size_t ct, size_t startOff) const {
Alex Sakhartchouk5c4369a2011-08-12 11:30:30 -0700402 if (!mHal.state.hasReferences || !getIsScript()) {
403 return;
404 }
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700405 mHal.state.type->decRefs(ptr, ct, startOff);
Jason Samse3929c92010-08-09 18:13:33 -0700406}
407
Jason Samsc7cec1e2011-08-18 18:01:33 -0700408void Allocation::freeChildrenUnlocked () {
Jason Sams61a4bb72012-07-25 19:33:43 -0700409 void *ptr = mRSC->mHal.funcs.allocation.lock1D(mRSC, this);
410 decRefs(ptr, mHal.state.type->getSizeBytes() / mHal.state.type->getElementSizeBytes(), 0);
411 mRSC->mHal.funcs.allocation.unlock1D(mRSC, this);
Jason Samsc7cec1e2011-08-18 18:01:33 -0700412}
413
414bool Allocation::freeChildren() {
415 if (mHal.state.hasReferences) {
416 incSysRef();
417 freeChildrenUnlocked();
418 return decSysRef();
419 }
420 return false;
421}
422
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800423void Allocation::copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len) {
Jason Sams96abf812010-10-05 13:32:49 -0700424}
425
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800426void Allocation::resize1D(Context *rsc, uint32_t dimX) {
Jason Samsa572aca2013-01-09 11:52:26 -0800427 uint32_t oldDimX = mHal.drvState.lod[0].dimX;
Jason Sams96abf812010-10-05 13:32:49 -0700428 if (dimX == oldDimX) {
429 return;
430 }
431
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700432 ObjectBaseRef<Type> t = mHal.state.type->cloneAndResize1D(rsc, dimX);
Jason Sams96abf812010-10-05 13:32:49 -0700433 if (dimX < oldDimX) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700434 decRefs(rsc->mHal.funcs.allocation.lock1D(rsc, this), oldDimX - dimX, dimX);
435 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Jason Sams96abf812010-10-05 13:32:49 -0700436 }
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700437 rsc->mHal.funcs.allocation.resize(rsc, this, t.get(), mHal.state.hasReferences);
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -0700438 setType(t.get());
Jason Samsbad80742011-03-16 16:29:28 -0700439 updateCache();
Jason Sams96abf812010-10-05 13:32:49 -0700440}
441
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800442void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000443 ALOGE("not implemented");
Jason Sams96abf812010-10-05 13:32:49 -0700444}
445
Jason Sams41e373d2012-01-13 14:01:20 -0800446int32_t Allocation::getSurfaceTextureID(const Context *rsc) {
447 int32_t id = rsc->mHal.funcs.allocation.initSurfaceTexture(rsc, this);
448 mHal.state.surfaceTextureID = id;
449 return id;
450}
451
Andy McFadden58fd6a52012-12-18 09:50:03 -0800452void Allocation::setSurfaceTexture(const Context *rsc, GLConsumer *st) {
Jason Sams3522f402012-03-23 11:47:26 -0700453 if(st != mHal.state.surfaceTexture) {
454 if(mHal.state.surfaceTexture != NULL) {
455 mHal.state.surfaceTexture->decStrong(NULL);
456 }
457 mHal.state.surfaceTexture = st;
458 if(mHal.state.surfaceTexture != NULL) {
459 mHal.state.surfaceTexture->incStrong(NULL);
460 }
461 }
462}
463
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800464void Allocation::setSurface(const Context *rsc, RsNativeWindow sur) {
465 ANativeWindow *nw = (ANativeWindow *)sur;
466 ANativeWindow *old = mHal.state.wndSurface;
467 if (nw) {
468 nw->incStrong(NULL);
469 }
470 rsc->mHal.funcs.allocation.setSurfaceTexture(rsc, this, nw);
471 mHal.state.wndSurface = nw;
472 if (old) {
473 old->decStrong(NULL);
474 }
475}
476
477void Allocation::ioSend(const Context *rsc) {
478 rsc->mHal.funcs.allocation.ioSend(rsc, this);
479}
480
481void Allocation::ioReceive(const Context *rsc) {
482 rsc->mHal.funcs.allocation.ioReceive(rsc, this);
483}
484
485
Jason Sams326e0dd2009-05-22 14:03:28 -0700486/////////////////
Jason Sams565ac362009-06-03 16:04:54 -0700487//
Stephen Hines6a121812011-03-01 17:34:59 -0800488
Jason Sams326e0dd2009-05-22 14:03:28 -0700489namespace android {
490namespace renderscript {
491
Jason Sams366c9c82010-12-08 16:14:36 -0800492void rsi_AllocationSyncAll(Context *rsc, RsAllocation va, RsAllocationUsageType src) {
493 Allocation *a = static_cast<Allocation *>(va);
Jason Samseb4fe182011-05-26 16:33:01 -0700494 a->sendDirty(rsc);
Jason Sams366c9c82010-12-08 16:14:36 -0800495 a->syncAll(rsc, src);
496}
497
Jason Samsa2371512011-01-12 13:28:37 -0800498void rsi_AllocationGenerateMipmaps(Context *rsc, RsAllocation va) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700499 Allocation *alloc = static_cast<Allocation *>(va);
500 rsc->mHal.funcs.allocation.generateMipmaps(rsc, alloc);
Jason Sams837e3882010-12-10 16:03:15 -0800501}
502
Jason Sams807fdc42012-07-25 17:55:39 -0700503void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) {
504 Allocation *a = static_cast<Allocation *>(va);
505 const Type * t = a->getType();
506 a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
507 t->getDimX(), t->getDimY(), data, sizeBytes);
Alex Sakhartchouk39f2ef62010-10-11 12:35:15 -0700508}
509
Jason Sams4b45b892010-12-29 14:31:29 -0800510void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700511 uint32_t count, const void *data, size_t sizeBytes) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700512 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800513 a->data(rsc, xoff, lod, count, data, sizeBytes);
Jason Sams326e0dd2009-05-22 14:03:28 -0700514}
515
Jason Sams4b45b892010-12-29 14:31:29 -0800516void rsi_Allocation2DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t lod, RsAllocationCubemapFace face,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800517 const void *data, size_t sizeBytes, size_t eoff) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700518 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800519 a->elementData(rsc, x, y, data, eoff, sizeBytes);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700520}
521
Jason Sams4b45b892010-12-29 14:31:29 -0800522void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800523 const void *data, size_t sizeBytes, size_t eoff) {
Jason Sams5f0c84c2010-08-31 13:50:42 -0700524 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800525 a->elementData(rsc, x, data, eoff, sizeBytes);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700526}
527
Jason Sams4b45b892010-12-29 14:31:29 -0800528void rsi_Allocation2DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
Tim Murray358747a2012-11-26 13:52:04 -0800529 uint32_t w, uint32_t h, const void *data, size_t sizeBytes, size_t stride) {
Jason Sams5f0c84c2010-08-31 13:50:42 -0700530 Allocation *a = static_cast<Allocation *>(va);
Tim Murray358747a2012-11-26 13:52:04 -0800531 a->data(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Jason Sams326e0dd2009-05-22 14:03:28 -0700532}
533
Jason Sams807fdc42012-07-25 17:55:39 -0700534void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) {
Jason Samse579df42009-08-10 14:55:26 -0700535 Allocation *a = static_cast<Allocation *>(va);
Jason Sams807fdc42012-07-25 17:55:39 -0700536 const Type * t = a->getType();
537 if(t->getDimY()) {
538 a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
539 t->getDimX(), t->getDimY(), data, sizeBytes);
540 } else {
541 a->read(rsc, 0, 0, t->getDimX(), data, sizeBytes);
542 }
543
Jason Samse579df42009-08-10 14:55:26 -0700544}
545
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800546void rsi_AllocationResize1D(Context *rsc, RsAllocation va, uint32_t dimX) {
Jason Sams96abf812010-10-05 13:32:49 -0700547 Allocation *a = static_cast<Allocation *>(va);
548 a->resize1D(rsc, dimX);
549}
550
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800551void rsi_AllocationResize2D(Context *rsc, RsAllocation va, uint32_t dimX, uint32_t dimY) {
Jason Sams96abf812010-10-05 13:32:49 -0700552 Allocation *a = static_cast<Allocation *>(va);
553 a->resize2D(rsc, dimX, dimY);
554}
555
Jason Samsc975cf42011-04-28 18:26:48 -0700556RsAllocation rsi_AllocationCreateTyped(Context *rsc, RsType vtype,
557 RsAllocationMipmapControl mips,
Jason Sams179e9a42011-11-23 15:02:15 -0800558 uint32_t usages, uint32_t ptr) {
559 Allocation * alloc = Allocation::createAllocation(rsc, static_cast<Type *>(vtype), usages, mips, (void *)ptr);
Jason Samseb4fe182011-05-26 16:33:01 -0700560 if (!alloc) {
561 return NULL;
562 }
Jason Samsf0c1df42010-10-26 13:09:17 -0700563 alloc->incUserRef();
564 return alloc;
565}
566
Jason Samsc975cf42011-04-28 18:26:48 -0700567RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, RsType vtype,
568 RsAllocationMipmapControl mips,
Jason Sams807fdc42012-07-25 17:55:39 -0700569 const void *data, size_t sizeBytes, uint32_t usages) {
Jason Sams366c9c82010-12-08 16:14:36 -0800570 Type *t = static_cast<Type *>(vtype);
Jason Samsf0c1df42010-10-26 13:09:17 -0700571
Jason Sams179e9a42011-11-23 15:02:15 -0800572 RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0);
Jason Samsf0c1df42010-10-26 13:09:17 -0700573 Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
574 if (texAlloc == NULL) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000575 ALOGE("Memory allocation failure");
Jason Samsf0c1df42010-10-26 13:09:17 -0700576 return NULL;
577 }
578
Jason Sams807fdc42012-07-25 17:55:39 -0700579 texAlloc->data(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray60c27962013-02-07 16:15:23 -0800580 t->getDimX(), t->getDimY(), data, sizeBytes, 0);
Jason Samsebc50192010-12-13 15:32:35 -0800581 if (mips == RS_ALLOCATION_MIPMAP_FULL) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700582 rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc);
Jason Samsf0c1df42010-10-26 13:09:17 -0700583 }
584
Jason Samseb4fe182011-05-26 16:33:01 -0700585 texAlloc->sendDirty(rsc);
Jason Samsf0c1df42010-10-26 13:09:17 -0700586 return texAlloc;
587}
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800588
Jason Samsc975cf42011-04-28 18:26:48 -0700589RsAllocation rsi_AllocationCubeCreateFromBitmap(Context *rsc, RsType vtype,
590 RsAllocationMipmapControl mips,
Jason Sams807fdc42012-07-25 17:55:39 -0700591 const void *data, size_t sizeBytes, uint32_t usages) {
Jason Sams366c9c82010-12-08 16:14:36 -0800592 Type *t = static_cast<Type *>(vtype);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800593
594 // Cubemap allocation's faces should be Width by Width each.
595 // Source data should have 6 * Width by Width pixels
596 // Error checking is done in the java layer
Jason Sams179e9a42011-11-23 15:02:15 -0800597 RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800598 Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
599 if (texAlloc == NULL) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000600 ALOGE("Memory allocation failure");
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800601 return NULL;
602 }
603
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800604 uint32_t faceSize = t->getDimX();
605 uint32_t strideBytes = faceSize * 6 * t->getElementSizeBytes();
606 uint32_t copySize = faceSize * t->getElementSizeBytes();
607
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800608 uint8_t *sourcePtr = (uint8_t*)data;
Jason Sams366c9c82010-12-08 16:14:36 -0800609 for (uint32_t face = 0; face < 6; face ++) {
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800610 for (uint32_t dI = 0; dI < faceSize; dI ++) {
Jason Sams807fdc42012-07-25 17:55:39 -0700611 texAlloc->data(rsc, 0, dI, 0, (RsAllocationCubemapFace)face,
Tim Murray60c27962013-02-07 16:15:23 -0800612 t->getDimX(), 1, sourcePtr + strideBytes * dI, copySize, 0);
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800613 }
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800614
Jason Sams366c9c82010-12-08 16:14:36 -0800615 // Move the data pointer to the next cube face
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800616 sourcePtr += copySize;
Alex Sakhartchoukf8aafcf2011-01-11 14:47:44 -0800617 }
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800618
Alex Sakhartchoukf8aafcf2011-01-11 14:47:44 -0800619 if (mips == RS_ALLOCATION_MIPMAP_FULL) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700620 rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800621 }
622
Jason Samseb4fe182011-05-26 16:33:01 -0700623 texAlloc->sendDirty(rsc);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800624 return texAlloc;
625}
Alex Sakhartchouk099d7d32011-01-28 09:31:47 -0800626
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700627void rsi_AllocationCopy2DRange(Context *rsc,
628 RsAllocation dstAlloc,
629 uint32_t dstXoff, uint32_t dstYoff,
630 uint32_t dstMip, uint32_t dstFace,
631 uint32_t width, uint32_t height,
632 RsAllocation srcAlloc,
633 uint32_t srcXoff, uint32_t srcYoff,
634 uint32_t srcMip, uint32_t srcFace) {
635 Allocation *dst = static_cast<Allocation *>(dstAlloc);
636 Allocation *src= static_cast<Allocation *>(srcAlloc);
637 rsc->mHal.funcs.allocation.allocData2D(rsc, dst, dstXoff, dstYoff, dstMip,
638 (RsAllocationCubemapFace)dstFace,
639 width, height,
640 src, srcXoff, srcYoff,srcMip,
641 (RsAllocationCubemapFace)srcFace);
642}
643
Jason Sams41e373d2012-01-13 14:01:20 -0800644int32_t rsi_AllocationGetSurfaceTextureID(Context *rsc, RsAllocation valloc) {
645 Allocation *alloc = static_cast<Allocation *>(valloc);
646 return alloc->getSurfaceTextureID(rsc);
647}
648
Jason Sams3522f402012-03-23 11:47:26 -0700649void rsi_AllocationGetSurfaceTextureID2(Context *rsc, RsAllocation valloc, void *vst, size_t len) {
650 Allocation *alloc = static_cast<Allocation *>(valloc);
Andy McFadden58fd6a52012-12-18 09:50:03 -0800651 alloc->setSurfaceTexture(rsc, static_cast<GLConsumer *>(vst));
Jason Sams3522f402012-03-23 11:47:26 -0700652}
653
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800654void rsi_AllocationSetSurface(Context *rsc, RsAllocation valloc, RsNativeWindow sur) {
655 Allocation *alloc = static_cast<Allocation *>(valloc);
656 alloc->setSurface(rsc, sur);
657}
658
659void rsi_AllocationIoSend(Context *rsc, RsAllocation valloc) {
660 Allocation *alloc = static_cast<Allocation *>(valloc);
661 alloc->ioSend(rsc);
662}
663
664void rsi_AllocationIoReceive(Context *rsc, RsAllocation valloc) {
665 Allocation *alloc = static_cast<Allocation *>(valloc);
666 alloc->ioReceive(rsc);
667}
668
Tim Murray509ea5c2012-11-13 11:56:40 -0800669void rsi_Allocation1DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
670 uint32_t count, void *data, size_t sizeBytes) {
671 Allocation *a = static_cast<Allocation *>(va);
672 a->readUnchecked(rsc, xoff, lod, count, data, sizeBytes);
673}
674
Tim Murray7b3e3092012-11-16 13:32:24 -0800675void rsi_Allocation2DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff,
676 uint32_t lod, RsAllocationCubemapFace face, uint32_t w,
Tim Murray358747a2012-11-26 13:52:04 -0800677 uint32_t h, void *data, size_t sizeBytes, size_t stride) {
Tim Murray7b3e3092012-11-16 13:32:24 -0800678 Allocation *a = static_cast<Allocation *>(va);
Tim Murray358747a2012-11-26 13:52:04 -0800679 a->read(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Tim Murray7b3e3092012-11-16 13:32:24 -0800680}
681
Jason Samsc975cf42011-04-28 18:26:48 -0700682}
683}
684
685const void * rsaAllocationGetType(RsContext con, RsAllocation va) {
686 Allocation *a = static_cast<Allocation *>(va);
687 a->getType()->incUserRef();
688
689 return a->getType();
690}