Merge "Squashed commit of the following:"
diff --git a/core/java/android/database/CursorWindow.java b/core/java/android/database/CursorWindow.java
index a026eca..9a8f2d2 100644
--- a/core/java/android/database/CursorWindow.java
+++ b/core/java/android/database/CursorWindow.java
@@ -16,6 +16,7 @@
 
 package android.database;
 
+import android.content.res.Resources;
 import android.database.sqlite.SQLiteClosable;
 import android.os.IBinder;
 import android.os.Parcel;
@@ -25,6 +26,13 @@
  * A buffer containing multiple cursor rows.
  */
 public class CursorWindow extends SQLiteClosable implements Parcelable {
+    /** The cursor window size. resource xml file specifies the value in kB.
+     * convert it to bytes here by multiplying with 1024.
+     */
+    private static final int sCursorWindowSize =
+        Resources.getSystem().getInteger(
+                com.android.internal.R.integer.config_cursorWindowSize) * 1024;
+
     /** The pointer to the native window class */
     @SuppressWarnings("unused")
     private int nWindow;
@@ -38,7 +46,7 @@
      */
     public CursorWindow(boolean localWindow) {
         mStartPos = 0;
-        native_init(localWindow);
+        native_init(sCursorWindowSize, localWindow);
     }
 
     /**
@@ -574,7 +582,7 @@
     private native IBinder native_getBinder();
 
     /** Does the native side initialization for an empty window */
-    private native void native_init(boolean localOnly);
+    private native void native_init(int cursorWindowSize, boolean localOnly);
 
     /** Does the native side initialization with an existing binder from another process */
     private native void native_init(IBinder nativeBinder);
diff --git a/core/java/android/database/sqlite/SQLiteDatabase.java b/core/java/android/database/sqlite/SQLiteDatabase.java
index 184988b..6f59dc9 100644
--- a/core/java/android/database/sqlite/SQLiteDatabase.java
+++ b/core/java/android/database/sqlite/SQLiteDatabase.java
@@ -18,6 +18,7 @@
 
 import android.app.AppGlobals;
 import android.content.ContentValues;
+import android.content.res.Resources;
 import android.database.Cursor;
 import android.database.DatabaseErrorHandler;
 import android.database.DatabaseUtils;
@@ -1963,6 +1964,15 @@
         // If the caller sets errorHandler = null, then use default errorhandler.
         mErrorHandler = (errorHandler == null) ? new DefaultDatabaseErrorHandler() : errorHandler;
         mConnectionNum = connectionNum;
+        /* sqlite soft heap limit http://www.sqlite.org/c3ref/soft_heap_limit64.html
+         * set it to 4 times the default cursor window size.
+         * TODO what is an appropriate value, considring the WAL feature which could burn
+         * a lot of memory with many connections to the database. needs testing to figure out
+         * optimal value for this.
+         */
+        int limit = Resources.getSystem().getInteger(
+                com.android.internal.R.integer.config_cursorWindowSize) * 1024 * 4;
+        native_setSqliteSoftHeapLimit(limit);
     }
 
     /**
@@ -2670,4 +2680,10 @@
      * @param statementId statement to be finzlied by sqlite
      */
     private final native void native_finalize(int statementId);
+
+    /**
+     * set sqlite soft heap limit
+     * http://www.sqlite.org/c3ref/soft_heap_limit64.html
+     */
+    private native void native_setSqliteSoftHeapLimit(int softHeapLimit);
 }
diff --git a/core/jni/android_database_CursorWindow.cpp b/core/jni/android_database_CursorWindow.cpp
index fad9539..c4cd2a6 100644
--- a/core/jni/android_database_CursorWindow.cpp
+++ b/core/jni/android_database_CursorWindow.cpp
@@ -50,13 +50,14 @@
     return GET_WINDOW(env, javaWindow);
 }
 
-static void native_init_empty(JNIEnv * env, jobject object, jboolean localOnly)
+static void native_init_empty(JNIEnv * env, jobject object, jint cursorWindowSize,
+        jboolean localOnly)
 {
     uint8_t * data;
     size_t size;
     CursorWindow * window;
 
-    window = new CursorWindow(MAX_WINDOW_SIZE);
+    window = new CursorWindow(cursorWindowSize);
     if (!window) {
         jniThrowException(env, "java/lang/RuntimeException", "No memory for native window object");
         return;
@@ -614,7 +615,7 @@
 static JNINativeMethod sMethods[] =
 {
      /* name, signature, funcPtr */
-    {"native_init", "(Z)V", (void *)native_init_empty},
+    {"native_init", "(IZ)V", (void *)native_init_empty},
     {"native_init", "(Landroid/os/IBinder;)V", (void *)native_init_memory},
     {"native_getBinder", "()Landroid/os/IBinder;", (void *)native_getBinder},
     {"native_clear", "()V", (void *)native_clear},
diff --git a/core/jni/android_database_SQLiteDatabase.cpp b/core/jni/android_database_SQLiteDatabase.cpp
index 7aeed98..a5878a9 100644
--- a/core/jni/android_database_SQLiteDatabase.cpp
+++ b/core/jni/android_database_SQLiteDatabase.cpp
@@ -46,7 +46,6 @@
 
 #define UTF16_STORAGE 0
 #define INVALID_VERSION -1
-#define SQLITE_SOFT_HEAP_LIMIT (4 * 1024 * 1024)
 #define ANDROID_TABLE "android_metadata"
 /* uncomment the next line to force-enable logging of all statements */
 // #define DB_LOG_STATEMENTS
@@ -66,6 +65,7 @@
 static jfieldID offset_db_handle;
 static jmethodID method_custom_function_callback;
 static jclass string_class = NULL;
+static jint sSqliteSoftHeapLimit = 0;
 
 static char *createStr(const char *path, short extra) {
     int len = strlen(path) + extra;
@@ -129,7 +129,7 @@
     // The soft heap limit prevents the page cache allocations from growing
     // beyond the given limit, no matter what the max page cache sizes are
     // set to. The limit does not, as of 3.5.0, affect any other allocations.
-    sqlite3_soft_heap_limit(SQLITE_SOFT_HEAP_LIMIT);
+    sqlite3_soft_heap_limit(sSqliteSoftHeapLimit);
 
     // Set the default busy handler to retry for 1000ms and then return SQLITE_BUSY
     err = sqlite3_busy_timeout(handle, 1000 /* ms */);
@@ -379,10 +379,14 @@
     if (meta != NULL) sqlite3_free_table(meta);
 }
 
+static void native_setSqliteSoftHeapLimit(JNIEnv* env, jobject clazz, jint limit) {
+    sSqliteSoftHeapLimit = limit;
+}
+
 static jint native_releaseMemory(JNIEnv *env, jobject clazz)
 {
     // Attempt to release as much memory from the
-    return sqlite3_release_memory(SQLITE_SOFT_HEAP_LIMIT);
+    return sqlite3_release_memory(sSqliteSoftHeapLimit);
 }
 
 static void native_finalize(JNIEnv* env, jobject object, jint statementId)
@@ -466,6 +470,7 @@
     {"enableSqlProfiling", "(Ljava/lang/String;S)V", (void *)enableSqlProfiling},
     {"native_setLocale", "(Ljava/lang/String;I)V", (void *)native_setLocale},
     {"native_getDbLookaside", "()I", (void *)native_getDbLookaside},
+    {"native_setSqliteSoftHeapLimit", "(I)V", (void *)native_setSqliteSoftHeapLimit},
     {"releaseMemory", "()I", (void *)native_releaseMemory},
     {"native_finalize", "(I)V", (void *)native_finalize},
     {"native_addCustomFunction",
diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml
index 0d2d42f..0d840c2 100644
--- a/core/res/res/values/config.xml
+++ b/core/res/res/values/config.xml
@@ -515,4 +515,7 @@
          Build.MODEL. The format string shall not be escaped. -->
     <string name="config_useragentprofile_url"></string>
 
+    <!-- When a database query is executed, the results retuned are paginated
+         in pages of size (in KB) indicated by this value -->
+    <integer name="config_cursorWindowSize">2048</integer>
 </resources>
diff --git a/include/binder/CursorWindow.h b/include/binder/CursorWindow.h
index 4fbff2a..f0b2909 100644
--- a/include/binder/CursorWindow.h
+++ b/include/binder/CursorWindow.h
@@ -25,7 +25,6 @@
 #include <utils/RefBase.h>
 
 #define DEFAULT_WINDOW_SIZE 4096
-#define MAX_WINDOW_SIZE (1024 * 1024)
 #define WINDOW_ALLOCATION_SIZE 4096
 
 #define ROW_SLOT_CHUNK_NUM_ROWS 16
diff --git a/media/libstagefright/CameraSource.cpp b/media/libstagefright/CameraSource.cpp
index 2f3353b..b1c6b18 100644
--- a/media/libstagefright/CameraSource.cpp
+++ b/media/libstagefright/CameraSource.cpp
@@ -573,7 +573,7 @@
 }
 
 status_t CameraSource::stop() {
-    LOGV("stop");
+    LOGD("stop: E");
     Mutex::Autolock autoLock(mLock);
     mStarted = false;
     mFrameAvailableCondition.signal();
@@ -581,9 +581,11 @@
     int64_t token = IPCThreadState::self()->clearCallingIdentity();
     releaseQueuedFrames();
     while (!mFramesBeingEncoded.empty()) {
-        LOGI("Waiting for outstanding frames being encoded: %d",
+        if (NO_ERROR !=
+            mFrameCompleteCondition.waitRelative(mLock, 3000000000LL)) {
+            LOGW("Timed out waiting for outstanding frames being encoded: %d",
                 mFramesBeingEncoded.size());
-        mFrameCompleteCondition.wait(mLock);
+        }
     }
     stopCameraRecording();
     releaseCamera();
@@ -601,6 +603,7 @@
     }
 
     CHECK_EQ(mNumFramesReceived, mNumFramesEncoded + mNumFramesDropped);
+    LOGD("stop: X");
     return OK;
 }
 
@@ -666,7 +669,11 @@
     {
         Mutex::Autolock autoLock(mLock);
         while (mStarted && mFramesReceived.empty()) {
-            mFrameAvailableCondition.wait(mLock);
+            if (NO_ERROR !=
+                mFrameAvailableCondition.waitRelative(mLock, 3000000000LL)) {
+                LOGW("Timed out waiting for incoming camera video frames: %lld us",
+                    mLastFrameTimestampUs);
+            }
         }
         if (!mStarted) {
             return OK;
diff --git a/media/libstagefright/OMXCodec.cpp b/media/libstagefright/OMXCodec.cpp
index 352f9fb..f63774a 100644
--- a/media/libstagefright/OMXCodec.cpp
+++ b/media/libstagefright/OMXCodec.cpp
@@ -3361,7 +3361,15 @@
     }
 
     while (mState != ERROR && !mNoMoreOutputData && mFilledBuffers.empty()) {
-        mBufferFilled.wait(mLock);
+        if (mIsEncoder) {
+            if (NO_ERROR != mBufferFilled.waitRelative(mLock, 3000000000LL)) {
+                LOGW("Timed out waiting for buffers from video encoder: %d/%d",
+                    countBuffersWeOwn(mPortBuffers[kPortIndexInput]),
+                    countBuffersWeOwn(mPortBuffers[kPortIndexOutput]));
+            }
+        } else {
+            mBufferFilled.wait(mLock);
+        }
     }
 
     if (mState == ERROR) {
diff --git a/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java b/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java
index b46d95c..60ad645 100644
--- a/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/app/Fragment_Delegate.java
@@ -16,7 +16,7 @@
 
 package android.app;
 
-import com.android.layoutlib.api.IProjectCallback;
+import com.android.ide.common.rendering.api.IProjectCallback;
 
 import android.content.Context;
 import android.os.Bundle;
diff --git a/tools/layoutlib/bridge/src/android/graphics/BitmapFactory.java b/tools/layoutlib/bridge/src/android/graphics/BitmapFactory.java
index 626f878..c57aef6 100644
--- a/tools/layoutlib/bridge/src/android/graphics/BitmapFactory.java
+++ b/tools/layoutlib/bridge/src/android/graphics/BitmapFactory.java
@@ -16,7 +16,7 @@
 
 package android.graphics;
 
-import com.android.layoutlib.api.ResourceDensity;
+import com.android.ide.common.rendering.api.ResourceDensity;
 import com.android.layoutlib.bridge.Bridge;
 
 import android.content.res.AssetManager;
diff --git a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
index fe201c1..d69abc9 100644
--- a/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
+++ b/tools/layoutlib/bridge/src/android/graphics/Bitmap_Delegate.java
@@ -16,7 +16,7 @@
 
 package android.graphics;
 
-import com.android.layoutlib.api.ResourceDensity;
+import com.android.ide.common.rendering.api.ResourceDensity;
 import com.android.layoutlib.bridge.impl.DelegateManager;
 
 import android.graphics.Bitmap.Config;
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
index c30e8e4..5f40854 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/Bridge.java
@@ -16,15 +16,17 @@
 
 package com.android.layoutlib.bridge;
 
-import com.android.layoutlib.api.Capability;
-import com.android.layoutlib.api.LayoutBridge;
-import com.android.layoutlib.api.LayoutLog;
-import com.android.layoutlib.api.SceneParams;
-import com.android.layoutlib.api.SceneResult;
-import com.android.layoutlib.api.SceneResult.SceneStatus;
+import static com.android.ide.common.rendering.api.Result.Status.ERROR_UNKNOWN;
+import static com.android.ide.common.rendering.api.Result.Status.SUCCESS;
+
+import com.android.ide.common.rendering.api.Capability;
+import com.android.ide.common.rendering.api.LayoutLog;
+import com.android.ide.common.rendering.api.Params;
+import com.android.ide.common.rendering.api.RenderSession;
+import com.android.ide.common.rendering.api.Result;
 import com.android.layoutlib.bridge.android.BridgeAssetManager;
 import com.android.layoutlib.bridge.impl.FontLoader;
-import com.android.layoutlib.bridge.impl.LayoutSceneImpl;
+import com.android.layoutlib.bridge.impl.RenderSessionImpl;
 import com.android.ninepatch.NinePatchChunk;
 import com.android.tools.layoutlib.create.MethodAdapter;
 import com.android.tools.layoutlib.create.OverrideMethod;
@@ -33,6 +35,7 @@
 import android.graphics.Typeface_Delegate;
 import android.os.Looper;
 
+import java.io.File;
 import java.lang.ref.SoftReference;
 import java.lang.reflect.Field;
 import java.lang.reflect.Modifier;
@@ -47,7 +50,7 @@
  * <p/>To use this bridge, simply instantiate an object of type {@link Bridge} and call
  * {@link #createScene(SceneParams)}
  */
-public final class Bridge extends LayoutBridge {
+public final class Bridge extends com.android.ide.common.rendering.api.Bridge {
 
     public static class StaticMethodNotImplementedException extends RuntimeException {
         private static final long serialVersionUID = 1L;
@@ -169,7 +172,7 @@
 
     @Override
     public int getApiLevel() {
-        return LayoutBridge.API_CURRENT;
+        return com.android.ide.common.rendering.api.Bridge.API_CURRENT;
     }
 
     @Override
@@ -179,10 +182,10 @@
 
     /*
      * (non-Javadoc)
-     * @see com.android.layoutlib.api.ILayoutLibBridge#init(java.lang.String, java.util.Map)
+     * @see com.android.layoutlib.api.ILayoutLibBridge#init(java.io.File, java.util.Map)
      */
     @Override
-    public boolean init(String fontOsLocation, Map<String, Map<String, Integer>> enumValueMap) {
+    public boolean init(File fontLocation, Map<String, Map<String, Integer>> enumValueMap) {
         sEnumValueMap = enumValueMap;
 
         // don't use EnumSet.allOf(), because the bridge doesn't come with its specific version
@@ -229,7 +232,7 @@
         }
 
         // load the fonts.
-        FontLoader fontLoader = FontLoader.create(fontOsLocation);
+        FontLoader fontLoader = FontLoader.create(fontLocation.getAbsolutePath());
         if (fontLoader != null) {
             Typeface_Delegate.init(fontLoader);
         } else {
@@ -299,10 +302,10 @@
      * @since 5
      */
     @Override
-    public BridgeLayoutScene createScene(SceneParams params) {
+    public RenderSession createSession(Params params) {
         try {
-            SceneResult lastResult = SceneStatus.SUCCESS.createResult();
-            LayoutSceneImpl scene = new LayoutSceneImpl(params);
+            Result lastResult = SUCCESS.createResult();
+            RenderSessionImpl scene = new RenderSessionImpl(params);
             try {
                 prepareThread();
                 lastResult = scene.init(params.getTimeout());
@@ -317,15 +320,15 @@
                 cleanupThread();
             }
 
-            return new BridgeLayoutScene(scene, lastResult);
+            return new BridgeRenderSession(scene, lastResult);
         } catch (Throwable t) {
             // get the real cause of the exception.
             Throwable t2 = t;
             while (t2.getCause() != null) {
                 t2 = t.getCause();
             }
-            return new BridgeLayoutScene(null,
-                    SceneStatus.ERROR_UNKNOWN.createResult(t2.getMessage(), t2));
+            return new BridgeRenderSession(null,
+                    ERROR_UNKNOWN.createResult(t2.getMessage(), t2));
         }
     }
 
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeLayoutScene.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeLayoutScene.java
deleted file mode 100644
index f43559f..0000000
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeLayoutScene.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * Copyright (C) 2010 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.layoutlib.bridge;
-
-import com.android.layoutlib.api.IXmlPullParser;
-import com.android.layoutlib.api.LayoutScene;
-import com.android.layoutlib.api.SceneParams;
-import com.android.layoutlib.api.SceneResult;
-import com.android.layoutlib.api.ViewInfo;
-import com.android.layoutlib.bridge.impl.LayoutSceneImpl;
-
-import android.view.View;
-import android.view.ViewGroup;
-
-import java.awt.image.BufferedImage;
-import java.util.Map;
-
-/**
- * An implementation of {@link LayoutScene}.
- *
- * This is a pretty basic class that does almost nothing. All of the work is done in
- * {@link LayoutSceneImpl}.
- *
- */
-public class BridgeLayoutScene extends LayoutScene {
-
-    private final LayoutSceneImpl mScene;
-    private SceneResult mLastResult;
-
-    @Override
-    public SceneResult getResult() {
-        return mLastResult;
-    }
-
-    @Override
-    public BufferedImage getImage() {
-        return mScene.getImage();
-    }
-
-    @Override
-    public ViewInfo getRootView() {
-        return mScene.getViewInfo();
-    }
-
-    @Override
-    public Map<String, String> getDefaultViewPropertyValues(Object viewObject) {
-        return mScene.getDefaultViewPropertyValues(viewObject);
-    }
-
-    @Override
-    public SceneResult render(long timeout) {
-        try {
-            Bridge.prepareThread();
-            mLastResult = mScene.acquire(timeout);
-            if (mLastResult.isSuccess()) {
-                mLastResult = mScene.render();
-            }
-        } finally {
-            mScene.release();
-            Bridge.cleanupThread();
-        }
-
-        return mLastResult;
-    }
-
-    @Override
-    public SceneResult animate(Object targetObject, String animationName,
-            boolean isFrameworkAnimation, IAnimationListener listener) {
-        try {
-            Bridge.prepareThread();
-            mLastResult = mScene.acquire(SceneParams.DEFAULT_TIMEOUT);
-            if (mLastResult.isSuccess()) {
-                mLastResult = mScene.animate(targetObject, animationName, isFrameworkAnimation,
-                        listener);
-            }
-        } finally {
-            mScene.release();
-            Bridge.cleanupThread();
-        }
-
-        return mLastResult;
-    }
-
-    @Override
-    public SceneResult insertChild(Object parentView, IXmlPullParser childXml, int index,
-            IAnimationListener listener) {
-        if (parentView instanceof ViewGroup == false) {
-            throw new IllegalArgumentException("parentView is not a ViewGroup");
-        }
-
-        try {
-            Bridge.prepareThread();
-            mLastResult = mScene.acquire(SceneParams.DEFAULT_TIMEOUT);
-            if (mLastResult.isSuccess()) {
-                mLastResult = mScene.insertChild((ViewGroup) parentView, childXml, index, listener);
-            }
-        } finally {
-            mScene.release();
-            Bridge.cleanupThread();
-        }
-
-        return mLastResult;
-    }
-
-
-    @Override
-    public SceneResult moveChild(Object parentView, Object childView, int index,
-            Map<String, String> layoutParams, IAnimationListener listener) {
-        if (parentView instanceof ViewGroup == false) {
-            throw new IllegalArgumentException("parentView is not a ViewGroup");
-        }
-        if (childView instanceof View == false) {
-            throw new IllegalArgumentException("childView is not a View");
-        }
-
-        try {
-            Bridge.prepareThread();
-            mLastResult = mScene.acquire(SceneParams.DEFAULT_TIMEOUT);
-            if (mLastResult.isSuccess()) {
-                mLastResult = mScene.moveChild((ViewGroup) parentView, (View) childView, index,
-                        layoutParams, listener);
-            }
-        } finally {
-            mScene.release();
-            Bridge.cleanupThread();
-        }
-
-        return mLastResult;
-    }
-
-    @Override
-    public SceneResult removeChild(Object childView, IAnimationListener listener) {
-        if (childView instanceof View == false) {
-            throw new IllegalArgumentException("childView is not a View");
-        }
-
-        try {
-            Bridge.prepareThread();
-            mLastResult = mScene.acquire(SceneParams.DEFAULT_TIMEOUT);
-            if (mLastResult.isSuccess()) {
-                mLastResult = mScene.removeChild((View) childView, listener);
-            }
-        } finally {
-            mScene.release();
-            Bridge.cleanupThread();
-        }
-
-        return mLastResult;
-    }
-
-    @Override
-    public void dispose() {
-    }
-
-    /*package*/ BridgeLayoutScene(LayoutSceneImpl scene, SceneResult lastResult) {
-        mScene = scene;
-        mScene.setScene(this);
-        mLastResult = lastResult;
-    }
-}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java
new file mode 100644
index 0000000..a09524c
--- /dev/null
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/BridgeRenderSession.java
@@ -0,0 +1,175 @@
+/*
+ * Copyright (C) 2010 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.layoutlib.bridge;
+
+import com.android.ide.common.rendering.api.IAnimationListener;
+import com.android.ide.common.rendering.api.ILayoutPullParser;
+import com.android.ide.common.rendering.api.Params;
+import com.android.ide.common.rendering.api.RenderSession;
+import com.android.ide.common.rendering.api.Result;
+import com.android.ide.common.rendering.api.ViewInfo;
+import com.android.layoutlib.bridge.impl.RenderSessionImpl;
+
+import android.view.View;
+import android.view.ViewGroup;
+
+import java.awt.image.BufferedImage;
+import java.util.Map;
+
+/**
+ * An implementation of {@link RenderSession}.
+ *
+ * This is a pretty basic class that does almost nothing. All of the work is done in
+ * {@link RenderSessionImpl}.
+ *
+ */
+public class BridgeRenderSession extends RenderSession {
+
+    private final RenderSessionImpl mSession;
+    private Result mLastResult;
+
+    @Override
+    public Result getResult() {
+        return mLastResult;
+    }
+
+    @Override
+    public BufferedImage getImage() {
+        return mSession.getImage();
+    }
+
+    @Override
+    public ViewInfo getRootView() {
+        return mSession.getViewInfo();
+    }
+
+    @Override
+    public Map<String, String> getDefaultProperties(Object viewObject) {
+        return mSession.getDefaultProperties(viewObject);
+    }
+
+    @Override
+    public Result render(long timeout) {
+        try {
+            Bridge.prepareThread();
+            mLastResult = mSession.acquire(timeout);
+            if (mLastResult.isSuccess()) {
+                mLastResult = mSession.render();
+            }
+        } finally {
+            mSession.release();
+            Bridge.cleanupThread();
+        }
+
+        return mLastResult;
+    }
+
+    @Override
+    public Result animate(Object targetObject, String animationName,
+            boolean isFrameworkAnimation, IAnimationListener listener) {
+        try {
+            Bridge.prepareThread();
+            mLastResult = mSession.acquire(Params.DEFAULT_TIMEOUT);
+            if (mLastResult.isSuccess()) {
+                mLastResult = mSession.animate(targetObject, animationName, isFrameworkAnimation,
+                        listener);
+            }
+        } finally {
+            mSession.release();
+            Bridge.cleanupThread();
+        }
+
+        return mLastResult;
+    }
+
+    @Override
+    public Result insertChild(Object parentView, ILayoutPullParser childXml, int index,
+            IAnimationListener listener) {
+        if (parentView instanceof ViewGroup == false) {
+            throw new IllegalArgumentException("parentView is not a ViewGroup");
+        }
+
+        try {
+            Bridge.prepareThread();
+            mLastResult = mSession.acquire(Params.DEFAULT_TIMEOUT);
+            if (mLastResult.isSuccess()) {
+                mLastResult = mSession.insertChild((ViewGroup) parentView, childXml, index, listener);
+            }
+        } finally {
+            mSession.release();
+            Bridge.cleanupThread();
+        }
+
+        return mLastResult;
+    }
+
+
+    @Override
+    public Result moveChild(Object parentView, Object childView, int index,
+            Map<String, String> layoutParams, IAnimationListener listener) {
+        if (parentView instanceof ViewGroup == false) {
+            throw new IllegalArgumentException("parentView is not a ViewGroup");
+        }
+        if (childView instanceof View == false) {
+            throw new IllegalArgumentException("childView is not a View");
+        }
+
+        try {
+            Bridge.prepareThread();
+            mLastResult = mSession.acquire(Params.DEFAULT_TIMEOUT);
+            if (mLastResult.isSuccess()) {
+                mLastResult = mSession.moveChild((ViewGroup) parentView, (View) childView, index,
+                        layoutParams, listener);
+            }
+        } finally {
+            mSession.release();
+            Bridge.cleanupThread();
+        }
+
+        return mLastResult;
+    }
+
+    @Override
+    public Result removeChild(Object childView, IAnimationListener listener) {
+        if (childView instanceof View == false) {
+            throw new IllegalArgumentException("childView is not a View");
+        }
+
+        try {
+            Bridge.prepareThread();
+            mLastResult = mSession.acquire(Params.DEFAULT_TIMEOUT);
+            if (mLastResult.isSuccess()) {
+                mLastResult = mSession.removeChild((View) childView, listener);
+            }
+        } finally {
+            mSession.release();
+            Bridge.cleanupThread();
+        }
+
+        return mLastResult;
+    }
+
+    @Override
+    public void dispose() {
+    }
+
+    /*package*/ BridgeRenderSession(RenderSessionImpl scene, Result lastResult) {
+        mSession = scene;
+        mSession.setScene(this);
+        mLastResult = lastResult;
+    }
+}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index f484e7a..7269227 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -16,9 +16,9 @@
 
 package com.android.layoutlib.bridge.android;
 
-import com.android.layoutlib.api.IProjectCallback;
-import com.android.layoutlib.api.ResourceValue;
-import com.android.layoutlib.api.StyleResourceValue;
+import com.android.ide.common.rendering.api.IProjectCallback;
+import com.android.ide.common.rendering.api.ResourceValue;
+import com.android.ide.common.rendering.api.StyleResourceValue;
 import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.BridgeConstants;
 import com.android.layoutlib.bridge.impl.Stack;
@@ -105,11 +105,11 @@
      * @param themeName The name of the theme to use.
      * @param projectResources the resources of the project. The map contains (String, map) pairs
      * where the string is the type of the resource reference used in the layout file, and the
-     * map contains (String, {@link IResourceValue}) pairs where the key is the resource name,
+     * map contains (String, {@link }) pairs where the key is the resource name,
      * and the value is the resource value.
      * @param frameworkResources the framework resources. The map contains (String, map) pairs
      * where the string is the type of the resource reference used in the layout file, and the map
-     * contains (String, {@link IResourceValue}) pairs where the key is the resource name, and the
+     * contains (String, {@link ResourceValue}) pairs where the key is the resource name, and the
      * value is the resource value.
      * @param styleInheritanceMap
      * @param projectCallback
@@ -321,7 +321,7 @@
 
             isPlatformFile = parser.isPlatformFile();
 
-            Object key = parser.getViewKey();
+            Object key = parser.getViewCookie();
             if (key != null) {
                 defaultPropMap = mDefaultPropMaps.get(key);
                 if (defaultPropMap == null) {
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java
index dbf83e7..1b59621 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeInflater.java
@@ -16,8 +16,8 @@
 
 package com.android.layoutlib.bridge.android;
 
-import com.android.layoutlib.api.IProjectCallback;
-import com.android.layoutlib.api.ResourceValue;
+import com.android.ide.common.rendering.api.IProjectCallback;
+import com.android.ide.common.rendering.api.ResourceValue;
 import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.BridgeConstants;
 
@@ -217,14 +217,14 @@
                 BridgeXmlBlockParser parser = (BridgeXmlBlockParser) attrs;
 
                 // get the view key
-                Object viewKey = parser.getViewKey();
+                Object viewKey = parser.getViewCookie();
 
                 // if there's no view key and the depth is 1 (ie this is the first tag),
                 // look for a previous parser in the context, and check if this one has a viewkey.
                 if (viewKey == null && parser.getDepth() == 1) {
                     BridgeXmlBlockParser previousParser = bc.getPreviousParser();
                     if (previousParser != null) {
-                        viewKey = previousParser.getViewKey();
+                        viewKey = previousParser.getViewCookie();
                     }
                 }
 
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java
index c1e2046..2ea5281 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeResources.java
@@ -16,8 +16,8 @@
 
 package com.android.layoutlib.bridge.android;
 
-import com.android.layoutlib.api.IProjectCallback;
-import com.android.layoutlib.api.ResourceValue;
+import com.android.ide.common.rendering.api.IProjectCallback;
+import com.android.ide.common.rendering.api.ResourceValue;
 import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.BridgeConstants;
 import com.android.layoutlib.bridge.impl.ResourceHelper;
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java
index fcbf5fa..6ae7e03 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeTypedArray.java
@@ -16,9 +16,9 @@
 
 package com.android.layoutlib.bridge.android;
 
+import com.android.ide.common.rendering.api.ResourceValue;
+import com.android.ide.common.rendering.api.StyleResourceValue;
 import com.android.internal.util.XmlUtils;
-import com.android.layoutlib.api.ResourceValue;
-import com.android.layoutlib.api.StyleResourceValue;
 import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.BridgeConstants;
 import com.android.layoutlib.bridge.impl.ResourceHelper;
@@ -66,7 +66,7 @@
     }
 
     /**
-     * Seals the array after all calls to {@link #bridgeSetValue(int, String, IResourceValue)} have
+     * Seals the array after all calls to {@link #bridgeSetValue(int, String, ResourceValue)} have
      * been done.
      * <p/>This allows to compute the list of non default values, permitting
      * {@link #getIndexCount()} to return the proper value.
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java
index 73bee96..38800da 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlBlockParser.java
@@ -16,7 +16,8 @@
 
 package com.android.layoutlib.bridge.android;
 
-import com.android.layoutlib.api.IXmlPullParser;
+
+import com.android.ide.common.rendering.api.ILayoutPullParser;
 
 import org.xmlpull.v1.XmlPullParser;
 import org.xmlpull.v1.XmlPullParserException;
@@ -65,17 +66,17 @@
         return mPlatformFile;
     }
 
-    public IXmlPullParser getParser(String layoutName) {
-        if (mParser instanceof IXmlPullParser) {
-            return ((IXmlPullParser)mParser).getParser(layoutName);
+    public ILayoutPullParser getParser(String layoutName) {
+        if (mParser instanceof ILayoutPullParser) {
+            return ((ILayoutPullParser)mParser).getParser(layoutName);
         }
 
         return null;
     }
 
-    public Object getViewKey() {
-        if (mParser instanceof IXmlPullParser) {
-            return ((IXmlPullParser)mParser).getViewKey();
+    public Object getViewCookie() {
+        if (mParser instanceof ILayoutPullParser) {
+            return ((ILayoutPullParser)mParser).getViewCookie();
         }
 
         return null;
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java
index 92b98e5..ba45217 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeXmlPullAttributes.java
@@ -16,7 +16,7 @@
 
 package com.android.layoutlib.bridge.android;
 
-import com.android.layoutlib.api.ResourceValue;
+import com.android.ide.common.rendering.api.ResourceValue;
 import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.BridgeConstants;
 
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java
index 4ee813c..1651d6a 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/AnimationThread.java
@@ -16,10 +16,10 @@
 
 package com.android.layoutlib.bridge.impl;
 
-import com.android.layoutlib.api.LayoutScene;
-import com.android.layoutlib.api.SceneResult;
-import com.android.layoutlib.api.LayoutScene.IAnimationListener;
-import com.android.layoutlib.api.SceneResult.SceneStatus;
+import com.android.ide.common.rendering.api.IAnimationListener;
+import com.android.ide.common.rendering.api.RenderSession;
+import com.android.ide.common.rendering.api.Result;
+import com.android.ide.common.rendering.api.Result.Status;
 import com.android.layoutlib.bridge.Bridge;
 
 import android.animation.ValueAnimator;
@@ -57,18 +57,19 @@
         }
     }
 
-    private final LayoutSceneImpl mScene;
+    private final RenderSessionImpl mSession;
 
     Queue<MessageBundle> mQueue = new LinkedList<MessageBundle>();
     private final IAnimationListener mListener;
 
-    public AnimationThread(LayoutSceneImpl scene, String threadName, IAnimationListener listener) {
+    public AnimationThread(RenderSessionImpl scene, String threadName,
+            IAnimationListener listener) {
         super(threadName);
-        mScene = scene;
+        mSession = scene;
         mListener = listener;
     }
 
-    public abstract SceneResult preAnimation();
+    public abstract Result preAnimation();
     public abstract void postAnimation();
 
     @Override
@@ -87,13 +88,13 @@
             });
 
             // call out to the pre-animation work, which should start an animation or more.
-            SceneResult result = preAnimation();
+            Result result = preAnimation();
             if (result.isSuccess() == false) {
                 mListener.done(result);
             }
 
             // loop the animation
-            LayoutScene scene = mScene.getScene();
+            RenderSession session = mSession.getSession();
             do {
                 // check early.
                 if (mListener.isCanceled()) {
@@ -123,7 +124,7 @@
                 }
 
                 // ready to do the work, acquire the scene.
-                result = mScene.acquire(250);
+                result = mSession.acquire(250);
                 if (result.isSuccess() == false) {
                     mListener.done(result);
                     return;
@@ -138,15 +139,15 @@
                     }
 
                     bundle.mTarget.handleMessage(bundle.mMessage);
-                    if (mScene.render().isSuccess()) {
-                        mListener.onNewFrame(scene);
+                    if (mSession.render().isSuccess()) {
+                        mListener.onNewFrame(session);
                     }
                 } finally {
-                    mScene.release();
+                    mSession.release();
                 }
             } while (mListener.isCanceled() == false && mQueue.size() > 0);
 
-            mListener.done(SceneStatus.SUCCESS.createResult());
+            mListener.done(Status.SUCCESS.createResult());
         } finally {
             postAnimation();
             Handler_Delegate.setCallback(null);
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/PlayAnimationThread.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/PlayAnimationThread.java
index 2e2c5f4..35e5987 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/PlayAnimationThread.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/PlayAnimationThread.java
@@ -16,9 +16,9 @@
 
 package com.android.layoutlib.bridge.impl;
 
-import com.android.layoutlib.api.SceneResult;
-import com.android.layoutlib.api.LayoutScene.IAnimationListener;
-import com.android.layoutlib.api.SceneResult.SceneStatus;
+import com.android.ide.common.rendering.api.IAnimationListener;
+import com.android.ide.common.rendering.api.Result;
+import com.android.ide.common.rendering.api.Result.Status;
 
 import android.animation.Animator;
 
@@ -26,19 +26,19 @@
 
     private final Animator mAnimator;
 
-    public PlayAnimationThread(Animator animator, LayoutSceneImpl scene, String animName,
+    public PlayAnimationThread(Animator animator, RenderSessionImpl scene, String animName,
             IAnimationListener listener) {
         super(scene, animName, listener);
         mAnimator = animator;
     }
 
     @Override
-    public SceneResult preAnimation() {
+    public Result preAnimation() {
         // start the animation. This will send a message to the handler right away, so
         // the queue is filled when this method returns.
         mAnimator.start();
 
-        return SceneStatus.SUCCESS.createResult();
+        return Status.SUCCESS.createResult();
     }
 
     @Override
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/LayoutSceneImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
similarity index 87%
rename from tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/LayoutSceneImpl.java
rename to tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
index 24cf380..5f86c92d 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/LayoutSceneImpl.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
@@ -16,24 +16,28 @@
 
 package com.android.layoutlib.bridge.impl;
 
-import static com.android.layoutlib.api.SceneResult.SceneStatus.ERROR_LOCK_INTERRUPTED;
-import static com.android.layoutlib.api.SceneResult.SceneStatus.ERROR_TIMEOUT;
-import static com.android.layoutlib.api.SceneResult.SceneStatus.SUCCESS;
+import static com.android.ide.common.rendering.api.Result.Status.ERROR_ANIM_NOT_FOUND;
+import static com.android.ide.common.rendering.api.Result.Status.ERROR_INFLATION;
+import static com.android.ide.common.rendering.api.Result.Status.ERROR_LOCK_INTERRUPTED;
+import static com.android.ide.common.rendering.api.Result.Status.ERROR_NOT_INFLATED;
+import static com.android.ide.common.rendering.api.Result.Status.ERROR_TIMEOUT;
+import static com.android.ide.common.rendering.api.Result.Status.ERROR_UNKNOWN;
+import static com.android.ide.common.rendering.api.Result.Status.ERROR_VIEWGROUP_NO_CHILDREN;
+import static com.android.ide.common.rendering.api.Result.Status.SUCCESS;
 
+import com.android.ide.common.rendering.api.IAnimationListener;
+import com.android.ide.common.rendering.api.ILayoutPullParser;
+import com.android.ide.common.rendering.api.IProjectCallback;
+import com.android.ide.common.rendering.api.Params;
+import com.android.ide.common.rendering.api.RenderSession;
+import com.android.ide.common.rendering.api.ResourceDensity;
+import com.android.ide.common.rendering.api.ResourceValue;
+import com.android.ide.common.rendering.api.Result;
+import com.android.ide.common.rendering.api.StyleResourceValue;
+import com.android.ide.common.rendering.api.ViewInfo;
+import com.android.ide.common.rendering.api.Params.RenderingMode;
+import com.android.ide.common.rendering.api.Result.Status;
 import com.android.internal.util.XmlUtils;
-import com.android.layoutlib.api.IProjectCallback;
-import com.android.layoutlib.api.IXmlPullParser;
-import com.android.layoutlib.api.LayoutBridge;
-import com.android.layoutlib.api.LayoutScene;
-import com.android.layoutlib.api.ResourceDensity;
-import com.android.layoutlib.api.ResourceValue;
-import com.android.layoutlib.api.SceneParams;
-import com.android.layoutlib.api.SceneResult;
-import com.android.layoutlib.api.StyleResourceValue;
-import com.android.layoutlib.api.ViewInfo;
-import com.android.layoutlib.api.LayoutScene.IAnimationListener;
-import com.android.layoutlib.api.SceneParams.RenderingMode;
-import com.android.layoutlib.api.SceneResult.SceneStatus;
 import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.BridgeConstants;
 import com.android.layoutlib.bridge.android.BridgeContext;
@@ -75,14 +79,14 @@
 import java.util.concurrent.locks.ReentrantLock;
 
 /**
- * Class managing a layout "scene".
+ * Class implementing the render session.
  *
- * A scene is a stateful representation of a layout file. It is initialized with data coming through
- * the {@link LayoutBridge} API to inflate the layout. Further actions and rendering can then
+ * A session is a stateful representation of a layout file. It is initialized with data coming
+ * through the {@link Bridge} API to inflate the layout. Further actions and rendering can then
  * be done on the layout.
  *
  */
-public class LayoutSceneImpl {
+public class RenderSessionImpl {
 
     private static final int DEFAULT_TITLE_BAR_HEIGHT = 25;
     private static final int DEFAULT_STATUS_BAR_HEIGHT = 25;
@@ -93,10 +97,10 @@
      */
     private static BridgeContext sCurrentContext = null;
 
-    private final SceneParams mParams;
+    private final Params mParams;
 
     // scene state
-    private LayoutScene mScene;
+    private RenderSession mScene;
     private BridgeContext mContext;
     private BridgeXmlBlockParser mBlockParser;
     private BridgeInflater mInflater;
@@ -123,14 +127,14 @@
     /**
      * Creates a layout scene with all the information coming from the layout bridge API.
      * <p>
-     * This <b>must</b> be followed by a call to {@link LayoutSceneImpl#init()}, which act as a
-     * call to {@link LayoutSceneImpl#acquire(long)}
+     * This <b>must</b> be followed by a call to {@link RenderSessionImpl#init()}, which act as a
+     * call to {@link RenderSessionImpl#acquire(long)}
      *
      * @see LayoutBridge#createScene(com.android.layoutlib.api.SceneParams)
      */
-    public LayoutSceneImpl(SceneParams params) {
+    public RenderSessionImpl(Params params) {
         // copy the params.
-        mParams = new SceneParams(params);
+        mParams = new Params(params);
     }
 
     /**
@@ -144,10 +148,10 @@
      * @see #acquire(long)
      * @see #release()
      */
-    public SceneResult init(long timeout) {
+    public Result init(long timeout) {
         // acquire the lock. if the result is null, lock was just acquired, otherwise, return
         // the result.
-        SceneResult result = acquireLock(timeout);
+        Result result = acquireLock(timeout);
         if (result != null) {
             return result;
         }
@@ -168,7 +172,7 @@
         Map<StyleResourceValue, StyleResourceValue> styleParentMap =
             new HashMap<StyleResourceValue, StyleResourceValue>();
 
-        mCurrentTheme = computeStyleMaps(mParams.getThemeName(), mParams.getIsProjectTheme(),
+        mCurrentTheme = computeStyleMaps(mParams.getThemeName(), mParams.isProjectTheme(),
                 mParams.getProjectResources().get(BridgeConstants.RES_STYLE),
                 mParams.getFrameworkResources().get(BridgeConstants.RES_STYLE), styleParentMap);
 
@@ -187,7 +191,7 @@
         // get the screen offset and window-background resource
         mWindowBackground = null;
         mScreenOffset = 0;
-        if (mCurrentTheme != null && mParams.isCustomBackgroundEnabled() == false) {
+        if (mCurrentTheme != null && mParams.isBgColorOverridden() == false) {
             mWindowBackground = mContext.findItemInStyle(mCurrentTheme, "windowBackground");
             mWindowBackground = mContext.resolveResValue(mWindowBackground);
 
@@ -203,7 +207,7 @@
         mBlockParser = new BridgeXmlBlockParser(mParams.getLayoutDescription(),
                 mContext, false /* platformResourceFlag */);
 
-        return SceneStatus.SUCCESS.createResult();
+        return SUCCESS.createResult();
     }
 
     /**
@@ -215,7 +219,7 @@
      * The preparation can fail if another rendering took too long and the timeout was elapsed.
      *
      * More than one call to this from the same thread will have no effect and will return
-     * {@link SceneResult#SUCCESS}.
+     * {@link Result#SUCCESS}.
      *
      * After scene actions have taken place, only one call to {@link #release()} must be
      * done.
@@ -228,14 +232,14 @@
      *
      * @throws IllegalStateException if {@link #init(long)} was never called.
      */
-    public SceneResult acquire(long timeout) {
+    public Result acquire(long timeout) {
         if (mContext == null) {
             throw new IllegalStateException("After scene creation, #init() must be called");
         }
 
         // acquire the lock. if the result is null, lock was just acquired, otherwise, return
         // the result.
-        SceneResult result = acquireLock(timeout);
+        Result result = acquireLock(timeout);
         if (result != null) {
             return result;
         }
@@ -253,8 +257,8 @@
      * Acquire the lock so that the scene can be acted upon.
      * <p>
      * This returns null if the lock was just acquired, otherwise it returns
-     * {@link SceneResult#SUCCESS} if the lock already belonged to that thread, or another
-     * instance (see {@link SceneResult#getStatus()}) if an error occurred.
+     * {@link Result#SUCCESS} if the lock already belonged to that thread, or another
+     * instance (see {@link Result#getStatus()}) if an error occurred.
      *
      * @param timeout the time to wait if another rendering is happening.
      * @return null if the lock was just acquire or another result depending on the state.
@@ -262,7 +266,7 @@
      * @throws IllegalStateException if the current context is different than the one owned by
      *      the scene.
      */
-    private SceneResult acquireLock(long timeout) {
+    private Result acquireLock(long timeout) {
         ReentrantLock lock = Bridge.getLock();
         if (lock.isHeldByCurrentThread() == false) {
             try {
@@ -314,7 +318,7 @@
      * @throws IllegalStateException if the current context is different than the one owned by
      *      the scene, or if {@link #init(long)} was not called.
      */
-    public SceneResult inflate() {
+    public Result inflate() {
         checkLock();
 
         try {
@@ -347,9 +351,9 @@
                 mViewRoot.setBackgroundDrawable(d);
             }
 
-            return SceneStatus.SUCCESS.createResult();
+            return SUCCESS.createResult();
         } catch (PostInflateException e) {
-            return SceneStatus.ERROR_INFLATION.createResult(e.getMessage(), e);
+            return ERROR_INFLATION.createResult(e.getMessage(), e);
         } catch (Throwable e) {
             // get the real cause of the exception.
             Throwable t = e;
@@ -360,7 +364,7 @@
             // log it
             mParams.getLog().error("Scene inflate failed", t);
 
-            return SceneStatus.ERROR_INFLATION.createResult(t.getMessage(), t);
+            return ERROR_INFLATION.createResult(t.getMessage(), t);
         }
     }
 
@@ -375,12 +379,12 @@
      * @see SceneParams#getRenderingMode()
      * @see LayoutScene#render(long)
      */
-    public SceneResult render() {
+    public Result render() {
         checkLock();
 
         try {
             if (mViewRoot == null) {
-                return SceneStatus.ERROR_NOT_INFLATED.createResult();
+                return ERROR_NOT_INFLATED.createResult();
             }
             // measure the views
             int w_spec, h_spec;
@@ -443,9 +447,9 @@
                             mMeasuredScreenHeight - mScreenOffset, BufferedImage.TYPE_INT_ARGB);
                 }
 
-                if (mParams.isCustomBackgroundEnabled()) {
+                if (mParams.isBgColorOverridden()) {
                     Graphics2D gc = mImage.createGraphics();
-                    gc.setColor(new Color(mParams.getCustomBackgroundColor(), true));
+                    gc.setColor(new Color(mParams.getOverrideBgColor(), true));
                     gc.fillRect(0, 0, mMeasuredScreenWidth, mMeasuredScreenHeight - mScreenOffset);
                     gc.dispose();
                 }
@@ -465,7 +469,7 @@
             mViewInfo = visit(((ViewGroup)mViewRoot).getChildAt(0), mContext);
 
             // success!
-            return SceneStatus.SUCCESS.createResult();
+            return SUCCESS.createResult();
         } catch (Throwable e) {
             // get the real cause of the exception.
             Throwable t = e;
@@ -476,7 +480,7 @@
             // log it
             mParams.getLog().error("Scene Render failed", t);
 
-            return SceneStatus.ERROR_UNKNOWN.createResult(t.getMessage(), t);
+            return ERROR_UNKNOWN.createResult(t.getMessage(), t);
         }
     }
 
@@ -490,7 +494,7 @@
      *
      * @see LayoutScene#animate(Object, String, boolean, IAnimationListener)
      */
-    public SceneResult animate(Object targetObject, String animationName,
+    public Result animate(Object targetObject, String animationName,
             boolean isFrameworkAnimation, IAnimationListener listener) {
         checkLock();
 
@@ -517,7 +521,7 @@
 
                     new PlayAnimationThread(anim, this, animationName, listener).start();
 
-                    return SceneStatus.SUCCESS.createResult();
+                    return SUCCESS.createResult();
                 }
             } catch (Exception e) {
                 // get the real cause of the exception.
@@ -526,11 +530,11 @@
                     t = t.getCause();
                 }
 
-                return SceneStatus.ERROR_UNKNOWN.createResult(t.getMessage(), t);
+                return ERROR_UNKNOWN.createResult(t.getMessage(), t);
             }
         }
 
-        return SceneStatus.ERROR_ANIM_NOT_FOUND.createResult();
+        return ERROR_ANIM_NOT_FOUND.createResult();
     }
 
     /**
@@ -541,9 +545,9 @@
      * @throws IllegalStateException if the current context is different than the one owned by
      *      the scene, or if {@link #acquire(long)} was not called.
      *
-     * @see LayoutScene#insertChild(Object, IXmlPullParser, int, IAnimationListener)
+     * @see LayoutScene#insertChild(Object, ILayoutPullParser, int, IAnimationListener)
      */
-    public SceneResult insertChild(final ViewGroup parentView, IXmlPullParser childXml,
+    public Result insertChild(final ViewGroup parentView, ILayoutPullParser childXml,
             final int index, IAnimationListener listener) {
         checkLock();
 
@@ -562,7 +566,7 @@
             new AnimationThread(this, "insertChild", listener) {
 
                 @Override
-                public SceneResult preAnimation() {
+                public Result preAnimation() {
                     parentView.setLayoutTransition(new LayoutTransition());
                     return addView(parentView, child, index);
                 }
@@ -574,11 +578,11 @@
             }.start();
 
             // always return success since the real status will come through the listener.
-            return SceneStatus.SUCCESS.createResult(child);
+            return SUCCESS.createResult(child);
         }
 
         // add it to the parentView in the correct location
-        SceneResult result = addView(parentView, child, index);
+        Result result = addView(parentView, child, index);
         if (result.isSuccess() == false) {
             return result;
         }
@@ -598,17 +602,17 @@
      * @param view the view to add to the parent
      * @param index the index where to do the add.
      *
-     * @return a SceneResult with {@link SceneStatus#SUCCESS} or
-     *     {@link SceneStatus#ERROR_VIEWGROUP_NO_CHILDREN} if the given parent doesn't support
+     * @return a Result with {@link Status#SUCCESS} or
+     *     {@link Status#ERROR_VIEWGROUP_NO_CHILDREN} if the given parent doesn't support
      *     adding views.
      */
-    private SceneResult addView(ViewGroup parent, View view, int index) {
+    private Result addView(ViewGroup parent, View view, int index) {
         try {
             parent.addView(view, index);
-            return SceneStatus.SUCCESS.createResult();
+            return SUCCESS.createResult();
         } catch (UnsupportedOperationException e) {
             // looks like this is a view class that doesn't support children manipulation!
-            return SceneStatus.ERROR_VIEWGROUP_NO_CHILDREN.createResult();
+            return ERROR_VIEWGROUP_NO_CHILDREN.createResult();
         }
     }
 
@@ -622,7 +626,7 @@
      *
      * @see LayoutScene#moveChild(Object, Object, int, Map, IAnimationListener)
      */
-    public SceneResult moveChild(final ViewGroup parentView, final View childView, final int index,
+    public Result moveChild(final ViewGroup parentView, final View childView, final int index,
             Map<String, String> layoutParamsMap, IAnimationListener listener) {
         checkLock();
 
@@ -640,7 +644,7 @@
             new AnimationThread(this, "moveChild", listener) {
 
                 @Override
-                public SceneResult preAnimation() {
+                public Result preAnimation() {
                     parentView.setLayoutTransition(new LayoutTransition());
                     return moveView(parentView, childView, index, params);
                 }
@@ -652,10 +656,10 @@
             }.start();
 
             // always return success since the real status will come through the listener.
-            return SceneStatus.SUCCESS.createResult(layoutParams);
+            return SUCCESS.createResult(layoutParams);
         }
 
-        SceneResult result = moveView(parentView, childView, index, layoutParams);
+        Result result = moveView(parentView, childView, index, layoutParams);
         if (result.isSuccess() == false) {
             return result;
         }
@@ -677,11 +681,11 @@
      * @param index the new location in the new parent
      * @param params an option (can be null) {@link LayoutParams} instance.
      *
-     * @return a SceneResult with {@link SceneStatus#SUCCESS} or
-     *     {@link SceneStatus#ERROR_VIEWGROUP_NO_CHILDREN} if the given parent doesn't support
+     * @return a Result with {@link Status#SUCCESS} or
+     *     {@link Status#ERROR_VIEWGROUP_NO_CHILDREN} if the given parent doesn't support
      *     adding views.
      */
-    private SceneResult moveView(ViewGroup parent, View view, int index, LayoutParams params) {
+    private Result moveView(ViewGroup parent, View view, int index, LayoutParams params) {
         try {
             ViewGroup previousParent = (ViewGroup) view.getParent();
             previousParent.removeView(view);
@@ -694,10 +698,10 @@
                 parent.addView(view, index);
             }
 
-            return SceneStatus.SUCCESS.createResult();
+            return SUCCESS.createResult();
         } catch (UnsupportedOperationException e) {
             // looks like this is a view class that doesn't support children manipulation!
-            return SceneStatus.ERROR_VIEWGROUP_NO_CHILDREN.createResult();
+            return ERROR_VIEWGROUP_NO_CHILDREN.createResult();
         }
     }
 
@@ -711,7 +715,7 @@
      *
      * @see LayoutScene#removeChild(Object, IAnimationListener)
      */
-    public SceneResult removeChild(final View childView, IAnimationListener listener) {
+    public Result removeChild(final View childView, IAnimationListener listener) {
         checkLock();
 
         invalidateRenderingSize();
@@ -722,7 +726,7 @@
             new AnimationThread(this, "moveChild", listener) {
 
                 @Override
-                public SceneResult preAnimation() {
+                public Result preAnimation() {
                     parent.setLayoutTransition(new LayoutTransition());
                     return removeView(parent, childView);
                 }
@@ -734,10 +738,10 @@
             }.start();
 
             // always return success since the real status will come through the listener.
-            return SceneStatus.SUCCESS.createResult();
+            return SUCCESS.createResult();
         }
 
-        SceneResult result = removeView(parent, childView);
+        Result result = removeView(parent, childView);
         if (result.isSuccess() == false) {
             return result;
         }
@@ -750,17 +754,17 @@
      *
      * @param view the view to remove from its parent
      *
-     * @return a SceneResult with {@link SceneStatus#SUCCESS} or
-     *     {@link SceneStatus#ERROR_VIEWGROUP_NO_CHILDREN} if the given parent doesn't support
+     * @return a Result with {@link Status#SUCCESS} or
+     *     {@link Status#ERROR_VIEWGROUP_NO_CHILDREN} if the given parent doesn't support
      *     adding views.
      */
-    private SceneResult removeView(ViewGroup parent, View view) {
+    private Result removeView(ViewGroup parent, View view) {
         try {
             parent.removeView(view);
-            return SceneStatus.SUCCESS.createResult();
+            return SUCCESS.createResult();
         } catch (UnsupportedOperationException e) {
             // looks like this is a view class that doesn't support children manipulation!
-            return SceneStatus.ERROR_VIEWGROUP_NO_CHILDREN.createResult();
+            return ERROR_VIEWGROUP_NO_CHILDREN.createResult();
         }
     }
 
@@ -791,7 +795,7 @@
      * @param inProjectStyleMap the project style map
      * @param inFrameworkStyleMap the framework style map
      * @param outInheritanceMap the map of style inheritance. This is filled by the method
-     * @return the {@link IStyleResourceValue} matching <var>themeName</var>
+     * @return the {@link StyleResourceValue} matching <var>themeName</var>
      */
     private StyleResourceValue computeStyleMaps(
             String themeName, boolean isProjectTheme, Map<String,
@@ -865,7 +869,7 @@
     }
 
     /**
-     * Searches for and returns the {@link IStyleResourceValue} from a given name.
+     * Searches for and returns the {@link StyleResourceValue} from a given name.
      * <p/>The format of the name can be:
      * <ul>
      * <li>[android:]&lt;name&gt;</li>
@@ -875,7 +879,7 @@
      * @param parentName the name of the style.
      * @param inProjectStyleMap the project style map. Can be <code>null</code>
      * @param inFrameworkStyleMap the framework style map.
-     * @return The matching {@link IStyleResourceValue} object or <code>null</code> if not found.
+     * @return The matching {@link StyleResourceValue} object or <code>null</code> if not found.
      */
     private StyleResourceValue getStyle(String parentName,
             Map<String, ResourceValue> inProjectStyleMap,
@@ -1143,15 +1147,15 @@
         return mViewInfo;
     }
 
-    public Map<String, String> getDefaultViewPropertyValues(Object viewObject) {
+    public Map<String, String> getDefaultProperties(Object viewObject) {
         return mContext.getDefaultPropMap(viewObject);
     }
 
-    public void setScene(LayoutScene scene) {
-        mScene = scene;
+    public void setScene(RenderSession session) {
+        mScene = session;
     }
 
-    public LayoutScene getScene() {
+    public RenderSession getSession() {
         return mScene;
     }
 }
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
index f03931f..5427f142 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/ResourceHelper.java
@@ -16,9 +16,9 @@
 
 package com.android.layoutlib.bridge.impl;
 
-import com.android.layoutlib.api.DensityBasedResourceValue;
-import com.android.layoutlib.api.ResourceDensity;
-import com.android.layoutlib.api.ResourceValue;
+import com.android.ide.common.rendering.api.DensityBasedResourceValue;
+import com.android.ide.common.rendering.api.ResourceDensity;
+import com.android.ide.common.rendering.api.ResourceValue;
 import com.android.layoutlib.bridge.Bridge;
 import com.android.layoutlib.bridge.android.BridgeContext;
 import com.android.layoutlib.bridge.android.BridgeXmlBlockParser;