Cleanup and refactoring of an earlier cl.

Change-Id: I5e356ed88375a1620846e0c500659e3b7ead5030
diff --git a/graphics/java/android/renderscript/Sampler.java b/graphics/java/android/renderscript/Sampler.java
index 9fbc09a..45a3949 100644
--- a/graphics/java/android/renderscript/Sampler.java
+++ b/graphics/java/android/renderscript/Sampler.java
@@ -40,6 +40,7 @@
         NEAREST (0),
         LINEAR (1),
         LINEAR_MIP_LINEAR (2),
+        LINEAR_MIP_NEAREST (5),
         WRAP (3),
         CLAMP (4);
 
@@ -201,7 +202,8 @@
         public void setMin(Value v) {
             if (v == Value.NEAREST ||
                 v == Value.LINEAR ||
-                v == Value.LINEAR_MIP_LINEAR) {
+                v == Value.LINEAR_MIP_LINEAR ||
+                v == Value.LINEAR_MIP_NEAREST) {
                 mMin = v;
             } else {
                 throw new IllegalArgumentException("Invalid value");
diff --git a/libs/rs/RenderScript.h b/libs/rs/RenderScript.h
index 43d4291..3ad453f 100644
--- a/libs/rs/RenderScript.h
+++ b/libs/rs/RenderScript.h
@@ -171,7 +171,8 @@
     RS_SAMPLER_LINEAR,
     RS_SAMPLER_LINEAR_MIP_LINEAR,
     RS_SAMPLER_WRAP,
-    RS_SAMPLER_CLAMP
+    RS_SAMPLER_CLAMP,
+    RS_SAMPLER_LINEAR_MIP_NEAREST,
 };
 
 enum RsTextureTarget {
diff --git a/libs/rs/java/Samples/AndroidManifest.xml b/libs/rs/java/Samples/AndroidManifest.xml
index 6f35e2a..9646a77 100644
--- a/libs/rs/java/Samples/AndroidManifest.xml
+++ b/libs/rs/java/Samples/AndroidManifest.xml
@@ -4,7 +4,7 @@
     <application android:label="Samples"
     android:icon="@drawable/test_pattern">
         <activity android:name="RsList"
-                  android:label="RsList"                  
+                  android:label="RsList"
                   android:theme="@android:style/Theme.Black.NoTitleBar">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
@@ -13,7 +13,7 @@
         </activity>
         
         <activity android:name="RsRenderStates"
-                  android:label="RsStates"                  
+                  android:label="RsStates"
                   android:theme="@android:style/Theme.Black.NoTitleBar">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
@@ -22,7 +22,7 @@
         </activity>
 
         <activity android:name="RsBench"
-                  android:label="RsBenchmark"                  
+                  android:label="RsBenchmark"
                   android:theme="@android:style/Theme.Black.NoTitleBar">
             <intent-filter>
                 <action android:name="android.intent.action.MAIN" />
diff --git a/libs/rs/java/Samples/res/raw/shader2movev.glsl b/libs/rs/java/Samples/res/raw/shader2movev.glsl
index 68712e6..a2c807e 100644
--- a/libs/rs/java/Samples/res/raw/shader2movev.glsl
+++ b/libs/rs/java/Samples/res/raw/shader2movev.glsl
@@ -14,7 +14,6 @@
 
    mat3 model3 = mat3(UNI_model[0].xyz, UNI_model[1].xyz, UNI_model[2].xyz);
    vec3 worldNorm = model3 * (ATTRIB_normal + oldPos - objPos.xyz);
-   //vec3 worldNorm = model3 * ATTRIB_normal;
 
    varWorldPos = worldPos.xyz;
    varWorldNormal = worldNorm;
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsBench.java b/libs/rs/java/Samples/src/com/android/samples/RsBench.java
index 5b9af6f..a29dddc 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsBench.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsBench.java
@@ -54,7 +54,7 @@
     @Override
     protected void onResume() {
         // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
+        // to take appropriate action when the activity loses focus
         super.onResume();
         mView.resume();
     }
@@ -62,7 +62,7 @@
     @Override
     protected void onPause() {
         // Ideally a game should implement onResume() and onPause()
-        // to take appropriate action when the activity looses focus
+        // to take appropriate action when the activity loses focus
         super.onPause();
         mView.pause();
     }
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java b/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java
index a47c308..ddb05b3 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsBenchRS.java
@@ -216,7 +216,7 @@
         ProgramVertex.ShaderBuilder pvbCustom = new ProgramVertex.ShaderBuilder(mRS);
         // Specify the resource that contains the shader string
         pvbCustom.setShader(mRes, R.raw.shaderv);
-        // Use a script field to spcify the input layout
+        // Use a script field to specify the input layout
         pvbCustom.addInput(ScriptField_VertexShaderInputs_s.createElement(mRS));
         // Define the constant input layout
         pvbCustom.addConstant(mVSConst.getAllocation().getType());
@@ -227,7 +227,7 @@
         ProgramFragment.ShaderBuilder pfbCustom = new ProgramFragment.ShaderBuilder(mRS);
         // Specify the resource that contains the shader string
         pfbCustom.setShader(mRes, R.raw.shaderf);
-        //Tell the builder how many textures we have
+        // Tell the builder how many textures we have
         pfbCustom.addTexture(Program.TextureType.TEXTURE_2D);
         // Define the constant input layout
         pfbCustom.addConstant(mFSConst.getAllocation().getType());
@@ -315,16 +315,22 @@
 
     private void initFonts() {
         // Sans font by family name
-        mFontSans = Font.createFromFamily(mRS, mRes, "sans-serif", Font.Style.NORMAL, 8);
+        mFontSans = Font.createFromFamily(mRS, mRes, "sans-serif",
+                                          Font.Style.NORMAL, 8);
         // Create font by file name
         mFontSerif = Font.create(mRS, mRes, "DroidSerif-Regular.ttf", 8);
         // Create fonts by family and style
-        mFontSerifBold = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD, 8);
-        mFontSerifItalic = Font.createFromFamily(mRS, mRes, "serif", Font.Style.ITALIC, 8);
-        mFontSerifBoldItalic = Font.createFromFamily(mRS, mRes, "serif", Font.Style.BOLD_ITALIC, 8);
-        mFontMono = Font.createFromFamily(mRS, mRes, "mono", Font.Style.NORMAL, 8);
+        mFontSerifBold = Font.createFromFamily(mRS, mRes, "serif",
+                                               Font.Style.BOLD, 8);
+        mFontSerifItalic = Font.createFromFamily(mRS, mRes, "serif",
+                                                 Font.Style.ITALIC, 8);
+        mFontSerifBoldItalic = Font.createFromFamily(mRS, mRes, "serif",
+                                                     Font.Style.BOLD_ITALIC, 8);
+        mFontMono = Font.createFromFamily(mRS, mRes, "mono",
+                                          Font.Style.NORMAL, 8);
 
-        mTextAlloc = Allocation.createFromString(mRS, "String from allocation", Allocation.USAGE_SCRIPT);
+        mTextAlloc = Allocation.createFromString(mRS, "String from allocation",
+                                                 Allocation.USAGE_SCRIPT);
 
         mScript.set_gFontSans(mFontSans);
         mScript.set_gFontSerif(mFontSerif);
diff --git a/libs/rs/java/Samples/src/com/android/samples/RsBenchView.java b/libs/rs/java/Samples/src/com/android/samples/RsBenchView.java
index 4283a42..0a56668 100644
--- a/libs/rs/java/Samples/src/com/android/samples/RsBenchView.java
+++ b/libs/rs/java/Samples/src/com/android/samples/RsBenchView.java
@@ -43,7 +43,6 @@
 
     public RsBenchView(Context context) {
         super(context);
-        //setFocusable(true);
     }
 
     private RenderScriptGL mRS;
@@ -71,17 +70,13 @@
     }
 
     @Override
-    public boolean onKeyDown(int keyCode, KeyEvent event)
-    {
-        // break point at here
-        // this method doesn't work when 'extends View' include 'extends ScrollView'.
+    public boolean onKeyDown(int keyCode, KeyEvent event) {
         return super.onKeyDown(keyCode, event);
     }
 
 
     @Override
-    public boolean onTouchEvent(MotionEvent ev)
-    {
+    public boolean onTouchEvent(MotionEvent ev) {
         boolean ret = false;
         int act = ev.getAction();
         if (act == ev.ACTION_DOWN) {
diff --git a/libs/rs/java/Samples/src/com/android/samples/rsbench.rs b/libs/rs/java/Samples/src/com/android/samples/rsbench.rs
index 87f2f29..905f34b 100644
--- a/libs/rs/java/Samples/src/com/android/samples/rsbench.rs
+++ b/libs/rs/java/Samples/src/com/android/samples/rsbench.rs
@@ -19,7 +19,7 @@
 #include "rs_graphics.rsh"
 #include "shader_def.rsh"
 
-const int gMaxModes = 23;
+const int gMaxModes = 26;
 
 rs_program_vertex gProgVertex;
 rs_program_fragment gProgFragmentColor;
@@ -94,7 +94,14 @@
                              0.5f, 0.6f, 0.7f, 1.0f,
 };
 
-void displayFontSamples(int fillNum) {
+static void displayFontSamples(int fillNum) {
+
+    rs_font fonts[5];
+    rsSetObject(&fonts[0], gFontSans);
+    rsSetObject(&fonts[1], gFontSerif);
+    rsSetObject(&fonts[2], gFontSerifBold);
+    rsSetObject(&fonts[3], gFontSerifBoldItalic);
+    rsSetObject(&fonts[4], gFontSans);
 
     uint width = rsgGetWidth();
     uint height = rsgGetHeight();
@@ -107,9 +114,8 @@
     int yPos = top;
 
     int xOffset = 0, yOffset = 0;
-    rsgBindFont(gFontSans); //rsgBindFont(gFontSerif); rsgBindFont(gFontSerifBold); rsgBindFont(gFontSerifBoldItalic); rsgBindFont(gFontSans);
-
     for(int fillI = 0; fillI < fillNum; fillI ++) {
+        rsgBindFont(fonts[fillI]);
         xOffset = textOffsets[fillI * 2];
         yOffset = textOffsets[fillI * 2 + 1];
         float *colPtr = textColors + fillI * 4;
@@ -122,18 +128,22 @@
             }
         }
     }
+
+    for (int i = 0; i < 5; i ++) {
+        rsClearObject(&fonts[i]);
+    }
 }
 
-void bindProgramVertexOrtho() {
+static void bindProgramVertexOrtho() {
     // Default vertex sahder
     rsgBindProgramVertex(gProgVertex);
-    // Setup the projectioni matrix
+    // Setup the projection matrix
     rs_matrix4x4 proj;
     rsMatrixLoadOrtho(&proj, 0, rsgGetWidth(), rsgGetHeight(), 0, -500, 500);
     rsgProgramVertexLoadProjectionMatrix(&proj);
 }
 
-void displaySingletexFill(bool blend, int quadCount) {
+static void displaySingletexFill(bool blend, int quadCount) {
     bindProgramVertexOrtho();
     rs_matrix4x4 matrix;
     rsMatrixLoadIdentity(&matrix);
@@ -159,7 +169,7 @@
     }
 }
 
-void displayBlendingSamples() {
+static void displayBlendingSamples() {
     int i;
 
     bindProgramVertexOrtho();
@@ -205,7 +215,7 @@
 
 }
 
-void displayMeshSamples(int meshNum) {
+static void displayMeshSamples(int meshNum) {
 
     bindProgramVertexOrtho();
     rs_matrix4x4 matrix;
@@ -227,7 +237,7 @@
     }
 }
 
-void displayTextureSamplers() {
+static void displayTextureSamplers() {
 
     bindProgramVertexOrtho();
     rs_matrix4x4 matrix;
@@ -282,27 +292,34 @@
     rsgDrawText("Filtering: miplinear wrap", 310, 590);
 }
 
-float gTorusRotation = 0;
-static void drawToruses(int numMeshes) {
-    rs_matrix4x4 matrix;
+static float gTorusRotation = 0;
+static void updateModelMatrix(rs_matrix4x4 *matrix, void *buffer) {
+    if (buffer == 0) {
+        rsgProgramVertexLoadModelMatrix(matrix);
+    } else {
+        rsAllocationMarkDirty(rsGetAllocation(buffer));
+    }
+}
+
+static void drawToruses(int numMeshes, rs_matrix4x4 *matrix, void *buffer) {
 
     if (numMeshes == 1) {
-        rsMatrixLoadTranslate(&matrix, 0.0f, 0.0f, -7.5f);
-        rsMatrixRotate(&matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
-        rsgProgramVertexLoadModelMatrix(&matrix);
+        rsMatrixLoadTranslate(matrix, 0.0f, 0.0f, -7.5f);
+        rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
+        updateModelMatrix(matrix, buffer);
         rsgDrawMesh(gTorusMesh);
         return;
     }
 
     if (numMeshes == 2) {
-        rsMatrixLoadTranslate(&matrix, -1.6f, 0.0f, -7.5f);
-        rsMatrixRotate(&matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
-        rsgProgramVertexLoadModelMatrix(&matrix);
+        rsMatrixLoadTranslate(matrix, -1.6f, 0.0f, -7.5f);
+        rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
+        updateModelMatrix(matrix, buffer);
         rsgDrawMesh(gTorusMesh);
 
-        rsMatrixLoadTranslate(&matrix, 1.6f, 0.0f, -7.5f);
-        rsMatrixRotate(&matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
-        rsgProgramVertexLoadModelMatrix(&matrix);
+        rsMatrixLoadTranslate(matrix, 1.6f, 0.0f, -7.5f);
+        rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
+        updateModelMatrix(matrix, buffer);
         rsgDrawMesh(gTorusMesh);
         return;
     }
@@ -315,9 +332,9 @@
     for (int h = 0; h < 4; h ++) {
         for (int v = 0; v < 2; v ++) {
             // Position our model on the screen
-            rsMatrixLoadTranslate(&matrix, startX + dist * h, startY + dist * v, startZ);
-            rsMatrixRotate(&matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
-            rsgProgramVertexLoadModelMatrix(&matrix);
+            rsMatrixLoadTranslate(matrix, startX + dist * h, startY + dist * v, startZ);
+            rsMatrixRotate(matrix, gTorusRotation, 1.0f, 0.0f, 0.0f);
+            updateModelMatrix(matrix, buffer);
             rsgDrawMesh(gTorusMesh);
         }
     }
@@ -325,10 +342,10 @@
 
 
 // Quick hack to get some geometry numbers
-void displaySimpleGeoSamples(bool useTexture, int numMeshes) {
+static void displaySimpleGeoSamples(bool useTexture, int numMeshes) {
     rsgBindProgramVertex(gProgVertex);
     rsgBindProgramRaster(gCullBack);
-    // Setup the projectioni matrix with 60 degree field of view
+    // Setup the projection matrix with 30 degree field of view
     rs_matrix4x4 proj;
     float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
     rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f);
@@ -345,19 +362,20 @@
     rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
     rsgBindTexture(gProgFragmentTexture, 0, gTexTorus);
 
-    // Aplly a rotation to our mesh
+    // Apply a rotation to our mesh
     gTorusRotation += 50.0f * gDt;
     if (gTorusRotation > 360.0f) {
         gTorusRotation -= 360.0f;
     }
 
-    drawToruses(numMeshes);
+    rs_matrix4x4 matrix;
+    drawToruses(numMeshes, &matrix, 0);
 }
 
 float gLight0Rotation = 0;
 float gLight1Rotation = 0;
 
-void setupCustomShaderLights() {
+static void setupCustomShaderLights() {
     float4 light0Pos = {-5.0f, 5.0f, -10.0f, 1.0f};
     float4 light1Pos = {2.0f, 5.0f, 15.0f, 1.0f};
     float4 light0DiffCol = {0.9f, 0.7f, 0.7f, 1.0f};
@@ -393,7 +411,7 @@
     gVSConstants->light1_CosinePower = 25.0f;
     rsAllocationMarkDirty(rsGetAllocation(gVSConstants));
 
-    // Update fragmetn shader constants
+    // Update fragment shader constants
     // Set light 0 colors
     gFSConstants->light0_DiffuseColor = light0DiffCol;
     gFSConstants->light0_SpecularColor = light0SpecCol;
@@ -419,17 +437,17 @@
     rsAllocationMarkDirty(rsGetAllocation(gFSConstPixel));
 }
 
-void displayCustomShaderSamples(int numMeshes) {
+static void displayCustomShaderSamples(int numMeshes) {
 
     // Update vertex shader constants
     // Load model matrix
-    // Aplly a rotation to our mesh
+    // Apply a rotation to our mesh
     gTorusRotation += 50.0f * gDt;
     if (gTorusRotation > 360.0f) {
         gTorusRotation -= 360.0f;
     }
 
-    // Setup the projectioni matrix
+    // Setup the projection matrix
     float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
     rsMatrixLoadPerspective(&gVSConstants->proj, 30.0f, aspect, 0.1f, 100.0f);
     setupCustomShaderLights();
@@ -445,70 +463,31 @@
     // Use back face culling
     rsgBindProgramRaster(gCullBack);
 
-    rs_matrix4x4 matrix;
-
-    if (numMeshes == 1) {
-        rsMatrixLoadTranslate(&gVSConstants->model, 0.0f, 0.0f, -7.5f);
-        rsMatrixRotate(&gVSConstants->model, gTorusRotation, 1.0f, 0.0f, 0.0f);
-        rsMatrixRotate(&gVSConstants->model, gTorusRotation, 0.0f, 0.0f, 1.0f);
-        rsAllocationMarkDirty(rsGetAllocation(gVSConstants));
-
-        rsgDrawMesh(gTorusMesh);
-        return;
-    }
-
-    if (numMeshes == 2) {
-        rsMatrixLoadTranslate(&gVSConstants->model, -1.6f, 0.0f, -7.5f);
-        rsMatrixRotate(&gVSConstants->model, gTorusRotation, 1.0f, 0.0f, 0.0f);
-        rsMatrixRotate(&gVSConstants->model, gTorusRotation, 0.0f, 0.0f, 1.0f);
-        rsAllocationMarkDirty(rsGetAllocation(gVSConstants));
-        rsgDrawMesh(gTorusMesh);
-
-        rsMatrixLoadTranslate(&gVSConstants->model, 1.6f, 0.0f, -7.5f);
-        rsMatrixRotate(&gVSConstants->model, gTorusRotation, 1.0f, 0.0f, 0.0f);
-        rsMatrixRotate(&gVSConstants->model, gTorusRotation, 0.0f, 0.0f, 1.0f);
-        rsAllocationMarkDirty(rsGetAllocation(gVSConstants));
-        rsgDrawMesh(gTorusMesh);
-        return;
-    }
-
-    float startX = -5.0f;
-    float startY = -1.5f;
-    float startZ = -15.0f;
-    float dist = 3.2f;
-
-    for (int h = 0; h < 4; h ++) {
-        for (int v = 0; v < 2; v ++) {
-            // Position our model on the screen
-            rsMatrixLoadTranslate(&gVSConstants->model, startX + dist * h, startY + dist * v, startZ);
-            rsMatrixRotate(&gVSConstants->model, gTorusRotation, 1.0f, 0.0f, 0.0f);
-            rsMatrixRotate(&gVSConstants->model, gTorusRotation, 0.0f, 0.0f, 1.0f);
-            rsAllocationMarkDirty(rsGetAllocation(gVSConstants));
-            rsgDrawMesh(gTorusMesh);
-        }
-    }
+    drawToruses(numMeshes, &gVSConstants->model, gVSConstants);
 }
 
-void displayPixelLightSamples(int numMeshes) {
+static void displayPixelLightSamples(int numMeshes, bool heavyVertex) {
 
     // Update vertex shader constants
     // Load model matrix
-    // Aplly a rotation to our mesh
-    gTorusRotation += 20.0f * gDt;
+    // Apply a rotation to our mesh
+    gTorusRotation += 30.0f * gDt;
     if (gTorusRotation > 360.0f) {
         gTorusRotation -= 360.0f;
     }
 
-    //gTorusRotation = 45.0f;
-
     gVSConstPixel->time = rsUptimeMillis()*0.005;
 
-    // Setup the projectioni matrix
+    // Setup the projection matrix
     float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
     rsMatrixLoadPerspective(&gVSConstPixel->proj, 30.0f, aspect, 0.1f, 100.0f);
     setupCustomShaderLights();
 
-    rsgBindProgramVertex(gProgVertexPixelLight);
+    if (heavyVertex) {
+        rsgBindProgramVertex(gProgVertexPixelLightMove);
+    } else {
+        rsgBindProgramVertex(gProgVertexPixelLight);
+    }
 
     // Fragment shader with texture
     rsgBindProgramStore(gProgStoreBlendNoneDepth);
@@ -519,51 +498,10 @@
     // Use back face culling
     rsgBindProgramRaster(gCullBack);
 
-    rs_matrix4x4 matrix;
-
-    if (numMeshes == 1) {
-        rsMatrixLoadTranslate(&gVSConstPixel->model, 0.0f, 0.0f, -7.5f);
-        rsMatrixRotate(&gVSConstPixel->model, gTorusRotation, 1.0f, 0.0f, 0.0f);
-        rsMatrixRotate(&gVSConstPixel->model, gTorusRotation, 0.0f, 0.0f, 1.0f);
-        rsAllocationMarkDirty(rsGetAllocation(gVSConstPixel));
-
-        rsgDrawMesh(gTorusMesh);
-        return;
-    }
-
-    if (numMeshes == 2) {
-        rsMatrixLoadTranslate(&gVSConstPixel->model, -1.6f, 0.0f, -7.5f);
-        rsMatrixRotate(&gVSConstPixel->model, gTorusRotation, 1.0f, 0.0f, 0.0f);
-        rsMatrixRotate(&gVSConstPixel->model, gTorusRotation, 0.0f, 0.0f, 1.0f);
-        rsAllocationMarkDirty(rsGetAllocation(gVSConstPixel));
-        rsgDrawMesh(gTorusMesh);
-
-        rsMatrixLoadTranslate(&gVSConstPixel->model, 1.6f, 0.0f, -7.5f);
-        rsMatrixRotate(&gVSConstPixel->model, gTorusRotation, 1.0f, 0.0f, 0.0f);
-        rsMatrixRotate(&gVSConstPixel->model, gTorusRotation, 0.0f, 0.0f, 1.0f);
-        rsAllocationMarkDirty(rsGetAllocation(gVSConstPixel));
-        rsgDrawMesh(gTorusMesh);
-        return;
-    }
-
-    float startX = -5.0f;
-    float startY = -1.5f;
-    float startZ = -15.0f;
-    float dist = 3.2f;
-
-    for (int h = 0; h < 4; h ++) {
-        for (int v = 0; v < 2; v ++) {
-            // Position our model on the screen
-            rsMatrixLoadTranslate(&gVSConstPixel->model, startX + dist * h, startY + dist * v, startZ);
-            rsMatrixRotate(&gVSConstPixel->model, gTorusRotation, 1.0f, 0.0f, 0.0f);
-            rsMatrixRotate(&gVSConstPixel->model, gTorusRotation, 0.0f, 0.0f, 1.0f);
-            rsAllocationMarkDirty(rsGetAllocation(gVSConstPixel));
-            rsgDrawMesh(gTorusMesh);
-        }
-    }
+    drawToruses(numMeshes, &gVSConstPixel->model, gVSConstPixel);
 }
 
-void displayMultitextureSample(bool blend, int quadCount) {
+static void displayMultitextureSample(bool blend, int quadCount) {
     bindProgramVertexOrtho();
     rs_matrix4x4 matrix;
     rsMatrixLoadIdentity(&matrix);
@@ -593,9 +531,9 @@
     }
 }
 
-float gAnisoTime = 0.0f;
-uint anisoMode = 0;
-void displayAnisoSample() {
+static float gAnisoTime = 0.0f;
+static uint anisoMode = 0;
+static void displayAnisoSample() {
 
     gAnisoTime += gDt;
 
@@ -672,6 +610,8 @@
         displayTextureSamplers();
         displayMultitextureSample(true, 5);
         displayAnisoSample();
+        displayPixelLightSamples(1, false);
+        displayPixelLightSamples(1, true);
         countdown --;
         rsgClearColor(0.2f, 0.2f, 0.2f, 0.0f);
 
@@ -699,7 +639,7 @@
 static int totalFramesRendered = 0;
 static int benchMode = 0;
 
-#define testTime 10.0f
+#define testTime 5.0f
 static float curTestTime = testTime;
 
 static const char *testNames[] = {
@@ -727,12 +667,9 @@
     "Finished 25.6k geo heavy fragment",
     "Finished 51.2k geo heavy fragment",
     "Finished 204.8k geo raster load heavy fragment",
-    "Finished simpleGeo",
-    "Finished simpleGeo",
-    "Finished simpleGeo",
-    "Finished simpleGeo",
-    "Finished simpleGeo",
-    "Finished simpleGeo",
+    "Finished 25.6k geo heavy fragment, heavy vertex",
+    "Finished 51.2k geo heavy fragment, heavy vertex",
+    "Finished 204.8k geo raster load heavy fragment, heavy vertex",
 };
 
 int root(int launchID) {
@@ -746,9 +683,6 @@
         return 1;
     }
 
-    /*displayPixelLightSamples(1);
-    return 1;*/
-
     curTestTime -= gDt;
     if(curTestTime < 0.0f) {
         float fps = (float)(frameCount) / (testTime - curTestTime);
@@ -829,14 +763,24 @@
         displayMultitextureSample(true, 5);
         break;
     case 21:
-        displayPixelLightSamples(1);
+        displayPixelLightSamples(1, false);
         break;
     case 22:
-        displayPixelLightSamples(2);
+        displayPixelLightSamples(2, false);
         break;
     case 23:
-        displayPixelLightSamples(8);
+        displayPixelLightSamples(8, false);
         break;
+    case 24:
+        displayPixelLightSamples(1, true);
+        break;
+    case 25:
+        displayPixelLightSamples(2, true);
+        break;
+    case 26:
+        displayPixelLightSamples(8, true);
+        break;
+
     }
 
     frameCount ++;
diff --git a/libs/rs/java/Samples/src/com/android/samples/rsrenderstates.rs b/libs/rs/java/Samples/src/com/android/samples/rsrenderstates.rs
index 39b0834..a973167 100644
--- a/libs/rs/java/Samples/src/com/android/samples/rsrenderstates.rs
+++ b/libs/rs/java/Samples/src/com/android/samples/rsrenderstates.rs
@@ -81,7 +81,7 @@
 void init() {
 }
 
-void displayFontSamples() {
+static void displayFontSamples() {
     rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
     int yPos = 100;
     rsgBindFont(gFontSans);
@@ -148,7 +148,7 @@
 
 }
 
-void bindProgramVertexOrtho() {
+static void bindProgramVertexOrtho() {
     // Default vertex sahder
     rsgBindProgramVertex(gProgVertex);
     // Setup the projectioni matrix
@@ -157,7 +157,7 @@
     rsgProgramVertexLoadProjectionMatrix(&proj);
 }
 
-void displayShaderSamples() {
+static void displayShaderSamples() {
     bindProgramVertexOrtho();
     rs_matrix4x4 matrix;
     rsMatrixLoadIdentity(&matrix);
@@ -206,7 +206,7 @@
     rsgDrawText("Flat color shader", 100, 450);
 }
 
-void displayBlendingSamples() {
+static void displayBlendingSamples() {
     int i;
 
     bindProgramVertexOrtho();
@@ -252,7 +252,7 @@
 
 }
 
-void displayMeshSamples() {
+static void displayMeshSamples() {
 
     bindProgramVertexOrtho();
     rs_matrix4x4 matrix;
@@ -272,7 +272,7 @@
     rsgDrawText("User gen 10 by 10 grid mesh", 10, 250);
 }
 
-void displayTextureSamplers() {
+static void displayTextureSamplers() {
 
     bindProgramVertexOrtho();
     rs_matrix4x4 matrix;
@@ -327,9 +327,9 @@
     rsgDrawText("Filtering: miplinear wrap", 310, 590);
 }
 
-float gTorusRotation = 0;
+static float gTorusRotation = 0;
 
-void displayCullingSamples() {
+static void displayCullingSamples() {
     rsgBindProgramVertex(gProgVertex);
     // Setup the projectioni matrix with 60 degree field of view
     rs_matrix4x4 proj;
@@ -370,10 +370,10 @@
     rsgDrawText("Displaying mesh front/back face culling", 10, rsgGetHeight() - 10);
 }
 
-float gLight0Rotation = 0;
-float gLight1Rotation = 0;
+static float gLight0Rotation = 0;
+static float gLight1Rotation = 0;
 
-void setupCustomShaderLights() {
+static void setupCustomShaderLights() {
     float4 light0Pos = {-5.0f, 5.0f, -10.0f, 1.0f};
     float4 light1Pos = {2.0f, 5.0f, 15.0f, 1.0f};
     float4 light0DiffCol = {0.9f, 0.7f, 0.7f, 1.0f};
@@ -436,7 +436,7 @@
     rsAllocationMarkDirty(rsGetAllocation(gFSConstants2));
 }
 
-void displayCustomShaderSamples() {
+static void displayCustomShaderSamples() {
 
     // Update vertex shader constants
     // Load model matrix
@@ -472,7 +472,7 @@
     rsgDrawText("Custom shader sample", 10, rsgGetHeight() - 10);
 }
 
-void displayCustomShaderSamples2() {
+static void displayCustomShaderSamples2() {
 
     // Update vertex shader constants
     // Load model matrix
@@ -509,7 +509,7 @@
     rsgDrawText("Custom shader sample with array uniforms", 10, rsgGetHeight() - 10);
 }
 
-void displayCubemapShaderSample() {
+static void displayCubemapShaderSample() {
     // Update vertex shader constants
     // Load model matrix
     // Aplly a rotation to our mesh
@@ -545,7 +545,7 @@
     rsgDrawText("Cubemap shader sample", 10, rsgGetHeight() - 10);
 }
 
-void displayMultitextureSample() {
+static void displayMultitextureSample() {
     bindProgramVertexOrtho();
     rs_matrix4x4 matrix;
     rsMatrixLoadIdentity(&matrix);
@@ -573,9 +573,9 @@
     rsgDrawText("Custom shader with multitexturing", 10, 280);
 }
 
-float gAnisoTime = 0.0f;
-uint anisoMode = 0;
-void displayAnisoSample() {
+static float gAnisoTime = 0.0f;
+static uint anisoMode = 0;
+static void displayAnisoSample() {
 
     gAnisoTime += gDt;
 
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index cb00223..77e8032 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -31,10 +31,13 @@
 using namespace android;
 using namespace android::renderscript;
 
-Allocation::Allocation(Context *rsc, const Type *type, uint32_t usages) : ObjectBase(rsc) {
+Allocation::Allocation(Context *rsc, const Type *type, uint32_t usages,
+                       RsAllocationMipmapControl mc)
+    : ObjectBase(rsc) {
     init(rsc, type);
 
     mUsageFlags = usages;
+    mMipmapControl = mc;
 
     allocScriptMemory();
     if (mType->getElement()->getHasReferences()) {
@@ -795,7 +798,7 @@
                                       RsAllocationMipmapControl mips,
                                       uint32_t usages) {
     Context *rsc = static_cast<Context *>(con);
-    Allocation * alloc = new Allocation(rsc, static_cast<Type *>(vtype), usages);
+    Allocation * alloc = new Allocation(rsc, static_cast<Type *>(vtype), usages, mips);
     alloc->incUserRef();
     return alloc;
 }
diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h
index 4a5f3da..44dce0d 100644
--- a/libs/rs/rsAllocation.h
+++ b/libs/rs/rsAllocation.h
@@ -29,7 +29,8 @@
     // The graphics equilivent of malloc.  The allocation contains a structure of elements.
 
 public:
-    Allocation(Context *rsc, const Type *, uint32_t usages);
+    Allocation(Context *rsc, const Type *, uint32_t usages,
+               RsAllocationMipmapControl mc = RS_ALLOCATION_MIPMAP_NONE);
 
     virtual ~Allocation();
 
diff --git a/libs/rs/rsSampler.cpp b/libs/rs/rsSampler.cpp
index 54282a8..e2757df 100644
--- a/libs/rs/rsSampler.cpp
+++ b/libs/rs/rsSampler.cpp
@@ -61,6 +61,7 @@
         GL_LINEAR_MIPMAP_LINEAR, //RS_SAMPLER_LINEAR_MIP_LINEAR,
         GL_REPEAT, //RS_SAMPLER_WRAP,
         GL_CLAMP_TO_EDGE, //RS_SAMPLER_CLAMP
+        GL_LINEAR_MIPMAP_NEAREST, //RS_SAMPLER_LINEAR_MIP_NEAREST
     };
 
     GLenum transNP[] = {
@@ -69,6 +70,7 @@
         GL_LINEAR, //RS_SAMPLER_LINEAR_MIP_LINEAR,
         GL_CLAMP_TO_EDGE, //RS_SAMPLER_WRAP,
         GL_CLAMP_TO_EDGE, //RS_SAMPLER_CLAMP
+        GL_LINEAR, //RS_SAMPLER_LINEAR_MIP_NEAREST,
     };
 
     // This tells us the correct texture type