Merge "Import revised translations."
diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java
index f562851..1dcaa04 100755
--- a/core/java/android/animation/ValueAnimator.java
+++ b/core/java/android/animation/ValueAnimator.java
@@ -1173,13 +1173,11 @@
         if (oldValues != null) {
             int numValues = oldValues.length;
             anim.mValues = new PropertyValuesHolder[numValues];
-            for (int i = 0; i < numValues; ++i) {
-                anim.mValues[i] = oldValues[i].clone();
-            }
             anim.mValuesMap = new HashMap<String, PropertyValuesHolder>(numValues);
             for (int i = 0; i < numValues; ++i) {
-                PropertyValuesHolder valuesHolder = mValues[i];
-                anim.mValuesMap.put(valuesHolder.getPropertyName(), valuesHolder);
+                PropertyValuesHolder newValuesHolder = oldValues[i].clone();
+                anim.mValues[i] = newValuesHolder;
+                anim.mValuesMap.put(newValuesHolder.getPropertyName(), newValuesHolder);
             }
         }
         return anim;
diff --git a/core/java/android/os/RecoverySystem.java b/core/java/android/os/RecoverySystem.java
index 4991914..c1dd911 100644
--- a/core/java/android/os/RecoverySystem.java
+++ b/core/java/android/os/RecoverySystem.java
@@ -16,6 +16,11 @@
 
 package android.os;
 
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.util.Log;
+
 import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -37,9 +42,6 @@
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipFile;
 
-import android.content.Context;
-import android.util.Log;
-
 import org.apache.harmony.security.asn1.BerInputStream;
 import org.apache.harmony.security.pkcs7.ContentInfo;
 import org.apache.harmony.security.pkcs7.SignedData;
@@ -336,8 +338,21 @@
      * @throws IOException  if writing the recovery command file
      * fails, or if the reboot itself fails.
      */
-    public static void rebootWipeUserData(Context context)
-        throws IOException {
+    public static void rebootWipeUserData(Context context) throws IOException {
+        final ConditionVariable condition = new ConditionVariable();
+
+        Intent intent = new Intent("android.intent.action.MASTER_CLEAR_NOTIFICATION");
+        context.sendOrderedBroadcast(intent, android.Manifest.permission.MASTER_CLEAR,
+                new BroadcastReceiver() {
+                    @Override
+                    public void onReceive(Context context, Intent intent) {
+                        condition.open();
+                    }
+                }, null, 0, null, null);
+
+        // Block until the ordered broadcast has completed.
+        condition.block();
+
         bootCommand(context, "--wipe_data");
     }
 
diff --git a/core/java/android/os/storage/IMountService.java b/core/java/android/os/storage/IMountService.java
index 4c83515..27da3c3 100644
--- a/core/java/android/os/storage/IMountService.java
+++ b/core/java/android/os/storage/IMountService.java
@@ -637,6 +637,22 @@
                 }
                 return _result;
             }
+
+            public String[] getVolumeList() throws RemoteException {
+                Parcel _data = Parcel.obtain();
+                Parcel _reply = Parcel.obtain();
+                String[] _result;
+                try {
+                    _data.writeInterfaceToken(DESCRIPTOR);
+                    mRemote.transact(Stub.TRANSACTION_getVolumeList, _data, _reply, 0);
+                    _reply.readException();
+                    _result = _reply.readStringArray();
+                } finally {
+                    _reply.recycle();
+                    _data.recycle();
+                }
+                return _result;
+            }
         }
 
         private static final String DESCRIPTOR = "IMountService";
@@ -699,6 +715,8 @@
 
         static final int TRANSACTION_changeEncryptionPassword = IBinder.FIRST_CALL_TRANSACTION + 28;
 
+        static final int TRANSACTION_getVolumeList = IBinder.FIRST_CALL_TRANSACTION + 29;
+
         /**
          * Cast an IBinder object into an IMountService interface, generating a
          * proxy if needed.
@@ -1004,6 +1022,13 @@
                     reply.writeInt(result);
                     return true;
                 }
+                case TRANSACTION_getVolumeList: {
+                    data.enforceInterface(DESCRIPTOR);
+                    String[] result = getVolumeList();
+                    reply.writeNoException();
+                    reply.writeStringArray(result);
+                    return true;
+                }
             }
             return super.onTransact(code, data, reply, flags);
         }
@@ -1179,4 +1204,8 @@
      */
     public int changeEncryptionPassword(String password) throws RemoteException;
 
+    /**
+     * Returns list of all mountable volumes.
+     */
+    public String[] getVolumeList() throws RemoteException;
 }
diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java
index 73ac79f..234057b 100644
--- a/core/java/android/os/storage/StorageManager.java
+++ b/core/java/android/os/storage/StorageManager.java
@@ -527,4 +527,30 @@
 
         return null;
     }
+
+    /**
+     * Gets the state of a volume via its mountpoint.
+     * @hide
+     */
+    public String getVolumeState(String mountPoint) {
+        try {
+            return mMountService.getVolumeState(mountPoint);
+        } catch (RemoteException e) {
+            Log.e(TAG, "Failed to get volume state", e);
+            return null;
+        }
+    }
+
+    /**
+     * Returns list of all mountable volumes.
+     * @hide
+     */
+    public String[] getVolumeList() {
+        try {
+            return mMountService.getVolumeList();
+        } catch (RemoteException e) {
+            Log.e(TAG, "Failed to get volume list", e);
+            return null;
+        }
+    }
 }
diff --git a/core/java/android/text/util/Rfc822Tokenizer.java b/core/java/android/text/util/Rfc822Tokenizer.java
index 69cf93c..68334e4 100644
--- a/core/java/android/text/util/Rfc822Tokenizer.java
+++ b/core/java/android/text/util/Rfc822Tokenizer.java
@@ -256,7 +256,7 @@
                     if (c == '"') {
                         i++;
                         break;
-                    } else if (c == '\\') {
+                    } else if (c == '\\' && i + 1 < len) {
                         i += 2;
                     } else {
                         i++;
@@ -275,7 +275,7 @@
                     } else if (c == '(') {
                         level++;
                         i++;
-                    } else if (c == '\\') {
+                    } else if (c == '\\' && i + 1 < len) {
                         i += 2;
                     } else {
                         i++;
diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java
index 9e482b4..86dfb9b 100644
--- a/core/java/android/widget/TextView.java
+++ b/core/java/android/widget/TextView.java
@@ -7197,14 +7197,6 @@
         }
 
         super.onFocusChanged(focused, direction, previouslyFocusedRect);
-
-        // Performed after super.onFocusChanged so that this TextView is registered and can ask for
-        // the IME. Showing the IME while focus is moved using the D-Pad is a bad idea, however this
-        // does not happen in that case (using the arrows on a bluetooth keyboard).
-        if (focused && isTextEditable()) {
-            final InputMethodManager imm = InputMethodManager.peekInstance();
-            if (imm != null) imm.showSoftInput(this, 0);
-        }
     }
 
     private int getLastTapPosition() {
diff --git a/core/jni/android_bluetooth_BluetoothSocket.cpp b/core/jni/android_bluetooth_BluetoothSocket.cpp
index b87f7c4..d09c4e9 100644
--- a/core/jni/android_bluetooth_BluetoothSocket.cpp
+++ b/core/jni/android_bluetooth_BluetoothSocket.cpp
@@ -448,7 +448,7 @@
 #ifdef HAVE_BLUETOOTH
     LOGV("%s", __FUNCTION__);
 
-    int ret;
+    int ret, total;
     jbyte *b;
     int sz;
     struct asocket *s = get_socketData(env, obj);
@@ -471,15 +471,21 @@
         return -1;
     }
 
-    ret = asocket_write(s, &b[offset], length, -1);
-    if (ret < 0) {
-        jniThrowIOException(env, errno);
-        env->ReleaseByteArrayElements(jb, b, JNI_ABORT);
-        return -1;
+    total = 0;
+    while (length > 0) {
+        ret = asocket_write(s, &b[offset], length, -1);
+        if (ret < 0) {
+            jniThrowIOException(env, errno);
+            env->ReleaseByteArrayElements(jb, b, JNI_ABORT);
+            return -1;
+        }
+        offset += ret;
+        total += ret;
+        length -= ret;
     }
 
     env->ReleaseByteArrayElements(jb, b, JNI_ABORT);  // no need to commit
-    return (jint)ret;
+    return (jint)total;
 
 #endif
     jniThrowIOException(env, ENOSYS);
diff --git a/core/res/AndroidManifest.xml b/core/res/AndroidManifest.xml
index 348ded7..2a4d1b2 100644
--- a/core/res/AndroidManifest.xml
+++ b/core/res/AndroidManifest.xml
@@ -57,6 +57,7 @@
     <protected-broadcast android:name="android.intent.action.NEW_OUTGOING_CALL" />
     <protected-broadcast android:name="android.intent.action.REBOOT" />
     <protected-broadcast android:name="android.intent.action.DOCK_EVENT" />
+    <protected-broadcast android:name="android.intent.action.MASTER_CLEAR_NOTIFICATION" />
 
     <protected-broadcast android:name="android.app.action.ENTER_CAR_MODE" />
     <protected-broadcast android:name="android.app.action.EXIT_CAR_MODE" />
diff --git a/core/tests/coretests/src/android/content/pm/PackageHelperTests.java b/core/tests/coretests/src/android/content/pm/PackageHelperTests.java
new file mode 100644
index 0000000..27112a6
--- /dev/null
+++ b/core/tests/coretests/src/android/content/pm/PackageHelperTests.java
@@ -0,0 +1,131 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package android.content.pm;
+
+import com.android.internal.content.PackageHelper;
+
+import android.os.IBinder;
+import android.os.RemoteException;
+import android.os.ServiceManager;
+import android.os.storage.IMountService;
+import android.test.AndroidTestCase;
+import android.util.Log;
+
+public class PackageHelperTests extends AndroidTestCase {
+    private static final boolean localLOGV = true;
+    public static final String TAG = "PackageHelperTests";
+    protected final String PREFIX = "android.content.pm";
+    private IMountService mMs;
+    private String fullId;
+    private String fullId2;
+
+    private IMountService getMs() {
+        IBinder service = ServiceManager.getService("mount");
+        if (service != null) {
+            return IMountService.Stub.asInterface(service);
+        } else {
+            Log.e(TAG, "Can't get mount service");
+        }
+        return null;
+    }
+
+    private void cleanupContainers() throws RemoteException {
+        Log.d(TAG,"cleanUp");
+        IMountService ms = getMs();
+        String[] containers = ms.getSecureContainerList();
+        for (int i = 0; i < containers.length; i++) {
+            if (containers[i].startsWith(PREFIX)) {
+                Log.d(TAG,"cleaing up "+containers[i]);
+                ms.destroySecureContainer(containers[i], true);
+            }
+        }
+    }
+
+    void failStr(String errMsg) {
+        Log.w(TAG, "errMsg=" + errMsg);
+        fail(errMsg);
+    }
+
+    void failStr(Exception e) {
+        failStr(e.getMessage());
+    }
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        if (localLOGV) Log.i(TAG, "Cleaning out old test containers");
+        cleanupContainers();
+    }
+
+    @Override
+    protected void tearDown() throws Exception {
+        super.tearDown();
+        if (localLOGV) Log.i(TAG, "Cleaning out old test containers");
+        cleanupContainers();
+    }
+
+    public void testMountAndPullSdCard() {
+        try {
+            fullId = PREFIX;
+            fullId2 = PackageHelper.createSdDir(1024, fullId, "none", android.os.Process.myUid());
+
+            Log.d(TAG,PackageHelper.getSdDir(fullId));
+            PackageHelper.unMountSdDir(fullId);
+
+            Runnable r1 = getMountRunnable();
+            Runnable r2 = getDestroyRunnable();
+            Thread thread = new Thread(r1);
+            Thread thread2 = new Thread(r2);
+            thread2.start();
+            thread.start();
+        } catch (Exception e) {
+            failStr(e);
+        }
+    }
+
+    public Runnable getMountRunnable() {
+        Runnable r = new Runnable () {
+            public void run () {
+                try {
+                    Thread.sleep(5);
+                    String path = PackageHelper.mountSdDir(fullId, "none",
+                            android.os.Process.myUid());
+                    Log.e(TAG, "mount done " + path);
+                } catch (IllegalArgumentException iae) {
+                    throw iae;
+                } catch (Throwable t) {
+                    Log.e(TAG, "mount failed", t);
+                }
+            }
+        };
+        return r;
+    }
+
+    public Runnable getDestroyRunnable() {
+        Runnable r = new Runnable () {
+            public void run () {
+                try {
+                    PackageHelper.destroySdDir(fullId);
+                    Log.e(TAG, "destroy done: " + fullId);
+                } catch (Throwable t) {
+                    Log.e(TAG, "destroy failed", t);
+                }
+            }
+        };
+        return r;
+    }
+}
diff --git a/core/tests/coretests/src/android/text/TextUtilsTest.java b/core/tests/coretests/src/android/text/TextUtilsTest.java
index e8e56de..c82962d 100644
--- a/core/tests/coretests/src/android/text/TextUtilsTest.java
+++ b/core/tests/coretests/src/android/text/TextUtilsTest.java
@@ -247,6 +247,23 @@
         assertEquals("Foo Bar", tokens[0].getAddress());
     }
 
+    @SmallTest
+    public void testRfc822FindToken() {
+        Rfc822Tokenizer tokenizer = new Rfc822Tokenizer();
+        //                0           1         2           3         4
+        //                0 1234 56789012345678901234 5678 90123456789012345
+        String address = "\"Foo\" <foo@google.com>, \"Bar\" <bar@google.com>";
+        assertEquals(0, tokenizer.findTokenStart(address, 21));
+        assertEquals(22, tokenizer.findTokenEnd(address, 21));
+        assertEquals(24, tokenizer.findTokenStart(address, 25));
+        assertEquals(46, tokenizer.findTokenEnd(address, 25));
+    }
+
+    @SmallTest
+    public void testRfc822FindTokenWithError() {
+        assertEquals(9, new Rfc822Tokenizer().findTokenEnd("\"Foo Bar\\", 0));
+    }
+
     @LargeTest
     public void testEllipsize() {
         CharSequence s1 = "The quick brown fox jumps over \u00FEhe lazy dog.";
diff --git a/docs/html/guide/developing/index.jd b/docs/html/guide/developing/index.jd
index 4257bf0..3d7e353 100644
--- a/docs/html/guide/developing/index.jd
+++ b/docs/html/guide/developing/index.jd
@@ -9,25 +9,21 @@
   <p>However, you may choose to develop with another IDE or a simple text editor and invoke the
   tools on the command line or with scripts. This is a less streamlined way to develop because you
   will sometimes have to call command line tools manually, but you will have access to the same
-  amount of features that you would have in Eclipse.</p>
+  number of features that you would have in Eclipse.</p>
+
+  <p class="note"><strong>Note:</strong> Before you begin developing Android applications, make
+    sure you have gone through all of the steps outlined in <a
+href="{@docRoot}sdk/installing.html">Installing the SDK</a>.</p>
 
   <p>The basic steps for developing applications with or without Eclipse are the same:</p>
 
   <ol>
-    <li>Install Eclipse or your own IDE.
-
-      <p>Install Eclipse along with <a href="{@docRoot}sdk/eclipse-adt.html#installing">the ADT
-      Plugin</a>, or install an editor of your choice if you want to use the command line SDK tools.
-      If you are already developing applications, be sure to <a href= 
-      "{@docRoot}sdk/eclipse-adt.html#updating">update Your ADT Plugin</a> to the latest version
-      before continuing.</p>
-    </li>
 
     <li>Set up Android Virtual Devices or hardware devices.
 
       <p>You need to create Android Virtual Devices (AVD) or connect hardware devices on which
       you will install your applications.</p>
-      
+
       <p>See <a href="{@docRoot}guide/developing/devices/index.html">Managing Virtual Devices</a>
       and <a href="{@docRoot}guide/developing/device.html">Using Hardware Devices</a> for more
 information.
diff --git a/docs/html/guide/developing/tools/index.jd b/docs/html/guide/developing/tools/index.jd
index c603780..3d831f3 100644
--- a/docs/html/guide/developing/tools/index.jd
+++ b/docs/html/guide/developing/tools/index.jd
@@ -3,83 +3,83 @@
 
 <img src="{@docRoot}assets/images/android_wrench.png" alt="" align="right">
 
-<p>The Android SDK includes a variety of custom tools that help you develop mobile
-applications on the Android platform. The most important of these are the Android
-Emulator and the Android Development Tools plugin for Eclipse, but the SDK also
-includes a variety of other tools for debugging, packaging, and installing your
-applications on the emulator. </p>
+<p>The Android SDK includes a variety of tools that help you develop mobile
+applications for the Android platform. The tools are classified into two groups: SDK tools
+and platform tools. SDK tools are platform independent and are required no matter which
+Android platform you are developing on. Platform tools are customized to support the features of the
+latest Android platform.</p>
 
- <dl>
-  <dt><a href="adb.html">Android Debug Bridge</a></dt>
-    <dd>A versatile tool lets you manage the state of an emulator instance
-    or Android-powered device.</dd>    
+<h2 id="tools-sdk">SDK Tools</h2>
+<p>The SDK tools are installed with the SDK starter package and are periodically updated.
+The SDK tools are required if you are developing Android applications. The most important SDK tools
+include the Android SDK and AVD Manager (<code>android</code>), the emulator
+(<code>emulator</code>), and the Dalvik Debug Monitor Server
+(<code>ddms</code>). A short summary of some frequently-used SDK tools is provided below.</p>
 
-   <dt><a href="android.html">android</a></dt>
-     <dd>Lets you manage AVDs, projects, and the installed components of the SDK.
-     </dd>
-
-  <dt><a href="bmgr.html">bmgr</a></dt>
-
-    <dd>Lets you interact with the Backup Manager on Android devices
-    supporting API Level 8 or greater. It provides commands to invoke backup and restore operations
-    so that you don't need to repeatedly wipe data or take similar intrusive steps in order to test
-    your application's backup agent. These commands are accessed via the adb shell.
-    </dd>
-
+<dl>
+  <dt><a href="android.html">android</a></dt>
+    <dd>Lets you manage AVDs, projects, and the installed components of the SDK.</dd>
+  <dt><a href="{@docRoot}guide/developing/debugging/ddms.html">Dalvik Debug Monitor
+Server (ddms)</a></dt>
+    <dd>Lets you debug Android applications.</dd>
   <dt><a href="dmtracedump.html">dmtracedump</a></dt>
-
-    <dd>Generates graphical call-stack diagrams from trace log files.
-    The tool uses the Graphviz Dot utility to create the graphical output, so you need to install
-    Graphviz before running <code>dmtracedump</code>. For more information on using <code>dmtracedump</code>, see
-    <a href="{@docRoot}guide/developing/debugging/debugging-tracing.html#dmtracedump">Profiling with
-    Traceview and dmtracedump</a>
-    </dd>
-
-    <dt><a href="draw9patch.html">Draw 9-patch</a></dt>
-	    <dd>Allows you to easily create a {@link android.graphics.NinePatch} graphic using a WYSIWYG editor.
-	    It also previews stretched versions of the image, and highlights the area in which content is allowed.
-	    </dd>
-
-  <dt><a href="emulator.html">Android Emulator</a></dt>
-    <dd>A QEMU-based device-emulation tool that you can use to design,
-    debug, and test your applications in an actual Android run-time environment. </dd>
-
+    <dd>Generates graphical call-stack diagrams from trace log files. The tool uses the
+Graphviz Dot utility to create the graphical output, so you need to install Graphviz before
+running <code>dmtracedump</code>. For more information on using <code>dmtracedump</code>, see <a
+href="{@docRoot}guide/developing/debugging/debugging-tracing.html#dmtracedump">Profiling
+with Traceview and dmtracedump</a></dd>
+  <dt><a href="draw9patch.html">Draw 9-patch</a></dt>
+    <dd>Allows you to easily create a {@link android.graphics.NinePatch} graphic using a
+WYSIWYG editor. It also previews stretched versions of the image, and highlights the area in which
+content is allowed.</dd>
+  <dt><a href="emulator.html">Android Emulator (emulator)</a></dt>
+    <dd>A QEMU-based device-emulation tool that you can use to design, debug, and test
+your applications in an actual Android run-time environment.</dd>
+  <dt><a href="hierarchy-viewer.html">Hierarchy Viewer (hierarchyviewer)</a></dt>
+    <dd>Lets you debug and optimize an Android application's user interface.</dd>
   <dt><a href="hprof-conv.html">hprof-conv</a></dt>
-
-    <dd>Converts the HPROF file that is generated by the Android SDK tools to a
-    standard format so you can view the file in a profiling tool of your choice.</dd>
-
+    <dd>Converts the HPROF file that is generated by the Android SDK tools to a standard format so
+you can view the file in a profiling tool of your choice.</dd>
   <dt><a href="layoutopt.html">layoutopt</a></dt>
-    <dd>Lets you quickly analyze your application's layouts in order to
-    optimize them for efficiency.
-    </dd>
-
-  <dt><a href="mksdcard.html">logcat</a></dt>
-      <dd>Lets you read system log messages that are output on an Android device or emulator.</dd>
-
+    <dd>Lets you quickly analyze your application's layouts in order to optimize them for
+efficiency.</dd>
   <dt><a href="mksdcard.html">mksdcard</a></dt>
-      <dd>Helps you create a disk image that you can use with the emulator, 
-      to simulate the presence of an external storage card (such as an SD card).</dd>
-
+    <dd>Helps you create a disk image that you can use with the emulator, to simulate the presence
+of an external storage card (such as an SD card).</dd>
   <dt><a href="monkey.html">Monkey</a></dt>
-      <dd>Runs on your emulator or device and generates pseudo-random
-      streams of user events such as clicks, touches, or gestures, as well as a number of system-level events.
-      You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.</dd>
-
+    <dd>Runs on your emulator or device and generates pseudo-random streams of user events such
+as clicks, touches, or gestures, as well as a number of  system-level events. You can use the Monkey
+to stress-test applications that you are developing, in a random yet repeatable manner.</dd>
   <dt><a href="monkeyrunner_concepts.html">monkeyrunner</a></dt>
-      <dd>Provides an API for writing programs that control an Android device
-      or emulator from outside of Android code.</dd>
-
+    <dd>Provides an API for writing programs that control an Android device or emulator from
+outside of Android code.</dd>
   <dt><a href="proguard.html">ProGuard</a></dt>
-      <dd>Shrinks, optimizes, and obfuscates your code by removing unused code and renaming classes,
-      fields, and methods with semantically obscure names.</dd>
-
+    <dd>Shrinks, optimizes, and obfuscates your code by removing unused code and renaming
+classes, fields, and methods with semantically obscure names.</dd>
   <dt><a href="sqlite3.html">sqlite3</a></dt>
-      <dd>Lets you access the SQLite data files created and used by Android applications.</dd>
-
+    <dd>Lets you access the SQLite data files created and used by Android applications.</dd>
+  <dt><a href="traceview.html">traceview</a></dt>
+    <dd>Provides a graphical viewer for execution logs saved by your application.</dd>
   <dt><a href="zipalign.html">zipalign</a></dt>
-            <dd>Optimizes <code>.apk</code> files by ensuring that all uncompressed data starts
-            with a particular alignment relative to the start of the file. This should always be used
-            to align .apk files after they have been signed.</dd>
-</dl>
+    <dd>Optimizes <code>.apk</code> files by ensuring that all uncompressed data starts with a
+particular alignment relative to the start of the file. This should always be used to align .apk
+files after they have been signed.</dd>
+ </dl>
 
+<h2 id="tools-platform">Platform Tools</h2>
+
+<p>The platform tools are typically updated every time you install a new SDK platform. Each update
+of the platform tools is backward compatible with older platforms. Usually, you directly use only
+one of the platform tools&mdash;the <a href="adb.html">Android Debug Bridge (<code>adb</code>)</a>.
+Android Debug Bridge is a versatile tool that lets you manage the state of an emulator instance or
+Android-powered device. You can also use it to install an Android application (.apk) file on a
+device.</p>
+
+<p>The other platform tools, such as <a href="{@docRoot}guide/developing/tools/aidl.html">aidl</a>,
+<code>aapt</code>, <code>dexdump</code>, and <code>dx</code>, are typically called by the Android
+build tools or Android Development Tools (ADT), so you rarely need to invoke these tools directly.
+As a general rule, you should rely on the build tools or the ADT plugin to call them as needed.</p>
+
+<p class="note"><strong>Note:</strong> The Android SDK provides additional shell tools that can
+be accessed through <code>adb</code>, such as <a href="bmgr.html">bmgr</a> and
+<a href="logcat.html">logcat</a>.</p>
\ No newline at end of file
diff --git a/docs/html/sdk/eclipse-adt.jd b/docs/html/sdk/eclipse-adt.jd
index ece9d4a..feb84b1 100644
--- a/docs/html/sdk/eclipse-adt.jd
+++ b/docs/html/sdk/eclipse-adt.jd
@@ -656,7 +656,7 @@
 <h3 id="downloading">Downloading the ADT Plugin</h3>
 
 <p>Use the Update Manager feature of your Eclipse installation to install the latest
-revision of ADT on your development computer.<p>
+revision of ADT on your development computer.<>
 
 <p>Assuming that you have a compatible version of the Eclipse IDE installed, as
 described in <a href="#preparing">Preparing for Installation</a>, above, follow
@@ -671,26 +671,32 @@
     <li>In the Add Repository dialog that appears, enter "ADT Plugin" for the <em>Name</em> and the
 following URL for the <em>Location</em>:
       <pre>https://dl-ssl.google.com/android/eclipse/</pre>
-        <p>Note: If you have trouble acquiring the plugin, try using "http" in the Location URL,
-        instead of "https" (https is preferred for security reasons).</p>
-      <p>Click <strong>OK</strong>.</p></li>
-    <li>In the Available Software dialog, select
-the checkbox next to Developer Tools and click <strong>Next</strong>.</li>
+    </li>
+    <li>Click <strong>OK</strong>
+      <p>Note: If you have trouble acquiring the plugin, try using "http" in the Location URL,
+instead of "https" (https is preferred for security reasons).</p></li>
+    <li>In the Available Software dialog, select the checkbox next to Developer Tools and click
+<strong>Next</strong>.</li>
     <li>In the next window, you'll see a list of the tools to be downloaded. Click
 <strong>Next</strong>. </li>
-    <li>Read and accept the license agreements, then click <strong>Finish</strong>.</li>
+    <li>Read and accept the license agreements, then click <strong>Finish</strong>.
+      <p>Note: If you get a security warning saying that the authenticity or validity of
+the software can't be established, click <strong>OK</strong>.</p></li>
     <li>When the installation completes, restart Eclipse. </li>
 </ol>
 
 <h3 id="configuring">Configuring the ADT Plugin</h3>
 
-<p>Once you've successfully downloaded ADT as described above, the next step
+<p>After you've successfully downloaded the ADT as described above, the next step
 is to modify your ADT preferences in Eclipse to point to the Android SDK directory:</p>
 
 <ol>
     <li>Select <strong>Window</strong> &gt; <strong>Preferences...</strong> to open the Preferences
         panel (Mac OS X: <strong>Eclipse</strong> &gt; <strong>Preferences</strong>).</li>
-    <li>Select <strong>Android</strong> from the left panel. </li>
+    <li>Select <strong>Android</strong> from the left panel.</li>
+      <p>You may see a dialog asking whether you want to send usage statistics to Google. If so,
+make your choice and click <strong>Proceed</strong>. You cannot continue with this procedure until
+you click <strong>Proceed</strong>.</p>
     <li>For the <em>SDK Location</em> in the main panel, click <strong>Browse...</strong> and
         locate your downloaded SDK directory. </li>
     <li>Click <strong>Apply</strong>, then <strong>OK</strong>.</li>
diff --git a/docs/html/sdk/installing.jd b/docs/html/sdk/installing.jd
index a1080c2..1dce483 100644
--- a/docs/html/sdk/installing.jd
+++ b/docs/html/sdk/installing.jd
@@ -81,9 +81,9 @@
 
 <h4>Updating?</h4>
 
-<p>If you already have an Android SDK, use the <em>Android SDK and AVD Manager</em> tool to install
+<p>If you already have an Android SDK, use the Android SDK and AVD Manager tool to install
 updated tools and new Android platforms into your existing environment. For information about how to
-do that, see <a href="{@docRoot}sdk/adding-components.html">Adding SDK Components</a></p>
+do that, see <a href="{@docRoot}sdk/adding-components.html">Adding SDK Components</a>.</p>
 
 
 <h2 id="Preparing">Step 1. Preparing Your Development Computer</h2>
@@ -126,7 +126,7 @@
 
 <p>Make a note of the name and location of the SDK directory on your system&mdash;you will need to
 refer to the SDK directory later, when setting up the ADT plugin and when using
-the SDK tools from command line.</p>
+the SDK tools from the command line.</p>
 
 
 <h2 id="InstallingADT">Step 3. Installing the ADT Plugin for Eclipse</h2>
@@ -147,26 +147,25 @@
 last step in setting up your Android SDK.</p>
 
 <p>If you prefer to work in a different IDE, you do not need to
-install Eclipse or ADT, instead, you can directly use the SDK tools to build and
-debug your application. The <a href="{@docRoot}guide/developing/index.html">Overview</a>
-section of the developer guide outlines the major steps that you need to complete
-when developing in Eclipse or other IDEs.</p>
+install Eclipse or ADT. Instead, you can directly use the SDK tools to build and
+debug your application. The <a href="{@docRoot}guide/developing/index.html">Introduction</a>
+to Android application development outlines the major steps that you need to complete when
+developing in Eclipse or other IDEs.</p>
 
 
 
 <h2 id="AddingComponents">Step 4. Adding Platforms and Other Components</h2>
 
-<p>The last step in setting up your SDK is using the <em>Android SDK and AVD Manager</em> (a
-tool included in the SDK starter package) to download
-essential SDK components into your development environment.</p>
+<p>The last step in setting up your SDK is using the Android SDK and AVD Manager (a
+tool included in the SDK starter package) to download essential SDK components into your development
+environment.</p>
 
 <p>The SDK uses a modular structure that separates the major parts of the SDK&mdash;Android platform
 versions, add-ons, tools, samples, and documentation&mdash;into a set of separately installable
 components. The SDK starter package, which you've already downloaded, includes only a single
-component: the latest version of the SDK Tools. To develop an Android
-application, you also need to download at least one Android platform and the SDK Platform-tools
-(tools that the latest platform depend upon). However, downloading
-additional components is highly recommended.</p>
+component: the latest version of the SDK Tools. To develop an Android application, you also need to
+download at least one Android platform and the associated platform tools. You can add other
+components and platforms as well, which is highly recommended.</p>
 
 <p>If you used the Windows installer, when you complete the installation wizard, it will launch the
 Android SDK and AVD Manager with a default set of platforms and other components selected
@@ -185,10 +184,10 @@
 </ul>
 
 <p>To download components, use the graphical UI of the Android SDK and AVD
-Manager, shown in Figure 1, to browse the SDK repository and select new or updated
-components. The Android SDK and AVD Manager will install the selected components in
-your SDK environment. For information about which components you should download, see the following
-section about <a href="#which">Recommended Components</a>.</p>
+Manager to browse the SDK repository and select new or updated
+components (see figure 1). The Android SDK and AVD Manager installs the selected components in
+your SDK environment. For information about which components you should download, see <a
+href="#which">Recommended Components</a>.</p>
 
 <img src="/images/sdk_manager_packages.png" />
 <p class="img-caption"><strong>Figure 1.</strong> The Android SDK and AVD Manager's
@@ -204,35 +203,34 @@
 <p>The <em>Android Repository</em> offers these types of components:</p>
 
 <ul>
-<li><strong>SDK Tools</strong> (pre-installed in the Android SDK starter
-package) &mdash; Contains tools for debugging
-and testing your application and other utility tools. You can access these
-in the <code>&lt;sdk&gt;/tools/</code> directory of your SDK and read more about them in the <a
-href="{@docRoot}guide/developing/tools/index.html">Tools</a> section of the developer guide. </li>
+<li><strong>SDK Tools</strong> &mdash; Contains tools for debugging and testing your application
+and other utility tools. These tools are installed with the Android SDK starter package and receive
+periodic updates. You can access these tools in the <code>&lt;sdk&gt;/tools/</code> directory of
+your SDK. To learn more about
+them, see <a href="{@docRoot}guide/developing/tools/index.html#tools-sdk">SDK Tools</a> in the
+developer guide.</li>
 
-<li><strong>SDK Platform-tools</strong> &mdash; Contains tools that are required to develop and
-debug your application, but which are developed alongside the Android platform in order to support
-the latest features. These tools are typically updated only when a new platform becomes
-available. You can access these
-in the <code>&lt;sdk&gt;/platform-tools/</code> directory. Read more about them in
-the <a href="{@docRoot}guide/developing/tools/index.html">Tools</a> section of the developer guide.
-</li>
+<li><strong>SDK Platform-tools</strong> &mdash; Contains platform-dependent tools for developing
+and debugging your application. These tools support the latest features of the Android platform and
+are typically updated only when a new platform becomes available. You can access these tools in the
+<code>&lt;sdk&gt;/platform-tools/</code> directory. To learn more about them, see <a
+href="{@docRoot}guide/developing/tools/index.html#tools-platform">Platform Tools</a> in the
+developer guide.</li>
 
 <li><strong>Android platforms</strong> &mdash; An SDK platform is
-available for every production Android platform deployable to Android-powered
-devices. Each platform component includes a fully compliant Android library and
-system image, sample code, emulator skins, and any version specific tools. For
-detailed information about each platform, see the overview documents available
-under the section "Downloadable SDK Components," at left. </li>
+available for every production Android platform deployable to Android-powered devices. Each
+SDK platform component includes a fully compliant Android library, system image, sample code,
+and emulator skins. To learn more about a specific platform, see the list of platforms that appears
+under the section "Downloadable SDK Components" on the left part of this page.</li>
 
 <li><strong>USB Driver for Windows</strong> (Windows only) &mdash; Contains driver files
 that you can install on your Windows computer, so that you can run and debug
 your applications on an actual device. You <em>do not</em> need the USB driver unless
 you plan to debug your application on an actual Android-powered device. If you
 develop on Mac OS X or Linux, you do not need a special driver to debug
-your application on an Android-powered device. (See <a
-href="{@docRoot}guide/developing/device.html">Developing on a Device</a> for more information
-about developing on a real device.)</li>
+your application on an Android-powered device. See <a
+href="{@docRoot}guide/developing/device.html">Using Hardware Devices</a> for more information
+about developing on a real device.</li>
 
 <li><strong>Samples</strong> &mdash; Contains the sample code and apps available
 for each Android development platform. If you are just getting started with
@@ -247,8 +245,8 @@
 
 <p>The <em>Third party Add-ons</em> provide components that allow you to create a development
 environment using a specific Android external library (such as the Google Maps library) or a
-customized (but fully compliant) Android system image. You can add additional Add-on repositories,
-by clicking <strong>Add Add-on Site</strong>.</p>
+customized (but fully compliant) Android system image. You can add additional Add-on repositories by
+clicking <strong>Add Add-on Site</strong>.</p>
 
 
 <h3 id="which">Recommended Components</h3>
@@ -381,12 +379,11 @@
 </tr>
 <tr>
 <td colspan="3"><code>platform-tools/</code></td>
-<td>Contains development tools that may be updated with each platform release (from the <em>Android
-SDK Platform-tools</em> component). Tools in here include {@code adb}, {@code dexdump}, and others
-others that you don't typically use directly. These tools are separate from the generic development
-tools in the {@code tools/} directory, because these tools may be updated in order to support new
-features in the latest Android platform, whereas the other tools have no dependencies on the
-platform version.</td>
+<td>Contains platform-dependent development tools that may be updated with each platform release.
+The platform tools include the Android Debug Bridge ({@code adb}) as well as other tools that you
+don't typically use directly. These tools are separate from the development tools in the {@code
+tools/} directory because these tools may be updated in order to support new
+features in the latest Android platform.</td>
 </tr>
 <tr>
 <td colspan="3"><code>platforms/</code></td>
@@ -394,52 +391,12 @@
 applications against, each in a separate directory.  </td>
 </tr>
 <tr>
-<td style="width:2em;border-bottom-color:white;"></td>
+<td style="width:2em;"></td>
 <td colspan="2"><code><em>&lt;platform&gt;</em>/</code></td>
-<td>Platform version directory, for example "android-1.6". All platform version
-directories contain a similar set of files and subdirectory structure.</td>
-</tr>
-
-<tr>
-<td style="width:2em;border-bottom-color:white;">&nbsp;</td>
-<td style="width:2em;border-bottom-color:white;"></td>
-<td><code>data/</code></td>
-<td>Storage area for default fonts and resource definitions.</td>
-</tr>
-<tr>
-<td style="width:2em;border-bottom-color:white;"></td>
-<td style="width:2em;border-bottom-color:white;"></td>
-<td><code>images/</code></td>
-<td>Storage area for default disk images, including the Android system image,
-the default userdata image, the default ramdisk image, and more. The images
-are used in emulator sessions.</td>
-</tr>
-<tr>
-<td style="width:2em;border-bottom-color:white;"></td>
-<td style="width:2em;border-bottom-color:white;"></td>
-<td><code>skins/</code></td>
-<td>A set of emulator skins available for the platform version. Each skin is
-designed for a specific screen resolution.</td>
-</tr>
-<tr>
-<td style="width:2em;border-bottom-color:white;"></td>
-<td style="width:2em;border-bottom-color:white;"></td>
-<td><code>templates/</code></td>
-<td>Storage area for file templates used by the SDK development tools.</td>
-</tr>
-<tr>
-<td style="width:2em;border-bottom-color:white;"></td>
-<td style="width:2em;border-bottom-color:white;"></td>
-<td><code>tools/</code></td>
-<td>This directory is used only by SDK Tools r7 and below for development tools that are specific to
-this platform version&mdash;it's not used by SDK Tools r8 and above.</td>
-</tr>
-<tr>
-<td style="width:2em;"></td>
-<td style="width:2em;"></td>
-<td><code>android.jar</code></td>
-<td>The Android library used when compiling applications against this platform
-version.</td>
+<td>Platform version directory, for example "android-11". All platform version directories contain
+a similar set of files and subdirectory structure. Each platform directory also includes the
+Android library (<code>android.jar</code>) that is used to compile applications against the
+platform version.</td>
 </tr>
 <tr>
 <td colspan="3"><code>samples/</code></td>
@@ -448,21 +405,20 @@
 <tr>
 <td colspan="3"><code>tools/</code></td>
 <td>Contains the set of development and profiling tools that are platform-independent, such
-as the emulator, the AVD and SDK Manager, ddms, hierarchyviewer and more. The tools in
-this directory may be updated at any time (from the <em>Android SDK Tools</em> component),
-independent of platform releases, whereas the tools in {@code platform-tools/} may be updated based
-on the latest platform release.</td>
+as the emulator, the Android SDK and AVD Manager, <code>ddms</code>, <code>hierarchyviewer</code>
+and more. The tools in this directory may be updated at any time using the Android SDK and AVD
+Manager and are independent of platform releases.</td>
 </tr>
 <tr>
 <td colspan="3"><code>SDK Readme.txt</code></td>
 <td>A file that explains how to perform the initial setup of your SDK,
 including how to launch the Android SDK and AVD Manager tool on all
-platforms</td>
+platforms.</td>
 </tr>
 <tr>
 <td colspan="3"><code>SDK Manager.exe</code></td>
 <td>Windows SDK only. A shortcut that launches the Android SDK and AVD
-Manager tool, which you use to add components to your SDK. </td>
+Manager tool, which you use to add components to your SDK.</td>
 </tr>
 <!--<tr>
 <td colspan="3"><code>documentation.html</code></td>
@@ -499,7 +455,7 @@
 
   <li>On Linux, edit your <code>~/.bash_profile</code> or <code>~/.bashrc</code> file. Look
   for a line that sets the PATH environment variable and add the
-  full path to the <code>tools/</code> and <code>platform-tools</code> directories to it. If you
+  full path to the <code>tools/</code> and <code>platform-tools/</code> directories to it. If you
   don't see a line setting the path, you can add one:
   <pre>export PATH=${PATH}:&lt;sdk&gt;/tools:&lt;sdk&gt;/platform-tools</pre>
   </li>
@@ -533,28 +489,27 @@
 <p><strong>Learn about Android</strong></p>
 <ul>
   <li>Take a look at the <a href="{@docRoot}guide/index.html">Dev
-  Guide</a> and the types of information it provides</li>
+  Guide</a> and the types of information it provides.</li>
   <li>Read an introduction to Android as a platform in <a
   href="{@docRoot}guide/basics/what-is-android.html">What is
   Android?</a></li>
   <li>Learn about the Android framework and how applications run on it in
   <a href="{@docRoot}guide/topics/fundamentals.html">Application
-  Fundamentals</a></li>
+  Fundamentals</a>.</li>
   <li>Take a look at the Android framework API specification in the <a
-  href="{@docRoot}reference/packages.html">Reference</a> tab</li>
+  href="{@docRoot}reference/packages.html">Reference</a> tab.</li>
 </ul>
 
 <p><strong>Explore the development tools</strong></p>
 <ul>
   <li>Get an overview of the <a
   href="{@docRoot}guide/developing/tools/index.html">development
-  tools</a> that are available to you</li>
-  <li>Read the <a
-  href="{@docRoot}guide/developing/index.html">Overview</a>
-  for how to develop an Android application.
+  tools</a> that are available to you.</li>
+  <li>Read the <a href="{@docRoot}guide/developing/index.html">Introduction</a> to Android
+application development.
   </li>
-  <li>Read <a href="{@docRoot}guide/developing/device.html">Developing on a Device</a> to set up an
-Android-powered device to run and test your application.</li>
+  <li>Read <a href="{@docRoot}guide/developing/device.html">Using Hardware Devices</a> to learn
+how to set up an Android-powered device so you can run and test your application.</li>
 </ul>
 
 <p><strong>Follow the Notepad tutorial</strong></p>
diff --git a/graphics/java/android/renderscript/Allocation.java b/graphics/java/android/renderscript/Allocation.java
index 4b8c58e..9ac1a00 100644
--- a/graphics/java/android/renderscript/Allocation.java
+++ b/graphics/java/android/renderscript/Allocation.java
@@ -99,6 +99,14 @@
      */
     public static final int USAGE_GRAPHICS_CONSTANTS = 0x0008;
 
+    /**
+     * @hide
+     * USAGE_GRAPHICS_RENDER_TARGET The allcation will be used as a
+     * target for offscreen rendering
+     *
+     */
+    public static final int USAGE_GRAPHICS_RENDER_TARGET = 0x0010;
+
 
     /**
      * Controls mipmap behavior when using the bitmap creation and
@@ -137,7 +145,8 @@
         if ((usage & ~(USAGE_SCRIPT |
                        USAGE_GRAPHICS_TEXTURE |
                        USAGE_GRAPHICS_VERTEX |
-                       USAGE_GRAPHICS_CONSTANTS)) != 0) {
+                       USAGE_GRAPHICS_CONSTANTS |
+                       USAGE_GRAPHICS_RENDER_TARGET)) != 0) {
             throw new RSIllegalArgumentException("Unknown usage specified.");
         }
         mType = t;
diff --git a/graphics/java/android/renderscript/Element.java b/graphics/java/android/renderscript/Element.java
index fae22f0..0c1ad2a 100644
--- a/graphics/java/android/renderscript/Element.java
+++ b/graphics/java/android/renderscript/Element.java
@@ -124,7 +124,8 @@
         PIXEL_A (8),
         PIXEL_LA (9),
         PIXEL_RGB (10),
-        PIXEL_RGBA (11);
+        PIXEL_RGBA (11),
+        PIXEL_DEPTH (12);
 
         int mID;
         DataKind(int id) {
@@ -536,10 +537,12 @@
               dk == DataKind.PIXEL_A ||
               dk == DataKind.PIXEL_LA ||
               dk == DataKind.PIXEL_RGB ||
-              dk == DataKind.PIXEL_RGBA)) {
+              dk == DataKind.PIXEL_RGBA ||
+              dk == DataKind.PIXEL_DEPTH)) {
             throw new RSIllegalArgumentException("Unsupported DataKind");
         }
         if (!(dt == DataType.UNSIGNED_8 ||
+              dt == DataType.UNSIGNED_16 ||
               dt == DataType.UNSIGNED_5_6_5 ||
               dt == DataType.UNSIGNED_4_4_4_4 ||
               dt == DataType.UNSIGNED_5_5_5_1)) {
@@ -554,16 +557,25 @@
         if (dt == DataType.UNSIGNED_4_4_4_4 && dk != DataKind.PIXEL_RGBA) {
             throw new RSIllegalArgumentException("Bad kind and type combo");
         }
+        if (dt == DataType.UNSIGNED_16 &&
+            dk != DataKind.PIXEL_DEPTH) {
+            throw new RSIllegalArgumentException("Bad kind and type combo");
+        }
 
         int size = 1;
-        if (dk == DataKind.PIXEL_LA) {
+        switch (dk) {
+        case PIXEL_LA:
             size = 2;
-        }
-        if (dk == DataKind.PIXEL_RGB) {
+            break;
+        case PIXEL_RGB:
             size = 3;
-        }
-        if (dk == DataKind.PIXEL_RGBA) {
+            break;
+        case PIXEL_RGBA:
             size = 4;
+            break;
+        case PIXEL_DEPTH:
+            size = 2;
+            break;
         }
 
         boolean norm = true;
diff --git a/libs/rs/Android.mk b/libs/rs/Android.mk
index 14152d8..9100693 100644
--- a/libs/rs/Android.mk
+++ b/libs/rs/Android.mk
@@ -90,6 +90,7 @@
 	rsContext.cpp \
 	rsDevice.cpp \
 	rsElement.cpp \
+	rsFBOCache.cpp \
 	rsFileA3D.cpp \
 	rsFont.cpp \
 	rsLocklessFifo.cpp \
diff --git a/libs/rs/RenderScriptDefines.h b/libs/rs/RenderScriptDefines.h
index 4e1ac88..bb275b5 100644
--- a/libs/rs/RenderScriptDefines.h
+++ b/libs/rs/RenderScriptDefines.h
@@ -84,6 +84,7 @@
     RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE = 0x0002,
     RS_ALLOCATION_USAGE_GRAPHICS_VERTEX = 0x0004,
     RS_ALLOCATION_USAGE_GRAPHICS_CONSTANTS = 0x0008,
+    RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET = 0x0010,
 
     RS_ALLOCATION_USAGE_ALL = 0x000F
 };
@@ -147,6 +148,7 @@
     RS_KIND_PIXEL_LA,
     RS_KIND_PIXEL_RGB,
     RS_KIND_PIXEL_RGBA,
+    RS_KIND_PIXEL_DEPTH,
 };
 
 enum RsSamplerParam {
diff --git a/libs/rs/rsAllocation.cpp b/libs/rs/rsAllocation.cpp
index b8ddb0b..6b37e03 100644
--- a/libs/rs/rsAllocation.cpp
+++ b/libs/rs/rsAllocation.cpp
@@ -56,7 +56,8 @@
 
     mTextureID = 0;
     mBufferID = 0;
-    mUploadDefered = false;
+    mRenderTargetID = 0;
+    mUploadDeferred = false;
 
     mUserBitmapCallback = NULL;
     mUserBitmapCallbackData = NULL;
@@ -93,6 +94,10 @@
         glDeleteTextures(1, &mTextureID);
         mTextureID = 0;
     }
+    if (mRenderTargetID) {
+        glDeleteRenderbuffers(1, &mRenderTargetID);
+        mRenderTargetID = 0;
+    }
 #endif //ANDROID_RS_SERIALIZE
 }
 
@@ -112,9 +117,14 @@
     return false;
 }
 
-void Allocation::deferedUploadToTexture(const Context *rsc) {
+void Allocation::deferredUploadToTexture(const Context *rsc) {
     mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE;
-    mUploadDefered = true;
+    mUploadDeferred = true;
+}
+
+void Allocation::deferredAllocateRenderTarget(const Context *rsc) {
+    mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET;
+    mUploadDeferred = true;
 }
 
 uint32_t Allocation::getGLTarget() const {
@@ -155,8 +165,11 @@
     if (getIsBufferObject()) {
         uploadToBufferObject(rsc);
     }
+    if (getIsRenderTarget() && !getIsTexture()) {
+        allocateRenderTarget(rsc);
+    }
 
-    mUploadDefered = false;
+    mUploadDeferred = false;
 }
 
 void Allocation::uploadToTexture(const Context *rsc) {
@@ -184,7 +197,7 @@
             // Force a crash to 1: restart the app, 2: make sure we get a bugreport.
             LOGE("Upload to texture failed to gen mTextureID");
             rsc->dumpDebug();
-            mUploadDefered = true;
+            mUploadDeferred = true;
             return;
         }
         isFirstUpload = true;
@@ -200,6 +213,32 @@
 #endif //ANDROID_RS_SERIALIZE
 }
 
+void Allocation::allocateRenderTarget(const Context *rsc) {
+#ifndef ANDROID_RS_SERIALIZE
+    mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET;
+
+    GLenum format = mHal.state.type->getElement()->getComponent().getGLFormat();
+    if (!format) {
+        return;
+    }
+
+    if (!mRenderTargetID) {
+        glGenRenderbuffers(1, &mRenderTargetID);
+
+        if (!mRenderTargetID) {
+            // This should generally not happen
+            LOGE("allocateRenderTarget failed to gen mRenderTargetID");
+            rsc->dumpDebug();
+            return;
+        }
+        glBindRenderbuffer(GL_RENDERBUFFER, mRenderTargetID);
+        glRenderbufferStorage(GL_RENDERBUFFER, format,
+                              mHal.state.type->getDimX(),
+                              mHal.state.type->getDimY());
+    }
+#endif //ANDROID_RS_SERIALIZE
+}
+
 #ifndef ANDROID_RS_SERIALIZE
 const static GLenum gFaceOrder[] = {
     GL_TEXTURE_CUBE_MAP_POSITIVE_X,
@@ -271,9 +310,9 @@
 #endif //ANDROID_RS_SERIALIZE
 }
 
-void Allocation::deferedUploadToBufferObject(const Context *rsc) {
+void Allocation::deferredUploadToBufferObject(const Context *rsc) {
     mHal.state.usageFlags |= RS_ALLOCATION_USAGE_GRAPHICS_VERTEX;
-    mUploadDefered = true;
+    mUploadDeferred = true;
 }
 
 void Allocation::uploadToBufferObject(const Context *rsc) {
@@ -288,7 +327,7 @@
     }
     if (!mBufferID) {
         LOGE("Upload to buffer object failed");
-        mUploadDefered = true;
+        mUploadDeferred = true;
         return;
     }
     GLenum target = (GLenum)getGLTarget();
@@ -300,7 +339,7 @@
 }
 
 void Allocation::uploadCheck(Context *rsc) {
-    if (mUploadDefered) {
+    if (mUploadDeferred) {
         syncAll(rsc, RS_ALLOCATION_USAGE_SCRIPT);
     }
 }
@@ -329,7 +368,7 @@
 
     memcpy(ptr, data, size);
     sendDirty();
-    mUploadDefered = true;
+    mUploadDeferred = true;
 }
 
 void Allocation::data(Context *rsc, uint32_t xoff, uint32_t yoff, uint32_t lod, RsAllocationCubemapFace face,
@@ -362,7 +401,7 @@
             dst += destW * eSize;
         }
         sendDirty();
-        mUploadDefered = true;
+        mUploadDeferred = true;
     } else {
         update2DTexture(data, xoff, yoff, lod, face, w, h);
     }
@@ -407,7 +446,7 @@
 
     memcpy(ptr, data, sizeBytes);
     sendDirty();
-    mUploadDefered = true;
+    mUploadDeferred = true;
 }
 
 void Allocation::elementData(Context *rsc, uint32_t x, uint32_t y,
@@ -450,7 +489,7 @@
 
     memcpy(ptr, data, sizeBytes);
     sendDirty();
-    mUploadDefered = true;
+    mUploadDeferred = true;
 }
 
 void Allocation::addProgramToDirty(const Program *p) {
@@ -617,12 +656,12 @@
 
 void rsi_AllocationUploadToTexture(Context *rsc, RsAllocation va, bool genmip, uint32_t baseMipLevel) {
     Allocation *alloc = static_cast<Allocation *>(va);
-    alloc->deferedUploadToTexture(rsc);
+    alloc->deferredUploadToTexture(rsc);
 }
 
 void rsi_AllocationUploadToBufferObject(Context *rsc, RsAllocation va) {
     Allocation *alloc = static_cast<Allocation *>(va);
-    alloc->deferedUploadToBufferObject(rsc);
+    alloc->deferredUploadToBufferObject(rsc);
 }
 
 static void mip565(const Adapter2D &out, const Adapter2D &in) {
@@ -792,7 +831,6 @@
     return alloc;
 }
 
-
 RsAllocation rsaAllocationCreateFromBitmap(RsContext con, RsType vtype,
                                            RsAllocationMipmapControl mips,
                                            const void *data, uint32_t usages) {
@@ -811,7 +849,7 @@
         rsaAllocationGenerateScriptMips(rsc, texAlloc);
     }
 
-    texAlloc->deferedUploadToTexture(rsc);
+    texAlloc->deferredUploadToTexture(rsc);
     return texAlloc;
 }
 
@@ -852,7 +890,7 @@
         rsaAllocationGenerateScriptMips(rsc, texAlloc);
     }
 
-    texAlloc->deferedUploadToTexture(rsc);
+    texAlloc->deferredUploadToTexture(rsc);
     return texAlloc;
 }
 
diff --git a/libs/rs/rsAllocation.h b/libs/rs/rsAllocation.h
index e63140c..d334841 100644
--- a/libs/rs/rsAllocation.h
+++ b/libs/rs/rsAllocation.h
@@ -71,13 +71,17 @@
 
     void syncAll(Context *rsc, RsAllocationUsageType src);
 
-    void deferedUploadToTexture(const Context *rsc);
+    void deferredUploadToTexture(const Context *rsc);
     void uploadToTexture(const Context *rsc);
     uint32_t getTextureID() const {return mTextureID;}
 
+    void deferredAllocateRenderTarget(const Context *rsc);
+    void allocateRenderTarget(const Context *rsc);
+    uint32_t getRenderTargetID() const {return mRenderTargetID;}
+
     uint32_t getGLTarget() const;
 
-    void deferedUploadToBufferObject(const Context *rsc);
+    void deferredUploadToBufferObject(const Context *rsc);
     void uploadToBufferObject(const Context *rsc);
     uint32_t getBufferObjectID() const {return mBufferID;}
 
@@ -118,6 +122,9 @@
     bool getIsTexture() const {
         return (mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_TEXTURE) != 0;
     }
+    bool getIsRenderTarget() const {
+        return (mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_RENDER_TARGET) != 0;
+    }
     bool getIsBufferObject() const {
         return (mHal.state.usageFlags & RS_ALLOCATION_USAGE_GRAPHICS_VERTEX) != 0;
     }
@@ -161,7 +168,10 @@
     // is allowed.
     uint32_t mBufferID;
 
-    bool mUploadDefered;
+    // Is this a legal structure to be used as an FBO render target
+    uint32_t mRenderTargetID;
+
+    bool mUploadDeferred;
 
 private:
     void init(Context *rsc, const Type *);
diff --git a/libs/rs/rsComponent.cpp b/libs/rs/rsComponent.cpp
index 4c4987a..e2ae043 100644
--- a/libs/rs/rsComponent.cpp
+++ b/libs/rs/rsComponent.cpp
@@ -18,6 +18,7 @@
 
 #ifndef ANDROID_RS_SERIALIZE
 #include <GLES/gl.h>
+#include <GLES2/gl2.h>
 #endif
 
 using namespace android;
@@ -207,6 +208,7 @@
     case RS_KIND_PIXEL_LA: return GL_LUMINANCE_ALPHA;
     case RS_KIND_PIXEL_RGB: return GL_RGB;
     case RS_KIND_PIXEL_RGBA: return GL_RGBA;
+    case RS_KIND_PIXEL_DEPTH: return GL_DEPTH_COMPONENT16;
     default: break;
     }
 #endif //ANDROID_RS_SERIALIZE
diff --git a/libs/rs/rsContext.cpp b/libs/rs/rsContext.cpp
index c761c75..d727ba1 100644
--- a/libs/rs/rsContext.cpp
+++ b/libs/rs/rsContext.cpp
@@ -409,6 +409,7 @@
     mFragment->setupGL2(this, &mStateFragment, &mShaderCache);
     mRaster->setupGL2(this, &mStateRaster);
     mVertex->setupGL2(this, &mStateVertex, &mShaderCache);
+    mFBOCache.setupGL2(this);
     return true;
 }
 
diff --git a/libs/rs/rsContext.h b/libs/rs/rsContext.h
index 72574a60..eacfdf7 100644
--- a/libs/rs/rsContext.h
+++ b/libs/rs/rsContext.h
@@ -38,6 +38,7 @@
 #include "rsProgramRaster.h"
 #include "rsProgramVertex.h"
 #include "rsShaderCache.h"
+#include "rsFBOCache.h"
 #include "rsVertexArray.h"
 
 #include "rsgApiStructs.h"
@@ -119,6 +120,7 @@
 
     ScriptCState mScriptC;
     ShaderCache mShaderCache;
+    FBOCache mFBOCache;
 
     void swapBuffers();
     void setRootScript(Script *);
diff --git a/libs/rs/rsFBOCache.cpp b/libs/rs/rsFBOCache.cpp
new file mode 100644
index 0000000..78aa8ce
--- /dev/null
+++ b/libs/rs/rsFBOCache.cpp
@@ -0,0 +1,209 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "rsFBOCache.h"
+
+#include "rsContext.h"
+#include "rsAllocation.h"
+
+#ifndef ANDROID_RS_SERIALIZE
+#include <GLES/gl.h>
+#include <GLES2/gl2.h>
+#endif //ANDROID_RS_SERIALIZE
+
+using namespace android;
+using namespace android::renderscript;
+
+
+FBOCache::FBOCache() {
+    mFBOId = 0;
+    mDirty = false;
+    mMaxTargets = 1;
+    mColorTargets = new ObjectBaseRef<Allocation>[mMaxTargets];
+}
+
+FBOCache::~FBOCache() {
+    delete[] mColorTargets;
+#ifndef ANDROID_RS_SERIALIZE
+    if(mFBOId != 0) {
+        glDeleteFramebuffers(1, &mFBOId);
+    }
+#endif //ANDROID_RS_SERIALIZE
+}
+
+void FBOCache::bindColorTarget(Context *rsc, Allocation *a, uint32_t slot) {
+    if (slot >= mMaxTargets) {
+        LOGE("Invalid render target index");
+        return;
+    }
+    if (a != NULL) {
+        if (!a->getIsTexture()) {
+            LOGE("Invalid Color Target");
+            return;
+        }
+        if (a->getIsTexture()) {
+            if (a->getTextureID() == 0) {
+                a->deferredUploadToTexture(rsc);
+            }
+        } else if (a->getRenderTargetID() == 0) {
+            a->deferredAllocateRenderTarget(rsc);
+        }
+    }
+    mColorTargets[slot].set(a);
+    mDirty = true;
+}
+
+void FBOCache::bindDepthTarget(Context *rsc, Allocation *a) {
+    if (a != NULL) {
+        if (!a->getIsRenderTarget()) {
+            LOGE("Invalid Depth Target");
+            return;
+        }
+        if (a->getIsTexture()) {
+            if (a->getTextureID() == 0) {
+                a->deferredUploadToTexture(rsc);
+            }
+        } else if (a->getRenderTargetID() == 0) {
+            a->deferredAllocateRenderTarget(rsc);
+        }
+    }
+    mDepthTarget.set(a);
+    mDirty = true;
+}
+
+void FBOCache::resetAll(Context *) {
+    for (uint32_t i = 0; i < mMaxTargets; i ++) {
+        mColorTargets[i].set(NULL);
+    }
+    mDepthTarget.set(NULL);
+    mDirty = true;
+}
+
+bool FBOCache::renderToFramebuffer() {
+    if (mDepthTarget.get() != NULL) {
+        return false;
+    }
+
+    for (uint32_t i = 0; i < mMaxTargets; i ++) {
+        if (mColorTargets[i].get() != NULL) {
+            return false;
+        }
+    }
+    return true;
+}
+
+void FBOCache::checkError(Context *rsc) {
+    GLenum status;
+    status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+    switch (status) {
+    case GL_FRAMEBUFFER_COMPLETE:
+        break;
+    case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
+        rsc->setError(RS_ERROR_BAD_VALUE,
+                      "Unable to set up render Target: RFRAMEBUFFER_INCOMPLETE_ATTACHMENT");
+        break;
+    case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
+        rsc->setError(RS_ERROR_BAD_VALUE,
+                      "Unable to set up render Target: GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");
+        break;
+    case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS:
+        rsc->setError(RS_ERROR_BAD_VALUE,
+                      "Unable to set up render Target: GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS");
+        break;
+    case GL_FRAMEBUFFER_UNSUPPORTED:
+        rsc->setError(RS_ERROR_BAD_VALUE,
+                      "Unable to set up render Target: GL_FRAMEBUFFER_UNSUPPORTED");
+        break;
+    }
+}
+
+void FBOCache::setDepthAttachment(Context *rsc) {
+#ifndef ANDROID_RS_SERIALIZE
+    if (mDepthTarget.get() != NULL) {
+        mDepthTarget->uploadCheck(rsc);
+        if (mDepthTarget->getIsTexture()) {
+            uint32_t texID = mDepthTarget->getTextureID();
+            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
+                                   GL_TEXTURE_2D, texID, 0);
+        } else {
+            uint32_t texID = mDepthTarget->getRenderTargetID();
+            glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
+                                      GL_RENDERBUFFER, texID);
+        }
+    } else {
+        // Reset last attachment
+        glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
+                                  GL_RENDERBUFFER, 0);
+        glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
+                               GL_TEXTURE_2D, 0, 0);
+    }
+#endif //ANDROID_RS_SERIALIZE
+}
+
+void FBOCache::setColorAttachment(Context *rsc) {
+#ifndef ANDROID_RS_SERIALIZE
+    // Now attach color targets
+    for (uint32_t i = 0; i < mMaxTargets; i ++) {
+        uint32_t texID = 0;
+        if (mColorTargets[i].get() != NULL) {
+            mColorTargets[i]->uploadCheck(rsc);
+            if (mColorTargets[i]->getIsTexture()) {
+                uint32_t texID = mColorTargets[i]->getTextureID();
+                glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
+                                       GL_TEXTURE_2D, texID, 0);
+            } else {
+                uint32_t texID = mDepthTarget->getRenderTargetID();
+                glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
+                                          GL_RENDERBUFFER, texID);
+            }
+        } else {
+            // Reset last attachment
+            glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
+                                      GL_RENDERBUFFER, 0);
+            glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0 + i,
+                                   GL_TEXTURE_2D, 0, 0);
+        }
+    }
+#endif //ANDROID_RS_SERIALIZE
+}
+
+void FBOCache::setupGL2(Context *rsc) {
+#ifndef ANDROID_RS_SERIALIZE
+    if (!mDirty) {
+        return;
+    }
+
+    bool framebuffer = renderToFramebuffer();
+
+    if (!framebuffer) {
+        if(mFBOId == 0) {
+            glGenFramebuffers(1, &mFBOId);
+        }
+        glBindFramebuffer(GL_FRAMEBUFFER, mFBOId);
+
+        setDepthAttachment(rsc);
+        setColorAttachment(rsc);
+
+        glViewport(0, 0, mColorTargets[0]->getType()->getDimX(),
+                         mColorTargets[0]->getType()->getDimY());
+
+        checkError(rsc);
+    } else {
+        glBindFramebuffer(GL_FRAMEBUFFER, 0);
+        glViewport(0, 0, rsc->getWidth(), rsc->getHeight());
+    }
+#endif //ANDROID_RS_SERIALIZE
+}
diff --git a/libs/rs/rsFBOCache.h b/libs/rs/rsFBOCache.h
new file mode 100644
index 0000000..9a0a3b6
--- /dev/null
+++ b/libs/rs/rsFBOCache.h
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef ANDROID_FRAME_BUFFER_OBJECT_CACHE_H
+#define ANDROID_FRAME_BUFFER_OBJECT_CACHE_H
+
+#include "rsObjectBase.h"
+
+// ---------------------------------------------------------------------------
+namespace android {
+namespace renderscript {
+
+class Allocation;
+
+class FBOCache {
+public:
+    FBOCache();
+    ~FBOCache();
+
+    void bindColorTarget(Context *rsc, Allocation *a, uint32_t slot);
+    void bindDepthTarget(Context *, Allocation *a);
+    void resetAll(Context *);
+
+    void setupGL2(Context *);
+
+protected:
+
+    bool mDirty;
+    uint32_t mMaxTargets;
+    void checkError(Context *);
+    void setColorAttachment(Context *rsc);
+    void setDepthAttachment(Context *rsc);
+    bool renderToFramebuffer();
+    ObjectBaseRef<Allocation> *mColorTargets;
+    ObjectBaseRef<Allocation> mDepthTarget;
+
+    uint32_t mFBOId;
+
+};
+
+} // renderscript
+} // android
+
+#endif //ANDROID_FRAME_BUFFER_OBJECT_CACHE_H
diff --git a/libs/rs/rsFont.cpp b/libs/rs/rsFont.cpp
index 01dbab8..595c89a 100644
--- a/libs/rs/rsFont.cpp
+++ b/libs/rs/rsFont.cpp
@@ -566,7 +566,7 @@
         indexPtr[i6 + 5] = i4 + 3;
     }
 
-    indexAlloc->deferedUploadToBufferObject(mRSC);
+    indexAlloc->deferredUploadToBufferObject(mRSC);
     mIndexBuffer.set(indexAlloc);
 
     const Element *posElem = Element::create(mRSC, RS_TYPE_FLOAT_32, RS_KIND_USER, false, 3);
diff --git a/libs/rs/rsMesh.cpp b/libs/rs/rsMesh.cpp
index 76fe62d..e29c800 100644
--- a/libs/rs/rsMesh.cpp
+++ b/libs/rs/rsMesh.cpp
@@ -282,13 +282,13 @@
 void Mesh::uploadAll(Context *rsc) {
     for (uint32_t ct = 0; ct < mVertexBufferCount; ct ++) {
         if (mVertexBuffers[ct].get()) {
-            mVertexBuffers[ct]->deferedUploadToBufferObject(rsc);
+            mVertexBuffers[ct]->deferredUploadToBufferObject(rsc);
         }
     }
 
     for (uint32_t ct = 0; ct < mPrimitivesCount; ct ++) {
         if (mPrimitives[ct]->mIndexBuffer.get()) {
-            mPrimitives[ct]->mIndexBuffer->deferedUploadToBufferObject(rsc);
+            mPrimitives[ct]->mIndexBuffer->deferredUploadToBufferObject(rsc);
         }
     }
 }
diff --git a/libs/rs/rsScriptC_LibGL.cpp b/libs/rs/rsScriptC_LibGL.cpp
index 4047049..1ed0f31 100644
--- a/libs/rs/rsScriptC_LibGL.cpp
+++ b/libs/rs/rsScriptC_LibGL.cpp
@@ -86,6 +86,33 @@
     rsi_ContextBindProgramRaster(rsc, pv);
 }
 
+static void SC_bindFrameBufferObjectColorTarget(RsAllocation va, uint32_t slot) {
+    CHECK_OBJ(va);
+    GET_TLS();
+    rsc->mFBOCache.bindColorTarget(rsc, static_cast<Allocation *>(va), slot);
+}
+
+static void SC_bindFrameBufferObjectDepthTarget(RsAllocation va) {
+    CHECK_OBJ(va);
+    GET_TLS();
+    rsc->mFBOCache.bindDepthTarget(rsc, static_cast<Allocation *>(va));
+}
+
+static void SC_clearFrameBufferObjectColorTarget(uint32_t slot) {
+    GET_TLS();
+    rsc->mFBOCache.bindColorTarget(rsc, NULL, slot);
+}
+
+static void SC_clearFrameBufferObjectDepthTarget() {
+    GET_TLS();
+    rsc->mFBOCache.bindDepthTarget(rsc, NULL);
+}
+
+static void SC_clearFrameBufferObjectTargets() {
+    GET_TLS();
+    rsc->mFBOCache.resetAll(rsc);
+}
+
 //////////////////////////////////////////////////////////////////////////////
 // VP
 //////////////////////////////////////////////////////////////////////////////
@@ -275,6 +302,10 @@
     pf->setConstantColor(rsc, r, g, b, a);
 }
 
+static void SC_finish() {
+    glFinish();
+}
+
 static void SC_allocationSyncAll(RsAllocation va) {
     CHECK_OBJ(va);
     GET_TLS();
@@ -291,6 +322,7 @@
 
 static void SC_ClearColor(float r, float g, float b, float a) {
     GET_TLS();
+    rsc->mFBOCache.setupGL2(rsc);
     rsc->setupProgramStore();
 
     glClearColor(r, g, b, a);
@@ -299,6 +331,7 @@
 
 static void SC_ClearDepth(float v) {
     GET_TLS();
+    rsc->mFBOCache.setupGL2(rsc);
     rsc->setupProgramStore();
 
     glClearDepthf(v);
@@ -444,8 +477,15 @@
     { "_Z11rsgBindFont7rs_font", (void *)&SC_BindFont, false },
     { "_Z12rsgFontColorffff", (void *)&SC_FontColor, false },
 
+    { "_Z18rsgBindColorTarget13rs_allocationj", (void *)&SC_bindFrameBufferObjectColorTarget, false },
+    { "_Z18rsgBindDepthTarget13rs_allocation", (void *)&SC_bindFrameBufferObjectDepthTarget, false },
+    { "_Z19rsgClearColorTargetj", (void *)&SC_clearFrameBufferObjectColorTarget, false },
+    { "_Z19rsgClearDepthTargetv", (void *)&SC_clearFrameBufferObjectDepthTarget, false },
+    { "_Z24rsgClearAllRenderTargetsv", (void *)&SC_clearFrameBufferObjectTargets, false },
+
     // misc
     { "_Z5colorffff", (void *)&SC_color, false },
+    { "_Z9rsgFinishv", (void *)&SC_finish, false },
 
     { NULL, NULL, false }
 };
diff --git a/libs/rs/scriptc/rs_graphics.rsh b/libs/rs/scriptc/rs_graphics.rsh
index 67ffc3d..d53bc95 100644
--- a/libs/rs/scriptc/rs_graphics.rsh
+++ b/libs/rs/scriptc/rs_graphics.rsh
@@ -1,6 +1,46 @@
 #ifndef __RS_GRAPHICS_RSH__
 #define __RS_GRAPHICS_RSH__
 
+/**
+ * Set the color target used for all subsequent rendering calls
+ * @param colorTarget
+ * @param slot
+ */
+extern void __attribute__((overloadable))
+    rsgBindColorTarget(rs_allocation colorTarget, uint slot);
+
+/**
+ * Clear the previously set color target
+ * @param slot
+ */
+extern void __attribute__((overloadable))
+    rsgClearColorTarget(uint slot);
+
+/**
+ * Set the depth target used for all subsequent rendering calls
+ * @param depthTarget
+ */
+extern void __attribute__((overloadable))
+    rsgBindDepthTarget(rs_allocation depthTarget);
+
+/**
+ * Clear the previously set depth target
+ */
+extern void __attribute__((overloadable))
+    rsgClearDepthTarget(void);
+
+/**
+ * Clear all color and depth targets and resume rendering into
+ * the framebuffer
+ */
+extern void __attribute__((overloadable))
+    rsgClearAllRenderTargets(void);
+
+/**
+ * Force RenderScript to finish all rendering commands
+ */
+extern uint __attribute__((overloadable))
+    rsgFinish(void);
 
 /**
  * Bind a new ProgramFragment to the rendering context.
diff --git a/packages/SystemUI/res/drawable-hdpi/stat_sys_roaming_cdma_0.png b/packages/SystemUI/res/drawable-hdpi/stat_sys_roaming_cdma_0.png
index adde938..c8ddfce 100644
--- a/packages/SystemUI/res/drawable-hdpi/stat_sys_roaming_cdma_0.png
+++ b/packages/SystemUI/res/drawable-hdpi/stat_sys_roaming_cdma_0.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-hdpi/stat_sys_roaming_cdma_flash_anim1.png b/packages/SystemUI/res/drawable-hdpi/stat_sys_roaming_cdma_flash_anim1.png
index adde938..6b6a6df 100644
--- a/packages/SystemUI/res/drawable-hdpi/stat_sys_roaming_cdma_flash_anim1.png
+++ b/packages/SystemUI/res/drawable-hdpi/stat_sys_roaming_cdma_flash_anim1.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/stat_sys_roaming_cdma_0.png b/packages/SystemUI/res/drawable-mdpi/stat_sys_roaming_cdma_0.png
index c61cce7..827d84a 100755
--- a/packages/SystemUI/res/drawable-mdpi/stat_sys_roaming_cdma_0.png
+++ b/packages/SystemUI/res/drawable-mdpi/stat_sys_roaming_cdma_0.png
Binary files differ
diff --git a/packages/SystemUI/res/drawable-mdpi/stat_sys_roaming_cdma_flash_anim1.png b/packages/SystemUI/res/drawable-mdpi/stat_sys_roaming_cdma_flash_anim1.png
index c61cce7..edc6023 100755
--- a/packages/SystemUI/res/drawable-mdpi/stat_sys_roaming_cdma_flash_anim1.png
+++ b/packages/SystemUI/res/drawable-mdpi/stat_sys_roaming_cdma_flash_anim1.png
Binary files differ
diff --git a/services/java/com/android/server/BackupManagerService.java b/services/java/com/android/server/BackupManagerService.java
index ea38fbb..6e76331 100644
--- a/services/java/com/android/server/BackupManagerService.java
+++ b/services/java/com/android/server/BackupManagerService.java
@@ -760,15 +760,15 @@
                     sf.delete();
                 }
             }
+        }
 
-            // Enqueue a new backup of every participant
-            int N = mBackupParticipants.size();
-            for (int i=0; i<N; i++) {
-                int uid = mBackupParticipants.keyAt(i);
-                HashSet<ApplicationInfo> participants = mBackupParticipants.valueAt(i);
-                for (ApplicationInfo app: participants) {
-                    dataChangedImpl(app.packageName);
-                }
+        // Enqueue a new backup of every participant
+        int N = mBackupParticipants.size();
+        for (int i=0; i<N; i++) {
+            int uid = mBackupParticipants.keyAt(i);
+            HashSet<ApplicationInfo> participants = mBackupParticipants.valueAt(i);
+            for (ApplicationInfo app: participants) {
+                dataChangedImpl(app.packageName);
             }
         }
     }
diff --git a/services/java/com/android/server/ConnectivityService.java b/services/java/com/android/server/ConnectivityService.java
index 3997702..f57f32e 100644
--- a/services/java/com/android/server/ConnectivityService.java
+++ b/services/java/com/android/server/ConnectivityService.java
@@ -1294,6 +1294,7 @@
                     }
                     if (!teardown(otherNet)) {
                         loge("Network declined teardown request");
+                        teardown(thisNet);
                         return;
                     }
                 }
diff --git a/services/java/com/android/server/MountService.java b/services/java/com/android/server/MountService.java
index 4e80147..7e5fd29 100644
--- a/services/java/com/android/server/MountService.java
+++ b/services/java/com/android/server/MountService.java
@@ -65,6 +65,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Map.Entry;
+import java.util.Set;
 
 import javax.crypto.SecretKey;
 import javax.crypto.SecretKeyFactory;
@@ -148,7 +149,8 @@
 
     private Context                               mContext;
     private NativeDaemonConnector                 mConnector;
-    private String                                mLegacyState = Environment.MEDIA_REMOVED;
+    private final HashMap<String, String>         mVolumeStates = new HashMap<String, String>();
+    private String                                mExternalStoragePath;
     private PackageManagerService                 mPms;
     private boolean                               mUmsEnabling;
     // Used as a lock for methods that register/unregister listeners.
@@ -453,22 +455,25 @@
                     @Override
                     public void run() {
                         try {
-                            String path = Environment.getExternalStorageDirectory().getPath();
-                            String state = getVolumeState(path);
+                            synchronized (mVolumeStates) {
+                                for (String path : mVolumeStates.keySet()) {
+                                    String state = mVolumeStates.get(path);
 
-                            if (mEmulateExternalStorage) {
-                                notifyVolumeStateChange(null, path, VolumeState.NoMedia, VolumeState.Mounted);
-                            } else if (state.equals(Environment.MEDIA_UNMOUNTED)) {
-                                int rc = doMountVolume(path);
-                                if (rc != StorageResultCode.OperationSucceeded) {
-                                    Slog.e(TAG, String.format("Boot-time mount failed (%d)", rc));
+                                    if (state.equals(Environment.MEDIA_UNMOUNTED)) {
+                                        int rc = doMountVolume(path);
+                                        if (rc != StorageResultCode.OperationSucceeded) {
+                                            Slog.e(TAG, String.format("Boot-time mount failed (%d)",
+                                                    rc));
+                                        }
+                                    } else if (state.equals(Environment.MEDIA_SHARED)) {
+                                        /*
+                                         * Bootstrap UMS enabled state since vold indicates
+                                         * the volume is shared (runtime restart while ums enabled)
+                                         */
+                                        notifyVolumeStateChange(null, path, VolumeState.NoMedia,
+                                                VolumeState.Shared);
+                                    }
                                 }
-                            } else if (state.equals(Environment.MEDIA_SHARED)) {
-                                /*
-                                 * Bootstrap UMS enabled state since vold indicates
-                                 * the volume is shared (runtime restart while ums enabled)
-                                 */
-                                notifyVolumeStateChange(null, path, VolumeState.NoMedia, VolumeState.Shared);
                             }
 
                             /*
@@ -519,35 +524,36 @@
     }
 
     private void updatePublicVolumeState(String path, String state) {
-        if (!path.equals(Environment.getExternalStorageDirectory().getPath())) {
-            Slog.w(TAG, "Multiple volumes not currently supported");
+        String oldState;
+        synchronized(mVolumeStates) {
+            oldState = mVolumeStates.put(path, state);
+        }
+        if (state.equals(oldState)) {
+            Slog.w(TAG, String.format("Duplicate state transition (%s -> %s) for %s",
+                    state, state, path));
             return;
         }
 
-        if (mLegacyState.equals(state)) {
-            Slog.w(TAG, String.format("Duplicate state transition (%s -> %s)", mLegacyState, state));
-            return;
-        }
-        // Update state on PackageManager, but only of real events
-        if (!mEmulateExternalStorage) {
-            if (Environment.MEDIA_UNMOUNTED.equals(state)) {
-                mPms.updateExternalMediaStatus(false, false);
+        Slog.d(TAG, "volume state changed for " + path + " (" + oldState + " -> " + state + ")");
 
-                /*
-                 * Some OBBs might have been unmounted when this volume was
-                 * unmounted, so send a message to the handler to let it know to
-                 * remove those from the list of mounted OBBS.
-                 */
-                mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(OBB_FLUSH_MOUNT_STATE,
-                        path));
-            } else if (Environment.MEDIA_MOUNTED.equals(state)) {
-                mPms.updateExternalMediaStatus(true, false);
+        if (path.equals(mExternalStoragePath)) {
+            // Update state on PackageManager, but only of real events
+            if (!mEmulateExternalStorage) {
+                if (Environment.MEDIA_UNMOUNTED.equals(state)) {
+                    mPms.updateExternalMediaStatus(false, false);
+
+                    /*
+                     * Some OBBs might have been unmounted when this volume was
+                     * unmounted, so send a message to the handler to let it know to
+                     * remove those from the list of mounted OBBS.
+                     */
+                    mObbActionHandler.sendMessage(mObbActionHandler.obtainMessage(
+                            OBB_FLUSH_MOUNT_STATE, path));
+                } else if (Environment.MEDIA_MOUNTED.equals(state)) {
+                    mPms.updateExternalMediaStatus(true, false);
+                }
             }
         }
-
-        String oldState = mLegacyState;
-        mLegacyState = state;
-
         synchronized (mListeners) {
             for (int i = mListeners.size() -1; i >= 0; i--) {
                 MountServiceBinderListener bl = mListeners.get(i);
@@ -578,20 +584,15 @@
                 /**
                  * Determine media state and UMS detection status
                  */
-                String path = Environment.getExternalStorageDirectory().getPath();
-                String state = Environment.MEDIA_REMOVED;
-
                 try {
                     String[] vols = mConnector.doListCommand(
                         "volume list", VoldResponseCode.VolumeListResult);
                     for (String volstr : vols) {
                         String[] tok = volstr.split(" ");
                         // FMT: <label> <mountpoint> <state>
-                        if (!tok[1].equals(path)) {
-                            Slog.w(TAG, String.format(
-                                    "Skipping unknown volume '%s'",tok[1]));
-                            continue;
-                        }
+                        String path = tok[1];
+                        String state = Environment.MEDIA_REMOVED;
+
                         int st = Integer.parseInt(tok[2]);
                         if (st == VolumeState.NoMedia) {
                             state = Environment.MEDIA_REMOVED;
@@ -606,14 +607,15 @@
                         } else {
                             throw new Exception(String.format("Unexpected state %d", st));
                         }
-                    }
-                    if (state != null) {
-                        if (DEBUG_EVENTS) Slog.i(TAG, "Updating valid state " + state);
-                        updatePublicVolumeState(path, state);
+
+                        if (state != null) {
+                            if (DEBUG_EVENTS) Slog.i(TAG, "Updating valid state " + state);
+                            updatePublicVolumeState(path, state);
+                        }
                     }
                 } catch (Exception e) {
                     Slog.e(TAG, "Error processing initial volume state", e);
-                    updatePublicVolumeState(path, Environment.MEDIA_REMOVED);
+                    updatePublicVolumeState(mExternalStoragePath, Environment.MEDIA_REMOVED);
                 }
 
                 try {
@@ -1055,11 +1057,12 @@
     public MountService(Context context) {
         mContext = context;
 
+        mExternalStoragePath = Environment.getExternalStorageDirectory().getPath();
         mEmulateExternalStorage = context.getResources().getBoolean(
                 com.android.internal.R.bool.config_emulateExternalStorage);
         if (mEmulateExternalStorage) {
             Slog.d(TAG, "using emulated external storage");
-            mLegacyState = Environment.MEDIA_MOUNTED;
+            mVolumeStates.put(mExternalStoragePath, Environment.MEDIA_MOUNTED);
         }
 
         // XXX: This will go away soon in favor of IMountServiceObserver
@@ -1127,54 +1130,56 @@
         validatePermission(android.Manifest.permission.SHUTDOWN);
 
         Slog.i(TAG, "Shutting down");
+        synchronized (mVolumeStates) {
+            for (String path : mVolumeStates.keySet()) {
+                String state = mVolumeStates.get(path);
 
-        String path = Environment.getExternalStorageDirectory().getPath();
-        String state = getVolumeState(path);
-
-        if (state.equals(Environment.MEDIA_SHARED)) {
-            /*
-             * If the media is currently shared, unshare it.
-             * XXX: This is still dangerous!. We should not
-             * be rebooting at *all* if UMS is enabled, since
-             * the UMS host could have dirty FAT cache entries
-             * yet to flush.
-             */
-            setUsbMassStorageEnabled(false);
-        } else if (state.equals(Environment.MEDIA_CHECKING)) {
-            /*
-             * If the media is being checked, then we need to wait for
-             * it to complete before being able to proceed.
-             */
-            // XXX: @hackbod - Should we disable the ANR timer here?
-            int retries = 30;
-            while (state.equals(Environment.MEDIA_CHECKING) && (retries-- >=0)) {
-                try {
-                    Thread.sleep(1000);
-                } catch (InterruptedException iex) {
-                    Slog.e(TAG, "Interrupted while waiting for media", iex);
-                    break;
+                if (state.equals(Environment.MEDIA_SHARED)) {
+                    /*
+                     * If the media is currently shared, unshare it.
+                     * XXX: This is still dangerous!. We should not
+                     * be rebooting at *all* if UMS is enabled, since
+                     * the UMS host could have dirty FAT cache entries
+                     * yet to flush.
+                     */
+                    setUsbMassStorageEnabled(false);
+                } else if (state.equals(Environment.MEDIA_CHECKING)) {
+                    /*
+                     * If the media is being checked, then we need to wait for
+                     * it to complete before being able to proceed.
+                     */
+                    // XXX: @hackbod - Should we disable the ANR timer here?
+                    int retries = 30;
+                    while (state.equals(Environment.MEDIA_CHECKING) && (retries-- >=0)) {
+                        try {
+                            Thread.sleep(1000);
+                        } catch (InterruptedException iex) {
+                            Slog.e(TAG, "Interrupted while waiting for media", iex);
+                            break;
+                        }
+                        state = Environment.getExternalStorageState();
+                    }
+                    if (retries == 0) {
+                        Slog.e(TAG, "Timed out waiting for media to check");
+                    }
                 }
-                state = Environment.getExternalStorageState();
-            }
-            if (retries == 0) {
-                Slog.e(TAG, "Timed out waiting for media to check");
-            }
-        }
 
-        if (state.equals(Environment.MEDIA_MOUNTED)) {
-            // Post a unmount message.
-            ShutdownCallBack ucb = new ShutdownCallBack(path, observer);
-            mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb));
-        } else if (observer != null) {
-            /*
-             * Observer is waiting for onShutDownComplete when we are done.
-             * Since nothing will be done send notification directly so shutdown
-             * sequence can continue.
-             */
-            try {
-                observer.onShutDownComplete(StorageResultCode.OperationSucceeded);
-            } catch (RemoteException e) {
-                Slog.w(TAG, "RemoteException when shutting down");
+                if (state.equals(Environment.MEDIA_MOUNTED)) {
+                    // Post a unmount message.
+                    ShutdownCallBack ucb = new ShutdownCallBack(path, observer);
+                    mHandler.sendMessage(mHandler.obtainMessage(H_UNMOUNT_PM_UPDATE, ucb));
+                } else if (observer != null) {
+                    /*
+                     * Observer is waiting for onShutDownComplete when we are done.
+                     * Since nothing will be done send notification directly so shutdown
+                     * sequence can continue.
+                     */
+                    try {
+                        observer.onShutDownComplete(StorageResultCode.OperationSucceeded);
+                    } catch (RemoteException e) {
+                        Slog.w(TAG, "RemoteException when shutting down");
+                    }
+                }
             }
         }
     }
@@ -1246,16 +1251,15 @@
      * @return state of the volume at the specified mount point
      */
     public String getVolumeState(String mountPoint) {
-        /*
-         * XXX: Until we have multiple volume discovery, just hardwire
-         * this to /sdcard
-         */
-        if (!mountPoint.equals(Environment.getExternalStorageDirectory().getPath())) {
-            Slog.w(TAG, "getVolumeState(" + mountPoint + "): Unknown volume");
-            throw new IllegalArgumentException();
-        }
+        synchronized (mVolumeStates) {
+            String state = mVolumeStates.get(mountPoint);
+            if (state == null) {
+                Slog.w(TAG, "getVolumeState(" + mountPoint + "): Unknown volume");
+                throw new IllegalArgumentException();
+            }
 
-        return mLegacyState;
+            return state;
+        }
     }
 
     public boolean isExternalStorageEmulated() {
@@ -1534,7 +1538,8 @@
         } catch (NativeDaemonConnectorException e) {
             int code = e.getCode();
             if (code == VoldResponseCode.OpFailedStorageNotFound) {
-                throw new IllegalArgumentException(String.format("Container '%s' not found", id));
+                Slog.i(TAG, String.format("Container '%s' not found", id));
+                return null;
             } else {
                 throw new IllegalStateException(String.format("Unexpected response code %d", code));
             }
@@ -1729,6 +1734,18 @@
         }
     }
 
+    public String[] getVolumeList() {
+        synchronized(mVolumeStates) {
+            Set<String> volumes = mVolumeStates.keySet();
+            String[] result = new String[volumes.size()];
+            int i = 0;
+            for (String volume : volumes) {
+                result[i++] = volume;
+            }
+            return result;
+        }
+    }
+
     private void addObbStateLocked(ObbState obbState) throws RemoteException {
         final IBinder binder = obbState.getBinder();
         List<ObbState> obbStates = mObbMounts.get(binder);
diff --git a/tests/RenderScriptTests/FBOTest/Android.mk b/tests/RenderScriptTests/FBOTest/Android.mk
new file mode 100644
index 0000000..55525c4
--- /dev/null
+++ b/tests/RenderScriptTests/FBOTest/Android.mk
@@ -0,0 +1,30 @@
+#
+# Copyright (C) 2008 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+ifneq ($(TARGET_SIMULATOR),true)
+
+LOCAL_PATH := $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := optional
+
+LOCAL_SRC_FILES := $(call all-java-files-under, src) $(call all-renderscript-files-under, src)
+
+LOCAL_PACKAGE_NAME := FBOTest
+
+include $(BUILD_PACKAGE)
+
+endif
diff --git a/tests/RenderScriptTests/FBOTest/AndroidManifest.xml b/tests/RenderScriptTests/FBOTest/AndroidManifest.xml
new file mode 100644
index 0000000..c2e0cc6
--- /dev/null
+++ b/tests/RenderScriptTests/FBOTest/AndroidManifest.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+    package="com.android.fbotest">
+    <application android:label="_FBOTest">
+        <activity android:name="FBOTest"
+                  android:theme="@android:style/Theme.Black.NoTitleBar">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>        
+    </application>
+</manifest>
diff --git a/tests/RenderScriptTests/FBOTest/res/drawable/robot.png b/tests/RenderScriptTests/FBOTest/res/drawable/robot.png
new file mode 100644
index 0000000..f7353fd
--- /dev/null
+++ b/tests/RenderScriptTests/FBOTest/res/drawable/robot.png
Binary files differ
diff --git a/tests/RenderScriptTests/FBOTest/res/raw/robot.a3d b/tests/RenderScriptTests/FBOTest/res/raw/robot.a3d
new file mode 100644
index 0000000..f48895c
--- /dev/null
+++ b/tests/RenderScriptTests/FBOTest/res/raw/robot.a3d
Binary files differ
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTest.java b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTest.java
new file mode 100644
index 0000000..79d60124
--- /dev/null
+++ b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTest.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2008 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.fbotest;
+
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScript;
+
+import android.app.Activity;
+import android.content.res.Configuration;
+import android.content.Intent;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Looper;
+import android.os.Message;
+import android.provider.Settings.System;
+import android.util.Config;
+import android.util.Log;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.View;
+import android.view.MenuInflater;
+import android.view.Window;
+import android.widget.Button;
+import android.widget.ListView;
+import android.net.Uri;
+
+import java.lang.Runtime;
+
+public class FBOTest extends Activity {
+
+    private FBOTestView mView;
+
+    @Override
+    public void onCreate(Bundle icicle) {
+        super.onCreate(icicle);
+
+        // Create our Preview view and set it as the content of our
+        // Activity
+        mView = new FBOTestView(this);
+        setContentView(mView);
+    }
+
+    @Override
+    protected void onResume() {
+        // Ideally a game should implement onResume() and onPause()
+        // to take appropriate action when the activity looses focus
+        super.onResume();
+        mView.resume();
+    }
+
+    @Override
+    protected void onPause() {
+        // Ideally a game should implement onResume() and onPause()
+        // to take appropriate action when the activity looses focus
+        super.onPause();
+        mView.pause();
+    }
+}
+
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTestRS.java b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTestRS.java
new file mode 100644
index 0000000..9e30c4b5
--- /dev/null
+++ b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTestRS.java
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.fbotest;
+
+import java.io.Writer;
+
+import android.content.res.Resources;
+import android.renderscript.*;
+import android.renderscript.Element.DataType;
+import android.renderscript.Element.DataKind;
+import android.renderscript.ProgramStore.DepthFunc;
+import android.renderscript.Type.Builder;
+import android.util.Log;
+
+
+public class FBOTestRS {
+
+    public FBOTestRS() {
+    }
+
+    public void init(RenderScriptGL rs, Resources res) {
+        mRS = rs;
+        mRes = res;
+        initRS();
+    }
+
+    public void surfaceChanged() {
+        mRS.getWidth();
+        mRS.getHeight();
+    }
+
+    private Resources mRes;
+    private RenderScriptGL mRS;
+    private Sampler mSampler;
+    private ProgramStore mPSBackground;
+    private ProgramFragment mPFBackground;
+    private ProgramVertex mPVBackground;
+    private ProgramVertexFixedFunction.Constants mPVA;
+
+    private Allocation mGridImage;
+    private Allocation mOffscreen;
+    private Allocation mOffscreenDepth;
+    private Allocation mAllocPV;
+
+    private Font mItalic;
+    private Allocation mTextAlloc;
+
+    private ScriptField_MeshInfo mMeshes;
+    private ScriptC_fbotest mScript;
+
+
+    public void onActionDown(float x, float y) {
+        mScript.invoke_onActionDown(x, y);
+    }
+
+    public void onActionScale(float scale) {
+        mScript.invoke_onActionScale(scale);
+    }
+
+    public void onActionMove(float x, float y) {
+        mScript.invoke_onActionMove(x, y);
+    }
+
+    private void initPFS() {
+        ProgramStore.Builder b = new ProgramStore.Builder(mRS);
+
+        b.setDepthFunc(ProgramStore.DepthFunc.LESS);
+        b.setDitherEnabled(false);
+        b.setDepthMaskEnabled(true);
+        mPSBackground = b.create();
+
+        mScript.set_gPFSBackground(mPSBackground);
+    }
+
+    private void initPF() {
+        Sampler.Builder bs = new Sampler.Builder(mRS);
+        bs.setMinification(Sampler.Value.LINEAR);
+        bs.setMagnification(Sampler.Value.LINEAR);
+        bs.setWrapS(Sampler.Value.CLAMP);
+        bs.setWrapT(Sampler.Value.CLAMP);
+        mSampler = bs.create();
+
+        ProgramFragmentFixedFunction.Builder b = new ProgramFragmentFixedFunction.Builder(mRS);
+        b.setTexture(ProgramFragmentFixedFunction.Builder.EnvMode.REPLACE,
+                     ProgramFragmentFixedFunction.Builder.Format.RGBA, 0);
+        mPFBackground = b.create();
+        mPFBackground.bindSampler(mSampler, 0);
+
+        mScript.set_gPFBackground(mPFBackground);
+    }
+
+    private void initPV() {
+        ProgramVertexFixedFunction.Builder pvb = new ProgramVertexFixedFunction.Builder(mRS);
+        mPVBackground = pvb.create();
+
+        mPVA = new ProgramVertexFixedFunction.Constants(mRS);
+        ((ProgramVertexFixedFunction)mPVBackground).bindConstants(mPVA);
+
+        mScript.set_gPVBackground(mPVBackground);
+    }
+
+    private void loadImage() {
+        mGridImage = Allocation.createFromBitmapResource(mRS, mRes, R.drawable.robot,
+                                                         Allocation.MipmapControl.MIPMAP_ON_SYNC_TO_TEXTURE,
+                                                         Allocation.USAGE_GRAPHICS_TEXTURE);
+        mScript.set_gTGrid(mGridImage);
+    }
+
+    private void initTextAllocation(String fileName) {
+        String allocString = "Displaying file: " + fileName;
+        mTextAlloc = Allocation.createFromString(mRS, allocString, Allocation.USAGE_SCRIPT);
+        mScript.set_gTextAlloc(mTextAlloc);
+    }
+
+    private void initMeshes(FileA3D model) {
+        int numEntries = model.getIndexEntryCount();
+        int numMeshes = 0;
+        for (int i = 0; i < numEntries; i ++) {
+            FileA3D.IndexEntry entry = model.getIndexEntry(i);
+            if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
+                numMeshes ++;
+            }
+        }
+
+        if (numMeshes > 0) {
+            mMeshes = new ScriptField_MeshInfo(mRS, numMeshes);
+
+            for (int i = 0; i < numEntries; i ++) {
+                FileA3D.IndexEntry entry = model.getIndexEntry(i);
+                if (entry != null && entry.getEntryType() == FileA3D.EntryType.MESH) {
+                    Mesh mesh = entry.getMesh();
+                    mMeshes.set_mMesh(i, mesh, false);
+                    mMeshes.set_mNumIndexSets(i, mesh.getPrimitiveCount(), false);
+                }
+            }
+            mMeshes.copyAll();
+        } else {
+            throw new RSRuntimeException("No valid meshes in file");
+        }
+
+        mScript.bind_gMeshes(mMeshes);
+        mScript.invoke_updateMeshInfo();
+    }
+
+    public void loadA3DFile(String path) {
+        FileA3D model = FileA3D.createFromFile(mRS, path);
+        initMeshes(model);
+        initTextAllocation(path);
+    }
+
+    private void initRS() {
+
+        mScript = new ScriptC_fbotest(mRS, mRes, R.raw.fbotest);
+
+        initPFS();
+        initPF();
+        initPV();
+
+        loadImage();
+
+        Type.Builder b = new Type.Builder(mRS, Element.RGBA_8888(mRS));
+        b.setX(512).setY(512);
+        mOffscreen = Allocation.createTyped(mRS,
+                                            b.create(),
+                                            Allocation.USAGE_GRAPHICS_TEXTURE |
+                                            Allocation.USAGE_GRAPHICS_RENDER_TARGET);
+        mScript.set_gOffscreen(mOffscreen);
+
+        b = new Type.Builder(mRS,
+                             Element.createPixel(mRS, DataType.UNSIGNED_16,
+                             DataKind.PIXEL_DEPTH));
+        b.setX(512).setY(512);
+        mOffscreenDepth = Allocation.createTyped(mRS,
+                                                 b.create(),
+                                                 Allocation.USAGE_GRAPHICS_RENDER_TARGET);
+        mScript.set_gOffscreenDepth(mOffscreenDepth);
+
+        FileA3D model = FileA3D.createFromResource(mRS, mRes, R.raw.robot);
+        initMeshes(model);
+
+        mItalic = Font.create(mRS, mRes, "serif", Font.Style.ITALIC, 8);
+        mScript.set_gItalic(mItalic);
+
+        initTextAllocation("R.raw.robot");
+
+        mRS.bindRootScript(mScript);
+    }
+}
+
+
+
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTestView.java b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTestView.java
new file mode 100644
index 0000000..c9598ee
--- /dev/null
+++ b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/FBOTestView.java
@@ -0,0 +1,144 @@
+/*
+ * Copyright (C) 2011 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.fbotest;
+
+import android.renderscript.RSSurfaceView;
+import android.renderscript.RenderScriptGL;
+
+import android.content.Context;
+import android.view.MotionEvent;
+import android.view.SurfaceHolder;
+import android.view.ScaleGestureDetector;
+import android.util.Log;
+
+public class FBOTestView extends RSSurfaceView {
+
+    private RenderScriptGL mRS;
+    private FBOTestRS mRender;
+
+    private ScaleGestureDetector mScaleDetector;
+
+    private static final int INVALID_POINTER_ID = -1;
+    private int mActivePointerId = INVALID_POINTER_ID;
+
+    public FBOTestView(Context context) {
+        super(context);
+        ensureRenderScript();
+        mScaleDetector = new ScaleGestureDetector(context, new ScaleListener());
+    }
+
+    private void ensureRenderScript() {
+        if (mRS == null) {
+            RenderScriptGL.SurfaceConfig sc = new RenderScriptGL.SurfaceConfig();
+            sc.setDepth(16, 24);
+            mRS = createRenderScriptGL(sc);
+            mRender = new FBOTestRS();
+            mRender.init(mRS, getResources());
+        }
+    }
+
+    @Override
+    protected void onAttachedToWindow() {
+        super.onAttachedToWindow();
+        ensureRenderScript();
+    }
+
+    @Override
+    public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
+        super.surfaceChanged(holder, format, w, h);
+        mRender.surfaceChanged();
+    }
+
+    @Override
+    protected void onDetachedFromWindow() {
+        mRender = null;
+        if (mRS != null) {
+            mRS = null;
+            destroyRenderScriptGL();
+        }
+    }
+
+    public void loadA3DFile(String path) {
+        mRender.loadA3DFile(path);
+    }
+
+    @Override
+    public boolean onTouchEvent(MotionEvent ev) {
+        mScaleDetector.onTouchEvent(ev);
+
+        boolean ret = false;
+        float x = ev.getX();
+        float y = ev.getY();
+
+        final int action = ev.getAction();
+
+        switch (action & MotionEvent.ACTION_MASK) {
+        case MotionEvent.ACTION_DOWN: {
+            mRender.onActionDown(x, y);
+            mActivePointerId = ev.getPointerId(0);
+            ret = true;
+            break;
+        }
+        case MotionEvent.ACTION_MOVE: {
+            if (!mScaleDetector.isInProgress()) {
+                mRender.onActionMove(x, y);
+            }
+            mRender.onActionDown(x, y);
+            ret = true;
+            break;
+        }
+
+        case MotionEvent.ACTION_UP: {
+            mActivePointerId = INVALID_POINTER_ID;
+            break;
+        }
+
+        case MotionEvent.ACTION_CANCEL: {
+            mActivePointerId = INVALID_POINTER_ID;
+            break;
+        }
+
+        case MotionEvent.ACTION_POINTER_UP: {
+            final int pointerIndex = (ev.getAction() & MotionEvent.ACTION_POINTER_INDEX_MASK)
+                    >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
+            final int pointerId = ev.getPointerId(pointerIndex);
+            if (pointerId == mActivePointerId) {
+                // This was our active pointer going up. Choose a new
+                // active pointer and adjust accordingly.
+                final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
+                x = ev.getX(newPointerIndex);
+                y = ev.getY(newPointerIndex);
+                mRender.onActionDown(x, y);
+                mActivePointerId = ev.getPointerId(newPointerIndex);
+            }
+            break;
+        }
+        }
+
+        return ret;
+    }
+
+    private class ScaleListener extends ScaleGestureDetector.SimpleOnScaleGestureListener {
+        @Override
+        public boolean onScale(ScaleGestureDetector detector) {
+            mRender.onActionScale(detector.getScaleFactor());
+            return true;
+        }
+    }
+}
+
+
diff --git a/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/fbotest.rs b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/fbotest.rs
new file mode 100644
index 0000000..31dd3e9
--- /dev/null
+++ b/tests/RenderScriptTests/FBOTest/src/com/android/fbotest/fbotest.rs
@@ -0,0 +1,221 @@
+// Copyright (C) 2011 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#pragma version(1)
+
+#pragma rs java_package_name(com.android.fbotest)
+
+#include "rs_graphics.rsh"
+
+rs_program_vertex gPVBackground;
+rs_program_fragment gPFBackground;
+
+rs_allocation gTGrid;
+
+rs_program_store gPFSBackground;
+
+rs_font gItalic;
+rs_allocation gTextAlloc;
+
+rs_allocation gOffscreen;
+rs_allocation gOffscreenDepth;
+
+typedef struct MeshInfo {
+    rs_mesh mMesh;
+    int mNumIndexSets;
+    float3 bBoxMin;
+    float3 bBoxMax;
+} MeshInfo_t;
+
+MeshInfo_t *gMeshes;
+
+static float3 gLookAt;
+
+static float gRotateX;
+static float gRotateY;
+static float gZoom;
+
+static float gLastX;
+static float gLastY;
+
+void onActionDown(float x, float y) {
+    gLastX = x;
+    gLastY = y;
+}
+
+void onActionScale(float scale) {
+
+    gZoom *= 1.0f / scale;
+    gZoom = max(0.1f, min(gZoom, 500.0f));
+}
+
+void onActionMove(float x, float y) {
+    float dx = gLastX - x;
+    float dy = gLastY - y;
+
+    if (fabs(dy) <= 2.0f) {
+        dy = 0.0f;
+    }
+    if (fabs(dx) <= 2.0f) {
+        dx = 0.0f;
+    }
+
+    gRotateY -= dx;
+    if (gRotateY > 360) {
+        gRotateY -= 360;
+    }
+    if (gRotateY < 0) {
+        gRotateY += 360;
+    }
+
+    gRotateX -= dy;
+    gRotateX = min(gRotateX, 80.0f);
+    gRotateX = max(gRotateX, -80.0f);
+
+    gLastX = x;
+    gLastY = y;
+}
+
+void init() {
+    gRotateX = 0.0f;
+    gRotateY = 0.0f;
+    gZoom = 50.0f;
+    gLookAt = 0.0f;
+}
+
+void updateMeshInfo() {
+    rs_allocation allMeshes = rsGetAllocation(gMeshes);
+    int size = rsAllocationGetDimX(allMeshes);
+    gLookAt = 0.0f;
+    float minX, minY, minZ, maxX, maxY, maxZ;
+    for (int i = 0; i < size; i++) {
+        MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
+        rsgMeshComputeBoundingBox(info->mMesh,
+                                  &minX, &minY, &minZ,
+                                  &maxX, &maxY, &maxZ);
+        info->bBoxMin = (minX, minY, minZ);
+        info->bBoxMax = (maxX, maxY, maxZ);
+        gLookAt += (info->bBoxMin + info->bBoxMax)*0.5f;
+    }
+    gLookAt = gLookAt / (float)size;
+}
+
+static void renderAllMeshes() {
+    rs_allocation allMeshes = rsGetAllocation(gMeshes);
+    int size = rsAllocationGetDimX(allMeshes);
+    gLookAt = 0.0f;
+    float minX, minY, minZ, maxX, maxY, maxZ;
+    for (int i = 0; i < size; i++) {
+        MeshInfo_t *info = (MeshInfo_t*)rsGetElementAt(allMeshes, i);
+        rsgDrawMesh(info->mMesh);
+    }
+}
+
+static void drawDescription() {
+    uint width = rsgGetWidth();
+    uint height = rsgGetHeight();
+    int left = 0, right = 0, top = 0, bottom = 0;
+
+    rsgBindFont(gItalic);
+
+    rsgMeasureText(gTextAlloc, &left, &right, &top, &bottom);
+    rsgDrawText(gTextAlloc, 2 -left, height - 2 + bottom);
+}
+
+static void renderOffscreen(bool useDepth) {
+
+    rsgBindColorTarget(gOffscreen, 0);
+    if (useDepth) {
+        rsgBindDepthTarget(gOffscreenDepth);
+        rsgClearDepth(1.0f);
+    } else {
+        rsgClearDepthTarget();
+    }
+    rsgClearColor(0.8f, 0.8f, 0.8f, 1.0f);
+
+    rsgBindProgramVertex(gPVBackground);
+    rs_matrix4x4 proj;
+    float aspect = (float)rsAllocationGetDimX(gOffscreen) / (float)rsAllocationGetDimY(gOffscreen);
+    rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 100.0f);
+    rsgProgramVertexLoadProjectionMatrix(&proj);
+
+    rsgBindProgramFragment(gPFBackground);
+    rsgBindProgramStore(gPFSBackground);
+    rsgBindTexture(gPFBackground, 0, gTGrid);
+
+    rs_matrix4x4 matrix;
+    rsMatrixLoadIdentity(&matrix);
+    // Position our models on the screen
+    rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
+    rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
+    rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
+    rsgProgramVertexLoadModelMatrix(&matrix);
+
+    renderAllMeshes();
+
+    // Render into the frambuffer
+    rsgClearAllRenderTargets();
+}
+
+static void drawOffscreenResult(int posX, int posY) {
+    // display the result
+    rs_matrix4x4 proj, matrix;
+    rsMatrixLoadOrtho(&proj, 0, rsgGetWidth(), rsgGetHeight(), 0, -500, 500);
+    rsgProgramVertexLoadProjectionMatrix(&proj);
+    rsMatrixLoadIdentity(&matrix);
+    rsgProgramVertexLoadModelMatrix(&matrix);
+    rsgBindTexture(gPFBackground, 0, gOffscreen);
+    float startX = posX, startY = posY;
+    float width = 256, height = 256;
+    rsgDrawQuadTexCoords(startX, startY, 0, 0, 1,
+                         startX, startY + height, 0, 0, 0,
+                         startX + width, startY + height, 0, 1, 0,
+                         startX + width, startY, 0, 1, 1);
+}
+
+int root(int launchID) {
+
+    rsgClearColor(1.0f, 1.0f, 1.0f, 1.0f);
+    rsgClearDepth(1.0f);
+
+    renderOffscreen(true);
+    drawOffscreenResult(0, 0);
+
+    renderOffscreen(false);
+    drawOffscreenResult(0, 256);
+
+    rsgBindProgramVertex(gPVBackground);
+    rs_matrix4x4 proj;
+    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
+    rsMatrixLoadPerspective(&proj, 30.0f, aspect, 1.0f, 100.0f);
+    rsgProgramVertexLoadProjectionMatrix(&proj);
+
+    rsgBindProgramFragment(gPFBackground);
+    rsgBindProgramStore(gPFSBackground);
+    rsgBindTexture(gPFBackground, 0, gTGrid);
+
+    rs_matrix4x4 matrix;
+    rsMatrixLoadIdentity(&matrix);
+    // Position our models on the screen
+    rsMatrixTranslate(&matrix, gLookAt.x, gLookAt.y, gLookAt.z - gZoom);
+    rsMatrixRotate(&matrix, gRotateX, 1.0f, 0.0f, 0.0f);
+    rsMatrixRotate(&matrix, gRotateY, 0.0f, 1.0f, 0.0f);
+    rsgProgramVertexLoadModelMatrix(&matrix);
+
+    renderAllMeshes();
+
+    drawDescription();
+
+    return 0;
+}
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java
index 9757ec6..5443ef8 100644
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java
+++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/RsBenchRS.java
@@ -22,6 +22,8 @@
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
 import android.renderscript.*;
+import android.renderscript.Element.DataKind;
+import android.renderscript.Element.DataType;
 import android.renderscript.Allocation.MipmapControl;
 import android.renderscript.Program.TextureType;
 import android.renderscript.ProgramStore.DepthFunc;
@@ -399,6 +401,23 @@
         initProgramRaster();
         initCustomShaders();
 
+        Type.Builder b = new Type.Builder(mRS, Element.RGBA_8888(mRS));
+        b.setX(1280).setY(720);
+        Allocation offscreen = Allocation.createTyped(mRS,
+                                                      b.create(),
+                                                      Allocation.USAGE_GRAPHICS_TEXTURE |
+                                                      Allocation.USAGE_GRAPHICS_RENDER_TARGET);
+        mScript.set_gRenderBufferColor(offscreen);
+
+        b = new Type.Builder(mRS,
+                             Element.createPixel(mRS, DataType.UNSIGNED_16,
+                             DataKind.PIXEL_DEPTH));
+        b.setX(1280).setY(720);
+        offscreen = Allocation.createTyped(mRS,
+                                           b.create(),
+                                           Allocation.USAGE_GRAPHICS_RENDER_TARGET);
+        mScript.set_gRenderBufferDepth(offscreen);
+
         mRS.bindRootScript(mScript);
     }
 }
diff --git a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
index 3c92725..fd0f16f 100644
--- a/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
+++ b/tests/RenderScriptTests/PerfTest/src/com/android/perftest/rsbench.rs
@@ -76,11 +76,17 @@
 rs_program_fragment gProgFragmentPixelLight;
 rs_program_fragment gProgFragmentMultitex;
 
+rs_allocation gRenderBufferColor;
+rs_allocation gRenderBufferDepth;
+
 float gDt = 0;
 
 void init() {
 }
 
+static int gRenderSurfaceW;
+static int gRenderSurfaceH;
+
 static const char *sampleText = "This is a sample of small text for performace";
 // Offsets for multiple layer of text
 static int textOffsets[] = { 0,  0, -5, -5, 5,  5, -8, -8, 8,  8};
@@ -91,6 +97,11 @@
                              0.5f, 0.6f, 0.7f, 1.0f,
 };
 
+static void setupOffscreenTarget() {
+    rsgBindColorTarget(gRenderBufferColor, 0);
+    rsgBindDepthTarget(gRenderBufferDepth);
+}
+
 static void displayFontSamples(int fillNum) {
 
     rs_font fonts[5];
@@ -100,8 +111,8 @@
     rsSetObject(&fonts[3], gFontSerifBoldItalic);
     rsSetObject(&fonts[4], gFontSans);
 
-    uint width = rsgGetWidth();
-    uint height = rsgGetHeight();
+    uint width = gRenderSurfaceW;
+    uint height = gRenderSurfaceH;
     int left = 0, right = 0, top = 0, bottom = 0;
     rsgMeasureText(sampleText, &left, &right, &top, &bottom);
 
@@ -136,7 +147,7 @@
     rsgBindProgramVertex(gProgVertex);
     // Setup the projection matrix
     rs_matrix4x4 proj;
-    rsMatrixLoadOrtho(&proj, 0, rsgGetWidth(), rsgGetHeight(), 0, -500, 500);
+    rsMatrixLoadOrtho(&proj, 0, gRenderSurfaceW, gRenderSurfaceH, 0, -500, 500);
     rsgProgramVertexLoadProjectionMatrix(&proj);
 }
 
@@ -158,7 +169,7 @@
 
     for (int i = 0; i < quadCount; i ++) {
         float startX = 10 * i, startY = 10 * i;
-        float width = rsgGetWidth() - startX, height = rsgGetHeight() - startY;
+        float width = gRenderSurfaceW - startX, height = gRenderSurfaceH - startY;
         rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
                              startX, startY + height, 0, 0, 1,
                              startX + width, startY + height, 0, 1, 1,
@@ -216,7 +227,7 @@
 
     bindProgramVertexOrtho();
     rs_matrix4x4 matrix;
-    rsMatrixLoadTranslate(&matrix, rsgGetWidth()/2, rsgGetHeight()/2, 0);
+    rsMatrixLoadTranslate(&matrix, gRenderSurfaceW/2, gRenderSurfaceH/2, 0);
     rsgProgramVertexLoadModelMatrix(&matrix);
 
     // Fragment shader with texture
@@ -344,7 +355,7 @@
     rsgBindProgramRaster(gCullBack);
     // Setup the projection matrix with 30 degree field of view
     rs_matrix4x4 proj;
-    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
+    float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH;
     rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f);
     rsgProgramVertexLoadProjectionMatrix(&proj);
 
@@ -445,7 +456,7 @@
     }
 
     // Setup the projection matrix
-    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
+    float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH;
     rsMatrixLoadPerspective(&gVSConstants->proj, 30.0f, aspect, 0.1f, 100.0f);
     setupCustomShaderLights();
 
@@ -476,7 +487,7 @@
     gVSConstPixel->time = rsUptimeMillis()*0.005;
 
     // Setup the projection matrix
-    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
+    float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH;
     rsMatrixLoadPerspective(&gVSConstPixel->proj, 30.0f, aspect, 0.1f, 100.0f);
     setupCustomShaderLights();
 
@@ -520,7 +531,7 @@
 
     for (int i = 0; i < quadCount; i ++) {
         float startX = 10 * i, startY = 10 * i;
-        float width = rsgGetWidth() - startX, height = rsgGetHeight() - startY;
+        float width = gRenderSurfaceW - startX, height = gRenderSurfaceH - startY;
         rsgDrawQuadTexCoords(startX, startY, 0, 0, 0,
                              startX, startY + height, 0, 0, 1,
                              startX + width, startY + height, 0, 1, 1,
@@ -535,7 +546,7 @@
     gAnisoTime += gDt;
 
     rsgBindProgramVertex(gProgVertex);
-    float aspect = (float)rsgGetWidth() / (float)rsgGetHeight();
+    float aspect = (float)gRenderSurfaceW / (float)gRenderSurfaceH;
     rs_matrix4x4 proj;
     rsMatrixLoadPerspective(&proj, 30.0f, aspect, 0.1f, 100.0f);
     rsgProgramVertexLoadProjectionMatrix(&proj);
@@ -592,10 +603,6 @@
 
     static int countdown = 5;
 
-    if (countdown == 0) {
-        gDt = 0;
-        countdown --;
-    }
     // Perform all the uploads so we only measure rendered time
     if(countdown > 1) {
         displayFontSamples(5);
@@ -612,19 +619,13 @@
         countdown --;
         rsgClearColor(0.2f, 0.2f, 0.2f, 0.0f);
 
-        // Now use text metrics to center the text
-        uint width = rsgGetWidth();
-        uint height = rsgGetHeight();
-        int left = 0, right = 0, top = 0, bottom = 0;
-
         rsgFontColor(0.9f, 0.9f, 0.95f, 1.0f);
         rsgBindFont(gFontSerifBoldItalic);
-
-        const char* text = "Initializing";
-        rsgMeasureText(text, &left, &right, &top, &bottom);
-        int centeredPosX = width / 2 - (right - left) / 2;
-        int centeredPosY = height / 2 - (top - bottom) / 2;
-        rsgDrawText(text, centeredPosX, centeredPosY);
+        if (countdown == 1) {
+            rsgDrawText("Rendering", 50, 50);
+        } else {
+            rsgDrawText("Initializing", 50, 50);
+        }
 
         return false;
     }
@@ -632,70 +633,40 @@
     return true;
 }
 
-static int frameCount = 0;
-static int totalFramesRendered = 0;
 static int benchMode = 0;
 
-#define testTime 5.0f
-static float curTestTime = testTime;
-
 static const char *testNames[] = {
-    "Finished text fill 1",
-    "Finished text fill 2",
-    "Finished text fill 3",
-    "Finished text fill 4",
-    "Finished text fill 5",
-    "Finished 25.6k geo flat color",
-    "Finished 51.2k geo flat color",
-    "Finished 204.8k geo raster load flat color",
-    "Finished 25.6k geo texture",
-    "Finished 51.2k geo texture",
-    "Finished 204.8k geo raster load texture",
-    "Finished full screen mesh 10 by 10",
-    "Finished full screen mesh 100 by 100",
-    "Finished full screen mesh W / 4 by H / 4",
-    "Finished 25.6k geo heavy vertex",
-    "Finished 51.2k geo heavy vertex",
-    "Finished 204.8k geo raster load heavy vertex",
-    "Finished singletexture 5x fill",
-    "Finished 3tex multitexture 5x fill",
-    "Finished blend singletexture 5x fill",
-    "Finished blend 3tex multitexture 5x fill",
-    "Finished 25.6k geo heavy fragment",
-    "Finished 51.2k geo heavy fragment",
-    "Finished 204.8k geo raster load heavy fragment",
-    "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",
+    "Finished text fill 1,",
+    "Finished text fill 2,",
+    "Finished text fill 3,",
+    "Finished text fill 4,",
+    "Finished text fill 5,",
+    "Finished 25.6k geo flat color,",
+    "Finished 51.2k geo flat color,",
+    "Finished 204.8k geo raster load flat color,",
+    "Finished 25.6k geo texture,",
+    "Finished 51.2k geo texture,",
+    "Finished 204.8k geo raster load texture,",
+    "Finished full screen mesh 10 by 10,",
+    "Finished full screen mesh 100 by 100,",
+    "Finished full screen mesh W / 4 by H / 4,",
+    "Finished 25.6k geo heavy vertex,",
+    "Finished 51.2k geo heavy vertex,",
+    "Finished 204.8k geo raster load heavy vertex,",
+    "Finished singletexture 5x fill,",
+    "Finished 3tex multitexture 5x fill,",
+    "Finished blend singletexture 5x fill,",
+    "Finished blend 3tex multitexture 5x fill,",
+    "Finished 25.6k geo heavy fragment,",
+    "Finished 51.2k geo heavy fragment,",
+    "Finished 204.8k geo raster load heavy fragment,",
+    "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) {
-
-    gDt = rsGetDt();
-
-    rsgClearColor(0.2f, 0.2f, 0.2f, 0.0f);
-    rsgClearDepth(1.0f);
-
-    if(!checkInit()) {
-        return 1;
-    }
-
-    curTestTime -= gDt;
-    if(curTestTime < 0.0f) {
-        float fps = (float)(frameCount) / (testTime - curTestTime);
-        rsDebug(testNames[benchMode], fps);
-        benchMode ++;
-        curTestTime = testTime;
-        totalFramesRendered += frameCount;
-        frameCount = 0;
-        gTorusRotation = 0;
-
-        if (benchMode > gMaxModes) {
-            benchMode = 0;
-        }
-    }
-
-    switch (benchMode) {
+static void runTest(int index) {
+    switch (index) {
     case 0:
         displayFontSamples(1);
         break;
@@ -777,10 +748,87 @@
     case 26:
         displayPixelLightSamples(8, true);
         break;
+    }
+}
 
+static void drawOffscreenResult(int posX, int posY, int width, int height) {
+    bindProgramVertexOrtho();
+
+    rs_matrix4x4 matrix;
+    rsMatrixLoadIdentity(&matrix);
+    rsgProgramVertexLoadModelMatrix(&matrix);
+
+    rsgBindProgramFragment(gProgFragmentTexture);
+
+    rsgBindSampler(gProgFragmentTexture, 0, gLinearClamp);
+    rsgBindTexture(gProgFragmentTexture, 0, gRenderBufferColor);
+
+    float startX = posX, startY = posY;
+    rsgDrawQuadTexCoords(startX, startY, 0, 0, 1,
+                         startX, startY + height, 0, 0, 0,
+                         startX + width, startY + height, 0, 1, 0,
+                         startX + width, startY, 0, 1, 1);
+}
+
+int root(int launchID) {
+
+    gRenderSurfaceW = rsgGetWidth();
+    gRenderSurfaceH = rsgGetHeight();
+    rsgClearColor(0.2f, 0.2f, 0.2f, 1.0f);
+    rsgClearDepth(1.0f);
+    if(!checkInit()) {
+        return 1;
     }
 
-    frameCount ++;
+    rsgFinish();
+    int64_t start = rsUptimeMillis();
+    rsGetDt();
+
+    int drawPos = 0;
+    int frameCount = 100;
+    for(int i = 0; i < frameCount; i ++) {
+        setupOffscreenTarget();
+        gRenderSurfaceW = rsAllocationGetDimX(gRenderBufferColor);
+        gRenderSurfaceH = rsAllocationGetDimY(gRenderBufferColor);
+        rsgClearColor(0.1f, 0.1f, 0.1f, 1.0f);
+        rsgClearDepth(1.0f);
+
+        runTest(benchMode);
+        rsgClearAllRenderTargets();
+        gRenderSurfaceW = rsgGetWidth();
+        gRenderSurfaceH = rsgGetHeight();
+        int size = 8;
+        drawOffscreenResult((drawPos+=size)%gRenderSurfaceW, (gRenderSurfaceH * 3) / 4, size, size);
+        gDt = rsGetDt();
+    }
+
+    rsgFinish();
+
+    int64_t end = rsUptimeMillis();
+    float fps = (float)(frameCount) / ((float)(end - start)*0.001f);
+    rsDebug(testNames[benchMode], fps);
+
+    drawOffscreenResult(0, 0,
+                        gRenderSurfaceW / 2,
+                        gRenderSurfaceH / 2);
+
+    const char* text = testNames[benchMode];
+    int left = 0, right = 0, top = 0, bottom = 0;
+    uint width = rsgGetWidth();
+    uint height = rsgGetHeight();
+    rsgFontColor(0.9f, 0.9f, 0.95f, 1.0f);
+    rsgBindFont(gFontSerifBoldItalic);
+    rsgMeasureText(text, &left, &right, &top, &bottom);
+    rsgFontColor(1.0f, 1.0f, 1.0f, 1.0f);
+    rsgDrawText(text, 2 -left, height - 2 + bottom);
+
+    benchMode ++;
+
+    gTorusRotation = 0;
+
+    if (benchMode > gMaxModes) {
+        benchMode = 0;
+    }
 
     return 1;
 }
diff --git a/voip/jni/rtp/AudioGroup.cpp b/voip/jni/rtp/AudioGroup.cpp
index c031eee..41fedce 100644
--- a/voip/jni/rtp/AudioGroup.cpp
+++ b/voip/jni/rtp/AudioGroup.cpp
@@ -30,6 +30,7 @@
 
 #define LOG_TAG "AudioGroup"
 #include <cutils/atomic.h>
+#include <cutils/properties.h>
 #include <utils/Log.h>
 #include <utils/Errors.h>
 #include <utils/RefBase.h>
@@ -619,6 +620,14 @@
     if (mode < 0 || mode > LAST_MODE) {
         return false;
     }
+    //FIXME: temporary code to overcome echo and mic gain issues on herring board.
+    // Must be modified/removed when proper support for voice processing query and control
+    // is included in audio framework
+    char value[PROPERTY_VALUE_MAX];
+    property_get("ro.product.board", value, "");
+    if (mode == NORMAL && !strcmp(value, "herring")) {
+        mode = ECHO_SUPPRESSION;
+    }
     if (mode == ECHO_SUPPRESSION && AudioSystem::getParameters(
         0, String8("ec_supported")) == "ec_supported=yes") {
         mode = NORMAL;