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
diff --git a/rsScriptGroup.cpp b/rsScriptGroup.cpp
index d4a6cd1..26ab6a8 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 @@
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 * 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 @@
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);
+ //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 (link->mDstKernel.get()) {
- node = findNode(link->mDstKernel->mScript);
- node->mInputs.push_back(link);
+ 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 @@
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 @@
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 @@
}
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::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 @@
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 (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 (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 nodeOutput : node->mOutputs) {
- if (nodeOutput->mSource.get() == kernel) {
- aout = nodeOutput->mAlloc.get();
- }
- }
+ if (ain == NULL) {
+ n->mScript->runForEach(rsc, k->mSlot, NULL, 0, aout, NULL, 0);
- for (auto sgOutput : mOutputs) {
- if (sgOutput->mKernel == kernel) {
- aout = sgOutput->mAlloc.get();
- }
- }
-
- if (ain == nullptr) {
- node->mScript->runForEach(rsc, kernel->mSlot, nullptr, 0, aout,
- nullptr, 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 @@
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);
}