Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 1 | /* |
| 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 Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 17 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 18 | #ifndef ANDROID_RS_BUILD_FOR_HOST |
| 19 | #include "rsContext.h" |
Jason Sams | e2ae85f | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 20 | #include <GLES/gl.h> |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 21 | #else |
| 22 | #include "rsContextHostStub.h" |
| 23 | #include <OpenGL/gl.h> |
| 24 | #endif |
Jason Sams | e2ae85f | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 25 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 26 | using namespace android; |
| 27 | using namespace android::renderscript; |
| 28 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 29 | |
Jason Sams | a9e7a05 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 30 | Element::Element(Context *rsc) : ObjectBase(rsc) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 31 | { |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 32 | mBits = 0; |
Jason Sams | 61f08d6 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 33 | mAllocFile = __FILE__; |
| 34 | mAllocLine = __LINE__; |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 35 | mFields = NULL; |
| 36 | mFieldCount = 0; |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 37 | mHasReference = false; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 40 | |
| 41 | Element::~Element() |
| 42 | { |
Jason Sams | e4c487a | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 43 | for (uint32_t ct = 0; ct < mRSC->mStateElement.mElements.size(); ct++) { |
| 44 | if (mRSC->mStateElement.mElements[ct] == this) { |
| 45 | mRSC->mStateElement.mElements.removeAt(ct); |
| 46 | break; |
| 47 | } |
| 48 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 49 | clear(); |
| 50 | } |
| 51 | |
| 52 | void Element::clear() |
| 53 | { |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 54 | delete [] mFields; |
| 55 | mFields = NULL; |
| 56 | mFieldCount = 0; |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 57 | mHasReference = false; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 58 | } |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 59 | |
| 60 | size_t Element::getSizeBits() const |
| 61 | { |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 62 | if (!mFieldCount) { |
| 63 | return mBits; |
| 64 | } |
| 65 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 66 | size_t total = 0; |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 67 | for (size_t ct=0; ct < mFieldCount; ct++) { |
Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame^] | 68 | total += mFields[ct].e->mBits * mFields[ct].arraySize;; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 69 | } |
| 70 | return total; |
| 71 | } |
| 72 | |
Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 73 | void Element::dumpLOGV(const char *prefix) const |
| 74 | { |
| 75 | ObjectBase::dumpLOGV(prefix); |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 76 | LOGV("%s Element: components %i, size %i", prefix, mFieldCount, mBits); |
| 77 | for (uint32_t ct = 0; ct < mFieldCount; ct++) { |
Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 78 | char buf[1024]; |
| 79 | sprintf(buf, "%s component %i: ", prefix, ct); |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 80 | //mComponents[ct]->dumpLOGV(buf); |
Jason Sams | 3c0dfba | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 81 | } |
| 82 | } |
| 83 | |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 84 | void Element::serialize(OStream *stream) const |
| 85 | { |
| 86 | // Need to identify ourselves |
| 87 | stream->addU32((uint32_t)getClassId()); |
| 88 | |
| 89 | String8 name(getName()); |
| 90 | stream->addString(&name); |
| 91 | |
| 92 | mComponent.serialize(stream); |
| 93 | |
| 94 | // Now serialize all the fields |
| 95 | stream->addU32(mFieldCount); |
| 96 | for(uint32_t ct = 0; ct < mFieldCount; ct++) { |
| 97 | stream->addString(&mFields[ct].name); |
Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame^] | 98 | stream->addU32(mFields[ct].arraySize); |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 99 | mFields[ct].e->serialize(stream); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | Element *Element::createFromStream(Context *rsc, IStream *stream) |
| 104 | { |
| 105 | // First make sure we are reading the correct object |
Alex Sakhartchouk | aae74ad | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 106 | RsA3DClassID classID = (RsA3DClassID)stream->loadU32(); |
| 107 | if(classID != RS_A3D_CLASS_ID_ELEMENT) { |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 108 | LOGE("element loading skipped due to invalid class id\n"); |
| 109 | return NULL; |
| 110 | } |
| 111 | |
| 112 | String8 name; |
| 113 | stream->loadString(&name); |
| 114 | |
| 115 | Element *elem = new Element(rsc); |
| 116 | elem->mComponent.loadFromStream(stream); |
| 117 | elem->mBits = elem->mComponent.getBits(); |
Alex Sakhartchouk | 2ce0e3f | 2010-08-11 10:30:44 -0700 | [diff] [blame] | 118 | elem->mHasReference = elem->mComponent.isReference(); |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 119 | |
| 120 | elem->mFieldCount = stream->loadU32(); |
| 121 | if(elem->mFieldCount) { |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 122 | uint32_t offset = 0; |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 123 | elem->mFields = new ElementField_t [elem->mFieldCount]; |
| 124 | for(uint32_t ct = 0; ct < elem->mFieldCount; ct ++) { |
| 125 | stream->loadString(&elem->mFields[ct].name); |
Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame^] | 126 | elem->mFields[ct].arraySize = stream->loadU32(); |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 127 | Element *fieldElem = Element::createFromStream(rsc, stream); |
| 128 | elem->mFields[ct].e.set(fieldElem); |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 129 | elem->mFields[ct].offsetBits = offset; |
| 130 | offset += fieldElem->getSizeBits(); |
Alex Sakhartchouk | 2ce0e3f | 2010-08-11 10:30:44 -0700 | [diff] [blame] | 131 | // Check if our sub-elements have references |
| 132 | if(fieldElem->mHasReference) { |
| 133 | elem->mHasReference = true; |
| 134 | } |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
| 138 | // We need to check if this already exists |
| 139 | for (uint32_t ct=0; ct < rsc->mStateElement.mElements.size(); ct++) { |
| 140 | Element *ee = rsc->mStateElement.mElements[ct]; |
| 141 | |
| 142 | if (!ee->getFieldCount() ) { |
| 143 | |
| 144 | if((ee->getComponent().getType() == elem->getComponent().getType()) && |
| 145 | (ee->getComponent().getKind() == elem->getComponent().getKind()) && |
| 146 | (ee->getComponent().getIsNormalized() == elem->getComponent().getIsNormalized()) && |
| 147 | (ee->getComponent().getVectorSize() == elem->getComponent().getVectorSize())) { |
| 148 | // Match |
| 149 | delete elem; |
| 150 | ee->incUserRef(); |
| 151 | return ee; |
| 152 | } |
| 153 | |
| 154 | } else if (ee->getFieldCount() == elem->mFieldCount) { |
| 155 | |
| 156 | bool match = true; |
| 157 | for (uint32_t i=0; i < elem->mFieldCount; i++) { |
| 158 | if ((ee->mFields[i].e.get() != elem->mFields[i].e.get()) || |
| 159 | (ee->mFields[i].name.length() != elem->mFields[i].name.length()) || |
Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame^] | 160 | (ee->mFields[i].name != elem->mFields[i].name) || |
| 161 | (ee->mFields[i].arraySize != elem->mFields[i].arraySize)) { |
Alex Sakhartchouk | aa7d288 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 162 | match = false; |
| 163 | break; |
| 164 | } |
| 165 | } |
| 166 | if (match) { |
| 167 | delete elem; |
| 168 | ee->incUserRef(); |
| 169 | return ee; |
| 170 | } |
| 171 | |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | rsc->mStateElement.mElements.push(elem); |
| 176 | return elem; |
| 177 | } |
| 178 | |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 179 | |
Jason Sams | e4c487a | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 180 | const Element * Element::create(Context *rsc, RsDataType dt, RsDataKind dk, |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 181 | bool isNorm, uint32_t vecSize) |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 182 | { |
Jason Sams | e4c487a | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 183 | // Look for an existing match. |
| 184 | for (uint32_t ct=0; ct < rsc->mStateElement.mElements.size(); ct++) { |
| 185 | const Element *ee = rsc->mStateElement.mElements[ct]; |
| 186 | if (!ee->getFieldCount() && |
| 187 | (ee->getComponent().getType() == dt) && |
| 188 | (ee->getComponent().getKind() == dk) && |
| 189 | (ee->getComponent().getIsNormalized() == isNorm) && |
| 190 | (ee->getComponent().getVectorSize() == vecSize)) { |
| 191 | // Match |
| 192 | ee->incUserRef(); |
| 193 | return ee; |
| 194 | } |
| 195 | } |
| 196 | |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 197 | Element *e = new Element(rsc); |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 198 | e->mComponent.set(dt, dk, isNorm, vecSize); |
| 199 | e->mBits = e->mComponent.getBits(); |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 200 | e->mHasReference = e->mComponent.isReference(); |
Jason Sams | e4c487a | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 201 | rsc->mStateElement.mElements.push(e); |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 202 | return e; |
| 203 | } |
| 204 | |
Jason Sams | e4c487a | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 205 | const Element * Element::create(Context *rsc, size_t count, const Element **ein, |
Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame^] | 206 | const char **nin, const size_t * lengths, const uint32_t *asin) |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 207 | { |
Jason Sams | e4c487a | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 208 | // Look for an existing match. |
| 209 | for (uint32_t ct=0; ct < rsc->mStateElement.mElements.size(); ct++) { |
| 210 | const Element *ee = rsc->mStateElement.mElements[ct]; |
| 211 | if (ee->getFieldCount() == count) { |
| 212 | bool match = true; |
| 213 | for (uint32_t i=0; i < count; i++) { |
| 214 | if ((ee->mFields[i].e.get() != ein[i]) || |
| 215 | (ee->mFields[i].name.length() != lengths[i]) || |
Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame^] | 216 | (ee->mFields[i].name != nin[i]) || |
| 217 | (ee->mFields[i].arraySize != asin[i])) { |
Jason Sams | e4c487a | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 218 | match = false; |
| 219 | break; |
| 220 | } |
| 221 | } |
| 222 | if (match) { |
| 223 | ee->incUserRef(); |
| 224 | return ee; |
| 225 | } |
| 226 | } |
| 227 | } |
| 228 | |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 229 | Element *e = new Element(rsc); |
| 230 | e->mFields = new ElementField_t [count]; |
| 231 | e->mFieldCount = count; |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 232 | size_t bits = 0; |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 233 | for (size_t ct=0; ct < count; ct++) { |
| 234 | e->mFields[ct].e.set(ein[ct]); |
| 235 | e->mFields[ct].name.setTo(nin[ct], lengths[ct]); |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 236 | e->mFields[ct].offsetBits = bits; |
Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame^] | 237 | e->mFields[ct].arraySize = asin[ct]; |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 238 | bits += ein[ct]->getSizeBits(); |
| 239 | |
| 240 | if (ein[ct]->mHasReference) { |
| 241 | e->mHasReference = true; |
| 242 | } |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Jason Sams | e4c487a | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 245 | rsc->mStateElement.mElements.push(e); |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 246 | return e; |
| 247 | } |
| 248 | |
Jason Sams | e17964e | 2010-01-04 16:52:27 -0800 | [diff] [blame] | 249 | String8 Element::getGLSLType(uint32_t indent) const |
| 250 | { |
| 251 | String8 s; |
| 252 | for (uint32_t ct=0; ct < indent; ct++) { |
| 253 | s.append(" "); |
| 254 | } |
| 255 | |
| 256 | if (!mFieldCount) { |
| 257 | // Basic component. |
| 258 | s.append(mComponent.getGLSLType()); |
| 259 | } else { |
| 260 | rsAssert(0); |
| 261 | //s.append("struct "); |
| 262 | //s.append(getCStructBody(indent)); |
| 263 | } |
| 264 | |
| 265 | return s; |
| 266 | } |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 267 | |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 268 | void Element::incRefs(const void *ptr) const |
| 269 | { |
| 270 | if (!mFieldCount) { |
| 271 | if (mComponent.isReference()) { |
| 272 | ObjectBase *const*obp = static_cast<ObjectBase *const*>(ptr); |
| 273 | ObjectBase *ob = obp[0]; |
Jason Sams | ee73498 | 2010-08-12 12:44:02 -0700 | [diff] [blame] | 274 | if (ob) ob->incSysRef(); |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 275 | } |
| 276 | return; |
| 277 | } |
| 278 | |
| 279 | const uint8_t *p = static_cast<const uint8_t *>(ptr); |
| 280 | for (uint32_t i=0; i < mFieldCount; i++) { |
| 281 | if (mFields[i].e->mHasReference) { |
Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame^] | 282 | p = &p[mFields[i].offsetBits >> 3]; |
| 283 | for (uint32_t ct=0; ct < mFields[i].arraySize; ct++) { |
| 284 | mFields[i].e->incRefs(p); |
| 285 | p += mFields[i].e->getSizeBytes(); |
| 286 | } |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 287 | } |
| 288 | } |
| 289 | } |
| 290 | |
| 291 | void Element::decRefs(const void *ptr) const |
| 292 | { |
| 293 | if (!mFieldCount) { |
| 294 | if (mComponent.isReference()) { |
| 295 | ObjectBase *const*obp = static_cast<ObjectBase *const*>(ptr); |
| 296 | ObjectBase *ob = obp[0]; |
Jason Sams | ee73498 | 2010-08-12 12:44:02 -0700 | [diff] [blame] | 297 | if (ob) ob->decSysRef(); |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 298 | } |
| 299 | return; |
| 300 | } |
| 301 | |
| 302 | const uint8_t *p = static_cast<const uint8_t *>(ptr); |
| 303 | for (uint32_t i=0; i < mFieldCount; i++) { |
| 304 | if (mFields[i].e->mHasReference) { |
Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame^] | 305 | p = &p[mFields[i].offsetBits >> 3]; |
| 306 | for (uint32_t ct=0; ct < mFields[i].arraySize; ct++) { |
| 307 | mFields[i].e->decRefs(p); |
| 308 | p += mFields[i].e->getSizeBytes(); |
| 309 | } |
Jason Sams | b28ca96f | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | } |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 313 | |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 314 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 315 | ElementState::ElementState() |
| 316 | { |
| 317 | } |
| 318 | |
| 319 | ElementState::~ElementState() |
| 320 | { |
Jason Sams | e4c487a | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 321 | rsAssert(!mElements.size()); |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Jason Sams | 0011bcf | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 324 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 325 | ///////////////////////////////////////// |
Jason Sams | 1bada8c | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 326 | // |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 327 | |
| 328 | namespace android { |
| 329 | namespace renderscript { |
| 330 | |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 331 | RsElement rsi_ElementCreate(Context *rsc, |
| 332 | RsDataType dt, |
| 333 | RsDataKind dk, |
| 334 | bool norm, |
| 335 | uint32_t vecSize) |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 336 | { |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 337 | //LOGE("rsi_ElementCreate %i %i %i %i", dt, dk, norm, vecSize); |
Jason Sams | e4c487a | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 338 | const Element *e = Element::create(rsc, dt, dk, norm, vecSize); |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 339 | e->incUserRef(); |
Jason Sams | e4c487a | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 340 | return (RsElement)e; |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 341 | } |
| 342 | |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 343 | RsElement rsi_ElementCreate2(Context *rsc, |
| 344 | size_t count, |
| 345 | const RsElement * ein, |
| 346 | const char ** names, |
Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame^] | 347 | const size_t * nameLengths, |
| 348 | const uint32_t * arraySizes) |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 349 | { |
| 350 | //LOGE("rsi_ElementCreate2 %i", count); |
Jason Sams | 70d4e50 | 2010-09-02 17:35:23 -0700 | [diff] [blame^] | 351 | const Element *e = Element::create(rsc, count, (const Element **)ein, names, nameLengths, arraySizes); |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 352 | e->incUserRef(); |
Jason Sams | e4c487a | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 353 | return (RsElement)e; |
Jason Sams | 718cd1f | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 354 | } |
| 355 | |
Alex Sakhartchouk | dfac814 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 356 | void rsi_ElementGetNativeData(Context *rsc, RsElement elem, uint32_t *elemData, uint32_t elemDataSize) |
| 357 | { |
| 358 | rsAssert(elemDataSize == 5); |
| 359 | // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements |
| 360 | Element *e = static_cast<Element *>(elem); |
| 361 | |
| 362 | (*elemData++) = (uint32_t)e->getType(); |
| 363 | (*elemData++) = (uint32_t)e->getKind(); |
| 364 | (*elemData++) = e->getComponent().getIsNormalized() ? 1 : 0; |
| 365 | (*elemData++) = e->getComponent().getVectorSize(); |
| 366 | (*elemData++) = e->getFieldCount(); |
| 367 | |
| 368 | } |
| 369 | |
| 370 | void rsi_ElementGetSubElements(Context *rsc, RsElement elem, uint32_t *ids, const char **names, uint32_t dataSize) |
| 371 | { |
| 372 | Element *e = static_cast<Element *>(elem); |
| 373 | rsAssert(e->getFieldCount() == dataSize); |
| 374 | |
| 375 | for(uint32_t i = 0; i < dataSize; i ++) { |
| 376 | ids[i] = (uint32_t)e->getField(i); |
| 377 | names[i] = e->getFieldName(i); |
| 378 | } |
| 379 | |
| 380 | } |
| 381 | |
Jason Sams | d19f10d | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 382 | |
| 383 | } |
| 384 | } |