auto import from //branches/cupcake/...@125939
diff --git a/include/ui/Camera.h b/include/ui/Camera.h
index 124f07f..44acce5 100644
--- a/include/ui/Camera.h
+++ b/include/ui/Camera.h
@@ -78,6 +78,8 @@
 
             status_t    reconnect();
             void        disconnect();
+            status_t    lock();
+            status_t    unlock();
 
             status_t    getStatus() { return mStatus; }
 
@@ -91,6 +93,9 @@
             // stop preview mode
             void        stopPreview();
 
+            // get preview state
+            bool        previewEnabled();
+
             // autoFocus - status returned from callback
             status_t    autoFocus();
 
diff --git a/include/ui/CameraHardwareInterface.h b/include/ui/CameraHardwareInterface.h
index 14ac96e..2bd53dd 100644
--- a/include/ui/CameraHardwareInterface.h
+++ b/include/ui/CameraHardwareInterface.h
@@ -96,6 +96,11 @@
     virtual void        stopPreview() = 0;
 
     /**
+     * Returns true if preview is enabled.
+     */
+    virtual bool        previewEnabled() = 0;
+
+    /**
      * Start auto focus, the callback routine is called
      * once when focusing is complete. autoFocus() will
      * be called again if another auto focus is needed.
diff --git a/include/ui/EGLNativeSurface.h b/include/ui/EGLNativeSurface.h
index 7c9ce99..c303cd8 100644
--- a/include/ui/EGLNativeSurface.h
+++ b/include/ui/EGLNativeSurface.h
@@ -30,10 +30,10 @@
 // ---------------------------------------------------------------------------
 
 template <class TYPE>
-class EGLNativeSurface : public egl_native_window_t
+class EGLNativeSurface : public egl_native_window_t, public LightRefBase<TYPE>
 {
 public:
-    EGLNativeSurface() : mCount(0) { 
+    EGLNativeSurface() { 
         memset(egl_native_window_t::reserved, 0, 
                 sizeof(egl_native_window_t::reserved));
         memset(egl_native_window_t::reserved_proc, 0, 
@@ -41,19 +41,10 @@
         memset(egl_native_window_t::oem, 0, 
                 sizeof(egl_native_window_t::oem));
     }
-    inline void incStrong(void*) const {
-        android_atomic_inc(&mCount);
-    }
-    inline void decStrong(void*) const {
-        if (android_atomic_dec(&mCount) == 1) {
-             delete static_cast<const TYPE*>(this);
-         }
-    }
 protected:
     EGLNativeSurface& operator = (const EGLNativeSurface& rhs);
     EGLNativeSurface(const EGLNativeSurface& rhs);
     inline ~EGLNativeSurface() { };
-    mutable volatile int32_t mCount;
 };
 
 // ---------------------------------------------------------------------------
diff --git a/include/ui/ICamera.h b/include/ui/ICamera.h
index 99c0d86..ea2fcee 100644
--- a/include/ui/ICamera.h
+++ b/include/ui/ICamera.h
@@ -39,6 +39,12 @@
     // connect new client with existing camera remote
     virtual status_t        connect(const sp<ICameraClient>& client) = 0;
 
+    // prevent other processes from using this ICamera interface
+    virtual status_t        lock() = 0;
+
+    // allow other processes to use this ICamera interface
+    virtual status_t        unlock() = 0;
+
     // pass the buffered ISurface to the camera service
     virtual status_t        setPreviewDisplay(const sp<ISurface>& surface) = 0;
 
@@ -52,6 +58,9 @@
     // stop preview mode
     virtual void            stopPreview() = 0;
 
+    // get preview state
+    virtual bool            previewEnabled() = 0;
+
     // auto focus
     virtual status_t        autoFocus() = 0;
 
diff --git a/include/ui/IOverlay.h b/include/ui/IOverlay.h
index 323ff07..699b1b0 100644
--- a/include/ui/IOverlay.h
+++ b/include/ui/IOverlay.h
@@ -33,8 +33,6 @@
     DECLARE_META_INTERFACE(Overlay);
 
     virtual void destroy() = 0; // one-way
-    
-    virtual ssize_t swapBuffers() = 0;
 };
 
 // ----------------------------------------------------------------------------
diff --git a/include/ui/ISurface.h b/include/ui/ISurface.h
index ff031d5..9a7383c 100644
--- a/include/ui/ISurface.h
+++ b/include/ui/ISurface.h
@@ -30,7 +30,7 @@
 typedef int32_t    SurfaceID;
 
 class IMemoryHeap;
-class Overlay;
+class OverlayRef;
 
 class ISurface : public IInterface
 {
@@ -44,7 +44,7 @@
 
     virtual void unregisterBuffers() = 0;
     
-    virtual sp<Overlay> createOverlay(
+    virtual sp<OverlayRef> createOverlay(
             uint32_t w, uint32_t h, int32_t format) = 0;
 };
 
diff --git a/include/ui/Overlay.h b/include/ui/Overlay.h
index f24780f..23cdee8 100644
--- a/include/ui/Overlay.h
+++ b/include/ui/Overlay.h
@@ -23,62 +23,82 @@
 #include <utils/Errors.h>
 #include <utils/IInterface.h>
 #include <utils/RefBase.h>
+#include <utils/threads.h>
+
 #include <ui/PixelFormat.h>
+#include <ui/IOverlay.h>
 
 #include <hardware/overlay.h>
 
 namespace android {
 
-class IOverlay;
 class IMemory;
 class IMemoryHeap;
 
+// ----------------------------------------------------------------------------
+
+class OverlayRef : public LightRefBase<OverlayRef>
+{
+public:
+    OverlayRef(overlay_handle_t const*, const sp<IOverlay>&,
+            uint32_t w, uint32_t h, int32_t f, uint32_t ws, uint32_t hs);
+
+    static sp<OverlayRef> readFromParcel(const Parcel& data);
+    static status_t writeToParcel(Parcel* reply, const sp<OverlayRef>& o);    
+
+private:
+    friend class LightRefBase<OverlayRef>;
+    friend class Overlay;
+
+    OverlayRef();
+    virtual ~OverlayRef();
+
+    overlay_handle_t const *mOverlayHandle;
+    sp<IOverlay> mOverlayChanel;
+    uint32_t mWidth;
+    uint32_t mHeight;
+    int32_t  mFormat;
+    int32_t  mWidthStride;
+    int32_t  mHeightStride;
+    bool mOwnHandle;
+};
+
+// ----------------------------------------------------------------------------
+
 class Overlay : public virtual RefBase
 {
 public:
-    Overlay(overlay_t* overlay, 
-            const sp<IOverlay>& o, const sp<IMemoryHeap>& heap);
+    Overlay(const sp<OverlayRef>& overlayRef);
 
     /* destroys this overlay */
     void destroy();
     
-    /* post/swaps buffers */
-    status_t swapBuffers();
-    
     /* get the HAL handle for this overlay */
     overlay_handle_t const* getHandleRef() const;
-    
-    /* returns the offset of the current buffer */
-    size_t getBufferOffset() const;
-    
-    /* returns a heap to this overlay. this may not be supported. */
-    sp<IMemoryHeap> getHeap() const;
-    
+
+    /* blocks until an overlay buffer is available and return that buffer. */
+    overlay_buffer_t dequeueBuffer();
+
+    /* release the overlay buffer and post it */
+    int queueBuffer(overlay_buffer_t buffer);
+
+    /* returns the address of a given buffer if supported, NULL otherwise. */
+    void* getBufferAddress(overlay_buffer_t buffer);
+
     /* get physical informations about the overlay */
     uint32_t getWidth() const;
     uint32_t getHeight() const;
     int32_t getFormat() const;
     int32_t getWidthStride() const;
     int32_t getHeightStride() const;
-
-    static sp<Overlay> readFromParcel(const Parcel& data);
-    static status_t writeToParcel(Parcel* reply, const sp<Overlay>& o);
-
+    status_t getStatus() const;
+    
 private:
-    Overlay(overlay_handle_t*, const sp<IOverlay>&, const sp<IMemoryHeap>&,  
-            uint32_t w, uint32_t h, int32_t f, uint32_t ws, uint32_t hs);
-
     virtual ~Overlay();
 
-    sp<IOverlay>        mOverlay;
-    sp<IMemoryHeap>     mHeap;
-    size_t              mCurrentBufferOffset;
-    overlay_handle_t const *mOverlayHandle;
-    uint32_t            mWidth;
-    uint32_t            mHeight;
-    int32_t             mFormat;
-    int32_t             mWidthStride;
-    int32_t             mHeightStride;
+    sp<OverlayRef> mOverlayRef;
+    overlay_data_device_t *mOverlayData;
+    status_t mStatus;
 };
 
 // ----------------------------------------------------------------------------
diff --git a/include/ui/PixelFormat.h b/include/ui/PixelFormat.h
index c61df32..b65c959 100644
--- a/include/ui/PixelFormat.h
+++ b/include/ui/PixelFormat.h
@@ -43,7 +43,7 @@
 
     // logical pixel formats used by the SurfaceFlinger -----------------------
     PIXEL_FORMAT_CUSTOM         = -4,
-        // Custom pixel-format described by a PixelFormatInfo sructure
+        // Custom pixel-format described by a PixelFormatInfo structure
 
     PIXEL_FORMAT_TRANSLUCENT    = -3,
         // System chooses a format that supports translucency (many alpha bits)
@@ -96,7 +96,7 @@
     uint32_t    reserved[2];
 };
 
-// considere caching the results of these functions are they're not
+// Consider caching the results of these functions are they're not
 // guaranteed to be fast.
 ssize_t     bytesPerPixel(PixelFormat format);
 ssize_t     bitsPerPixel(PixelFormat format);
diff --git a/include/ui/Region.h b/include/ui/Region.h
index a0c4608..7689673 100644
--- a/include/ui/Region.h
+++ b/include/ui/Region.h
@@ -27,7 +27,7 @@
 
 #include <hardware/copybit.h>
 
-#include <corecg/SkRegion.h>
+#include <core/SkRegion.h>
 
 namespace android {
 // ---------------------------------------------------------------------------