Continue development of es2.0 user shader support for renderscript.  This change cleans up ProgramVertex creation and adds support for passing input, output, and constant type info.
diff --git a/rsElement.cpp b/rsElement.cpp
index 67e4f14..e796556 100644
--- a/rsElement.cpp
+++ b/rsElement.cpp
@@ -24,19 +24,16 @@
 
 Element::Element(Context *rsc) : ObjectBase(rsc)
 {
+    mType = RS_TYPE_FLOAT;
+    mIsNormalized = false;
+    mKind = RS_KIND_USER;
+    mBits = 0;
     mAllocFile = __FILE__;
     mAllocLine = __LINE__;
-    mComponents = NULL;
-    mComponentCount = 0;
+    mFields = NULL;
+    mFieldCount = 0;
 }
 
-Element::Element(Context *rsc, uint32_t count) : ObjectBase(rsc)
-{
-    mAllocFile = __FILE__;
-    mAllocLine = __LINE__;
-    mComponents = new ObjectBaseRef<Component> [count];
-    mComponentCount = count;
-}
 
 Element::~Element()
 {
@@ -45,11 +42,11 @@
 
 void Element::clear()
 {
-    delete [] mComponents;
-    mComponents = NULL;
-    mComponentCount = 0;
+    delete [] mFields;
+    mFields = NULL;
+    mFieldCount = 0;
 }
-
+/*
 void Element::setComponent(uint32_t idx, Component *c)
 {
     rsAssert(!mComponents[idx].get());
@@ -59,22 +56,26 @@
 // Fixme: This should probably not be here
     c->incUserRef();
 }
-
+*/
 
 size_t Element::getSizeBits() const
 {
+    if (!mFieldCount) {
+        return mBits;
+    }
+
     size_t total = 0;
-    for (size_t ct=0; ct < mComponentCount; ct++) {
-        total += mComponents[ct]->getBits();
+    for (size_t ct=0; ct < mFieldCount; ct++) {
+        total += mFields[ct].e->mBits;
     }
     return total;
 }
 
-size_t Element::getComponentOffsetBits(uint32_t componentNumber) const
+size_t Element::getFieldOffsetBits(uint32_t componentNumber) const
 {
     size_t offset = 0;
     for (uint32_t ct = 0; ct < componentNumber; ct++) {
-        offset += mComponents[ct]->getBits();
+        offset += mFields[ct].e->mBits;
     }
     return offset;
 }
@@ -83,21 +84,54 @@
 {
     int bits[4];
 
-    if (mComponentCount > 4) {
+    if (!mFieldCount) {
+        switch (mType) {
+        case RS_TYPE_FLOAT:
+            if (mBits == 32) {
+                return GL_FLOAT;
+            }
+            return 0;
+        case RS_TYPE_SIGNED:
+            switch (mBits) {
+            case 8:
+                return GL_BYTE;
+            case 16:
+                return GL_SHORT;
+            //case 32:
+                //return GL_INT;
+            }
+            return 0;
+        case RS_TYPE_UNSIGNED:
+            switch (mBits) {
+            case 8:
+                return GL_UNSIGNED_BYTE;
+            case 16:
+                return GL_UNSIGNED_SHORT;
+            //case 32:
+                //return GL_UNSIGNED_INT;
+            }
+            return 0;
+        }
+    }
+
+    if (mFieldCount > 4) {
         return 0;
     }
 
-    for (uint32_t ct=0; ct < mComponentCount; ct++) {
-        bits[ct] = mComponents[ct]->getBits();
-        if (mComponents[ct]->getType() != Component::UNSIGNED) {
+    for (uint32_t ct=0; ct < mFieldCount; ct++) {
+        bits[ct] = mFields[ct].e->mBits;
+        if (mFields[ct].e->mFieldCount) {
             return 0;
         }
-        if (!mComponents[ct]->getIsNormalized()) {
+        if (mFields[ct].e->mType != RS_TYPE_UNSIGNED) {
+            return 0;
+        }
+        if (!mFields[ct].e->mIsNormalized) {
             return 0;
         }
     }
 
-    switch(mComponentCount) {
+    switch(mFieldCount) {
     case 1:
         if (bits[0] == 8) {
             return GL_UNSIGNED_BYTE;
@@ -146,33 +180,34 @@
 
 uint32_t Element::getGLFormat() const
 {
-    switch(mComponentCount) {
-    case 1:
-        if (mComponents[0]->getKind() == Component::ALPHA) {
+    if (!mFieldCount) {
+        if (mKind == RS_KIND_ALPHA) {
             return GL_ALPHA;
         }
-        if (mComponents[0]->getKind() == Component::LUMINANCE) {
+        if (mKind == RS_KIND_LUMINANCE) {
             return GL_LUMINANCE;
         }
-        break;
+    }
+
+    switch(mFieldCount) {
     case 2:
-        if ((mComponents[0]->getKind() == Component::LUMINANCE) &&
-            (mComponents[1]->getKind() == Component::ALPHA)) {
+        if ((mFields[0].e->mKind == RS_KIND_LUMINANCE) &&
+            (mFields[1].e->mKind == RS_KIND_ALPHA)) {
             return GL_LUMINANCE_ALPHA;
         }
         break;
     case 3:
-        if ((mComponents[0]->getKind() == Component::RED) &&
-            (mComponents[1]->getKind() == Component::GREEN) &&
-            (mComponents[2]->getKind() == Component::BLUE)) {
+        if ((mFields[0].e->mKind == RS_KIND_RED) &&
+            (mFields[1].e->mKind == RS_KIND_GREEN) &&
+            (mFields[2].e->mKind == RS_KIND_BLUE)) {
             return GL_RGB;
         }
         break;
     case 4:
-        if ((mComponents[0]->getKind() == Component::RED) &&
-            (mComponents[1]->getKind() == Component::GREEN) &&
-            (mComponents[2]->getKind() == Component::BLUE) &&
-            (mComponents[3]->getKind() == Component::ALPHA)) {
+        if ((mFields[0].e->mKind == RS_KIND_RED) &&
+            (mFields[1].e->mKind == RS_KIND_GREEN) &&
+            (mFields[2].e->mKind == RS_KIND_BLUE) &&
+            (mFields[3].e->mKind == RS_KIND_ALPHA)) {
             return GL_RGBA;
         }
         break;
@@ -180,18 +215,64 @@
     return 0;
 }
 
+const char * Element::getCType() const
+{
+    switch(mType) {
+    case RS_TYPE_FLOAT:
+        return "float";
+    case RS_TYPE_SIGNED:
+    case RS_TYPE_UNSIGNED:
+        switch(mBits) {
+        case 32:
+            return "int";
+        case 16:
+            return "short";
+        case 8:
+            return "char";
+        }
+        break;
+    }
+    return NULL;
+}
 
 void Element::dumpLOGV(const char *prefix) const
 {
     ObjectBase::dumpLOGV(prefix);
-    LOGV("%s   Element: components %i,  size %i", prefix, mComponentCount, getSizeBytes());
-    for (uint32_t ct = 0; ct < mComponentCount; ct++) {
+    LOGV("%s   Element: components %i,  size %i", prefix, mFieldCount, mBits);
+    for (uint32_t ct = 0; ct < mFieldCount; ct++) {
         char buf[1024];
         sprintf(buf, "%s component %i: ", prefix, ct);
-        mComponents[ct]->dumpLOGV(buf);
+        //mComponents[ct]->dumpLOGV(buf);
     }
 }
 
+Element * Element::create(Context *rsc, RsDataKind dk, RsDataType dt,
+                          bool isNorm, size_t bits)
+{
+    Element *e = new Element(rsc);
+    e->mKind = dk;
+    e->mType = dt;
+    e->mIsNormalized = isNorm;
+    e->mBits = bits;
+    return e;
+}
+
+Element * Element::create(Context *rsc, Element **ein, const char **nin,
+                          const size_t * lengths, size_t count)
+{
+    Element *e = new Element(rsc);
+    e->mFields = new ElementField_t [count];
+    e->mFieldCount = count;
+
+    for (size_t ct=0; ct < count; ct++) {
+        e->mFields[ct].e.set(ein[ct]);
+        e->mFields[ct].name.setTo(nin[ct], lengths[ct]);
+    }
+
+    return e;
+}
+
+
 ElementState::ElementState()
 {
 }
@@ -200,6 +281,7 @@
 {
 }
 
+
 /////////////////////////////////////////
 //
 
@@ -208,7 +290,10 @@
 
 void rsi_ElementBegin(Context *rsc)
 {
-    rsc->mStateElement.mComponentBuildList.clear();
+    ElementState * sec = &rsc->mStateElement;
+
+    sec->mBuildList.clear();
+    sec->mNames.clear();
 }
 
 void rsi_ElementAdd(Context *rsc, RsDataKind dk, RsDataType dt, bool isNormalized, size_t bits, const char *name)
@@ -217,28 +302,47 @@
 
     rsAssert(bits > 0);
 
-    Component *c = new Component(rsc,
-                                 static_cast<Component::DataKind>(dk),
-                                 static_cast<Component::DataType>(dt),
-                                 isNormalized,
-                                 bits,
-                                 name);
-    sec->mComponentBuildList.add(c);
+    Element *c = Element::create(rsc, dk, dt, isNormalized, bits);
+    sec->mBuildList.add(c);
+    if (name)
+        sec->mNames.add(String8(name));
+    else
+        sec->mNames.add(String8(""));
 }
 
 RsElement rsi_ElementCreate(Context *rsc)
 {
     ElementState * sec = &rsc->mStateElement;
-    Element *se = new Element(rsc, sec->mComponentBuildList.size());
 
-    rsAssert(se->getComponentCount() > 0);
+    size_t count = sec->mBuildList.size();
+    rsAssert(count > 0);
 
-    for (size_t ct = 0; ct < se->getComponentCount(); ct++) {
-        se->setComponent(ct, sec->mComponentBuildList[ct]);
+    if (count == 1) {
+        Element *se = sec->mBuildList[0];
+        se->incUserRef();
+        sec->mBuildList.clear();
+        sec->mNames.clear();
+        return se;
     }
 
-    rsc->mStateElement.mComponentBuildList.clear();
+    Element ** tmpElements = (Element **)calloc(count, sizeof(Element *));
+    const char ** tmpNames = (const char **)calloc(count, sizeof(char *));
+    size_t * tmpLengths = (size_t *)calloc(count, sizeof(size_t));
+
+
+    for (size_t ct = 0; ct < count; ct++) {
+        tmpElements[ct] = sec->mBuildList[ct];
+        tmpNames[ct] = sec->mNames[ct].string();
+        tmpLengths[ct] = sec->mNames[ct].length();
+    }
+    Element *se = Element::create(rsc, tmpElements, tmpNames, tmpLengths, count);
+
+    sec->mBuildList.clear();
+    sec->mNames.clear();
     se->incUserRef();
+    free(tmpElements);
+    free(tmpNames);
+    free(tmpLengths);
     return se;
 }