diff options
author | Yang Ni <yangni@google.com> | 2015-01-23 17:16:02 -0800 |
---|---|---|
committer | Yang Ni <yangni@google.com> | 2015-02-04 16:24:48 -0800 |
commit | be392ad35e29b17ed54fdbbbb8dd3e80fc1022b9 (patch) | |
tree | 6737ba3025bb6113bb117099164ea8fcc5cce3fa /rs/java/android/renderscript/ScriptGroup2.java | |
parent | 240e8743977d1a1e7a43ff42e0d52148db10cda8 (diff) |
Adds invocable functions to ScriptGroup
This also includes InvokeID support
Change-Id: I5b59df166ea30b309b8dd9623825ac0e72d03856
Diffstat (limited to 'rs/java/android/renderscript/ScriptGroup2.java')
-rw-r--r-- | rs/java/android/renderscript/ScriptGroup2.java | 58 |
1 files changed, 57 insertions, 1 deletions
diff --git a/rs/java/android/renderscript/ScriptGroup2.java b/rs/java/android/renderscript/ScriptGroup2.java index 366039e3342a..113b89616d8d 100644 --- a/rs/java/android/renderscript/ScriptGroup2.java +++ b/rs/java/android/renderscript/ScriptGroup2.java @@ -34,6 +34,8 @@ public class ScriptGroup2 extends BaseObj { private Future mReturnFuture; private Map<Script.FieldID, Future> mGlobalFuture; + private FieldPacker mFP; + private static final String TAG = "Closure"; public Closure(long id, RenderScript rs) { @@ -89,6 +91,44 @@ public class ScriptGroup2 extends BaseObj { setID(id); } + public Closure(RenderScript rs, Script.InvokeID invokeID, + Object[] args, Map<Script.FieldID, Object> globals) { + super(0, rs); + mFP = FieldPacker.createFieldPack(args); + + mBindings = new HashMap<Script.FieldID, Object>(); + mGlobalFuture = new HashMap<Script.FieldID, Future>(); + + int numValues = globals.size(); + + long[] fieldIDs = new long[numValues]; + long[] values = new long[numValues]; + int[] sizes = new int[numValues]; + long[] depClosures = new long[numValues]; + long[] depFieldIDs = new long[numValues]; + + int i = 0; + for (Map.Entry<Script.FieldID, Object> entry : globals.entrySet()) { + Object obj = entry.getValue(); + Script.FieldID fieldID = entry.getKey(); + fieldIDs[i] = fieldID.getID(rs); + if (obj instanceof UnboundValue) { + UnboundValue unbound = (UnboundValue)obj; + unbound.addReference(this, fieldID); + } else { + // TODO(yangni): Verify obj not a future. + retrieveValueAndDependenceInfo(rs, i, obj, values, + sizes, depClosures, depFieldIDs); + } + i++; + } + + long id = rs.nInvokeClosureCreate(invokeID.getID(rs), mFP.getData(), fieldIDs, + values, sizes); + + setID(id); + } + private static void retrieveValueAndDependenceInfo(RenderScript rs, int index, Object obj, long[] values, int[] sizes, long[] depClosures, long[] depFieldIDs) { @@ -99,6 +139,12 @@ public class ScriptGroup2 extends BaseObj { depClosures[index] = f.getClosure().getID(rs); Script.FieldID fieldID = f.getFieldID(); depFieldIDs[index] = fieldID != null ? fieldID.getID(rs) : 0; + if (obj == null) { + // Value is originally created by the owner closure + values[index] = 0; + sizes[index] = 0; + return; + } } else { depClosures[index] = 0; depFieldIDs[index] = 0; @@ -121,6 +167,10 @@ public class ScriptGroup2 extends BaseObj { Future f = mGlobalFuture.get(field); if (f == null) { + // If the field is not bound to this closure, this will return a future + // without an associated value (reference). So this is not working for + // cross-module (cross-script) linking in this case where a field not + // explicitly bound. f = new Future(this, field, mBindings.get(field)); mGlobalFuture.put(field, f); } @@ -160,7 +210,6 @@ public class ScriptGroup2 extends BaseObj { size = 8; } } - public long value; public int size; } @@ -297,6 +346,13 @@ public class ScriptGroup2 extends BaseObj { return c; } + public Closure addInvoke(Script.InvokeID invoke, Object[] args, + Map<Script.FieldID, Object> globalBindings) { + Closure c = new Closure(mRS, invoke, args, globalBindings); + mClosures.add(c); + return c; + } + public UnboundValue addInput() { UnboundValue unbound = new UnboundValue(); mInputs.add(unbound); |