Merge change 26896 into eclair

* changes:
  ResultTransport needs a default value. If the thread is ununlocked by something else other than CallbackProxy's notify(), it can have a null value.
diff --git a/api/current.xml b/api/current.xml
index 9de4797..5b1e4d1 100644
--- a/api/current.xml
+++ b/api/current.xml
@@ -97573,6 +97573,32 @@
 <parameter name="stencilSize" type="int">
 </parameter>
 </method>
+<method name="setEGLContextFactory"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="factory" type="android.opengl.GLSurfaceView.EGLContextFactory">
+</parameter>
+</method>
+<method name="setEGLWindowSurfaceFactory"
+ return="void"
+ abstract="false"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="factory" type="android.opengl.GLSurfaceView.EGLWindowSurfaceFactory">
+</parameter>
+</method>
 <method name="setGLWrapper"
  return="void"
  abstract="false"
@@ -97725,6 +97751,92 @@
 </parameter>
 </method>
 </interface>
+<interface name="GLSurfaceView.EGLContextFactory"
+ abstract="true"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<method name="createContext"
+ return="javax.microedition.khronos.egl.EGLContext"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="egl" type="javax.microedition.khronos.egl.EGL10">
+</parameter>
+<parameter name="display" type="javax.microedition.khronos.egl.EGLDisplay">
+</parameter>
+<parameter name="eglConfig" type="javax.microedition.khronos.egl.EGLConfig">
+</parameter>
+</method>
+<method name="destroyContext"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="egl" type="javax.microedition.khronos.egl.EGL10">
+</parameter>
+<parameter name="display" type="javax.microedition.khronos.egl.EGLDisplay">
+</parameter>
+<parameter name="context" type="javax.microedition.khronos.egl.EGLContext">
+</parameter>
+</method>
+</interface>
+<interface name="GLSurfaceView.EGLWindowSurfaceFactory"
+ abstract="true"
+ static="true"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<method name="createWindowSurface"
+ return="javax.microedition.khronos.egl.EGLSurface"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="egl" type="javax.microedition.khronos.egl.EGL10">
+</parameter>
+<parameter name="display" type="javax.microedition.khronos.egl.EGLDisplay">
+</parameter>
+<parameter name="config" type="javax.microedition.khronos.egl.EGLConfig">
+</parameter>
+<parameter name="nativeWindow" type="java.lang.Object">
+</parameter>
+</method>
+<method name="destroySurface"
+ return="void"
+ abstract="true"
+ native="false"
+ synchronized="false"
+ static="false"
+ final="false"
+ deprecated="not deprecated"
+ visibility="public"
+>
+<parameter name="egl" type="javax.microedition.khronos.egl.EGL10">
+</parameter>
+<parameter name="display" type="javax.microedition.khronos.egl.EGLDisplay">
+</parameter>
+<parameter name="surface" type="javax.microedition.khronos.egl.EGLSurface">
+</parameter>
+</method>
+</interface>
 <interface name="GLSurfaceView.GLWrapper"
  abstract="true"
  static="true"
diff --git a/core/java/android/pim/vcard/VCardComposer.java b/core/java/android/pim/vcard/VCardComposer.java
index 3c01a9e..45f7ef3 100644
--- a/core/java/android/pim/vcard/VCardComposer.java
+++ b/core/java/android/pim/vcard/VCardComposer.java
@@ -1,12 +1,12 @@
 /*
  * Copyright (C) 2009 The Android Open Source Project
- * 
+ *
  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  * use this file except in compliance with the License. You may obtain a copy of
  * the License at
- * 
+ *
  * http://www.apache.org/licenses/LICENSE-2.0
- * 
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
@@ -38,6 +38,10 @@
 import android.provider.ContactsContract.CommonDataKinds.StructuredName;
 import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
 import android.provider.ContactsContract.CommonDataKinds.Website;
+import android.provider.CallLog.Calls;
+import android.provider.CallLog;
+import android.text.format.DateUtils;
+import android.text.format.Time;
 import android.text.TextUtils;
 import android.util.CharsetUtils;
 import android.util.Log;
@@ -61,11 +65,11 @@
  * completely differnt implementation from
  * android.syncml.pim.vcard.VCardComposer, which is not maintained anymore.
  * </p>
- * 
+ *
  * <p>
  * Usually, this class should be used like this.
  * </p>
- * 
+ *
  * <pre class="prettyprint"> VCardComposer composer = null; try { composer = new
  * VCardComposer(context); composer.addHandler(composer.new
  * HandlerForOutputStream(outputStream)); if (!composer.init()) { // Do
@@ -213,6 +217,9 @@
     private static final String VCARD_PROPERTY_X_NICKNAME = "X-NICKNAME";
     // TODO: add properties like X-LATITUDE
 
+    // Property for call log entry
+    private static final String VCARD_PROPERTY_X_TIMESTAMP = "X-IRMC-CALL-DATETIME";
+
     // Properties for DoCoMo vCard.
     private static final String VCARD_PROPERTY_X_CLASS = "X-CLASS";
     private static final String VCARD_PROPERTY_X_REDUCTION = "X-REDUCTION";
@@ -227,6 +234,7 @@
     private static final String VCARD_DATA_SEPARATOR = ":";
     private static final String VCARD_ITEM_SEPARATOR = ";";
     private static final String VCARD_WS = " ";
+    private static final String VCARD_ATTR_EQUAL = "=";
 
     // Type strings are now in VCardConstants.java.
 
@@ -238,20 +246,20 @@
     private static final String SHIFT_JIS = "SHIFT_JIS";
 
     private final Context mContext;
-    private final int mVCardType;
-    private final boolean mCareHandlerErrors;
-    private final ContentResolver mContentResolver;
+    private int mVCardType;
+    private boolean mCareHandlerErrors;
+    private ContentResolver mContentResolver;
 
     // Convenient member variables about the restriction of the vCard format.
     // Used for not calling the same methods returning same results.
-    private final boolean mIsV30;
-    private final boolean mIsJapaneseMobilePhone;
-    private final boolean mOnlyOneNoteFieldIsAvailable;
-    private final boolean mIsDoCoMo;
-    private final boolean mUsesQuotedPrintable;
-    private final boolean mUsesAndroidProperty;
-    private final boolean mUsesDefactProperty;
-    private final boolean mUsesShiftJis;
+    private boolean mIsV30;
+    private boolean mIsJapaneseMobilePhone;
+    private boolean mOnlyOneNoteFieldIsAvailable;
+    private boolean mIsDoCoMo;
+    private boolean mUsesQuotedPrintable;
+    private boolean mUsesAndroidProperty;
+    private boolean mUsesDefactProperty;
+    private boolean mUsesShiftJis;
 
     private Cursor mCursor;
     private int mIdColumn;
@@ -264,7 +272,7 @@
     private String mErrorReason = "No error";
 
     private static final Map<Integer, String> sImMap;
-    
+
     static {
         sImMap = new HashMap<Integer, String>();
         sImMap.put(Im.PROTOCOL_AIM, Constants.PROPERTY_X_AIM);
@@ -275,8 +283,27 @@
         sImMap.put(Im.PROTOCOL_SKYPE, Constants.PROPERTY_X_SKYPE_USERNAME);
         // Google talk is a special case.
     }
-    
-    
+
+    private boolean mIsCallLogComposer = false;
+
+    private static final String[] CONTACTS_PROJECTION = new String[] {
+        Contacts._ID,
+    };
+
+    /** The projection to use when querying the call log table */
+    private static final String[] CALL_LOG_PROJECTION = new String[] {
+            Calls.NUMBER, Calls.DATE, Calls.TYPE, Calls.CACHED_NAME, Calls.CACHED_NUMBER_TYPE,
+            Calls.CACHED_NUMBER_LABEL
+    };
+    private static final int NUMBER_COLUMN_INDEX = 0;
+    private static final int DATE_COLUMN_INDEX = 1;
+    private static final int CALL_TYPE_COLUMN_INDEX = 2;
+    private static final int CALLER_NAME_COLUMN_INDEX = 3;
+    private static final int CALLER_NUMBERTYPE_COLUMN_INDEX = 4;
+    private static final int CALLER_NUMBERLABEL_COLUMN_INDEX = 5;
+
+    private static final String FLAG_TIMEZONE_UTC = "Z";
+
     public VCardComposer(Context context) {
         this(context, VCardConfig.VCARD_TYPE_DEFAULT, true);
     }
@@ -287,10 +314,15 @@
                 careHandlerErrors);
     }
 
-    public VCardComposer(Context context, int vcardType, boolean careHandlerErrors) {
+    /**
+     * Construct for supporting call log entry vCard composing
+     */
+    public VCardComposer(Context context, int vcardType, boolean careHandlerErrors,
+            boolean isCallLogComposer) {
         mContext = context;
         mVCardType = vcardType;
         mCareHandlerErrors = careHandlerErrors;
+        mIsCallLogComposer = isCallLogComposer;
         mContentResolver = context.getContentResolver();
 
         mIsV30 = VCardConfig.isV30(vcardType);
@@ -320,6 +352,38 @@
         }
     }
 
+    public VCardComposer(Context context, int vcardType, boolean careHandlerErrors) {
+        this(context, vcardType, careHandlerErrors, false);
+    }
+
+    /**
+     * This static function is to compose vCard for phone own number
+     */
+    public String composeVCardForPhoneOwnNumber(int phonetype, String phoneName,
+            String phoneNumber, boolean vcardVer21) {
+        final StringBuilder builder = new StringBuilder();
+        appendVCardLine(builder, VCARD_PROPERTY_BEGIN, VCARD_DATA_VCARD);
+        if (!vcardVer21) {
+            appendVCardLine(builder, VCARD_PROPERTY_VERSION, Constants.VERSION_V30);
+        } else {
+            appendVCardLine(builder, VCARD_PROPERTY_VERSION, Constants.VERSION_V21);
+        }
+
+        boolean needCharset = false;
+        if (!(VCardUtils.containsOnlyAscii(phoneName))) {
+            needCharset = true;
+        }
+        appendVCardLine(builder, VCARD_PROPERTY_FULL_NAME, phoneName, needCharset, false);
+        appendVCardLine(builder, VCARD_PROPERTY_NAME, phoneName, needCharset, false);
+
+        String label = Integer.toString(phonetype);
+        appendVCardTelephoneLine(builder, phonetype, label, phoneNumber);
+
+        appendVCardLine(builder, VCARD_PROPERTY_END, VCARD_DATA_VCARD);
+
+        return builder.toString();
+    }
+
     /**
      * Must call before {{@link #init()}.
      */
@@ -357,11 +421,15 @@
             }
         }
 
-        final String[] projection = new String[] {Contacts._ID,};
+        if (mIsCallLogComposer) {
+            mCursor = mContentResolver.query(CallLog.Calls.CONTENT_URI, CALL_LOG_PROJECTION,
+                    selection, selectionArgs, null);
+        } else {
+            // TODO: thorow an appropriate exception!
+            mCursor = mContentResolver.query(RawContacts.CONTENT_URI, CONTACTS_PROJECTION,
+                    selection, selectionArgs, null);
+        }
 
-        // TODO: thorow an appropriate exception!
-        mCursor = mContentResolver.query(RawContacts.CONTENT_URI, projection,
-                selection, selectionArgs, null);
         if (mCursor == null || !mCursor.moveToFirst()) {
             if (mCursor != null) {
                 try {
@@ -376,7 +444,11 @@
             return false;
         }
 
-        mIdColumn = mCursor.getColumnIndex(Contacts._ID);
+        if (mIsCallLogComposer) {
+            mIdColumn = -1;
+        } else {
+            mIdColumn = mCursor.getColumnIndex(Contacts._ID);
+        }
 
         return true;
     }
@@ -390,7 +462,16 @@
         String name = null;
         String vcard;
         try {
-            vcard = createOneEntryInternal(mCursor.getString(mIdColumn));
+            if (mIsCallLogComposer) {
+                vcard = createOneCallLogEntryInternal();
+            } else {
+                if (mIdColumn >= 0) {
+                    vcard = createOneEntryInternal(mCursor.getString(mIdColumn));
+                } else {
+                    Log.e(LOG_TAG, "Incorrect mIdColumn: " + mIdColumn);
+                    return true;
+                }
+            }
         } catch (OutOfMemoryError error) {
             // Maybe some data (e.g. photo) is too big to have in memory. But it
             // should be rare.
@@ -422,6 +503,89 @@
         return true;
     }
 
+    /**
+     * Format according to RFC 2445 DATETIME type.
+     * The format is: ("%Y%m%dT%H%M%S").
+     */
+    private final String formatDate(final long millSecs) {
+        Time startDate = new Time();
+        startDate.set(millSecs);
+        String date = startDate.format2445();
+        return date + FLAG_TIMEZONE_UTC;
+    }
+
+    /**
+     * Create call history time stamp field.
+     *
+     * @param type call type
+     */
+    private String createCallHistoryTimeStampField(int type) {
+        // Extension for call history as defined in
+        // in the Specification for Ic Mobile Communcation - ver 1.1,
+        // Oct 2000. This is used to send the details of the call
+        // history - missed, incoming, outgoing along with date and time
+        // to the requesting device (For example, transferring phone book
+        // when connected over bluetooth)
+        // X-IRMC-CALL-DATETIME;MISSED:20050320T100000
+        final StringBuilder builder = new StringBuilder();
+        builder.append(VCARD_PROPERTY_X_TIMESTAMP);
+        builder.append(VCARD_ATTR_SEPARATOR);
+
+        if (mIsV30) {
+            builder.append(Constants.ATTR_TYPE).append(VCARD_ATTR_EQUAL);
+        }
+
+        if (type == Calls.INCOMING_TYPE) {
+            builder.append("INCOMING");
+        } else if (type == Calls.OUTGOING_TYPE) {
+            builder.append("OUTGOING");
+        } else if (type == Calls.MISSED_TYPE) {
+            builder.append("MISSED");
+        } else {
+            Log.w(LOG_TAG, "Call log type not correct.");
+            return null;
+        }
+
+        return builder.toString();
+    }
+
+    private String createOneCallLogEntryInternal() {
+        final StringBuilder builder = new StringBuilder();
+        appendVCardLine(builder, VCARD_PROPERTY_BEGIN, VCARD_DATA_VCARD);
+        if (mIsV30) {
+            appendVCardLine(builder, VCARD_PROPERTY_VERSION, Constants.VERSION_V30);
+        } else {
+            appendVCardLine(builder, VCARD_PROPERTY_VERSION, Constants.VERSION_V21);
+        }
+        String name = mCursor.getString(CALLER_NAME_COLUMN_INDEX);
+        if (TextUtils.isEmpty(name)) {
+            name = mCursor.getString(NUMBER_COLUMN_INDEX);
+        }
+        boolean needCharset = !(VCardUtils.containsOnlyAscii(name));
+        appendVCardLine(builder, VCARD_PROPERTY_FULL_NAME, name, needCharset, false);
+        appendVCardLine(builder, VCARD_PROPERTY_NAME, name, needCharset, false);
+
+        String number = mCursor.getString(NUMBER_COLUMN_INDEX);
+        int type = mCursor.getInt(CALLER_NUMBERTYPE_COLUMN_INDEX);
+        String label = mCursor.getString(CALLER_NUMBERLABEL_COLUMN_INDEX);
+        if (TextUtils.isEmpty(label)) {
+            label = Integer.toString(type);
+        }
+        appendVCardTelephoneLine(builder, type, label, number);
+
+        long date = mCursor.getLong(DATE_COLUMN_INDEX);
+        String dateClause = formatDate(date);
+        int callLogType = mCursor.getInt(CALL_TYPE_COLUMN_INDEX);
+        String timestampFeldString = createCallHistoryTimeStampField(callLogType);
+        if (timestampFeldString != null) {
+            appendVCardLine(builder, timestampFeldString, dateClause);
+        }
+
+        appendVCardLine(builder, VCARD_PROPERTY_END, VCARD_DATA_VCARD);
+
+        return builder.toString();
+    }
+
     private String createOneEntryInternal(final String contactId) {
         final StringBuilder builder = new StringBuilder();
         appendVCardLine(builder, VCARD_PROPERTY_BEGIN, VCARD_DATA_VCARD);
@@ -576,7 +740,7 @@
                 final String encodedPrefix = escapeCharacters(prefix);
                 final String encodedSuffix = escapeCharacters(suffix);
 
-                // N property. This order is specified by vCard spec and does not depend on countries. 
+                // N property. This order is specified by vCard spec and does not depend on countries.
                 builder.append(VCARD_PROPERTY_NAME);
                 if (!(VCardUtils.containsOnlyAscii(familyName) &&
                         VCardUtils.containsOnlyAscii(givenName) &&
@@ -584,7 +748,7 @@
                         VCardUtils.containsOnlyAscii(prefix) &&
                         VCardUtils.containsOnlyAscii(suffix))) {
                     builder.append(VCARD_ATTR_SEPARATOR);
-                    builder.append(mVCardAttributeCharset);   
+                    builder.append(mVCardAttributeCharset);
                 }
 
                 builder.append(VCARD_DATA_SEPARATOR);
@@ -658,7 +822,7 @@
                         // but we'll add this info since parser side may be able to
                         // use the charset via
                         // this attribute field.
-                        // 
+                        //
                         // e.g. Japanese mobile phones use Shift_Jis while RFC 2426
                         // recommends
                         // UTF-8. By adding this field, parsers may be able to know
@@ -684,12 +848,12 @@
                     builder.append(VCARD_ATTR_SEPARATOR);
                     builder.append(Constants.ATTR_TYPE_X_IRMC_N);
                     builder.append(VCARD_ATTR_SEPARATOR);
-                    
+
                     if (!(VCardUtils.containsOnlyAscii(phoneticFamilyName) &&
                             VCardUtils.containsOnlyAscii(phoneticMiddleName) &&
                             VCardUtils.containsOnlyAscii(phoneticGivenName))) {
                         builder.append(mVCardAttributeCharset);
-                        builder.append(VCARD_DATA_SEPARATOR);                        
+                        builder.append(VCARD_DATA_SEPARATOR);
                     }
 
                     builder.append(escapeCharacters(phoneticFamilyName));
@@ -841,7 +1005,7 @@
             builder.append(VCARD_COL_SEPARATOR);
         }
     }
-    
+
     /**
      * Try to append just one line. If there's no appropriate address
      * information, append an empty line.
@@ -907,10 +1071,10 @@
                     }
                     // TODO: add "X-GOOGLE TALK" case...
                 }
-            }            
+            }
         }
     }
-    
+
     private void appendWebsites(final StringBuilder builder,
             final Map<String, List<ContentValues>> contentValuesListMap) {
         List<ContentValues> contentValuesList = contentValuesListMap
@@ -922,7 +1086,7 @@
             }
         }
     }
-    
+
     private void appendBirthday(final StringBuilder builder,
             final Map<String, List<ContentValues>> contentValuesListMap) {
         List<ContentValues> contentValuesList = contentValuesListMap
@@ -1029,7 +1193,7 @@
     /**
      * Append '\' to the characters which should be escaped. The character set is different
      * not only between vCard 2.1 and vCard 3.0 but also among each device.
-     * 
+     *
      * Note that Quoted-Printable string must not be input here.
      */
     @SuppressWarnings("fallthrough")
@@ -1037,7 +1201,7 @@
         if (TextUtils.isEmpty(unescaped)) {
             return "";
         }
-        
+
         StringBuilder builder = new StringBuilder();
         final int length = unescaped.length();
         for (int i = 0; i < length; i++) {
@@ -1358,7 +1522,7 @@
             encodedData = encodeQuotedPrintable(rawData);
         } else {
             // TODO: one line may be too huge, which may be invalid in vCard spec, though
-            //       several (even well-known) applications do not care this. 
+            //       several (even well-known) applications do not care this.
             encodedData = escapeCharacters(rawData);
         }
 
diff --git a/core/java/com/google/android/mms/pdu/PduPersister.java b/core/java/com/google/android/mms/pdu/PduPersister.java
index 568aeb7..2a1f23a 100644
--- a/core/java/com/google/android/mms/pdu/PduPersister.java
+++ b/core/java/com/google/android/mms/pdu/PduPersister.java
@@ -855,6 +855,8 @@
         if (subject != null) {
             values.put(Mms.SUBJECT, toIsoString(subject.getTextString()));
             values.put(Mms.SUBJECT_CHARSET, subject.getCharacterSet());
+        } else {
+            values.put(Mms.SUBJECT, "");
         }
         
         long messageSize = sendReq.getMessageSize();
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index 1ce7083..b7cd21b 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -65,8 +65,6 @@
     native int  nContextCreate(int dev, Surface sur, int ver, boolean useDepth);
     native void nContextDestroy(int con);
 
-    //void rsContextBindSampler (uint32_t slot, RsSampler sampler);
-    //void rsContextBindRootScript (RsScript sampler);
     native void nContextBindRootScript(int script);
     native void nContextBindSampler(int sampler, int slot);
     native void nContextBindProgramFragmentStore(int pfs);
@@ -92,7 +90,6 @@
     native void nTypeSetupFields(Type t, int[] types, int[] bits, Field[] IDs);
 
     native int  nAllocationCreateTyped(int type);
-    //native int  nAllocationCreateSized(int elem, int count);
     native int  nAllocationCreateFromBitmap(int dstFmt, boolean genMips, Bitmap bmp);
     native int  nAllocationCreateFromBitmapBoxed(int dstFmt, boolean genMips, Bitmap bmp);
     native int  nAllocationCreateFromAssetStream(int dstFmt, boolean genMips, int assetStream);
@@ -112,15 +109,6 @@
     native void nAllocationSubDataFromObject(int id, Type t, int offset, Object o);
     native void nAllocationSubReadFromObject(int id, Type t, int offset, Object o);
 
-    native void nTriangleMeshBegin(int vertex, int index);
-    native void nTriangleMeshAddVertex_XY (float x, float y);
-    native void nTriangleMeshAddVertex_XYZ (float x, float y, float z);
-    native void nTriangleMeshAddVertex_XY_ST (float x, float y, float s, float t);
-    native void nTriangleMeshAddVertex_XYZ_ST (float x, float y, float z, float s, float t);
-    native void nTriangleMeshAddVertex_XYZ_ST_NORM (float x, float y, float z, float s, float t, float nx, float ny, float nz);
-    native void nTriangleMeshAddTriangle(int i1, int i2, int i3);
-    native int  nTriangleMeshCreate();
-
     native void nAdapter1DBindAllocation(int ad, int alloc);
     native void nAdapter1DSetConstraint(int ad, int dim, int value);
     native void nAdapter1DData(int ad, int[] d);
@@ -230,49 +218,6 @@
     }
 
     //////////////////////////////////////////////////////////////////////////////////
-    // Triangle Mesh
-
-    public class TriangleMesh extends BaseObj {
-        TriangleMesh(int id) {
-            super(RenderScript.this);
-            mID = id;
-        }
-    }
-
-    public void triangleMeshBegin(Element vertex, Element index) {
-        nTriangleMeshBegin(vertex.mID, index.mID);
-    }
-
-    public void triangleMeshAddVertex_XY(float x, float y) {
-        nTriangleMeshAddVertex_XY(x, y);
-    }
-
-    public void triangleMeshAddVertex_XYZ(float x, float y, float z) {
-        nTriangleMeshAddVertex_XYZ(x, y, z);
-    }
-
-    public void triangleMeshAddVertex_XY_ST(float x, float y, float s, float t) {
-        nTriangleMeshAddVertex_XY_ST(x, y, s, t);
-    }
-
-    public void triangleMeshAddVertex_XYZ_ST(float x, float y, float z, float s, float t) {
-        nTriangleMeshAddVertex_XYZ_ST(x, y, z, s, t);
-    }
-
-    public void triangleMeshAddVertex_XYZ_ST_NORM(float x, float y, float z, float s, float t, float nx, float ny, float nz) {
-        nTriangleMeshAddVertex_XYZ_ST_NORM(x, y, z, s, t, nx, ny, nz);
-    }
-
-    public void triangleMeshAddTriangle(int i1, int i2, int i3) {
-        nTriangleMeshAddTriangle(i1, i2, i3);
-    }
-
-    public TriangleMesh triangleMeshCreate() {
-        int id = nTriangleMeshCreate();
-        return new TriangleMesh(id);
-    }
-
-    //////////////////////////////////////////////////////////////////////////////////
     // File
 
     public class File extends BaseObj {
@@ -301,32 +246,31 @@
     ///////////////////////////////////////////////////////////////////////////////////
     // Root state
 
-    public void contextBindRootScript(Script s) {
-        int id = 0;
-        if(s != null) {
-            id = s.mID;
+    private int safeID(BaseObj o) {
+        if(o != null) {
+            return o.mID;
         }
-        nContextBindRootScript(id);
+        return 0;
     }
 
-    //public void contextBindSampler(Sampler s, int slot) {
-        //nContextBindSampler(s.mID);
-    //}
-
-    public void contextBindProgramFragmentStore(ProgramStore pfs) {
-        nContextBindProgramFragmentStore(pfs.mID);
+    public void contextBindRootScript(Script s) {
+        nContextBindRootScript(safeID(s));
     }
 
-    public void contextBindProgramFragment(ProgramFragment pf) {
-        nContextBindProgramFragment(pf.mID);
+    public void contextBindProgramFragmentStore(ProgramStore p) {
+        nContextBindProgramFragmentStore(safeID(p));
     }
 
-    public void contextBindProgramRaster(ProgramRaster pf) {
-        nContextBindProgramRaster(pf.mID);
+    public void contextBindProgramFragment(ProgramFragment p) {
+        nContextBindProgramFragment(safeID(p));
     }
 
-    public void contextBindProgramVertex(ProgramVertex pf) {
-        nContextBindProgramVertex(pf.mID);
+    public void contextBindProgramRaster(ProgramRaster p) {
+        nContextBindProgramRaster(safeID(p));
+    }
+
+    public void contextBindProgramVertex(ProgramVertex p) {
+        nContextBindProgramVertex(safeID(p));
     }
 
 }
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 4a8f8a3..f86d86a 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -603,76 +603,6 @@
     free(bufAlloc);
 }
 
-// -----------------------------------
-
-static void
-nTriangleMeshBegin(JNIEnv *_env, jobject _this, jint v, jint i)
-{
-    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
-    LOG_API("nTriangleMeshBegin, con(%p), vertex(%p), index(%p)", con, (RsElement)v, (RsElement)i);
-    rsTriangleMeshBegin(con, (RsElement)v, (RsElement)i);
-}
-
-static void
-nTriangleMeshAddVertex_XY(JNIEnv *_env, jobject _this, jfloat x, jfloat y)
-{
-    float v[] = {x, y};
-    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
-    LOG_API("nTriangleMeshAddVertex_XY, con(%p), x(%f), y(%f)", con, x, y);
-    rsTriangleMeshAddVertex(con, v);
-}
-
-static void
-nTriangleMeshAddVertex_XYZ(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z)
-{
-    float v[] = {x, y, z};
-    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
-    LOG_API("nTriangleMeshAddVertex_XYZ, con(%p), x(%f), y(%f), z(%f)", con, x, y, z);
-    rsTriangleMeshAddVertex(con, v);
-}
-
-static void
-nTriangleMeshAddVertex_XY_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat s, jfloat t)
-{
-    float v[] = {s, t, x, y};
-    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
-    LOG_API("nTriangleMeshAddVertex_XY_ST, con(%p), x(%f), y(%f), s(%f), t(%f)", con, x, y, s, t);
-    rsTriangleMeshAddVertex(con, v);
-}
-
-static void
-nTriangleMeshAddVertex_XYZ_ST(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t)
-{
-    float v[] = {s, t, x, y, z};
-    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
-    LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t);
-    rsTriangleMeshAddVertex(con, v);
-}
-
-static void
-nTriangleMeshAddVertex_XYZ_ST_NORM(JNIEnv *_env, jobject _this, jfloat x, jfloat y, jfloat z, jfloat s, jfloat t, jfloat nx, jfloat ny, jfloat nz)
-{
-    float v[] = {nx, ny, nz, s, t, x, y, z};
-    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
-    LOG_API("nTriangleMeshAddVertex_XYZ_ST, con(%p), x(%f), y(%f), z(%f), s(%f), t(%f)", con, x, y, z, s, t);
-    rsTriangleMeshAddVertex(con, v);
-}
-
-static void
-nTriangleMeshAddTriangle(JNIEnv *_env, jobject _this, jint i1, jint i2, jint i3)
-{
-    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
-    LOG_API("nTriangleMeshAddTriangle, con(%p), i1(%i), i2(%i), i3(%i)", con, i1, i2, i3);
-    rsTriangleMeshAddTriangle(con, i1, i2, i3);
-}
-
-static jint
-nTriangleMeshCreate(JNIEnv *_env, jobject _this)
-{
-    RsContext con = (RsContext)(_env->GetIntField(_this, gContextId));
-    LOG_API("nTriangleMeshCreate, con(%p)", con);
-    return (jint) rsTriangleMeshCreate(con);
-}
 
 // -----------------------------------
 
@@ -1385,15 +1315,6 @@
 {"nAllocationSubDataFromObject",   "(ILandroid/renderscript/Type;ILjava/lang/Object;)V",   (void*)nAllocationSubDataFromObject },
 {"nAllocationSubReadFromObject",   "(ILandroid/renderscript/Type;ILjava/lang/Object;)V",   (void*)nAllocationSubReadFromObject },
 
-{"nTriangleMeshBegin",             "(II)V",                                (void*)nTriangleMeshBegin },
-{"nTriangleMeshAddVertex_XY",      "(FF)V",                                (void*)nTriangleMeshAddVertex_XY },
-{"nTriangleMeshAddVertex_XYZ",     "(FFF)V",                               (void*)nTriangleMeshAddVertex_XYZ },
-{"nTriangleMeshAddVertex_XY_ST",   "(FFFF)V",                              (void*)nTriangleMeshAddVertex_XY_ST },
-{"nTriangleMeshAddVertex_XYZ_ST",  "(FFFFF)V",                             (void*)nTriangleMeshAddVertex_XYZ_ST },
-{"nTriangleMeshAddVertex_XYZ_ST_NORM",  "(FFFFFFFF)V",                     (void*)nTriangleMeshAddVertex_XYZ_ST_NORM },
-{"nTriangleMeshAddTriangle",       "(III)V",                               (void*)nTriangleMeshAddTriangle },
-{"nTriangleMeshCreate",            "()I",                                  (void*)nTriangleMeshCreate },
-
 {"nAdapter1DBindAllocation",       "(II)V",                                (void*)nAdapter1DBindAllocation },
 {"nAdapter1DSetConstraint",        "(III)V",                               (void*)nAdapter1DSetConstraint },
 {"nAdapter1DData",                 "(I[I)V",                               (void*)nAdapter1DData_i },
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index 2c17599..262ac8d 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -98,8 +98,7 @@
 	rsScriptC_Lib.cpp \
 	rsSimpleMesh.cpp \
 	rsThreadIO.cpp \
-	rsType.cpp \
-	rsTriangleMesh.cpp
+	rsType.cpp
 
 LOCAL_SHARED_LIBRARIES += libcutils libutils libEGL libGLESv1_CM libui libacc
 LOCAL_LDLIBS := -lpthread -ldl
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h
index 9f18b78..87a2f4a 100644
--- a/libs/rs/RenderScript.h
+++ b/libs/rs/RenderScript.h
@@ -37,7 +37,6 @@
 typedef void * RsSampler;
 typedef void * RsScript;
 typedef void * RsScriptBasicTemp;
-typedef void * RsTriangleMesh;
 typedef void * RsSimpleMesh;
 typedef void * RsType;
 typedef void * RsLight;
@@ -91,32 +90,6 @@
     RS_KIND_POINT_SIZE
 };
 
-enum RsElementPredefined {
-    RS_ELEMENT_USER_U8,
-    RS_ELEMENT_USER_I8,
-    RS_ELEMENT_USER_U16,
-    RS_ELEMENT_USER_I16,
-    RS_ELEMENT_USER_U32,
-    RS_ELEMENT_USER_I32,
-    RS_ELEMENT_USER_FLOAT,
-
-    RS_ELEMENT_A_8,          // 7
-    RS_ELEMENT_RGB_565,      // 8
-    RS_ELEMENT_RGBA_5551,    // 9
-    RS_ELEMENT_RGBA_4444,    // 10
-    RS_ELEMENT_RGB_888,      // 11
-    RS_ELEMENT_RGBA_8888,    // 12
-
-    RS_ELEMENT_INDEX_16, //13
-    RS_ELEMENT_INDEX_32,
-    RS_ELEMENT_XY_F32,
-    RS_ELEMENT_XYZ_F32,
-    RS_ELEMENT_ST_XY_F32,
-    RS_ELEMENT_ST_XYZ_F32,
-    RS_ELEMENT_NORM_XYZ_F32,
-    RS_ELEMENT_NORM_ST_XYZ_F32,
-};
-
 enum RsSamplerParam {
     RS_SAMPLER_MIN_FILTER,
     RS_SAMPLER_MAG_FILTER,
diff --git a/libs/rs/RenderScriptEnv.h b/libs/rs/RenderScriptEnv.h
index 5eb8912..ff0a7b1 100644
--- a/libs/rs/RenderScriptEnv.h
+++ b/libs/rs/RenderScriptEnv.h
@@ -10,7 +10,6 @@
 typedef void * RsSampler;
 typedef void * RsScript;
 typedef void * RsScriptBasicTemp;
-typedef void * RsTriangleMesh;
 typedef void * RsSimpleMesh;
 typedef void * RsType;
 typedef void * RsProgramFragment;
diff --git a/libs/rs/rs.spec b/libs/rs/rs.spec
index d7ae532..8cdf2b7 100644
--- a/libs/rs/rs.spec
+++ b/libs/rs/rs.spec
@@ -55,11 +55,6 @@
 	ret RsElement
 	}
 
-ElementGetPredefined {
-	param RsElementPredefined predef
-	ret RsElement
-	}
-
 TypeBegin {
 	param RsElement type
 	}
@@ -78,24 +73,12 @@
 	ret RsAllocation
 	}
 
-AllocationCreatePredefSized {
-	param RsElementPredefined predef
-	param size_t count
-	ret RsAllocation
-	}
-
 AllocationCreateSized {
 	param RsElement e
 	param size_t count
 	ret RsAllocation
 	}
 
-AllocationCreateFromFile {
-	param const char *file
-	param bool genMips
-	ret RsAllocation
-	}
-
 AllocationCreateFromBitmap {
 	param uint32_t width
 	param uint32_t height
@@ -229,36 +212,6 @@
 	}
 
 
-TriangleMeshBegin {
-	param RsElement vertex
-	param RsElement index
-	}
-
-TriangleMeshAddVertex {
-	param const void *vtx
-	}
-
-TriangleMeshAddTriangle {
-	param uint32_t idx1
-	param uint32_t idx2
-	param uint32_t idx3
-	}
-
-TriangleMeshCreate {
-	ret RsTriangleMesh
-	}
-
-
-TriangleMeshRender {
-	param RsTriangleMesh vtm
-	}
-
-TriangleMeshRenderRange {
-	param RsTriangleMesh vtm
-	param uint32_t start
-	param uint32_t count
-	}
-
 
 ScriptBindAllocation {
 	param RsScript vtm
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index c267e16..cb82624 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -191,12 +191,6 @@
     return alloc;
 }
 
-RsAllocation rsi_AllocationCreatePredefSized(Context *rsc, RsElementPredefined t, size_t count)
-{
-    RsElement e = rsi_ElementGetPredefined(rsc, t);
-    return rsi_AllocationCreateSized(rsc, e, count);
-}
-
 RsAllocation rsi_AllocationCreateSized(Context *rsc, RsElement e, size_t count)
 {
     Type * type = new Type();
@@ -421,116 +415,6 @@
 
 }
 
-
-RsAllocation rsi_AllocationCreateFromFile(Context *rsc, const char *file, bool genMips)
-{
-    bool use32bpp = false;
-
-    typedef struct _Win3xBitmapHeader
-    {
-       uint16_t type;
-       uint32_t totalSize;
-       uint32_t reserved;
-       uint32_t offset;
-       int32_t hdrSize;            /* Size of this header in bytes */
-       int32_t width;           /* Image width in pixels */
-       int32_t height;          /* Image height in pixels */
-       int16_t planes;          /* Number of color planes */
-       int16_t bpp;             /* Number of bits per pixel */
-       /* Fields added for Windows 3.x follow this line */
-       int32_t compression;     /* Compression methods used */
-       int32_t sizeOfBitmap;    /* Size of bitmap in bytes */
-       int32_t horzResolution;  /* Horizontal resolution in pixels per meter */
-       int32_t vertResolution;  /* Vertical resolution in pixels per meter */
-       int32_t colorsUsed;      /* Number of colors in the image */
-       int32_t colorsImportant; /* Minimum number of important colors */
-    } __attribute__((__packed__)) WIN3XBITMAPHEADER;
-
-    _Win3xBitmapHeader hdr;
-
-    FILE *f = fopen(file, "rb");
-    if (f == NULL) {
-        LOGE("rsAllocationCreateFromBitmap failed to open file %s", file);
-        return NULL;
-    }
-    memset(&hdr, 0, sizeof(hdr));
-    fread(&hdr, sizeof(hdr), 1, f);
-
-    if (hdr.bpp != 24) {
-        LOGE("Unsuported BMP type");
-        fclose(f);
-        return NULL;
-    }
-
-    int32_t texWidth = rsHigherPow2(hdr.width);
-    int32_t texHeight = rsHigherPow2(hdr.height);
-
-    if (use32bpp) {
-        rsi_TypeBegin(rsc, rsi_ElementGetPredefined(rsc, RS_ELEMENT_RGBA_8888));
-    } else {
-        rsi_TypeBegin(rsc, rsi_ElementGetPredefined(rsc, RS_ELEMENT_RGB_565));
-    }
-    rsi_TypeAdd(rsc, RS_DIMENSION_X, texWidth);
-    rsi_TypeAdd(rsc, RS_DIMENSION_Y, texHeight);
-    if (genMips) {
-        rsi_TypeAdd(rsc, RS_DIMENSION_LOD, 1);
-    }
-    RsType type = rsi_TypeCreate(rsc);
-
-    RsAllocation vTexAlloc = rsi_AllocationCreateTyped(rsc, type);
-    Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
-    texAlloc->incUserRef();
-    if (texAlloc == NULL) {
-        LOGE("Memory allocation failure");
-        fclose(f);
-        return NULL;
-    }
-
-    // offset to letterbox if height is not pow2
-    Adapter2D adapt(texAlloc);
-    uint8_t * fileInBuf = new uint8_t[texWidth * 3];
-    uint32_t yOffset = (hdr.width - hdr.height) / 2;
-
-    if (use32bpp) {
-        uint8_t *tmp = static_cast<uint8_t *>(adapt.getElement(0, yOffset));
-        for (int y=0; y < hdr.height; y++) {
-            fseek(f, hdr.offset + (y*hdr.width*3), SEEK_SET);
-            fread(fileInBuf, 1, hdr.width * 3, f);
-            for(int x=0; x < hdr.width; x++) {
-                tmp[0] = fileInBuf[x*3 + 2];
-                tmp[1] = fileInBuf[x*3 + 1];
-                tmp[2] = fileInBuf[x*3];
-                tmp[3] = 0xff;
-                tmp += 4;
-            }
-        }
-    } else {
-        uint16_t *tmp = static_cast<uint16_t *>(adapt.getElement(0, yOffset));
-        for (int y=0; y < hdr.height; y++) {
-            fseek(f, hdr.offset + (y*hdr.width*3), SEEK_SET);
-            fread(fileInBuf, 1, hdr.width * 3, f);
-            for(int x=0; x < hdr.width; x++) {
-                *tmp = rs888to565(fileInBuf[x*3 + 2], fileInBuf[x*3 + 1], fileInBuf[x*3]);
-                tmp++;
-            }
-        }
-    }
-
-    fclose(f);
-    delete [] fileInBuf;
-
-    if (genMips) {
-        Adapter2D adapt2(texAlloc);
-        for(uint32_t lod=0; lod < (texAlloc->getType()->getLODCount() -1); lod++) {
-            adapt.setLOD(lod);
-            adapt2.setLOD(lod + 1);
-            mip(adapt2, adapt);
-        }
-    }
-
-    return texAlloc;
-}
-
 void rsi_AllocationData(Context *rsc, RsAllocation va, const void *data, uint32_t sizeBytes)
 {
     Allocation *a = static_cast<Allocation *>(va);
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 1fb697a..8cabf87 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -25,7 +25,6 @@
 #include "rsType.h"
 #include "rsMatrix.h"
 #include "rsAllocation.h"
-#include "rsTriangleMesh.h"
 #include "rsSimpleMesh.h"
 #include "rsMesh.h"
 #include "rsDevice.h"
@@ -70,8 +69,6 @@
     ProgramVertexState mStateVertex;
     LightState mStateLight;
 
-    TriangleMeshContext mStateTriangleMesh;
-
     ScriptCState mScriptC;
 
     void swapBuffers();
diff --git a/libs/rs/rsElement.cpp b/libs/rs/rsElement.cpp
index 6794522..b5267b3 100644
--- a/libs/rs/rsElement.cpp
+++ b/libs/rs/rsElement.cpp
@@ -21,170 +21,6 @@
 using namespace android;
 using namespace android::renderscript;
 
-void ElementState::initPredefined()
-{
-    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, 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, 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, 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, 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, 0);
-    Component * idx_32 = new Component(Component::INDEX,  Component::UNSIGNED,  false, 32, 0);
-
-    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, 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, 0);
-    Component * t    = new Component(Component::T,      Component::FLOAT,     false, 32, 0);
-
-    Element * e;
-
-    e = new Element(1);
-    e->setComponent(0, u_8);
-    mPredefinedList.add(Predefined(RS_ELEMENT_USER_U8, e));
-
-    e = new Element(1);
-    e->setComponent(0, i_8);
-    mPredefinedList.add(Predefined(RS_ELEMENT_USER_I8, e));
-
-    e = new Element(1);
-    e->setComponent(0, u_16);
-    mPredefinedList.add(Predefined(RS_ELEMENT_USER_U16, e));
-
-    e = new Element(1);
-    e->setComponent(0, i_16);
-    mPredefinedList.add(Predefined(RS_ELEMENT_USER_I16, e));
-
-    e = new Element(1);
-    e->setComponent(0, u_32);
-    mPredefinedList.add(Predefined(RS_ELEMENT_USER_U32, e));
-
-    e = new Element(1);
-    e->setComponent(0, i_32);
-    mPredefinedList.add(Predefined(RS_ELEMENT_USER_I32, e));
-
-    e = new Element(1);
-    e->setComponent(0, f_32);
-    mPredefinedList.add(Predefined(RS_ELEMENT_USER_FLOAT, e));
-
-    e = new Element(1);
-    e->setComponent(0, a_8);
-    mPredefinedList.add(Predefined(RS_ELEMENT_A_8, e));
-
-    e = new Element(3);
-    e->setComponent(0, r_5);
-    e->setComponent(1, g_6);
-    e->setComponent(2, b_5);
-    mPredefinedList.add(Predefined(RS_ELEMENT_RGB_565, e));
-
-    e = new Element(4);
-    e->setComponent(0, r_5);
-    e->setComponent(1, g_5);
-    e->setComponent(2, b_5);
-    e->setComponent(3, a_1);
-    mPredefinedList.add(Predefined(RS_ELEMENT_RGBA_5551, e));
-
-    e = new Element(4);
-    e->setComponent(0, r_4);
-    e->setComponent(1, g_4);
-    e->setComponent(2, b_4);
-    e->setComponent(3, a_4);
-    mPredefinedList.add(Predefined(RS_ELEMENT_RGBA_4444, e));
-
-    e = new Element(3);
-    e->setComponent(0, r_8);
-    e->setComponent(1, g_8);
-    e->setComponent(2, b_8);
-    mPredefinedList.add(Predefined(RS_ELEMENT_RGB_888, e));
-
-    e = new Element(4);
-    e->setComponent(0, r_8);
-    e->setComponent(1, g_8);
-    e->setComponent(2, b_8);
-    e->setComponent(3, a_8);
-    mPredefinedList.add(Predefined(RS_ELEMENT_RGBA_8888, e));
-
-    e = new Element(1);
-    e->setComponent(0, idx_16);
-    mPredefinedList.add(Predefined(RS_ELEMENT_INDEX_16, e));
-
-    e = new Element(1);
-    e->setComponent(0, idx_32);
-    mPredefinedList.add(Predefined(RS_ELEMENT_INDEX_32, e));
-
-    e = new Element(2);
-    e->setComponent(0, x);
-    e->setComponent(1, y);
-    mPredefinedList.add(Predefined(RS_ELEMENT_XY_F32, e));
-
-    e = new Element(3);
-    e->setComponent(0, x);
-    e->setComponent(1, y);
-    e->setComponent(2, z);
-    mPredefinedList.add(Predefined(RS_ELEMENT_XYZ_F32, e));
-
-    e = new Element(4);
-    e->setComponent(0, s);
-    e->setComponent(1, t);
-    e->setComponent(2, x);
-    e->setComponent(3, y);
-    mPredefinedList.add(Predefined(RS_ELEMENT_ST_XY_F32, e));
-
-    e = new Element(5);
-    e->setComponent(0, s);
-    e->setComponent(1, t);
-    e->setComponent(2, x);
-    e->setComponent(3, y);
-    e->setComponent(4, z);
-    mPredefinedList.add(Predefined(RS_ELEMENT_ST_XYZ_F32, e));
-
-    e = new Element(6);
-    e->setComponent(0, nx);
-    e->setComponent(1, ny);
-    e->setComponent(2, nz);
-    e->setComponent(3, x);
-    e->setComponent(4, y);
-    e->setComponent(5, z);
-    mPredefinedList.add(Predefined(RS_ELEMENT_NORM_XYZ_F32, e));
-
-    e = new Element(8);
-    e->setComponent(0, nx);
-    e->setComponent(1, ny);
-    e->setComponent(2, nz);
-    e->setComponent(3, s);
-    e->setComponent(4, t);
-    e->setComponent(5, x);
-    e->setComponent(6, y);
-    e->setComponent(7, z);
-    mPredefinedList.add(Predefined(RS_ELEMENT_NORM_ST_XYZ_F32, e));
-}
-
 
 Element::Element()
 {
@@ -358,39 +194,6 @@
     rsc->mStateElement.mComponentBuildList.clear();
 }
 
-void rsi_ElementAddPredefined(Context *rsc, RsElementPredefined predef)
-{
-    ElementState * sec = &rsc->mStateElement;
-
-    RsElement ve = rsi_ElementGetPredefined(rsc, predef);
-    const Element *e = static_cast<const Element *>(ve);
-
-    for(size_t ct = 0; ct < sec->mPredefinedList[predef].mElement->getComponentCount(); ct++) {
-        sec->mComponentBuildList.add(sec->mPredefinedList[predef].mElement->getComponent(ct));
-    }
-}
-
-RsElement rsi_ElementGetPredefined(Context *rsc, RsElementPredefined predef)
-{
-    ElementState * sec = &rsc->mStateElement;
-
-    if (!sec->mPredefinedList.size()) {
-        sec->initPredefined();
-    }
-
-    if ((predef < 0) ||
-        (static_cast<uint32_t>(predef) >= sec->mPredefinedList.size())) {
-        LOGE("rsElementGetPredefined: Request for bad predefined type");
-        // error
-        return NULL;
-    }
-
-    rsAssert(sec->mPredefinedList[predef].mEnum == predef);
-    Element * e = sec->mPredefinedList[predef].mElement;
-    e->incUserRef();
-    return e;
-}
-
 void rsi_ElementAdd(Context *rsc, RsDataKind dk, RsDataType dt, bool isNormalized, size_t bits, const char *name)
 {
     ElementState * sec = &rsc->mStateElement;
diff --git a/libs/rs/rsElement.h b/libs/rs/rsElement.h
index 0918522..7b5a83d 100644
--- a/libs/rs/rsElement.h
+++ b/libs/rs/rsElement.h
@@ -69,24 +69,6 @@
     ~ElementState();
 
     Vector<Component *> mComponentBuildList;
-
-
-
-    struct Predefined {
-        Predefined() {
-            mElement = NULL;
-        }
-        Predefined(RsElementPredefined en, Element *e) {
-            mEnum = en;
-            mElement = e;
-        }
-        RsElementPredefined mEnum;
-        Element * mElement;
-    };
-    Vector<Predefined> mPredefinedList;
-
-    void initPredefined();
-
 };
 
 
diff --git a/libs/rs/rsProgramVertex.cpp b/libs/rs/rsProgramVertex.cpp
index a07e166..dda56d7 100644
--- a/libs/rs/rsProgramVertex.cpp
+++ b/libs/rs/rsProgramVertex.cpp
@@ -133,9 +133,16 @@
 
 void ProgramVertexState::init(Context *rsc, int32_t w, int32_t h)
 {
+    rsi_ElementBegin(rsc);
+    rsi_ElementAdd(rsc, RS_KIND_USER, RS_TYPE_FLOAT, false, 32, NULL);
+    RsElement e = rsi_ElementCreate(rsc);
+
+    rsi_TypeBegin(rsc, e);
+    rsi_TypeAdd(rsc, RS_DIMENSION_X, 48);
+    mAllocType = rsi_TypeCreate(rsc);
+
     ProgramVertex *pv = new ProgramVertex(NULL, NULL);
-    Allocation *alloc = (Allocation *)
-        rsi_AllocationCreatePredefSized(rsc, RS_ELEMENT_USER_FLOAT, 48);
+    Allocation *alloc = (Allocation *)rsi_AllocationCreateTyped(rsc, mAllocType);
     mDefaultAlloc.set(alloc);
     mDefault.set(pv);
 
diff --git a/libs/rs/rsProgramVertex.h b/libs/rs/rsProgramVertex.h
index 523c3ed..32d147c 100644
--- a/libs/rs/rsProgramVertex.h
+++ b/libs/rs/rsProgramVertex.h
@@ -64,7 +64,7 @@
     ObjectBaseRef<ProgramVertex> mLast;
     ObjectBaseRef<Allocation> mDefaultAlloc;
 
-
+    RsType mAllocType;
 
     ProgramVertex *mPV;
 
diff --git a/libs/rs/rsScriptC_Lib.cpp b/libs/rs/rsScriptC_Lib.cpp
index 6dc3e8b..f5f182f 100644
--- a/libs/rs/rsScriptC_Lib.cpp
+++ b/libs/rs/rsScriptC_Lib.cpp
@@ -92,24 +92,17 @@
     return i + offset;
 }
 
-static float* SC_loadTriangleMeshVerticesF(RsTriangleMesh mesh)
+static float* SC_loadSimpleMeshVerticesF(RsSimpleMesh mesh, uint32_t idx)
 {
-    TriangleMesh *tm = static_cast<TriangleMesh *>(mesh);
-    void *vp = tm->mVertexData;
-    float *f = static_cast<float *>(vp);
-    return f;
+    SimpleMesh *tm = static_cast<SimpleMesh *>(mesh);
+    void *vp = tm->mVertexBuffers[idx]->getPtr();;
+    return static_cast<float *>(vp);
 }
 
-static void SC_updateTriangleMesh(RsTriangleMesh mesh)
+static void SC_updateSimpleMesh(RsSimpleMesh mesh)
 {
-    TriangleMesh *tm = static_cast<TriangleMesh *>(mesh);
-    glBindBuffer(GL_ARRAY_BUFFER, tm->mBufferObjects[0]);
-    glBufferData(GL_ARRAY_BUFFER, tm->mVertexDataSize, tm->mVertexData, GL_STATIC_DRAW);
-    glBindBuffer(GL_ARRAY_BUFFER, 0);
-
-    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
-    glBufferData(GL_ELEMENT_ARRAY_BUFFER, tm->mIndexDataSize, tm->mIndexData, GL_STATIC_DRAW);
-    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
+    SimpleMesh *sm = static_cast<SimpleMesh *>(mesh);
+    sm->uploadAll();
 }
 
 static uint32_t SC_loadU32(uint32_t bank, uint32_t offset)
@@ -661,18 +654,6 @@
 // Drawing
 //////////////////////////////////////////////////////////////////////////////
 
-static void SC_drawTriangleMesh(RsTriangleMesh mesh)
-{
-    GET_TLS();
-    rsi_TriangleMeshRender(rsc, mesh);
-}
-
-static void SC_drawTriangleMeshRange(RsTriangleMesh mesh, uint32_t start, uint32_t count)
-{
-    GET_TLS();
-    rsi_TriangleMeshRenderRange(rsc, mesh, start, count);
-}
-
 static void SC_drawLine(float x1, float y1, float z1,
                         float x2, float y2, float z2)
 {
@@ -988,9 +969,9 @@
         "void", "(int, int, float *)" },
     { "storeMatrix", (void *)&SC_storeMatrix,
         "void", "(int, int, float *)" },
-    { "loadTriangleMeshVerticesF", (void *)&SC_loadTriangleMeshVerticesF,
-        "float*", "(int)" },
-    { "updateTriangleMesh", (void *)&SC_updateTriangleMesh,
+    { "loadSimpleMeshVerticesF", (void *)&SC_loadSimpleMeshVerticesF,
+        "float*", "(int, int)" },
+    { "updateSimpleMesh", (void *)&SC_updateSimpleMesh,
         "void", "(int)" },
 
     // math
@@ -1172,10 +1153,6 @@
         "void", "(float x1, float y1, float z1, float x2, float y2, float z2, float x3, float y3, float z3, float x4, float y4, float z4)" },
     { "drawQuadTexCoords", (void *)&SC_drawQuadTexCoords,
         "void", "(float x1, float y1, float z1, float u1, float v1, float x2, float y2, float z2, float u2, float v2, float x3, float y3, float z3, float u3, float v3, float x4, float y4, float z4, float u4, float v4)" },
-    { "drawTriangleMesh", (void *)&SC_drawTriangleMesh,
-        "void", "(int mesh)" },
-    { "drawTriangleMeshRange", (void *)&SC_drawTriangleMeshRange,
-        "void", "(int mesh, int start, int count)" },
     { "drawLine", (void *)&SC_drawLine,
         "void", "(float x1, float y1, float z1, float x2, float y2, float z2)" },
     { "drawSimpleMesh", (void *)&SC_drawSimpleMesh,
diff --git a/libs/rs/rsSimpleMesh.cpp b/libs/rs/rsSimpleMesh.cpp
index 7c73eb9..447bcee 100644
--- a/libs/rs/rsSimpleMesh.cpp
+++ b/libs/rs/rsSimpleMesh.cpp
@@ -73,6 +73,20 @@
     }
 }
 
+void SimpleMesh::uploadAll()
+{
+    for (uint32_t ct=0; ct < mVertexTypeCount; ct++) {
+        if (mVertexBuffers[ct].get()) {
+            mVertexBuffers[ct]->uploadToBufferObject();
+        }
+    }
+    if (mIndexBuffer.get()) {
+        mIndexBuffer->uploadToBufferObject();
+    }
+    if (mPrimitiveBuffer.get()) {
+        mPrimitiveBuffer->uploadToBufferObject();
+    }
+}
 
 
 SimpleMeshContext::SimpleMeshContext()
diff --git a/libs/rs/rsSimpleMesh.h b/libs/rs/rsSimpleMesh.h
index 03b6c2c..dc5e19c 100644
--- a/libs/rs/rsSimpleMesh.h
+++ b/libs/rs/rsSimpleMesh.h
@@ -47,6 +47,7 @@
 
     void render() const;
     void renderRange(uint32_t start, uint32_t len) const;
+    void uploadAll();
 
 
 protected:
diff --git a/libs/rs/rsTriangleMesh.cpp b/libs/rs/rsTriangleMesh.cpp
deleted file mode 100644
index 64bb71b..0000000
--- a/libs/rs/rsTriangleMesh.cpp
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "rsContext.h"
-
-using namespace android;
-using namespace android::renderscript;
-
-#include <GLES/gl.h>
-#include <GLES/glext.h>
-
-TriangleMesh::TriangleMesh()
-{
-    mVertexElement = NULL;
-    mIndexElement = NULL;
-    mVertexData = NULL;
-    mIndexData = NULL;
-    mTriangleCount = 0;
-    mVertexDataSize = 0;
-    mIndexDataSize = 0;
-
-    mBufferObjects[0] = 0;
-    mBufferObjects[1] = 0;
-
-    mOffsetCoord = 0;
-    mOffsetTex = 0;
-    mOffsetNorm = 0;
-
-    mSizeCoord = 0;
-    mSizeTex = 0;
-    mSizeNorm = 0;
-
-}
-
-TriangleMesh::~TriangleMesh()
-{
-    free(mVertexData);
-    free(mIndexData);
-}
-
-
-
-TriangleMeshContext::TriangleMeshContext()
-{
-    clear();
-}
-
-TriangleMeshContext::~TriangleMeshContext()
-{
-}
-
-void TriangleMeshContext::clear()
-{
-    mVertexElement = NULL;
-    mVertexSizeBits = 0;
-    mIndexElement = NULL;
-    mIndexSizeBits = 0;
-    mTriangleCount = 0;
-    mVertexData.clear();
-    mIndexData.clear();
-}
-
-void TriangleMesh::analyzeElement()
-{
-    for (uint32_t ct=0; ct < mVertexElement->getComponentCount(); ct++) {
-        const Component *c = mVertexElement->getComponent(ct);
-
-        if (c->getKind() == Component::X) {
-            rsAssert(mSizeCoord == 0);
-            mSizeCoord = 1;
-            mOffsetCoord = ct;
-        }
-        if (c->getKind() == Component::Y) {
-            rsAssert(mSizeCoord == 1);
-            mSizeCoord = 2;
-        }
-        if (c->getKind() == Component::Z) {
-            rsAssert(mSizeCoord == 2);
-            mSizeCoord = 3;
-        }
-        if (c->getKind() == Component::W) {
-            rsAssert(mSizeCoord == 4);
-            mSizeCoord = 4;
-        }
-
-        if (c->getKind() == Component::NX) {
-            rsAssert(mSizeNorm == 0);
-            mSizeNorm = 1;
-            mOffsetNorm = ct;
-        }
-        if (c->getKind() == Component::NY) {
-            rsAssert(mSizeNorm == 1);
-            mSizeNorm = 2;
-        }
-        if (c->getKind() == Component::NZ) {
-            rsAssert(mSizeNorm == 2);
-            mSizeNorm = 3;
-        }
-
-        if (c->getKind() == Component::S) {
-            rsAssert(mSizeTex == 0);
-            mSizeTex = 1;
-            mOffsetTex = ct;
-        }
-        if (c->getKind() == Component::T) {
-            rsAssert(mSizeTex == 1);
-            mSizeTex = 2;
-        }
-    }
-    LOGV("TriangleMesh %i,%i  %i,%i  %i,%i", mSizeCoord, mOffsetCoord, mSizeNorm, mOffsetNorm, mSizeTex, mOffsetTex);
-
-}
-
-
-namespace android {
-namespace renderscript {
-
-void rsi_TriangleMeshBegin(Context *rsc, RsElement vertex, RsElement index)
-{
-    TriangleMeshContext *tmc = &rsc->mStateTriangleMesh;
-
-    tmc->clear();
-    tmc->mVertexElement = static_cast<Element *>(vertex);
-    tmc->mVertexSizeBits = tmc->mVertexElement->getSizeBits();
-    tmc->mIndexElement = static_cast<Element *>(index);
-    tmc->mIndexSizeBits = tmc->mIndexElement->getSizeBits();
-
-    assert(!(tmc->mVertexSizeBits & 0x7));
-    assert(!(tmc->mIndexSizeBits & 0x7));
-}
-
-void rsi_TriangleMeshAddVertex(Context *rsc, const void *data)
-{
-    TriangleMeshContext *tmc = &rsc->mStateTriangleMesh;
-
-    // todo: Make this efficient.
-    for (uint32_t ct = 0; (ct * 8) < tmc->mVertexSizeBits; ct++) {
-        tmc->mVertexData.add(static_cast<const uint8_t *>(data) [ct]);
-    }
-}
-
-void rsi_TriangleMeshAddTriangle(Context *rsc, uint32_t idx1, uint32_t idx2, uint32_t idx3)
-{
-    TriangleMeshContext *tmc = &rsc->mStateTriangleMesh;
-
-    // todo: Make this efficient.
-    switch(tmc->mIndexSizeBits) {
-    case 16:
-        tmc->mIndexData.add(idx1);
-        tmc->mIndexData.add(idx2);
-        tmc->mIndexData.add(idx3);
-        break;
-    default:
-        assert(0);
-    }
-
-    tmc->mTriangleCount++;
-}
-
-RsTriangleMesh rsi_TriangleMeshCreate(Context *rsc)
-{
-    TriangleMeshContext *tmc = &rsc->mStateTriangleMesh;
-
-    TriangleMesh * tm = new TriangleMesh();
-    if (!tm) {
-        LOGE("rsTriangleMeshCreate: Error OUT OF MEMORY");
-        // error
-        return 0;
-    }
-
-    tm->mTriangleCount = tmc->mTriangleCount;
-    tm->mIndexDataSize = tmc->mIndexData.size() * tmc->mIndexSizeBits >> 3;
-    tm->mVertexDataSize = tmc->mVertexData.size();
-    tm->mIndexElement = tmc->mIndexElement;
-    tm->mVertexElement = tmc->mVertexElement;
-
-    tm->mIndexData = malloc(tm->mIndexDataSize);
-    tm->mVertexData = malloc(tm->mVertexDataSize);
-    if (!tm->mIndexData || !tm->mVertexData) {
-        LOGE("rsTriangleMeshCreate: Error OUT OF MEMORY");
-        delete tm;
-        return 0;
-    }
-
-    memcpy(tm->mVertexData, tmc->mVertexData.array(), tm->mVertexDataSize);
-    memcpy(tm->mIndexData, tmc->mIndexData.array(), tm->mIndexDataSize);
-    tm->analyzeElement();
-
-    tm->incUserRef();
-    return tm;
-}
-
-void rsi_TriangleMeshDestroy(Context *rsc, RsTriangleMesh vtm)
-{
-    TriangleMeshContext *tmc = &rsc->mStateTriangleMesh;
-    TriangleMesh * tm = static_cast<TriangleMesh *>(vtm);
-
-    free(tm->mIndexData);
-    free(tm->mVertexData);
-    delete tm;
-}
-
-
-
-void rsi_TriangleMeshRenderRange(Context *rsc, RsTriangleMesh vtm, uint32_t first, uint32_t count)
-{
-    TriangleMesh * tm = static_cast<TriangleMesh *>(vtm);
-
-    rsc->setupCheck();
-
-    if (!tm->mBufferObjects[0]) {
-        glGenBuffers(2, &tm->mBufferObjects[0]);
-
-        glBindBuffer(GL_ARRAY_BUFFER, tm->mBufferObjects[0]);
-        glBufferData(GL_ARRAY_BUFFER, tm->mVertexDataSize, tm->mVertexData, GL_STATIC_DRAW);
-        glBindBuffer(GL_ARRAY_BUFFER, 0);
-
-        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
-        glBufferData(GL_ELEMENT_ARRAY_BUFFER, tm->mIndexDataSize, tm->mIndexData, GL_STATIC_DRAW);
-        glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
-    }
-
-    if (first >= tm->mTriangleCount) {
-        return;
-    }
-    if (count >= (tm->mTriangleCount - first)) {
-        count = tm->mTriangleCount - first;
-    }
-    if (!count) {
-        return;
-    }
-
-    const float *f = (const float *)tm->mVertexData;
-
-    glBindBuffer(GL_ARRAY_BUFFER, tm->mBufferObjects[0]);
-    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, tm->mBufferObjects[1]);
-
-    glEnableClientState(GL_VERTEX_ARRAY);
-    glVertexPointer(tm->mSizeCoord,
-                    GL_FLOAT,
-                    tm->mVertexElement->getSizeBytes(),
-                    (void *)tm->mVertexElement->getComponentOffsetBytes(tm->mOffsetCoord));
-
-    if (tm->mSizeTex) {
-        glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-        glTexCoordPointer(tm->mSizeTex,
-                          GL_FLOAT,
-                          tm->mVertexElement->getSizeBytes(),
-                          (void *)tm->mVertexElement->getComponentOffsetBytes(tm->mOffsetTex));
-    } else {
-        glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-    }
-
-    if (tm->mSizeNorm) {
-        glEnableClientState(GL_NORMAL_ARRAY);
-        glNormalPointer(GL_FLOAT,
-                        tm->mVertexElement->getSizeBytes(),
-                        (void *)tm->mVertexElement->getComponentOffsetBytes(tm->mOffsetNorm));
-    } else {
-        glDisableClientState(GL_NORMAL_ARRAY);
-    }
-
-    glDrawElements(GL_TRIANGLES, count * 3, GL_UNSIGNED_SHORT, (GLvoid *)(first * 3 * 2));
-
-    glBindBuffer(GL_ARRAY_BUFFER, 0);
-    glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
-}
-
-void rsi_TriangleMeshRender(Context *rsc, RsTriangleMesh vtm)
-{
-    rsi_TriangleMeshRenderRange(rsc, vtm, 0, 0xffffff);
-}
-
-}}
diff --git a/libs/rs/rsTriangleMesh.h b/libs/rs/rsTriangleMesh.h
deleted file mode 100644
index e56c7c2..0000000
--- a/libs/rs/rsTriangleMesh.h
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#ifndef ANDROID_RS_TRIANGLE_MESH_H
-#define ANDROID_RS_TRIANGLE_MESH_H
-
-
-#include "RenderScript.h"
-
-// ---------------------------------------------------------------------------
-namespace android {
-namespace renderscript {
-
-
-// An element is a group of Components that occupies one cell in a structure.
-class TriangleMesh : public ObjectBase
-{
-public:
-    TriangleMesh();
-    ~TriangleMesh();
-
-    const Element * mVertexElement;
-    const Element * mIndexElement;
-
-    void * mVertexData;
-    void * mIndexData;
-
-    size_t mVertexDataSize;
-    size_t mIndexDataSize;
-    uint32_t mTriangleCount;
-
-    size_t mOffsetCoord;
-    size_t mOffsetTex;
-    size_t mOffsetNorm;
-
-    size_t mSizeCoord;
-    size_t mSizeTex;
-    size_t mSizeNorm;
-
-    // GL buffer info
-    uint32_t mBufferObjects[2];
-
-    void analyzeElement();
-protected:
-};
-
-class TriangleMeshContext
-{
-public:
-    TriangleMeshContext();
-    ~TriangleMeshContext();
-
-    const Element * mVertexElement;
-    const Element * mIndexElement;
-    size_t mVertexSizeBits;
-    size_t mIndexSizeBits;
-
-    Vector<uint8_t> mVertexData; 
-    Vector<uint16_t> mIndexData; 
-
-    uint32_t mTriangleCount;
-
-    void clear();
-};
-
-
-}
-}
-#endif //ANDROID_RS_TRIANGLE_MESH_H
-
diff --git a/opengl/java/android/opengl/GLSurfaceView.java b/opengl/java/android/opengl/GLSurfaceView.java
index 4599b77..070b7ae 100644
--- a/opengl/java/android/opengl/GLSurfaceView.java
+++ b/opengl/java/android/opengl/GLSurfaceView.java
@@ -286,7 +286,6 @@
     }
 
     /**
-     * @hide
      * Install a custom EGLContextFactory.
      * <p>If this method is
      * called, it must be called before {@link #setRenderer(Renderer)}
@@ -302,7 +301,6 @@
     }
 
     /**
-     * @hide
      * Install a custom EGLWindowSurfaceFactory.
      * <p>If this method is
      * called, it must be called before {@link #setRenderer(Renderer)}
@@ -609,7 +607,6 @@
     }
 
     /**
-     * @hide
      * An interface for customizing the eglCreateContext and eglDestroyContext calls.
      * <p>
      * This interface must be implemented by clients wishing to call
@@ -633,7 +630,6 @@
     }
 
     /**
-     * @hide
      * An interface for customizing the eglCreateWindowSurface and eglDestroySurface calls.
      * <p>
      * This interface must be implemented by clients wishing to call
diff --git a/opengl/tests/tritex/Android.mk b/opengl/tests/tritex/Android.mk
index 76fd8dd..6db3f49 100644
--- a/opengl/tests/tritex/Android.mk
+++ b/opengl/tests/tritex/Android.mk
@@ -2,7 +2,7 @@
 include $(CLEAR_VARS)
 
 LOCAL_SRC_FILES:= \
-	tritex.c
+	tritex.cpp
 
 LOCAL_SHARED_LIBRARIES := \
 	libcutils \
diff --git a/opengl/tests/tritex/tritex.c b/opengl/tests/tritex/tritex.cpp
similarity index 89%
rename from opengl/tests/tritex/tritex.c
rename to opengl/tests/tritex/tritex.cpp
index 60a7feb..629b53c 100644
--- a/opengl/tests/tritex/tritex.c
+++ b/opengl/tests/tritex/tritex.cpp
@@ -6,10 +6,16 @@
 
 #include <EGL/egl.h>

 #include <GLES/gl.h>
+#include <GLES/glext.h>
+
+#include <ui/FramebufferNativeWindow.h>
+#include <ui/EGLUtils.h>
 
 #include <stdio.h>

 #include <stdlib.h>
 #include <math.h>
+
+using namespace android;
 

 EGLDisplay eglDisplay;

 EGLSurface eglSurface;

@@ -117,6 +123,7 @@
     EGLConfig myConfig = {0};

     EGLint attrib[] =

     {

+            EGL_SURFACE_TYPE, EGL_PBUFFER_BIT|EGL_WINDOW_BIT,
             EGL_DEPTH_SIZE,     16,

             EGL_NONE

     };

@@ -132,15 +139,12 @@
         printf("eglInitialize failed\n");

         return 0;

     }

-

-    if ( eglChooseConfig(eglDisplay, attrib, &myConfig, 1, &numConfigs) != EGL_TRUE )

-    {

-        printf("eglChooseConfig failed\n");

-        return 0;

-    }

+
+    EGLNativeWindowType window = android_createDisplaySurface();

+    EGLUtils::selectConfigForNativeWindow(eglDisplay, attrib, window, &myConfig);

 

     if ( (eglSurface = eglCreateWindowSurface(eglDisplay, myConfig,
-            android_createDisplaySurface(), 0)) == EGL_NO_SURFACE )

+            window, 0)) == EGL_NO_SURFACE )

     {

         printf("eglCreateWindowSurface failed\n");

         return 0;

@@ -239,12 +243,12 @@
             0,            FIXED_ONE

     };

 

-    const GLushort template[] = { 0, 1, 2,  0, 2, 3 };
+    const GLushort quadIndices[] = { 0, 1, 2,  0, 2, 3 };
 
 
-    GLushort* indices = (GLushort*)malloc(quads*sizeof(template));
+    GLushort* indices = (GLushort*)malloc(quads*sizeof(quadIndices));
     for (i=0 ; i<quads ; i++)
-        memcpy(indices+(sizeof(template)/sizeof(indices[0]))*i, template, sizeof(template));
+        memcpy(indices+(sizeof(quadIndices)/sizeof(indices[0]))*i, quadIndices, sizeof(quadIndices));
 

     glVertexPointer(3, GL_FLOAT, 0, vertices);

     glTexCoordPointer(2, GL_FIXED, 0, texCoords);
@@ -262,7 +266,7 @@
     for (j=0 ; j<10 ; j++) {
         printf("loop %d / 10 (%d quads / loop)\n", j, quads);
 
-        int nelem = sizeof(template)/sizeof(template[0]);
+        int nelem = sizeof(quadIndices)/sizeof(quadIndices[0]);
         glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
         glDrawElements(GL_TRIANGLES, nelem*quads, GL_UNSIGNED_SHORT, indices);
         eglSwapBuffers(eglDisplay, eglSurface);