blob: ae1bd9123341607f87eaaff2b3c692cab570a4f3 [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
Stephen Hines6ae039b2012-01-18 18:46:27 -08002 * Copyright (C) 2009-2012 The Android Open Source Project
Jason Sams326e0dd2009-05-22 14:03:28 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Jason Sams326e0dd2009-05-22 14:03:28 -070016
Alex Sakhartchouk77d9f4b2011-01-31 14:53:24 -080017#include "rsContext.h"
Alex Sakhartchouk4edf0302012-03-09 10:47:27 -080018#include "rsAllocation.h"
19#include "rsAdapter.h"
Jason Samseb4fe182011-05-26 16:33:01 -070020#include "rs_hal.h"
21
Jason Sams7ac2a4d2012-02-15 12:04:24 -080022#include "system/window.h"
Jason Sams3522f402012-03-23 11:47:26 -070023#include "gui/SurfaceTexture.h"
Alex Sakhartchouk39f2ef62010-10-11 12:35:15 -070024
Jason Sams326e0dd2009-05-22 14:03:28 -070025using namespace android;
26using namespace android::renderscript;
27
Alex Sakhartchouka2aab8b2010-12-15 09:59:58 -080028Allocation::Allocation(Context *rsc, const Type *type, uint32_t usages,
Jason Sams179e9a42011-11-23 15:02:15 -080029 RsAllocationMipmapControl mc, void * ptr)
Alex Sakhartchouka2aab8b2010-12-15 09:59:58 -080030 : ObjectBase(rsc) {
Jason Samsfa84da22010-03-01 15:31:04 -080031
Jason Samseb4fe182011-05-26 16:33:01 -070032 memset(&mHal, 0, sizeof(mHal));
33 mHal.state.mipmapControl = RS_ALLOCATION_MIPMAP_NONE;
Jason Samsbad80742011-03-16 16:29:28 -070034 mHal.state.usageFlags = usages;
35 mHal.state.mipmapControl = mc;
Jason Sams366c9c82010-12-08 16:14:36 -080036
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070037 setType(type);
Jason Samsbad80742011-03-16 16:29:28 -070038 updateCache();
39}
Jason Samsfa84da22010-03-01 15:31:04 -080040
Jason Samseb4fe182011-05-26 16:33:01 -070041Allocation * Allocation::createAllocation(Context *rsc, const Type *type, uint32_t usages,
Jason Sams179e9a42011-11-23 15:02:15 -080042 RsAllocationMipmapControl mc, void * ptr) {
43 Allocation *a = new Allocation(rsc, type, usages, mc, ptr);
Jason Samseb4fe182011-05-26 16:33:01 -070044
45 if (!rsc->mHal.funcs.allocation.init(rsc, a, type->getElement()->getHasReferences())) {
46 rsc->setError(RS_ERROR_FATAL_DRIVER, "Allocation::Allocation, alloc failure");
47 delete a;
48 return NULL;
49 }
Jason Sams7ac2a4d2012-02-15 12:04:24 -080050
Jason Samseb4fe182011-05-26 16:33:01 -070051 return a;
52}
53
Jason Samsbad80742011-03-16 16:29:28 -070054void Allocation::updateCache() {
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -070055 const Type *type = mHal.state.type;
Jason Samsbad80742011-03-16 16:29:28 -070056 mHal.state.dimensionX = type->getDimX();
57 mHal.state.dimensionY = type->getDimY();
58 mHal.state.dimensionZ = type->getDimZ();
59 mHal.state.hasFaces = type->getDimFaces();
60 mHal.state.hasMipmaps = type->getDimLOD();
61 mHal.state.elementSizeBytes = type->getElementSizeBytes();
62 mHal.state.hasReferences = mHal.state.type->getElement()->getHasReferences();
Jason Sams326e0dd2009-05-22 14:03:28 -070063}
64
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080065Allocation::~Allocation() {
Jason Samsc7cec1e2011-08-18 18:01:33 -070066 freeChildrenUnlocked();
Jason Sams3522f402012-03-23 11:47:26 -070067 setSurfaceTexture(mRSC, NULL);
Jason Samseb4fe182011-05-26 16:33:01 -070068 mRSC->mHal.funcs.allocation.destroy(mRSC, this);
Jason Sams326e0dd2009-05-22 14:03:28 -070069}
70
Jason Sams366c9c82010-12-08 16:14:36 -080071void Allocation::syncAll(Context *rsc, RsAllocationUsageType src) {
Jason Samseb4fe182011-05-26 16:33:01 -070072 rsc->mHal.funcs.allocation.syncAll(rsc, this, src);
Jason Samscf4c7c92009-12-14 12:57:40 -080073}
74
Jason Sams4b45b892010-12-29 14:31:29 -080075void Allocation::data(Context *rsc, uint32_t xoff, uint32_t lod,
Stephen Hines6ae039b2012-01-18 18:46:27 -080076 uint32_t count, const void *data, size_t sizeBytes) {
77 const size_t eSize = mHal.state.type->getElementSizeBytes();
Jason Sams9397e302009-08-27 20:23:34 -070078
Jason Samseb4fe182011-05-26 16:33:01 -070079 if ((count * eSize) != sizeBytes) {
Stephen Hines6ae039b2012-01-18 18:46:27 -080080 ALOGE("Allocation::subData called with mismatched size expected %zu, got %zu",
Jason Samseb4fe182011-05-26 16:33:01 -070081 (count * eSize), sizeBytes);
Jason Samsbad80742011-03-16 16:29:28 -070082 mHal.state.type->dumpLOGV("type info");
Jason Sams9397e302009-08-27 20:23:34 -070083 return;
84 }
Jason Samse3929c92010-08-09 18:13:33 -070085
Jason Samseb4fe182011-05-26 16:33:01 -070086 rsc->mHal.funcs.allocation.data1D(rsc, this, xoff, lod, count, data, sizeBytes);
87 sendDirty(rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -070088}
89
Jason Sams4b45b892010-12-29 14:31:29 -080090void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
Stephen Hines6ae039b2012-01-18 18:46:27 -080091 uint32_t w, uint32_t h, const void *data, size_t sizeBytes) {
92 const size_t eSize = mHal.state.elementSizeBytes;
93 const size_t lineSize = eSize * w;
Jason Sams326e0dd2009-05-22 14:03:28 -070094
Steve Blockaf12ac62012-01-06 19:20:56 +000095 //ALOGE("data2d %p, %i %i %i %i %i %i %p %i", this, xoff, yoff, lod, face, w, h, data, sizeBytes);
Jason Sams9397e302009-08-27 20:23:34 -070096
Jason Samsa2371512011-01-12 13:28:37 -080097 if ((lineSize * h) != sizeBytes) {
Stephen Hines6ae039b2012-01-18 18:46:27 -080098 ALOGE("Allocation size mismatch, expected %zu, got %zu", (lineSize * h), sizeBytes);
Jason Sams9397e302009-08-27 20:23:34 -070099 rsAssert(!"Allocation::subData called with mismatched size");
100 return;
101 }
102
Jason Samseb4fe182011-05-26 16:33:01 -0700103 rsc->mHal.funcs.allocation.data2D(rsc, this, xoff, yoff, lod, face, w, h, data, sizeBytes);
104 sendDirty(rsc);
Jason Sams326e0dd2009-05-22 14:03:28 -0700105}
106
Jason Sams236385b2011-01-12 14:53:25 -0800107void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff,
108 uint32_t lod, RsAllocationCubemapFace face,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800109 uint32_t w, uint32_t h, uint32_t d, const void *data, size_t sizeBytes) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700110}
111
Jason Sams807fdc42012-07-25 17:55:39 -0700112void Allocation::read(Context *rsc, uint32_t xoff, uint32_t lod,
113 uint32_t count, void *data, size_t sizeBytes) {
114 const size_t eSize = mHal.state.type->getElementSizeBytes();
115
116 if ((count * eSize) != sizeBytes) {
117 ALOGE("Allocation::read called with mismatched size expected %zu, got %zu",
118 (count * eSize), sizeBytes);
119 mHal.state.type->dumpLOGV("type info");
120 return;
121 }
122
123 rsc->mHal.funcs.allocation.read1D(rsc, this, xoff, lod, count, data, sizeBytes);
124}
125
126void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
127 uint32_t w, uint32_t h, void *data, size_t sizeBytes) {
128 const size_t eSize = mHal.state.elementSizeBytes;
129 const size_t lineSize = eSize * w;
130
131 if ((lineSize * h) != sizeBytes) {
132 ALOGE("Allocation size mismatch, expected %zu, got %zu", (lineSize * h), sizeBytes);
133 rsAssert(!"Allocation::read called with mismatched size");
134 return;
135 }
136
137 rsc->mHal.funcs.allocation.read2D(rsc, this, xoff, yoff, lod, face, w, h, data, sizeBytes);
138}
139
140void Allocation::read(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t zoff,
141 uint32_t lod, RsAllocationCubemapFace face,
142 uint32_t w, uint32_t h, uint32_t d, void *data, size_t sizeBytes) {
143}
144
Jason Sams4b45b892010-12-29 14:31:29 -0800145void Allocation::elementData(Context *rsc, uint32_t x, const void *data,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800146 uint32_t cIdx, size_t sizeBytes) {
147 size_t eSize = mHal.state.elementSizeBytes;
Jason Sams5f0c84c2010-08-31 13:50:42 -0700148
Jason Samsbad80742011-03-16 16:29:28 -0700149 if (cIdx >= mHal.state.type->getElement()->getFieldCount()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000150 ALOGE("Error Allocation::subElementData component %i out of range.", cIdx);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700151 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range.");
152 return;
153 }
154
Jason Samsbad80742011-03-16 16:29:28 -0700155 if (x >= mHal.state.dimensionX) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000156 ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700157 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
158 return;
159 }
160
Jason Samsbad80742011-03-16 16:29:28 -0700161 const Element * e = mHal.state.type->getElement()->getField(cIdx);
Alex Sakhartchouk76946322012-02-02 09:47:26 -0800162 uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx);
163 if (sizeBytes != e->getSizeBytes() * elemArraySize) {
Stephen Hines6ae039b2012-01-18 18:46:27 -0800164 ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes());
Jason Sams5f0c84c2010-08-31 13:50:42 -0700165 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
166 return;
167 }
168
Jason Samseb4fe182011-05-26 16:33:01 -0700169 rsc->mHal.funcs.allocation.elementData1D(rsc, this, x, data, cIdx, sizeBytes);
170 sendDirty(rsc);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700171}
172
Jason Sams4b45b892010-12-29 14:31:29 -0800173void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800174 const void *data, uint32_t cIdx, size_t sizeBytes) {
175 size_t eSize = mHal.state.elementSizeBytes;
Jason Sams5f0c84c2010-08-31 13:50:42 -0700176
Jason Samsbad80742011-03-16 16:29:28 -0700177 if (x >= mHal.state.dimensionX) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000178 ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700179 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
180 return;
181 }
182
Jason Samsbad80742011-03-16 16:29:28 -0700183 if (y >= mHal.state.dimensionY) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000184 ALOGE("Error Allocation::subElementData X offset %i out of range.", x);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700185 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range.");
186 return;
187 }
188
Jason Samsbad80742011-03-16 16:29:28 -0700189 if (cIdx >= mHal.state.type->getElement()->getFieldCount()) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000190 ALOGE("Error Allocation::subElementData component %i out of range.", cIdx);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700191 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range.");
192 return;
193 }
194
Jason Samsbad80742011-03-16 16:29:28 -0700195 const Element * e = mHal.state.type->getElement()->getField(cIdx);
Alex Sakhartchouk76946322012-02-02 09:47:26 -0800196 uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx);
197 if (sizeBytes != e->getSizeBytes() * elemArraySize) {
Stephen Hines6ae039b2012-01-18 18:46:27 -0800198 ALOGE("Error Allocation::subElementData data size %zu does not match field size %zu.", sizeBytes, e->getSizeBytes());
Jason Sams5f0c84c2010-08-31 13:50:42 -0700199 rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size.");
200 return;
201 }
202
Jason Samseb4fe182011-05-26 16:33:01 -0700203 rsc->mHal.funcs.allocation.elementData2D(rsc, this, x, y, data, cIdx, sizeBytes);
204 sendDirty(rsc);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700205}
206
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800207void Allocation::addProgramToDirty(const Program *p) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700208 mToDirtyList.push(p);
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700209}
Jason Sams326e0dd2009-05-22 14:03:28 -0700210
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800211void Allocation::removeProgramToDirty(const Program *p) {
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700212 for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
213 if (mToDirtyList[ct] == p) {
214 mToDirtyList.removeAt(ct);
215 return;
216 }
217 }
218 rsAssert(0);
219}
220
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800221void Allocation::dumpLOGV(const char *prefix) const {
Jason Samsc21cf402009-11-17 17:26:46 -0800222 ObjectBase::dumpLOGV(prefix);
223
224 String8 s(prefix);
225 s.append(" type ");
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -0700226 if (mHal.state.type) {
Jason Samsbad80742011-03-16 16:29:28 -0700227 mHal.state.type->dumpLOGV(s.string());
Jason Samsc21cf402009-11-17 17:26:46 -0800228 }
229
Steve Block65982012011-10-20 11:56:00 +0100230 ALOGV("%s allocation ptr=%p mUsageFlags=0x04%x, mMipmapControl=0x%04x",
Jason Samseb4fe182011-05-26 16:33:01 -0700231 prefix, getPtr(), mHal.state.usageFlags, mHal.state.mipmapControl);
Jason Samsc21cf402009-11-17 17:26:46 -0800232}
Jason Sams326e0dd2009-05-22 14:03:28 -0700233
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800234uint32_t Allocation::getPackedSize() const {
235 uint32_t numItems = mHal.state.type->getSizeBytes() / mHal.state.type->getElementSizeBytes();
236 return numItems * mHal.state.type->getElement()->getSizeBytesUnpadded();
237}
238
Jason Samse3150cf2012-07-24 18:10:20 -0700239void Allocation::writePackedData(Context *rsc, const Type *type,
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800240 uint8_t *dst, const uint8_t *src, bool dstPadded) {
241 const Element *elem = type->getElement();
242 uint32_t unpaddedBytes = elem->getSizeBytesUnpadded();
243 uint32_t paddedBytes = elem->getSizeBytes();
244 uint32_t numItems = type->getSizeBytes() / paddedBytes;
245
246 uint32_t srcInc = !dstPadded ? paddedBytes : unpaddedBytes;
247 uint32_t dstInc = dstPadded ? paddedBytes : unpaddedBytes;
248
249 // no sub-elements
250 uint32_t fieldCount = elem->getFieldCount();
251 if (fieldCount == 0) {
252 for (uint32_t i = 0; i < numItems; i ++) {
253 memcpy(dst, src, unpaddedBytes);
254 src += srcInc;
255 dst += dstInc;
256 }
257 return;
258 }
259
260 // Cache offsets
261 uint32_t *offsetsPadded = new uint32_t[fieldCount];
262 uint32_t *offsetsUnpadded = new uint32_t[fieldCount];
263 uint32_t *sizeUnpadded = new uint32_t[fieldCount];
264
265 for (uint32_t i = 0; i < fieldCount; i++) {
266 offsetsPadded[i] = elem->getFieldOffsetBytes(i);
267 offsetsUnpadded[i] = elem->getFieldOffsetBytesUnpadded(i);
268 sizeUnpadded[i] = elem->getField(i)->getSizeBytesUnpadded();
269 }
270
271 uint32_t *srcOffsets = !dstPadded ? offsetsPadded : offsetsUnpadded;
272 uint32_t *dstOffsets = dstPadded ? offsetsPadded : offsetsUnpadded;
273
274 // complex elements, need to copy subelem after subelem
275 for (uint32_t i = 0; i < numItems; i ++) {
276 for (uint32_t fI = 0; fI < fieldCount; fI++) {
277 memcpy(dst + dstOffsets[fI], src + srcOffsets[fI], sizeUnpadded[fI]);
278 }
279 src += srcInc;
280 dst += dstInc;
281 }
282
283 delete[] offsetsPadded;
284 delete[] offsetsUnpadded;
285 delete[] sizeUnpadded;
286}
287
Jason Samse3150cf2012-07-24 18:10:20 -0700288void Allocation::unpackVec3Allocation(Context *rsc, const void *data, size_t dataSize) {
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800289 const uint8_t *src = (const uint8_t*)data;
290 uint8_t *dst = (uint8_t*)getPtr();
291
Jason Samse3150cf2012-07-24 18:10:20 -0700292 writePackedData(rsc, getType(), dst, src, true);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800293}
294
Jason Samse3150cf2012-07-24 18:10:20 -0700295void Allocation::packVec3Allocation(Context *rsc, OStream *stream) const {
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800296 uint32_t paddedBytes = getType()->getElement()->getSizeBytes();
297 uint32_t unpaddedBytes = getType()->getElement()->getSizeBytesUnpadded();
298 uint32_t numItems = mHal.state.type->getSizeBytes() / paddedBytes;
299
300 const uint8_t *src = (const uint8_t*)getPtr();
301 uint8_t *dst = new uint8_t[numItems * unpaddedBytes];
302
Jason Samse3150cf2012-07-24 18:10:20 -0700303 writePackedData(rsc, getType(), dst, src, false);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800304 stream->addByteArray(dst, getPackedSize());
305
306 delete[] dst;
307}
308
Jason Samse3150cf2012-07-24 18:10:20 -0700309void Allocation::serialize(Context *rsc, OStream *stream) const {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700310 // Need to identify ourselves
311 stream->addU32((uint32_t)getClassId());
312
313 String8 name(getName());
314 stream->addString(&name);
315
316 // First thing we need to serialize is the type object since it will be needed
317 // to initialize the class
Jason Samse3150cf2012-07-24 18:10:20 -0700318 mHal.state.type->serialize(rsc, stream);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700319
Jason Samsbad80742011-03-16 16:29:28 -0700320 uint32_t dataSize = mHal.state.type->getSizeBytes();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800321 // 3 element vectors are padded to 4 in memory, but padding isn't serialized
322 uint32_t packedSize = getPackedSize();
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700323 // Write how much data we are storing
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800324 stream->addU32(packedSize);
325 if (dataSize == packedSize) {
326 // Now write the data
327 stream->addByteArray(getPtr(), dataSize);
328 } else {
329 // Now write the data
Jason Samse3150cf2012-07-24 18:10:20 -0700330 packVec3Allocation(rsc, stream);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800331 }
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700332}
333
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800334Allocation *Allocation::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700335 // First make sure we are reading the correct object
Alex Sakhartchoukb825f672010-06-04 10:06:50 -0700336 RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800337 if (classID != RS_A3D_CLASS_ID_ALLOCATION) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000338 ALOGE("allocation loading skipped due to invalid class id\n");
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700339 return NULL;
340 }
341
342 String8 name;
343 stream->loadString(&name);
344
345 Type *type = Type::createFromStream(rsc, stream);
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800346 if (!type) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700347 return NULL;
348 }
349 type->compute();
350
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800351 Allocation *alloc = Allocation::createAllocation(rsc, type, RS_ALLOCATION_USAGE_SCRIPT);
352 type->decUserRef();
353
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700354 // Number of bytes we wrote out for this allocation
355 uint32_t dataSize = stream->loadU32();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800356 // 3 element vectors are padded to 4 in memory, but padding isn't serialized
357 uint32_t packedSize = alloc->getPackedSize();
358 if (dataSize != type->getSizeBytes() &&
359 dataSize != packedSize) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000360 ALOGE("failed to read allocation because numbytes written is not the same loaded type wants\n");
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800361 ObjectBase::checkDelete(alloc);
Jason Sams225afd32010-10-21 14:06:55 -0700362 ObjectBase::checkDelete(type);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700363 return NULL;
364 }
365
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700366 alloc->setName(name.string(), name.size());
367
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800368 if (dataSize == type->getSizeBytes()) {
369 uint32_t count = dataSize / type->getElementSizeBytes();
370 // Read in all of our allocation data
371 alloc->data(rsc, 0, 0, count, stream->getPtr() + stream->getPos(), dataSize);
372 } else {
Jason Samse3150cf2012-07-24 18:10:20 -0700373 alloc->unpackVec3Allocation(rsc, stream->getPtr() + stream->getPos(), dataSize);
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800374 }
Alex Sakhartchouke6d9fbc2010-08-11 10:30:44 -0700375 stream->reset(stream->getPos() + dataSize);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700376
377 return alloc;
378}
379
Jason Samseb4fe182011-05-26 16:33:01 -0700380void Allocation::sendDirty(const Context *rsc) const {
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700381 for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
382 mToDirtyList[ct]->forceDirty();
383 }
Jason Samseb4fe182011-05-26 16:33:01 -0700384 mRSC->mHal.funcs.allocation.markDirty(rsc, this);
Jason Sams5c3e3bc2009-10-26 15:19:28 -0700385}
Jason Sams326e0dd2009-05-22 14:03:28 -0700386
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800387void Allocation::incRefs(const void *ptr, size_t ct, size_t startOff) const {
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700388 mHal.state.type->incRefs(ptr, ct, startOff);
Jason Samse3929c92010-08-09 18:13:33 -0700389}
390
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800391void Allocation::decRefs(const void *ptr, size_t ct, size_t startOff) const {
Alex Sakhartchouk5c4369a2011-08-12 11:30:30 -0700392 if (!mHal.state.hasReferences || !getIsScript()) {
393 return;
394 }
Stephen Hines9f70a4e2012-04-02 20:18:48 -0700395 mHal.state.type->decRefs(ptr, ct, startOff);
Jason Samse3929c92010-08-09 18:13:33 -0700396}
397
Jason Samsc7cec1e2011-08-18 18:01:33 -0700398void Allocation::freeChildrenUnlocked () {
399 decRefs(getPtr(), mHal.state.type->getSizeBytes() / mHal.state.type->getElementSizeBytes(), 0);
400}
401
402bool Allocation::freeChildren() {
403 if (mHal.state.hasReferences) {
404 incSysRef();
405 freeChildrenUnlocked();
406 return decSysRef();
407 }
408 return false;
409}
410
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800411void Allocation::copyRange1D(Context *rsc, const Allocation *src, int32_t srcOff, int32_t destOff, int32_t len) {
Jason Sams96abf812010-10-05 13:32:49 -0700412}
413
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800414void Allocation::resize1D(Context *rsc, uint32_t dimX) {
Jason Samsbad80742011-03-16 16:29:28 -0700415 uint32_t oldDimX = mHal.state.dimensionX;
Jason Sams96abf812010-10-05 13:32:49 -0700416 if (dimX == oldDimX) {
417 return;
418 }
419
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700420 ObjectBaseRef<Type> t = mHal.state.type->cloneAndResize1D(rsc, dimX);
Jason Sams96abf812010-10-05 13:32:49 -0700421 if (dimX < oldDimX) {
Jason Samseb4fe182011-05-26 16:33:01 -0700422 decRefs(getPtr(), oldDimX - dimX, dimX);
Jason Sams96abf812010-10-05 13:32:49 -0700423 }
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700424 rsc->mHal.funcs.allocation.resize(rsc, this, t.get(), mHal.state.hasReferences);
Alex Sakhartchouk064aa7e2011-10-18 10:54:29 -0700425 setType(t.get());
Jason Samsbad80742011-03-16 16:29:28 -0700426 updateCache();
Jason Sams96abf812010-10-05 13:32:49 -0700427}
428
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800429void Allocation::resize2D(Context *rsc, uint32_t dimX, uint32_t dimY) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000430 ALOGE("not implemented");
Jason Sams96abf812010-10-05 13:32:49 -0700431}
432
Jason Sams41e373d2012-01-13 14:01:20 -0800433int32_t Allocation::getSurfaceTextureID(const Context *rsc) {
434 int32_t id = rsc->mHal.funcs.allocation.initSurfaceTexture(rsc, this);
435 mHal.state.surfaceTextureID = id;
436 return id;
437}
438
Jason Sams3522f402012-03-23 11:47:26 -0700439void Allocation::setSurfaceTexture(const Context *rsc, SurfaceTexture *st) {
440 if(st != mHal.state.surfaceTexture) {
441 if(mHal.state.surfaceTexture != NULL) {
442 mHal.state.surfaceTexture->decStrong(NULL);
443 }
444 mHal.state.surfaceTexture = st;
445 if(mHal.state.surfaceTexture != NULL) {
446 mHal.state.surfaceTexture->incStrong(NULL);
447 }
448 }
449}
450
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800451void Allocation::setSurface(const Context *rsc, RsNativeWindow sur) {
452 ANativeWindow *nw = (ANativeWindow *)sur;
453 ANativeWindow *old = mHal.state.wndSurface;
454 if (nw) {
455 nw->incStrong(NULL);
456 }
457 rsc->mHal.funcs.allocation.setSurfaceTexture(rsc, this, nw);
458 mHal.state.wndSurface = nw;
459 if (old) {
460 old->decStrong(NULL);
461 }
462}
463
464void Allocation::ioSend(const Context *rsc) {
465 rsc->mHal.funcs.allocation.ioSend(rsc, this);
466}
467
468void Allocation::ioReceive(const Context *rsc) {
469 rsc->mHal.funcs.allocation.ioReceive(rsc, this);
470}
471
472
Jason Sams326e0dd2009-05-22 14:03:28 -0700473/////////////////
Jason Sams565ac362009-06-03 16:04:54 -0700474//
Stephen Hines6a121812011-03-01 17:34:59 -0800475
Jason Sams326e0dd2009-05-22 14:03:28 -0700476namespace android {
477namespace renderscript {
478
Jason Samsc975cf42011-04-28 18:26:48 -0700479static void AllocationGenerateScriptMips(RsContext con, RsAllocation va);
480
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800481static void mip565(const Adapter2D &out, const Adapter2D &in) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700482 uint32_t w = out.getDimX();
483 uint32_t h = out.getDimY();
484
Jason Samse9f5c532009-07-28 17:20:11 -0700485 for (uint32_t y=0; y < h; y++) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700486 uint16_t *oPtr = static_cast<uint16_t *>(out.getElement(0, y));
487 const uint16_t *i1 = static_cast<uint16_t *>(in.getElement(0, y*2));
488 const uint16_t *i2 = static_cast<uint16_t *>(in.getElement(0, y*2+1));
489
Jason Samse9f5c532009-07-28 17:20:11 -0700490 for (uint32_t x=0; x < w; x++) {
Jason Sams565ac362009-06-03 16:04:54 -0700491 *oPtr = rsBoxFilter565(i1[0], i1[1], i2[0], i2[1]);
492 oPtr ++;
493 i1 += 2;
494 i2 += 2;
495 }
496 }
497}
498
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800499static void mip8888(const Adapter2D &out, const Adapter2D &in) {
Jason Sams565ac362009-06-03 16:04:54 -0700500 uint32_t w = out.getDimX();
501 uint32_t h = out.getDimY();
502
Jason Samse9f5c532009-07-28 17:20:11 -0700503 for (uint32_t y=0; y < h; y++) {
Jason Sams565ac362009-06-03 16:04:54 -0700504 uint32_t *oPtr = static_cast<uint32_t *>(out.getElement(0, y));
505 const uint32_t *i1 = static_cast<uint32_t *>(in.getElement(0, y*2));
506 const uint32_t *i2 = static_cast<uint32_t *>(in.getElement(0, y*2+1));
507
Jason Samse9f5c532009-07-28 17:20:11 -0700508 for (uint32_t x=0; x < w; x++) {
Jason Sams565ac362009-06-03 16:04:54 -0700509 *oPtr = rsBoxFilter8888(i1[0], i1[1], i2[0], i2[1]);
Jason Sams326e0dd2009-05-22 14:03:28 -0700510 oPtr ++;
511 i1 += 2;
512 i2 += 2;
513 }
514 }
Jason Sams326e0dd2009-05-22 14:03:28 -0700515}
516
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800517static void mip8(const Adapter2D &out, const Adapter2D &in) {
Jason Sams2f6d8612010-01-19 17:53:54 -0800518 uint32_t w = out.getDimX();
519 uint32_t h = out.getDimY();
520
521 for (uint32_t y=0; y < h; y++) {
522 uint8_t *oPtr = static_cast<uint8_t *>(out.getElement(0, y));
523 const uint8_t *i1 = static_cast<uint8_t *>(in.getElement(0, y*2));
524 const uint8_t *i2 = static_cast<uint8_t *>(in.getElement(0, y*2+1));
525
526 for (uint32_t x=0; x < w; x++) {
527 *oPtr = (uint8_t)(((uint32_t)i1[0] + i1[1] + i2[0] + i2[1]) * 0.25f);
528 oPtr ++;
529 i1 += 2;
530 i2 += 2;
531 }
532 }
533}
534
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800535static void mip(const Adapter2D &out, const Adapter2D &in) {
536 switch (out.getBaseType()->getElement()->getSizeBits()) {
Jason Samse9f5c532009-07-28 17:20:11 -0700537 case 32:
538 mip8888(out, in);
539 break;
540 case 16:
541 mip565(out, in);
542 break;
Jason Sams2f6d8612010-01-19 17:53:54 -0800543 case 8:
544 mip8(out, in);
545 break;
Jason Samse9f5c532009-07-28 17:20:11 -0700546 }
Jason Samse9f5c532009-07-28 17:20:11 -0700547}
Jason Sams326e0dd2009-05-22 14:03:28 -0700548
Jason Sams366c9c82010-12-08 16:14:36 -0800549void rsi_AllocationSyncAll(Context *rsc, RsAllocation va, RsAllocationUsageType src) {
550 Allocation *a = static_cast<Allocation *>(va);
Jason Samseb4fe182011-05-26 16:33:01 -0700551 a->sendDirty(rsc);
Jason Sams366c9c82010-12-08 16:14:36 -0800552 a->syncAll(rsc, src);
553}
554
Jason Samsa2371512011-01-12 13:28:37 -0800555void rsi_AllocationGenerateMipmaps(Context *rsc, RsAllocation va) {
Alex Sakhartchouk39f2ef62010-10-11 12:35:15 -0700556 Allocation *texAlloc = static_cast<Allocation *>(va);
Jason Samsc975cf42011-04-28 18:26:48 -0700557 AllocationGenerateScriptMips(rsc, texAlloc);
Jason Sams837e3882010-12-10 16:03:15 -0800558}
559
Jason Sams807fdc42012-07-25 17:55:39 -0700560void rsi_AllocationCopyToBitmap(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) {
561 Allocation *a = static_cast<Allocation *>(va);
562 const Type * t = a->getType();
563 a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
564 t->getDimX(), t->getDimY(), data, sizeBytes);
Alex Sakhartchouk39f2ef62010-10-11 12:35:15 -0700565}
566
Jason Sams4b45b892010-12-29 14:31:29 -0800567void rsi_Allocation1DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t lod,
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700568 uint32_t count, const void *data, size_t sizeBytes) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700569 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800570 a->data(rsc, xoff, lod, count, data, sizeBytes);
Jason Sams326e0dd2009-05-22 14:03:28 -0700571}
572
Jason Sams4b45b892010-12-29 14:31:29 -0800573void rsi_Allocation2DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t y, uint32_t lod, RsAllocationCubemapFace face,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800574 const void *data, size_t sizeBytes, size_t eoff) {
Jason Sams326e0dd2009-05-22 14:03:28 -0700575 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800576 a->elementData(rsc, x, y, data, eoff, sizeBytes);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700577}
578
Jason Sams4b45b892010-12-29 14:31:29 -0800579void rsi_Allocation1DElementData(Context *rsc, RsAllocation va, uint32_t x, uint32_t lod,
Stephen Hines6ae039b2012-01-18 18:46:27 -0800580 const void *data, size_t sizeBytes, size_t eoff) {
Jason Sams5f0c84c2010-08-31 13:50:42 -0700581 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800582 a->elementData(rsc, x, data, eoff, sizeBytes);
Jason Sams5f0c84c2010-08-31 13:50:42 -0700583}
584
Jason Sams4b45b892010-12-29 14:31:29 -0800585void rsi_Allocation2DData(Context *rsc, RsAllocation va, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
Alex Sakhartchoukb81a0eb2011-06-03 10:18:01 -0700586 uint32_t w, uint32_t h, const void *data, size_t sizeBytes) {
Jason Sams5f0c84c2010-08-31 13:50:42 -0700587 Allocation *a = static_cast<Allocation *>(va);
Jason Sams4b45b892010-12-29 14:31:29 -0800588 a->data(rsc, xoff, yoff, lod, face, w, h, data, sizeBytes);
Jason Sams326e0dd2009-05-22 14:03:28 -0700589}
590
Jason Sams807fdc42012-07-25 17:55:39 -0700591void rsi_AllocationRead(Context *rsc, RsAllocation va, void *data, size_t sizeBytes) {
Jason Samse579df42009-08-10 14:55:26 -0700592 Allocation *a = static_cast<Allocation *>(va);
Jason Sams807fdc42012-07-25 17:55:39 -0700593 const Type * t = a->getType();
594 if(t->getDimY()) {
595 a->read(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
596 t->getDimX(), t->getDimY(), data, sizeBytes);
597 } else {
598 a->read(rsc, 0, 0, t->getDimX(), data, sizeBytes);
599 }
600
Jason Samse579df42009-08-10 14:55:26 -0700601}
602
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800603void rsi_AllocationResize1D(Context *rsc, RsAllocation va, uint32_t dimX) {
Jason Sams96abf812010-10-05 13:32:49 -0700604 Allocation *a = static_cast<Allocation *>(va);
605 a->resize1D(rsc, dimX);
606}
607
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800608void rsi_AllocationResize2D(Context *rsc, RsAllocation va, uint32_t dimX, uint32_t dimY) {
Jason Sams96abf812010-10-05 13:32:49 -0700609 Allocation *a = static_cast<Allocation *>(va);
610 a->resize2D(rsc, dimX, dimY);
611}
612
Jason Samsc975cf42011-04-28 18:26:48 -0700613static void AllocationGenerateScriptMips(RsContext con, RsAllocation va) {
Alex Sakhartchoukf8aafcf2011-01-11 14:47:44 -0800614 Context *rsc = static_cast<Context *>(con);
615 Allocation *texAlloc = static_cast<Allocation *>(va);
616 uint32_t numFaces = texAlloc->getType()->getDimFaces() ? 6 : 1;
617 for (uint32_t face = 0; face < numFaces; face ++) {
618 Adapter2D adapt(rsc, texAlloc);
619 Adapter2D adapt2(rsc, texAlloc);
620 adapt.setFace(face);
621 adapt2.setFace(face);
622 for (uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) {
623 adapt.setLOD(lod);
624 adapt2.setLOD(lod + 1);
625 mip(adapt2, adapt);
626 }
627 }
628}
629
Jason Samsc975cf42011-04-28 18:26:48 -0700630RsAllocation rsi_AllocationCreateTyped(Context *rsc, RsType vtype,
631 RsAllocationMipmapControl mips,
Jason Sams179e9a42011-11-23 15:02:15 -0800632 uint32_t usages, uint32_t ptr) {
633 Allocation * alloc = Allocation::createAllocation(rsc, static_cast<Type *>(vtype), usages, mips, (void *)ptr);
Jason Samseb4fe182011-05-26 16:33:01 -0700634 if (!alloc) {
635 return NULL;
636 }
Jason Samsf0c1df42010-10-26 13:09:17 -0700637 alloc->incUserRef();
638 return alloc;
639}
640
Jason Samsc975cf42011-04-28 18:26:48 -0700641RsAllocation rsi_AllocationCreateFromBitmap(Context *rsc, RsType vtype,
642 RsAllocationMipmapControl mips,
Jason Sams807fdc42012-07-25 17:55:39 -0700643 const void *data, size_t sizeBytes, uint32_t usages) {
Jason Sams366c9c82010-12-08 16:14:36 -0800644 Type *t = static_cast<Type *>(vtype);
Jason Samsf0c1df42010-10-26 13:09:17 -0700645
Jason Sams179e9a42011-11-23 15:02:15 -0800646 RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0);
Jason Samsf0c1df42010-10-26 13:09:17 -0700647 Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
648 if (texAlloc == NULL) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000649 ALOGE("Memory allocation failure");
Jason Samsf0c1df42010-10-26 13:09:17 -0700650 return NULL;
651 }
652
Jason Sams807fdc42012-07-25 17:55:39 -0700653 texAlloc->data(rsc, 0, 0, 0, RS_ALLOCATION_CUBEMAP_FACE_POSITIVE_X,
654 t->getDimX(), t->getDimY(), data, sizeBytes);
Jason Samsebc50192010-12-13 15:32:35 -0800655 if (mips == RS_ALLOCATION_MIPMAP_FULL) {
Jason Samsc975cf42011-04-28 18:26:48 -0700656 AllocationGenerateScriptMips(rsc, texAlloc);
Jason Samsf0c1df42010-10-26 13:09:17 -0700657 }
658
Jason Samseb4fe182011-05-26 16:33:01 -0700659 texAlloc->sendDirty(rsc);
Jason Samsf0c1df42010-10-26 13:09:17 -0700660 return texAlloc;
661}
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800662
Jason Samsc975cf42011-04-28 18:26:48 -0700663RsAllocation rsi_AllocationCubeCreateFromBitmap(Context *rsc, RsType vtype,
664 RsAllocationMipmapControl mips,
Jason Sams807fdc42012-07-25 17:55:39 -0700665 const void *data, size_t sizeBytes, uint32_t usages) {
Jason Sams366c9c82010-12-08 16:14:36 -0800666 Type *t = static_cast<Type *>(vtype);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800667
668 // Cubemap allocation's faces should be Width by Width each.
669 // Source data should have 6 * Width by Width pixels
670 // Error checking is done in the java layer
Jason Sams179e9a42011-11-23 15:02:15 -0800671 RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, vtype, mips, usages, 0);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800672 Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
673 if (texAlloc == NULL) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000674 ALOGE("Memory allocation failure");
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800675 return NULL;
676 }
677
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800678 uint32_t faceSize = t->getDimX();
679 uint32_t strideBytes = faceSize * 6 * t->getElementSizeBytes();
680 uint32_t copySize = faceSize * t->getElementSizeBytes();
681
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800682 uint8_t *sourcePtr = (uint8_t*)data;
Jason Sams366c9c82010-12-08 16:14:36 -0800683 for (uint32_t face = 0; face < 6; face ++) {
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800684 for (uint32_t dI = 0; dI < faceSize; dI ++) {
Jason Sams807fdc42012-07-25 17:55:39 -0700685 texAlloc->data(rsc, 0, dI, 0, (RsAllocationCubemapFace)face,
686 t->getDimX(), 1, sourcePtr + strideBytes * dI, copySize);
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800687 }
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800688
Jason Sams366c9c82010-12-08 16:14:36 -0800689 // Move the data pointer to the next cube face
Alex Sakhartchouk9f8bc4f2011-01-10 15:57:57 -0800690 sourcePtr += copySize;
Alex Sakhartchoukf8aafcf2011-01-11 14:47:44 -0800691 }
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800692
Alex Sakhartchoukf8aafcf2011-01-11 14:47:44 -0800693 if (mips == RS_ALLOCATION_MIPMAP_FULL) {
Jason Samsc975cf42011-04-28 18:26:48 -0700694 AllocationGenerateScriptMips(rsc, texAlloc);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800695 }
696
Jason Samseb4fe182011-05-26 16:33:01 -0700697 texAlloc->sendDirty(rsc);
Alex Sakhartchouk84e40272010-11-18 15:22:43 -0800698 return texAlloc;
699}
Alex Sakhartchouk099d7d32011-01-28 09:31:47 -0800700
Alex Sakhartchouk74a82792011-06-14 11:13:19 -0700701void rsi_AllocationCopy2DRange(Context *rsc,
702 RsAllocation dstAlloc,
703 uint32_t dstXoff, uint32_t dstYoff,
704 uint32_t dstMip, uint32_t dstFace,
705 uint32_t width, uint32_t height,
706 RsAllocation srcAlloc,
707 uint32_t srcXoff, uint32_t srcYoff,
708 uint32_t srcMip, uint32_t srcFace) {
709 Allocation *dst = static_cast<Allocation *>(dstAlloc);
710 Allocation *src= static_cast<Allocation *>(srcAlloc);
711 rsc->mHal.funcs.allocation.allocData2D(rsc, dst, dstXoff, dstYoff, dstMip,
712 (RsAllocationCubemapFace)dstFace,
713 width, height,
714 src, srcXoff, srcYoff,srcMip,
715 (RsAllocationCubemapFace)srcFace);
716}
717
Jason Sams41e373d2012-01-13 14:01:20 -0800718int32_t rsi_AllocationGetSurfaceTextureID(Context *rsc, RsAllocation valloc) {
719 Allocation *alloc = static_cast<Allocation *>(valloc);
720 return alloc->getSurfaceTextureID(rsc);
721}
722
Jason Sams3522f402012-03-23 11:47:26 -0700723void rsi_AllocationGetSurfaceTextureID2(Context *rsc, RsAllocation valloc, void *vst, size_t len) {
724 Allocation *alloc = static_cast<Allocation *>(valloc);
725 alloc->setSurfaceTexture(rsc, static_cast<SurfaceTexture *>(vst));
726}
727
Jason Sams7ac2a4d2012-02-15 12:04:24 -0800728void rsi_AllocationSetSurface(Context *rsc, RsAllocation valloc, RsNativeWindow sur) {
729 Allocation *alloc = static_cast<Allocation *>(valloc);
730 alloc->setSurface(rsc, sur);
731}
732
733void rsi_AllocationIoSend(Context *rsc, RsAllocation valloc) {
734 Allocation *alloc = static_cast<Allocation *>(valloc);
735 alloc->ioSend(rsc);
736}
737
738void rsi_AllocationIoReceive(Context *rsc, RsAllocation valloc) {
739 Allocation *alloc = static_cast<Allocation *>(valloc);
740 alloc->ioReceive(rsc);
741}
742
Jason Samsc975cf42011-04-28 18:26:48 -0700743}
744}
745
746const void * rsaAllocationGetType(RsContext con, RsAllocation va) {
747 Allocation *a = static_cast<Allocation *>(va);
748 a->getType()->incUserRef();
749
750 return a->getType();
751}