blob: a81df48eea6897b5a595c3b5f86f35087ffed8ef [file] [log] [blame]
Jason Sams326e0dd2009-05-22 14:03:28 -07001/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
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 */
16
Jason Sams326e0dd2009-05-22 14:03:28 -070017
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -070018#include "rsContext.h"
Jason Sams565ac362009-06-03 16:04:54 -070019
Jason Sams326e0dd2009-05-22 14:03:28 -070020using namespace android;
21using namespace android::renderscript;
22
Jason Sams326e0dd2009-05-22 14:03:28 -070023
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080024Element::Element(Context *rsc) : ObjectBase(rsc) {
Jason Sams4815c0d2009-12-15 12:58:36 -080025 mBits = 0;
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -080026 mBitsUnpadded = 0;
Jason Sams4815c0d2009-12-15 12:58:36 -080027 mFields = NULL;
28 mFieldCount = 0;
Jason Samse3929c92010-08-09 18:13:33 -070029 mHasReference = false;
Alex Sakhartchoukb7c8c522011-12-22 13:11:48 -080030 memset(&mHal, 0, sizeof(mHal));
Jason Sams326e0dd2009-05-22 14:03:28 -070031}
32
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080033Element::~Element() {
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070034 clear();
35}
36
37void Element::preDestroy() const {
Jason Sams81549542010-02-17 15:38:10 -080038 for (uint32_t ct = 0; ct < mRSC->mStateElement.mElements.size(); ct++) {
39 if (mRSC->mStateElement.mElements[ct] == this) {
40 mRSC->mStateElement.mElements.removeAt(ct);
41 break;
42 }
43 }
Jason Sams326e0dd2009-05-22 14:03:28 -070044}
45
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080046void Element::clear() {
Jason Sams48ecf6a2013-07-09 15:35:29 -070047 if (mFields) {
48 for (size_t i = 0; i < mFieldCount; i++) {
49 delete[] mFields[i].name;
50 }
51 delete [] mFields;
52 }
Jason Sams4815c0d2009-12-15 12:58:36 -080053 mFields = NULL;
54 mFieldCount = 0;
Jason Samse3929c92010-08-09 18:13:33 -070055 mHasReference = false;
Alex Sakhartchouk253325d2011-12-15 09:56:10 -080056
57 delete [] mHal.state.fields;
58 delete [] mHal.state.fieldArraySizes;
59 delete [] mHal.state.fieldNames;
60 delete [] mHal.state.fieldNameLengths;
61 delete [] mHal.state.fieldOffsetBytes;
Jason Sams326e0dd2009-05-22 14:03:28 -070062}
Jason Sams326e0dd2009-05-22 14:03:28 -070063
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080064size_t Element::getSizeBits() const {
Jason Sams4815c0d2009-12-15 12:58:36 -080065 if (!mFieldCount) {
66 return mBits;
67 }
68
Jason Sams326e0dd2009-05-22 14:03:28 -070069 size_t total = 0;
Jason Sams4815c0d2009-12-15 12:58:36 -080070 for (size_t ct=0; ct < mFieldCount; ct++) {
Alex Sakhartchouk39f2ef62010-10-11 12:35:15 -070071 total += mFields[ct].e->mBits * mFields[ct].arraySize;
Jason Sams326e0dd2009-05-22 14:03:28 -070072 }
73 return total;
74}
75
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -080076size_t Element::getSizeBitsUnpadded() const {
77 if (!mFieldCount) {
78 return mBitsUnpadded;
79 }
80
81 size_t total = 0;
82 for (size_t ct=0; ct < mFieldCount; ct++) {
83 total += mFields[ct].e->mBitsUnpadded * mFields[ct].arraySize;
84 }
85 return total;
86}
87
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -080088void Element::dumpLOGV(const char *prefix) const {
Jason Samse12c1c52009-09-27 17:50:38 -070089 ObjectBase::dumpLOGV(prefix);
Steve Block65982012011-10-20 11:56:00 +010090 ALOGV("%s Element: fieldCount: %zu, size bytes: %zu", prefix, mFieldCount, getSizeBytes());
Alex Sakhartchoukc700e642011-08-16 13:09:46 -070091 mComponent.dumpLOGV(prefix);
Jason Sams4815c0d2009-12-15 12:58:36 -080092 for (uint32_t ct = 0; ct < mFieldCount; ct++) {
Steve Block65982012011-10-20 11:56:00 +010093 ALOGV("%s Element field index: %u ------------------", prefix, ct);
94 ALOGV("%s name: %s, offsetBits: %u, arraySize: %u",
Jason Sams48ecf6a2013-07-09 15:35:29 -070095 prefix, mFields[ct].name, mFields[ct].offsetBits, mFields[ct].arraySize);
Alex Sakhartchouk963bb452010-10-13 14:22:02 -070096 mFields[ct].e->dumpLOGV(prefix);
Jason Samse12c1c52009-09-27 17:50:38 -070097 }
98}
99
Jason Samse3150cf2012-07-24 18:10:20 -0700100void Element::serialize(Context *rsc, OStream *stream) const {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700101 // Need to identify ourselves
102 stream->addU32((uint32_t)getClassId());
Jason Sams48ecf6a2013-07-09 15:35:29 -0700103 stream->addString(getName());
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700104
105 mComponent.serialize(stream);
106
107 // Now serialize all the fields
108 stream->addU32(mFieldCount);
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800109 for (uint32_t ct = 0; ct < mFieldCount; ct++) {
Jason Sams48ecf6a2013-07-09 15:35:29 -0700110 stream->addString(mFields[ct].name);
Jason Sams46e45542010-09-02 17:35:23 -0700111 stream->addU32(mFields[ct].arraySize);
Jason Samse3150cf2012-07-24 18:10:20 -0700112 mFields[ct].e->serialize(rsc, stream);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700113 }
114}
115
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800116Element *Element::createFromStream(Context *rsc, IStream *stream) {
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700117 // First make sure we are reading the correct object
Alex Sakhartchoukb825f672010-06-04 10:06:50 -0700118 RsA3DClassID classID = (RsA3DClassID)stream->loadU32();
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800119 if (classID != RS_A3D_CLASS_ID_ELEMENT) {
Steve Blockaf12ac62012-01-06 19:20:56 +0000120 ALOGE("element loading skipped due to invalid class id\n");
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700121 return NULL;
122 }
123
Jason Sams48ecf6a2013-07-09 15:35:29 -0700124 const char *name = stream->loadString();
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700125
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700126 Component component;
127 component.loadFromStream(stream);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700128
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700129 uint32_t fieldCount = stream->loadU32();
130 if (!fieldCount) {
131 return (Element *)Element::create(rsc,
132 component.getType(),
133 component.getKind(),
134 component.getIsNormalized(),
Jason Sams807fdc42012-07-25 17:55:39 -0700135 component.getVectorSize());
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700136 }
137
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700138 const Element **subElems = new const Element *[fieldCount];
139 const char **subElemNames = new const char *[fieldCount];
140 size_t *subElemNamesLengths = new size_t[fieldCount];
141 uint32_t *arraySizes = new uint32_t[fieldCount];
142
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700143 for (uint32_t ct = 0; ct < fieldCount; ct ++) {
Jason Sams48ecf6a2013-07-09 15:35:29 -0700144 subElemNames[ct] = stream->loadString();
145 subElemNamesLengths[ct] = strlen(subElemNames[ct]);
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700146 arraySizes[ct] = stream->loadU32();
147 subElems[ct] = Element::createFromStream(rsc, stream);
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700148 }
149
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700150 const Element *elem = Element::create(rsc, fieldCount, subElems, subElemNames,
151 subElemNamesLengths, arraySizes);
152 for (uint32_t ct = 0; ct < fieldCount; ct ++) {
153 delete [] subElemNames[ct];
154 subElems[ct]->decUserRef();
155 }
Jason Sams48ecf6a2013-07-09 15:35:29 -0700156 delete[] name;
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700157 delete[] subElems;
158 delete[] subElemNames;
159 delete[] subElemNamesLengths;
160 delete[] arraySizes;
Alex Sakhartchoukfb6b6142010-05-21 12:53:13 -0700161
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700162 return (Element *)elem;
Alex Sakhartchouk383e5b12010-09-23 16:16:33 -0700163}
Jason Samsd01d9702009-12-23 14:35:29 -0800164
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -0800165void Element::compute() {
Alex Sakhartchouk253325d2011-12-15 09:56:10 -0800166 mHal.state.dataType = mComponent.getType();
167 mHal.state.dataKind = mComponent.getKind();
168 mHal.state.vectorSize = mComponent.getVectorSize();
169
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800170 if (mFieldCount == 0) {
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -0800171 mBits = mComponent.getBits();
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800172 mBitsUnpadded = mComponent.getBitsUnpadded();
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -0800173 mHasReference = mComponent.isReference();
Alex Sakhartchouk253325d2011-12-15 09:56:10 -0800174
175 mHal.state.elementSizeBytes = getSizeBytes();
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -0800176 return;
177 }
178
Alex Sakhartchoukb7c8c522011-12-22 13:11:48 -0800179 uint32_t noPaddingFieldCount = 0;
180 for (uint32_t ct = 0; ct < mFieldCount; ct ++) {
Jason Sams48ecf6a2013-07-09 15:35:29 -0700181 if (mFields[ct].name[0] != '#') {
Alex Sakhartchoukb7c8c522011-12-22 13:11:48 -0800182 noPaddingFieldCount ++;
183 }
184 }
185
186 mHal.state.fields = new const Element*[noPaddingFieldCount];
187 mHal.state.fieldArraySizes = new uint32_t[noPaddingFieldCount];
188 mHal.state.fieldNames = new const char*[noPaddingFieldCount];
189 mHal.state.fieldNameLengths = new uint32_t[noPaddingFieldCount];
190 mHal.state.fieldOffsetBytes = new uint32_t[noPaddingFieldCount];
191 mHal.state.fieldsCount = noPaddingFieldCount;
Alex Sakhartchouk253325d2011-12-15 09:56:10 -0800192
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -0800193 size_t bits = 0;
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800194 size_t bitsUnpadded = 0;
Alex Sakhartchoukb7c8c522011-12-22 13:11:48 -0800195 for (size_t ct = 0, ctNoPadding = 0; ct < mFieldCount; ct++) {
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -0800196 mFields[ct].offsetBits = bits;
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800197 mFields[ct].offsetBitsUnpadded = bitsUnpadded;
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -0800198 bits += mFields[ct].e->getSizeBits() * mFields[ct].arraySize;
Alex Sakhartchouk2d1220c2011-11-15 15:15:21 -0800199 bitsUnpadded += mFields[ct].e->getSizeBitsUnpadded() * mFields[ct].arraySize;
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -0800200
201 if (mFields[ct].e->mHasReference) {
202 mHasReference = true;
203 }
Alex Sakhartchouk253325d2011-12-15 09:56:10 -0800204
Jason Sams48ecf6a2013-07-09 15:35:29 -0700205 if (mFields[ct].name[0] == '#') {
Alex Sakhartchoukb7c8c522011-12-22 13:11:48 -0800206 continue;
207 }
208
209 mHal.state.fields[ctNoPadding] = mFields[ct].e.get();
210 mHal.state.fieldArraySizes[ctNoPadding] = mFields[ct].arraySize;
Jason Sams48ecf6a2013-07-09 15:35:29 -0700211 mHal.state.fieldNames[ctNoPadding] = mFields[ct].name;
212 mHal.state.fieldNameLengths[ctNoPadding] = strlen(mFields[ct].name) + 1; // to include 0
Alex Sakhartchoukb7c8c522011-12-22 13:11:48 -0800213 mHal.state.fieldOffsetBytes[ctNoPadding] = mFields[ct].offsetBits >> 3;
214
215 ctNoPadding ++;
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -0800216 }
217
Alex Sakhartchouk253325d2011-12-15 09:56:10 -0800218 mHal.state.elementSizeBytes = getSizeBytes();
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -0800219}
220
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700221ObjectBaseRef<const Element> Element::createRef(Context *rsc, RsDataType dt, RsDataKind dk,
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800222 bool isNorm, uint32_t vecSize) {
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700223 ObjectBaseRef<const Element> returnRef;
Jason Sams81549542010-02-17 15:38:10 -0800224 // Look for an existing match.
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700225 ObjectBase::asyncLock();
Jason Sams81549542010-02-17 15:38:10 -0800226 for (uint32_t ct=0; ct < rsc->mStateElement.mElements.size(); ct++) {
227 const Element *ee = rsc->mStateElement.mElements[ct];
228 if (!ee->getFieldCount() &&
229 (ee->getComponent().getType() == dt) &&
230 (ee->getComponent().getKind() == dk) &&
231 (ee->getComponent().getIsNormalized() == isNorm) &&
232 (ee->getComponent().getVectorSize() == vecSize)) {
233 // Match
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700234 returnRef.set(ee);
235 ObjectBase::asyncUnlock();
Jason Sams81549542010-02-17 15:38:10 -0800236 return ee;
237 }
238 }
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700239 ObjectBase::asyncUnlock();
Jason Sams81549542010-02-17 15:38:10 -0800240
Jason Sams4815c0d2009-12-15 12:58:36 -0800241 Element *e = new Element(rsc);
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700242 returnRef.set(e);
Jason Samsd01d9702009-12-23 14:35:29 -0800243 e->mComponent.set(dt, dk, isNorm, vecSize);
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -0800244 e->compute();
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700245
246 ObjectBase::asyncLock();
Jason Sams81549542010-02-17 15:38:10 -0800247 rsc->mStateElement.mElements.push(e);
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700248 ObjectBase::asyncUnlock();
249
250 return returnRef;
Jason Sams4815c0d2009-12-15 12:58:36 -0800251}
252
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700253ObjectBaseRef<const Element> Element::createRef(Context *rsc, size_t count, const Element **ein,
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800254 const char **nin, const size_t * lengths, const uint32_t *asin) {
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700255
256 ObjectBaseRef<const Element> returnRef;
Jason Sams81549542010-02-17 15:38:10 -0800257 // Look for an existing match.
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700258 ObjectBase::asyncLock();
Jason Sams81549542010-02-17 15:38:10 -0800259 for (uint32_t ct=0; ct < rsc->mStateElement.mElements.size(); ct++) {
260 const Element *ee = rsc->mStateElement.mElements[ct];
261 if (ee->getFieldCount() == count) {
262 bool match = true;
263 for (uint32_t i=0; i < count; i++) {
Jason Samsf313dc32013-07-09 14:29:39 -0700264 size_t len;
265 uint32_t asize = 1;
266 if (lengths) {
267 len = lengths[i];
268 } else {
269 len = strlen(nin[i]);
270 }
271 if (asin) {
272 asize = asin[i];
273 }
274
Jason Sams81549542010-02-17 15:38:10 -0800275 if ((ee->mFields[i].e.get() != ein[i]) ||
Jason Sams48ecf6a2013-07-09 15:35:29 -0700276 (strlen(ee->mFields[i].name) != len) ||
277 strcmp(ee->mFields[i].name, nin[i]) ||
Jason Samsf313dc32013-07-09 14:29:39 -0700278 (ee->mFields[i].arraySize != asize)) {
Jason Sams81549542010-02-17 15:38:10 -0800279 match = false;
280 break;
281 }
282 }
283 if (match) {
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700284 returnRef.set(ee);
285 ObjectBase::asyncUnlock();
286 return returnRef;
Jason Sams81549542010-02-17 15:38:10 -0800287 }
288 }
289 }
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700290 ObjectBase::asyncUnlock();
Jason Sams81549542010-02-17 15:38:10 -0800291
Jason Sams4815c0d2009-12-15 12:58:36 -0800292 Element *e = new Element(rsc);
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700293 returnRef.set(e);
Jason Sams4815c0d2009-12-15 12:58:36 -0800294 e->mFields = new ElementField_t [count];
295 e->mFieldCount = count;
Jason Sams4815c0d2009-12-15 12:58:36 -0800296 for (size_t ct=0; ct < count; ct++) {
Jason Samsf313dc32013-07-09 14:29:39 -0700297 size_t len;
298 uint32_t asize = 1;
299 if (lengths) {
300 len = lengths[ct];
301 } else {
302 len = strlen(nin[ct]);
303 }
304 if (asin) {
305 asize = asin[ct];
306 }
307
Jason Sams4815c0d2009-12-15 12:58:36 -0800308 e->mFields[ct].e.set(ein[ct]);
Jason Sams48ecf6a2013-07-09 15:35:29 -0700309 e->mFields[ct].name = rsuCopyString(nin[ct], len);
Jason Samsf313dc32013-07-09 14:29:39 -0700310 e->mFields[ct].arraySize = asize;
Jason Sams4815c0d2009-12-15 12:58:36 -0800311 }
Alex Sakhartchouk54929cc2010-11-08 15:10:52 -0800312 e->compute();
Jason Sams4815c0d2009-12-15 12:58:36 -0800313
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700314 ObjectBase::asyncLock();
Jason Sams81549542010-02-17 15:38:10 -0800315 rsc->mStateElement.mElements.push(e);
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700316 ObjectBase::asyncUnlock();
Jason Sams4815c0d2009-12-15 12:58:36 -0800317
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700318 return returnRef;
Jason Samsb4d35682010-01-04 16:52:27 -0800319}
Jason Samsd01d9702009-12-23 14:35:29 -0800320
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800321void Element::incRefs(const void *ptr) const {
Jason Samse3929c92010-08-09 18:13:33 -0700322 if (!mFieldCount) {
323 if (mComponent.isReference()) {
324 ObjectBase *const*obp = static_cast<ObjectBase *const*>(ptr);
325 ObjectBase *ob = obp[0];
Jason Sams10e5e572010-08-12 12:44:02 -0700326 if (ob) ob->incSysRef();
Jason Samse3929c92010-08-09 18:13:33 -0700327 }
328 return;
329 }
330
331 const uint8_t *p = static_cast<const uint8_t *>(ptr);
332 for (uint32_t i=0; i < mFieldCount; i++) {
333 if (mFields[i].e->mHasReference) {
Alex Sakhartchouk49464a92011-07-12 13:25:14 -0700334 const uint8_t *p2 = &p[mFields[i].offsetBits >> 3];
Jason Sams46e45542010-09-02 17:35:23 -0700335 for (uint32_t ct=0; ct < mFields[i].arraySize; ct++) {
Alex Sakhartchouk49464a92011-07-12 13:25:14 -0700336 mFields[i].e->incRefs(p2);
337 p2 += mFields[i].e->getSizeBytes();
Jason Sams46e45542010-09-02 17:35:23 -0700338 }
Jason Samse3929c92010-08-09 18:13:33 -0700339 }
340 }
341}
342
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800343void Element::decRefs(const void *ptr) const {
Jason Samse3929c92010-08-09 18:13:33 -0700344 if (!mFieldCount) {
345 if (mComponent.isReference()) {
346 ObjectBase *const*obp = static_cast<ObjectBase *const*>(ptr);
347 ObjectBase *ob = obp[0];
Jason Sams10e5e572010-08-12 12:44:02 -0700348 if (ob) ob->decSysRef();
Jason Samse3929c92010-08-09 18:13:33 -0700349 }
350 return;
351 }
352
353 const uint8_t *p = static_cast<const uint8_t *>(ptr);
354 for (uint32_t i=0; i < mFieldCount; i++) {
355 if (mFields[i].e->mHasReference) {
Alex Sakhartchouk49464a92011-07-12 13:25:14 -0700356 const uint8_t *p2 = &p[mFields[i].offsetBits >> 3];
Jason Sams46e45542010-09-02 17:35:23 -0700357 for (uint32_t ct=0; ct < mFields[i].arraySize; ct++) {
Alex Sakhartchouk49464a92011-07-12 13:25:14 -0700358 mFields[i].e->decRefs(p2);
359 p2 += mFields[i].e->getSizeBytes();
Jason Sams46e45542010-09-02 17:35:23 -0700360 }
Jason Samse3929c92010-08-09 18:13:33 -0700361 }
362 }
363}
Jason Samsd01d9702009-12-23 14:35:29 -0800364
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800365ElementState::ElementState() {
Jason Sams326e0dd2009-05-22 14:03:28 -0700366}
367
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800368ElementState::~ElementState() {
Jason Sams81549542010-02-17 15:38:10 -0800369 rsAssert(!mElements.size());
Jason Sams326e0dd2009-05-22 14:03:28 -0700370}
371
372/////////////////////////////////////////
Jason Samse5ffb872009-08-09 17:01:55 -0700373//
Jason Sams326e0dd2009-05-22 14:03:28 -0700374
375namespace android {
376namespace renderscript {
377
Jason Samsd01d9702009-12-23 14:35:29 -0800378RsElement rsi_ElementCreate(Context *rsc,
379 RsDataType dt,
380 RsDataKind dk,
381 bool norm,
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800382 uint32_t vecSize) {
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700383 return (RsElement)Element::create(rsc, dt, dk, norm, vecSize);
Jason Sams326e0dd2009-05-22 14:03:28 -0700384}
385
Jason Sams20087472011-05-06 14:14:30 -0700386
Jason Samsd01d9702009-12-23 14:35:29 -0800387RsElement rsi_ElementCreate2(Context *rsc,
Jason Samsd01d9702009-12-23 14:35:29 -0800388 const RsElement * ein,
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700389 size_t ein_length,
Jason Sams20087472011-05-06 14:14:30 -0700390
Jason Samsd01d9702009-12-23 14:35:29 -0800391 const char ** names,
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700392 size_t nameLengths_length,
Jason Sams20087472011-05-06 14:14:30 -0700393 const size_t * nameLengths,
394
Alex Sakhartchouk70b83c12011-04-06 10:57:51 -0700395 const uint32_t * arraySizes,
396 size_t arraySizes_length) {
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700397 return (RsElement)Element::create(rsc, ein_length, (const Element **)ein,
398 names, nameLengths, arraySizes);
Jason Samsd01d9702009-12-23 14:35:29 -0800399}
400
Alex Sakhartchoukdc763f32010-10-27 14:10:07 -0700401}
402}
403
Tim Murrayc2ce7072013-07-17 18:38:53 -0700404extern "C" void rsaElementGetNativeData(RsContext con, RsElement elem,
Alex Sakhartchoukc700e642011-08-16 13:09:46 -0700405 uint32_t *elemData, uint32_t elemDataSize) {
Alex Sakhartchouk417e6a42010-07-15 11:33:03 -0700406 rsAssert(elemDataSize == 5);
407 // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements
408 Element *e = static_cast<Element *>(elem);
409
410 (*elemData++) = (uint32_t)e->getType();
411 (*elemData++) = (uint32_t)e->getKind();
412 (*elemData++) = e->getComponent().getIsNormalized() ? 1 : 0;
413 (*elemData++) = e->getComponent().getVectorSize();
414 (*elemData++) = e->getFieldCount();
Alex Sakhartchouk417e6a42010-07-15 11:33:03 -0700415}
416
Tim Murrayc2ce7072013-07-17 18:38:53 -0700417extern "C" void rsaElementGetSubElements(RsContext con, RsElement elem, uintptr_t *ids,
Tim Murray099bc262013-03-20 16:54:03 -0700418 const char **names, size_t *arraySizes, uint32_t dataSize) {
Alex Sakhartchouk417e6a42010-07-15 11:33:03 -0700419 Element *e = static_cast<Element *>(elem);
420 rsAssert(e->getFieldCount() == dataSize);
421
Alex Sakhartchoukafb743a2010-11-09 17:00:54 -0800422 for (uint32_t i = 0; i < dataSize; i ++) {
Jason Samsf0c1df42010-10-26 13:09:17 -0700423 e->getField(i)->incUserRef();
Tim Murray099bc262013-03-20 16:54:03 -0700424 ids[i] = (uintptr_t)e->getField(i);
Alex Sakhartchouk417e6a42010-07-15 11:33:03 -0700425 names[i] = e->getFieldName(i);
Alex Sakhartchouk31aca7d2011-10-18 11:08:31 -0700426 arraySizes[i] = e->getFieldArraySize(i);
Alex Sakhartchouk417e6a42010-07-15 11:33:03 -0700427 }
Alex Sakhartchouk417e6a42010-07-15 11:33:03 -0700428}