Implement reflecting Java objects into the ACC enviroment.
diff --git a/libs/rs/java/Fountain/res/raw/fountain.c b/libs/rs/java/Fountain/res/raw/fountain.c
index 5ed9ed51..6e6afcd 100644
--- a/libs/rs/java/Fountain/res/raw/fountain.c
+++ b/libs/rs/java/Fountain/res/raw/fountain.c
@@ -7,38 +7,23 @@
 
 
 int main(int launchID) {
-    int count, touch, x, y, rate;
-    int ct, ct2;
-    int newPart;
-    int drawCount;
-    int idx;
-    float dx, dy;
-    float posx,posy;
-    int c;
-    int srcIdx;
-    int dstIdx;
-
-    count = loadI32(0, 1);
-    touch = loadI32(0, 2);
-    x = loadI32(0, 3);
-    y = loadI32(0, 4);
-
-    rate = 4;
+    int ct;
+    int count = loadI32(0, OFFSETOF_SomeData_count);
+    int touch = loadI32(0, OFFSETOF_SomeData_touch);
+    int rate = 4;
     int maxLife = (count / rate) - 1;
 
     if (touch) {
-        newPart = loadI32(2, 0);
-        for (ct2=0; ct2<rate; ct2++) {
-            dx = randf(1.f) - 0.5f;
-            dy = randf(1.f) - 0.5f;
-
-            idx = newPart * 5 + 1;
-            storeF(2, idx, dx);
-            storeF(2, idx + 1, dy);
+        int x = loadI32(0, OFFSETOF_SomeData_x);
+        int y = loadI32(0, OFFSETOF_SomeData_y);
+        int newPart = loadI32(2, 0);
+        for (ct=0; ct<rate; ct++) {
+            int idx = newPart * 5 + 1;
+            storeF(2, idx, randf(1.f) - 0.5f);
+            storeF(2, idx + 1, randf(1.f) - 0.5f);
             storeI32(2, idx + 2, maxLife);
             storeF(2, idx + 3, x);
             storeF(2, idx + 4, y);
-
             newPart++;
             if (newPart >= count) {
                 newPart = 0;
@@ -47,21 +32,21 @@
         storeI32(2, 0, newPart);
     }
 
-    drawCount = 0;
+    int drawCount = 0;
     float height = getHeight();
     for (ct=0; ct < count; ct++) {
-        srcIdx = ct * 5 + 1;
+        int srcIdx = ct * 5 + 1;
 
-        dx = loadF(2, srcIdx);
-        dy = loadF(2, srcIdx + 1);
         int life = loadI32(2, srcIdx + 2);
-        posx = loadF(2, srcIdx + 3);
-        posy = loadF(2, srcIdx + 4);
 
         if (life) {
+            float posx = loadF(2, srcIdx + 3);
+            float posy = loadF(2, srcIdx + 4);
+            float dx = loadF(2, srcIdx);
+            float dy = loadF(2, srcIdx + 1);
             if (posy < height) {
-                dstIdx = drawCount * 9;
-                c = 0xcfcfcfcf;
+                int dstIdx = drawCount * 9;
+                int c = 0xcfcfcfcf;
 
                 storeI32(1, dstIdx, c);
                 storeF(1, dstIdx + 1, posx);
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
index ad4f949..3e680e35 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
@@ -23,24 +23,21 @@
 import android.graphics.Bitmap;
 import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
+import android.renderscript.*;
 import android.util.Log;
 
-import android.renderscript.RenderScript;
-import android.renderscript.ProgramVertex;
-import android.renderscript.Element;
-import android.renderscript.Allocation;
-import android.renderscript.Script;
-import android.renderscript.ScriptC;
-import android.renderscript.ProgramFragment;
-import android.renderscript.ProgramStore;
-import android.renderscript.SimpleMesh;
-import android.renderscript.Type;
-import android.renderscript.Primitive;
-
 
 public class FountainRS {
     public static final int PART_COUNT = 4000;
 
+    static class SomeData {
+        public int x;
+        public int y;
+        public int touch;
+        public int rate;
+        public int count;
+    }
+
     public FountainRS() {
     }
 
@@ -51,10 +48,10 @@
     }
 
     public void newTouchPosition(int x, int y) {
-        mParams[0] = 1;
-        mParams[1] = x;
-        mParams[2] = y;
-        mIntAlloc.subData1D(2, 3, mParams);
+        mSD.touch = 1;
+        mSD.x = x;
+        mSD.y = y;
+        mIntAlloc.data(mSD);
     }
 
 
@@ -73,10 +70,13 @@
 
     private Bitmap mBackground;
 
-    int mParams[] = new int[10];
+    SomeData mSD = new SomeData();
+    private Type mSDType;
 
     private void initRS() {
-        mIntAlloc = Allocation.createSized(mRS, Element.USER_I32, 10);
+        mSD = new SomeData();
+        mSDType = Type.createFromClass(mRS, SomeData.class, 1, "SomeData");
+        mIntAlloc = Allocation.createTyped(mRS, mSDType);
         mVertAlloc = Allocation.createSized(mRS, Element.USER_I32, PART_COUNT * 5 + 1);
 
         ProgramStore.Builder bs = new ProgramStore.Builder(mRS, null, null);
@@ -91,14 +91,8 @@
         mPF = bf.create();
         mPF.setName("PgmFragParts");
 
-        mParams[0] = 0;
-        mParams[1] = PART_COUNT;
-        mParams[2] = 0;
-        mParams[3] = 0;
-        mParams[4] = 0;
-        mParams[5] = 0;
-        mParams[6] = 0;
-        mIntAlloc.data(mParams);
+        mSD.count = PART_COUNT;
+        mIntAlloc.data(mSD);
 
         Element.Builder eb = new Element.Builder(mRS);
         eb.add(Element.DataType.UNSIGNED, Element.DataKind.RED, true, 8);
@@ -124,6 +118,7 @@
         ScriptC.Builder sb = new ScriptC.Builder(mRS);
         sb.setScript(mRes, R.raw.fountain);
         sb.setRoot(true);
+        sb.addType(mSDType);
         mScript = sb.create();
         mScript.setClearColor(0.0f, 0.0f, 0.0f, 1.0f);
 
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index 7dbf412..d4fbf6b 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -44,6 +44,7 @@
 	param RsDataType dataType
 	param bool isNormalized
 	param size_t bits
+	param const char * name
 	}
 
 ElementCreate {
diff --git a/libs/rs/rsComponent.cpp b/libs/rs/rsComponent.cpp
index fde62a0..831580b 100644
--- a/libs/rs/rsComponent.cpp
+++ b/libs/rs/rsComponent.cpp
@@ -31,12 +31,15 @@
 
 Component::Component(
     DataKind dk, DataType dt,
-    bool isNormalized, uint32_t bits)
+    bool isNormalized, uint32_t bits, const char * name)
 {
     mType = dt;
     mKind = dk;
     mIsNormalized = isNormalized;
     mBits = bits;
+    if (name) {
+        mName = name;
+    }
 }
 
 Component::~Component()
diff --git a/libs/rs/rsComponent.h b/libs/rs/rsComponent.h
index 9db107f..5ee95c7 100644
--- a/libs/rs/rsComponent.h
+++ b/libs/rs/rsComponent.h
@@ -44,7 +44,7 @@
     };
 
 
-    Component(DataKind dk, DataType dt, bool isNormalized, uint32_t bits);
+    Component(DataKind dk, DataType dt, bool isNorm, uint32_t bits, const char *);
     virtual ~Component();
 
     DataType getType() const {return mType;}
@@ -54,12 +54,15 @@
 
     uint32_t getGLType() const;
 
+    const char * getComponentName() const {return mName.string();}
+
 protected:
 
     DataType mType;
     bool mIsNormalized;
     DataKind mKind;
     uint32_t mBits;
+    String8 mName;
 
 private:
     Component();
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index 9de23b3..2860452 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -17,7 +17,6 @@
 #include "rsDevice.h"
 #include "rsContext.h"
 #include "rsThreadIO.h"
-#include "utils/String8.h"
 #include <ui/FramebufferNativeWindow.h>
 
 #include <GLES/gl.h>
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 54c555f..60a526b 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -19,9 +19,6 @@
 
 #include "rsUtils.h"
 
-#include <utils/KeyedVector.h>
-#include <utils/String8.h>
-#include <utils/Vector.h>
 #include <ui/Surface.h>
 
 #include "rsType.h"
diff --git a/libs/rs/rsElement.cpp b/libs/rs/rsElement.cpp
index 0c5cb18..97b18c0 100644
--- a/libs/rs/rsElement.cpp
+++ b/libs/rs/rsElement.cpp
@@ -23,45 +23,45 @@
 
 void ElementState::initPredefined()
 {
-    Component * u_8  = new Component(Component::USER,   Component::UNSIGNED,  true,  8);
-    Component * i_8  = new Component(Component::USER,   Component::SIGNED,    true,  8);
-    Component * u_16 = new Component(Component::USER,   Component::UNSIGNED,  true,  16);
-    Component * i_16 = new Component(Component::USER,   Component::SIGNED,    true,  16);
-    Component * u_32 = new Component(Component::USER,   Component::UNSIGNED,  true,  32);
-    Component * i_32 = new Component(Component::USER,   Component::SIGNED,    true,  32);
-    Component * f_32 = new Component(Component::USER,   Component::FLOAT,     true,  32);
+    Component * u_8  = new Component(Component::USER,   Component::UNSIGNED,  true,  8, 0);
+    Component * i_8  = new Component(Component::USER,   Component::SIGNED,    true,  8, 0);
+    Component * u_16 = new Component(Component::USER,   Component::UNSIGNED,  true,  16, 0);
+    Component * i_16 = new Component(Component::USER,   Component::SIGNED,    true,  16, 0);
+    Component * u_32 = new Component(Component::USER,   Component::UNSIGNED,  true,  32, 0);
+    Component * i_32 = new Component(Component::USER,   Component::SIGNED,    true,  32, 0);
+    Component * f_32 = new Component(Component::USER,   Component::FLOAT,     true,  32, 0);
 
 
-    Component * r_4  = new Component(Component::RED,    Component::UNSIGNED,  true,  4);
-    Component * r_5  = new Component(Component::RED,    Component::UNSIGNED,  true,  5);
-    Component * r_8  = new Component(Component::RED,    Component::UNSIGNED,  true,  8);
+    Component * r_4  = new Component(Component::RED,    Component::UNSIGNED,  true,  4, 0);
+    Component * r_5  = new Component(Component::RED,    Component::UNSIGNED,  true,  5, 0);
+    Component * r_8  = new Component(Component::RED,    Component::UNSIGNED,  true,  8, 0);
 
-    Component * g_4  = new Component(Component::GREEN,  Component::UNSIGNED,  true,  4);
-    Component * g_5  = new Component(Component::GREEN,  Component::UNSIGNED,  true,  5);
-    Component * g_6  = new Component(Component::GREEN,  Component::UNSIGNED,  true,  6);
-    Component * g_8  = new Component(Component::GREEN,  Component::UNSIGNED,  true,  8);
+    Component * g_4  = new Component(Component::GREEN,  Component::UNSIGNED,  true,  4, 0);
+    Component * g_5  = new Component(Component::GREEN,  Component::UNSIGNED,  true,  5, 0);
+    Component * g_6  = new Component(Component::GREEN,  Component::UNSIGNED,  true,  6, 0);
+    Component * g_8  = new Component(Component::GREEN,  Component::UNSIGNED,  true,  8, 0);
 
-    Component * b_4  = new Component(Component::BLUE,   Component::UNSIGNED,  true,  4);
-    Component * b_5  = new Component(Component::BLUE,   Component::UNSIGNED,  true,  5);
-    Component * b_8  = new Component(Component::BLUE,   Component::UNSIGNED,  true,  8);
+    Component * b_4  = new Component(Component::BLUE,   Component::UNSIGNED,  true,  4, 0);
+    Component * b_5  = new Component(Component::BLUE,   Component::UNSIGNED,  true,  5, 0);
+    Component * b_8  = new Component(Component::BLUE,   Component::UNSIGNED,  true,  8, 0);
 
-    Component * a_1  = new Component(Component::ALPHA,  Component::UNSIGNED,  true,  1);
-    Component * a_4  = new Component(Component::ALPHA,  Component::UNSIGNED,  true,  4);
-    Component * a_8  = new Component(Component::ALPHA,  Component::UNSIGNED,  true,  8);
+    Component * a_1  = new Component(Component::ALPHA,  Component::UNSIGNED,  true,  1, 0);
+    Component * a_4  = new Component(Component::ALPHA,  Component::UNSIGNED,  true,  4, 0);
+    Component * a_8  = new Component(Component::ALPHA,  Component::UNSIGNED,  true,  8, 0);
 
-    Component * idx_16 = new Component(Component::INDEX,  Component::UNSIGNED,  false, 16);
-    Component * idx_32 = new Component(Component::INDEX,  Component::UNSIGNED,  false, 32);
+    Component * idx_16 = new Component(Component::INDEX,  Component::UNSIGNED,  false, 16, 0);
+    Component * idx_32 = new Component(Component::INDEX,  Component::UNSIGNED,  false, 32, 0);
 
-    Component * x    = new Component(Component::X,      Component::FLOAT,     false, 32);
-    Component * y    = new Component(Component::Y,      Component::FLOAT,     false, 32);
-    Component * z    = new Component(Component::Z,      Component::FLOAT,     false, 32);
+    Component * x    = new Component(Component::X,      Component::FLOAT,     false, 32, 0);
+    Component * y    = new Component(Component::Y,      Component::FLOAT,     false, 32, 0);
+    Component * z    = new Component(Component::Z,      Component::FLOAT,     false, 32, 0);
 
-    Component * nx   = new Component(Component::NX,     Component::FLOAT,     false, 32);
-    Component * ny   = new Component(Component::NY,     Component::FLOAT,     false, 32);
-    Component * nz   = new Component(Component::NZ,     Component::FLOAT,     false, 32);
+    Component * nx   = new Component(Component::NX,     Component::FLOAT,     false, 32, 0);
+    Component * ny   = new Component(Component::NY,     Component::FLOAT,     false, 32, 0);
+    Component * nz   = new Component(Component::NZ,     Component::FLOAT,     false, 32, 0);
 
-    Component * s    = new Component(Component::S,      Component::FLOAT,     false, 32);
-    Component * t    = new Component(Component::T,      Component::FLOAT,     false, 32);
+    Component * s    = new Component(Component::S,      Component::FLOAT,     false, 32, 0);
+    Component * t    = new Component(Component::T,      Component::FLOAT,     false, 32, 0);
 
     Element * e;
 
@@ -391,14 +391,14 @@
     return e;
 }
 
-void rsi_ElementAdd(Context *rsc, RsDataKind dk, RsDataType dt, bool isNormalized, size_t bits)
+void rsi_ElementAdd(Context *rsc, RsDataKind dk, RsDataType dt, bool isNormalized, size_t bits, const char *name)
 {
     ElementState * sec = &rsc->mStateElement;
-
     Component *c = new Component(static_cast<Component::DataKind>(dk),
                                  static_cast<Component::DataType>(dt),
                                  isNormalized,
-                                 bits);
+                                 bits,
+                                 name);
     sec->mComponentBuildList.add(c);
 }
 
diff --git a/libs/rs/rsFileA3D.cpp b/libs/rs/rsFileA3D.cpp
index 86d294b..347ef23 100644
--- a/libs/rs/rsFileA3D.cpp
+++ b/libs/rs/rsFileA3D.cpp
@@ -334,7 +334,7 @@
         uint32_t bits = io->loadU8();
         bool isNorm = io->loadU8() != 0;
         LOGE("  %i %i %i %i", dk, dt, bits, isNorm);
-        rsi_ElementAdd(rsc, dk, dt, isNorm, bits);
+        rsi_ElementAdd(rsc, dk, dt, isNorm, bits, 0);
     }
     LOGE("processChunk_Element create");
     ie->mRsObj = rsi_ElementCreate(rsc);
diff --git a/libs/rs/rsScript.h b/libs/rs/rsScript.h
index a8e04a6..6983ef4 100644
--- a/libs/rs/rsScript.h
+++ b/libs/rs/rsScript.h
@@ -29,6 +29,8 @@
 class ProgramRaster;
 class ProgramFragmentStore;
 
+#define MAX_SCRIPT_BANKS 16
+
 class Script : public ObjectBase
 {
 public:
@@ -57,7 +59,8 @@
     const Type * mConstantBufferTypes;
     uint32_t mCounstantBufferCount;
 
-    ObjectBaseRef<Allocation> mSlots[16];
+    ObjectBaseRef<Allocation> mSlots[MAX_SCRIPT_BANKS];
+    ObjectBaseRef<Type> mTypes[MAX_SCRIPT_BANKS];
 
     virtual bool run(Context *, uint32_t launchID) = 0;
 };
diff --git a/libs/rs/rsScriptC.cpp b/libs/rs/rsScriptC.cpp
index 3343db5..652283d 100644
--- a/libs/rs/rsScriptC.cpp
+++ b/libs/rs/rsScriptC.cpp
@@ -19,7 +19,6 @@
 #include "rsMatrix.h"
 
 #include "acc/acc.h"
-#include "utils/String8.h"
 #include "utils/Timers.h"
 
 #include <GLES/gl.h>
@@ -91,7 +90,10 @@
 {
     memset(&mProgram, 0, sizeof(mProgram));
 
-    mConstantBufferTypes.clear();
+    mConstantTypeCount = 0;
+    for (uint32_t ct=0; ct < MAX_SCRIPT_BANKS; ct++) {
+        mConstantBufferTypes[ct].clear();
+    }
 
     memset(&mEnviroment, 0, sizeof(mEnviroment));
     mEnviroment.mClearColor[0] = 0;
@@ -127,6 +129,7 @@
     appendDecls(&tmp);
     rsc->appendVarDefines(&tmp);
     appendVarDefines(&tmp);
+    appendTypes(&tmp);
     tmp.append("#line 1\n");
 
     const char* scriptSource[] = {tmp.string(), mProgram.mScriptText};
@@ -242,6 +245,31 @@
     }
 }
 
+void ScriptCState::appendTypes(String8 *str)
+{
+    char buf[256];
+
+    for (size_t ct=0; ct < mConstantTypeCount; ct++) {
+        const Type *t = mConstantBufferTypes[ct].get();
+        const Element *e = t->getElement();
+
+        if (!t->getName()) {
+            continue;
+        }
+        for (size_t ct2=0; ct2 < e->getComponentCount(); ct2++) {
+            const Component *c = e->getComponent(ct2);
+            str->append("#define OFFSETOF_");
+            str->append(t->getName());
+            str->append("_");
+            str->append(c->getComponentName());
+            sprintf(buf, " %i\n", ct2);
+            str->append(buf);
+        }
+
+    }
+
+}
+
 
 namespace android {
 namespace renderscript {
@@ -255,7 +283,10 @@
 void rsi_ScriptCAddType(Context * rsc, RsType vt)
 {
     ScriptCState *ss = &rsc->mScriptC;
-    ss->mConstantBufferTypes.add(static_cast<const Type *>(vt));
+    const Type *t = static_cast<const Type *>(vt);
+
+    ss->mConstantBufferTypes[ss->mConstantTypeCount].set(t);
+    ss->mConstantTypeCount ++;
 }
 
 void rsi_ScriptCSetScript(Context * rsc, void *vp)
diff --git a/libs/rs/rsScriptC.h b/libs/rs/rsScriptC.h
index ad0e3ee..60a6fba 100644
--- a/libs/rs/rsScriptC.h
+++ b/libs/rs/rsScriptC.h
@@ -68,11 +68,13 @@
     ScriptC::Program_t mProgram;
     Script::Enviroment_t mEnviroment;
 
-    Vector<const Type *> mConstantBufferTypes;
+    ObjectBaseRef<const Type> mConstantBufferTypes[MAX_SCRIPT_BANKS];
+    uint32_t mConstantTypeCount;
 
     void clear();
     void runCompiler(Context *rsc);
     void appendVarDefines(String8 *str);
+    void appendTypes(String8 *str);
 
     struct SymbolTable_t {
         const char * mName;
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index 4ee112d..c13894b 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -20,7 +20,6 @@
 #include "rsNoise.h"
 
 #include "acc/acc.h"
-#include "utils/String8.h"
 #include "utils/Timers.h"
 
 #include <GLES/gl.h>
diff --git a/libs/rs/rsUtils.h b/libs/rs/rsUtils.h
index f0e4750..ec928db 100644
--- a/libs/rs/rsUtils.h
+++ b/libs/rs/rsUtils.h
@@ -21,6 +21,8 @@
 #define LOG_TAG "rs"
 #include <utils/Log.h>
 #include <utils/Vector.h>
+#include <utils/KeyedVector.h>
+#include <utils/String8.h>
 #include <stdlib.h>
 #include <pthread.h>
 #include <time.h>