diff options
Diffstat (limited to 'graphics/java/android/renderscript')
-rw-r--r-- | graphics/java/android/renderscript/RenderScript.java | 17 | ||||
-rw-r--r-- | graphics/java/android/renderscript/Sampler.java | 80 | ||||
-rw-r--r-- | graphics/java/android/renderscript/Script.java | 88 | ||||
-rw-r--r-- | graphics/java/android/renderscript/ScriptC.java | 60 |
4 files changed, 124 insertions, 121 deletions
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java index db2a3fd..e9f8fe6 100644 --- a/graphics/java/android/renderscript/RenderScript.java +++ b/graphics/java/android/renderscript/RenderScript.java @@ -138,16 +138,17 @@ public class RenderScript { native void nScriptSetClearDepth(int script, float depth); native void nScriptSetClearStencil(int script, int stencil); native void nScriptSetTimeZone(int script, byte[] timeZone); - native void nScriptSetType(int type, boolean writable, String name, int slot); native void nScriptSetRoot(boolean isRoot); - native void nScriptSetInvokable(String name, int slot); native void nScriptInvoke(int id, int slot); + native void nScriptInvokeData(int id, int slot); + native void nScriptInvokeV(int id, int slot, byte[] params); + native void nScriptSetVarI(int id, int slot, int val); + native void nScriptSetVarF(int id, int slot, float val); + native void nScriptSetVarV(int id, int slot, byte[] val); native void nScriptCBegin(); native void nScriptCSetScript(byte[] script, int offset, int length); native int nScriptCCreate(); - native void nScriptCAddDefineI32(String name, int value); - native void nScriptCAddDefineF(String name, float value); native void nSamplerBegin(); native void nSamplerSet(int param, int value); @@ -229,6 +230,13 @@ public class RenderScript { Element mElement_COLOR_U8_4; Element mElement_COLOR_F32_4; + Sampler mSampler_CLAMP_NEAREST; + Sampler mSampler_CLAMP_LINEAR; + Sampler mSampler_CLAMP_LINEAR_MIP_LINEAR; + Sampler mSampler_WRAP_NEAREST; + Sampler mSampler_WRAP_LINEAR; + Sampler mSampler_WRAP_LINEAR_MIP_LINEAR; + /////////////////////////////////////////////////////////////////////////////////// // @@ -293,7 +301,6 @@ public class RenderScript { mRS.mMessageCallback.mID = msg; mRS.mMessageCallback.run(); } - //Log.d(LOG_TAG, "MessageThread msg " + msg + " v1 " + rbuf[0] + " v2 " + rbuf[1] + " v3 " +rbuf[2]); } Log.d(LOG_TAG, "MessageThread exiting."); } diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java index 40ba722..da83d04 100644 --- a/graphics/java/android/renderscript/Sampler.java +++ b/graphics/java/android/renderscript/Sampler.java @@ -51,6 +51,86 @@ public class Sampler extends BaseObj { mID = id; } + Sampler mSampler_CLAMP_NEAREST; + Sampler mSampler_CLAMP_LINEAR; + Sampler mSampler_CLAMP_LINEAR_MIP; + Sampler mSampler_WRAP_NEAREST; + Sampler mSampler_WRAP_LINEAR; + Sampler mSampler_WRAP_LINEAR_MIP; + + public static Sampler CLAMP_NEAREST(RenderScript rs) { + if(rs.mSampler_CLAMP_NEAREST == null) { + Builder b = new Builder(rs); + b.setMin(Value.NEAREST); + b.setMag(Value.NEAREST); + b.setWrapS(Value.CLAMP); + b.setWrapT(Value.CLAMP); + rs.mSampler_CLAMP_NEAREST = b.create(); + } + return rs.mSampler_CLAMP_NEAREST; + } + + public static Sampler CLAMP_LINEAR(RenderScript rs) { + if(rs.mSampler_CLAMP_LINEAR == null) { + Builder b = new Builder(rs); + b.setMin(Value.LINEAR); + b.setMag(Value.LINEAR); + b.setWrapS(Value.CLAMP); + b.setWrapT(Value.CLAMP); + rs.mSampler_CLAMP_LINEAR = b.create(); + } + return rs.mSampler_CLAMP_LINEAR; + } + + public static Sampler CLAMP_LINEAR_MIP_LINEAR(RenderScript rs) { + if(rs.mSampler_CLAMP_LINEAR_MIP_LINEAR == null) { + Builder b = new Builder(rs); + b.setMin(Value.LINEAR_MIP_LINEAR); + b.setMag(Value.LINEAR_MIP_LINEAR); + b.setWrapS(Value.CLAMP); + b.setWrapT(Value.CLAMP); + rs.mSampler_CLAMP_LINEAR_MIP_LINEAR = b.create(); + } + return rs.mSampler_CLAMP_LINEAR_MIP_LINEAR; + } + + public static Sampler WRAP_NEAREST(RenderScript rs) { + if(rs.mSampler_WRAP_NEAREST == null) { + Builder b = new Builder(rs); + b.setMin(Value.NEAREST); + b.setMag(Value.NEAREST); + b.setWrapS(Value.WRAP); + b.setWrapT(Value.WRAP); + rs.mSampler_WRAP_NEAREST = b.create(); + } + return rs.mSampler_WRAP_NEAREST; + } + + public static Sampler WRAP_LINEAR(RenderScript rs) { + if(rs.mSampler_WRAP_LINEAR == null) { + Builder b = new Builder(rs); + b.setMin(Value.LINEAR); + b.setMag(Value.LINEAR); + b.setWrapS(Value.WRAP); + b.setWrapT(Value.WRAP); + rs.mSampler_WRAP_LINEAR = b.create(); + } + return rs.mSampler_WRAP_LINEAR; + } + + public static Sampler WRAP_LINEAR_MIP_LINEAR(RenderScript rs) { + if(rs.mSampler_WRAP_LINEAR_MIP_LINEAR == null) { + Builder b = new Builder(rs); + b.setMin(Value.LINEAR_MIP_LINEAR); + b.setMag(Value.LINEAR_MIP_LINEAR); + b.setWrapS(Value.WRAP); + b.setWrapT(Value.WRAP); + rs.mSampler_WRAP_LINEAR_MIP_LINEAR = b.create(); + } + return rs.mSampler_WRAP_LINEAR_MIP_LINEAR; + } + + public static class Builder { RenderScript mRS; Value mMin; diff --git a/graphics/java/android/renderscript/Script.java b/graphics/java/android/renderscript/Script.java index 0d21368..632a459 100644 --- a/graphics/java/android/renderscript/Script.java +++ b/graphics/java/android/renderscript/Script.java @@ -46,6 +46,15 @@ public class Script extends BaseObj { mRS.nScriptInvoke(mID, slot); } + protected void invokeData(int slot) { + mRS.nScriptInvokeData(mID, slot); + } + + protected void invokeV(int slot, FieldPacker v) { + mRS.nScriptInvokeV(mID, slot, v.getData()); + } + + Script(int id, RenderScript rs) { super(rs); mID = id; @@ -53,7 +62,23 @@ public class Script extends BaseObj { public void bindAllocation(Allocation va, int slot) { mRS.validate(); - mRS.nScriptBindAllocation(mID, va.mID, slot); + if (va != null) { + mRS.nScriptBindAllocation(mID, va.mID, slot); + } else { + mRS.nScriptBindAllocation(mID, 0, slot); + } + } + + public void setVar(int index, float v) { + mRS.nScriptSetVarF(mID, index, v); + } + + public void setVar(int index, int v) { + mRS.nScriptSetVarI(mID, index, v); + } + + public void setVar(int index, FieldPacker v) { + mRS.nScriptSetVarV(mID, index, v.getData()); } public void setClearColor(float r, float g, float b, float a) { @@ -82,71 +107,10 @@ public class Script extends BaseObj { public static class Builder { RenderScript mRS; - boolean mIsRoot = false; - Type[] mTypes; - String[] mNames; - boolean[] mWritable; - int mInvokableCount = 0; - Invokable[] mInvokables; Builder(RenderScript rs) { mRS = rs; - mTypes = new Type[MAX_SLOT]; - mNames = new String[MAX_SLOT]; - mWritable = new boolean[MAX_SLOT]; - mInvokables = new Invokable[MAX_SLOT]; - } - - public void setType(Type t, int slot) { - mTypes[slot] = t; - mNames[slot] = null; } - - public void setType(Type t, String name, int slot) { - mTypes[slot] = t; - mNames[slot] = name; - } - - public Invokable addInvokable(String func) { - Invokable i = new Invokable(); - i.mName = func; - i.mRS = mRS; - i.mSlot = mInvokableCount; - mInvokables[mInvokableCount++] = i; - return i; - } - - public void setType(boolean writable, int slot) { - mWritable[slot] = writable; - } - - void transferCreate() { - mRS.nScriptSetRoot(mIsRoot); - for(int ct=0; ct < mTypes.length; ct++) { - if(mTypes[ct] != null) { - mRS.nScriptSetType(mTypes[ct].mID, mWritable[ct], mNames[ct], ct); - } - } - for(int ct=0; ct < mInvokableCount; ct++) { - mRS.nScriptSetInvokable(mInvokables[ct].mName, ct); - } - } - - void transferObject(Script s) { - s.mIsRoot = mIsRoot; - s.mTypes = mTypes; - s.mInvokables = new Invokable[mInvokableCount]; - for(int ct=0; ct < mInvokableCount; ct++) { - s.mInvokables[ct] = mInvokables[ct]; - s.mInvokables[ct].mScript = s; - } - s.mInvokables = null; - } - - public void setRoot(boolean r) { - mIsRoot = r; - } - } diff --git a/graphics/java/android/renderscript/ScriptC.java b/graphics/java/android/renderscript/ScriptC.java index f5d5b2f..c1ba000 100644 --- a/graphics/java/android/renderscript/ScriptC.java +++ b/graphics/java/android/renderscript/ScriptC.java @@ -81,8 +81,6 @@ public class ScriptC extends Script { public static class Builder extends Script.Builder { byte[] mProgram; int mProgramLength; - HashMap<String,Integer> mIntDefines = new HashMap(); - HashMap<String,Float> mFloatDefines = new HashMap(); public Builder(RenderScript rs) { super(rs); @@ -133,66 +131,20 @@ public class ScriptC extends Script { static synchronized ScriptC internalCreate(Builder b) { b.mRS.nScriptCBegin(); - b.transferCreate(); - - for (Entry<String,Integer> e: b.mIntDefines.entrySet()) { - b.mRS.nScriptCAddDefineI32(e.getKey(), e.getValue().intValue()); - } - for (Entry<String,Float> e: b.mFloatDefines.entrySet()) { - b.mRS.nScriptCAddDefineF(e.getKey(), e.getValue().floatValue()); - } + android.util.Log.e("rs", "len = " + b.mProgramLength); b.mRS.nScriptCSetScript(b.mProgram, 0, b.mProgramLength); int id = b.mRS.nScriptCCreate(); ScriptC obj = new ScriptC(id, b.mRS); - b.transferObject(obj); - return obj; } - public void addDefine(String name, int value) { - mIntDefines.put(name, value); - } - - public void addDefine(String name, float value) { - mFloatDefines.put(name, value); - } - - /** - * Takes the all public static final fields for a class, and adds defines - * for them, using the name of the field as the name of the define. - */ - public void addDefines(Class cl) { - addDefines(cl.getFields(), (Modifier.STATIC | Modifier.FINAL | Modifier.PUBLIC), null); - } - - /** - * Takes the all public fields for an object, and adds defines - * for them, using the name of the field as the name of the define. - */ - public void addDefines(Object o) { - addDefines(o.getClass().getFields(), Modifier.PUBLIC, o); - } - - void addDefines(Field[] fields, int mask, Object o) { - for (Field f: fields) { - try { - if ((f.getModifiers() & mask) == mask) { - Class t = f.getType(); - if (t == int.class) { - mIntDefines.put(f.getName(), f.getInt(o)); - } - else if (t == float.class) { - mFloatDefines.put(f.getName(), f.getFloat(o)); - } - } - } catch (IllegalAccessException ex) { - // TODO: Do we want this log? - Log.d(TAG, "addDefines skipping field " + f.getName()); - } - } - } + public void addDefine(String name, int value) {} + public void addDefine(String name, float value) {} + public void addDefines(Class cl) {} + public void addDefines(Object o) {} + void addDefines(Field[] fields, int mask, Object o) {} public ScriptC create() { return internalCreate(this); |