blob: 0c271c1edb104cbf846c868b93f2c3092b72e8a6 [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
Stephen Hinesb0934b62013-07-03 17:27:38 -070022#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
Jason Sams7ac2a4d2012-02-15 12:04:24 -080023#include "system/window.h"
Andy McFadden58fd6a52012-12-18 09:50:03 -080024#include "gui/GLConsumer.h"
Tim Murray0b575de2013-03-15 15:56:43 -070025#endif
Alex Sakhartchouk39f2ef62010-10-11 12:35:15 -070026
Jason Sams326e0dd2009-05-22 14:03:28 -070027using namespace android;
28using namespace android::renderscript;
29
Alex Sakhartchouka2aab8b2010-12-15 09:59:58 -080030Allocation::Allocation(Context *rsc, const Type *type, uint32_t usages,
Jason Sams179e9a42011-11-23 15:02:15 -080031 RsAllocationMipmapControl mc, void * ptr)
Alex Sakhartchouka2aab8b2010-12-15 09:59:58 -080032 : ObjectBase(rsc) {
Jason Samsfa84da22010-03-01 15:31:04 -080033
Jason Samseb4fe182011-05-26 16:33:01 -070034 memset(&mHal, 0, sizeof(mHal));
35 mHal.state.mipmapControl = RS_ALLOCATION_MIPMAP_NONE;
Jason Samsbad80742011-03-16 16:29:28 -070036 mHal.state.usageFlags = usages;
37 mHal.state.mipmapControl = mc;
Tim Murray2e1a94d2012-11-29 13:12:25 -080038 mHal.state.userProvidedPtr = ptr;
Jason Sams366c9c82010-12-08 16:14:36 -080039
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070040 setType(type);
Jason Samsbad80742011-03-16 16:29:28 -070041 updateCache();
42}
Jason Samsfa84da22010-03-01 15:31:04 -080043
Tim Murray34689382013-03-11 12:12:03 -070044void Allocation::operator delete(void* ptr) {
45 if (ptr) {
46 Allocation *a = (Allocation*) ptr;
47 a->getContext()->mHal.funcs.freeRuntimeMem(ptr);
48 }
49}
50
Jason Samseb4fe182011-05-26 16:33:01 -070051Allocation * Allocation::createAllocation(Context *rsc, const Type *type, uint32_t usages,
Jason Sams179e9a42011-11-23 15:02:15 -080052 RsAllocationMipmapControl mc, void * ptr) {
Tim Murray34689382013-03-11 12:12:03 -070053 // Allocation objects must use allocator specified by the driver
54 void* allocMem = rsc->mHal.funcs.allocRuntimeMem(sizeof(Allocation), 0);
55
56 if (!allocMem) {
57 rsc->setError(RS_ERROR_FATAL_DRIVER, "Couldn't allocate memory for Allocation");
58 return NULL;
59 }
60
61 Allocation *a = new (allocMem) Allocation(rsc, type, usages, mc, ptr);
Jason Samseb4fe182011-05-26 16:33:01 -070062
63 if (!rsc->mHal.funcs.allocation.init(rsc, a, type->getElement()->getHasReferences())) {
64 rsc->setError(RS_ERROR_FATAL_DRIVER, "Allocation::Allocation, alloc failure");
65 delete a;
66 return NULL;
67 }
Jason Sams7ac2a4d2012-02-15 12:04:24 -080068
Jason Samseb4fe182011-05-26 16:33:01 -070069 return a;
70}
71
Jason Samsbad80742011-03-16 16:29:28 -070072void Allocation::updateCache() {
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070073 const Type *type = mHal.state.type;
Jason Samsa572aca2013-01-09 11:52:26 -080074 mHal.state.yuv = type->getDimYuv();
Jason Samsbad80742011-03-16 16:29:28 -070075 mHal.state.hasFaces = type->getDimFaces();
76 mHal.state.hasMipmaps = type->getDimLOD();
77 mHal.state.elementSizeBytes = type->getElementSizeBytes();
78 mHal.state.hasReferences = mHal.state.type->getElement()->getHasReferences();
Jason Sams326e0dd2009-05-22 14:03:28 -070079}
80
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080081Allocation::~Allocation() {
Jason Samsc7cec1e2011-08-18 18:01:33 -070082 freeChildrenUnlocked();
Jason Samseb4fe182011-05-26 16:33:01 -070083 mRSC->mHal.funcs.allocation.destroy(mRSC, this);
Jason Sams326e0dd2009-05-22 14:03:28 -070084}
85
Jason Sams366c9c82010-12-08 16:14:36 -080086void Allocation::syncAll(Context *rsc, RsAllocationUsageType src) {
Jason Samseb4fe182011-05-26 16:33:01 -070087 rsc->mHal.funcs.allocation.syncAll(rsc, this, src);
Jason Samscf4c7c92009-12-14 12:57:40 -080088}
89
Jason Sams4b45b892010-12-29 14:31:29 -080090void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod,
Stephen Hines6ae039b2012-01-18 18:46:27 -080091 uint32_t count, const void *data, size_t sizeBytes) {
92 const size_t eSize = mHal.state.type->getElementSizeBytes();
Jason Sams9397e302009-08-27 20:23:34 -070093
Jason Samseb4fe182011-05-26 16:33:01 -070094 if ((count * eSize) != sizeBytes) {
Stephen Hines6ae039b2012-01-18 18:46:27 -080095 ALOGE("Allocation::subData called with mismatched size expected %zu, got %zu",
Jason Samseb4fe182011-05-26 16:33:01 -070096 (count * eSize), sizeBytes);
Jason Samsbad80742011-03-16 16:29:28 -070097 mHal.state.type->dumpLOGV("type info");
Jason Sams9397e302009-08-27 20:23:34 -070098 return;
99 }
Jason Samse3929c92010-08-09 18:13:33 -0700100
Jason Samseb4fe182011-05-26 16:33:01 -0700101 rsc->mHal.funcs.allocation.data1D(rsc, this, xoff, lod, count, data, sizeBytes);
102 sendDirty(rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -0700103}
104
Jason Sams4b45b892010-12-29 14:31:29 -0800105void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
Tim Murray358747a2012-11-26 13:52:04 -0800106 uint32_t w, uint32_t h, const void *data, size_t sizeBytes, size_t stride) {
Tim Murray358747a2012-11-26 13:52:04 -0800107 rsc->mHal.funcs.allocation.data2D(rsc, this, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700108 sendDirty(rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -0700109}
110
Jason Sams236385b2011-01-12 14:53:25 -0800111void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700112 uint32_t lod,
113 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, size_t stride) {
114 rsc->mHal.funcs.allocation.data3D(rsc, this, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride);
115 sendDirty(rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -0700116}
117
Jason Sams807fdc42012-07-25 17:55:39 -0700118void Allocation::read(Context *rsc, uint32_t xoff, uint32_t lod,
Tim Murray358747a2012-11-26 13:52:04 -0800119 uint32_t count, void *data, size_t sizeBytes) {
Jason Sams807fdc42012-07-25 17:55:39 -0700120 const size_t eSize = mHal.state.type->getElementSizeBytes();
121
122 if ((count * eSize) != sizeBytes) {
123 ALOGE("Allocation::read called with mismatched size expected %zu, got %zu",
124 (count * eSize), sizeBytes);
125 mHal.state.type->dumpLOGV("type info");
126 return;
127 }
128
129 rsc->mHal.funcs.allocation.read1D(rsc, this, xoff, lod, count, data, sizeBytes);
130}
131
Tim Murray358747a2012-11-26 13:52:04 -0800132void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
133 uint32_t w, uint32_t h, void *data, size_t sizeBytes, size_t stride) {
134 const size_t eSize = mHal.state.elementSizeBytes;
135 const size_t lineSize = eSize * w;
136 if (!stride) {
137 stride = lineSize;
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700138 } else {
139 if ((lineSize * h) != sizeBytes) {
140 ALOGE("Allocation size mismatch, expected %zu, got %zu", (lineSize * h), sizeBytes);
141 rsAssert(!"Allocation::read called with mismatched size");
142 return;
143 }
Tim Murray358747a2012-11-26 13:52:04 -0800144 }
145
146 rsc->mHal.funcs.allocation.read2D(rsc, this, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700147}
148
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700149void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
150 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes, size_t stride) {
151 const size_t eSize = mHal.state.elementSizeBytes;
152 const size_t lineSize = eSize * w;
153 if (!stride) {
154 stride = lineSize;
155 }
156
157 rsc->mHal.funcs.allocation.read3D(rsc, this, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride);
158
Jason Sams807fdc42012-07-25 17:55:39 -0700159}
160
Jason Sams4b45b892010-12-29 14:31:29 -0800161void Allocation::elementData(Context *rsc, uint32_t x, const void *data,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800162 uint32_t cIdx, size_t sizeBytes) {
163 size_t eSize = mHal.state.elementSizeBytes;
Jason Sams5f0c84c2010-08-31 13:50:42 -0700164
Jason Samsbad80742011-03-16 16:29:28 -0700165 if (cIdx >= mHal.state.type->getElement()->getFieldCount()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000166 ALOGE("Error Allocation::subElementData component %i out of range.", cIdx);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700167 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range.");
168 return;
169 }
170
Jason Samsa572aca2013-01-09 11:52:26 -0800171 if (x >= mHal.drvState.lod[0].dimX) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000172 ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700173 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
174 return;
175 }
176
Jason Samsbad80742011-03-16 16:29:28 -0700177 const Element * e = mHal.state.type->getElement()->getField(cIdx);
Alex Sakhartchouk76946322012-02-02 09:47:26 -0800178 uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx);
179 if (sizeBytes != e->getSizeBytes() * elemArraySize) {
Stephen Hines6ae039b2012-01-18 18:46:27 -0800180 ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes());
Jason Sams5f0c84c2010-08-31 13:50:42 -0700181 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
182 return;
183 }
184
Jason Samseb4fe182011-05-26 16:33:01 -0700185 rsc->mHal.funcs.allocation.elementData1D(rsc, this, x, data, cIdx, sizeBytes);
186 sendDirty(rsc);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700187}
188
Jason Sams4b45b892010-12-29 14:31:29 -0800189void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800190 const void *data, uint32_t cIdx, size_t sizeBytes) {
191 size_t eSize = mHal.state.elementSizeBytes;
Jason Sams5f0c84c2010-08-31 13:50:42 -0700192
Jason Samsa572aca2013-01-09 11:52:26 -0800193 if (x >= mHal.drvState.lod[0].dimX) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000194 ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700195 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
196 return;
197 }
198
Jason Samsa572aca2013-01-09 11:52:26 -0800199 if (y >= mHal.drvState.lod[0].dimY) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000200 ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700201 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
202 return;
203 }
204
Jason Samsbad80742011-03-16 16:29:28 -0700205 if (cIdx >= mHal.state.type->getElement()->getFieldCount()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000206 ALOGE("Error Allocation::subElementData component %i out of range.", cIdx);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700207 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range.");
208 return;
209 }
210
Jason Samsbad80742011-03-16 16:29:28 -0700211 const Element * e = mHal.state.type->getElement()->getField(cIdx);
Alex Sakhartchouk76946322012-02-02 09:47:26 -0800212 uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx);
213 if (sizeBytes != e->getSizeBytes() * elemArraySize) {
Stephen Hines6ae039b2012-01-18 18:46:27 -0800214 ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes());
Jason Sams5f0c84c2010-08-31 13:50:42 -0700215 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
216 return;
217 }
218
Jason Samseb4fe182011-05-26 16:33:01 -0700219 rsc->mHal.funcs.allocation.elementData2D(rsc, this, x, y, data, cIdx, sizeBytes);
220 sendDirty(rsc);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700221}
222
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800223void Allocation::addProgramToDirty(const Program *p) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700224 mToDirtyList.push(p);
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700225}
Jason Sams326e0dd2009-05-22 14:03:28 -0700226
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800227void Allocation::removeProgramToDirty(const Program *p) {
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700228 for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
229 if (mToDirtyList[ct] == p) {
230 mToDirtyList.removeAt(ct);
231 return;
232 }
233 }
234 rsAssert(0);
235}
236
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800237void Allocation::dumpLOGV(const char *prefix) const {
Jason Samsc21cf402009-11-17 17:26:46 -0800238 ObjectBase::dumpLOGV(prefix);
239
240 String8 s(prefix);
241 s.append(" type ");
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -0700242 if (mHal.state.type) {
Jason Samsbad80742011-03-16 16:29:28 -0700243 mHal.state.type->dumpLOGV(s.string());
Jason Samsc21cf402009-11-17 17:26:46 -0800244 }
245
Steve Block65982012011-10-20 11:56:00 +0100246 ALOGV("%s allocation ptr=%p mUsageFlags=0x04%x, mMipmapControl=0x%04x",
Jason Sams709a0972012-11-15 18:18:04 -0800247 prefix, mHal.drvState.lod[0].mallocPtr, mHal.state.usageFlags, mHal.state.mipmapControl);
Jason Samsc21cf402009-11-17 17:26:46 -0800248}
Jason Sams326e0dd2009-05-22 14:03:28 -0700249
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800250uint32_t Allocation::getPackedSize() const {
251 uint32_t numItems = mHal.state.type->getSizeBytes() / mHal.state.type->getElementSizeBytes();
252 return numItems * mHal.state.type->getElement()->getSizeBytesUnpadded();
253}
254
Jason Samse3150cf2012-07-24 18:10:20 -0700255void Allocation::writePackedData(Context *rsc, const Type *type,
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800256 uint8_t *dst, const uint8_t *src, bool dstPadded) {
257 const Element *elem = type->getElement();
258 uint32_t unpaddedBytes = elem->getSizeBytesUnpadded();
259 uint32_t paddedBytes = elem->getSizeBytes();
260 uint32_t numItems = type->getSizeBytes() / paddedBytes;
261
262 uint32_t srcInc = !dstPadded ? paddedBytes : unpaddedBytes;
263 uint32_t dstInc = dstPadded ? paddedBytes : unpaddedBytes;
264
265 // no sub-elements
266 uint32_t fieldCount = elem->getFieldCount();
267 if (fieldCount == 0) {
268 for (uint32_t i = 0; i < numItems; i ++) {
269 memcpy(dst, src, unpaddedBytes);
270 src += srcInc;
271 dst += dstInc;
272 }
273 return;
274 }
275
276 // Cache offsets
277 uint32_t *offsetsPadded = new uint32_t[fieldCount];
278 uint32_t *offsetsUnpadded = new uint32_t[fieldCount];
279 uint32_t *sizeUnpadded = new uint32_t[fieldCount];
280
281 for (uint32_t i = 0; i < fieldCount; i++) {
282 offsetsPadded[i] = elem->getFieldOffsetBytes(i);
283 offsetsUnpadded[i] = elem->getFieldOffsetBytesUnpadded(i);
284 sizeUnpadded[i] = elem->getField(i)->getSizeBytesUnpadded();
285 }
286
287 uint32_t *srcOffsets = !dstPadded ? offsetsPadded : offsetsUnpadded;
288 uint32_t *dstOffsets = dstPadded ? offsetsPadded : offsetsUnpadded;
289
290 // complex elements, need to copy subelem after subelem
291 for (uint32_t i = 0; i < numItems; i ++) {
292 for (uint32_t fI = 0; fI < fieldCount; fI++) {
293 memcpy(dst + dstOffsets[fI], src + srcOffsets[fI], sizeUnpadded[fI]);
294 }
295 src += srcInc;
296 dst += dstInc;
297 }
298
299 delete[] offsetsPadded;
300 delete[] offsetsUnpadded;
301 delete[] sizeUnpadded;
302}
303
Jason Samse3150cf2012-07-24 18:10:20 -0700304void Allocation::unpackVec3Allocation(Context *rsc, const void *data, size_t dataSize) {
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800305 const uint8_t *src = (const uint8_t*)data;
Jason Sams61a4bb72012-07-25 19:33:43 -0700306 uint8_t *dst = (uint8_t *)rsc->mHal.funcs.allocation.lock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800307
Jason Samse3150cf2012-07-24 18:10:20 -0700308 writePackedData(rsc, getType(), dst, src, true);
Jason Sams61a4bb72012-07-25 19:33:43 -0700309 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800310}
311
Jason Samse3150cf2012-07-24 18:10:20 -0700312void Allocation::packVec3Allocation(Context *rsc, OStream *stream) const {
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800313 uint32_t paddedBytes = getType()->getElement()->getSizeBytes();
314 uint32_t unpaddedBytes = getType()->getElement()->getSizeBytesUnpadded();
315 uint32_t numItems = mHal.state.type->getSizeBytes() / paddedBytes;
316
Jason Sams61a4bb72012-07-25 19:33:43 -0700317 const uint8_t *src = (const uint8_t*)rsc->mHal.funcs.allocation.lock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800318 uint8_t *dst = new uint8_t[numItems * unpaddedBytes];
319
Jason Samse3150cf2012-07-24 18:10:20 -0700320 writePackedData(rsc, getType(), dst, src, false);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800321 stream->addByteArray(dst, getPackedSize());
322
323 delete[] dst;
Jason Sams61a4bb72012-07-25 19:33:43 -0700324 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800325}
326
Jason Samse3150cf2012-07-24 18:10:20 -0700327void Allocation::serialize(Context *rsc, OStream *stream) const {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700328 // Need to identify ourselves
329 stream->addU32((uint32_t)getClassId());
330
331 String8 name(getName());
332 stream->addString(&name);
333
334 // First thing we need to serialize is the type object since it will be needed
335 // to initialize the class
Jason Samse3150cf2012-07-24 18:10:20 -0700336 mHal.state.type->serialize(rsc, stream);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700337
Jason Samsbad80742011-03-16 16:29:28 -0700338 uint32_t dataSize = mHal.state.type->getSizeBytes();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800339 // 3 element vectors are padded to 4 in memory, but padding isn't serialized
340 uint32_t packedSize = getPackedSize();
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700341 // Write how much data we are storing
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800342 stream->addU32(packedSize);
343 if (dataSize == packedSize) {
344 // Now write the data
Jason Sams61a4bb72012-07-25 19:33:43 -0700345 stream->addByteArray(rsc->mHal.funcs.allocation.lock1D(rsc, this), dataSize);
346 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800347 } else {
348 // Now write the data
Jason Samse3150cf2012-07-24 18:10:20 -0700349 packVec3Allocation(rsc, stream);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800350 }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700351}
352
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800353Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700354 // First make sure we are reading the correct object
Alex Sakhartchoukb825f672010-06-04 10:06:50 -0700355 RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800356 if (classID != RS_A3D_CLASS_ID_ALLOCATION) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000357 ALOGE("allocation loading skipped due to invalid class id\n");
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700358 return NULL;
359 }
360
361 String8 name;
362 stream->loadString(&name);
363
364 Type *type = Type::createFromStream(rsc, stream);
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800365 if (!type) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700366 return NULL;
367 }
368 type->compute();
369
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800370 Allocation *alloc = Allocation::createAllocation(rsc, type, RS_ALLOCATION_USAGE_SCRIPT);
371 type->decUserRef();
372
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700373 // Number of bytes we wrote out for this allocation
374 uint32_t dataSize = stream->loadU32();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800375 // 3 element vectors are padded to 4 in memory, but padding isn't serialized
376 uint32_t packedSize = alloc->getPackedSize();
377 if (dataSize != type->getSizeBytes() &&
378 dataSize != packedSize) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000379 ALOGE("failed to read allocation because numbytes written is not the same loaded type wants\n");
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800380 ObjectBase::checkDelete(alloc);
Jason Sams225afd32010-10-21 14:06:55 -0700381 ObjectBase::checkDelete(type);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700382 return NULL;
383 }
384
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700385 alloc->setName(name.string(), name.size());
386
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800387 if (dataSize == type->getSizeBytes()) {
388 uint32_t count = dataSize / type->getElementSizeBytes();
389 // Read in all of our allocation data
390 alloc->data(rsc, 0, 0, count, stream->getPtr() + stream->getPos(), dataSize);
391 } else {
Jason Samse3150cf2012-07-24 18:10:20 -0700392 alloc->unpackVec3Allocation(rsc, stream->getPtr() + stream->getPos(), dataSize);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800393 }
Alex Sakhartchouke6d9fbc2010-08-11 10:30:44 -0700394 stream->reset(stream->getPos() + dataSize);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700395
396 return alloc;
397}
398
Jason Samseb4fe182011-05-26 16:33:01 -0700399void Allocation::sendDirty(const Context *rsc) const {
Jason Sams93eacc72012-12-18 14:26:57 -0800400#ifndef RS_COMPATIBILITY_LIB
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700401 for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
402 mToDirtyList[ct]->forceDirty();
403 }
Jason Sams93eacc72012-12-18 14:26:57 -0800404#endif
Jason Samseb4fe182011-05-26 16:33:01 -0700405 mRSC->mHal.funcs.allocation.markDirty(rsc, this);
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700406}
Jason Sams326e0dd2009-05-22 14:03:28 -0700407
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800408void Allocation::incRefs(const void *ptr, size_t ct, size_t startOff) const {
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700409 mHal.state.type->incRefs(ptr, ct, startOff);
Jason Samse3929c92010-08-09 18:13:33 -0700410}
411
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800412void Allocation::decRefs(const void *ptr, size_t ct, size_t startOff) const {
Alex Sakhartchouk5c4369a2011-08-12 11:30:30 -0700413 if (!mHal.state.hasReferences || !getIsScript()) {
414 return;
415 }
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700416 mHal.state.type->decRefs(ptr, ct, startOff);
Jason Samse3929c92010-08-09 18:13:33 -0700417}
418
Jason Samsc7cec1e2011-08-18 18:01:33 -0700419void Allocation::freeChildrenUnlocked () {
Jason Sams61a4bb72012-07-25 19:33:43 -0700420 void *ptr = mRSC->mHal.funcs.allocation.lock1D(mRSC, this);
421 decRefs(ptr, mHal.state.type->getSizeBytes() / mHal.state.type->getElementSizeBytes(), 0);
422 mRSC->mHal.funcs.allocation.unlock1D(mRSC, this);
Jason Samsc7cec1e2011-08-18 18:01:33 -0700423}
424
425bool Allocation::freeChildren() {
426 if (mHal.state.hasReferences) {
427 incSysRef();
428 freeChildrenUnlocked();
429 return decSysRef();
430 }
431 return false;
432}
433
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800434void Allocation::copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len) {
Jason Sams96abf812010-10-05 13:32:49 -0700435}
436
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800437void Allocation::resize1D(Context *rsc, uint32_t dimX) {
Jason Samsa572aca2013-01-09 11:52:26 -0800438 uint32_t oldDimX = mHal.drvState.lod[0].dimX;
Jason Sams96abf812010-10-05 13:32:49 -0700439 if (dimX == oldDimX) {
440 return;
441 }
442
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700443 ObjectBaseRef<Type> t = mHal.state.type->cloneAndResize1D(rsc, dimX);
Jason Sams96abf812010-10-05 13:32:49 -0700444 if (dimX < oldDimX) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700445 decRefs(rsc->mHal.funcs.allocation.lock1D(rsc, this), oldDimX - dimX, dimX);
446 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Jason Sams96abf812010-10-05 13:32:49 -0700447 }
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700448 rsc->mHal.funcs.allocation.resize(rsc, this, t.get(), mHal.state.hasReferences);
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -0700449 setType(t.get());
Jason Samsbad80742011-03-16 16:29:28 -0700450 updateCache();
Jason Sams96abf812010-10-05 13:32:49 -0700451}
452
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800453void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000454 ALOGE("not implemented");
Jason Sams96abf812010-10-05 13:32:49 -0700455}
456
Jason Sams733396b2013-02-22 12:46:18 -0800457void * Allocation::getSurface(const Context *rsc) {
458 return rsc->mHal.funcs.allocation.getSurface(rsc, this);
Jason Sams41e373d2012-01-13 14:01:20 -0800459}
460
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800461void Allocation::setSurface(const Context *rsc, RsNativeWindow sur) {
462 ANativeWindow *nw = (ANativeWindow *)sur;
Jason Sams733396b2013-02-22 12:46:18 -0800463 rsc->mHal.funcs.allocation.setSurface(rsc, this, nw);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800464}
465
466void Allocation::ioSend(const Context *rsc) {
467 rsc->mHal.funcs.allocation.ioSend(rsc, this);
468}
469
470void Allocation::ioReceive(const Context *rsc) {
471 rsc->mHal.funcs.allocation.ioReceive(rsc, this);
472}
473
474
Jason Sams326e0dd2009-05-22 14:03:28 -0700475/////////////////
Jason Sams565ac362009-06-03 16:04:54 -0700476//
Stephen Hines6a121812011-03-01 17:34:59 -0800477
Jason Sams326e0dd2009-05-22 14:03:28 -0700478namespace android {
479namespace renderscript {
480
Jason Sams366c9c82010-12-08 16:14:36 -0800481void rsi_AllocationSyncAll(Context *rsc, RsAllocation va, RsAllocationUsageType src) {
482 Allocation *a = static_cast<Allocation *>(va);
Jason Samseb4fe182011-05-26 16:33:01 -0700483 a->sendDirty(rsc);
Jason Sams366c9c82010-12-08 16:14:36 -0800484 a->syncAll(rsc, src);
485}
486
Jason Samsa2371512011-01-12 13:28:37 -0800487void rsi_AllocationGenerateMipmaps(Context *rsc, RsAllocation va) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700488 Allocation *alloc = static_cast<Allocation *>(va);
489 rsc->mHal.funcs.allocation.generateMipmaps(rsc, alloc);
Jason Sams837e3882010-12-10 16:03:15 -0800490}
491
Jason Sams807fdc42012-07-25 17:55:39 -0700492void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) {
493 Allocation *a = static_cast<Allocation *>(va);
494 const Type * t = a->getType();
495 a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700496 t->getDimX(), t->getDimY(), data, sizeBytes, 0);
Alex Sakhartchouk39f2ef62010-10-11 12:35:15 -0700497}
498
Jason Sams4b45b892010-12-29 14:31:29 -0800499void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700500 uint32_t count, const void *data, size_t sizeBytes) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700501 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800502 a->data(rsc, xoff, lod, count, data, sizeBytes);
Jason Sams326e0dd2009-05-22 14:03:28 -0700503}
504
Jason Sams4b45b892010-12-29 14:31:29 -0800505void rsi_Allocation2DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t lod, RsAllocationCubemapFace face,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800506 const void *data, size_t sizeBytes, size_t eoff) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700507 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800508 a->elementData(rsc, x, y, data, eoff, sizeBytes);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700509}
510
Jason Sams4b45b892010-12-29 14:31:29 -0800511void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800512 const void *data, size_t sizeBytes, size_t eoff) {
Jason Sams5f0c84c2010-08-31 13:50:42 -0700513 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800514 a->elementData(rsc, x, data, eoff, sizeBytes);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700515}
516
Jason Sams4b45b892010-12-29 14:31:29 -0800517void rsi_Allocation2DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
Tim Murray358747a2012-11-26 13:52:04 -0800518 uint32_t w, uint32_t h, const void *data, size_t sizeBytes, size_t stride) {
Jason Sams5f0c84c2010-08-31 13:50:42 -0700519 Allocation *a = static_cast<Allocation *>(va);
Tim Murray358747a2012-11-26 13:52:04 -0800520 a->data(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Jason Sams326e0dd2009-05-22 14:03:28 -0700521}
522
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700523void rsi_Allocation3DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
524 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, size_t stride) {
525 Allocation *a = static_cast<Allocation *>(va);
526 a->data(rsc, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride);
527}
528
529
Jason Sams807fdc42012-07-25 17:55:39 -0700530void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) {
Jason Samse579df42009-08-10 14:55:26 -0700531 Allocation *a = static_cast<Allocation *>(va);
Jason Sams807fdc42012-07-25 17:55:39 -0700532 const Type * t = a->getType();
533 if(t->getDimY()) {
534 a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700535 t->getDimX(), t->getDimY(), data, sizeBytes, 0);
Jason Sams807fdc42012-07-25 17:55:39 -0700536 } else {
537 a->read(rsc, 0, 0, t->getDimX(), data, sizeBytes);
538 }
539
Jason Samse579df42009-08-10 14:55:26 -0700540}
541
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800542void rsi_AllocationResize1D(Context *rsc, RsAllocation va, uint32_t dimX) {
Jason Sams96abf812010-10-05 13:32:49 -0700543 Allocation *a = static_cast<Allocation *>(va);
544 a->resize1D(rsc, dimX);
545}
546
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800547void rsi_AllocationResize2D(Context *rsc, RsAllocation va, uint32_t dimX, uint32_t dimY) {
Jason Sams96abf812010-10-05 13:32:49 -0700548 Allocation *a = static_cast<Allocation *>(va);
549 a->resize2D(rsc, dimX, dimY);
550}
551
Jason Samsc975cf42011-04-28 18:26:48 -0700552RsAllocation rsi_AllocationCreateTyped(Context *rsc, RsType vtype,
553 RsAllocationMipmapControl mips,
Tim Murray099bc262013-03-20 16:54:03 -0700554 uint32_t usages, uintptr_t ptr) {
555 Allocation * alloc = Allocation::createAllocation(rsc, static_cast<Type *>(vtype), usages, mips, (void*)ptr);
Jason Samseb4fe182011-05-26 16:33:01 -0700556 if (!alloc) {
557 return NULL;
558 }
Jason Samsf0c1df42010-10-26 13:09:17 -0700559 alloc->incUserRef();
560 return alloc;
561}
562
Jason Samsc975cf42011-04-28 18:26:48 -0700563RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, RsType vtype,
564 RsAllocationMipmapControl mips,
Jason Sams807fdc42012-07-25 17:55:39 -0700565 const void *data, size_t sizeBytes, uint32_t usages) {
Jason Sams366c9c82010-12-08 16:14:36 -0800566 Type *t = static_cast<Type *>(vtype);
Jason Samsf0c1df42010-10-26 13:09:17 -0700567
Jason Sams179e9a42011-11-23 15:02:15 -0800568 RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0);
Jason Samsf0c1df42010-10-26 13:09:17 -0700569 Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
570 if (texAlloc == NULL) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000571 ALOGE("Memory allocation failure");
Jason Samsf0c1df42010-10-26 13:09:17 -0700572 return NULL;
573 }
574
Jason Sams807fdc42012-07-25 17:55:39 -0700575 texAlloc->data(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray60c27962013-02-07 16:15:23 -0800576 t->getDimX(), t->getDimY(), data, sizeBytes, 0);
Jason Samsebc50192010-12-13 15:32:35 -0800577 if (mips == RS_ALLOCATION_MIPMAP_FULL) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700578 rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc);
Jason Samsf0c1df42010-10-26 13:09:17 -0700579 }
580
Jason Samseb4fe182011-05-26 16:33:01 -0700581 texAlloc->sendDirty(rsc);
Jason Samsf0c1df42010-10-26 13:09:17 -0700582 return texAlloc;
583}
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800584
Jason Samsc975cf42011-04-28 18:26:48 -0700585RsAllocation rsi_AllocationCubeCreateFromBitmap(Context *rsc, RsType vtype,
586 RsAllocationMipmapControl mips,
Jason Sams807fdc42012-07-25 17:55:39 -0700587 const void *data, size_t sizeBytes, uint32_t usages) {
Jason Sams366c9c82010-12-08 16:14:36 -0800588 Type *t = static_cast<Type *>(vtype);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800589
590 // Cubemap allocation's faces should be Width by Width each.
591 // Source data should have 6 * Width by Width pixels
592 // Error checking is done in the java layer
Jason Sams179e9a42011-11-23 15:02:15 -0800593 RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800594 Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
595 if (texAlloc == NULL) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000596 ALOGE("Memory allocation failure");
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800597 return NULL;
598 }
599
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800600 uint32_t faceSize = t->getDimX();
601 uint32_t strideBytes = faceSize * 6 * t->getElementSizeBytes();
602 uint32_t copySize = faceSize * t->getElementSizeBytes();
603
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800604 uint8_t *sourcePtr = (uint8_t*)data;
Jason Sams366c9c82010-12-08 16:14:36 -0800605 for (uint32_t face = 0; face < 6; face ++) {
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800606 for (uint32_t dI = 0; dI < faceSize; dI ++) {
Jason Sams807fdc42012-07-25 17:55:39 -0700607 texAlloc->data(rsc, 0, dI, 0, (RsAllocationCubemapFace)face,
Tim Murray60c27962013-02-07 16:15:23 -0800608 t->getDimX(), 1, sourcePtr + strideBytes * dI, copySize, 0);
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800609 }
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800610
Jason Sams366c9c82010-12-08 16:14:36 -0800611 // Move the data pointer to the next cube face
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800612 sourcePtr += copySize;
Alex Sakhartchoukf8aafcf2011-01-11 14:47:44 -0800613 }
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800614
Alex Sakhartchoukf8aafcf2011-01-11 14:47:44 -0800615 if (mips == RS_ALLOCATION_MIPMAP_FULL) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700616 rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800617 }
618
Jason Samseb4fe182011-05-26 16:33:01 -0700619 texAlloc->sendDirty(rsc);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800620 return texAlloc;
621}
Alex Sakhartchouk099d7d32011-01-28 09:31:47 -0800622
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700623void rsi_AllocationCopy2DRange(Context *rsc,
624 RsAllocation dstAlloc,
625 uint32_t dstXoff, uint32_t dstYoff,
626 uint32_t dstMip, uint32_t dstFace,
627 uint32_t width, uint32_t height,
628 RsAllocation srcAlloc,
629 uint32_t srcXoff, uint32_t srcYoff,
630 uint32_t srcMip, uint32_t srcFace) {
631 Allocation *dst = static_cast<Allocation *>(dstAlloc);
632 Allocation *src= static_cast<Allocation *>(srcAlloc);
633 rsc->mHal.funcs.allocation.allocData2D(rsc, dst, dstXoff, dstYoff, dstMip,
634 (RsAllocationCubemapFace)dstFace,
635 width, height,
636 src, srcXoff, srcYoff,srcMip,
637 (RsAllocationCubemapFace)srcFace);
638}
639
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700640void rsi_AllocationCopy3DRange(Context *rsc,
641 RsAllocation dstAlloc,
642 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
643 uint32_t dstMip,
644 uint32_t width, uint32_t height, uint32_t depth,
645 RsAllocation srcAlloc,
646 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
647 uint32_t srcMip) {
648 Allocation *dst = static_cast<Allocation *>(dstAlloc);
649 Allocation *src= static_cast<Allocation *>(srcAlloc);
650 rsc->mHal.funcs.allocation.allocData3D(rsc, dst, dstXoff, dstYoff, dstZoff, dstMip,
651 width, height, depth,
652 src, srcXoff, srcYoff, srcZoff, srcMip);
653}
654
655
Jason Sams733396b2013-02-22 12:46:18 -0800656void * rsi_AllocationGetSurface(Context *rsc, RsAllocation valloc) {
Jason Sams41e373d2012-01-13 14:01:20 -0800657 Allocation *alloc = static_cast<Allocation *>(valloc);
Jason Sams733396b2013-02-22 12:46:18 -0800658 void *s = alloc->getSurface(rsc);
659 return s;
Jason Sams3522f402012-03-23 11:47:26 -0700660}
661
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800662void rsi_AllocationSetSurface(Context *rsc, RsAllocation valloc, RsNativeWindow sur) {
663 Allocation *alloc = static_cast<Allocation *>(valloc);
664 alloc->setSurface(rsc, sur);
665}
666
667void rsi_AllocationIoSend(Context *rsc, RsAllocation valloc) {
668 Allocation *alloc = static_cast<Allocation *>(valloc);
669 alloc->ioSend(rsc);
670}
671
672void rsi_AllocationIoReceive(Context *rsc, RsAllocation valloc) {
673 Allocation *alloc = static_cast<Allocation *>(valloc);
674 alloc->ioReceive(rsc);
675}
676
Tim Murray509ea5c2012-11-13 11:56:40 -0800677void rsi_Allocation1DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
678 uint32_t count, void *data, size_t sizeBytes) {
679 Allocation *a = static_cast<Allocation *>(va);
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700680 rsc->mHal.funcs.allocation.read1D(rsc, a, xoff, lod, count, data, sizeBytes);
Tim Murray509ea5c2012-11-13 11:56:40 -0800681}
682
Tim Murray7b3e3092012-11-16 13:32:24 -0800683void rsi_Allocation2DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff,
684 uint32_t lod, RsAllocationCubemapFace face, uint32_t w,
Tim Murray358747a2012-11-26 13:52:04 -0800685 uint32_t h, void *data, size_t sizeBytes, size_t stride) {
Tim Murray7b3e3092012-11-16 13:32:24 -0800686 Allocation *a = static_cast<Allocation *>(va);
Tim Murray358747a2012-11-26 13:52:04 -0800687 a->read(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Tim Murray7b3e3092012-11-16 13:32:24 -0800688}
689
Jason Samsc975cf42011-04-28 18:26:48 -0700690}
691}
692
693const void * rsaAllocationGetType(RsContext con, RsAllocation va) {
694 Allocation *a = static_cast<Allocation *>(va);
695 a->getType()->incUserRef();
696
697 return a->getType();
698}