blob: c861d09c83f29f87751da67f070d7e06682d55a4 [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);
Jason Sams48ecf6a2013-07-09 15:35:29 -0700239 char buf[1024];
Jason Samsc21cf402009-11-17 17:26:46 -0800240
Jason Sams48ecf6a2013-07-09 15:35:29 -0700241 if ((strlen(prefix) + 10) < sizeof(buf)) {
242 sprintf(buf, "%s type ", prefix);
243 if (mHal.state.type) {
244 mHal.state.type->dumpLOGV(buf);
245 }
Jason Samsc21cf402009-11-17 17:26:46 -0800246 }
Steve Block65982012011-10-20 11:56:00 +0100247 ALOGV("%s allocation ptr=%p mUsageFlags=0x04%x, mMipmapControl=0x%04x",
Jason Sams709a0972012-11-15 18:18:04 -0800248 prefix, mHal.drvState.lod[0].mallocPtr, mHal.state.usageFlags, mHal.state.mipmapControl);
Jason Samsc21cf402009-11-17 17:26:46 -0800249}
Jason Sams326e0dd2009-05-22 14:03:28 -0700250
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800251uint32_t Allocation::getPackedSize() const {
252 uint32_t numItems = mHal.state.type->getSizeBytes() / mHal.state.type->getElementSizeBytes();
253 return numItems * mHal.state.type->getElement()->getSizeBytesUnpadded();
254}
255
Jason Samse3150cf2012-07-24 18:10:20 -0700256void Allocation::writePackedData(Context *rsc, const Type *type,
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800257 uint8_t *dst, const uint8_t *src, bool dstPadded) {
258 const Element *elem = type->getElement();
259 uint32_t unpaddedBytes = elem->getSizeBytesUnpadded();
260 uint32_t paddedBytes = elem->getSizeBytes();
261 uint32_t numItems = type->getSizeBytes() / paddedBytes;
262
263 uint32_t srcInc = !dstPadded ? paddedBytes : unpaddedBytes;
264 uint32_t dstInc = dstPadded ? paddedBytes : unpaddedBytes;
265
266 // no sub-elements
267 uint32_t fieldCount = elem->getFieldCount();
268 if (fieldCount == 0) {
269 for (uint32_t i = 0; i < numItems; i ++) {
270 memcpy(dst, src, unpaddedBytes);
271 src += srcInc;
272 dst += dstInc;
273 }
274 return;
275 }
276
277 // Cache offsets
278 uint32_t *offsetsPadded = new uint32_t[fieldCount];
279 uint32_t *offsetsUnpadded = new uint32_t[fieldCount];
280 uint32_t *sizeUnpadded = new uint32_t[fieldCount];
281
282 for (uint32_t i = 0; i < fieldCount; i++) {
283 offsetsPadded[i] = elem->getFieldOffsetBytes(i);
284 offsetsUnpadded[i] = elem->getFieldOffsetBytesUnpadded(i);
285 sizeUnpadded[i] = elem->getField(i)->getSizeBytesUnpadded();
286 }
287
288 uint32_t *srcOffsets = !dstPadded ? offsetsPadded : offsetsUnpadded;
289 uint32_t *dstOffsets = dstPadded ? offsetsPadded : offsetsUnpadded;
290
291 // complex elements, need to copy subelem after subelem
292 for (uint32_t i = 0; i < numItems; i ++) {
293 for (uint32_t fI = 0; fI < fieldCount; fI++) {
294 memcpy(dst + dstOffsets[fI], src + srcOffsets[fI], sizeUnpadded[fI]);
295 }
296 src += srcInc;
297 dst += dstInc;
298 }
299
300 delete[] offsetsPadded;
301 delete[] offsetsUnpadded;
302 delete[] sizeUnpadded;
303}
304
Jason Samse3150cf2012-07-24 18:10:20 -0700305void Allocation::unpackVec3Allocation(Context *rsc, const void *data, size_t dataSize) {
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800306 const uint8_t *src = (const uint8_t*)data;
Jason Sams61a4bb72012-07-25 19:33:43 -0700307 uint8_t *dst = (uint8_t *)rsc->mHal.funcs.allocation.lock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800308
Jason Samse3150cf2012-07-24 18:10:20 -0700309 writePackedData(rsc, getType(), dst, src, true);
Jason Sams61a4bb72012-07-25 19:33:43 -0700310 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800311}
312
Jason Samse3150cf2012-07-24 18:10:20 -0700313void Allocation::packVec3Allocation(Context *rsc, OStream *stream) const {
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800314 uint32_t paddedBytes = getType()->getElement()->getSizeBytes();
315 uint32_t unpaddedBytes = getType()->getElement()->getSizeBytesUnpadded();
316 uint32_t numItems = mHal.state.type->getSizeBytes() / paddedBytes;
317
Jason Sams61a4bb72012-07-25 19:33:43 -0700318 const uint8_t *src = (const uint8_t*)rsc->mHal.funcs.allocation.lock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800319 uint8_t *dst = new uint8_t[numItems * unpaddedBytes];
320
Jason Samse3150cf2012-07-24 18:10:20 -0700321 writePackedData(rsc, getType(), dst, src, false);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800322 stream->addByteArray(dst, getPackedSize());
323
324 delete[] dst;
Jason Sams61a4bb72012-07-25 19:33:43 -0700325 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800326}
327
Jason Samse3150cf2012-07-24 18:10:20 -0700328void Allocation::serialize(Context *rsc, OStream *stream) const {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700329 // Need to identify ourselves
330 stream->addU32((uint32_t)getClassId());
Jason Sams48ecf6a2013-07-09 15:35:29 -0700331 stream->addString(getName());
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700332
333 // First thing we need to serialize is the type object since it will be needed
334 // to initialize the class
Jason Samse3150cf2012-07-24 18:10:20 -0700335 mHal.state.type->serialize(rsc, stream);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700336
Jason Samsbad80742011-03-16 16:29:28 -0700337 uint32_t dataSize = mHal.state.type->getSizeBytes();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800338 // 3 element vectors are padded to 4 in memory, but padding isn't serialized
339 uint32_t packedSize = getPackedSize();
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700340 // Write how much data we are storing
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800341 stream->addU32(packedSize);
342 if (dataSize == packedSize) {
343 // Now write the data
Jason Sams61a4bb72012-07-25 19:33:43 -0700344 stream->addByteArray(rsc->mHal.funcs.allocation.lock1D(rsc, this), dataSize);
345 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800346 } else {
347 // Now write the data
Jason Samse3150cf2012-07-24 18:10:20 -0700348 packVec3Allocation(rsc, stream);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800349 }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700350}
351
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800352Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700353 // First make sure we are reading the correct object
Alex Sakhartchoukb825f672010-06-04 10:06:50 -0700354 RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800355 if (classID != RS_A3D_CLASS_ID_ALLOCATION) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000356 ALOGE("allocation loading skipped due to invalid class id\n");
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700357 return NULL;
358 }
359
Jason Sams48ecf6a2013-07-09 15:35:29 -0700360 const char *name = stream->loadString();
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700361
362 Type *type = Type::createFromStream(rsc, stream);
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800363 if (!type) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700364 return NULL;
365 }
366 type->compute();
367
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800368 Allocation *alloc = Allocation::createAllocation(rsc, type, RS_ALLOCATION_USAGE_SCRIPT);
369 type->decUserRef();
370
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700371 // Number of bytes we wrote out for this allocation
372 uint32_t dataSize = stream->loadU32();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800373 // 3 element vectors are padded to 4 in memory, but padding isn't serialized
374 uint32_t packedSize = alloc->getPackedSize();
375 if (dataSize != type->getSizeBytes() &&
376 dataSize != packedSize) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000377 ALOGE("failed to read allocation because numbytes written is not the same loaded type wants\n");
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800378 ObjectBase::checkDelete(alloc);
Jason Sams225afd32010-10-21 14:06:55 -0700379 ObjectBase::checkDelete(type);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700380 return NULL;
381 }
382
Jason Sams48ecf6a2013-07-09 15:35:29 -0700383 alloc->assignName(name);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800384 if (dataSize == type->getSizeBytes()) {
385 uint32_t count = dataSize / type->getElementSizeBytes();
386 // Read in all of our allocation data
387 alloc->data(rsc, 0, 0, count, stream->getPtr() + stream->getPos(), dataSize);
388 } else {
Jason Samse3150cf2012-07-24 18:10:20 -0700389 alloc->unpackVec3Allocation(rsc, stream->getPtr() + stream->getPos(), dataSize);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800390 }
Alex Sakhartchouke6d9fbc2010-08-11 10:30:44 -0700391 stream->reset(stream->getPos() + dataSize);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700392
393 return alloc;
394}
395
Jason Samseb4fe182011-05-26 16:33:01 -0700396void Allocation::sendDirty(const Context *rsc) const {
Jason Sams93eacc72012-12-18 14:26:57 -0800397#ifndef RS_COMPATIBILITY_LIB
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700398 for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
399 mToDirtyList[ct]->forceDirty();
400 }
Jason Sams93eacc72012-12-18 14:26:57 -0800401#endif
Jason Samseb4fe182011-05-26 16:33:01 -0700402 mRSC->mHal.funcs.allocation.markDirty(rsc, this);
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700403}
Jason Sams326e0dd2009-05-22 14:03:28 -0700404
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800405void Allocation::incRefs(const void *ptr, size_t ct, size_t startOff) const {
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700406 mHal.state.type->incRefs(ptr, ct, startOff);
Jason Samse3929c92010-08-09 18:13:33 -0700407}
408
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800409void Allocation::decRefs(const void *ptr, size_t ct, size_t startOff) const {
Alex Sakhartchouk5c4369a2011-08-12 11:30:30 -0700410 if (!mHal.state.hasReferences || !getIsScript()) {
411 return;
412 }
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700413 mHal.state.type->decRefs(ptr, ct, startOff);
Jason Samse3929c92010-08-09 18:13:33 -0700414}
415
Jason Samsc7cec1e2011-08-18 18:01:33 -0700416void Allocation::freeChildrenUnlocked () {
Jason Sams61a4bb72012-07-25 19:33:43 -0700417 void *ptr = mRSC->mHal.funcs.allocation.lock1D(mRSC, this);
418 decRefs(ptr, mHal.state.type->getSizeBytes() / mHal.state.type->getElementSizeBytes(), 0);
419 mRSC->mHal.funcs.allocation.unlock1D(mRSC, this);
Jason Samsc7cec1e2011-08-18 18:01:33 -0700420}
421
422bool Allocation::freeChildren() {
423 if (mHal.state.hasReferences) {
424 incSysRef();
425 freeChildrenUnlocked();
426 return decSysRef();
427 }
428 return false;
429}
430
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800431void Allocation::copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len) {
Jason Sams96abf812010-10-05 13:32:49 -0700432}
433
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800434void Allocation::resize1D(Context *rsc, uint32_t dimX) {
Jason Samsa572aca2013-01-09 11:52:26 -0800435 uint32_t oldDimX = mHal.drvState.lod[0].dimX;
Jason Sams96abf812010-10-05 13:32:49 -0700436 if (dimX == oldDimX) {
437 return;
438 }
439
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700440 ObjectBaseRef<Type> t = mHal.state.type->cloneAndResize1D(rsc, dimX);
Jason Sams96abf812010-10-05 13:32:49 -0700441 if (dimX < oldDimX) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700442 decRefs(rsc->mHal.funcs.allocation.lock1D(rsc, this), oldDimX - dimX, dimX);
443 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Jason Sams96abf812010-10-05 13:32:49 -0700444 }
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700445 rsc->mHal.funcs.allocation.resize(rsc, this, t.get(), mHal.state.hasReferences);
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -0700446 setType(t.get());
Jason Samsbad80742011-03-16 16:29:28 -0700447 updateCache();
Jason Sams96abf812010-10-05 13:32:49 -0700448}
449
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800450void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000451 ALOGE("not implemented");
Jason Sams96abf812010-10-05 13:32:49 -0700452}
453
Jason Sams733396b2013-02-22 12:46:18 -0800454void * Allocation::getSurface(const Context *rsc) {
455 return rsc->mHal.funcs.allocation.getSurface(rsc, this);
Jason Sams41e373d2012-01-13 14:01:20 -0800456}
457
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800458void Allocation::setSurface(const Context *rsc, RsNativeWindow sur) {
459 ANativeWindow *nw = (ANativeWindow *)sur;
Jason Sams733396b2013-02-22 12:46:18 -0800460 rsc->mHal.funcs.allocation.setSurface(rsc, this, nw);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800461}
462
463void Allocation::ioSend(const Context *rsc) {
464 rsc->mHal.funcs.allocation.ioSend(rsc, this);
465}
466
467void Allocation::ioReceive(const Context *rsc) {
468 rsc->mHal.funcs.allocation.ioReceive(rsc, this);
469}
470
471
Jason Sams326e0dd2009-05-22 14:03:28 -0700472/////////////////
Jason Sams565ac362009-06-03 16:04:54 -0700473//
Stephen Hines6a121812011-03-01 17:34:59 -0800474
Jason Sams326e0dd2009-05-22 14:03:28 -0700475namespace android {
476namespace renderscript {
477
Jason Sams366c9c82010-12-08 16:14:36 -0800478void rsi_AllocationSyncAll(Context *rsc, RsAllocation va, RsAllocationUsageType src) {
479 Allocation *a = static_cast<Allocation *>(va);
Jason Samseb4fe182011-05-26 16:33:01 -0700480 a->sendDirty(rsc);
Jason Sams366c9c82010-12-08 16:14:36 -0800481 a->syncAll(rsc, src);
482}
483
Jason Samsa2371512011-01-12 13:28:37 -0800484void rsi_AllocationGenerateMipmaps(Context *rsc, RsAllocation va) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700485 Allocation *alloc = static_cast<Allocation *>(va);
486 rsc->mHal.funcs.allocation.generateMipmaps(rsc, alloc);
Jason Sams837e3882010-12-10 16:03:15 -0800487}
488
Jason Sams807fdc42012-07-25 17:55:39 -0700489void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) {
490 Allocation *a = static_cast<Allocation *>(va);
491 const Type * t = a->getType();
492 a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700493 t->getDimX(), t->getDimY(), data, sizeBytes, 0);
Alex Sakhartchouk39f2ef62010-10-11 12:35:15 -0700494}
495
Jason Sams4b45b892010-12-29 14:31:29 -0800496void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700497 uint32_t count, const void *data, size_t sizeBytes) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700498 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800499 a->data(rsc, xoff, lod, count, data, sizeBytes);
Jason Sams326e0dd2009-05-22 14:03:28 -0700500}
501
Jason Sams4b45b892010-12-29 14:31:29 -0800502void rsi_Allocation2DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t lod, RsAllocationCubemapFace face,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800503 const void *data, size_t sizeBytes, size_t eoff) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700504 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800505 a->elementData(rsc, x, y, data, eoff, sizeBytes);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700506}
507
Jason Sams4b45b892010-12-29 14:31:29 -0800508void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800509 const void *data, size_t sizeBytes, size_t eoff) {
Jason Sams5f0c84c2010-08-31 13:50:42 -0700510 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800511 a->elementData(rsc, x, data, eoff, sizeBytes);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700512}
513
Jason Sams4b45b892010-12-29 14:31:29 -0800514void rsi_Allocation2DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
Tim Murray358747a2012-11-26 13:52:04 -0800515 uint32_t w, uint32_t h, const void *data, size_t sizeBytes, size_t stride) {
Jason Sams5f0c84c2010-08-31 13:50:42 -0700516 Allocation *a = static_cast<Allocation *>(va);
Tim Murray358747a2012-11-26 13:52:04 -0800517 a->data(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Jason Sams326e0dd2009-05-22 14:03:28 -0700518}
519
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700520void rsi_Allocation3DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
521 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, size_t stride) {
522 Allocation *a = static_cast<Allocation *>(va);
523 a->data(rsc, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride);
524}
525
526
Jason Sams807fdc42012-07-25 17:55:39 -0700527void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) {
Jason Samse579df42009-08-10 14:55:26 -0700528 Allocation *a = static_cast<Allocation *>(va);
Jason Sams807fdc42012-07-25 17:55:39 -0700529 const Type * t = a->getType();
530 if(t->getDimY()) {
531 a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700532 t->getDimX(), t->getDimY(), data, sizeBytes, 0);
Jason Sams807fdc42012-07-25 17:55:39 -0700533 } else {
534 a->read(rsc, 0, 0, t->getDimX(), data, sizeBytes);
535 }
536
Jason Samse579df42009-08-10 14:55:26 -0700537}
538
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800539void rsi_AllocationResize1D(Context *rsc, RsAllocation va, uint32_t dimX) {
Jason Sams96abf812010-10-05 13:32:49 -0700540 Allocation *a = static_cast<Allocation *>(va);
541 a->resize1D(rsc, dimX);
542}
543
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800544void rsi_AllocationResize2D(Context *rsc, RsAllocation va, uint32_t dimX, uint32_t dimY) {
Jason Sams96abf812010-10-05 13:32:49 -0700545 Allocation *a = static_cast<Allocation *>(va);
546 a->resize2D(rsc, dimX, dimY);
547}
548
Jason Samsc975cf42011-04-28 18:26:48 -0700549RsAllocation rsi_AllocationCreateTyped(Context *rsc, RsType vtype,
550 RsAllocationMipmapControl mips,
Tim Murray099bc262013-03-20 16:54:03 -0700551 uint32_t usages, uintptr_t ptr) {
552 Allocation * alloc = Allocation::createAllocation(rsc, static_cast<Type *>(vtype), usages, mips, (void*)ptr);
Jason Samseb4fe182011-05-26 16:33:01 -0700553 if (!alloc) {
554 return NULL;
555 }
Jason Samsf0c1df42010-10-26 13:09:17 -0700556 alloc->incUserRef();
557 return alloc;
558}
559
Jason Samsc975cf42011-04-28 18:26:48 -0700560RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, RsType vtype,
561 RsAllocationMipmapControl mips,
Jason Sams807fdc42012-07-25 17:55:39 -0700562 const void *data, size_t sizeBytes, uint32_t usages) {
Jason Sams366c9c82010-12-08 16:14:36 -0800563 Type *t = static_cast<Type *>(vtype);
Jason Samsf0c1df42010-10-26 13:09:17 -0700564
Jason Sams179e9a42011-11-23 15:02:15 -0800565 RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0);
Jason Samsf0c1df42010-10-26 13:09:17 -0700566 Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
567 if (texAlloc == NULL) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000568 ALOGE("Memory allocation failure");
Jason Samsf0c1df42010-10-26 13:09:17 -0700569 return NULL;
570 }
571
Jason Sams807fdc42012-07-25 17:55:39 -0700572 texAlloc->data(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray60c27962013-02-07 16:15:23 -0800573 t->getDimX(), t->getDimY(), data, sizeBytes, 0);
Jason Samsebc50192010-12-13 15:32:35 -0800574 if (mips == RS_ALLOCATION_MIPMAP_FULL) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700575 rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc);
Jason Samsf0c1df42010-10-26 13:09:17 -0700576 }
577
Jason Samseb4fe182011-05-26 16:33:01 -0700578 texAlloc->sendDirty(rsc);
Jason Samsf0c1df42010-10-26 13:09:17 -0700579 return texAlloc;
580}
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800581
Jason Samsc975cf42011-04-28 18:26:48 -0700582RsAllocation rsi_AllocationCubeCreateFromBitmap(Context *rsc, RsType vtype,
583 RsAllocationMipmapControl mips,
Jason Sams807fdc42012-07-25 17:55:39 -0700584 const void *data, size_t sizeBytes, uint32_t usages) {
Jason Sams366c9c82010-12-08 16:14:36 -0800585 Type *t = static_cast<Type *>(vtype);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800586
587 // Cubemap allocation's faces should be Width by Width each.
588 // Source data should have 6 * Width by Width pixels
589 // Error checking is done in the java layer
Jason Sams179e9a42011-11-23 15:02:15 -0800590 RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800591 Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
592 if (texAlloc == NULL) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000593 ALOGE("Memory allocation failure");
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800594 return NULL;
595 }
596
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800597 uint32_t faceSize = t->getDimX();
598 uint32_t strideBytes = faceSize * 6 * t->getElementSizeBytes();
599 uint32_t copySize = faceSize * t->getElementSizeBytes();
600
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800601 uint8_t *sourcePtr = (uint8_t*)data;
Jason Sams366c9c82010-12-08 16:14:36 -0800602 for (uint32_t face = 0; face < 6; face ++) {
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800603 for (uint32_t dI = 0; dI < faceSize; dI ++) {
Jason Sams807fdc42012-07-25 17:55:39 -0700604 texAlloc->data(rsc, 0, dI, 0, (RsAllocationCubemapFace)face,
Tim Murray60c27962013-02-07 16:15:23 -0800605 t->getDimX(), 1, sourcePtr + strideBytes * dI, copySize, 0);
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800606 }
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800607
Jason Sams366c9c82010-12-08 16:14:36 -0800608 // Move the data pointer to the next cube face
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800609 sourcePtr += copySize;
Alex Sakhartchoukf8aafcf2011-01-11 14:47:44 -0800610 }
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800611
Alex Sakhartchoukf8aafcf2011-01-11 14:47:44 -0800612 if (mips == RS_ALLOCATION_MIPMAP_FULL) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700613 rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800614 }
615
Jason Samseb4fe182011-05-26 16:33:01 -0700616 texAlloc->sendDirty(rsc);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800617 return texAlloc;
618}
Alex Sakhartchouk099d7d32011-01-28 09:31:47 -0800619
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700620void rsi_AllocationCopy2DRange(Context *rsc,
621 RsAllocation dstAlloc,
622 uint32_t dstXoff, uint32_t dstYoff,
623 uint32_t dstMip, uint32_t dstFace,
624 uint32_t width, uint32_t height,
625 RsAllocation srcAlloc,
626 uint32_t srcXoff, uint32_t srcYoff,
627 uint32_t srcMip, uint32_t srcFace) {
628 Allocation *dst = static_cast<Allocation *>(dstAlloc);
629 Allocation *src= static_cast<Allocation *>(srcAlloc);
630 rsc->mHal.funcs.allocation.allocData2D(rsc, dst, dstXoff, dstYoff, dstMip,
631 (RsAllocationCubemapFace)dstFace,
632 width, height,
633 src, srcXoff, srcYoff,srcMip,
634 (RsAllocationCubemapFace)srcFace);
635}
636
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700637void rsi_AllocationCopy3DRange(Context *rsc,
638 RsAllocation dstAlloc,
639 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
640 uint32_t dstMip,
641 uint32_t width, uint32_t height, uint32_t depth,
642 RsAllocation srcAlloc,
643 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
644 uint32_t srcMip) {
645 Allocation *dst = static_cast<Allocation *>(dstAlloc);
646 Allocation *src= static_cast<Allocation *>(srcAlloc);
647 rsc->mHal.funcs.allocation.allocData3D(rsc, dst, dstXoff, dstYoff, dstZoff, dstMip,
648 width, height, depth,
649 src, srcXoff, srcYoff, srcZoff, srcMip);
650}
651
652
Jason Sams733396b2013-02-22 12:46:18 -0800653void * rsi_AllocationGetSurface(Context *rsc, RsAllocation valloc) {
Jason Sams41e373d2012-01-13 14:01:20 -0800654 Allocation *alloc = static_cast<Allocation *>(valloc);
Jason Sams733396b2013-02-22 12:46:18 -0800655 void *s = alloc->getSurface(rsc);
656 return s;
Jason Sams3522f402012-03-23 11:47:26 -0700657}
658
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800659void rsi_AllocationSetSurface(Context *rsc, RsAllocation valloc, RsNativeWindow sur) {
660 Allocation *alloc = static_cast<Allocation *>(valloc);
661 alloc->setSurface(rsc, sur);
662}
663
664void rsi_AllocationIoSend(Context *rsc, RsAllocation valloc) {
665 Allocation *alloc = static_cast<Allocation *>(valloc);
666 alloc->ioSend(rsc);
667}
668
669void rsi_AllocationIoReceive(Context *rsc, RsAllocation valloc) {
670 Allocation *alloc = static_cast<Allocation *>(valloc);
671 alloc->ioReceive(rsc);
672}
673
Tim Murray509ea5c2012-11-13 11:56:40 -0800674void rsi_Allocation1DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
675 uint32_t count, void *data, size_t sizeBytes) {
676 Allocation *a = static_cast<Allocation *>(va);
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700677 rsc->mHal.funcs.allocation.read1D(rsc, a, xoff, lod, count, data, sizeBytes);
Tim Murray509ea5c2012-11-13 11:56:40 -0800678}
679
Tim Murray7b3e3092012-11-16 13:32:24 -0800680void rsi_Allocation2DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff,
681 uint32_t lod, RsAllocationCubemapFace face, uint32_t w,
Tim Murray358747a2012-11-26 13:52:04 -0800682 uint32_t h, void *data, size_t sizeBytes, size_t stride) {
Tim Murray7b3e3092012-11-16 13:32:24 -0800683 Allocation *a = static_cast<Allocation *>(va);
Tim Murray358747a2012-11-26 13:52:04 -0800684 a->read(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Tim Murray7b3e3092012-11-16 13:32:24 -0800685}
686
Jason Samsc975cf42011-04-28 18:26:48 -0700687}
688}
689
Tim Murrayc2ce7072013-07-17 18:38:53 -0700690extern "C" const void * rsaAllocationGetType(RsContext con, RsAllocation va) {
Jason Samsc975cf42011-04-28 18:26:48 -0700691 Allocation *a = static_cast<Allocation *>(va);
692 a->getType()->incUserRef();
693
694 return a->getType();
695}