blob: f6f4ac9b3f5e643bbf9d016777a9801e89f84471 [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 Samsddceab92013-08-07 13:02:32 -070082#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
83 if (mGrallocConsumer.get()) {
84 mGrallocConsumer->unlockBuffer();
85 mGrallocConsumer = NULL;
86 }
87#endif
88
Jason Samsc7cec1e2011-08-18 18:01:33 -070089 freeChildrenUnlocked();
Jason Samseb4fe182011-05-26 16:33:01 -070090 mRSC->mHal.funcs.allocation.destroy(mRSC, this);
Jason Sams326e0dd2009-05-22 14:03:28 -070091}
92
Jason Sams366c9c82010-12-08 16:14:36 -080093void Allocation::syncAll(Context *rsc, RsAllocationUsageType src) {
Jason Samseb4fe182011-05-26 16:33:01 -070094 rsc->mHal.funcs.allocation.syncAll(rsc, this, src);
Jason Samscf4c7c92009-12-14 12:57:40 -080095}
96
Jason Sams4b45b892010-12-29 14:31:29 -080097void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod,
Stephen Hines6ae039b2012-01-18 18:46:27 -080098 uint32_t count, const void *data, size_t sizeBytes) {
99 const size_t eSize = mHal.state.type->getElementSizeBytes();
Jason Sams9397e302009-08-27 20:23:34 -0700100
Jason Samseb4fe182011-05-26 16:33:01 -0700101 if ((count * eSize) != sizeBytes) {
Stephen Hines6ae039b2012-01-18 18:46:27 -0800102 ALOGE("Allocation::subData called with mismatched size expected %zu, got %zu",
Jason Samseb4fe182011-05-26 16:33:01 -0700103 (count * eSize), sizeBytes);
Jason Samsbad80742011-03-16 16:29:28 -0700104 mHal.state.type->dumpLOGV("type info");
Jason Sams9397e302009-08-27 20:23:34 -0700105 return;
106 }
Jason Samse3929c92010-08-09 18:13:33 -0700107
Jason Samseb4fe182011-05-26 16:33:01 -0700108 rsc->mHal.funcs.allocation.data1D(rsc, this, xoff, lod, count, data, sizeBytes);
109 sendDirty(rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -0700110}
111
Jason Sams4b45b892010-12-29 14:31:29 -0800112void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
Tim Murray358747a2012-11-26 13:52:04 -0800113 uint32_t w, uint32_t h, const void *data, size_t sizeBytes, size_t stride) {
Tim Murray358747a2012-11-26 13:52:04 -0800114 rsc->mHal.funcs.allocation.data2D(rsc, this, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Jason Samseb4fe182011-05-26 16:33:01 -0700115 sendDirty(rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -0700116}
117
Jason Sams236385b2011-01-12 14:53:25 -0800118void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700119 uint32_t lod,
120 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, size_t stride) {
121 rsc->mHal.funcs.allocation.data3D(rsc, this, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride);
122 sendDirty(rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -0700123}
124
Jason Sams807fdc42012-07-25 17:55:39 -0700125void Allocation::read(Context *rsc, uint32_t xoff, uint32_t lod,
Tim Murray358747a2012-11-26 13:52:04 -0800126 uint32_t count, void *data, size_t sizeBytes) {
Jason Sams807fdc42012-07-25 17:55:39 -0700127 const size_t eSize = mHal.state.type->getElementSizeBytes();
128
129 if ((count * eSize) != sizeBytes) {
130 ALOGE("Allocation::read called with mismatched size expected %zu, got %zu",
131 (count * eSize), sizeBytes);
132 mHal.state.type->dumpLOGV("type info");
133 return;
134 }
135
136 rsc->mHal.funcs.allocation.read1D(rsc, this, xoff, lod, count, data, sizeBytes);
137}
138
Tim Murray358747a2012-11-26 13:52:04 -0800139void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
140 uint32_t w, uint32_t h, void *data, size_t sizeBytes, size_t stride) {
141 const size_t eSize = mHal.state.elementSizeBytes;
142 const size_t lineSize = eSize * w;
143 if (!stride) {
144 stride = lineSize;
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700145 } else {
146 if ((lineSize * h) != sizeBytes) {
147 ALOGE("Allocation size mismatch, expected %zu, got %zu", (lineSize * h), sizeBytes);
148 rsAssert(!"Allocation::read called with mismatched size");
149 return;
150 }
Tim Murray358747a2012-11-26 13:52:04 -0800151 }
152
153 rsc->mHal.funcs.allocation.read2D(rsc, this, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Jason Sams807fdc42012-07-25 17:55:39 -0700154}
155
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700156void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
157 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes, size_t stride) {
158 const size_t eSize = mHal.state.elementSizeBytes;
159 const size_t lineSize = eSize * w;
160 if (!stride) {
161 stride = lineSize;
162 }
163
164 rsc->mHal.funcs.allocation.read3D(rsc, this, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride);
165
Jason Sams807fdc42012-07-25 17:55:39 -0700166}
167
Jason Sams4b45b892010-12-29 14:31:29 -0800168void Allocation::elementData(Context *rsc, uint32_t x, const void *data,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800169 uint32_t cIdx, size_t sizeBytes) {
170 size_t eSize = mHal.state.elementSizeBytes;
Jason Sams5f0c84c2010-08-31 13:50:42 -0700171
Jason Samsbad80742011-03-16 16:29:28 -0700172 if (cIdx >= mHal.state.type->getElement()->getFieldCount()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000173 ALOGE("Error Allocation::subElementData component %i out of range.", cIdx);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700174 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range.");
175 return;
176 }
177
Jason Samsa572aca2013-01-09 11:52:26 -0800178 if (x >= mHal.drvState.lod[0].dimX) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000179 ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700180 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
181 return;
182 }
183
Jason Samsbad80742011-03-16 16:29:28 -0700184 const Element * e = mHal.state.type->getElement()->getField(cIdx);
Alex Sakhartchouk76946322012-02-02 09:47:26 -0800185 uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx);
186 if (sizeBytes != e->getSizeBytes() * elemArraySize) {
Stephen Hines6ae039b2012-01-18 18:46:27 -0800187 ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes());
Jason Sams5f0c84c2010-08-31 13:50:42 -0700188 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
189 return;
190 }
191
Jason Samseb4fe182011-05-26 16:33:01 -0700192 rsc->mHal.funcs.allocation.elementData1D(rsc, this, x, data, cIdx, sizeBytes);
193 sendDirty(rsc);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700194}
195
Jason Sams4b45b892010-12-29 14:31:29 -0800196void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800197 const void *data, uint32_t cIdx, size_t sizeBytes) {
198 size_t eSize = mHal.state.elementSizeBytes;
Jason Sams5f0c84c2010-08-31 13:50:42 -0700199
Jason Samsa572aca2013-01-09 11:52:26 -0800200 if (x >= mHal.drvState.lod[0].dimX) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000201 ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700202 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
203 return;
204 }
205
Jason Samsa572aca2013-01-09 11:52:26 -0800206 if (y >= mHal.drvState.lod[0].dimY) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000207 ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700208 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
209 return;
210 }
211
Jason Samsbad80742011-03-16 16:29:28 -0700212 if (cIdx >= mHal.state.type->getElement()->getFieldCount()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000213 ALOGE("Error Allocation::subElementData component %i out of range.", cIdx);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700214 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range.");
215 return;
216 }
217
Jason Samsbad80742011-03-16 16:29:28 -0700218 const Element * e = mHal.state.type->getElement()->getField(cIdx);
Alex Sakhartchouk76946322012-02-02 09:47:26 -0800219 uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx);
220 if (sizeBytes != e->getSizeBytes() * elemArraySize) {
Stephen Hines6ae039b2012-01-18 18:46:27 -0800221 ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes());
Jason Sams5f0c84c2010-08-31 13:50:42 -0700222 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
223 return;
224 }
225
Jason Samseb4fe182011-05-26 16:33:01 -0700226 rsc->mHal.funcs.allocation.elementData2D(rsc, this, x, y, data, cIdx, sizeBytes);
227 sendDirty(rsc);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700228}
229
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800230void Allocation::addProgramToDirty(const Program *p) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700231 mToDirtyList.push(p);
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700232}
Jason Sams326e0dd2009-05-22 14:03:28 -0700233
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800234void Allocation::removeProgramToDirty(const Program *p) {
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700235 for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
236 if (mToDirtyList[ct] == p) {
237 mToDirtyList.removeAt(ct);
238 return;
239 }
240 }
241 rsAssert(0);
242}
243
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800244void Allocation::dumpLOGV(const char *prefix) const {
Jason Samsc21cf402009-11-17 17:26:46 -0800245 ObjectBase::dumpLOGV(prefix);
Jason Sams48ecf6a2013-07-09 15:35:29 -0700246 char buf[1024];
Jason Samsc21cf402009-11-17 17:26:46 -0800247
Jason Sams48ecf6a2013-07-09 15:35:29 -0700248 if ((strlen(prefix) + 10) < sizeof(buf)) {
249 sprintf(buf, "%s type ", prefix);
250 if (mHal.state.type) {
251 mHal.state.type->dumpLOGV(buf);
252 }
Jason Samsc21cf402009-11-17 17:26:46 -0800253 }
Steve Block65982012011-10-20 11:56:00 +0100254 ALOGV("%s allocation ptr=%p mUsageFlags=0x04%x, mMipmapControl=0x%04x",
Jason Sams709a0972012-11-15 18:18:04 -0800255 prefix, mHal.drvState.lod[0].mallocPtr, mHal.state.usageFlags, mHal.state.mipmapControl);
Jason Samsc21cf402009-11-17 17:26:46 -0800256}
Jason Sams326e0dd2009-05-22 14:03:28 -0700257
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800258uint32_t Allocation::getPackedSize() const {
Jason Sams61656a72013-09-03 16:21:18 -0700259 uint32_t numItems = mHal.state.type->getCellCount();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800260 return numItems * mHal.state.type->getElement()->getSizeBytesUnpadded();
261}
262
Jason Samse3150cf2012-07-24 18:10:20 -0700263void Allocation::writePackedData(Context *rsc, const Type *type,
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800264 uint8_t *dst, const uint8_t *src, bool dstPadded) {
265 const Element *elem = type->getElement();
266 uint32_t unpaddedBytes = elem->getSizeBytesUnpadded();
267 uint32_t paddedBytes = elem->getSizeBytes();
Jason Sams61656a72013-09-03 16:21:18 -0700268 uint32_t numItems = type->getPackedSizeBytes() / paddedBytes;
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800269
270 uint32_t srcInc = !dstPadded ? paddedBytes : unpaddedBytes;
271 uint32_t dstInc = dstPadded ? paddedBytes : unpaddedBytes;
272
273 // no sub-elements
274 uint32_t fieldCount = elem->getFieldCount();
275 if (fieldCount == 0) {
276 for (uint32_t i = 0; i < numItems; i ++) {
277 memcpy(dst, src, unpaddedBytes);
278 src += srcInc;
279 dst += dstInc;
280 }
281 return;
282 }
283
284 // Cache offsets
285 uint32_t *offsetsPadded = new uint32_t[fieldCount];
286 uint32_t *offsetsUnpadded = new uint32_t[fieldCount];
287 uint32_t *sizeUnpadded = new uint32_t[fieldCount];
288
289 for (uint32_t i = 0; i < fieldCount; i++) {
290 offsetsPadded[i] = elem->getFieldOffsetBytes(i);
291 offsetsUnpadded[i] = elem->getFieldOffsetBytesUnpadded(i);
292 sizeUnpadded[i] = elem->getField(i)->getSizeBytesUnpadded();
293 }
294
295 uint32_t *srcOffsets = !dstPadded ? offsetsPadded : offsetsUnpadded;
296 uint32_t *dstOffsets = dstPadded ? offsetsPadded : offsetsUnpadded;
297
298 // complex elements, need to copy subelem after subelem
299 for (uint32_t i = 0; i < numItems; i ++) {
300 for (uint32_t fI = 0; fI < fieldCount; fI++) {
301 memcpy(dst + dstOffsets[fI], src + srcOffsets[fI], sizeUnpadded[fI]);
302 }
303 src += srcInc;
304 dst += dstInc;
305 }
306
307 delete[] offsetsPadded;
308 delete[] offsetsUnpadded;
309 delete[] sizeUnpadded;
310}
311
Jason Samse3150cf2012-07-24 18:10:20 -0700312void Allocation::unpackVec3Allocation(Context *rsc, const void *data, size_t dataSize) {
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800313 const uint8_t *src = (const uint8_t*)data;
Jason Sams61a4bb72012-07-25 19:33:43 -0700314 uint8_t *dst = (uint8_t *)rsc->mHal.funcs.allocation.lock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800315
Jason Samse3150cf2012-07-24 18:10:20 -0700316 writePackedData(rsc, getType(), dst, src, true);
Jason Sams61a4bb72012-07-25 19:33:43 -0700317 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800318}
319
Jason Samse3150cf2012-07-24 18:10:20 -0700320void Allocation::packVec3Allocation(Context *rsc, OStream *stream) const {
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800321 uint32_t paddedBytes = getType()->getElement()->getSizeBytes();
322 uint32_t unpaddedBytes = getType()->getElement()->getSizeBytesUnpadded();
Jason Sams61656a72013-09-03 16:21:18 -0700323 uint32_t numItems = mHal.state.type->getCellCount();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800324
Jason Sams61a4bb72012-07-25 19:33:43 -0700325 const uint8_t *src = (const uint8_t*)rsc->mHal.funcs.allocation.lock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800326 uint8_t *dst = new uint8_t[numItems * unpaddedBytes];
327
Jason Samse3150cf2012-07-24 18:10:20 -0700328 writePackedData(rsc, getType(), dst, src, false);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800329 stream->addByteArray(dst, getPackedSize());
330
331 delete[] dst;
Jason Sams61a4bb72012-07-25 19:33:43 -0700332 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800333}
334
Jason Samse3150cf2012-07-24 18:10:20 -0700335void Allocation::serialize(Context *rsc, OStream *stream) const {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700336 // Need to identify ourselves
337 stream->addU32((uint32_t)getClassId());
Jason Sams48ecf6a2013-07-09 15:35:29 -0700338 stream->addString(getName());
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700339
340 // First thing we need to serialize is the type object since it will be needed
341 // to initialize the class
Jason Samse3150cf2012-07-24 18:10:20 -0700342 mHal.state.type->serialize(rsc, stream);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700343
Jason Sams61656a72013-09-03 16:21:18 -0700344 uint32_t dataSize = mHal.state.type->getPackedSizeBytes();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800345 // 3 element vectors are padded to 4 in memory, but padding isn't serialized
346 uint32_t packedSize = getPackedSize();
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700347 // Write how much data we are storing
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800348 stream->addU32(packedSize);
349 if (dataSize == packedSize) {
350 // Now write the data
Jason Sams61a4bb72012-07-25 19:33:43 -0700351 stream->addByteArray(rsc->mHal.funcs.allocation.lock1D(rsc, this), dataSize);
352 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800353 } else {
354 // Now write the data
Jason Samse3150cf2012-07-24 18:10:20 -0700355 packVec3Allocation(rsc, stream);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800356 }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700357}
358
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800359Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700360 // First make sure we are reading the correct object
Alex Sakhartchoukb825f672010-06-04 10:06:50 -0700361 RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800362 if (classID != RS_A3D_CLASS_ID_ALLOCATION) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000363 ALOGE("allocation loading skipped due to invalid class id\n");
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700364 return NULL;
365 }
366
Jason Sams48ecf6a2013-07-09 15:35:29 -0700367 const char *name = stream->loadString();
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700368
369 Type *type = Type::createFromStream(rsc, stream);
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800370 if (!type) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700371 return NULL;
372 }
373 type->compute();
374
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800375 Allocation *alloc = Allocation::createAllocation(rsc, type, RS_ALLOCATION_USAGE_SCRIPT);
376 type->decUserRef();
377
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700378 // Number of bytes we wrote out for this allocation
379 uint32_t dataSize = stream->loadU32();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800380 // 3 element vectors are padded to 4 in memory, but padding isn't serialized
381 uint32_t packedSize = alloc->getPackedSize();
Jason Sams61656a72013-09-03 16:21:18 -0700382 if (dataSize != type->getPackedSizeBytes() &&
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800383 dataSize != packedSize) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000384 ALOGE("failed to read allocation because numbytes written is not the same loaded type wants\n");
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800385 ObjectBase::checkDelete(alloc);
Jason Sams225afd32010-10-21 14:06:55 -0700386 ObjectBase::checkDelete(type);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700387 return NULL;
388 }
389
Jason Sams48ecf6a2013-07-09 15:35:29 -0700390 alloc->assignName(name);
Jason Sams61656a72013-09-03 16:21:18 -0700391 if (dataSize == type->getPackedSizeBytes()) {
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800392 uint32_t count = dataSize / type->getElementSizeBytes();
393 // Read in all of our allocation data
394 alloc->data(rsc, 0, 0, count, stream->getPtr() + stream->getPos(), dataSize);
395 } else {
Jason Samse3150cf2012-07-24 18:10:20 -0700396 alloc->unpackVec3Allocation(rsc, stream->getPtr() + stream->getPos(), dataSize);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800397 }
Alex Sakhartchouke6d9fbc2010-08-11 10:30:44 -0700398 stream->reset(stream->getPos() + dataSize);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700399
400 return alloc;
401}
402
Jason Samseb4fe182011-05-26 16:33:01 -0700403void Allocation::sendDirty(const Context *rsc) const {
Jason Sams93eacc72012-12-18 14:26:57 -0800404#ifndef RS_COMPATIBILITY_LIB
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700405 for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
406 mToDirtyList[ct]->forceDirty();
407 }
Jason Sams93eacc72012-12-18 14:26:57 -0800408#endif
Jason Samseb4fe182011-05-26 16:33:01 -0700409 mRSC->mHal.funcs.allocation.markDirty(rsc, this);
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700410}
Jason Sams326e0dd2009-05-22 14:03:28 -0700411
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800412void Allocation::incRefs(const void *ptr, size_t ct, size_t startOff) const {
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700413 mHal.state.type->incRefs(ptr, ct, startOff);
Jason Samse3929c92010-08-09 18:13:33 -0700414}
415
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800416void Allocation::decRefs(const void *ptr, size_t ct, size_t startOff) const {
Alex Sakhartchouk5c4369a2011-08-12 11:30:30 -0700417 if (!mHal.state.hasReferences || !getIsScript()) {
418 return;
419 }
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700420 mHal.state.type->decRefs(ptr, ct, startOff);
Jason Samse3929c92010-08-09 18:13:33 -0700421}
422
Jason Samsc7cec1e2011-08-18 18:01:33 -0700423void Allocation::freeChildrenUnlocked () {
Jason Sams61a4bb72012-07-25 19:33:43 -0700424 void *ptr = mRSC->mHal.funcs.allocation.lock1D(mRSC, this);
Jason Sams61656a72013-09-03 16:21:18 -0700425 decRefs(ptr, mHal.state.type->getCellCount(), 0);
Jason Sams61a4bb72012-07-25 19:33:43 -0700426 mRSC->mHal.funcs.allocation.unlock1D(mRSC, this);
Jason Samsc7cec1e2011-08-18 18:01:33 -0700427}
428
429bool Allocation::freeChildren() {
430 if (mHal.state.hasReferences) {
431 incSysRef();
432 freeChildrenUnlocked();
433 return decSysRef();
434 }
435 return false;
436}
437
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800438void Allocation::copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len) {
Jason Sams96abf812010-10-05 13:32:49 -0700439}
440
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800441void Allocation::resize1D(Context *rsc, uint32_t dimX) {
Jason Samsa572aca2013-01-09 11:52:26 -0800442 uint32_t oldDimX = mHal.drvState.lod[0].dimX;
Jason Sams96abf812010-10-05 13:32:49 -0700443 if (dimX == oldDimX) {
444 return;
445 }
446
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700447 ObjectBaseRef<Type> t = mHal.state.type->cloneAndResize1D(rsc, dimX);
Jason Sams96abf812010-10-05 13:32:49 -0700448 if (dimX < oldDimX) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700449 decRefs(rsc->mHal.funcs.allocation.lock1D(rsc, this), oldDimX - dimX, dimX);
450 rsc->mHal.funcs.allocation.unlock1D(rsc, this);
Jason Sams96abf812010-10-05 13:32:49 -0700451 }
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700452 rsc->mHal.funcs.allocation.resize(rsc, this, t.get(), mHal.state.hasReferences);
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -0700453 setType(t.get());
Jason Samsbad80742011-03-16 16:29:28 -0700454 updateCache();
Jason Sams96abf812010-10-05 13:32:49 -0700455}
456
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800457void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000458 ALOGE("not implemented");
Jason Sams96abf812010-10-05 13:32:49 -0700459}
460
Jason Samsddceab92013-08-07 13:02:32 -0700461#ifndef RS_COMPATIBILITY_LIB
462void Allocation::NewBufferListener::onFrameAvailable() {
463 intptr_t ip = (intptr_t)alloc;
464 rsc->sendMessageToClient(NULL, RS_MESSAGE_TO_CLIENT_NEW_BUFFER, ip, 0, true);
465}
466#endif
467
Jason Sams733396b2013-02-22 12:46:18 -0800468void * Allocation::getSurface(const Context *rsc) {
Jason Samsddceab92013-08-07 13:02:32 -0700469#ifndef RS_COMPATIBILITY_LIB
470 // Configure GrallocConsumer to be in asynchronous mode
471 sp<BufferQueue> bq = new BufferQueue();
472 mGrallocConsumer = new GrallocConsumer(this, bq);
473 sp<IGraphicBufferProducer> bp = bq;
474 bp->incStrong(NULL);
475
476 mBufferListener = new NewBufferListener();
477 mBufferListener->rsc = rsc;
478 mBufferListener->alloc = this;
479
480 mGrallocConsumer->setFrameAvailableListener(mBufferListener);
481 return bp.get();
482#else
483 return NULL;
484#endif
485 //return rsc->mHal.funcs.allocation.getSurface(rsc, this);
Jason Sams41e373d2012-01-13 14:01:20 -0800486}
487
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800488void Allocation::setSurface(const Context *rsc, RsNativeWindow sur) {
489 ANativeWindow *nw = (ANativeWindow *)sur;
Jason Sams733396b2013-02-22 12:46:18 -0800490 rsc->mHal.funcs.allocation.setSurface(rsc, this, nw);
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800491}
492
493void Allocation::ioSend(const Context *rsc) {
494 rsc->mHal.funcs.allocation.ioSend(rsc, this);
495}
496
497void Allocation::ioReceive(const Context *rsc) {
Jason Samsddceab92013-08-07 13:02:32 -0700498 void *ptr = NULL;
499 size_t stride = 0;
500#ifndef RS_COMPATIBILITY_LIB
501 if (mHal.state.usageFlags & RS_ALLOCATION_USAGE_SCRIPT) {
502 status_t ret = mGrallocConsumer->lockNextBuffer();
503
504 if (ret == OK) {
505 rsc->mHal.funcs.allocation.ioReceive(rsc, this);
506 } else if (ret == BAD_VALUE) {
507 // No new frame, don't do anything
508 } else {
509 rsc->setError(RS_ERROR_DRIVER, "Error receiving IO input buffer.");
510 }
511
512 }
513#endif
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800514}
515
516
Jason Sams326e0dd2009-05-22 14:03:28 -0700517/////////////////
Jason Sams565ac362009-06-03 16:04:54 -0700518//
Stephen Hines6a121812011-03-01 17:34:59 -0800519
Jason Sams326e0dd2009-05-22 14:03:28 -0700520namespace android {
521namespace renderscript {
522
Jason Sams366c9c82010-12-08 16:14:36 -0800523void rsi_AllocationSyncAll(Context *rsc, RsAllocation va, RsAllocationUsageType src) {
524 Allocation *a = static_cast<Allocation *>(va);
Jason Samseb4fe182011-05-26 16:33:01 -0700525 a->sendDirty(rsc);
Jason Sams366c9c82010-12-08 16:14:36 -0800526 a->syncAll(rsc, src);
527}
528
Jason Samsa2371512011-01-12 13:28:37 -0800529void rsi_AllocationGenerateMipmaps(Context *rsc, RsAllocation va) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700530 Allocation *alloc = static_cast<Allocation *>(va);
531 rsc->mHal.funcs.allocation.generateMipmaps(rsc, alloc);
Jason Sams837e3882010-12-10 16:03:15 -0800532}
533
Jason Sams807fdc42012-07-25 17:55:39 -0700534void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) {
535 Allocation *a = static_cast<Allocation *>(va);
536 const Type * t = a->getType();
537 a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700538 t->getDimX(), t->getDimY(), data, sizeBytes, 0);
Alex Sakhartchouk39f2ef62010-10-11 12:35:15 -0700539}
540
Jason Sams4b45b892010-12-29 14:31:29 -0800541void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700542 uint32_t count, const void *data, size_t sizeBytes) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700543 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800544 a->data(rsc, xoff, lod, count, data, sizeBytes);
Jason Sams326e0dd2009-05-22 14:03:28 -0700545}
546
Jason Sams4b45b892010-12-29 14:31:29 -0800547void rsi_Allocation2DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t lod, RsAllocationCubemapFace face,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800548 const void *data, size_t sizeBytes, size_t eoff) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700549 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800550 a->elementData(rsc, x, y, data, eoff, sizeBytes);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700551}
552
Jason Sams4b45b892010-12-29 14:31:29 -0800553void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800554 const void *data, size_t sizeBytes, size_t eoff) {
Jason Sams5f0c84c2010-08-31 13:50:42 -0700555 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800556 a->elementData(rsc, x, data, eoff, sizeBytes);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700557}
558
Jason Sams4b45b892010-12-29 14:31:29 -0800559void rsi_Allocation2DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
Tim Murray358747a2012-11-26 13:52:04 -0800560 uint32_t w, uint32_t h, const void *data, size_t sizeBytes, size_t stride) {
Jason Sams5f0c84c2010-08-31 13:50:42 -0700561 Allocation *a = static_cast<Allocation *>(va);
Tim Murray358747a2012-11-26 13:52:04 -0800562 a->data(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Jason Sams326e0dd2009-05-22 14:03:28 -0700563}
564
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700565void rsi_Allocation3DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t zoff, uint32_t lod,
566 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes, size_t stride) {
567 Allocation *a = static_cast<Allocation *>(va);
568 a->data(rsc, xoff, yoff, zoff, lod, w, h, d, data, sizeBytes, stride);
569}
570
571
Jason Sams807fdc42012-07-25 17:55:39 -0700572void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) {
Jason Samse579df42009-08-10 14:55:26 -0700573 Allocation *a = static_cast<Allocation *>(va);
Jason Sams807fdc42012-07-25 17:55:39 -0700574 const Type * t = a->getType();
575 if(t->getDimY()) {
576 a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700577 t->getDimX(), t->getDimY(), data, sizeBytes, 0);
Jason Sams807fdc42012-07-25 17:55:39 -0700578 } else {
579 a->read(rsc, 0, 0, t->getDimX(), data, sizeBytes);
580 }
581
Jason Samse579df42009-08-10 14:55:26 -0700582}
583
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800584void rsi_AllocationResize1D(Context *rsc, RsAllocation va, uint32_t dimX) {
Jason Sams96abf812010-10-05 13:32:49 -0700585 Allocation *a = static_cast<Allocation *>(va);
586 a->resize1D(rsc, dimX);
587}
588
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800589void rsi_AllocationResize2D(Context *rsc, RsAllocation va, uint32_t dimX, uint32_t dimY) {
Jason Sams96abf812010-10-05 13:32:49 -0700590 Allocation *a = static_cast<Allocation *>(va);
591 a->resize2D(rsc, dimX, dimY);
592}
593
Jason Samsc975cf42011-04-28 18:26:48 -0700594RsAllocation rsi_AllocationCreateTyped(Context *rsc, RsType vtype,
595 RsAllocationMipmapControl mips,
Tim Murray099bc262013-03-20 16:54:03 -0700596 uint32_t usages, uintptr_t ptr) {
597 Allocation * alloc = Allocation::createAllocation(rsc, static_cast<Type *>(vtype), usages, mips, (void*)ptr);
Jason Samseb4fe182011-05-26 16:33:01 -0700598 if (!alloc) {
599 return NULL;
600 }
Jason Samsf0c1df42010-10-26 13:09:17 -0700601 alloc->incUserRef();
602 return alloc;
603}
604
Jason Samsc975cf42011-04-28 18:26:48 -0700605RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, RsType vtype,
606 RsAllocationMipmapControl mips,
Jason Sams807fdc42012-07-25 17:55:39 -0700607 const void *data, size_t sizeBytes, uint32_t usages) {
Jason Sams366c9c82010-12-08 16:14:36 -0800608 Type *t = static_cast<Type *>(vtype);
Jason Samsf0c1df42010-10-26 13:09:17 -0700609
Jason Sams179e9a42011-11-23 15:02:15 -0800610 RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0);
Jason Samsf0c1df42010-10-26 13:09:17 -0700611 Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
612 if (texAlloc == NULL) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000613 ALOGE("Memory allocation failure");
Jason Samsf0c1df42010-10-26 13:09:17 -0700614 return NULL;
615 }
616
Jason Sams807fdc42012-07-25 17:55:39 -0700617 texAlloc->data(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
Tim Murray60c27962013-02-07 16:15:23 -0800618 t->getDimX(), t->getDimY(), data, sizeBytes, 0);
Jason Samsebc50192010-12-13 15:32:35 -0800619 if (mips == RS_ALLOCATION_MIPMAP_FULL) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700620 rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc);
Jason Samsf0c1df42010-10-26 13:09:17 -0700621 }
622
Jason Samseb4fe182011-05-26 16:33:01 -0700623 texAlloc->sendDirty(rsc);
Jason Samsf0c1df42010-10-26 13:09:17 -0700624 return texAlloc;
625}
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800626
Jason Samsc975cf42011-04-28 18:26:48 -0700627RsAllocation rsi_AllocationCubeCreateFromBitmap(Context *rsc, RsType vtype,
628 RsAllocationMipmapControl mips,
Jason Sams807fdc42012-07-25 17:55:39 -0700629 const void *data, size_t sizeBytes, uint32_t usages) {
Jason Sams366c9c82010-12-08 16:14:36 -0800630 Type *t = static_cast<Type *>(vtype);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800631
632 // Cubemap allocation's faces should be Width by Width each.
633 // Source data should have 6 * Width by Width pixels
634 // Error checking is done in the java layer
Jason Sams179e9a42011-11-23 15:02:15 -0800635 RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800636 Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
637 if (texAlloc == NULL) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000638 ALOGE("Memory allocation failure");
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800639 return NULL;
640 }
641
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800642 uint32_t faceSize = t->getDimX();
643 uint32_t strideBytes = faceSize * 6 * t->getElementSizeBytes();
644 uint32_t copySize = faceSize * t->getElementSizeBytes();
645
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800646 uint8_t *sourcePtr = (uint8_t*)data;
Jason Sams366c9c82010-12-08 16:14:36 -0800647 for (uint32_t face = 0; face < 6; face ++) {
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800648 for (uint32_t dI = 0; dI < faceSize; dI ++) {
Jason Sams807fdc42012-07-25 17:55:39 -0700649 texAlloc->data(rsc, 0, dI, 0, (RsAllocationCubemapFace)face,
Tim Murray60c27962013-02-07 16:15:23 -0800650 t->getDimX(), 1, sourcePtr + strideBytes * dI, copySize, 0);
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800651 }
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800652
Jason Sams366c9c82010-12-08 16:14:36 -0800653 // Move the data pointer to the next cube face
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800654 sourcePtr += copySize;
Alex Sakhartchoukf8aafcf2011-01-11 14:47:44 -0800655 }
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800656
Alex Sakhartchoukf8aafcf2011-01-11 14:47:44 -0800657 if (mips == RS_ALLOCATION_MIPMAP_FULL) {
Jason Sams61a4bb72012-07-25 19:33:43 -0700658 rsc->mHal.funcs.allocation.generateMipmaps(rsc, texAlloc);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800659 }
660
Jason Samseb4fe182011-05-26 16:33:01 -0700661 texAlloc->sendDirty(rsc);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800662 return texAlloc;
663}
Alex Sakhartchouk099d7d32011-01-28 09:31:47 -0800664
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700665void rsi_AllocationCopy2DRange(Context *rsc,
666 RsAllocation dstAlloc,
667 uint32_t dstXoff, uint32_t dstYoff,
668 uint32_t dstMip, uint32_t dstFace,
669 uint32_t width, uint32_t height,
670 RsAllocation srcAlloc,
671 uint32_t srcXoff, uint32_t srcYoff,
672 uint32_t srcMip, uint32_t srcFace) {
673 Allocation *dst = static_cast<Allocation *>(dstAlloc);
674 Allocation *src= static_cast<Allocation *>(srcAlloc);
675 rsc->mHal.funcs.allocation.allocData2D(rsc, dst, dstXoff, dstYoff, dstMip,
676 (RsAllocationCubemapFace)dstFace,
677 width, height,
678 src, srcXoff, srcYoff,srcMip,
679 (RsAllocationCubemapFace)srcFace);
680}
681
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700682void rsi_AllocationCopy3DRange(Context *rsc,
683 RsAllocation dstAlloc,
684 uint32_t dstXoff, uint32_t dstYoff, uint32_t dstZoff,
685 uint32_t dstMip,
686 uint32_t width, uint32_t height, uint32_t depth,
687 RsAllocation srcAlloc,
688 uint32_t srcXoff, uint32_t srcYoff, uint32_t srcZoff,
689 uint32_t srcMip) {
690 Allocation *dst = static_cast<Allocation *>(dstAlloc);
691 Allocation *src= static_cast<Allocation *>(srcAlloc);
692 rsc->mHal.funcs.allocation.allocData3D(rsc, dst, dstXoff, dstYoff, dstZoff, dstMip,
693 width, height, depth,
694 src, srcXoff, srcYoff, srcZoff, srcMip);
695}
696
697
Jason Sams733396b2013-02-22 12:46:18 -0800698void * rsi_AllocationGetSurface(Context *rsc, RsAllocation valloc) {
Jason Sams41e373d2012-01-13 14:01:20 -0800699 Allocation *alloc = static_cast<Allocation *>(valloc);
Jason Sams733396b2013-02-22 12:46:18 -0800700 void *s = alloc->getSurface(rsc);
701 return s;
Jason Sams3522f402012-03-23 11:47:26 -0700702}
703
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800704void rsi_AllocationSetSurface(Context *rsc, RsAllocation valloc, RsNativeWindow sur) {
705 Allocation *alloc = static_cast<Allocation *>(valloc);
706 alloc->setSurface(rsc, sur);
707}
708
709void rsi_AllocationIoSend(Context *rsc, RsAllocation valloc) {
710 Allocation *alloc = static_cast<Allocation *>(valloc);
711 alloc->ioSend(rsc);
712}
713
714void rsi_AllocationIoReceive(Context *rsc, RsAllocation valloc) {
715 Allocation *alloc = static_cast<Allocation *>(valloc);
716 alloc->ioReceive(rsc);
717}
718
Tim Murray509ea5c2012-11-13 11:56:40 -0800719void rsi_Allocation1DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
720 uint32_t count, void *data, size_t sizeBytes) {
721 Allocation *a = static_cast<Allocation *>(va);
Jason Sams3bbc0fd2013-04-09 14:16:13 -0700722 rsc->mHal.funcs.allocation.read1D(rsc, a, xoff, lod, count, data, sizeBytes);
Tim Murray509ea5c2012-11-13 11:56:40 -0800723}
724
Tim Murray7b3e3092012-11-16 13:32:24 -0800725void rsi_Allocation2DRead(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff,
726 uint32_t lod, RsAllocationCubemapFace face, uint32_t w,
Tim Murray358747a2012-11-26 13:52:04 -0800727 uint32_t h, void *data, size_t sizeBytes, size_t stride) {
Tim Murray7b3e3092012-11-16 13:32:24 -0800728 Allocation *a = static_cast<Allocation *>(va);
Tim Murray358747a2012-11-26 13:52:04 -0800729 a->read(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes, stride);
Tim Murray7b3e3092012-11-16 13:32:24 -0800730}
731
Jason Samsc975cf42011-04-28 18:26:48 -0700732}
733}
734
Tim Murrayc2ce7072013-07-17 18:38:53 -0700735extern "C" const void * rsaAllocationGetType(RsContext con, RsAllocation va) {
Jason Samsc975cf42011-04-28 18:26:48 -0700736 Allocation *a = static_cast<Allocation *>(va);
737 a->getType()->incUserRef();
738
739 return a->getType();
740}