diff options
author | Chris Wailes <chriswailes@google.com> | 2014-07-28 16:54:38 -0700 |
---|---|---|
committer | Chris Wailes <chriswailes@google.com> | 2014-08-18 15:12:32 -0700 |
commit | 93d6bc872b7d9fba63abfa7513d56b38d9c3d371 (patch) | |
tree | 0a99fbd58c3254f82ffa1600f653aeac81c55d03 | |
parent | 70d4971878444fe7cf4263998b0c3f46e2b6c71f (diff) | |
download | rs-93d6bc872b7d9fba63abfa7513d56b38d9c3d371.tar.gz |
Replaced android::Vector with std::vector.
Change-Id: I4c6abd964dc4b1412ec2e592fc8e835fecfe53f6
37 files changed, 334 insertions, 433 deletions
@@ -1,7 +1,7 @@ LOCAL_PATH:=$(call my-dir) -rs_base_CFLAGS := -Werror -Wall -Wno-unused-parameter -Wno-unused-variable -fno-exceptions +rs_base_CFLAGS := -Werror -Wall -Wno-unused-parameter -Wno-unused-variable -fno-exceptions -std=c++11 ifeq ($(TARGET_BUILD_PDK), true) rs_base_CFLAGS += -D__RS_PDK__ endif diff --git a/cpu_ref/rsCpuScript.cpp b/cpu_ref/rsCpuScript.cpp index 86e61e17..91914888 100644 --- a/cpu_ref/rsCpuScript.cpp +++ b/cpu_ref/rsCpuScript.cpp @@ -176,7 +176,7 @@ static void *loadSharedLibrary(const char *cacheDir, const char *resName) { // library fallback path. Those applications don't have a private // library path, so they need to install to the system directly. // Note that this is really just a testing path. - android::String8 scriptSONameSystem("/system/lib/librs."); + std::string scriptSONameSystem("/system/lib/librs."); scriptSONameSystem.append(resName); scriptSONameSystem.append(".so"); loaded = loadSOHelper(scriptSONameSystem.c_str(), cacheDir, diff --git a/cpu_ref/rsCpuScriptGroup.cpp b/cpu_ref/rsCpuScriptGroup.cpp index 4eb9e9d9..1d26f59d 100644 --- a/cpu_ref/rsCpuScriptGroup.cpp +++ b/cpu_ref/rsCpuScriptGroup.cpp @@ -126,11 +126,11 @@ void CpuScriptGroupImpl::scriptGroupRoot(const RsExpandKernelParams *kparams, void CpuScriptGroupImpl::execute() { - Vector<Allocation *> ins; - Vector<bool> inExts; - Vector<Allocation *> outs; - Vector<bool> outExts; - Vector<const ScriptKernelID *> kernels; + std::vector<Allocation *> ins; + std::vector<char> inExts; + std::vector<Allocation *> outs; + std::vector<char> outExts; + std::vector<const ScriptKernelID *> kernels; bool fieldDep = false; for (size_t ct=0; ct < mSG->mNodes.size(); ct++) { @@ -196,11 +196,11 @@ void CpuScriptGroupImpl::execute() { rsAssert((k->mHasKernelOutput == (aout != NULL)) && (k->mHasKernelInput == (ain != NULL))); - ins.add(ain); - inExts.add(inExt); - outs.add(aout); - outExts.add(outExt); - kernels.add(k); + ins.push_back(ain); + inExts.push_back(inExt); + outs.push_back(aout); + outExts.push_back(outExt); + kernels.push_back(k); } } @@ -237,10 +237,16 @@ void CpuScriptGroupImpl::execute() { } } else { ScriptList sl; - sl.ins = ins.array(); - sl.outs = outs.array(); - sl.kernels = kernels.array(); - sl.count = kernels.size(); + + /* + * TODO: This is a hacky way of doing this and should be replaced by a + * call to std::vector's data() member once we have a C++11 + * version of the STL. + */ + sl.ins = &ins.front(); + sl.outs = &outs.front(); + sl.kernels = &kernels.front(); + sl.count = kernels.size(); uint32_t inLen; const Allocation **ains; @@ -254,25 +260,27 @@ void CpuScriptGroupImpl::execute() { ains = const_cast<const Allocation**>(&ins[0]); } - Vector<const void *> usrPtrs; - Vector<const void *> fnPtrs; - Vector<uint32_t> sigs; + std::vector<const void *> usrPtrs; + std::vector<const void *> fnPtrs; + std::vector<uint32_t> sigs; for (size_t ct=0; ct < kernels.size(); ct++) { Script *s = kernels[ct]->mScript; RsdCpuScriptImpl *si = (RsdCpuScriptImpl *)mCtx->lookupScript(s); si->forEachKernelSetup(kernels[ct]->mSlot, &mtls); - fnPtrs.add((void *)mtls.kernel); - usrPtrs.add(mtls.fep.usr); - sigs.add(mtls.fep.usrLen); + fnPtrs.push_back((void *)mtls.kernel); + usrPtrs.push_back(mtls.fep.usr); + sigs.push_back(mtls.fep.usrLen); si->preLaunch(kernels[ct]->mSlot, ains, inLen, outs[ct], mtls.fep.usr, mtls.fep.usrLen, NULL); } - sl.sigs = sigs.array(); - sl.usrPtrs = usrPtrs.array(); - sl.fnPtrs = fnPtrs.array(); - sl.inExts = inExts.array(); - sl.outExts = outExts.array(); + + sl.sigs = &sigs.front(); + sl.usrPtrs = &usrPtrs.front(); + sl.fnPtrs = &fnPtrs.front(); + + sl.inExts = (bool*)&inExts.front(); + sl.outExts = (bool*)&outExts.front(); Script *s = kernels[0]->mScript; RsdCpuScriptImpl *si = (RsdCpuScriptImpl *)mCtx->lookupScript(s); diff --git a/driver/rsdBcc.cpp b/driver/rsdBcc.cpp index b7c7f2e5..419422a8 100644 --- a/driver/rsdBcc.cpp +++ b/driver/rsdBcc.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include <vector> + #include "../cpu_ref/rsd_cpu.h" #include "rsdCore.h" @@ -26,7 +28,6 @@ #include "rsScriptC.h" #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB) -#include "utils/Vector.h" #include "utils/Timers.h" #include "utils/StopWatch.h" #endif diff --git a/driver/rsdMeshObj.cpp b/driver/rsdMeshObj.cpp index 66c3b187..5837c261 100644 --- a/driver/rsdMeshObj.cpp +++ b/driver/rsdMeshObj.cpp @@ -114,7 +114,7 @@ bool RsdMeshObj::init(const Context *rsc) { mAttribs[userNum].stride = stride; String8 tmp(RS_SHADER_ATTR); tmp.append(elem->mHal.state.fieldNames[fieldI]); - mAttribs[userNum].name.setTo(tmp.string()); + mAttribs[userNum].name = tmp.string(); // Remember which allocation this attribute came from mAttribAllocationIndex[userNum] = ct; diff --git a/driver/rsdShader.cpp b/driver/rsdShader.cpp index 0b182fff..8a0b0153 100644 --- a/driver/rsdShader.cpp +++ b/driver/rsdShader.cpp @@ -41,13 +41,13 @@ RsdShader::RsdShader(const Program *p, uint32_t type, init(textureNames, textureNamesCount, textureNamesLength); for(size_t i=0; i < textureNamesCount; i++) { - mTextureNames.push(String8(textureNames[i], textureNamesLength[i])); + mTextureNames.push_back(String8(textureNames[i], textureNamesLength[i])); } } RsdShader::~RsdShader() { for (uint32_t i = 0; i < mStateBasedShaders.size(); i ++) { - StateBasedKey *state = mStateBasedShaders.itemAt(i); + StateBasedKey *state = mStateBasedShaders[i]; if (state->mShaderID) { glDeleteShader(state->mShaderID); } @@ -76,7 +76,7 @@ RsdShader::StateBasedKey *RsdShader::getExistingState() { RsdShader::StateBasedKey *returnKey = NULL; for (uint32_t i = 0; i < mStateBasedShaders.size(); i ++) { - returnKey = mStateBasedShaders.itemAt(i); + returnKey = mStateBasedShaders[i]; for (uint32_t ct = 0; ct < mRSProgram->mHal.state.texturesCount; ct ++) { uint32_t texType = 0; @@ -108,7 +108,7 @@ uint32_t RsdShader::getStateBasedShaderID(const Context *rsc) { // We have not created a shader for this particular state yet state = new StateBasedKey(mTextureCount); mCurrentState = state; - mStateBasedShaders.add(state); + mStateBasedShaders.push_back(state); createShader(); loadShader(rsc); return mCurrentState->mShaderID; diff --git a/driver/rsdShader.h b/driver/rsdShader.h index fba17907..d5076e3d 100644 --- a/driver/rsdShader.h +++ b/driver/rsdShader.h @@ -49,7 +49,7 @@ public: // Add ability to get all ID's to clean up the cached program objects uint32_t getStateBasedIDCount() const { return mStateBasedShaders.size(); } uint32_t getStateBasedID(uint32_t index) const { - return mStateBasedShaders.itemAt(index)->mShaderID; + return mStateBasedShaders[index]->mShaderID; } uint32_t getAttribCount() const {return mAttribCount;} @@ -116,9 +116,9 @@ protected: android::String8 *mUniformNames; uint32_t *mUniformArraySizes; - android::Vector<android::String8> mTextureNames; + std::vector<android::String8> mTextureNames; - android::Vector<StateBasedKey*> mStateBasedShaders; + std::vector<StateBasedKey*> mStateBasedShaders; int32_t mTextureUniformIndexStart; @@ -133,7 +133,3 @@ protected: }; #endif //ANDROID_RSD_SHADER_H - - - - diff --git a/driver/rsdShaderCache.cpp b/driver/rsdShaderCache.cpp index 69b43fce..9eb16312 100644 --- a/driver/rsdShaderCache.cpp +++ b/driver/rsdShaderCache.cpp @@ -29,7 +29,7 @@ using namespace android::renderscript; RsdShaderCache::RsdShaderCache() { - mEntries.setCapacity(16); + mEntries.reserve(16); mVertexDirty = true; mFragmentDirty = true; } @@ -132,7 +132,7 @@ bool RsdShaderCache::link(const Context *rsc) { ProgramEntry *e = new ProgramEntry(vtx->getAttribCount(), vtx->getUniformCount(), frag->getUniformCount()); - mEntries.push(e); + mEntries.push_back(e); mCurrent = e; e->vtx = vID; e->frag = fID; @@ -228,7 +228,7 @@ bool RsdShaderCache::link(const Context *rsc) { return true; } -int32_t RsdShaderCache::vtxAttribSlot(const String8 &attrName) const { +int32_t RsdShaderCache::vtxAttribSlot(const std::string &attrName) const { for (uint32_t ct=0; ct < mCurrent->vtxAttrCount; ct++) { if (attrName == mCurrent->vtxAttrs[ct].name) { return mCurrent->vtxAttrs[ct].slot; @@ -238,46 +238,45 @@ int32_t RsdShaderCache::vtxAttribSlot(const String8 &attrName) const { } void RsdShaderCache::cleanupVertex(RsdShader *s) { - int32_t numEntries = (int32_t)mEntries.size(); uint32_t numShaderIDs = s->getStateBasedIDCount(); for (uint32_t sId = 0; sId < numShaderIDs; sId ++) { uint32_t id = s->getStateBasedID(sId); - for (int32_t ct = 0; ct < numEntries; ct ++) { - if (mEntries[ct]->vtx == id) { - glDeleteProgram(mEntries[ct]->program); - - delete mEntries[ct]; - mEntries.removeAt(ct); - numEntries = (int32_t)mEntries.size(); - ct --; + + for (auto entry = mEntries.begin(); entry != mEntries.end();) { + if ((*entry)->vtx == id) { + glDeleteProgram((*entry)->program); + + delete *entry; + entry = mEntries.erase(entry); + } else { + entry++; } } } } void RsdShaderCache::cleanupFragment(RsdShader *s) { - int32_t numEntries = (int32_t)mEntries.size(); uint32_t numShaderIDs = s->getStateBasedIDCount(); for (uint32_t sId = 0; sId < numShaderIDs; sId ++) { uint32_t id = s->getStateBasedID(sId); - for (int32_t ct = 0; ct < numEntries; ct ++) { - if (mEntries[ct]->frag == id) { - glDeleteProgram(mEntries[ct]->program); - - delete mEntries[ct]; - mEntries.removeAt(ct); - numEntries = (int32_t)mEntries.size(); - ct --; + + for (auto entry = mEntries.begin(); entry != mEntries.end();) { + if ((*entry)->frag == id) { + glDeleteProgram((*entry)->program); + + delete *entry; + entry = mEntries.erase(entry); + } else { + entry++; } } } } void RsdShaderCache::cleanupAll() { - for (uint32_t ct=0; ct < mEntries.size(); ct++) { - glDeleteProgram(mEntries[ct]->program); - free(mEntries[ct]); + for (auto entry : mEntries) { + glDeleteProgram(entry->program); + delete entry; } mEntries.clear(); } - diff --git a/driver/rsdShaderCache.h b/driver/rsdShaderCache.h index 6de1d637..e782fe5d 100644 --- a/driver/rsdShaderCache.h +++ b/driver/rsdShaderCache.h @@ -17,6 +17,9 @@ #ifndef ANDROID_RSD_SHADER_CACHE_H #define ANDROID_RSD_SHADER_CACHE_H +#include <string> +#include <vector> + namespace android { namespace renderscript { @@ -27,7 +30,6 @@ class Context; #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB) #include <utils/String8.h> -#include <utils/Vector.h> #else #include "rsUtils.h" #endif @@ -58,7 +60,7 @@ public: void cleanupAll(); - int32_t vtxAttribSlot(const android::String8 &attrName) const; + int32_t vtxAttribSlot(const std::string &attrName) const; int32_t vtxUniformSlot(uint32_t a) const {return mCurrent->vtxUniforms[a].slot;} uint32_t vtxUniformSize(uint32_t a) const {return mCurrent->vtxUniforms[a].arraySize;} int32_t fragUniformSlot(uint32_t a) const {return mCurrent->fragUniforms[a].slot;} @@ -143,7 +145,7 @@ protected: UniformData *fragUniforms; bool *fragUniformIsSTO; }; - android::Vector<ProgramEntry*> mEntries; + std::vector<ProgramEntry*> mEntries; ProgramEntry *mCurrent; bool hasArrayUniforms(RsdShader *vtx, RsdShader *frag); @@ -156,7 +158,3 @@ protected: #endif //ANDROID_RSD_SHADER_CACHE_H - - - - diff --git a/driver/rsdVertexArray.cpp b/driver/rsdVertexArray.cpp index 4e293f69..d0a9b3e4 100644 --- a/driver/rsdVertexArray.cpp +++ b/driver/rsdVertexArray.cpp @@ -48,7 +48,7 @@ void RsdVertexArray::Attrib::clear() { stride = 0; ptr = NULL; normalized = false; - name.setTo(""); + name = ""; } void RsdVertexArray::Attrib::set(uint32_t type, uint32_t size, uint32_t stride, @@ -60,7 +60,7 @@ void RsdVertexArray::Attrib::set(uint32_t type, uint32_t size, uint32_t stride, this->offset = offset; this->normalized = normalized; this->stride = stride; - this->name.setTo(name); + this->name = name; } void RsdVertexArray::logAttrib(uint32_t idx, uint32_t slot) const { @@ -69,7 +69,7 @@ void RsdVertexArray::logAttrib(uint32_t idx, uint32_t slot) const { } ALOGV("va %i: slot=%i name=%s buf=%i ptr=%p size=%i type=0x%x stride=0x%x norm=%i offset=0x%p", idx, slot, - mAttribs[idx].name.string(), + mAttribs[idx].name.c_str(), mAttribs[idx].buffer, mAttribs[idx].ptr, mAttribs[idx].size, @@ -135,4 +135,3 @@ void RsdVertexArrayState::init(uint32_t maxAttrs) { mAttrsEnabled[ct] = false; } } - diff --git a/driver/rsdVertexArray.h b/driver/rsdVertexArray.h index 975121b8..1bafe3bc 100644 --- a/driver/rsdVertexArray.h +++ b/driver/rsdVertexArray.h @@ -17,6 +17,8 @@ #ifndef ANDROID_RSD_VERTEX_ARRAY_H #define ANDROID_RSD_VERTEX_ARRAY_H +#include <string> + #include "rsUtils.h" namespace android { @@ -39,7 +41,7 @@ public: uint32_t size; uint32_t stride; bool normalized; - android::String8 name; + std::string name; Attrib(); void clear(); @@ -74,6 +76,3 @@ public: #endif //ANDROID_RSD_VERTEX_ARRAY_H - - - diff --git a/rsAllocation.cpp b/rsAllocation.cpp index 59967e9b..f9e4266a 100644 --- a/rsAllocation.cpp +++ b/rsAllocation.cpp @@ -223,34 +223,40 @@ void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y, } if (y >= mHal.drvState.lod[0].dimY) { - rsc->setError(RS_ERROR_BAD_VALUE, "subElementData X offset out of range."); + rsc->setError(RS_ERROR_BAD_VALUE, + "subElementData X offset out of range."); return; } if (cIdx >= mHal.state.type->getElement()->getFieldCount()) { - rsc->setError(RS_ERROR_BAD_VALUE, "subElementData component out of range."); + rsc->setError(RS_ERROR_BAD_VALUE, + "subElementData component out of range."); return; } const Element * e = mHal.state.type->getElement()->getField(cIdx); - uint32_t elemArraySize = mHal.state.type->getElement()->getFieldArraySize(cIdx); + uint32_t elemArraySize = + mHal.state.type->getElement()->getFieldArraySize(cIdx); if (sizeBytes != e->getSizeBytes() * elemArraySize) { rsc->setError(RS_ERROR_BAD_VALUE, "subElementData bad size."); return; } - rsc->mHal.funcs.allocation.elementData2D(rsc, this, x, y, data, cIdx, sizeBytes); + rsc->mHal.funcs.allocation.elementData2D(rsc, this, x, y, data, cIdx, + sizeBytes); sendDirty(rsc); } void Allocation::addProgramToDirty(const Program *p) { - mToDirtyList.push(p); + mToDirtyList.push_back(p); } void Allocation::removeProgramToDirty(const Program *p) { - for (size_t ct=0; ct < mToDirtyList.size(); ct++) { - if (mToDirtyList[ct] == p) { - mToDirtyList.removeAt(ct); + for (auto entryIter = mToDirtyList.begin(), endIter = mToDirtyList.end(); + entryIter != endIter; entryIter++) { + + if (p == *entryIter) { + mToDirtyList.erase(entryIter); return; } } @@ -268,7 +274,8 @@ void Allocation::dumpLOGV(const char *prefix) const { } } ALOGV("%s allocation ptr=%p mUsageFlags=0x04%x, mMipmapControl=0x%04x", - prefix, mHal.drvState.lod[0].mallocPtr, mHal.state.usageFlags, mHal.state.mipmapControl); + prefix, mHal.drvState.lod[0].mallocPtr, mHal.state.usageFlags, + mHal.state.mipmapControl); } uint32_t Allocation::getPackedSize() const { diff --git a/rsAllocation.h b/rsAllocation.h index f197efc1..47344d8e 100644 --- a/rsAllocation.h +++ b/rsAllocation.h @@ -170,7 +170,7 @@ public: bool hasSameDims(const Allocation *Other) const; protected: - Vector<const Program *> mToDirtyList; + std::vector<const Program *> mToDirtyList; ObjectBaseRef<const Type> mType; void setType(const Type *t) { mType.set(t); diff --git a/rsContext.cpp b/rsContext.cpp index d3d8349d..410ab354 100644 --- a/rsContext.cpp +++ b/rsContext.cpp @@ -743,13 +743,15 @@ void Context::finish() { void Context::assignName(ObjectBase *obj, const char *name, uint32_t len) { rsAssert(!obj->getName()); obj->setName(name, len); - mNames.add(obj); + mNames.push_back(obj); } void Context::removeName(ObjectBase *obj) { - for (size_t ct=0; ct < mNames.size(); ct++) { - if (obj == mNames[ct]) { - mNames.removeAt(ct); + for (auto nameIter = mNames.begin(), endIter = mNames.end(); + nameIter != endIter; nameIter++) { + + if (obj == *nameIter) { + mNames.erase(nameIter); return; } } @@ -984,4 +986,3 @@ void rsaGetName(RsContext con, void * obj, const char **name) { ObjectBase *ob = static_cast<ObjectBase *>(obj); (*name) = ob->getName(); } - diff --git a/rsContext.h b/rsContext.h index b3823586..f750670f 100644 --- a/rsContext.h +++ b/rsContext.h @@ -297,7 +297,7 @@ private: bool mHasSurface; bool mIsContextLite; - Vector<ObjectBase *> mNames; + std::vector<ObjectBase *> mNames; uint64_t mTimers[_RS_TIMER_TOTAL]; Timers mTimerActive; diff --git a/rsCppUtils.h b/rsCppUtils.h index 71cf0775..31578573 100644 --- a/rsCppUtils.h +++ b/rsCppUtils.h @@ -20,7 +20,6 @@ #if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB) #include <utils/Log.h> #include <utils/String8.h> -#include <utils/Vector.h> #include <cutils/atomic.h> #endif @@ -54,96 +53,6 @@ #define ALOGV(...) \ __android_log_print(ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__); -namespace android { - - // server has no Vector or String8 classes; implement on top of STL - class String8: public std::string { - public: - String8(const char *ptr) : std::string(ptr) { - - } - String8(const char *ptr, size_t len) : std::string(ptr, len) { - - } - String8() : std::string() { - - } - - const char* string() const { - return this->c_str(); - } - - void setTo(const char* str, ssize_t len) { - this->assign(str, len); - } - void setTo(const char* str) { - this->assign(str); - } - String8 getPathDir(void) const { - const char* cp; - const char*const str = this->c_str(); - - cp = strrchr(str, OS_PATH_SEPARATOR); - if (cp == NULL) - return String8(""); - else - return String8(str, cp - str); - } - }; - - template <class T> class Vector: public std::vector<T> { - public: - void push(T obj) { - this->push_back(obj); - } - void removeAt(uint32_t index) { - this->erase(this->begin() + index); - } - ssize_t add(const T& obj) { - this->push_back(obj); - return this->size() - 1; - } - void setCapacity(ssize_t capacity) { - this->resize(capacity); - } - - T* editArray() { - return (T*)(this->begin()); - } - - const T* array() { - return (const T*)(this->begin()); - } - - }; - - template<> class Vector<bool>: public std::vector<char> { - public: - void push(bool obj) { - this->push_back(obj); - } - void removeAt(uint32_t index) { - this->erase(this->begin() + index); - } - ssize_t add(const bool& obj) { - this->push_back(obj); - return this->size() - 1; - } - void setCapacity(ssize_t capacity) { - this->resize(capacity); - } - - bool* editArray() { - return (bool*)(this->begin()); - } - - const bool* array() { - return (const bool*)(this->begin()); - } - }; - -} - typedef int64_t nsecs_t; // nano-seconds enum { @@ -286,5 +195,3 @@ static inline uint32_t rsBoxFilter8888(uint32_t i1, uint32_t i2, uint32_t i3, ui } #endif //ANDROID_RS_OBJECT_BASE_H - - diff --git a/rsDevice.cpp b/rsDevice.cpp index 2688890b..1ba005a2 100644 --- a/rsDevice.cpp +++ b/rsDevice.cpp @@ -28,14 +28,16 @@ Device::~Device() { } void Device::addContext(Context *rsc) { - mContexts.push(rsc); + mContexts.push_back(rsc); } void Device::removeContext(Context *rsc) { - for (size_t idx=0; idx < mContexts.size(); idx++) { - if (mContexts[idx] == rsc) { - mContexts.removeAt(idx); - break; + for (auto ctxIter = mContexts.begin(), endIter = mContexts.end(); + ctxIter != endIter; ctxIter++) { + + if (rsc == *ctxIter) { + mContexts.erase(ctxIter); + return; } } } @@ -58,4 +60,3 @@ extern "C" void rsDeviceSetConfig(RsDevice dev, RsDeviceParam p, int32_t value) } rsAssert(0); } - @@ -17,6 +17,8 @@ #ifndef ANDROID_RS_DEVICE_H #define ANDROID_RS_DEVICE_H +#include <vector> + #include "rsUtils.h" // --------------------------------------------------------------------------- @@ -36,7 +38,7 @@ public: bool mForceSW; protected: - Vector<Context *> mContexts; + std::vector<Context *> mContexts; }; } diff --git a/rsElement.cpp b/rsElement.cpp index f7b064ab..0da8096b 100644 --- a/rsElement.cpp +++ b/rsElement.cpp @@ -42,10 +42,14 @@ void Element::operator delete(void* ptr) { } void Element::preDestroy() const { - for (uint32_t ct = 0; ct < mRSC->mStateElement.mElements.size(); ct++) { - if (mRSC->mStateElement.mElements[ct] == this) { - mRSC->mStateElement.mElements.removeAt(ct); - break; + auto &elements = mRSC->mStateElement.mElements; + + for (auto elIter = elements.begin(), endIter = elements.end(); + elIter != endIter; elIter++) { + + if (this == *elIter) { + elements.erase(elIter); + return; } } } @@ -264,7 +268,7 @@ ObjectBaseRef<const Element> Element::createRef(Context *rsc, RsDataType dt, RsD ObjectBase::asyncLock(); - rsc->mStateElement.mElements.push(e); + rsc->mStateElement.mElements.push_back(e); ObjectBase::asyncUnlock(); return returnRef; @@ -339,7 +343,7 @@ ObjectBaseRef<const Element> Element::createRef(Context *rsc, size_t count, cons e->compute(); ObjectBase::asyncLock(); - rsc->mStateElement.mElements.push(e); + rsc->mStateElement.mElements.push_back(e); ObjectBase::asyncUnlock(); return returnRef; diff --git a/rsElement.h b/rsElement.h index 5a3bc13c..2ae9404f 100644 --- a/rsElement.h +++ b/rsElement.h @@ -17,6 +17,8 @@ #ifndef ANDROID_STRUCTURED_ELEMENT_H #define ANDROID_STRUCTURED_ELEMENT_H +#include <vector> + #include "rsComponent.h" #include "rsUtils.h" #include "rsDefines.h" @@ -170,7 +172,7 @@ public: ~ElementState(); // Cache of all existing elements. - Vector<Element *> mElements; + std::vector<Element *> mElements; }; diff --git a/rsFileA3D.cpp b/rsFileA3D.cpp index a589033d..ef5730f6 100644 --- a/rsFileA3D.cpp +++ b/rsFileA3D.cpp @@ -87,7 +87,7 @@ void FileA3D::parseHeader(IStream *headerStream) { entry->mLength = headerStream->loadU32(); } entry->mRsObj = NULL; - mIndex.push(entry); + mIndex.push_back(entry); } } @@ -379,7 +379,7 @@ void FileA3D::appendToFile(Context *con, ObjectBase *obj) { indexEntry->mType = obj->getClassId(); indexEntry->mOffset = mWriteStream->getPos(); indexEntry->mRsObj = obj; - mWriteIndex.push(indexEntry); + mWriteIndex.push_back(indexEntry); obj->serialize(con, mWriteStream); indexEntry->mLength = mWriteStream->getPos() - indexEntry->mOffset; mWriteStream->align(4); diff --git a/rsFileA3D.h b/rsFileA3D.h index 8bf36b97..0c8b3d67 100644 --- a/rsFileA3D.h +++ b/rsFileA3D.h @@ -88,15 +88,13 @@ protected: Asset *mAsset; OStream *mWriteStream; - Vector<A3DIndexEntry*> mWriteIndex; + std::vector<A3DIndexEntry*> mWriteIndex; IStream *mReadStream; - Vector<A3DIndexEntry*> mIndex; + std::vector<A3DIndexEntry*> mIndex; }; } } #endif //ANDROID_RS_FILE_A3D_H - - @@ -33,7 +33,7 @@ using namespace android; using namespace android::renderscript; -Font::Font(Context *rsc) : ObjectBase(rsc), mCachedGlyphs(NULL) { +Font::Font(Context *rsc) : ObjectBase(rsc) { mInitialized = false; mHasKerning = false; mFace = NULL; @@ -76,17 +76,21 @@ bool Font::init(const char *name, float fontSize, uint32_t dpi, const void *data } void Font::preDestroy() const { - for (uint32_t ct = 0; ct < mRSC->mStateFont.mActiveFonts.size(); ct++) { - if (mRSC->mStateFont.mActiveFonts[ct] == this) { - mRSC->mStateFont.mActiveFonts.removeAt(ct); - break; + auto &activeFonts = mRSC->mStateFont.mActiveFonts; + + for (auto font = activeFonts.begin(), end = activeFonts.end(); font != end; + font++) { + + if (this == *font) { + activeFonts.erase(font); + return; } } } void Font::invalidateTextureCache() { for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) { - mCachedGlyphs.valueAt(i)->mIsValid = false; + mCachedGlyphs[i]->mIsValid = false; } } @@ -224,7 +228,7 @@ void Font::renderUTF(const char *text, uint32_t len, int32_t x, int32_t y, Font::CachedGlyphInfo* Font::getCachedUTFChar(int32_t utfChar) { - CachedGlyphInfo *cachedGlyph = mCachedGlyphs.valueFor((uint32_t)utfChar); + CachedGlyphInfo *cachedGlyph = mCachedGlyphs[(uint32_t)utfChar]; if (cachedGlyph == NULL) { cachedGlyph = cacheGlyph((uint32_t)utfChar); } @@ -283,7 +287,7 @@ void Font::updateGlyphCache(CachedGlyphInfo *glyph) { Font::CachedGlyphInfo *Font::cacheGlyph(uint32_t glyph) { CachedGlyphInfo *newGlyph = new CachedGlyphInfo(); - mCachedGlyphs.add(glyph, newGlyph); + mCachedGlyphs[glyph] = newGlyph; #ifndef ANDROID_RS_SERIALIZE newGlyph->mGlyphIndex = FT_Get_Char_Index(mFace, glyph); newGlyph->mIsValid = false; @@ -296,11 +300,14 @@ Font::CachedGlyphInfo *Font::cacheGlyph(uint32_t glyph) { Font * Font::create(Context *rsc, const char *name, float fontSize, uint32_t dpi, const void *data, uint32_t dataLen) { rsc->mStateFont.checkInit(); - Vector<Font*> &activeFonts = rsc->mStateFont.mActiveFonts; + std::vector<Font*> &activeFonts = rsc->mStateFont.mActiveFonts; for (uint32_t i = 0; i < activeFonts.size(); i ++) { Font *ithFont = activeFonts[i]; - if (ithFont->mFontName == name && ithFont->mFontSize == fontSize && ithFont->mDpi == dpi) { + if (ithFont->mFontName == name && + ithFont->mFontSize == fontSize && + ithFont->mDpi == dpi) { + return ithFont; } } @@ -308,7 +315,7 @@ Font * Font::create(Context *rsc, const char *name, float fontSize, uint32_t dpi Font *newFont = new Font(rsc); bool isInitialized = newFont->init(name, fontSize, dpi, data, dataLen); if (isInitialized) { - activeFonts.push(newFont); + activeFonts.push_back(newFont); rsc->mStateFont.precacheLatin(newFont); return newFont; } @@ -325,7 +332,7 @@ Font::~Font() { #endif for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) { - CachedGlyphInfo *glyph = mCachedGlyphs.valueAt(i); + CachedGlyphInfo *glyph = mCachedGlyphs[i]; delete glyph; } } @@ -551,29 +558,39 @@ void FontState::initTextTexture() { mCacheHeight = 256; mCacheWidth = 1024; ObjectBaseRef<Type> texType = Type::getTypeRef(mRSC, alphaElem.get(), - mCacheWidth, mCacheHeight, 0, false, false, 0); + mCacheWidth, mCacheHeight, + 0, false, false, 0); + mCacheBuffer = new uint8_t[mCacheWidth * mCacheHeight]; - Allocation *cacheAlloc = Allocation::createAllocation(mRSC, texType.get(), - RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE); + Allocation *cacheAlloc = + Allocation::createAllocation(mRSC, texType.get(), + RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE); mTextTexture.set(cacheAlloc); // Split up our cache texture into lines of certain widths int32_t nextLine = 0; - mCacheLines.push(new CacheTextureLine(16, texType->getDimX(), nextLine, 0)); - nextLine += mCacheLines.top()->mMaxHeight; - mCacheLines.push(new CacheTextureLine(24, texType->getDimX(), nextLine, 0)); - nextLine += mCacheLines.top()->mMaxHeight; - mCacheLines.push(new CacheTextureLine(24, texType->getDimX(), nextLine, 0)); - nextLine += mCacheLines.top()->mMaxHeight; - mCacheLines.push(new CacheTextureLine(32, texType->getDimX(), nextLine, 0)); - nextLine += mCacheLines.top()->mMaxHeight; - mCacheLines.push(new CacheTextureLine(32, texType->getDimX(), nextLine, 0)); - nextLine += mCacheLines.top()->mMaxHeight; - mCacheLines.push(new CacheTextureLine(40, texType->getDimX(), nextLine, 0)); - nextLine += mCacheLines.top()->mMaxHeight; - mCacheLines.push(new CacheTextureLine(texType->getDimY() - nextLine, texType->getDimX(), nextLine, 0)); + mCacheLines.push_back(new CacheTextureLine(16, texType->getDimX(), + nextLine, 0)); + nextLine += mCacheLines.back()->mMaxHeight; + mCacheLines.push_back(new CacheTextureLine(24, texType->getDimX(), + nextLine, 0)); + nextLine += mCacheLines.back()->mMaxHeight; + mCacheLines.push_back(new CacheTextureLine(24, texType->getDimX(), + nextLine, 0)); + nextLine += mCacheLines.back()->mMaxHeight; + mCacheLines.push_back(new CacheTextureLine(32, texType->getDimX(), + nextLine, 0)); + nextLine += mCacheLines.back()->mMaxHeight; + mCacheLines.push_back(new CacheTextureLine(32, texType->getDimX(), + nextLine, 0)); + nextLine += mCacheLines.back()->mMaxHeight; + mCacheLines.push_back(new CacheTextureLine(40, texType->getDimX(), + nextLine, 0)); + nextLine += mCacheLines.back()->mMaxHeight; + mCacheLines.push_back(new CacheTextureLine(texType->getDimY() - nextLine, + texType->getDimX(), nextLine, 0)); } // Avoid having to reallocate memory and render quad by quad @@ -17,9 +17,10 @@ #ifndef ANDROID_RS_FONT_H #define ANDROID_RS_FONT_H +#include <map> +#include <vector> + #include "rsStream.h" -#include <utils/Vector.h> -#include <utils/KeyedVector.h> struct FT_LibraryRec_; struct FT_FaceRec_; @@ -124,7 +125,7 @@ protected: bool mInitialized; bool mHasKerning; - DefaultKeyedVector<uint32_t, CachedGlyphInfo* > mCachedGlyphs; + std::map<uint32_t, CachedGlyphInfo* > mCachedGlyphs; CachedGlyphInfo* getCachedUTFChar(int32_t utfChar); CachedGlyphInfo *cacheGlyph(uint32_t glyph); @@ -178,7 +179,7 @@ protected: bool fitBitmap(FT_Bitmap_ *bitmap, uint32_t *retOriginX, uint32_t *retOriginY); }; - Vector<CacheTextureLine*> mCacheLines; + std::vector<CacheTextureLine*> mCacheLines; uint32_t getRemainingCacheCapacity(); void precacheLatin(Font *font); @@ -203,7 +204,7 @@ protected: FT_LibraryRec_ *mLibrary; FT_LibraryRec_ *getLib(); #endif //ANDROID_RS_SERIALIZE - Vector<Font*> mActiveFonts; + std::vector<Font*> mActiveFonts; // Render state for the font ObjectBaseRef<Allocation> mFontShaderFConstant; diff --git a/rsGrallocConsumer.h b/rsGrallocConsumer.h index 9e4fc586..b134862e 100644 --- a/rsGrallocConsumer.h +++ b/rsGrallocConsumer.h @@ -17,12 +17,13 @@ #ifndef ANDROID_RS_GRALLOC_CONSUMER_H #define ANDROID_RS_GRALLOC_CONSUMER_H +#include <vector> + #include <gui/ConsumerBase.h> #include <ui/GraphicBuffer.h> #include <utils/String8.h> -#include <utils/Vector.h> #include <utils/threads.h> @@ -75,4 +76,3 @@ class GrallocConsumer : public ConsumerBase } // namespace android #endif // ANDROID_RS_GRALLOC_CONSUMER_H - diff --git a/rsProgramFragment.h b/rsProgramFragment.h index e7456b91..1357bfcf 100644 --- a/rsProgramFragment.h +++ b/rsProgramFragment.h @@ -55,7 +55,7 @@ public: void deinit(Context *rsc); ObjectBaseRef<ProgramFragment> mDefault; - Vector<ProgramFragment *> mPrograms; + std::vector<ProgramFragment *> mPrograms; ObjectBaseRef<ProgramFragment> mLast; }; @@ -63,7 +63,3 @@ public: } } #endif - - - - diff --git a/rsProgramRaster.cpp b/rsProgramRaster.cpp index 4f27f2ec..d2d06027 100644 --- a/rsProgramRaster.cpp +++ b/rsProgramRaster.cpp @@ -31,10 +31,14 @@ ProgramRaster::ProgramRaster(Context *rsc, bool pointSprite, RsCullMode cull) } void ProgramRaster::preDestroy() const { - for (uint32_t ct = 0; ct < mRSC->mStateRaster.mRasterPrograms.size(); ct++) { - if (mRSC->mStateRaster.mRasterPrograms[ct] == this) { - mRSC->mStateRaster.mRasterPrograms.removeAt(ct); - break; + auto &rasters = mRSC->mStateRaster.mRasterPrograms; + + for (auto prIter = rasters.begin(), endIter = rasters.end(); + prIter != endIter; prIter++) { + + if (this == *prIter) { + rasters.erase(prIter); + return; } } } @@ -94,7 +98,7 @@ ObjectBaseRef<ProgramRaster> ProgramRaster::getProgramRaster(Context *rsc, returnRef.set(pr); ObjectBase::asyncLock(); - rsc->mStateRaster.mRasterPrograms.push(pr); + rsc->mStateRaster.mRasterPrograms.push_back(pr); ObjectBase::asyncUnlock(); return returnRef; @@ -111,4 +115,3 @@ RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, bool pointSprite, RsCullM } } - diff --git a/rsProgramRaster.h b/rsProgramRaster.h index e9a524b9..207d74ca 100644 --- a/rsProgramRaster.h +++ b/rsProgramRaster.h @@ -75,14 +75,10 @@ public: ObjectBaseRef<ProgramRaster> mLast; // Cache of all existing raster programs. - Vector<ProgramRaster *> mRasterPrograms; + std::vector<ProgramRaster *> mRasterPrograms; }; } } #endif - - - - diff --git a/rsProgramStore.cpp b/rsProgramStore.cpp index 83c1f2c0..b2d527e9 100644 --- a/rsProgramStore.cpp +++ b/rsProgramStore.cpp @@ -42,10 +42,14 @@ ProgramStore::ProgramStore(Context *rsc, } void ProgramStore::preDestroy() const { - for (uint32_t ct = 0; ct < mRSC->mStateFragmentStore.mStorePrograms.size(); ct++) { - if (mRSC->mStateFragmentStore.mStorePrograms[ct] == this) { - mRSC->mStateFragmentStore.mStorePrograms.removeAt(ct); - break; + auto &stores = mRSC->mStateFragmentStore.mStorePrograms; + + for (auto psIter = stores.begin(), endIter = stores.end(); + psIter != endIter; psIter++) { + + if (this == *psIter) { + stores.erase(psIter); + return; } } } @@ -118,7 +122,7 @@ ObjectBaseRef<ProgramStore> ProgramStore::getProgramStore(Context *rsc, pfs->init(); ObjectBase::asyncLock(); - rsc->mStateFragmentStore.mStorePrograms.push(pfs); + rsc->mStateFragmentStore.mStorePrograms.push_back(pfs); ObjectBase::asyncUnlock(); return returnRef; diff --git a/rsProgramStore.h b/rsProgramStore.h index 9a7f7f17..06824fe5 100644 --- a/rsProgramStore.h +++ b/rsProgramStore.h @@ -92,12 +92,9 @@ public: ObjectBaseRef<ProgramStore> mLast; // Cache of all existing store programs. - Vector<ProgramStore *> mStorePrograms; + std::vector<ProgramStore *> mStorePrograms; }; } } #endif - - - diff --git a/rsSampler.cpp b/rsSampler.cpp index 0cf0b55f..0ea9729b 100644 --- a/rsSampler.cpp +++ b/rsSampler.cpp @@ -49,10 +49,14 @@ Sampler::~Sampler() { } void Sampler::preDestroy() const { - for (uint32_t ct = 0; ct < mRSC->mStateSampler.mAllSamplers.size(); ct++) { - if (mRSC->mStateSampler.mAllSamplers[ct] == this) { - mRSC->mStateSampler.mAllSamplers.removeAt(ct); - break; + auto &samplers = mRSC->mStateSampler.mAllSamplers; + + for (auto sampleIter = samplers.begin(), endIter = samplers.end(); + sampleIter != endIter; sampleIter++) { + + if (this == *sampleIter) { + samplers.erase(sampleIter); + return; } } } @@ -113,7 +117,7 @@ ObjectBaseRef<Sampler> Sampler::getSampler(Context *rsc, #endif ObjectBase::asyncLock(); - rsc->mStateSampler.mAllSamplers.push(s); + rsc->mStateSampler.mAllSamplers.push_back(s); ObjectBase::asyncUnlock(); return returnRef; diff --git a/rsSampler.h b/rsSampler.h index 2fdf7073..3f5855f8 100644 --- a/rsSampler.h +++ b/rsSampler.h @@ -96,12 +96,9 @@ public: } } // Cache of all existing raster programs. - Vector<Sampler *> mAllSamplers; + std::vector<Sampler *> mAllSamplers; }; } } #endif //ANDROID_RS_SAMPLER_H - - - diff --git a/rsScriptC.cpp b/rsScriptC.cpp index 892807bd..2958e84e 100644 --- a/rsScriptC.cpp +++ b/rsScriptC.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include <string> + #include "rsContext.h" #include "rsScriptC.h" @@ -165,15 +167,14 @@ void ScriptC::runForEach(Context *rsc, // Trace this function call. // To avoid overhead we only build the string if tracing is actually // enabled. - String8 *AString = NULL; - const char *String = ""; + std::string *traceString = NULL; + const char *stringData = ""; if (ATRACE_ENABLED()) { - AString = new String8("runForEach_"); - AString->append(mHal.info.exportedForeachFuncList[slot].first); - String = AString->string(); + traceString = new std::string("runForEach_"); + traceString->append(mHal.info.exportedForeachFuncList[slot].first); + stringData = traceString->c_str(); } - ATRACE_NAME(String); - (void)String; + ATRACE_NAME(stringData); Context::PushState ps(rsc); @@ -193,8 +194,8 @@ void ScriptC::runForEach(Context *rsc, "Driver support for multi-input not present"); } - if (AString) { - delete AString; + if (traceString) { + delete traceString; } } diff --git a/rsScriptGroup.cpp b/rsScriptGroup.cpp index a03cb786..f41c65d0 100644 --- a/rsScriptGroup.cpp +++ b/rsScriptGroup.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include <algorithm> + #include "rsContext.h" #include <time.h> @@ -28,8 +30,8 @@ ScriptGroup::~ScriptGroup() { mRSC->mHal.funcs.scriptgroup.destroy(mRSC, this); } - for (size_t ct=0; ct < mLinks.size(); ct++) { - delete mLinks[ct]; + for (auto link : mLinks) { + delete link; } } @@ -44,148 +46,116 @@ ScriptGroup::Node::Node(Script *s) { } ScriptGroup::Node * ScriptGroup::findNode(Script *s) const { - //ALOGE("find %p %i", s, (int)mNodes.size()); - for (size_t ct=0; ct < mNodes.size(); ct++) { - Node *n = mNodes[ct]; - for (size_t ct2=0; ct2 < n->mKernels.size(); ct2++) { - if (n->mKernels[ct2]->mScript == s) { - return n; + for (auto node : mNodes) { + for (auto kernelRef : node->mKernels) { + if (kernelRef->mScript == s) { + return node; } } } + return NULL; } -bool ScriptGroup::calcOrderRecurse(Node *n, int depth) { - n->mSeen = true; - if (n->mOrder < depth) { - n->mOrder = depth; +bool ScriptGroup::calcOrderRecurse(Node *node0, int depth) { + node0->mSeen = true; + if (node0->mOrder < depth) { + node0->mOrder = depth; } bool ret = true; - for (size_t ct=0; ct < n->mOutputs.size(); ct++) { - const Link *l = n->mOutputs[ct]; - Node *nt = NULL; - if (l->mDstField.get()) { - nt = findNode(l->mDstField->mScript); + + for (auto link : node0->mOutputs) { + Node *node1 = NULL; + if (link->mDstField.get()) { + node1 = findNode(link->mDstField->mScript); } else { - nt = findNode(l->mDstKernel->mScript); + node1 = findNode(link->mDstKernel->mScript); } - if (nt->mSeen) { + if (node1->mSeen) { return false; } - ret &= calcOrderRecurse(nt, n->mOrder + 1); + ret &= calcOrderRecurse(node1, node0->mOrder + 1); } - return ret; -} -#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB) -static int CompareNodeForSort(ScriptGroup::Node *const* lhs, - ScriptGroup::Node *const* rhs) { - if (lhs[0]->mOrder > rhs[0]->mOrder) { - return 1; - } - return 0; + return ret; } -#else -class NodeCompare { -public: - bool operator() (const ScriptGroup::Node* lhs, - const ScriptGroup::Node* rhs) { - if (lhs->mOrder > rhs->mOrder) { - return true; - } - return false; - } -}; -#endif bool ScriptGroup::calcOrder() { // Make nodes - for (size_t ct=0; ct < mKernels.size(); ct++) { - const ScriptKernelID *k = mKernels[ct].get(); - //ALOGE(" kernel %i, %p s=%p", (int)ct, k, mKernels[ct]->mScript); - Node *n = findNode(k->mScript); - //ALOGE(" n = %p", n); - if (n == NULL) { - n = new Node(k->mScript); - mNodes.add(n); + + for (auto kernelRef : mKernels) { + const ScriptKernelID *kernel = kernelRef.get(); + Node *node = findNode(kernel->mScript); + if (node == NULL) { + node = new Node(kernel->mScript); + mNodes.push_back(node); } - n->mKernels.add(k); + node->mKernels.push_back(kernel); } // add links - //ALOGE("link count %i", (int)mLinks.size()); - for (size_t ct=0; ct < mLinks.size(); ct++) { - Link *l = mLinks[ct]; - //ALOGE("link %i %p", (int)ct, l); - Node *n = findNode(l->mSource->mScript); - //ALOGE("link n %p", n); - n->mOutputs.add(l); - - if (l->mDstKernel.get()) { - //ALOGE("l->mDstKernel.get() %p", l->mDstKernel.get()); - n = findNode(l->mDstKernel->mScript); - //ALOGE(" n1 %p", n); - n->mInputs.add(l); + for (auto link : mLinks) { + Node *node = findNode(link->mSource->mScript); + node->mOutputs.push_back(link); + + if (link->mDstKernel.get()) { + node = findNode(link->mDstKernel->mScript); + node->mInputs.push_back(link); } else { - n = findNode(l->mDstField->mScript); - //ALOGE(" n2 %p", n); - n->mInputs.add(l); + node = findNode(link->mDstField->mScript); + node->mInputs.push_back(link); } } - //ALOGE("node count %i", (int)mNodes.size()); // Order nodes bool ret = true; - for (size_t ct=0; ct < mNodes.size(); ct++) { - Node *n = mNodes[ct]; - if (n->mInputs.size() == 0) { - for (size_t ct2=0; ct2 < mNodes.size(); ct2++) { - mNodes[ct2]->mSeen = false; + for (auto n0 : mNodes) { + if (n0->mInputs.size() == 0) { + for (auto n1 : mNodes) { + n1->mSeen = false; } - ret &= calcOrderRecurse(n, 0); + ret &= calcOrderRecurse(n0, 1); } } - for (size_t ct=0; ct < mKernels.size(); ct++) { - const ScriptKernelID *k = mKernels[ct].get(); - const Node *n = findNode(k->mScript); + for (auto kernelRef : mKernels) { + const ScriptKernelID *kernel = kernelRef.get(); + const Node *node = findNode(kernel->mScript); - if (k->mHasKernelOutput) { + if (kernel->mHasKernelOutput) { bool found = false; - for (size_t ct2=0; ct2 < n->mOutputs.size(); ct2++) { - if (n->mOutputs[ct2]->mSource.get() == k) { + for (auto output : node->mOutputs) { + if (output->mSource.get() == kernel) { found = true; break; } } + if (!found) { - //ALOGE("add io out %p", k); - mOutputs.add(new IO(k)); + mOutputs.push_back(new IO(kernel)); } } - if (k->mHasKernelInput) { + if (kernel->mHasKernelInput) { bool found = false; - for (size_t ct2=0; ct2 < n->mInputs.size(); ct2++) { - if (n->mInputs[ct2]->mDstKernel.get() == k) { + for (auto input : node->mInputs) { + if (input->mDstKernel.get() == kernel) { found = true; break; } } if (!found) { - //ALOGE("add io in %p", k); - mInputs.add(new IO(k)); + mInputs.push_back(new IO(kernel)); } } } // sort -#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB) - mNodes.sort(&CompareNodeForSort); -#else - std::sort(mNodes.begin(), mNodes.end(), NodeCompare()); -#endif + std::stable_sort(mNodes.begin(), mNodes.end(), + [](const ScriptGroup::Node* lhs, + const ScriptGroup::Node* rhs) { + return lhs->mOrder < rhs->mOrder; + }); return ret; } @@ -209,7 +179,7 @@ ScriptGroup * ScriptGroup::create(Context *rsc, sg->mKernels.reserve(kernelCount); for (size_t ct=0; ct < kernelCount; ct++) { - sg->mKernels.add(kernels[ct]); + sg->mKernels.push_back(kernels[ct]); } sg->mLinks.reserve(linkCount); @@ -219,7 +189,7 @@ ScriptGroup * ScriptGroup::create(Context *rsc, l->mSource = src[ct]; l->mDstField = dstF[ct]; l->mDstKernel = dstK[ct]; - sg->mLinks.add(l); + sg->mLinks.push_back(l); } sg->calcOrder(); @@ -254,9 +224,9 @@ ScriptGroup * ScriptGroup::create(Context *rsc, } void ScriptGroup::setInput(Context *rsc, ScriptKernelID *kid, Allocation *a) { - for (size_t ct=0; ct < mInputs.size(); ct++) { - if (mInputs[ct]->mKernel == kid) { - mInputs[ct]->mAlloc = a; + for (auto input : mInputs) { + if (input->mKernel == kid) { + input->mAlloc = a; if (rsc->mHal.funcs.scriptgroup.setInput) { rsc->mHal.funcs.scriptgroup.setInput(rsc, this, kid, a); @@ -268,9 +238,9 @@ void ScriptGroup::setInput(Context *rsc, ScriptKernelID *kid, Allocation *a) { } void ScriptGroup::setOutput(Context *rsc, ScriptKernelID *kid, Allocation *a) { - for (size_t ct=0; ct < mOutputs.size(); ct++) { - if (mOutputs[ct]->mKernel == kid) { - mOutputs[ct]->mAlloc = a; + for (auto output : mOutputs) { + if (output->mKernel == kid) { + output->mAlloc = a; if (rsc->mHal.funcs.scriptgroup.setOutput) { rsc->mHal.funcs.scriptgroup.setOutput(rsc, this, kid, a); @@ -311,52 +281,45 @@ void ScriptGroup::execute(Context *rsc) { return; } - for (size_t ct=0; ct < mNodes.size(); ct++) { - Node *n = mNodes[ct]; - //ALOGE("node %i, order %i, in %i out %i", (int)ct, n->mOrder, (int)n->mInputs.size(), (int)n->mOutputs.size()); - - for (size_t ct2=0; ct2 < n->mKernels.size(); ct2++) { - const ScriptKernelID *k = n->mKernels[ct2]; - Allocation *ain = NULL; + for (auto node : mNodes) { + for (auto kernel : node->mKernels) { + Allocation *ain = NULL; Allocation *aout = NULL; - for (size_t ct3=0; ct3 < n->mInputs.size(); ct3++) { - if (n->mInputs[ct3]->mDstKernel.get() == k) { - ain = n->mInputs[ct3]->mAlloc.get(); - //ALOGE(" link in %p", ain); + for (auto nodeInput : node->mInputs) { + if (nodeInput->mDstKernel.get() == kernel) { + ain = nodeInput->mAlloc.get(); } } - for (size_t ct3=0; ct3 < mInputs.size(); ct3++) { - if (mInputs[ct3]->mKernel == k) { - ain = mInputs[ct3]->mAlloc.get(); - //ALOGE(" io in %p", ain); + + for (auto sgInput : mInputs) { + if (sgInput->mKernel == kernel) { + ain = sgInput->mAlloc.get(); } } - for (size_t ct3=0; ct3 < n->mOutputs.size(); ct3++) { - if (n->mOutputs[ct3]->mSource.get() == k) { - aout = n->mOutputs[ct3]->mAlloc.get(); - //ALOGE(" link out %p", aout); + for (auto nodeOutput : node->mOutputs) { + if (nodeOutput->mDstKernel.get() == kernel) { + aout = nodeOutput->mAlloc.get(); } } - for (size_t ct3=0; ct3 < mOutputs.size(); ct3++) { - if (mOutputs[ct3]->mKernel == k) { - aout = mOutputs[ct3]->mAlloc.get(); - //ALOGE(" io out %p", aout); + + for (auto sgOutput : mOutputs) { + if (sgOutput->mKernel == kernel) { + aout = sgOutput->mAlloc.get(); } } if (ain == NULL) { - n->mScript->runForEach(rsc, k->mSlot, NULL, 0, aout, NULL, 0); - + node->mScript->runForEach(rsc, kernel->mSlot, NULL, 0, aout, + NULL, 0); } else { const Allocation *ains[1] = {ain}; - n->mScript->runForEach(rsc, k->mSlot, ains, - sizeof(ains) / sizeof(RsAllocation), - aout, NULL, 0); + node->mScript->runForEach(rsc, kernel->mSlot, ains, + sizeof(ains) / sizeof(RsAllocation), + aout, NULL, 0); } } - } } @@ -397,20 +360,17 @@ RsScriptGroup rsi_ScriptGroupCreate(Context *rsc, void rsi_ScriptGroupSetInput(Context *rsc, RsScriptGroup sg, RsScriptKernelID kid, RsAllocation alloc) { - //ALOGE("rsi_ScriptGroupSetInput"); ScriptGroup *s = (ScriptGroup *)sg; s->setInput(rsc, (ScriptKernelID *)kid, (Allocation *)alloc); } void rsi_ScriptGroupSetOutput(Context *rsc, RsScriptGroup sg, RsScriptKernelID kid, RsAllocation alloc) { - //ALOGE("rsi_ScriptGroupSetOutput"); ScriptGroup *s = (ScriptGroup *)sg; s->setOutput(rsc, (ScriptKernelID *)kid, (Allocation *)alloc); } void rsi_ScriptGroupExecute(Context *rsc, RsScriptGroup sg) { - //ALOGE("rsi_ScriptGroupExecute"); ScriptGroup *s = (ScriptGroup *)sg; s->execute(rsc); } diff --git a/rsScriptGroup.h b/rsScriptGroup.h index af98b50a..974e3ba5 100644 --- a/rsScriptGroup.h +++ b/rsScriptGroup.h @@ -32,7 +32,7 @@ class ProgramStore; class ScriptGroup : public ObjectBase { public: - Vector<ObjectBaseRef<ScriptKernelID> > mKernels; + std::vector<ObjectBaseRef<ScriptKernelID> > mKernels; class Link { public: @@ -49,9 +49,9 @@ public: public: Node(Script *); - Vector<const ScriptKernelID *> mKernels; - Vector<Link *> mOutputs; - Vector<Link *> mInputs; + std::vector<const ScriptKernelID *> mKernels; + std::vector<Link *> mOutputs; + std::vector<Link *> mInputs; bool mSeen; int mOrder; Script *mScript; @@ -65,10 +65,10 @@ public: ObjectBaseRef<Allocation> mAlloc; }; - Vector<Link *> mLinks; - Vector<Node *> mNodes; - Vector<IO *> mInputs; - Vector<IO *> mOutputs; + std::vector<Link *> mLinks; + std::vector<Node *> mNodes; + std::vector<IO *> mInputs; + std::vector<IO *> mOutputs; struct Hal { void * drv; @@ -115,4 +115,3 @@ private: } } #endif - @@ -33,10 +33,14 @@ Type::Type(Context *rsc) : ObjectBase(rsc) { } void Type::preDestroy() const { - for (uint32_t ct = 0; ct < mRSC->mStateType.mTypes.size(); ct++) { - if (mRSC->mStateType.mTypes[ct] == this) { - mRSC->mStateType.mTypes.removeAt(ct); - break; + auto &types = mRSC->mStateType.mTypes; + + for (auto typeIter = types.begin(), endIter = types.end(); + typeIter != endIter; typeIter++) { + + if (this == *typeIter) { + types.erase(typeIter); + return; } } } @@ -258,7 +262,7 @@ ObjectBaseRef<Type> Type::getTypeRef(Context *rsc, const Element *e, nt->compute(); ObjectBase::asyncLock(); - stc->mTypes.push(nt); + stc->mTypes.push_back(nt); ObjectBase::asyncUnlock(); return returnRef; @@ -146,7 +146,7 @@ public: ~TypeState(); // Cache of all existing types. - Vector<Type *> mTypes; + std::vector<Type *> mTypes; }; |