ObjectBaseRef<const Element> Element::createRef(Context *rsc, RsDataType dt, RsDataKind dk, bool isNorm, uint32_t vecSize) { ObjectBaseRef<const Element> returnRef; // Look for an existing match. ObjectBase::asyncLock(); for (uint32_t ct=0; ct < rsc->mStateElement.mElements.size(); ct++) { const Element *ee = rsc->mStateElement.mElements[ct]; if (!ee->getFieldCount() && (ee->getComponent().getType() == dt) && (ee->getComponent().getKind() == dk) && (ee->getComponent().getIsNormalized() == isNorm) && (ee->getComponent().getVectorSize() == vecSize)) { // Match returnRef.set(ee); ObjectBase::asyncUnlock(); return ee; } } ObjectBase::asyncUnlock(); Element *e = new Element(rsc); returnRef.set(e); e->mComponent.set(dt, dk, isNorm, vecSize); e->compute(); ObjectBase::asyncLock(); rsc->mStateElement.mElements.push(e); ObjectBase::asyncUnlock(); return returnRef; }
ObjectBaseRef<const Element> Element::createRef(Context *rsc, size_t count, const Element **ein, const char **nin, const size_t * lengths, const uint32_t *asin) { ObjectBaseRef<const Element> returnRef; // Look for an existing match. ObjectBase::asyncLock(); for (uint32_t ct=0; ct < rsc->mStateElement.mElements.size(); ct++) { const Element *ee = rsc->mStateElement.mElements[ct]; if (ee->getFieldCount() == count) { bool match = true; for (uint32_t i=0; i < count; i++) { if ((ee->mFields[i].e.get() != ein[i]) || (ee->mFields[i].name.length() != lengths[i]) || (ee->mFields[i].name != nin[i]) || (ee->mFields[i].arraySize != asin[i])) { match = false; break; } } if (match) { returnRef.set(ee); ObjectBase::asyncUnlock(); return returnRef; } } } ObjectBase::asyncUnlock(); Element *e = new Element(rsc); returnRef.set(e); e->mFields = new ElementField_t [count]; e->mFieldCount = count; for (size_t ct=0; ct < count; ct++) { e->mFields[ct].e.set(ein[ct]); e->mFields[ct].name.setTo(nin[ct], lengths[ct]); e->mFields[ct].arraySize = asin[ct]; } e->compute(); ObjectBase::asyncLock(); rsc->mStateElement.mElements.push(e); ObjectBase::asyncUnlock(); return returnRef; }
ObjectBaseRef<Sampler> Sampler::getSampler(Context *rsc, RsSamplerValue magFilter, RsSamplerValue minFilter, RsSamplerValue wrapS, RsSamplerValue wrapT, RsSamplerValue wrapR, float aniso) { ObjectBaseRef<Sampler> returnRef; ObjectBase::asyncLock(); for (uint32_t ct = 0; ct < rsc->mStateSampler.mAllSamplers.size(); ct++) { Sampler *existing = rsc->mStateSampler.mAllSamplers[ct]; if (existing->mHal.state.magFilter != magFilter) continue; if (existing->mHal.state.minFilter != minFilter ) continue; if (existing->mHal.state.wrapS != wrapS) continue; if (existing->mHal.state.wrapT != wrapT) continue; if (existing->mHal.state.wrapR != wrapR) continue; if (existing->mHal.state.aniso != aniso) continue; returnRef.set(existing); ObjectBase::asyncUnlock(); return returnRef; } ObjectBase::asyncUnlock(); void* allocMem = rsc->mHal.funcs.allocRuntimeMem(sizeof(Sampler), 0); if (!allocMem) { rsc->setError(RS_ERROR_FATAL_DRIVER, "Couldn't allocate memory for Allocation"); return NULL; } Sampler *s = new (allocMem) Sampler(rsc, magFilter, minFilter, wrapS, wrapT, wrapR, aniso); returnRef.set(s); #ifdef RS_FIND_OFFSETS ALOGE("pointer for sampler: %p", s); ALOGE("pointer for sampler.drv: %p", &s->mHal.drv); #endif ObjectBase::asyncLock(); rsc->mStateSampler.mAllSamplers.push(s); ObjectBase::asyncUnlock(); return returnRef; }
ObjectBaseRef<ProgramRaster> ProgramRaster::getProgramRaster(Context *rsc, bool pointSprite, RsCullMode cull) { ObjectBaseRef<ProgramRaster> returnRef; ObjectBase::asyncLock(); for (uint32_t ct = 0; ct < rsc->mStateRaster.mRasterPrograms.size(); ct++) { ProgramRaster *existing = rsc->mStateRaster.mRasterPrograms[ct]; if (existing->mHal.state.pointSprite != pointSprite) continue; if (existing->mHal.state.cull != cull) continue; returnRef.set(existing); ObjectBase::asyncUnlock(); return returnRef; } ObjectBase::asyncUnlock(); ProgramRaster *pr = new ProgramRaster(rsc, pointSprite, cull); returnRef.set(pr); ObjectBase::asyncLock(); rsc->mStateRaster.mRasterPrograms.push(pr); ObjectBase::asyncUnlock(); return returnRef; }