summaryrefslogtreecommitdiffstats
path: root/rsClosure.cpp
diff options
context:
space:
mode:
authorYang Ni <yangni@google.com>2015-02-02 14:33:47 -0800
committerYang Ni <yangni@google.com>2015-02-10 17:14:21 +0000
commitff2bb54ebf593b1d19d3a2e4cfa70a8ea4432c0d (patch)
tree16e55dabfc72c3a1428e1b5e748f9fc1436e9be4 /rsClosure.cpp
parent841ba73b843babb8ca0117e9801b6db6ba6cd394 (diff)
downloadandroid_frameworks_rs-ff2bb54ebf593b1d19d3a2e4cfa70a8ea4432c0d.tar.gz
android_frameworks_rs-ff2bb54ebf593b1d19d3a2e4cfa70a8ea4432c0d.tar.bz2
android_frameworks_rs-ff2bb54ebf593b1d19d3a2e4cfa70a8ea4432c0d.zip
Reformat and remove STL reference from header
b/19148482 Reformmated according to Android C++ style guidelines. Removed STL references in headers. Change-Id: I6d82b8fe5ac868067b6d9ebe797125feb97e5641
Diffstat (limited to 'rsClosure.cpp')
-rw-r--r--rsClosure.cpp122
1 files changed, 60 insertions, 62 deletions
diff --git a/rsClosure.cpp b/rsClosure.cpp
index 7aa0acbf..ece92d5a 100644
--- a/rsClosure.cpp
+++ b/rsClosure.cpp
@@ -16,15 +16,15 @@ RsClosure rsi_ClosureCreate(Context* context, RsScriptKernelID kernelID,
RsClosure* depClosures, size_t depClosures_length,
RsScriptFieldID* depFieldIDs,
size_t depFieldIDs_length) {
- rsAssert(fieldIDs_length == values_length && values_length == sizes_length &&
- sizes_length == depClosures_length &&
- depClosures_length == depFieldIDs_length);
-
- return (RsClosure)(new Closure(
- context, (const ScriptKernelID*)kernelID, (Allocation*)returnValue,
- fieldIDs_length, (const ScriptFieldID**)fieldIDs, (const void**)values,
- sizes, (const Closure**)depClosures,
- (const ScriptFieldID**)depFieldIDs));
+ rsAssert(fieldIDs_length == values_length && values_length == sizes_length &&
+ sizes_length == depClosures_length &&
+ depClosures_length == depFieldIDs_length);
+
+ return (RsClosure)(new Closure(
+ context, (const ScriptKernelID*)kernelID, (Allocation*)returnValue,
+ fieldIDs_length, (const ScriptFieldID**)fieldIDs, (const void**)values,
+ sizes, (const Closure**)depClosures,
+ (const ScriptFieldID**)depFieldIDs));
}
RsClosure rsi_InvokeClosureCreate(Context* context, RsScriptInvokeID invokeID,
@@ -39,9 +39,11 @@ RsClosure rsi_InvokeClosureCreate(Context* context, RsScriptInvokeID invokeID,
sizes));
}
+#if 0
void rsi_ClosureEval(Context* rsc, RsClosure closure) {
((Closure*)closure)->eval();
}
+#endif
void rsi_ClosureSetArg(Context* rsc, RsClosure closure, uint32_t index,
uintptr_t value, size_t size) {
@@ -67,47 +69,59 @@ Closure::Closure(Context* context,
ObjectBase(context), mContext(context), mKernelID((ScriptKernelID*)kernelID),
mInvokeID(nullptr), mReturnValue(returnValue), mParams(nullptr),
mParamLength(0) {
- size_t i;
+ size_t i;
- for (i = 0; i < (size_t)numValues && fieldIDs[i] == nullptr; i++);
+ for (i = 0; i < (size_t)numValues && fieldIDs[i] == nullptr; i++);
- vector<const void*> args(values, values + i);
- mArgs.swap(args);
+ mNumArg = i;
+ mArgs = new const void*[mNumArg];
+ memcpy(mArgs, values, sizeof(const void*) * mNumArg);
- for (; i < (size_t)numValues; i++) {
- mGlobals[fieldIDs[i]] = std::make_pair(values[i], sizes[i]);
- }
+ for (; i < (size_t)numValues; i++) {
+ rsAssert(fieldIDs[i] != nullptr);
+ mGlobals[fieldIDs[i]] = make_pair(values[i], sizes[i]);
+ ALOGV("Creating closure %p, binding field %p (Script %p, slot: %d)",
+ this, fieldIDs[i], fieldIDs[i]->mScript, fieldIDs[i]->mSlot);
+ }
- mDependences.insert(depClosures, depClosures + numValues);
+ size_t j = mNumArg;
+ for (const auto& p : mGlobals) {
+ rsAssert(p.first == fieldIDs[j]);
+ rsAssert(p.second.first == values[j]);
+ rsAssert(p.second.second == sizes[j]);
+ j++;
+ }
- for (i = 0; i < mArgs.size(); i++) {
- const Closure* dep = depClosures[i];
- if (dep != nullptr) {
- auto mapping = mArgDeps[dep];
- if (mapping == nullptr) {
- mapping = new map<int, const ObjectBaseRef<ScriptFieldID>*>();
- mArgDeps[dep] = mapping;
- }
- (*mapping)[i] = new ObjectBaseRef<ScriptFieldID>(
- const_cast<ScriptFieldID*>(depFieldIDs[i]));
+ // mDependences.insert(depClosures, depClosures + numValues);
+
+ for (i = 0; i < mNumArg; i++) {
+ const Closure* dep = depClosures[i];
+ if (dep != nullptr) {
+ auto mapping = mArgDeps[dep];
+ if (mapping == nullptr) {
+ mapping = new Map<int, const ObjectBaseRef<ScriptFieldID>*>();
+ mArgDeps[dep] = mapping;
+ }
+ (*mapping)[i] = new ObjectBaseRef<ScriptFieldID>(
+ const_cast<ScriptFieldID*>(depFieldIDs[i]));
+ }
}
- }
-
- for (; i < (size_t)numValues; i++) {
- const Closure* dep = depClosures[i];
- if (dep != nullptr) {
- auto mapping = mGlobalDeps[dep];
- if (mapping == nullptr) {
- mapping = new map<const ObjectBaseRef<ScriptFieldID>*,
- const ObjectBaseRef<ScriptFieldID>*>();
- mGlobalDeps[dep] = mapping;
- }
- (*mapping)[new ObjectBaseRef<ScriptFieldID>(
- const_cast<ScriptFieldID*>(fieldIDs[i]))] =
- new ObjectBaseRef<ScriptFieldID>(
- const_cast<ScriptFieldID*>(depFieldIDs[i]));
+
+ for (; i < (size_t)numValues; i++) {
+ const Closure* dep = depClosures[i];
+ if (dep != nullptr) {
+ auto mapping = mGlobalDeps[dep];
+ if (mapping == nullptr) {
+ mapping = new Map<const ObjectBaseRef<ScriptFieldID>*,
+ const ObjectBaseRef<ScriptFieldID>*>();
+ mGlobalDeps[dep] = mapping;
+ }
+ (*mapping)[new ObjectBaseRef<ScriptFieldID>(
+ const_cast<ScriptFieldID*>(fieldIDs[i]))] =
+ new ObjectBaseRef<ScriptFieldID>(
+ const_cast<ScriptFieldID*>(depFieldIDs[i]));
+ }
}
- }
}
Closure::Closure(Context* context, const ScriptInvokeID* invokeID,
@@ -117,7 +131,7 @@ Closure::Closure(Context* context, const ScriptInvokeID* invokeID,
ObjectBase(context), mContext(context), mKernelID(nullptr), mInvokeID(invokeID),
mReturnValue(nullptr), mParams(params), mParamLength(paramLength) {
for (size_t i = 0; i < numValues; i++) {
- mGlobals[fieldIDs[i]] = std::make_pair(values[i], sizes[i]);
+ mGlobals[fieldIDs[i]] = make_pair(values[i], sizes[i]);
}
}
@@ -138,24 +152,8 @@ Closure::~Closure() {
}
delete p.second;
}
-}
-
-void Closure::eval() {
- Script *s = mKernelID->mScript;
-
- for (const auto& p : mGlobals) {
- const void* value = p.second.first;
- int size = p.second.second;
- // We use -1 size to indicate an ObjectBase rather than a primitive type
- if (size < 0) {
- s->setVarObj(p.first->mSlot, (ObjectBase*)value);
- } else {
- s->setVar(p.first->mSlot, (const void*)&value, size);
- }
- }
- s->runForEach(mContext, mKernelID->mSlot, (const Allocation **)(&mArgs[0]),
- mArgs.size(), mReturnValue, nullptr, 0, nullptr);
+ delete[] mArgs;
}
void Closure::setArg(const uint32_t index, const void* value, const size_t size) {
@@ -164,7 +162,7 @@ void Closure::setArg(const uint32_t index, const void* value, const size_t size)
void Closure::setGlobal(const ScriptFieldID* fieldID, const void* value,
const size_t size) {
- mGlobals[fieldID] = std::make_pair(value, size);
+ mGlobals[fieldID] = make_pair(value, size);
}
} // namespace renderscript