Jason Sams | 326e0dd | 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 | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 17 | |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 18 | #ifndef ANDROID_RS_BUILD_FOR_HOST |
| 19 | #include "rsContext.h" |
Jason Sams | 565ac36 | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 20 | #include <GLES/gl.h> |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 21 | #else |
| 22 | #include "rsContextHostStub.h" |
| 23 | #include <OpenGL/gl.h> |
| 24 | #endif |
Jason Sams | 565ac36 | 2009-06-03 16:04:54 -0700 | [diff] [blame] | 25 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 26 | using namespace android; |
| 27 | using namespace android::renderscript; |
| 28 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 29 | |
Jason Sams | e514b45 | 2009-09-25 14:51:22 -0700 | [diff] [blame] | 30 | Element::Element(Context *rsc) : ObjectBase(rsc) |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 31 | { |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 32 | mBits = 0; |
Jason Sams | f2649a9 | 2009-09-25 16:37:33 -0700 | [diff] [blame] | 33 | mAllocFile = __FILE__; |
| 34 | mAllocLine = __LINE__; |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 35 | mFields = NULL; |
| 36 | mFieldCount = 0; |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 37 | mHasReference = false; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 38 | } |
| 39 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 40 | |
| 41 | Element::~Element() |
| 42 | { |
Jason Sams | 8154954 | 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 | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 49 | clear(); |
| 50 | } |
| 51 | |
| 52 | void Element::clear() |
| 53 | { |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 54 | delete [] mFields; |
| 55 | mFields = NULL; |
| 56 | mFieldCount = 0; |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 57 | mHasReference = false; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 58 | } |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 59 | |
| 60 | size_t Element::getSizeBits() const |
| 61 | { |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 62 | if (!mFieldCount) { |
| 63 | return mBits; |
| 64 | } |
| 65 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 66 | size_t total = 0; |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 67 | for (size_t ct=0; ct < mFieldCount; ct++) { |
Alex Sakhartchouk | 39f2ef6 | 2010-10-11 12:35:15 -0700 | [diff] [blame] | 68 | total += mFields[ct].e->mBits * mFields[ct].arraySize; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 69 | } |
| 70 | return total; |
| 71 | } |
| 72 | |
Jason Sams | e12c1c5 | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 73 | void Element::dumpLOGV(const char *prefix) const |
| 74 | { |
| 75 | ObjectBase::dumpLOGV(prefix); |
Alex Sakhartchouk | 963bb45 | 2010-10-13 14:22:02 -0700 | [diff] [blame^] | 76 | LOGV("%s Element: fieldCount: %i, size bytes: %i", prefix, mFieldCount, getSizeBytes()); |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 77 | for (uint32_t ct = 0; ct < mFieldCount; ct++) { |
Alex Sakhartchouk | 963bb45 | 2010-10-13 14:22:02 -0700 | [diff] [blame^] | 78 | LOGV("%s Element field index: %u ------------------", prefix, ct); |
| 79 | LOGV("%s name: %s, offsetBits: %u, arraySize: %u", |
| 80 | prefix, mFields[ct].name.string(), mFields[ct].offsetBits, mFields[ct].arraySize); |
| 81 | mFields[ct].e->dumpLOGV(prefix); |
Jason Sams | e12c1c5 | 2009-09-27 17:50:38 -0700 | [diff] [blame] | 82 | } |
| 83 | } |
| 84 | |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 85 | void Element::serialize(OStream *stream) const |
| 86 | { |
| 87 | // Need to identify ourselves |
| 88 | stream->addU32((uint32_t)getClassId()); |
| 89 | |
| 90 | String8 name(getName()); |
| 91 | stream->addString(&name); |
| 92 | |
| 93 | mComponent.serialize(stream); |
| 94 | |
| 95 | // Now serialize all the fields |
| 96 | stream->addU32(mFieldCount); |
| 97 | for(uint32_t ct = 0; ct < mFieldCount; ct++) { |
| 98 | stream->addString(&mFields[ct].name); |
Jason Sams | 46e4554 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 99 | stream->addU32(mFields[ct].arraySize); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 100 | mFields[ct].e->serialize(stream); |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | Element *Element::createFromStream(Context *rsc, IStream *stream) |
| 105 | { |
| 106 | // First make sure we are reading the correct object |
Alex Sakhartchouk | b825f67 | 2010-06-04 10:06:50 -0700 | [diff] [blame] | 107 | RsA3DClassID classID = (RsA3DClassID)stream->loadU32(); |
| 108 | if(classID != RS_A3D_CLASS_ID_ELEMENT) { |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 109 | LOGE("element loading skipped due to invalid class id\n"); |
| 110 | return NULL; |
| 111 | } |
| 112 | |
| 113 | String8 name; |
| 114 | stream->loadString(&name); |
| 115 | |
| 116 | Element *elem = new Element(rsc); |
| 117 | elem->mComponent.loadFromStream(stream); |
| 118 | elem->mBits = elem->mComponent.getBits(); |
Alex Sakhartchouk | e6d9fbc | 2010-08-11 10:30:44 -0700 | [diff] [blame] | 119 | elem->mHasReference = elem->mComponent.isReference(); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 120 | |
| 121 | elem->mFieldCount = stream->loadU32(); |
| 122 | if(elem->mFieldCount) { |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 123 | uint32_t offset = 0; |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 124 | elem->mFields = new ElementField_t [elem->mFieldCount]; |
| 125 | for(uint32_t ct = 0; ct < elem->mFieldCount; ct ++) { |
| 126 | stream->loadString(&elem->mFields[ct].name); |
Jason Sams | 46e4554 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 127 | elem->mFields[ct].arraySize = stream->loadU32(); |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 128 | Element *fieldElem = Element::createFromStream(rsc, stream); |
| 129 | elem->mFields[ct].e.set(fieldElem); |
Jason Sams | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 130 | elem->mFields[ct].offsetBits = offset; |
| 131 | offset += fieldElem->getSizeBits(); |
Alex Sakhartchouk | e6d9fbc | 2010-08-11 10:30:44 -0700 | [diff] [blame] | 132 | // Check if our sub-elements have references |
| 133 | if(fieldElem->mHasReference) { |
| 134 | elem->mHasReference = true; |
| 135 | } |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 136 | } |
| 137 | } |
| 138 | |
| 139 | // We need to check if this already exists |
| 140 | for (uint32_t ct=0; ct < rsc->mStateElement.mElements.size(); ct++) { |
| 141 | Element *ee = rsc->mStateElement.mElements[ct]; |
Alex Sakhartchouk | 383e5b1 | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 142 | if(ee->isEqual(elem)) { |
| 143 | delete elem; |
| 144 | ee->incUserRef(); |
| 145 | return ee; |
Alex Sakhartchouk | fb6b614 | 2010-05-21 12:53:13 -0700 | [diff] [blame] | 146 | } |
| 147 | } |
| 148 | |
| 149 | rsc->mStateElement.mElements.push(elem); |
| 150 | return elem; |
| 151 | } |
| 152 | |
Alex Sakhartchouk | 383e5b1 | 2010-09-23 16:16:33 -0700 | [diff] [blame] | 153 | bool Element::isEqual(const Element *other) const { |
| 154 | if(other == NULL) { |
| 155 | return false; |
| 156 | } |
| 157 | if (!other->getFieldCount() && !mFieldCount) { |
| 158 | if((other->getType() == getType()) && |
| 159 | (other->getKind() == getKind()) && |
| 160 | (other->getComponent().getIsNormalized() == getComponent().getIsNormalized()) && |
| 161 | (other->getComponent().getVectorSize() == getComponent().getVectorSize())) { |
| 162 | return true; |
| 163 | } |
| 164 | return false; |
| 165 | } |
| 166 | if (other->getFieldCount() == mFieldCount) { |
| 167 | for (uint32_t i=0; i < mFieldCount; i++) { |
| 168 | if ((!other->mFields[i].e->isEqual(mFields[i].e.get())) || |
| 169 | (other->mFields[i].name.length() != mFields[i].name.length()) || |
| 170 | (other->mFields[i].name != mFields[i].name) || |
| 171 | (other->mFields[i].arraySize != mFields[i].arraySize)) { |
| 172 | return false; |
| 173 | } |
| 174 | } |
| 175 | return true; |
| 176 | } |
| 177 | return false; |
| 178 | } |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 179 | |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 180 | const Element * Element::create(Context *rsc, RsDataType dt, RsDataKind dk, |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 181 | bool isNorm, uint32_t vecSize) |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 182 | { |
Jason Sams | 8154954 | 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 | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 197 | Element *e = new Element(rsc); |
Jason Sams | d01d970 | 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 | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 200 | e->mHasReference = e->mComponent.isReference(); |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 201 | rsc->mStateElement.mElements.push(e); |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 202 | return e; |
| 203 | } |
| 204 | |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 205 | const Element * Element::create(Context *rsc, size_t count, const Element **ein, |
Jason Sams | 46e4554 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 206 | const char **nin, const size_t * lengths, const uint32_t *asin) |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 207 | { |
Jason Sams | 8154954 | 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 | 46e4554 | 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 | 8154954 | 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 | 4815c0d | 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 | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 232 | size_t bits = 0; |
Jason Sams | 4815c0d | 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 | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 236 | e->mFields[ct].offsetBits = bits; |
Jason Sams | 46e4554 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 237 | e->mFields[ct].arraySize = asin[ct]; |
Jason Sams | e3929c9 | 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 | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 243 | } |
| 244 | |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 245 | rsc->mStateElement.mElements.push(e); |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 246 | return e; |
| 247 | } |
| 248 | |
Jason Sams | b4d3568 | 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 | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 267 | |
Jason Sams | e3929c9 | 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 | 10e5e57 | 2010-08-12 12:44:02 -0700 | [diff] [blame] | 274 | if (ob) ob->incSysRef(); |
Jason Sams | e3929c9 | 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 | 46e4554 | 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 | e3929c9 | 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 | 10e5e57 | 2010-08-12 12:44:02 -0700 | [diff] [blame] | 297 | if (ob) ob->decSysRef(); |
Jason Sams | e3929c9 | 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 | 46e4554 | 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 | e3929c9 | 2010-08-09 18:13:33 -0700 | [diff] [blame] | 310 | } |
| 311 | } |
| 312 | } |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 313 | |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 314 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 315 | ElementState::ElementState() |
| 316 | { |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 317 | const uint32_t initialCapacity = 32; |
| 318 | mBuilderElements.setCapacity(initialCapacity); |
| 319 | mBuilderNameStrings.setCapacity(initialCapacity); |
| 320 | mBuilderNameLengths.setCapacity(initialCapacity); |
| 321 | mBuilderArrays.setCapacity(initialCapacity); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | ElementState::~ElementState() |
| 325 | { |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 326 | rsAssert(!mElements.size()); |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 327 | } |
| 328 | |
Alex Sakhartchouk | e7ae69f | 2010-09-14 09:50:43 -0700 | [diff] [blame] | 329 | void ElementState::elementBuilderBegin() { |
| 330 | mBuilderElements.clear(); |
| 331 | mBuilderNameStrings.clear(); |
| 332 | mBuilderNameLengths.clear(); |
| 333 | mBuilderArrays.clear(); |
| 334 | } |
| 335 | |
| 336 | void ElementState::elementBuilderAdd(const Element *e, const char *nameStr, uint32_t arraySize) { |
| 337 | mBuilderElements.push(e); |
| 338 | mBuilderNameStrings.push(nameStr); |
| 339 | mBuilderNameLengths.push(strlen(nameStr)); |
| 340 | mBuilderArrays.push(arraySize); |
| 341 | |
| 342 | } |
| 343 | |
| 344 | const Element *ElementState::elementBuilderCreate(Context *rsc) { |
| 345 | return Element::create(rsc, mBuilderElements.size(), |
| 346 | &(mBuilderElements.editArray()[0]), |
| 347 | &(mBuilderNameStrings.editArray()[0]), |
| 348 | mBuilderNameLengths.editArray(), |
| 349 | mBuilderArrays.editArray()); |
| 350 | } |
| 351 | |
Jason Sams | 4815c0d | 2009-12-15 12:58:36 -0800 | [diff] [blame] | 352 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 353 | ///////////////////////////////////////// |
Jason Sams | e5ffb87 | 2009-08-09 17:01:55 -0700 | [diff] [blame] | 354 | // |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 355 | |
| 356 | namespace android { |
| 357 | namespace renderscript { |
| 358 | |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 359 | RsElement rsi_ElementCreate(Context *rsc, |
| 360 | RsDataType dt, |
| 361 | RsDataKind dk, |
| 362 | bool norm, |
| 363 | uint32_t vecSize) |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 364 | { |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 365 | //LOGE("rsi_ElementCreate %i %i %i %i", dt, dk, norm, vecSize); |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 366 | const Element *e = Element::create(rsc, dt, dk, norm, vecSize); |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 367 | e->incUserRef(); |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 368 | return (RsElement)e; |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 369 | } |
| 370 | |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 371 | RsElement rsi_ElementCreate2(Context *rsc, |
| 372 | size_t count, |
| 373 | const RsElement * ein, |
| 374 | const char ** names, |
Jason Sams | 46e4554 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 375 | const size_t * nameLengths, |
| 376 | const uint32_t * arraySizes) |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 377 | { |
| 378 | //LOGE("rsi_ElementCreate2 %i", count); |
Jason Sams | 46e4554 | 2010-09-02 17:35:23 -0700 | [diff] [blame] | 379 | const Element *e = Element::create(rsc, count, (const Element **)ein, names, nameLengths, arraySizes); |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 380 | e->incUserRef(); |
Jason Sams | 8154954 | 2010-02-17 15:38:10 -0800 | [diff] [blame] | 381 | return (RsElement)e; |
Jason Sams | d01d970 | 2009-12-23 14:35:29 -0800 | [diff] [blame] | 382 | } |
| 383 | |
Alex Sakhartchouk | 417e6a4 | 2010-07-15 11:33:03 -0700 | [diff] [blame] | 384 | void rsi_ElementGetNativeData(Context *rsc, RsElement elem, uint32_t *elemData, uint32_t elemDataSize) |
| 385 | { |
| 386 | rsAssert(elemDataSize == 5); |
| 387 | // we will pack mType; mKind; mNormalized; mVectorSize; NumSubElements |
| 388 | Element *e = static_cast<Element *>(elem); |
| 389 | |
| 390 | (*elemData++) = (uint32_t)e->getType(); |
| 391 | (*elemData++) = (uint32_t)e->getKind(); |
| 392 | (*elemData++) = e->getComponent().getIsNormalized() ? 1 : 0; |
| 393 | (*elemData++) = e->getComponent().getVectorSize(); |
| 394 | (*elemData++) = e->getFieldCount(); |
| 395 | |
| 396 | } |
| 397 | |
| 398 | void rsi_ElementGetSubElements(Context *rsc, RsElement elem, uint32_t *ids, const char **names, uint32_t dataSize) |
| 399 | { |
| 400 | Element *e = static_cast<Element *>(elem); |
| 401 | rsAssert(e->getFieldCount() == dataSize); |
| 402 | |
| 403 | for(uint32_t i = 0; i < dataSize; i ++) { |
| 404 | ids[i] = (uint32_t)e->getField(i); |
| 405 | names[i] = e->getFieldName(i); |
| 406 | } |
| 407 | |
| 408 | } |
| 409 | |
Jason Sams | 326e0dd | 2009-05-22 14:03:28 -0700 | [diff] [blame] | 410 | |
| 411 | } |
| 412 | } |