summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYang Ni <yangni@google.com>2015-02-14 18:00:59 -0800
committerYang Ni <yangni@google.com>2015-02-15 20:10:40 +0000
commitb8353c5943f4038fd7f08db3d958390ce9418798 (patch)
tree2cfac49d1f790e077f40dfc7ba42904ee5658f50
parent1ce0dfd82311d4922dbffdde302599410fc25c5d (diff)
downloadrs-b8353c5943f4038fd7f08db3d958390ce9418798.tar.gz
Revert "Replaced android::Vector with std::vector."
b/19148482 This reverts commit 93d6bc872b7d9fba63abfa7513d56b38d9c3d371. I also made some changes to Make it work with HEAD. Change-Id: I5e516976ec1d85ffe1cf388c01795348a9441982
-rw-r--r--cpu_ref/rsCpuScriptGroup.cpp58
-rw-r--r--driver/rsdBcc.cpp3
-rw-r--r--driver/rsdMeshObj.cpp4
-rw-r--r--driver/rsdShader.cpp9
-rw-r--r--driver/rsdShader.h10
-rw-r--r--driver/rsdShaderCache.cpp49
-rw-r--r--driver/rsdShaderCache.h17
-rw-r--r--driver/rsdVertexArray.cpp7
-rw-r--r--driver/rsdVertexArray.h7
-rw-r--r--rsAllocation.cpp25
-rw-r--r--rsAllocation.h2
-rw-r--r--rsContext.cpp11
-rw-r--r--rsContext.h2
-rw-r--r--rsCppUtils.h94
-rw-r--r--rsDevice.cpp13
-rw-r--r--rsDevice.h4
-rw-r--r--rsElement.cpp16
-rw-r--r--rsElement.h4
-rw-r--r--rsFileA3D.cpp4
-rw-r--r--rsFileA3D.h6
-rw-r--r--rsFont.cpp69
-rw-r--r--rsFont.h11
-rw-r--r--rsGrallocConsumer.h5
-rw-r--r--rsProgramFragment.h6
-rw-r--r--rsProgramRaster.cpp15
-rw-r--r--rsProgramRaster.h6
-rw-r--r--rsProgramStore.cpp14
-rw-r--r--rsProgramStore.h5
-rw-r--r--rsSampler.cpp14
-rw-r--r--rsSampler.h5
-rw-r--r--rsScriptC.cpp21
-rw-r--r--rsScriptGroup.cpp221
-rw-r--r--rsScriptGroup.h17
-rw-r--r--rsType.cpp14
-rw-r--r--rsType.h2
35 files changed, 441 insertions, 329 deletions
diff --git a/cpu_ref/rsCpuScriptGroup.cpp b/cpu_ref/rsCpuScriptGroup.cpp
index 166c80da..281a7156 100644
--- a/cpu_ref/rsCpuScriptGroup.cpp
+++ b/cpu_ref/rsCpuScriptGroup.cpp
@@ -124,11 +124,11 @@ void CpuScriptGroupImpl::scriptGroupRoot(const RsExpandKernelParams *kparams,
void CpuScriptGroupImpl::execute() {
- std::vector<Allocation *> ins;
- std::vector<char> inExts;
- std::vector<Allocation *> outs;
- std::vector<char> outExts;
- std::vector<const ScriptKernelID *> kernels;
+ Vector<Allocation *> ins;
+ Vector<bool> inExts;
+ Vector<Allocation *> outs;
+ Vector<bool> outExts;
+ Vector<const ScriptKernelID *> kernels;
bool fieldDep = false;
for (size_t ct=0; ct < mSG->mNodes.size(); ct++) {
@@ -194,11 +194,11 @@ void CpuScriptGroupImpl::execute() {
rsAssert((k->mHasKernelOutput == (aout != nullptr)) &&
(k->mHasKernelInput == (ain != nullptr)));
- ins.push_back(ain);
- inExts.push_back(inExt);
- outs.push_back(aout);
- outExts.push_back(outExt);
- kernels.push_back(k);
+ ins.add(ain);
+ inExts.add(inExt);
+ outs.add(aout);
+ outExts.add(outExt);
+ kernels.add(k);
}
}
@@ -237,16 +237,10 @@ void CpuScriptGroupImpl::execute() {
}
} else {
ScriptList sl;
-
- /*
- * 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();
+ sl.ins = ins.array();
+ sl.outs = outs.array();
+ sl.kernels = kernels.array();
+ sl.count = kernels.size();
uint32_t inLen;
const Allocation **ains;
@@ -260,27 +254,25 @@ void CpuScriptGroupImpl::execute() {
ains = const_cast<const Allocation**>(&ins[0]);
}
- std::vector<const void *> usrPtrs;
- std::vector<const void *> fnPtrs;
- std::vector<uint32_t> sigs;
+ Vector<const void *> usrPtrs;
+ Vector<const void *> fnPtrs;
+ 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.push_back((void *)mtls.kernel);
- usrPtrs.push_back(mtls.fep.usr);
- sigs.push_back(mtls.fep.usrLen);
+ fnPtrs.add((void *)mtls.kernel);
+ usrPtrs.add(mtls.fep.usr);
+ sigs.add(mtls.fep.usrLen);
si->preLaunch(kernels[ct]->mSlot, ains, inLen, outs[ct],
mtls.fep.usr, mtls.fep.usrLen, nullptr);
}
-
- sl.sigs = &sigs.front();
- sl.usrPtrs = &usrPtrs.front();
- sl.fnPtrs = &fnPtrs.front();
-
- sl.inExts = (bool*)&inExts.front();
- sl.outExts = (bool*)&outExts.front();
+ sl.sigs = sigs.array();
+ sl.usrPtrs = usrPtrs.array();
+ sl.fnPtrs = fnPtrs.array();
+ sl.inExts = inExts.array();
+ sl.outExts = outExts.array();
Script *s = kernels[0]->mScript;
RsdCpuScriptImpl *si = (RsdCpuScriptImpl *)mCtx->lookupScript(s);
diff --git a/driver/rsdBcc.cpp b/driver/rsdBcc.cpp
index 811fa3e3..a57409d9 100644
--- a/driver/rsdBcc.cpp
+++ b/driver/rsdBcc.cpp
@@ -14,8 +14,6 @@
* limitations under the License.
*/
-#include <vector>
-
#include "../cpu_ref/rsd_cpu.h"
#include "rsdCore.h"
@@ -28,6 +26,7 @@
#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 ac1780cf..974b41d1 100644
--- a/driver/rsdMeshObj.cpp
+++ b/driver/rsdMeshObj.cpp
@@ -112,9 +112,9 @@ bool RsdMeshObj::init(const Context *rsc) {
mAttribs[userNum].type = rsdTypeToGLType(f->mHal.state.dataType);
mAttribs[userNum].normalized = f->mHal.state.dataType != RS_TYPE_FLOAT_32;
mAttribs[userNum].stride = stride;
- std::string tmp(RS_SHADER_ATTR);
+ String8 tmp(RS_SHADER_ATTR);
tmp.append(elem->mHal.state.fieldNames[fieldI]);
- mAttribs[userNum].name = tmp.c_str();
+ 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 7511883e..eaf679a5 100644
--- a/driver/rsdShader.cpp
+++ b/driver/rsdShader.cpp
@@ -41,14 +41,13 @@ RsdShader::RsdShader(const Program *p, uint32_t type,
init(textureNames, textureNamesCount, textureNamesLength);
for(size_t i=0; i < textureNamesCount; i++) {
- mTextureNames.push_back(std::string(textureNames[i],
- textureNamesLength[i]));
+ mTextureNames.push(String8(textureNames[i], textureNamesLength[i]));
}
}
RsdShader::~RsdShader() {
for (uint32_t i = 0; i < mStateBasedShaders.size(); i ++) {
- StateBasedKey *state = mStateBasedShaders[i];
+ StateBasedKey *state = mStateBasedShaders.itemAt(i);
if (state->mShaderID) {
glDeleteShader(state->mShaderID);
}
@@ -77,7 +76,7 @@ RsdShader::StateBasedKey *RsdShader::getExistingState() {
RsdShader::StateBasedKey *returnKey = nullptr;
for (uint32_t i = 0; i < mStateBasedShaders.size(); i ++) {
- returnKey = mStateBasedShaders[i];
+ returnKey = mStateBasedShaders.itemAt(i);
for (uint32_t ct = 0; ct < mRSProgram->mHal.state.texturesCount; ct ++) {
uint32_t texType = 0;
@@ -109,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.push_back(state);
+ mStateBasedShaders.add(state);
createShader();
loadShader(rsc);
return mCurrentState->mShaderID;
diff --git a/driver/rsdShader.h b/driver/rsdShader.h
index 0dc5102d..caccc099 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[index]->mShaderID;
+ return mStateBasedShaders.itemAt(index)->mShaderID;
}
uint32_t getAttribCount() const {return mAttribCount;}
@@ -116,9 +116,9 @@ protected:
std::string *mUniformNames;
uint32_t *mUniformArraySizes;
- std::vector<std::string> mTextureNames;
+ android::Vector<android::String8> mTextureNames;
- std::vector<StateBasedKey*> mStateBasedShaders;
+ android::Vector<StateBasedKey*> mStateBasedShaders;
int32_t mTextureUniformIndexStart;
@@ -133,3 +133,7 @@ protected:
};
#endif //ANDROID_RSD_SHADER_H
+
+
+
+
diff --git a/driver/rsdShaderCache.cpp b/driver/rsdShaderCache.cpp
index 608922ce..c6052e2f 100644
--- a/driver/rsdShaderCache.cpp
+++ b/driver/rsdShaderCache.cpp
@@ -29,7 +29,7 @@ using namespace android::renderscript;
RsdShaderCache::RsdShaderCache() {
- mEntries.reserve(16);
+ mEntries.setCapacity(16);
mVertexDirty = true;
mFragmentDirty = true;
}
@@ -139,7 +139,7 @@ bool RsdShaderCache::link(const Context *rsc) {
ProgramEntry *e = new ProgramEntry(vtx->getAttribCount(),
vtx->getUniformCount(),
frag->getUniformCount());
- mEntries.push_back(e);
+ mEntries.push(e);
mCurrent = e;
e->vtx = vID;
e->frag = fID;
@@ -237,7 +237,7 @@ bool RsdShaderCache::link(const Context *rsc) {
return true;
}
-int32_t RsdShaderCache::vtxAttribSlot(const std::string &attrName) const {
+int32_t RsdShaderCache::vtxAttribSlot(const String8 &attrName) const {
for (uint32_t ct=0; ct < mCurrent->vtxAttrCount; ct++) {
if (attrName == mCurrent->vtxAttrs[ct].name) {
return mCurrent->vtxAttrs[ct].slot;
@@ -247,45 +247,46 @@ int32_t RsdShaderCache::vtxAttribSlot(const std::string &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 (auto entry = mEntries.begin(); entry != mEntries.end();) {
- if ((*entry)->vtx == id) {
- glDeleteProgram((*entry)->program);
-
- delete *entry;
- entry = mEntries.erase(entry);
- } else {
- entry++;
+ 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 --;
}
}
}
}
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 (auto entry = mEntries.begin(); entry != mEntries.end();) {
- if ((*entry)->frag == id) {
- glDeleteProgram((*entry)->program);
-
- delete *entry;
- entry = mEntries.erase(entry);
- } else {
- entry++;
+ 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 --;
}
}
}
}
void RsdShaderCache::cleanupAll() {
- for (auto entry : mEntries) {
- glDeleteProgram(entry->program);
- delete entry;
+ for (uint32_t ct=0; ct < mEntries.size(); ct++) {
+ glDeleteProgram(mEntries[ct]->program);
+ free(mEntries[ct]);
}
mEntries.clear();
}
+
diff --git a/driver/rsdShaderCache.h b/driver/rsdShaderCache.h
index de195e60..29f91bb6 100644
--- a/driver/rsdShaderCache.h
+++ b/driver/rsdShaderCache.h
@@ -17,9 +17,6 @@
#ifndef ANDROID_RSD_SHADER_CACHE_H
#define ANDROID_RSD_SHADER_CACHE_H
-#include <string>
-#include <vector>
-
namespace android {
namespace renderscript {
@@ -28,7 +25,11 @@ class Context;
}
}
-#if defined(RS_SERVER) || defined(RS_COMPATIBILITY_LIB)
+
+#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
+#include <utils/String8.h>
+#include <utils/Vector.h>
+#else
#include "rsUtils.h"
#endif
class RsdShader;
@@ -58,7 +59,7 @@ public:
void cleanupAll();
- int32_t vtxAttribSlot(const std::string &attrName) const;
+ int32_t vtxAttribSlot(const android::String8 &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 +144,7 @@ protected:
UniformData *fragUniforms;
bool *fragUniformIsSTO;
};
- std::vector<ProgramEntry*> mEntries;
+ android::Vector<ProgramEntry*> mEntries;
ProgramEntry *mCurrent;
bool hasArrayUniforms(RsdShader *vtx, RsdShader *frag);
@@ -156,3 +157,7 @@ protected:
#endif //ANDROID_RSD_SHADER_CACHE_H
+
+
+
+
diff --git a/driver/rsdVertexArray.cpp b/driver/rsdVertexArray.cpp
index c18a062f..64fc3aa2 100644
--- a/driver/rsdVertexArray.cpp
+++ b/driver/rsdVertexArray.cpp
@@ -48,7 +48,7 @@ void RsdVertexArray::Attrib::clear() {
stride = 0;
ptr = nullptr;
normalized = false;
- name = "";
+ name.setTo("");
}
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 = name;
+ this->name.setTo(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.c_str(),
+ mAttribs[idx].name.string(),
mAttribs[idx].buffer,
mAttribs[idx].ptr,
mAttribs[idx].size,
@@ -135,3 +135,4 @@ void RsdVertexArrayState::init(uint32_t maxAttrs) {
mAttrsEnabled[ct] = false;
}
}
+
diff --git a/driver/rsdVertexArray.h b/driver/rsdVertexArray.h
index 1bafe3bc..975121b8 100644
--- a/driver/rsdVertexArray.h
+++ b/driver/rsdVertexArray.h
@@ -17,8 +17,6 @@
#ifndef ANDROID_RSD_VERTEX_ARRAY_H
#define ANDROID_RSD_VERTEX_ARRAY_H
-#include <string>
-
#include "rsUtils.h"
namespace android {
@@ -41,7 +39,7 @@ public:
uint32_t size;
uint32_t stride;
bool normalized;
- std::string name;
+ android::String8 name;
Attrib();
void clear();
@@ -76,3 +74,6 @@ public:
#endif //ANDROID_RSD_VERTEX_ARRAY_H
+
+
+
diff --git a/rsAllocation.cpp b/rsAllocation.cpp
index 5712a175..386d86fb 100644
--- a/rsAllocation.cpp
+++ b/rsAllocation.cpp
@@ -291,40 +291,34 @@ 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_back(p);
+ mToDirtyList.push(p);
}
void Allocation::removeProgramToDirty(const Program *p) {
- for (auto entryIter = mToDirtyList.begin(), endIter = mToDirtyList.end();
- entryIter != endIter; entryIter++) {
-
- if (p == *entryIter) {
- mToDirtyList.erase(entryIter);
+ for (size_t ct=0; ct < mToDirtyList.size(); ct++) {
+ if (mToDirtyList[ct] == p) {
+ mToDirtyList.removeAt(ct);
return;
}
}
@@ -342,8 +336,7 @@ 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 3714852b..10009575 100644
--- a/rsAllocation.h
+++ b/rsAllocation.h
@@ -200,7 +200,7 @@ public:
bool hasSameDims(const Allocation *Other) const;
protected:
- std::vector<const Program *> mToDirtyList;
+ 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 72431187..5818b661 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -762,15 +762,13 @@ void Context::finish() {
void Context::assignName(ObjectBase *obj, const char *name, uint32_t len) {
rsAssert(!obj->getName());
obj->setName(name, len);
- mNames.push_back(obj);
+ mNames.add(obj);
}
void Context::removeName(ObjectBase *obj) {
- for (auto nameIter = mNames.begin(), endIter = mNames.end();
- nameIter != endIter; nameIter++) {
-
- if (obj == *nameIter) {
- mNames.erase(nameIter);
+ for (size_t ct=0; ct < mNames.size(); ct++) {
+ if (obj == mNames[ct]) {
+ mNames.removeAt(ct);
return;
}
}
@@ -1012,3 +1010,4 @@ 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 c3fc115e..3084a9a2 100644
--- a/rsContext.h
+++ b/rsContext.h
@@ -307,7 +307,7 @@ private:
bool mHasSurface;
bool mIsContextLite;
- std::vector<ObjectBase *> mNames;
+ Vector<ObjectBase *> mNames;
uint64_t mTimers[_RS_TIMER_TOTAL];
Timers mTimerActive;
diff --git a/rsCppUtils.h b/rsCppUtils.h
index 8b490569..1f792bc1 100644
--- a/rsCppUtils.h
+++ b/rsCppUtils.h
@@ -19,6 +19,8 @@
#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
@@ -52,6 +54,96 @@
#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 {
@@ -194,3 +286,5 @@ 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 1ba005a2..2688890b 100644
--- a/rsDevice.cpp
+++ b/rsDevice.cpp
@@ -28,16 +28,14 @@ Device::~Device() {
}
void Device::addContext(Context *rsc) {
- mContexts.push_back(rsc);
+ mContexts.push(rsc);
}
void Device::removeContext(Context *rsc) {
- for (auto ctxIter = mContexts.begin(), endIter = mContexts.end();
- ctxIter != endIter; ctxIter++) {
-
- if (rsc == *ctxIter) {
- mContexts.erase(ctxIter);
- return;
+ for (size_t idx=0; idx < mContexts.size(); idx++) {
+ if (mContexts[idx] == rsc) {
+ mContexts.removeAt(idx);
+ break;
}
}
}
@@ -60,3 +58,4 @@ extern "C" void rsDeviceSetConfig(RsDevice dev, RsDeviceParam p, int32_t value)
}
rsAssert(0);
}
+
diff --git a/rsDevice.h b/rsDevice.h
index 59613367..ffb514bc 100644
--- a/rsDevice.h
+++ b/rsDevice.h
@@ -17,8 +17,6 @@
#ifndef ANDROID_RS_DEVICE_H
#define ANDROID_RS_DEVICE_H
-#include <vector>
-
#include "rsUtils.h"
// ---------------------------------------------------------------------------
@@ -38,7 +36,7 @@ public:
bool mForceSW;
protected:
- std::vector<Context *> mContexts;
+ Vector<Context *> mContexts;
};
}
diff --git a/rsElement.cpp b/rsElement.cpp
index 907e3d25..a734400f 100644
--- a/rsElement.cpp
+++ b/rsElement.cpp
@@ -42,14 +42,10 @@ void Element::operator delete(void* ptr) {
}
void Element::preDestroy() const {
- auto &elements = mRSC->mStateElement.mElements;
-
- for (auto elIter = elements.begin(), endIter = elements.end();
- elIter != endIter; elIter++) {
-
- if (this == *elIter) {
- elements.erase(elIter);
- return;
+ for (uint32_t ct = 0; ct < mRSC->mStateElement.mElements.size(); ct++) {
+ if (mRSC->mStateElement.mElements[ct] == this) {
+ mRSC->mStateElement.mElements.removeAt(ct);
+ break;
}
}
}
@@ -268,7 +264,7 @@ ObjectBaseRef<const Element> Element::createRef(Context *rsc, RsDataType dt, RsD
ObjectBase::asyncLock();
- rsc->mStateElement.mElements.push_back(e);
+ rsc->mStateElement.mElements.push(e);
ObjectBase::asyncUnlock();
return returnRef;
@@ -343,7 +339,7 @@ ObjectBaseRef<const Element> Element::createRef(Context *rsc, size_t count, cons
e->compute();
ObjectBase::asyncLock();
- rsc->mStateElement.mElements.push_back(e);
+ rsc->mStateElement.mElements.push(e);
ObjectBase::asyncUnlock();
return returnRef;
diff --git a/rsElement.h b/rsElement.h
index ccf69eb5..9374c64a 100644
--- a/rsElement.h
+++ b/rsElement.h
@@ -17,8 +17,6 @@
#ifndef ANDROID_STRUCTURED_ELEMENT_H
#define ANDROID_STRUCTURED_ELEMENT_H
-#include <vector>
-
#include "rsComponent.h"
#include "rsUtils.h"
#include "rsInternalDefines.h"
@@ -172,7 +170,7 @@ public:
~ElementState();
// Cache of all existing elements.
- std::vector<Element *> mElements;
+ Vector<Element *> mElements;
};
diff --git a/rsFileA3D.cpp b/rsFileA3D.cpp
index f85fffef..a81d0f93 100644
--- a/rsFileA3D.cpp
+++ b/rsFileA3D.cpp
@@ -87,7 +87,7 @@ void FileA3D::parseHeader(IStream *headerStream) {
entry->mLength = headerStream->loadU32();
}
entry->mRsObj = nullptr;
- mIndex.push_back(entry);
+ mIndex.push(entry);
}
}
@@ -385,7 +385,7 @@ void FileA3D::appendToFile(Context *con, ObjectBase *obj) {
indexEntry->mType = obj->getClassId();
indexEntry->mOffset = mWriteStream->getPos();
indexEntry->mRsObj = obj;
- mWriteIndex.push_back(indexEntry);
+ mWriteIndex.push(indexEntry);
obj->serialize(con, mWriteStream);
indexEntry->mLength = mWriteStream->getPos() - indexEntry->mOffset;
mWriteStream->align(4);
diff --git a/rsFileA3D.h b/rsFileA3D.h
index 0c8b3d67..8bf36b97 100644
--- a/rsFileA3D.h
+++ b/rsFileA3D.h
@@ -88,13 +88,15 @@ protected:
Asset *mAsset;
OStream *mWriteStream;
- std::vector<A3DIndexEntry*> mWriteIndex;
+ Vector<A3DIndexEntry*> mWriteIndex;
IStream *mReadStream;
- std::vector<A3DIndexEntry*> mIndex;
+ Vector<A3DIndexEntry*> mIndex;
};
}
}
#endif //ANDROID_RS_FILE_A3D_H
+
+
diff --git a/rsFont.cpp b/rsFont.cpp
index 8f39ca9e..8b38fdee 100644
--- a/rsFont.cpp
+++ b/rsFont.cpp
@@ -33,7 +33,7 @@
using namespace android;
using namespace android::renderscript;
-Font::Font(Context *rsc) : ObjectBase(rsc) {
+Font::Font(Context *rsc) : ObjectBase(rsc), mCachedGlyphs(NULL) {
mInitialized = false;
mHasKerning = false;
mFace = nullptr;
@@ -76,21 +76,17 @@ bool Font::init(const char *name, float fontSize, uint32_t dpi, const void *data
}
void Font::preDestroy() const {
- auto &activeFonts = mRSC->mStateFont.mActiveFonts;
-
- for (auto font = activeFonts.begin(), end = activeFonts.end(); font != end;
- font++) {
-
- if (this == *font) {
- activeFonts.erase(font);
- return;
+ for (uint32_t ct = 0; ct < mRSC->mStateFont.mActiveFonts.size(); ct++) {
+ if (mRSC->mStateFont.mActiveFonts[ct] == this) {
+ mRSC->mStateFont.mActiveFonts.removeAt(ct);
+ break;
}
}
}
void Font::invalidateTextureCache() {
for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) {
- mCachedGlyphs[i]->mIsValid = false;
+ mCachedGlyphs.valueAt(i)->mIsValid = false;
}
}
@@ -228,7 +224,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[(uint32_t)utfChar];
+ CachedGlyphInfo *cachedGlyph = mCachedGlyphs.valueFor((uint32_t)utfChar);
if (cachedGlyph == nullptr) {
cachedGlyph = cacheGlyph((uint32_t)utfChar);
}
@@ -287,7 +283,7 @@ void Font::updateGlyphCache(CachedGlyphInfo *glyph) {
Font::CachedGlyphInfo *Font::cacheGlyph(uint32_t glyph) {
CachedGlyphInfo *newGlyph = new CachedGlyphInfo();
- mCachedGlyphs[glyph] = newGlyph;
+ mCachedGlyphs.add(glyph, newGlyph);
#ifndef ANDROID_RS_SERIALIZE
newGlyph->mGlyphIndex = FT_Get_Char_Index(mFace, glyph);
newGlyph->mIsValid = false;
@@ -300,14 +296,11 @@ 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();
- std::vector<Font*> &activeFonts = rsc->mStateFont.mActiveFonts;
+ 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;
}
}
@@ -315,7 +308,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_back(newFont);
+ activeFonts.push(newFont);
rsc->mStateFont.precacheLatin(newFont);
return newFont;
}
@@ -332,7 +325,7 @@ Font::~Font() {
#endif
for (uint32_t i = 0; i < mCachedGlyphs.size(); i ++) {
- CachedGlyphInfo *glyph = mCachedGlyphs[i];
+ CachedGlyphInfo *glyph = mCachedGlyphs.valueAt(i);
delete glyph;
}
}
@@ -561,33 +554,25 @@ void FontState::initTextTexture() {
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_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));
+ 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));
}
// Avoid having to reallocate memory and render quad by quad
diff --git a/rsFont.h b/rsFont.h
index bc343c19..0f173408 100644
--- a/rsFont.h
+++ b/rsFont.h
@@ -17,10 +17,9 @@
#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_;
@@ -125,7 +124,7 @@ protected:
bool mInitialized;
bool mHasKerning;
- std::map<uint32_t, CachedGlyphInfo* > mCachedGlyphs;
+ DefaultKeyedVector<uint32_t, CachedGlyphInfo* > mCachedGlyphs;
CachedGlyphInfo* getCachedUTFChar(int32_t utfChar);
CachedGlyphInfo *cacheGlyph(uint32_t glyph);
@@ -179,7 +178,7 @@ protected:
bool fitBitmap(FT_Bitmap_ *bitmap, uint32_t *retOriginX, uint32_t *retOriginY);
};
- std::vector<CacheTextureLine*> mCacheLines;
+ Vector<CacheTextureLine*> mCacheLines;
uint32_t getRemainingCacheCapacity();
void precacheLatin(Font *font);
@@ -204,7 +203,7 @@ protected:
FT_LibraryRec_ *mLibrary;
FT_LibraryRec_ *getLib();
#endif //ANDROID_RS_SERIALIZE
- std::vector<Font*> mActiveFonts;
+ Vector<Font*> mActiveFonts;
// Render state for the font
ObjectBaseRef<Allocation> mFontShaderFConstant;
diff --git a/rsGrallocConsumer.h b/rsGrallocConsumer.h
index 527e734a..3ffee28d 100644
--- a/rsGrallocConsumer.h
+++ b/rsGrallocConsumer.h
@@ -17,12 +17,12 @@
#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,3 +75,4 @@ class GrallocConsumer : public ConsumerBase
} // namespace android
#endif // ANDROID_RS_GRALLOC_CONSUMER_H
+
diff --git a/rsProgramFragment.h b/rsProgramFragment.h
index 1357bfcf..e7456b91 100644
--- a/rsProgramFragment.h
+++ b/rsProgramFragment.h
@@ -55,7 +55,7 @@ public:
void deinit(Context *rsc);
ObjectBaseRef<ProgramFragment> mDefault;
- std::vector<ProgramFragment *> mPrograms;
+ Vector<ProgramFragment *> mPrograms;
ObjectBaseRef<ProgramFragment> mLast;
};
@@ -63,3 +63,7 @@ public:
}
}
#endif
+
+
+
+
diff --git a/rsProgramRaster.cpp b/rsProgramRaster.cpp
index d47e588d..c9a24bf6 100644
--- a/rsProgramRaster.cpp
+++ b/rsProgramRaster.cpp
@@ -31,14 +31,10 @@ ProgramRaster::ProgramRaster(Context *rsc, bool pointSprite, RsCullMode cull)
}
void ProgramRaster::preDestroy() const {
- auto &rasters = mRSC->mStateRaster.mRasterPrograms;
-
- for (auto prIter = rasters.begin(), endIter = rasters.end();
- prIter != endIter; prIter++) {
-
- if (this == *prIter) {
- rasters.erase(prIter);
- return;
+ for (uint32_t ct = 0; ct < mRSC->mStateRaster.mRasterPrograms.size(); ct++) {
+ if (mRSC->mStateRaster.mRasterPrograms[ct] == this) {
+ mRSC->mStateRaster.mRasterPrograms.removeAt(ct);
+ break;
}
}
}
@@ -98,7 +94,7 @@ ObjectBaseRef<ProgramRaster> ProgramRaster::getProgramRaster(Context *rsc,
returnRef.set(pr);
ObjectBase::asyncLock();
- rsc->mStateRaster.mRasterPrograms.push_back(pr);
+ rsc->mStateRaster.mRasterPrograms.push(pr);
ObjectBase::asyncUnlock();
return returnRef;
@@ -115,3 +111,4 @@ RsProgramRaster rsi_ProgramRasterCreate(Context * rsc, bool pointSprite, RsCullM
}
}
+
diff --git a/rsProgramRaster.h b/rsProgramRaster.h
index 207d74ca..e9a524b9 100644
--- a/rsProgramRaster.h
+++ b/rsProgramRaster.h
@@ -75,10 +75,14 @@ public:
ObjectBaseRef<ProgramRaster> mLast;
// Cache of all existing raster programs.
- std::vector<ProgramRaster *> mRasterPrograms;
+ Vector<ProgramRaster *> mRasterPrograms;
};
}
}
#endif
+
+
+
+
diff --git a/rsProgramStore.cpp b/rsProgramStore.cpp
index b07f820e..3ee75cc3 100644
--- a/rsProgramStore.cpp
+++ b/rsProgramStore.cpp
@@ -42,14 +42,10 @@ ProgramStore::ProgramStore(Context *rsc,
}
void ProgramStore::preDestroy() const {
- auto &stores = mRSC->mStateFragmentStore.mStorePrograms;
-
- for (auto psIter = stores.begin(), endIter = stores.end();
- psIter != endIter; psIter++) {
-
- if (this == *psIter) {
- stores.erase(psIter);
- return;
+ for (uint32_t ct = 0; ct < mRSC->mStateFragmentStore.mStorePrograms.size(); ct++) {
+ if (mRSC->mStateFragmentStore.mStorePrograms[ct] == this) {
+ mRSC->mStateFragmentStore.mStorePrograms.removeAt(ct);
+ break;
}
}
}
@@ -122,7 +118,7 @@ ObjectBaseRef<ProgramStore> ProgramStore::getProgramStore(Context *rsc,
pfs->init();
ObjectBase::asyncLock();
- rsc->mStateFragmentStore.mStorePrograms.push_back(pfs);
+ rsc->mStateFragmentStore.mStorePrograms.push(pfs);
ObjectBase::asyncUnlock();
return returnRef;
diff --git a/rsProgramStore.h b/rsProgramStore.h
index 06824fe5..9a7f7f17 100644
--- a/rsProgramStore.h
+++ b/rsProgramStore.h
@@ -92,9 +92,12 @@ public:
ObjectBaseRef<ProgramStore> mLast;
// Cache of all existing store programs.
- std::vector<ProgramStore *> mStorePrograms;
+ Vector<ProgramStore *> mStorePrograms;
};
}
}
#endif
+
+
+
diff --git a/rsSampler.cpp b/rsSampler.cpp
index 924ba860..858658dc 100644
--- a/rsSampler.cpp
+++ b/rsSampler.cpp
@@ -49,14 +49,10 @@ Sampler::~Sampler() {
}
void Sampler::preDestroy() const {
- auto &samplers = mRSC->mStateSampler.mAllSamplers;
-
- for (auto sampleIter = samplers.begin(), endIter = samplers.end();
- sampleIter != endIter; sampleIter++) {
-
- if (this == *sampleIter) {
- samplers.erase(sampleIter);
- return;
+ for (uint32_t ct = 0; ct < mRSC->mStateSampler.mAllSamplers.size(); ct++) {
+ if (mRSC->mStateSampler.mAllSamplers[ct] == this) {
+ mRSC->mStateSampler.mAllSamplers.removeAt(ct);
+ break;
}
}
}
@@ -117,7 +113,7 @@ ObjectBaseRef<Sampler> Sampler::getSampler(Context *rsc,
#endif
ObjectBase::asyncLock();
- rsc->mStateSampler.mAllSamplers.push_back(s);
+ rsc->mStateSampler.mAllSamplers.push(s);
ObjectBase::asyncUnlock();
return returnRef;
diff --git a/rsSampler.h b/rsSampler.h
index 3f5855f8..2fdf7073 100644
--- a/rsSampler.h
+++ b/rsSampler.h
@@ -96,9 +96,12 @@ public:
}
}
// Cache of all existing raster programs.
- std::vector<Sampler *> mAllSamplers;
+ Vector<Sampler *> mAllSamplers;
};
}
}
#endif //ANDROID_RS_SAMPLER_H
+
+
+
diff --git a/rsScriptC.cpp b/rsScriptC.cpp
index 71761f1c..4b204d38 100644
--- a/rsScriptC.cpp
+++ b/rsScriptC.cpp
@@ -14,8 +14,6 @@
* limitations under the License.
*/
-#include <string>
-
#include "rsContext.h"
#include "rsScriptC.h"
@@ -31,6 +29,8 @@
#include <sys/stat.h>
+#include <string>
+
#ifdef USE_MINGW
/* Define the default path separator for the platform. */
#define OS_PATH_SEPARATOR '\\'
@@ -195,14 +195,15 @@ void ScriptC::runForEach(Context *rsc,
// Trace this function call.
// To avoid overhead we only build the string if tracing is actually
// enabled.
- std::string *traceString = nullptr;
- const char *stringData = "";
+ String8 *AString = NULL;
+ const char *String = "";
if (ATRACE_ENABLED()) {
- traceString = new std::string("runForEach_");
- traceString->append(mHal.info.exportedForeachFuncList[slot].first);
- stringData = traceString->c_str();
+ AString = new String8("runForEach_");
+ AString->append(mHal.info.exportedForeachFuncList[slot].first);
+ String = AString->string();
}
- ATRACE_NAME(stringData);
+ ATRACE_NAME(String);
+ (void)String;
Context::PushState ps(rsc);
@@ -222,8 +223,8 @@ void ScriptC::runForEach(Context *rsc,
"Driver support for multi-input not present");
}
- if (traceString) {
- delete traceString;
+ if (AString) {
+ delete AString;
}
}
diff --git a/rsScriptGroup.cpp b/rsScriptGroup.cpp
index d4a6cd1d..26ab6a8d 100644
--- a/rsScriptGroup.cpp
+++ b/rsScriptGroup.cpp
@@ -17,6 +17,7 @@
#include "rsScriptGroup.h"
#include "rsContext.h"
+// TODO: Is this header needed here?
#include "rsScriptGroup2.h"
#include <algorithm>
@@ -33,8 +34,8 @@ ScriptGroup::~ScriptGroup() {
mRSC->mHal.funcs.scriptgroup.destroy(mRSC, this);
}
- for (auto link : mLinks) {
- delete link;
+ for (size_t ct=0; ct < mLinks.size(); ct++) {
+ delete mLinks[ct];
}
for (auto input : mInputs) {
@@ -57,10 +58,12 @@ ScriptGroup::Node::Node(Script *s) {
}
ScriptGroup::Node * ScriptGroup::findNode(Script *s) const {
- for (auto node : mNodes) {
- for (auto kernelRef : node->mKernels) {
- if (kernelRef->mScript == s) {
- return node;
+ //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;
}
}
}
@@ -68,105 +71,138 @@ ScriptGroup::Node * ScriptGroup::findNode(Script *s) const {
return nullptr;
}
-bool ScriptGroup::calcOrderRecurse(Node *node0, int depth) {
- node0->mSeen = true;
- if (node0->mOrder < depth) {
- node0->mOrder = depth;
+bool ScriptGroup::calcOrderRecurse(Node *n, int depth) {
+ n->mSeen = true;
+ if (n->mOrder < depth) {
+ n->mOrder = depth;
}
bool ret = true;
- for (auto link : node0->mOutputs) {
- Node *node1 = nullptr;
- if (link->mDstField.get()) {
- node1 = findNode(link->mDstField->mScript);
+ 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);
} else {
- node1 = findNode(link->mDstKernel->mScript);
+ nt = findNode(l->mDstKernel->mScript);
}
- if (node1->mSeen) {
+ if (nt->mSeen) {
return false;
}
- ret &= calcOrderRecurse(node1, node0->mOrder + 1);
+ ret &= calcOrderRecurse(nt, n->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;
+}
+#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 (auto kernelRef : mKernels) {
- const ScriptKernelID *kernel = kernelRef.get();
- Node *node = findNode(kernel->mScript);
- if (node == nullptr) {
- node = new Node(kernel->mScript);
- mNodes.push_back(node);
+ 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);
}
- node->mKernels.push_back(kernel);
+ n->mKernels.add(k);
}
// add links
- 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);
+ //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);
} else {
- node = findNode(link->mDstField->mScript);
- node->mInputs.push_back(link);
+ n = findNode(l->mDstField->mScript);
+ //ALOGE(" n2 %p", n);
+ n->mInputs.add(l);
}
}
+ //ALOGE("node count %i", (int)mNodes.size());
// Order nodes
bool ret = true;
- for (auto n0 : mNodes) {
- if (n0->mInputs.size() == 0) {
- for (auto n1 : mNodes) {
- n1->mSeen = false;
+ 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;
}
- ret &= calcOrderRecurse(n0, 1);
+ ret &= calcOrderRecurse(n, 0);
}
}
- for (auto kernelRef : mKernels) {
- const ScriptKernelID *kernel = kernelRef.get();
- const Node *node = findNode(kernel->mScript);
+ for (size_t ct=0; ct < mKernels.size(); ct++) {
+ const ScriptKernelID *k = mKernels[ct].get();
+ const Node *n = findNode(k->mScript);
- if (kernel->mHasKernelOutput) {
+ if (k->mHasKernelOutput) {
bool found = false;
- for (auto output : node->mOutputs) {
- if (output->mSource.get() == kernel) {
+ for (size_t ct2=0; ct2 < n->mOutputs.size(); ct2++) {
+ if (n->mOutputs[ct2]->mSource.get() == k) {
found = true;
break;
}
}
-
if (!found) {
- mOutputs.push_back(new IO(kernel));
+ //ALOGE("add io out %p", k);
+ mOutputs.add(new IO(k));
}
}
- if (kernel->mHasKernelInput) {
+ if (k->mHasKernelInput) {
bool found = false;
- for (auto input : node->mInputs) {
- if (input->mDstKernel.get() == kernel) {
+ for (size_t ct2=0; ct2 < n->mInputs.size(); ct2++) {
+ if (n->mInputs[ct2]->mDstKernel.get() == k) {
found = true;
break;
}
}
if (!found) {
- mInputs.push_back(new IO(kernel));
+ //ALOGE("add io in %p", k);
+ mInputs.add(new IO(k));
}
}
}
// sort
- std::stable_sort(mNodes.begin(), mNodes.end(),
- [](const ScriptGroup::Node* lhs,
- const ScriptGroup::Node* rhs) {
- return lhs->mOrder < rhs->mOrder;
- });
+#if !defined(RS_SERVER) && !defined(RS_COMPATIBILITY_LIB)
+ mNodes.sort(&CompareNodeForSort);
+#else
+ std::sort(mNodes.begin(), mNodes.end(), NodeCompare());
+#endif
return ret;
}
@@ -190,7 +226,7 @@ ScriptGroup * ScriptGroup::create(Context *rsc,
sg->mKernels.reserve(kernelCount);
for (size_t ct=0; ct < kernelCount; ct++) {
- sg->mKernels.push_back(kernels[ct]);
+ sg->mKernels.add(kernels[ct]);
}
sg->mLinks.reserve(linkCount);
@@ -200,7 +236,7 @@ ScriptGroup * ScriptGroup::create(Context *rsc,
l->mSource = src[ct];
l->mDstField = dstF[ct];
l->mDstKernel = dstK[ct];
- sg->mLinks.push_back(l);
+ sg->mLinks.add(l);
}
sg->calcOrder();
@@ -235,9 +271,9 @@ ScriptGroup * ScriptGroup::create(Context *rsc,
}
void ScriptGroup::setInput(Context *rsc, ScriptKernelID *kid, Allocation *a) {
- for (auto input : mInputs) {
- if (input->mKernel == kid) {
- input->mAlloc = a;
+ for (size_t ct=0; ct < mInputs.size(); ct++) {
+ if (mInputs[ct]->mKernel == kid) {
+ mInputs[ct]->mAlloc = a;
if (rsc->mHal.funcs.scriptgroup.setInput) {
rsc->mHal.funcs.scriptgroup.setInput(rsc, this, kid, a);
@@ -249,9 +285,9 @@ void ScriptGroup::setInput(Context *rsc, ScriptKernelID *kid, Allocation *a) {
}
void ScriptGroup::setOutput(Context *rsc, ScriptKernelID *kid, Allocation *a) {
- for (auto output : mOutputs) {
- if (output->mKernel == kid) {
- output->mAlloc = a;
+ for (size_t ct=0; ct < mOutputs.size(); ct++) {
+ if (mOutputs[ct]->mKernel == kid) {
+ mOutputs[ct]->mAlloc = a;
if (rsc->mHal.funcs.scriptgroup.setOutput) {
rsc->mHal.funcs.scriptgroup.setOutput(rsc, this, kid, a);
@@ -290,45 +326,52 @@ void ScriptGroup::execute(Context *rsc) {
return;
}
- for (auto node : mNodes) {
- for (auto kernel : node->mKernels) {
- Allocation *ain = nullptr;
- Allocation *aout = nullptr;
+ 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 (auto nodeInput : node->mInputs) {
- if (nodeInput->mDstKernel.get() == kernel) {
- ain = nodeInput->mAlloc.get();
+ for (size_t ct2=0; ct2 < n->mKernels.size(); ct2++) {
+ const ScriptKernelID *k = n->mKernels[ct2];
+ 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 sgInput : mInputs) {
- if (sgInput->mKernel == kernel) {
- ain = sgInput->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 nodeOutput : node->mOutputs) {
- if (nodeOutput->mSource.get() == kernel) {
- aout = nodeOutput->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 sgOutput : mOutputs) {
- if (sgOutput->mKernel == kernel) {
- aout = sgOutput->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);
}
}
- if (ain == nullptr) {
- node->mScript->runForEach(rsc, kernel->mSlot, nullptr, 0, aout,
- nullptr, 0);
+ if (ain == NULL) {
+ n->mScript->runForEach(rsc, k->mSlot, NULL, 0, aout, NULL, 0);
+
} else {
const Allocation *ains[1] = {ain};
- node->mScript->runForEach(rsc, kernel->mSlot, ains,
- sizeof(ains) / sizeof(RsAllocation),
- aout, nullptr, 0);
+ n->mScript->runForEach(rsc, k->mSlot, ains,
+ sizeof(ains) / sizeof(RsAllocation),
+ aout, NULL, 0);
}
}
+
}
}
@@ -362,12 +405,14 @@ 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);
}
diff --git a/rsScriptGroup.h b/rsScriptGroup.h
index ff0259a4..68783f39 100644
--- a/rsScriptGroup.h
+++ b/rsScriptGroup.h
@@ -41,7 +41,7 @@ public:
virtual SG_API_Version getApiVersion() const { return SG_V1; }
virtual void execute(Context *rsc);
- std::vector<ObjectBaseRef<ScriptKernelID> > mKernels;
+ Vector<ObjectBaseRef<ScriptKernelID> > mKernels;
class Link {
public:
@@ -58,9 +58,9 @@ public:
public:
Node(Script *);
- std::vector<const ScriptKernelID *> mKernels;
- std::vector<Link *> mOutputs;
- std::vector<Link *> mInputs;
+ Vector<const ScriptKernelID *> mKernels;
+ Vector<Link *> mOutputs;
+ Vector<Link *> mInputs;
bool mSeen;
int mOrder;
Script *mScript;
@@ -74,10 +74,10 @@ public:
ObjectBaseRef<Allocation> mAlloc;
};
- std::vector<Link *> mLinks;
- std::vector<Node *> mNodes;
- std::vector<IO *> mInputs;
- std::vector<IO *> mOutputs;
+ Vector<Link *> mLinks;
+ Vector<Node *> mNodes;
+ Vector<IO *> mInputs;
+ Vector<IO *> mOutputs;
static ScriptGroup * create(Context *rsc,
ScriptKernelID ** kernels, size_t kernelsSize,
@@ -110,3 +110,4 @@ private:
}
}
#endif
+
diff --git a/rsType.cpp b/rsType.cpp
index 39c91cdc..d45de2de 100644
--- a/rsType.cpp
+++ b/rsType.cpp
@@ -33,14 +33,10 @@ Type::Type(Context *rsc) : ObjectBase(rsc) {
}
void Type::preDestroy() const {
- auto &types = mRSC->mStateType.mTypes;
-
- for (auto typeIter = types.begin(), endIter = types.end();
- typeIter != endIter; typeIter++) {
-
- if (this == *typeIter) {
- types.erase(typeIter);
- return;
+ for (uint32_t ct = 0; ct < mRSC->mStateType.mTypes.size(); ct++) {
+ if (mRSC->mStateType.mTypes[ct] == this) {
+ mRSC->mStateType.mTypes.removeAt(ct);
+ break;
}
}
}
@@ -291,7 +287,7 @@ ObjectBaseRef<Type> Type::getTypeRef(Context *rsc, const Element *e,
nt->compute();
ObjectBase::asyncLock();
- stc->mTypes.push_back(nt);
+ stc->mTypes.push(nt);
ObjectBase::asyncUnlock();
return returnRef;
diff --git a/rsType.h b/rsType.h
index 445f4ff1..6ae84466 100644
--- a/rsType.h
+++ b/rsType.h
@@ -161,7 +161,7 @@ public:
~TypeState();
// Cache of all existing types.
- std::vector<Type *> mTypes;
+ Vector<Type *> mTypes;
};