API review cleanup.

Change-Id: Ieae7d450308b5637ed4253fe9baed3634c6ed141
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index bad1208..074e423 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -84,24 +84,38 @@
         mRS.nAllocationUploadToBufferObject(getID());
     }
 
-    public void data(int[] d) {
+
+    public void copyFrom(BaseObj[] d) {
         mRS.validate();
-        subData1D(0, mType.getElementCount(), d);
-    }
-    public void data(short[] d) {
-        mRS.validate();
-        subData1D(0, mType.getElementCount(), d);
-    }
-    public void data(byte[] d) {
-        mRS.validate();
-        subData1D(0, mType.getElementCount(), d);
-    }
-    public void data(float[] d) {
-        mRS.validate();
-        subData1D(0, mType.getElementCount(), d);
+        if (d.length != mType.getCount()) {
+            throw new RSIllegalArgumentException("Array size mismatch, allocation sizeX = " +
+                                                 mType.getCount() + ", array length = " + d.length);
+        }
+        int i[] = new int[d.length];
+        for (int ct=0; ct < d.length; ct++) {
+            i[ct] = d[ct].getID();
+        }
+        subData1D(0, mType.getCount(), i);
     }
 
-    public void updateFromBitmap(Bitmap b) {
+    public void copyFrom(int[] d) {
+        mRS.validate();
+        subData1D(0, mType.getCount(), d);
+    }
+    public void copyFrom(short[] d) {
+        mRS.validate();
+        subData1D(0, mType.getCount(), d);
+    }
+    public void copyFrom(byte[] d) {
+        mRS.validate();
+        subData1D(0, mType.getCount(), d);
+    }
+    public void copyFrom(float[] d) {
+        mRS.validate();
+        subData1D(0, mType.getCount(), d);
+    }
+
+    public void copyFrom(Bitmap b) {
 
         mRS.validate();
         if(mType.getX() != b.getWidth() ||
@@ -153,8 +167,8 @@
         if(count < 1) {
             throw new RSIllegalArgumentException("Count must be >= 1.");
         }
-        if((off + count) > mType.getElementCount()) {
-            throw new RSIllegalArgumentException("Overflow, Available count " + mType.getElementCount() +
+        if((off + count) > mType.getCount()) {
+            throw new RSIllegalArgumentException("Overflow, Available count " + mType.getCount() +
                                                ", got " + count + " at offset " + off + ".");
         }
         if((len) < dataSize) {
@@ -205,7 +219,7 @@
     }
 
     public synchronized void resize(int dimX) {
-        if ((mType.getY() > 0)|| (mType.getZ() > 0) || mType.getFaces() || mType.getLOD()) {
+        if ((mType.getY() > 0)|| (mType.getZ() > 0) || mType.hasFaces() || mType.hasMipmaps()) {
             throw new RSInvalidStateException("Resize only support for 1D allocations at this time.");
         }
         mRS.nAllocationResize1D(getID(), dimX);
@@ -340,7 +354,7 @@
 
         rs.validate();
         Type.Builder b = new Type.Builder(rs, e);
-        b.add(Dimension.X, count);
+        b.setX(count);
         Type t = b.create();
 
         int id = rs.nAllocationCreateTyped(t.getID());
@@ -370,11 +384,9 @@
     static private Type typeFromBitmap(RenderScript rs, Bitmap b, boolean mip) {
         Element e = elementFromBitmap(rs, b);
         Type.Builder tb = new Type.Builder(rs, e);
-        tb.add(Dimension.X, b.getWidth());
-        tb.add(Dimension.Y, b.getHeight());
-        if (mip) {
-            tb.add(Dimension.LOD, 1);
-        }
+        tb.setX(b.getWidth());
+        tb.setY(b.getHeight());
+        tb.setMipmaps(mip);
         return tb.create();
     }
 
@@ -414,12 +426,10 @@
 
         Element e = elementFromBitmap(rs, b);
         Type.Builder tb = new Type.Builder(rs, e);
-        tb.add(Dimension.X, width);
-        tb.add(Dimension.Y, width);
-        tb.add(Dimension.FACE, 1);
-        if (genMips) {
-            tb.add(Dimension.LOD, 1);
-        }
+        tb.setX(width);
+        tb.setY(width);
+        tb.setFaces(true);
+        tb.setMipmaps(genMips);
         Type t = tb.create();
 
         int id = rs.nAllocationCubeCreateFromBitmap(dstFmt.getID(), genMips, b);
@@ -477,7 +487,7 @@
         try {
             allocArray = str.getBytes("UTF-8");
             Allocation alloc = Allocation.createSized(rs, Element.U8(rs), allocArray.length);
-            alloc.data(allocArray);
+            alloc.copyFrom(allocArray);
             return alloc;
         }
         catch (Exception e) {
diff --git a/graphics/java/android/renderscript/BaseObj.java b/graphics/java/android/renderscript/BaseObj.java
index 78b5617..c02435f 100644
--- a/graphics/java/android/renderscript/BaseObj.java
+++ b/graphics/java/android/renderscript/BaseObj.java
@@ -48,13 +48,19 @@
      *
      * @return int
      */
-    public int getID() {
+    int getID() {
         if (mDestroyed) {
             throw new RSInvalidStateException("using a destroyed object.");
         }
         return mID;
     }
 
+    void checkValid() {
+        if (mID == 0) {
+            throw new RSIllegalArgumentException("Invalid object.");
+        }
+    }
+
     private int mID;
     private boolean mDestroyed;
     private String mName;
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index 4b007f2..7e89a56 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -477,10 +477,6 @@
 
     }
 
-    public void destroy() {
-        super.destroy();
-    }
-
     /**
      * Create a custom Element of the specified DataType.  The DataKind will be
      * set to USER and the vector size to 1 indicating non-vector.
@@ -489,7 +485,7 @@
      * @param dt The DataType for the new element.
      * @return Element
      */
-    public static Element createUser(RenderScript rs, DataType dt) {
+    static Element createUser(RenderScript rs, DataType dt) {
         DataKind dk = DataKind.USER;
         boolean norm = false;
         int vecSize = 1;
@@ -510,7 +506,7 @@
      */
     public static Element createVector(RenderScript rs, DataType dt, int size) {
         if (size < 2 || size > 4) {
-            throw new RSIllegalArgumentException("Vector size out of rance 2-4.");
+            throw new RSIllegalArgumentException("Vector size out of range 2-4.");
         }
         DataKind dk = DataKind.USER;
         boolean norm = false;
@@ -603,7 +599,7 @@
          * @param name
          * @param arraySize
          */
-        public void add(Element element, String name, int arraySize) {
+        public Builder add(Element element, String name, int arraySize) {
             if (arraySize < 1) {
                 throw new RSIllegalArgumentException("Array size cannot be less than 1.");
             }
@@ -622,6 +618,7 @@
             mElementNames[mCount] = name;
             mArraySizes[mCount] = arraySize;
             mCount++;
+            return this;
         }
 
         /**
@@ -630,8 +627,8 @@
          * @param element
          * @param name
          */
-        public void add(Element element, String name) {
-            add(element, name, 1);
+        public Builder add(Element element, String name) {
+            return add(element, name, 1);
         }
 
         /**
diff --git a/graphics/java/android/renderscript/Mesh.java b/graphics/java/android/renderscript/Mesh.java
index 4187992..9176bc8 100644
--- a/graphics/java/android/renderscript/Mesh.java
+++ b/graphics/java/android/renderscript/Mesh.java
@@ -174,7 +174,7 @@
 
         Type newType(Element e, int size) {
             Type.Builder tb = new Type.Builder(mRS, e);
-            tb.add(Dimension.X, size);
+            tb.setX(size);
             return tb.create();
         }
 
@@ -466,12 +466,12 @@
 
             Mesh sm = smb.create();
 
-            sm.getVertexAllocation(0).data(mVtxData);
+            sm.getVertexAllocation(0).copyFrom(mVtxData);
             if(uploadToBufferObject) {
                 sm.getVertexAllocation(0).uploadToBufferObject();
             }
 
-            sm.getIndexAllocation(0).data(mIndexData);
+            sm.getIndexAllocation(0).copyFrom(mIndexData);
             sm.getIndexAllocation(0).uploadToBufferObject();
 
             return sm;
diff --git a/graphics/java/android/renderscript/Program.java b/graphics/java/android/renderscript/Program.java
index 22f3fc5..c3536c3 100644
--- a/graphics/java/android/renderscript/Program.java
+++ b/graphics/java/android/renderscript/Program.java
@@ -87,7 +87,7 @@
         if ((slot < 0) || (slot >= mTextureCount)) {
             throw new IllegalArgumentException("Slot ID out of range.");
         }
-        if (va != null && va.getType().getFaces() &&
+        if (va != null && va.getType().hasFaces() &&
             mTextures[slot] != TextureType.TEXTURE_CUBE) {
             throw new IllegalArgumentException("Cannot bind cubemap to 2d texture slot");
         }
diff --git a/graphics/java/android/renderscript/ProgramFragment.java b/graphics/java/android/renderscript/ProgramFragment.java
index faaf980..074c393 100644
--- a/graphics/java/android/renderscript/ProgramFragment.java
+++ b/graphics/java/android/renderscript/ProgramFragment.java
@@ -208,7 +208,7 @@
                 Element.Builder b = new Element.Builder(mRS);
                 b.add(Element.F32_4(mRS), "Color");
                 Type.Builder typeBuilder = new Type.Builder(mRS, b.create());
-                typeBuilder.add(Dimension.X, 1);
+                typeBuilder.setX(1);
                 constType = typeBuilder.create();
                 addConstant(constType);
             }
@@ -220,7 +220,7 @@
                 Allocation constantData = Allocation.createTyped(mRS,constType);
                 float[] data = new float[4];
                 data[0] = data[1] = data[2] = data[3] = 1.0f;
-                constantData.data(data);
+                constantData.copyFrom(data);
                 pf.bindConstants(constantData, 0);
             }
             return pf;
diff --git a/graphics/java/android/renderscript/ProgramVertex.java b/graphics/java/android/renderscript/ProgramVertex.java
index 998e05e..5d41f63 100644
--- a/graphics/java/android/renderscript/ProgramVertex.java
+++ b/graphics/java/android/renderscript/ProgramVertex.java
@@ -95,7 +95,7 @@
             b.add(Element.MATRIX4X4(rs), "MVP");
 
             Type.Builder typeBuilder = new Type.Builder(rs, b.create());
-            typeBuilder.add(Dimension.X, 1);
+            typeBuilder.setX(1);
             return typeBuilder.create();
         }
 
@@ -153,7 +153,7 @@
             Type constInputType = ProgramVertex.Builder.getConstantInputType(rs);
             mAlloc = Allocation.createTyped(rs, constInputType);
             int bufferSize = constInputType.getElement().getSizeBytes()*
-                             constInputType.getElementCount();
+                             constInputType.getCount();
             mIOBuffer = new FieldPacker(bufferSize);
             loadModelview(new Matrix4f());
             loadProjection(new Matrix4f());
@@ -170,7 +170,7 @@
             for(int i = 0; i < 16; i ++) {
                 mIOBuffer.addF32(m.mMat[i]);
             }
-            mAlloc.data(mIOBuffer.getData());
+            mAlloc.copyFrom(mIOBuffer.getData());
         }
 
         public void loadModelview(Matrix4f m) {
diff --git a/graphics/java/android/renderscript/RSSurfaceView.java b/graphics/java/android/renderscript/RSSurfaceView.java
index 2540d01..0211a4a 100644
--- a/graphics/java/android/renderscript/RSSurfaceView.java
+++ b/graphics/java/android/renderscript/RSSurfaceView.java
@@ -69,7 +69,6 @@
      * not normally called or subclassed by clients of RSSurfaceView.
      */
     public void surfaceCreated(SurfaceHolder holder) {
-        Log.v(RenderScript.LOG_TAG, "surfaceCreated");
         mSurfaceHolder = holder;
     }
 
@@ -79,9 +78,8 @@
      */
     public void surfaceDestroyed(SurfaceHolder holder) {
         // Surface will be destroyed when we return
-        Log.v(RenderScript.LOG_TAG, "surfaceDestroyed");
         if (mRS != null) {
-            mRS.contextSetSurface(0, 0, null);
+            mRS.setSurface(null, 0, 0);
         }
     }
 
@@ -90,23 +88,21 @@
      * not normally called or subclassed by clients of RSSurfaceView.
      */
     public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
-        Log.v(RenderScript.LOG_TAG, "surfaceChanged");
         if (mRS != null) {
-            mRS.contextSetSurface(w, h, holder.getSurface());
+            mRS.setSurface(holder, w, h);
         }
     }
 
-    /**
+   /**
      * Inform the view that the activity is paused. The owner of this view must
      * call this method when the activity is paused. Calling this method will
      * pause the rendering thread.
      * Must not be called before a renderer has been set.
      */
-    public void onPause() {
+    public void pause() {
         if(mRS != null) {
             mRS.pause();
         }
-        //Log.v(RenderScript.LOG_TAG, "onPause");
     }
 
     /**
@@ -116,49 +112,29 @@
      * thread.
      * Must not be called before a renderer has been set.
      */
-    public void onResume() {
+    public void resume() {
         if(mRS != null) {
             mRS.resume();
         }
-        //Log.v(RenderScript.LOG_TAG, "onResume");
     }
 
-    /**
-     * Queue a runnable to be run on the GL rendering thread. This can be used
-     * to communicate with the Renderer on the rendering thread.
-     * Must not be called before a renderer has been set.
-     * @param r the runnable to be run on the GL rendering thread.
-     */
-    public void queueEvent(Runnable r) {
-        //Log.v(RenderScript.LOG_TAG, "queueEvent");
+    public RenderScriptGL createRenderScriptGL(RenderScriptGL.SurfaceConfig sc) {
+        RenderScriptGL rs = new RenderScriptGL(sc);
+        setRenderScriptGL(rs);
+        return rs;
     }
 
-    /**
-     * This method is used as part of the View class and is not normally
-     * called or subclassed by clients of RSSurfaceView.
-     * Must not be called before a renderer has been set.
-     */
-    @Override
-    protected void onDetachedFromWindow() {
-        super.onDetachedFromWindow();
-    }
-
-    // ----------------------------------------------------------------------
-
-    public RenderScriptGL createRenderScript(RenderScriptGL.SurfaceConfig sc) {
-        Log.v(RenderScript.LOG_TAG, "createRenderScript");
-        mRS = new RenderScriptGL(sc);
-        return mRS;
-    }
-
-    public void destroyRenderScript() {
-        Log.v(RenderScript.LOG_TAG, "destroyRenderScript");
+    public void destroyRenderScriptGL() {
         mRS.destroy();
         mRS = null;
     }
 
-    public void createRenderScript(RenderScriptGL rs) {
+    public void setRenderScriptGL(RenderScriptGL rs) {
         mRS = rs;
     }
+
+    public RenderScriptGL getRenderScriptGL() {
+        return mRS;
+    }
 }
 
diff --git a/graphics/java/android/renderscript/RenderScript.java b/graphics/java/android/renderscript/RenderScript.java
index f16e045..6ff894d 100644
--- a/graphics/java/android/renderscript/RenderScript.java
+++ b/graphics/java/android/renderscript/RenderScript.java
@@ -38,9 +38,9 @@
  **/
 public class RenderScript {
     static final String LOG_TAG = "RenderScript_jni";
-    protected static final boolean DEBUG  = false;
+    static final boolean DEBUG  = false;
     @SuppressWarnings({"UnusedDeclaration", "deprecation"})
-    protected static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
+    static final boolean LOG_ENABLED = DEBUG ? Config.LOGD : Config.LOGV;
 
 
 
@@ -49,8 +49,8 @@
      * field offsets.
      */
     @SuppressWarnings({"FieldCanBeLocal", "UnusedDeclaration"})
-    protected static boolean sInitialized;
-    native protected static void _nInit();
+    static boolean sInitialized;
+    native static void _nInit();
 
 
     static {
@@ -183,9 +183,9 @@
         rsnElementGetSubElements(mContext, id, IDs, names);
     }
 
-    native int rsnTypeCreate(int con, int eid, int[] dims, int[] vals);
-    synchronized int nTypeCreate(int eid, int[] dims, int[] vals) {
-        return rsnTypeCreate(mContext, eid, dims, vals);
+    native int rsnTypeCreate(int con, int eid, int x, int y, int z, boolean mips, boolean faces);
+    synchronized int nTypeCreate(int eid, int x, int y, int z, boolean mips, boolean faces) {
+        return rsnTypeCreate(mContext, eid, x, y, z, mips, faces);
     }
     native void rsnTypeGetNativeData(int con, int id, int[] typeData);
     synchronized void nTypeGetNativeData(int id, int[] typeData) {
@@ -525,10 +525,10 @@
     }
 
 
-    protected int     mDev;
-    protected int     mContext;
+    int     mDev;
+    int     mContext;
     @SuppressWarnings({"FieldCanBeLocal"})
-    protected MessageThread mMessageThread;
+    MessageThread mMessageThread;
 
     Element mElement_U8;
     Element mElement_I8;
@@ -604,7 +604,7 @@
      * in the script.
      *
      */
-    public static class RSMessage implements Runnable {
+    public static class RSMessageHandler implements Runnable {
         protected int[] mData;
         protected int mID;
         protected int mLength;
@@ -617,7 +617,14 @@
      * sent from sendToClient by scripts from this context.
      *
      */
-    public RSMessage mMessageCallback = null;
+    RSMessageHandler mMessageCallback = null;
+
+    public void setMessageHandler(RSMessageHandler msg) {
+        mMessageCallback = msg;
+    }
+    public RSMessageHandler getMessageHandler() {
+        return mMessageCallback;
+    }
 
     /**
      * Runtime error base class.  An application should derive from this class
@@ -625,7 +632,7 @@
      * the fields in this class will be filled and the run method called.
      *
      */
-    public static class RSAsyncError implements Runnable {
+    public static class RSErrorHandler implements Runnable {
         protected String mErrorMessage;
         protected int mErrorNum;
         public void run() {
@@ -639,7 +646,14 @@
      * This will cause program termaination.
      *
      */
-    public RSAsyncError mErrorCallback = null;
+    RSErrorHandler mErrorCallback = null;
+
+    public void setErrorHandler(RSErrorHandler msg) {
+        mErrorCallback = msg;
+    }
+    public RSErrorHandler getErrorHandler() {
+        return mErrorCallback;
+    }
 
     /**
      * RenderScript worker threads priority enumeration.  The default value is
@@ -648,6 +662,7 @@
      * processes.
      */
     public enum Priority {
+        // Remap these numbers to opaque...
         LOW (5),     //ANDROID_PRIORITY_BACKGROUND + 5
         NORMAL (-4);  //ANDROID_PRIORITY_DISPLAY
 
@@ -669,23 +684,23 @@
      *
      * @param p New priority to be set.
      */
-    public void contextSetPriority(Priority p) {
+    public void setPriority(Priority p) {
         validate();
         nContextSetPriority(p.mID);
     }
 
-    protected static class MessageThread extends Thread {
+    static class MessageThread extends Thread {
         RenderScript mRS;
         boolean mRun = true;
-        int[] auxData = new int[2];
+        int[] mAuxData = new int[2];
 
-        public static final int RS_MESSAGE_TO_CLIENT_NONE = 0;
-        public static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
-        public static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
-        public static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
-        public static final int RS_MESSAGE_TO_CLIENT_USER = 4;
+        static final int RS_MESSAGE_TO_CLIENT_NONE = 0;
+        static final int RS_MESSAGE_TO_CLIENT_EXCEPTION = 1;
+        static final int RS_MESSAGE_TO_CLIENT_RESIZE = 2;
+        static final int RS_MESSAGE_TO_CLIENT_ERROR = 3;
+        static final int RS_MESSAGE_TO_CLIENT_USER = 4;
 
-        public static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
+        static final int RS_ERROR_FATAL_UNKNOWN = 0x1000;
 
         MessageThread(RenderScript rs) {
             super("RSMessageThread");
@@ -700,9 +715,9 @@
             mRS.nContextInitToClient(mRS.mContext);
             while(mRun) {
                 rbuf[0] = 0;
-                int msg = mRS.nContextPeekMessage(mRS.mContext, auxData, true);
-                int size = auxData[1];
-                int subID = auxData[0];
+                int msg = mRS.nContextPeekMessage(mRS.mContext, mAuxData, true);
+                int size = mAuxData[1];
+                int subID = mAuxData[0];
 
                 if (msg == RS_MESSAGE_TO_CLIENT_USER) {
                     if ((size>>2) >= rbuf.length) {
@@ -775,12 +790,10 @@
      * Print the currently available debugging information about the state of
      * the RS context to the log.
      *
-     *
-     * @param bits Currently ignored.
      */
-    public void contextDump(int bits) {
+    public void contextDump() {
         validate();
-        nContextDump(bits);
+        nContextDump(0);
     }
 
     /**
@@ -817,7 +830,7 @@
         return mContext != 0;
     }
 
-    protected int safeID(BaseObj o) {
+    int safeID(BaseObj o) {
         if(o != null) {
             return o.getID();
         }
diff --git a/graphics/java/android/renderscript/RenderScriptGL.java b/graphics/java/android/renderscript/RenderScriptGL.java
index 181d4bd..4a1c40a 100644
--- a/graphics/java/android/renderscript/RenderScriptGL.java
+++ b/graphics/java/android/renderscript/RenderScriptGL.java
@@ -45,6 +45,9 @@
      * Class which is used to describe a pixel format for a graphical buffer.
      * This is used to describe the intended format of the display surface.
      *
+     * The configuration is described by pairs of minimum and preferred bit
+     * depths for each component within the config and additional structural
+     * information.
      */
     public static class SurfaceConfig {
         int mDepthMin       = 0;
@@ -81,38 +84,75 @@
                 throw new RSIllegalArgumentException("Minimum value provided out of range.");
             }
             if (upref < umin) {
-                throw new RSIllegalArgumentException("Prefered must be >= Minimum.");
+                throw new RSIllegalArgumentException("preferred must be >= Minimum.");
             }
         }
 
-        public void setColor(int minimum, int prefered) {
-            validateRange(minimum, prefered, 5, 8);
+        /**
+         * Set the per-component bit depth for color (red, green, blue).  This
+         * configures the surface for an unsigned integer buffer type.
+         *
+         * @param minimum
+         * @param preferred
+         */
+        public void setColor(int minimum, int preferred) {
+            validateRange(minimum, preferred, 5, 8);
             mColorMin = minimum;
-            mColorPref = prefered;
+            mColorPref = preferred;
         }
-        public void setAlpha(int minimum, int prefered) {
-            validateRange(minimum, prefered, 0, 8);
+
+        /**
+         * Set the bit depth for alpha. This configures the surface for
+         * an unsigned integer buffer type.
+         *
+         * @param minimum
+         * @param preferred
+         */
+        public void setAlpha(int minimum, int preferred) {
+            validateRange(minimum, preferred, 0, 8);
             mAlphaMin = minimum;
-            mAlphaPref = prefered;
+            mAlphaPref = preferred;
         }
-        public void setDepth(int minimum, int prefered) {
-            validateRange(minimum, prefered, 0, 24);
+
+         /**
+         * Set the bit depth for the depth buffer. This configures the
+         * surface for an unsigned integer buffer type.  If a minimum of 0
+         * is specified then its possible no depth buffer will be
+         * allocated.
+         *
+         * @param minimum
+         * @param preferred
+         */
+        public void setDepth(int minimum, int preferred) {
+            validateRange(minimum, preferred, 0, 24);
             mDepthMin = minimum;
-            mDepthPref = prefered;
+            mDepthPref = preferred;
         }
-        public void setSamples(int minimum, int prefered, float Q) {
-            validateRange(minimum, prefered, 0, 24);
+
+        /**
+         * Configure the multisample rendering.
+         *
+         * @param minimum The required number of samples, must be at least 1.
+         * @param preferred The targe number of samples, must be at least
+         *                  minimum
+         * @param Q  The quality of samples, range 0-1.  Used to decide between
+         *           different formats which have the same number of samples but
+         *           different rendering quality.
+         */
+        public void setSamples(int minimum, int preferred, float Q) {
+            validateRange(minimum, preferred, 1, 32);
             if (Q < 0.0f || Q > 1.0f) {
                 throw new RSIllegalArgumentException("Quality out of 0-1 range.");
             }
             mSamplesMin = minimum;
-            mSamplesPref = prefered;
+            mSamplesPref = preferred;
             mSamplesQ = Q;
         }
     };
 
     SurfaceConfig mSurfaceConfig;
-
+/*
+    // Keep?
     public void configureSurface(SurfaceHolder sh) {
         if (mSurfaceConfig.mAlphaMin > 1) {
             sh.setFormat(PixelFormat.RGBA_8888);
@@ -123,7 +163,14 @@
 
     public void checkSurface(SurfaceHolder sh) {
     }
+*/
 
+    /**
+     * Construct a new RenderScriptGL context.
+     *
+     *
+     * @param sc The desired format of the primart rendering surface.
+     */
     public RenderScriptGL(SurfaceConfig sc) {
         mSurfaceConfig = new SurfaceConfig(sc);
 
@@ -146,54 +193,113 @@
         Element.initPredefined(this);
     }
 
-    public void contextSetSurface(int w, int h, Surface sur) {
-        mSurface = sur;
+    /**
+     * Bind an os surface
+     *
+     *
+     * @param w
+     * @param h
+     * @param sur
+     */
+    public void setSurface(SurfaceHolder sur, int w, int h) {
+        validate();
+        if (sur != null) {
+            mSurface = sur.getSurface();
+        } else {
+            mSurface = null;
+        }
         mWidth = w;
         mHeight = h;
-        validate();
         nContextSetSurface(w, h, mSurface);
     }
 
+    /**
+     * return the height of the last set surface.
+     *
+     * @return int
+     */
     public int getHeight() {
         return mHeight;
     }
 
+    /**
+     * return the width of the last set surface.
+     *
+     * @return int
+     */
     public int getWidth() {
         return mWidth;
     }
 
-    void pause() {
+    /**
+     * Temporarly halt calls to the root rendering script.
+     *
+     */
+    public void pause() {
         validate();
         nContextPause();
     }
 
-    void resume() {
+    /**
+     * Resume calls to the root rendering script.
+     *
+     */
+    public void resume() {
         validate();
         nContextResume();
     }
 
 
-    public void contextBindRootScript(Script s) {
+    /**
+     * Set the script to handle calls to render the primary surface.
+     *
+     * @param s Graphics script to process rendering requests.
+     */
+    public void bindRootScript(Script s) {
         validate();
         nContextBindRootScript(safeID(s));
     }
 
-    public void contextBindProgramStore(ProgramStore p) {
+    /**
+     * Set the default ProgramStore object seen as the parent state by the root
+     * rendering script.
+     *
+     * @param p
+     */
+    public void bindProgramStore(ProgramStore p) {
         validate();
         nContextBindProgramStore(safeID(p));
     }
 
-    public void contextBindProgramFragment(ProgramFragment p) {
+    /**
+     * Set the default ProgramFragment object seen as the parent state by the
+     * root rendering script.
+     *
+     * @param p
+     */
+    public void bindProgramFragment(ProgramFragment p) {
         validate();
         nContextBindProgramFragment(safeID(p));
     }
 
-    public void contextBindProgramRaster(ProgramRaster p) {
+    /**
+     * Set the default ProgramRaster object seen as the parent state by the
+     * root rendering script.
+     *
+     * @param p
+     */
+    public void bindProgramRaster(ProgramRaster p) {
         validate();
         nContextBindProgramRaster(safeID(p));
     }
 
-    public void contextBindProgramVertex(ProgramVertex p) {
+    /**
+     * Set the default ProgramVertex object seen as the parent state by the
+     * root rendering script.
+     *
+     * @param p
+     */
+    public void bindProgramVertex(ProgramVertex p) {
         validate();
         nContextBindProgramVertex(safeID(p));
     }
diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java
index b627207..9fbc09a 100644
--- a/graphics/java/android/renderscript/Sampler.java
+++ b/graphics/java/android/renderscript/Sampler.java
@@ -31,6 +31,9 @@
 /**
  * @hide
  *
+ * Sampler object which defines how data is extracted from textures.  Samplers
+ * are attached to Program objects (currently only fragment) when those objects
+ * need to access texture data.
  **/
 public class Sampler extends BaseObj {
     public enum Value {
@@ -50,6 +53,14 @@
         super(id, rs);
     }
 
+    /**
+     * Retrieve a sampler with min and mag set to nearest and wrap modes set to
+     * clamp.
+     *
+     * @param rs
+     *
+     * @return Sampler
+     */
     public static Sampler CLAMP_NEAREST(RenderScript rs) {
         if(rs.mSampler_CLAMP_NEAREST == null) {
             Builder b = new Builder(rs);
@@ -62,6 +73,14 @@
         return rs.mSampler_CLAMP_NEAREST;
     }
 
+    /**
+     * Retrieve a sampler with min and mag set to linear and wrap modes set to
+     * clamp.
+     *
+     * @param rs
+     *
+     * @return Sampler
+     */
     public static Sampler CLAMP_LINEAR(RenderScript rs) {
         if(rs.mSampler_CLAMP_LINEAR == null) {
             Builder b = new Builder(rs);
@@ -74,6 +93,14 @@
         return rs.mSampler_CLAMP_LINEAR;
     }
 
+    /**
+     * Retrieve a sampler with ag set to linear, min linear mipmap linear, and
+     * to and wrap modes set to clamp.
+     *
+     * @param rs
+     *
+     * @return Sampler
+     */
     public static Sampler CLAMP_LINEAR_MIP_LINEAR(RenderScript rs) {
         if(rs.mSampler_CLAMP_LINEAR_MIP_LINEAR == null) {
             Builder b = new Builder(rs);
@@ -86,6 +113,14 @@
         return rs.mSampler_CLAMP_LINEAR_MIP_LINEAR;
     }
 
+    /**
+     * Retrieve a sampler with min and mag set to nearest and wrap modes set to
+     * wrap.
+     *
+     * @param rs
+     *
+     * @return Sampler
+     */
     public static Sampler WRAP_NEAREST(RenderScript rs) {
         if(rs.mSampler_WRAP_NEAREST == null) {
             Builder b = new Builder(rs);
@@ -98,6 +133,14 @@
         return rs.mSampler_WRAP_NEAREST;
     }
 
+    /**
+     * Retrieve a sampler with min and mag set to nearest and wrap modes set to
+     * wrap.
+     *
+     * @param rs
+     *
+     * @return Sampler
+     */
     public static Sampler WRAP_LINEAR(RenderScript rs) {
         if(rs.mSampler_WRAP_LINEAR == null) {
             Builder b = new Builder(rs);
@@ -110,6 +153,14 @@
         return rs.mSampler_WRAP_LINEAR;
     }
 
+    /**
+     * Retrieve a sampler with ag set to linear, min linear mipmap linear, and
+     * to and wrap modes set to wrap.
+     *
+     * @param rs
+     *
+     * @return Sampler
+     */
     public static Sampler WRAP_LINEAR_MIP_LINEAR(RenderScript rs) {
         if(rs.mSampler_WRAP_LINEAR_MIP_LINEAR == null) {
             Builder b = new Builder(rs);
@@ -123,6 +174,11 @@
     }
 
 
+    /**
+     * Builder for creating non-standard samplers.  Usefull if mix and match of
+     * wrap modes is necesary or if anisotropic filtering is desired.
+     *
+     */
     public static class Builder {
         RenderScript mRS;
         Value mMin;
diff --git a/graphics/java/android/renderscript/Type.java b/graphics/java/android/renderscript/Type.java
index 44aee63..859369c 100644
--- a/graphics/java/android/renderscript/Type.java
+++ b/graphics/java/android/renderscript/Type.java
@@ -42,7 +42,7 @@
     int mDimX;
     int mDimY;
     int mDimZ;
-    boolean mDimLOD;
+    boolean mDimMipmaps;
     boolean mDimFaces;
     int mElementCount;
     Element mElement;
@@ -88,8 +88,8 @@
      *
      * @return boolean
      */
-    public boolean getLOD() {
-        return mDimLOD;
+    public boolean hasMipmaps() {
+        return mDimMipmaps;
     }
 
     /**
@@ -97,7 +97,7 @@
      *
      * @return boolean
      */
-    public boolean getFaces() {
+    public boolean hasFaces() {
         return mDimFaces;
     }
 
@@ -106,31 +106,31 @@
      *
      * @return int
      */
-    public int getElementCount() {
+    public int getCount() {
         return mElementCount;
     }
 
     void calcElementCount() {
-        boolean hasLod = getLOD();
+        boolean hasLod = hasMipmaps();
         int x = getX();
         int y = getY();
         int z = getZ();
         int faces = 1;
-        if(getFaces()) {
+        if (hasFaces()) {
             faces = 6;
         }
-        if(x == 0) {
+        if (x == 0) {
             x = 1;
         }
-        if(y == 0) {
+        if (y == 0) {
             y = 1;
         }
-        if(z == 0) {
+        if (z == 0) {
             z = 1;
         }
 
         int count = x * y * z * faces;
-        if(hasLod && (x > 1) && (y > 1) && (z > 1)) {
+        if (hasLod && (x > 1) && (y > 1) && (z > 1)) {
             if(x > 1) {
                 x >>= 1;
             }
@@ -151,10 +151,6 @@
         super(id, rs);
     }
 
-    protected void finalize() throws Throwable {
-        super.finalize();
-    }
-
     @Override
     void updateFromNative() {
         // We have 6 integer to obtain mDimX; mDimY; mDimZ;
@@ -165,7 +161,7 @@
         mDimX = dataBuffer[0];
         mDimY = dataBuffer[1];
         mDimZ = dataBuffer[2];
-        mDimLOD = dataBuffer[3] == 1 ? true : false;
+        mDimMipmaps = dataBuffer[3] == 1 ? true : false;
         mDimFaces = dataBuffer[4] == 1 ? true : false;
 
         int elementID = dataBuffer[5];
@@ -182,15 +178,13 @@
      */
     public static class Builder {
         RenderScript mRS;
-        Dimension[] mDimensions;
-        int[] mDimensionValues;
-        int mEntryCount;
-        Element mElement;
+        int mDimX = 1;
+        int mDimY;
+        int mDimZ;
+        boolean mDimMipmaps;
+        boolean mDimFaces;
 
-        class Entry {
-            Dimension mDim;
-            int mValue;
-        }
+        Element mElement;
 
         /**
          * Create a new builder object.
@@ -199,13 +193,8 @@
          * @param e The element for the type to be created.
          */
         public Builder(RenderScript rs, Element e) {
-            if(e.getID() == 0) {
-                throw new RSIllegalArgumentException("Invalid element.");
-            }
-
+            e.checkValid();
             mRS = rs;
-            mDimensions = new Dimension[4];
-            mDimensionValues = new int[4];
             mElement = e;
         }
 
@@ -216,76 +205,67 @@
          * @param d
          * @param value
          */
-        public void add(Dimension d, int value) {
+        public Builder setX(int value) {
             if(value < 1) {
-                throw new RSIllegalArgumentException("Values of less than 1 for Dimensions are not valid.");
+                throw new RSIllegalArgumentException("Values of less than 1 for Dimension X are not valid.");
             }
-            if(mDimensions.length >= mEntryCount) {
-                Dimension[] dn = new Dimension[mEntryCount + 8];
-                System.arraycopy(mDimensions, 0, dn, 0, mEntryCount);
-                mDimensions = dn;
-
-                int[] in = new int[mEntryCount + 8];
-                System.arraycopy(mDimensionValues, 0, in, 0, mEntryCount);
-                mDimensionValues = in;
-            }
-            mDimensions[mEntryCount] = d;
-            mDimensionValues[mEntryCount] = value;
-            mEntryCount++;
+            mDimX = value;
+            return this;
         }
 
+        public Builder setY(int value) {
+            if(value < 1) {
+                throw new RSIllegalArgumentException("Values of less than 1 for Dimension Y are not valid.");
+            }
+            mDimY = value;
+            return this;
+        }
+
+        public Builder setMipmaps(boolean value) {
+            mDimMipmaps = value;
+            return this;
+        }
+
+        public Builder setFaces(boolean value) {
+            mDimFaces = value;
+            return this;
+        }
+
+
         /**
          * Validate structure and create a new type.
          *
          * @return Type
          */
         public Type create() {
-            int dims[] = new int[mEntryCount];
-            for (int ct=0; ct < mEntryCount; ct++) {
-                dims[ct] = mDimensions[ct].mID;
-            }
-
-            int id = mRS.nTypeCreate(mElement.getID(), dims, mDimensionValues);
-            Type t = new Type(id, mRS);
-            t.mElement = mElement;
-
-            for(int ct=0; ct < mEntryCount; ct++) {
-                if(mDimensions[ct] == Dimension.X) {
-                    t.mDimX = mDimensionValues[ct];
-                }
-                if(mDimensions[ct] == Dimension.Y) {
-                    t.mDimY = mDimensionValues[ct];
-                }
-                if(mDimensions[ct] == Dimension.Z) {
-                    t.mDimZ = mDimensionValues[ct];
-                }
-                if(mDimensions[ct] == Dimension.LOD) {
-                    t.mDimLOD = mDimensionValues[ct] != 0;
-                }
-                if(mDimensions[ct] == Dimension.FACE) {
-                    t.mDimFaces = mDimensionValues[ct] != 0;
-                }
-            }
-
-            if (t.mDimZ > 0) {
-                if ((t.mDimX < 1) || (t.mDimY < 1)) {
+            if (mDimZ > 0) {
+                if ((mDimX < 1) || (mDimY < 1)) {
                     throw new RSInvalidStateException("Both X and Y dimension required when Z is present.");
                 }
-                if (t.mDimFaces) {
+                if (mDimFaces) {
                     throw new RSInvalidStateException("Cube maps not supported with 3D types.");
                 }
             }
-            if (t.mDimY > 0) {
-                if (t.mDimX < 1) {
+            if (mDimY > 0) {
+                if (mDimX < 1) {
                     throw new RSInvalidStateException("X dimension required when Y is present.");
                 }
             }
-            if (t.mDimFaces) {
-                if (t.mDimY < 1) {
+            if (mDimFaces) {
+                if (mDimY < 1) {
                     throw new RSInvalidStateException("Cube maps require 2D Types.");
                 }
             }
 
+            int id = mRS.nTypeCreate(mElement.getID(), mDimX, mDimY, mDimZ, mDimMipmaps, mDimFaces);
+            Type t = new Type(id, mRS);
+            t.mElement = mElement;
+            t.mDimX = mDimX;
+            t.mDimY = mDimY;
+            t.mDimZ = mDimZ;
+            t.mDimMipmaps = mDimMipmaps;
+            t.mDimFaces = mDimFaces;
+
             t.calcElementCount();
             return t;
         }
diff --git a/graphics/jni/android_renderscript_RenderScript.cpp b/graphics/jni/android_renderscript_RenderScript.cpp
index 6a1a319..c4e0372 100644
--- a/graphics/jni/android_renderscript_RenderScript.cpp
+++ b/graphics/jni/android_renderscript_RenderScript.cpp
@@ -357,19 +357,13 @@
 // -----------------------------------
 
 static int
-nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid, jintArray _dims, jintArray _dimValues)
+nTypeCreate(JNIEnv *_env, jobject _this, RsContext con, RsElement eid,
+            jint dimx, jint dimy, jint dimz, jboolean mips, jboolean faces)
 {
-    int count = _env->GetArrayLength(_dims);
-    LOG_API("nTypeCreate, con(%p)", con);
+    LOG_API("nTypeCreate, con(%p) eid(%p), x(%i), y(%i), z(%i), mips(%i), faces(%i)",
+            con, eid, dimx, dimy, dimz, mips, faces);
 
-    jint *dimPtr = _env->GetIntArrayElements(_dims, NULL);
-    jint *dimValPtr = _env->GetIntArrayElements(_dimValues, NULL);
-
-    jint id = (jint)rsaTypeCreate(con, (RsElement)eid, count,
-                                  (RsDimension *)dimPtr, (uint32_t *)dimValPtr);
-
-    _env->ReleaseIntArrayElements(_dims, dimPtr, JNI_ABORT);
-    _env->ReleaseIntArrayElements(_dimValues, dimValPtr, JNI_ABORT);
+    jint id = (jint)rsaTypeCreate(con, (RsElement)eid, dimx, dimy, dimz, mips, faces);
     return (jint)id;
 }
 
@@ -1316,7 +1310,7 @@
 {"rsnElementGetNativeData",          "(II[I)V",                               (void*)nElementGetNativeData },
 {"rsnElementGetSubElements",         "(II[I[Ljava/lang/String;)V",            (void*)nElementGetSubElements },
 
-{"rsnTypeCreate",                    "(II[I[I)I",                             (void*)nTypeCreate },
+{"rsnTypeCreate",                    "(IIIIIZZ)I",                            (void*)nTypeCreate },
 {"rsnTypeGetNativeData",             "(II[I)V",                               (void*)nTypeGetNativeData },
 
 {"rsnAllocationCreateTyped",         "(II)I",                                 (void*)nAllocationCreateTyped },
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h
index f00f748..7351793 100644
--- a/libs/rs/RenderScript.h
+++ b/libs/rs/RenderScript.h
@@ -328,8 +328,7 @@
 void rsaElementGetSubElements(RsContext, RsElement, uint32_t *ids, const char **names, uint32_t dataSize);
 
 // Async commands for returning new IDS
-RsType rsaTypeCreate(RsContext, RsElement, uint32_t dimCount,
-                     const RsDimension *dims, const uint32_t *vals);
+RsType rsaTypeCreate(RsContext, RsElement, uint32_t dimX, uint32_t dimY, uint32_t dimZ, bool mips, bool faces);
 RsAllocation rsaAllocationCreateTyped(RsContext rsc, RsType vtype);
 RsAllocation rsaAllocationCreateFromBitmap(RsContext con, uint32_t w, uint32_t h, RsElement _dst, RsElement _src,  bool genMips, const void *data);
 RsAllocation rsaAllocationCubeCreateFromBitmap(RsContext con, uint32_t w, uint32_t h, RsElement _dst, RsElement _src,  bool genMips, const void *data);
diff --git a/libs/rs/java/Balls/src/com/android/balls/Balls.java b/libs/rs/java/Balls/src/com/android/balls/Balls.java
index 5957c94..c24e616 100644
--- a/libs/rs/java/Balls/src/com/android/balls/Balls.java
+++ b/libs/rs/java/Balls/src/com/android/balls/Balls.java
@@ -94,21 +94,14 @@
         // Ideally a game should implement onResume() and onPause()
         // to take appropriate action when the activity looses focus
         super.onResume();
-        mView.onResume();
+        mView.resume();
     }
 
     @Override
     protected void onPause() {
-        Log.e("rs", "onPause");
-
-        // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
         super.onPause();
-        mView.onPause();
-
-
-
-        //Runtime.getRuntime().exit(0);
+        mView.pause();
+        Runtime.getRuntime().exit(0);
     }
 
     @Override
diff --git a/libs/rs/java/Balls/src/com/android/balls/BallsRS.java b/libs/rs/java/Balls/src/com/android/balls/BallsRS.java
index 42eaede..83b755f 100644
--- a/libs/rs/java/Balls/src/com/android/balls/BallsRS.java
+++ b/libs/rs/java/Balls/src/com/android/balls/BallsRS.java
@@ -63,7 +63,7 @@
         sb.addInput(mPoints.getElement());
         ProgramVertex pvs = sb.create();
         pvs.bindConstants(mVpConsts.getAllocation(), 0);
-        mRS.contextBindProgramVertex(pvs);
+        mRS.bindProgramVertex(pvs);
     }
 
     private Allocation loadTexture(int id) {
@@ -118,14 +118,14 @@
         mScript.set_gPFPoints(mPFPoints);
         createProgramVertex();
 
-        mRS.contextBindProgramStore(ProgramStore.BLEND_ADD_DEPTH_NO_DEPTH(mRS));
+        mRS.bindProgramStore(ProgramStore.BLEND_ADD_DEPTH_NO_DEPTH(mRS));
 
         mPhysicsScript.set_gMinPos(new Float2(5, 5));
         mPhysicsScript.set_gMaxPos(new Float2(width - 5, height - 5));
 
         mScript.invoke_initParts(width, height);
 
-        mRS.contextBindRootScript(mScript);
+        mRS.bindRootScript(mScript);
     }
 
     public void newTouchPosition(float x, float y, float pressure, int id) {
diff --git a/libs/rs/java/Balls/src/com/android/balls/BallsView.java b/libs/rs/java/Balls/src/com/android/balls/BallsView.java
index 635dac9..12f017b 100644
--- a/libs/rs/java/Balls/src/com/android/balls/BallsView.java
+++ b/libs/rs/java/Balls/src/com/android/balls/BallsView.java
@@ -53,8 +53,8 @@
         super.surfaceChanged(holder, format, w, h);
         if (mRS == null) {
             RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            mRS = createRenderScript(sc);
-            mRS.contextSetSurface(w, h, holder.getSurface());
+            mRS = createRenderScriptGL(sc);
+            mRS.setSurface(holder, w, h);
             mRender = new BallsRS();
             mRender.init(mRS, getResources(), w, h);
         }
@@ -65,7 +65,7 @@
     protected void onDetachedFromWindow() {
         if(mRS != null) {
             mRS = null;
-            destroyRenderScript();
+            destroyRenderScriptGL();
         }
     }
 
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java b/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java
index 9ae3e67..116c478 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/Fountain.java
@@ -67,7 +67,7 @@
         // Ideally a game should implement onResume() and onPause()
         // to take appropriate action when the activity looses focus
         super.onResume();
-        mView.onResume();
+        mView.resume();
     }
 
     @Override
@@ -77,7 +77,7 @@
         // Ideally a game should implement onResume() and onPause()
         // to take appropriate action when the activity looses focus
         super.onPause();
-        mView.onPause();
+        mView.pause();
 
 
 
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 53fb6462..5188050 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainRS.java
@@ -36,7 +36,7 @@
 
         ProgramFragment.Builder pfb = new ProgramFragment.Builder(rs);
         pfb.setVaryingColor(true);
-        rs.contextBindProgramFragment(pfb.create());
+        rs.bindProgramFragment(pfb.create());
 
         ScriptField_Point points = new ScriptField_Point(mRS, PART_COUNT);
 
@@ -48,7 +48,7 @@
         mScript = new ScriptC_fountain(mRS, mRes, R.raw.fountain);
         mScript.set_partMesh(sm);
         mScript.bind_point(points);
-        mRS.contextBindRootScript(mScript);
+        mRS.bindRootScript(mScript);
     }
 
     boolean holdingColor[] = new boolean[10];
diff --git a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
index 50a9707..69b181d 100644
--- a/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
+++ b/libs/rs/java/Fountain/src/com/android/fountain/FountainView.java
@@ -53,8 +53,8 @@
         super.surfaceChanged(holder, format, w, h);
         if (mRS == null) {
             RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            mRS = createRenderScript(sc);
-            mRS.contextSetSurface(w, h, holder.getSurface());
+            mRS = createRenderScriptGL(sc);
+            mRS.setSurface(holder, w, h);
             mRender = new FountainRS();
             mRender.init(mRS, getResources(), w, h);
         }
@@ -64,7 +64,7 @@
     protected void onDetachedFromWindow() {
         if (mRS != null) {
             mRS = null;
-            destroyRenderScript();
+            destroyRenderScriptGL();
         }
     }
 
diff --git a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
index c617759..e935fa9 100644
--- a/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
+++ b/libs/rs/java/ImageProcessing/src/com/android/rs/image/ImageProcessingActivity.java
@@ -78,7 +78,7 @@
     private SurfaceView mSurfaceView;
     private ImageView mDisplayView;
 
-    class FilterCallback extends RenderScript.RSMessage {
+    class FilterCallback extends RenderScript.RSMessageHandler {
         private Runnable mAction = new Runnable() {
             public void run() {
                 mDisplayView.invalidate();
@@ -363,14 +363,14 @@
 
     private void createScript() {
         mRS = RenderScript.create();
-        mRS.mMessageCallback = new FilterCallback();
+        mRS.setMessageHandler(new FilterCallback());
 
         mInPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapIn);
         mOutPixelsAllocation = Allocation.createBitmapRef(mRS, mBitmapOut);
 
         Type.Builder tb = new Type.Builder(mRS, Element.F32_4(mRS));
-        tb.add(android.renderscript.Dimension.X, mBitmapIn.getWidth());
-        tb.add(android.renderscript.Dimension.Y, mBitmapIn.getHeight());
+        tb.setX(mBitmapIn.getWidth());
+        tb.setY(mBitmapIn.getHeight());
         mScratchPixelsAllocation1 = Allocation.createTyped(mRS, tb.create());
         mScratchPixelsAllocation2 = Allocation.createTyped(mRS, tb.create());
 
diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraph.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraph.java
index 557e0cc..b8717a7 100644
--- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraph.java
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraph.java
@@ -56,7 +56,7 @@
         // Ideally a game should implement onResume() and onPause()
         // to take appropriate action when the activity looses focus
         super.onResume();
-        mView.onResume();
+        mView.resume();
     }
 
     @Override
@@ -64,7 +64,7 @@
         // Ideally a game should implement onResume() and onPause()
         // to take appropriate action when the activity looses focus
         super.onPause();
-        mView.onPause();
+        mView.pause();
     }
 
 }
diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java
index 954ec96..07a4412 100644
--- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphRS.java
@@ -210,7 +210,7 @@
         mScript.bind_gRobot2(mRobot2.mParent.mChildField);
         mScript.set_gRobot2Index(mRobot2.mIndexInParentGroup);
 
-        mRS.contextBindRootScript(mScript);
+        mRS.bindRootScript(mScript);
     }
 }
 
diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphView.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphView.java
index 1cabba1..0b6a3b8 100644
--- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphView.java
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SceneGraphView.java
@@ -55,8 +55,8 @@
         if (mRS == null) {
             RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
             sc.setDepth(16, 24);
-            mRS = createRenderScript(sc);
-            mRS.contextSetSurface(w, h, holder.getSurface());
+            mRS = createRenderScriptGL(sc);
+            mRS.setSurface(holder, w, h);
             mRender = new SceneGraphRS();
             mRender.init(mRS, getResources(), w, h);
         }
@@ -66,7 +66,7 @@
     protected void onDetachedFromWindow() {
         if (mRS != null) {
             mRS = null;
-            destroyRenderScript();
+            destroyRenderScriptGL();
         }
     }
 
diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModel.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModel.java
index cb7c39c..9910970 100644
--- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModel.java
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModel.java
@@ -56,7 +56,7 @@
         // Ideally a game should implement onResume() and onPause()
         // to take appropriate action when the activity looses focus
         super.onResume();
-        mView.onResume();
+        mView.resume();
     }
 
     @Override
@@ -64,7 +64,7 @@
         // Ideally a game should implement onResume() and onPause()
         // to take appropriate action when the activity looses focus
         super.onPause();
-        mView.onPause();
+        mView.pause();
     }
 
 }
diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java
index 29c3728..fb9e4c1 100644
--- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelRS.java
@@ -160,7 +160,7 @@
 
         initTextAllocation();
 
-        mRS.contextBindRootScript(mScript);
+        mRS.bindRootScript(mScript);
     }
 }
 
diff --git a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelView.java b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelView.java
index 875c4bd..5c5956d 100644
--- a/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelView.java
+++ b/libs/rs/java/ModelViewer/src/com/android/modelviewer/SimpleModelView.java
@@ -55,8 +55,8 @@
         if (mRS == null) {
             RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
             sc.setDepth(16, 24);
-            mRS = createRenderScript(sc);
-            mRS.contextSetSurface(w, h, holder.getSurface());
+            mRS = createRenderScriptGL(sc);
+            mRS.setSurface(holder, w, h);
             mRender = new SimpleModelRS();
             mRender.init(mRS, getResources(), w, h);
         }
@@ -66,7 +66,7 @@
     protected void onDetachedFromWindow() {
         if (mRS != null) {
             mRS = null;
-            destroyRenderScript();
+            destroyRenderScriptGL();
         }
     }
 
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsList.java b/libs/rs/java/Samples/src/com/android/samples/RsList.java
index 0f6b1ac..d47be42 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsList.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsList.java
@@ -56,7 +56,7 @@
         // Ideally a game should implement onResume() and onPause()
         // to take appropriate action when the activity loses focus
         super.onResume();
-        mView.onResume();
+        mView.resume();
     }
 
     @Override
@@ -64,7 +64,7 @@
         // Ideally a game should implement onResume() and onPause()
         // to take appropriate action when the activity loses focus
         super.onPause();
-        mView.onPause();
+        mView.pause();
     }
 
 }
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsListRS.java b/libs/rs/java/Samples/src/com/android/samples/RsListRS.java
index 3aa20e8..e139107 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsListRS.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsListRS.java
@@ -137,7 +137,7 @@
         mItalic = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8);
         mScript.set_gItalic(mItalic);
 
-        mRS.contextBindRootScript(mScript);
+        mRS.bindRootScript(mScript);
     }
 }
 
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsListView.java b/libs/rs/java/Samples/src/com/android/samples/RsListView.java
index 21b58b1..00b1723 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsListView.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsListView.java
@@ -55,8 +55,8 @@
         if (mRS == null) {
             RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
             sc.setDepth(16, 24);
-            mRS = createRenderScript(sc);
-            mRS.contextSetSurface(w, h, holder.getSurface());
+            mRS = createRenderScriptGL(sc);
+            mRS.setSurface(holder, w, h);
             mRender = new RsListRS();
             mRender.init(mRS, getResources(), w, h);
         }
@@ -66,7 +66,7 @@
     protected void onDetachedFromWindow() {
         if (mRS != null) {
             mRS = null;
-            destroyRenderScript();
+            destroyRenderScriptGL();
         }
     }
 
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java
index 391007e..33c1719 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStates.java
@@ -56,7 +56,7 @@
         // Ideally a game should implement onResume() and onPause()
         // to take appropriate action when the activity looses focus
         super.onResume();
-        mView.onResume();
+        mView.resume();
     }
 
     @Override
@@ -64,7 +64,7 @@
         // Ideally a game should implement onResume() and onPause()
         // to take appropriate action when the activity looses focus
         super.onPause();
-        mView.onPause();
+        mView.pause();
     }
 
 }
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java
index 766601b..aff36de 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesRS.java
@@ -396,7 +396,7 @@
         initProgramRaster();
         initCustomShaders();
 
-        mRS.contextBindRootScript(mScript);
+        mRS.bindRootScript(mScript);
     }
 }
 
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java
index 6893d20..235d29b 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsRenderStatesView.java
@@ -55,8 +55,8 @@
         if (mRS == null) {
             RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
             sc.setDepth(16, 24);
-            mRS = createRenderScript(sc);
-            mRS.contextSetSurface(w, h, holder.getSurface());
+            mRS = createRenderScriptGL(sc);
+            mRS.setSurface(holder, w, h);
             mRender = new RsRenderStatesRS();
             mRender.init(mRS, getResources(), w, h);
         }
@@ -66,7 +66,7 @@
     protected void onDetachedFromWindow() {
         if (mRS != null) {
             mRS = null;
-            destroyRenderScript();
+            destroyRenderScriptGL();
         }
     }
 
diff --git a/libs/rs/java/tests/src/com/android/rs/test/RSTest.java b/libs/rs/java/tests/src/com/android/rs/test/RSTest.java
index c264649..6b8fa6b 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/RSTest.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/RSTest.java
@@ -63,7 +63,7 @@
         // Ideally a game should implement onResume() and onPause()
         // to take appropriate action when the activity loses focus
         super.onResume();
-        mView.onResume();
+        mView.resume();
     }
 
     @Override
@@ -71,7 +71,7 @@
         // Ideally a game should implement onResume() and onPause()
         // to take appropriate action when the activity loses focus
         super.onPause();
-        mView.onPause();
+        mView.pause();
     }
 
     static void log(String message) {
diff --git a/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java b/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java
index d2ce6c8..a1d1c2b 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/RSTestCore.java
@@ -95,7 +95,7 @@
         mFont = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD, 8);
         mScript.set_gFont(mFont);
 
-        mRS.contextBindRootScript(mScript);
+        mRS.bindRootScript(mScript);
 
         test_iter = unitTests.listIterator();
         refreshTestResults(); /* Kick off the first test */
@@ -148,7 +148,7 @@
             mListAllocs.copyAll();
 
             mScript.bind_gList(mListAllocs);
-            mRS.contextBindRootScript(mScript);
+            mRS.bindRootScript(mScript);
         }
     }
 
diff --git a/libs/rs/java/tests/src/com/android/rs/test/RSTestView.java b/libs/rs/java/tests/src/com/android/rs/test/RSTestView.java
index c65f8c6..2f7542d 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/RSTestView.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/RSTestView.java
@@ -53,8 +53,8 @@
         super.surfaceChanged(holder, format, w, h);
         if (mRS == null) {
             RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
-            mRS = createRenderScript(sc);
-            mRS.contextSetSurface(w, h, holder.getSurface());
+            mRS = createRenderScriptGL(sc);
+            mRS.setSurface(holder, w, h);
             mRender = new RSTestCore();
             mRender.init(mRS, getResources(), w, h);
         }
@@ -65,7 +65,7 @@
         if(mRS != null) {
             mRender.cleanup();
             mRS = null;
-            destroyRenderScript();
+            destroyRenderScriptGL();
         }
     }
 
diff --git a/libs/rs/java/tests/src/com/android/rs/test/UT_fp_mad.java b/libs/rs/java/tests/src/com/android/rs/test/UT_fp_mad.java
index e2cff00..409192b 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/UT_fp_mad.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/UT_fp_mad.java
@@ -30,7 +30,7 @@
     public void run() {
         RenderScript pRS = RenderScript.create();
         ScriptC_fp_mad s = new ScriptC_fp_mad(pRS, mRes, R.raw.fp_mad);
-        pRS.mMessageCallback = mRsMessage;
+        pRS.setMessageHandler(mRsMessage);
         s.invoke_fp_mad_test(0, 0);
         pRS.finish();
         waitForMessage();
diff --git a/libs/rs/java/tests/src/com/android/rs/test/UT_primitives.java b/libs/rs/java/tests/src/com/android/rs/test/UT_primitives.java
index 2da43fc..6e0859a 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/UT_primitives.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/UT_primitives.java
@@ -89,7 +89,7 @@
     public void run() {
         RenderScript pRS = RenderScript.create();
         ScriptC_primitives s = new ScriptC_primitives(pRS, mRes, R.raw.primitives);
-        pRS.mMessageCallback = mRsMessage;
+        pRS.setMessageHandler(mRsMessage);
         if (!initializeGlobals(s)) {
             // initializeGlobals failed
             result = -1;
diff --git a/libs/rs/java/tests/src/com/android/rs/test/UT_rsdebug.java b/libs/rs/java/tests/src/com/android/rs/test/UT_rsdebug.java
index 7ad77c7..df31f98 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/UT_rsdebug.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/UT_rsdebug.java
@@ -30,7 +30,7 @@
     public void run() {
         RenderScript pRS = RenderScript.create();
         ScriptC_rsdebug s = new ScriptC_rsdebug(pRS, mRes, R.raw.rsdebug);
-        pRS.mMessageCallback = mRsMessage;
+        pRS.setMessageHandler(mRsMessage);
         s.invoke_test_rsdebug(0, 0);
         pRS.finish();
         waitForMessage();
diff --git a/libs/rs/java/tests/src/com/android/rs/test/UT_rstypes.java b/libs/rs/java/tests/src/com/android/rs/test/UT_rstypes.java
index 55f3746..d1232ce 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/UT_rstypes.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/UT_rstypes.java
@@ -29,8 +29,8 @@
 
     public void run() {
         RenderScript pRS = RenderScript.create();
-        ScriptC_rstypes s = new ScriptC_rstypes(pRS, mRes, R.raw.rstypes, true);
-        pRS.mMessageCallback = mRsMessage;
+        ScriptC_rstypes s = new ScriptC_rstypes(pRS, mRes, R.raw.rstypes);
+        pRS.setMessageHandler(mRsMessage);
         s.invoke_test_rstypes(0, 0);
         pRS.finish();
         waitForMessage();
diff --git a/libs/rs/java/tests/src/com/android/rs/test/UT_vector_array.java b/libs/rs/java/tests/src/com/android/rs/test/UT_vector_array.java
index 615ce14..6798781 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/UT_vector_array.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/UT_vector_array.java
@@ -30,7 +30,7 @@
     public void run() {
         RenderScript pRS = RenderScript.create();
         ScriptC_vector_array s = new ScriptC_vector_array(pRS, mRes, R.raw.vector_array);
-        pRS.mMessageCallback = mRsMessage;
+        pRS.setMessageHandler(mRsMessage);
         s.invoke_vector_array_test();
         pRS.finish();
         waitForMessage();
diff --git a/libs/rs/java/tests/src/com/android/rs/test/UnitTest.java b/libs/rs/java/tests/src/com/android/rs/test/UnitTest.java
index 90bb8a3..8923a19 100644
--- a/libs/rs/java/tests/src/com/android/rs/test/UnitTest.java
+++ b/libs/rs/java/tests/src/com/android/rs/test/UnitTest.java
@@ -15,7 +15,7 @@
  */
 
 package com.android.rs.test;
-import android.renderscript.RenderScript.RSMessage;
+import android.renderscript.RenderScript.RSMessageHandler;
 import android.util.Log;
 
 public class UnitTest extends Thread {
@@ -53,7 +53,7 @@
         this (null);
     }
 
-    protected RSMessage mRsMessage = new RSMessage() {
+    protected RSMessageHandler mRsMessage = new RSMessageHandler() {
         public void run() {
             if (result == 0) {
                 switch (mID) {
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index 4ade714..fbb5ac9 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -848,9 +848,7 @@
     const Element *dst = static_cast<const Element *>(_dst);
 
     //LOGE("%p rsi_AllocationCreateFromBitmap %i %i %i", rsc, w, h, genMips);
-    RsDimension dims[] = {RS_DIMENSION_X, RS_DIMENSION_Y, RS_DIMENSION_LOD};
-    uint32_t dimValues[] = {w, h, genMips};
-    RsType type = rsaTypeCreate(rsc, _dst, 3, dims, dimValues);
+    RsType type = rsaTypeCreate(rsc, _dst, w, h, 0, genMips, false);
 
     RsAllocation vTexAlloc = rsaAllocationCreateTyped(rsc, type);
     Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
@@ -888,9 +886,7 @@
     // Cubemap allocation's faces should be Width by Width each.
     // Source data should have 6 * Width by Width pixels
     // Error checking is done in the java layer
-    RsDimension dims[] = {RS_DIMENSION_X, RS_DIMENSION_Y, RS_DIMENSION_LOD, RS_DIMENSION_FACE};
-    uint32_t dimValues[] = {w, w, genMips, true};
-    RsType type = rsaTypeCreate(rsc, _dst, 4, dims, dimValues);
+    RsType type = rsaTypeCreate(rsc, _dst, w, h, 0, genMips, true);
 
     RsAllocation vTexAlloc = rsaAllocationCreateTyped(rsc, type);
     Allocation *texAlloc = static_cast<Allocation *>(vTexAlloc);
diff --git a/libs/rs/rsType.cpp b/libs/rs/rsType.cpp
index c195b9b..670ea33 100644
--- a/libs/rs/rsType.cpp
+++ b/libs/rs/rsType.cpp
@@ -272,33 +272,12 @@
 }
 }
 
-RsType rsaTypeCreate(RsContext con, RsElement _e, uint32_t dimCount,
-                     const RsDimension *dims, const uint32_t *vals) {
+RsType rsaTypeCreate(RsContext con, RsElement _e, uint32_t dimX,
+                     uint32_t dimY, uint32_t dimZ, bool mips, bool faces) {
     Context *rsc = static_cast<Context *>(con);
     Element *e = static_cast<Element *>(_e);
-    TypeState * stc = &rsc->mStateType;
 
-    uint32_t dimX = 0;
-    uint32_t dimY = 0;
-    uint32_t dimZ = 0;
-    uint32_t dimLOD = 0;
-    uint32_t dimFaces = 0;
-
-    for (uint32_t ct=0; ct < dimCount; ct++) {
-        switch (dims[ct]) {
-        case RS_DIMENSION_X: dimX = vals[ct]; break;
-        case RS_DIMENSION_Y: dimY = vals[ct]; break;
-        case RS_DIMENSION_Z: dimZ = vals[ct]; break;
-        case RS_DIMENSION_LOD: dimLOD = vals[ct]; break;
-        case RS_DIMENSION_FACE: dimFaces = vals[ct]; break;
-
-        default:
-            LOGE("rsaTypeCreate: Bad dimension");
-            rsAssert(0);
-        }
-    }
-
-    return Type::getType(rsc, e, dimX, dimY, dimZ, dimLOD, dimFaces);
+    return Type::getType(rsc, e, dimX, dimY, dimZ, mips, faces);
 }
 
 void rsaTypeGetNativeData(RsContext con, RsType type, uint32_t *typeData, uint32_t typeDataSize) {