Let java put #defines into renderscript
diff --git a/rs.spec b/rs.spec
index e5d30e4..b644833 100644
--- a/rs.spec
+++ b/rs.spec
@@ -16,6 +16,16 @@
 	param RsProgramVertex pgm
 	}
 
+ContextSetDefineF {
+    param const char* name
+    param float value
+    }
+
+ContextSetDefineI32 {
+    param const char* name
+    param int32_t value
+    }
+
 AssignName {
 	param void *obj
 	param const char *name
@@ -318,6 +328,15 @@
 	ret RsScript
 	}
 
+ScriptCSetDefineF {
+    param const char* name
+    param float value
+    }
+
+ScriptCSetDefineI32 {
+    param const char* name
+    param int32_t value
+    }
 
 ProgramFragmentStoreBegin {
 	param RsElement in
diff --git a/rsContext.cpp b/rsContext.cpp
index 46bd892..9de23b3 100644
--- a/rsContext.cpp
+++ b/rsContext.cpp
@@ -331,6 +331,26 @@
     }
 }
 
+void Context::appendVarDefines(String8 *str) const
+{
+    char buf[256];
+    for (size_t ct=0; ct < mInt32Defines.size(); ct++) {
+        str->append("#define ");
+        str->append(mInt32Defines.keyAt(ct));
+        str->append(" ");
+        sprintf(buf, "%i\n", (int)mInt32Defines.valueAt(ct));
+        str->append(buf);
+
+    }
+    for (size_t ct=0; ct < mFloatDefines.size(); ct++) {
+        str->append("#define ");
+        str->append(mFloatDefines.keyAt(ct));
+        str->append(" ");
+        sprintf(buf, "%ff\n", mFloatDefines.valueAt(ct));
+        str->append(buf);
+    }
+}
+
 
 ///////////////////////////////////////////////////////////////////////////////////////////
 //
@@ -381,6 +401,15 @@
     rsc->assignName(ob, name, len);
 }
 
+void rsi_ContextSetDefineF(Context *rsc, const char* name, float value)
+{
+    rsc->addInt32Define(name, value);
+}
+
+void rsi_ContextSetDefineI32(Context *rsc, const char* name, int32_t value)
+{
+    rsc->addFloatDefine(name, value);
+}
 
 }
 }
diff --git a/rsContext.h b/rsContext.h
index 5d41460..799c443 100644
--- a/rsContext.h
+++ b/rsContext.h
@@ -19,6 +19,8 @@
 
 #include "rsUtils.h"
 
+#include <utils/KeyedVector.h>
+#include <utils/String8.h>
 #include <utils/Vector.h>
 #include <ui/Surface.h>
 
@@ -93,7 +95,7 @@
     void removeName(ObjectBase *obj);
     ObjectBase * lookupName(const char *name) const;
     void appendNameDefines(String8 *str) const;
-
+    void appendVarDefines(String8 *str) const;
 
     ProgramFragment * getDefaultProgramFragment() const {
         return mStateFragment.mDefault.get();
@@ -105,6 +107,14 @@
         return mStateFragmentStore.mDefault.get();
     }
 
+    void addInt32Define(const char* name, int32_t value) {
+        mInt32Defines.add(String8(name), value);
+    }
+
+    void addFloatDefine(const char* name, float value) {
+        mFloatDefines.add(String8(name), value);
+    }
+
 protected:
     Device *mDev;
 
@@ -143,6 +153,8 @@
     Surface *mWndSurface;
 
     Vector<ObjectBase *> mNames;
+    KeyedVector<String8,int> mInt32Defines;
+    KeyedVector<String8,float> mFloatDefines;
 };
 
 
diff --git a/rsScriptC.cpp b/rsScriptC.cpp
index efe6ff7..3343db5 100644
--- a/rsScriptC.cpp
+++ b/rsScriptC.cpp
@@ -104,6 +104,8 @@
 
     mAccScript = NULL;
 
+    mInt32Defines.clear();
+    mFloatDefines.clear();
 }
 
 static ACCvoid* symbolLookup(ACCvoid* pContext, const ACCchar* name)
@@ -123,6 +125,8 @@
 
     rsc->appendNameDefines(&tmp);
     appendDecls(&tmp);
+    rsc->appendVarDefines(&tmp);
+    appendVarDefines(&tmp);
     tmp.append("#line 1\n");
 
     const char* scriptSource[] = {tmp.string(), mProgram.mScriptText};
@@ -138,7 +142,6 @@
         ACCsizei len;
         accGetScriptInfoLog(mAccScript, sizeof(buf), &len, buf);
         LOGE(buf);
-
     }
 
     mEnviroment.mFragment.set(rsc->getDefaultProgramFragment());
@@ -215,9 +218,31 @@
     } else {
         // Deal with an error.
     }
-
 }
 
+
+void ScriptCState::appendVarDefines(String8 *str)
+{
+    char buf[256];
+    LOGD("appendVarDefines mInt32Defines.size()=%d mFloatDefines.size()=%d\n",
+            mInt32Defines.size(), mFloatDefines.size());
+    for (size_t ct=0; ct < mInt32Defines.size(); ct++) {
+        str->append("#define ");
+        str->append(mInt32Defines.keyAt(ct));
+        str->append(" ");
+        sprintf(buf, "%i\n", (int)mInt32Defines.valueAt(ct));
+        str->append(buf);
+    }
+    for (size_t ct=0; ct < mFloatDefines.size(); ct++) {
+        str->append("#define ");
+        str->append(mFloatDefines.keyAt(ct));
+        str->append(" ");
+        sprintf(buf, "%ff\n", mFloatDefines.valueAt(ct));
+        str->append(buf);
+    }
+}
+
+
 namespace android {
 namespace renderscript {
 
@@ -270,6 +295,18 @@
     return s;
 }
 
+void rsi_ScriptCSetDefineF(Context *rsc, const char* name, float value)
+{
+    ScriptCState *ss = &rsc->mScriptC;
+    ss->mFloatDefines.add(String8(name), value);
+}
+
+void rsi_ScriptCSetDefineI32(Context *rsc, const char* name, int32_t value)
+{
+    ScriptCState *ss = &rsc->mScriptC;
+    ss->mInt32Defines.add(String8(name), value);
+}
+
 }
 }
 
diff --git a/rsScriptC.h b/rsScriptC.h
index 860b4d1..ad0e3ee 100644
--- a/rsScriptC.h
+++ b/rsScriptC.h
@@ -21,6 +21,8 @@
 
 #include "RenderScriptEnv.h"
 
+#include <utils/KeyedVector.h>
+
 struct ACCscript;
 
 // ---------------------------------------------------------------------------
@@ -70,6 +72,7 @@
 
     void clear();
     void runCompiler(Context *rsc);
+    void appendVarDefines(String8 *str);
 
     struct SymbolTable_t {
         const char * mName;
@@ -80,6 +83,9 @@
     static SymbolTable_t gSyms[];
     static const SymbolTable_t * lookupSymbol(const char *);
     static void appendDecls(String8 *str);
+
+    KeyedVector<String8,int> mInt32Defines;
+    KeyedVector<String8,float> mFloatDefines;
 };