auto import from //branches/cupcake/...@130745
diff --git a/include/ui/Camera.h b/include/ui/Camera.h
index 44acce5..e593fea 100644
--- a/include/ui/Camera.h
+++ b/include/ui/Camera.h
@@ -23,8 +23,8 @@
 namespace android {
 
 /*
- * A set of bit masks for specifying how the received frames from preview are
- * handled before the frame callback call.
+ * A set of bit masks for specifying how the received preview frames are
+ * handled before the previewCallback() call.
  *
  * The least significant 3 bits of an "int" value are used for this purpose:
  *
@@ -34,10 +34,18 @@
  *       | |-----------> determine whether the callback is one-shot or not
  *       |-------------> determine whether the frame is copied out or not
  *
+ * WARNING:
+ * When a frame is sent directly without copying, it is the frame receiver's
+ * responsiblity to make sure that the frame data won't get corrupted by
+ * subsequent preview frames filled by the camera. This flag is recommended
+ * only when copying out data brings significant performance price and the
+ * handling/processing of the received frame data is always faster than
+ * the preview frame rate so that data corruption won't occur.
+ *
  * For instance,
  * 1. 0x00 disables the callback. In this case, copy out and one shot bits
  *    are ignored.
- * 2. 0x01 enables a callback without copying out the recievied frames. A
+ * 2. 0x01 enables a callback without copying out the received frames. A
  *    typical use case is the Camcorder application to avoid making costly
  *    frame copies.
  * 3. 0x05 is enabling a callback with frame copied out repeatedly. A typical
@@ -96,6 +104,18 @@
             // get preview state
             bool        previewEnabled();
 
+            // start recording mode, must call setPreviewDisplay first
+            status_t    startRecording();
+
+            // stop recording mode
+            void        stopRecording();
+
+            // get recording state
+            bool        recordingEnabled();
+
+            // release a recording frame
+            void        releaseRecordingFrame(const sp<IMemory>& mem);
+
             // autoFocus - status returned from callback
             status_t    autoFocus();
 
@@ -111,20 +131,19 @@
             void        setShutterCallback(shutter_callback cb, void *cookie);
             void        setRawCallback(frame_callback cb, void *cookie);
             void        setJpegCallback(frame_callback cb, void *cookie);
-
-            void        setFrameCallback(frame_callback cb,
-                            void *cookie,
-                            int frame_callback_flag = FRAME_CALLBACK_FLAG_NOOP);
-
+            void        setRecordingCallback(frame_callback cb, void *cookie);
+            void        setPreviewCallback(frame_callback cb, void *cookie, int preview_callback_flag = FRAME_CALLBACK_FLAG_NOOP);
             void        setErrorCallback(error_callback cb, void *cookie);
             void        setAutoFocusCallback(autofocus_callback cb, void *cookie);
+
     // ICameraClient interface
     virtual void        shutterCallback();
     virtual void        rawCallback(const sp<IMemory>& picture);
     virtual void        jpegCallback(const sp<IMemory>& picture);
-    virtual void        frameCallback(const sp<IMemory>& frame);
+    virtual void        previewCallback(const sp<IMemory>& frame);
     virtual void        errorCallback(status_t error);
     virtual void        autoFocusCallback(bool focused);
+    virtual void        recordingCallback(const sp<IMemory>& frame);
 
     sp<ICamera>         remote();
 
@@ -155,8 +174,10 @@
             void                *mRawCallbackCookie;
             frame_callback      mJpegCallback;
             void                *mJpegCallbackCookie;
-            frame_callback      mFrameCallback;
-            void                *mFrameCallbackCookie;
+            frame_callback      mPreviewCallback;
+            void                *mPreviewCallbackCookie;
+            frame_callback      mRecordingCallback;
+            void                *mRecordingCallbackCookie;
             error_callback      mErrorCallback;
             void                *mErrorCallbackCookie;
             autofocus_callback  mAutoFocusCallback;
diff --git a/include/ui/CameraHardwareInterface.h b/include/ui/CameraHardwareInterface.h
index 2bd53dd..b068c52 100644
--- a/include/ui/CameraHardwareInterface.h
+++ b/include/ui/CameraHardwareInterface.h
@@ -20,12 +20,16 @@
 #include <utils/IMemory.h>
 #include <utils/RefBase.h>
 #include <ui/CameraParameters.h>
+#include <ui/Overlay.h>
 
 namespace android {
 
 /** Callback for startPreview() */
 typedef void (*preview_callback)(const sp<IMemory>& mem, void* user);
 
+/** Callback for startRecord() */
+typedef void (*recording_callback)(const sp<IMemory>& mem, void* user);
+
 /** Callback for takePicture() */
 typedef void (*shutter_callback)(void* user);
 
@@ -89,6 +93,11 @@
      * call back parameter may be null.
      */
     virtual status_t    startPreview(preview_callback cb, void* user) = 0;
+    /**
+     * Only used if overlays are used for camera preview.
+     */
+    virtual bool useOverlay() {return false;}
+    virtual status_t setOverlay(const sp<Overlay> &overlay) {return BAD_VALUE;}
 
     /**
      * Stop a previously started preview.
@@ -101,6 +110,29 @@
     virtual bool        previewEnabled() = 0;
 
     /**
+     * Start record mode. When a record image is available recording_callback()
+     * is called with the user parameter.  Every record frame must be released
+     * by calling releaseRecordingFrame().
+     */
+    virtual status_t    startRecording(recording_callback cb, void* user) = 0;
+
+    /**
+     * Stop a previously started recording.
+     */
+    virtual void        stopRecording() = 0;
+
+    /**
+     * Returns true if recording is enabled.
+     */
+    virtual bool        recordingEnabled() = 0;
+    
+    /**
+     * Release a record frame previously returned by the recording_callback()
+     * passed to startRecord().
+     */
+    virtual void        releaseRecordingFrame(const sp<IMemory>& mem) = 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/CameraParameters.h b/include/ui/CameraParameters.h
index e35a054..9ca1806 100644
--- a/include/ui/CameraParameters.h
+++ b/include/ui/CameraParameters.h
@@ -29,6 +29,12 @@
     CameraParameters(const String8 &params) { unflatten(params); }
     ~CameraParameters();
 
+    enum {
+        CAMERA_ORIENTATION_UNKNOWN = 0,
+        CAMERA_ORIENTATION_PORTRAIT = 1,
+        CAMERA_ORIENTATION_LANDSCAPE = 2,
+    };
+
     String8 flatten() const;
     void unflatten(const String8 &params);
 
@@ -57,6 +63,9 @@
     void setPictureFormat(const char *format);
     const char *getPictureFormat() const;
 
+    int getOrientation() const;
+    void setOrientation(int orientation);
+
     void dump() const;
     status_t dump(int fd, const Vector<String16>& args) const;
 
diff --git a/include/ui/EGLDisplaySurface.h b/include/ui/EGLDisplaySurface.h
index 0190e09..a8b5853 100644
--- a/include/ui/EGLDisplaySurface.h
+++ b/include/ui/EGLDisplaySurface.h
@@ -27,7 +27,10 @@
 #include <pixelflinger/pixelflinger.h>
 #include <linux/fb.h>
 
+#include <EGL/egl.h>
+
 struct copybit_device_t;
+struct copybit_image_t;
 
 // ---------------------------------------------------------------------------
 namespace android {
@@ -44,17 +47,17 @@
     
     int32_t getPageFlipCount() const;
     void    copyFrontToBack(const Region& copyback);
+    void    copyFrontToImage(const copybit_image_t& dst);
+    void    copyBackToImage(const copybit_image_t& dst);
     
+    void        setSwapRectangle(int l, int t, int w, int h);
+
 private:
     static void         hook_incRef(NativeWindowType window);
     static void         hook_decRef(NativeWindowType window);
     static uint32_t     hook_swapBuffers(NativeWindowType window);
-    static void         hook_setSwapRectangle(NativeWindowType window, int l, int t, int w, int h);
-    static uint32_t     hook_nextBuffer(NativeWindowType window);
      
             uint32_t    swapBuffers();
-            uint32_t    nextBuffer();
-            void        setSwapRectangle(int l, int t, int w, int h);
 
             status_t    mapFrameBuffer();
 
diff --git a/include/ui/EGLNativeSurface.h b/include/ui/EGLNativeSurface.h
index c303cd8..7964e7c 100644
--- a/include/ui/EGLNativeSurface.h
+++ b/include/ui/EGLNativeSurface.h
@@ -23,7 +23,7 @@
 #include <cutils/atomic.h>
 #include <utils/RefBase.h>
 
-#include <GLES/eglnatives.h>
+#include <EGL/eglnatives.h>
 
 // ---------------------------------------------------------------------------
 namespace android {
diff --git a/include/ui/EGLNativeWindowSurface.h b/include/ui/EGLNativeWindowSurface.h
index 058479a..3494234 100644
--- a/include/ui/EGLNativeWindowSurface.h
+++ b/include/ui/EGLNativeWindowSurface.h
@@ -20,6 +20,7 @@
 #include <stdint.h>
 #include <sys/types.h>
 #include <ui/EGLNativeSurface.h>
+#include <EGL/egl.h>
 
 // ---------------------------------------------------------------------------
 namespace android {
@@ -33,18 +34,16 @@
     EGLNativeWindowSurface(const sp<Surface>& surface);
     ~EGLNativeWindowSurface();
 
+    void        setSwapRectangle(int l, int t, int w, int h);
+
 private:
     static void         hook_incRef(NativeWindowType window);
     static void         hook_decRef(NativeWindowType window);
     static uint32_t     hook_swapBuffers(NativeWindowType window);
-    static uint32_t     hook_nextBuffer(NativeWindowType window);
-    static void         hook_setSwapRectangle(NativeWindowType window, int l, int t, int w, int h);
     static void         hook_connect(NativeWindowType window);
     static void         hook_disconnect(NativeWindowType window);
 
             uint32_t    swapBuffers();
-            uint32_t    nextBuffer();
-            void        setSwapRectangle(int l, int t, int w, int h);
             void        connect();
             void        disconnect();
             
diff --git a/include/ui/EventHub.h b/include/ui/EventHub.h
index 017c145..3848d8c 100644
--- a/include/ui/EventHub.h
+++ b/include/ui/EventHub.h
@@ -76,6 +76,9 @@
         DEVICE_REMOVED = 0x20000000
     };
     
+    // examine key input devices for specific framework keycode support
+    bool hasKeys(size_t numCodes, int32_t* keyCodes, uint8_t* outFlags);
+
     virtual bool getEvent(int32_t* outDeviceId, int32_t* outType,
             int32_t* outScancode, int32_t* outKeycode, uint32_t *outFlags,
             int32_t* outValue, nsecs_t* outWhen);
@@ -100,6 +103,7 @@
         const String8   path;
         String8         name;
         uint32_t        classes;
+        uint8_t*        keyBitmask;
         KeyLayoutMap*   layoutMap;
         String8         keylayoutFilename;
         device_t*       next;
@@ -134,8 +138,6 @@
 #ifdef EV_SW
     int32_t         mSwitches[SW_MAX+1];
 #endif
-
-    KeyLayoutMap * mLayoutMap;
 };
 
 }; // namespace android
diff --git a/include/ui/ICamera.h b/include/ui/ICamera.h
index ea2fcee..241fb63 100644
--- a/include/ui/ICamera.h
+++ b/include/ui/ICamera.h
@@ -48,9 +48,9 @@
     // pass the buffered ISurface to the camera service
     virtual status_t        setPreviewDisplay(const sp<ISurface>& surface) = 0;
 
-    // set the frame callback flag to affect how the received frames from
+    // set the preview callback flag to affect how the received frames from
     // preview are handled.
-    virtual void            setFrameCallbackFlag(int frame_callback_flag) = 0;
+    virtual void            setPreviewCallbackFlag(int flag) = 0;
 
     // start preview mode, must call setPreviewDisplay first
     virtual status_t        startPreview() = 0;
@@ -61,6 +61,18 @@
     // get preview state
     virtual bool            previewEnabled() = 0;
 
+    // start recording mode
+    virtual status_t        startRecording() = 0;
+
+    // stop recording mode
+    virtual void            stopRecording() = 0;    
+
+    // get recording state
+    virtual bool            recordingEnabled() = 0;
+
+    // release a recording frame
+    virtual void            releaseRecordingFrame(const sp<IMemory>& mem) = 0;
+
     // auto focus
     virtual status_t        autoFocus() = 0;
 
diff --git a/include/ui/ICameraClient.h b/include/ui/ICameraClient.h
index a286b8e..73b951c 100644
--- a/include/ui/ICameraClient.h
+++ b/include/ui/ICameraClient.h
@@ -32,9 +32,10 @@
     virtual void            shutterCallback() = 0;
     virtual void            rawCallback(const sp<IMemory>& picture) = 0;
     virtual void            jpegCallback(const sp<IMemory>& picture) = 0;
-    virtual void            frameCallback(const sp<IMemory>& frame) = 0;
+    virtual void            previewCallback(const sp<IMemory>& frame) = 0;
     virtual void            errorCallback(status_t error) = 0;
     virtual void            autoFocusCallback(bool focused) = 0;
+    virtual void            recordingCallback(const sp<IMemory>& frame) = 0;
 
 };
 
diff --git a/include/ui/ISurface.h b/include/ui/ISurface.h
index 9a7383c..1c8043d 100644
--- a/include/ui/ISurface.h
+++ b/include/ui/ISurface.h
@@ -34,11 +34,56 @@
 
 class ISurface : public IInterface
 {
+protected:
+    enum {
+        REGISTER_BUFFERS = IBinder::FIRST_CALL_TRANSACTION,
+        UNREGISTER_BUFFERS,
+        POST_BUFFER, // one-way transaction
+        CREATE_OVERLAY,
+    };
+
 public: 
     DECLARE_META_INTERFACE(Surface);
 
-    virtual status_t registerBuffers(int w, int h, int hstride, int vstride,
-            PixelFormat format, const sp<IMemoryHeap>& heap) = 0;
+    
+    class BufferHeap {
+    public:
+        enum {
+            /* flip source image horizontally */
+            FLIP_H    = 0x01,
+            /* flip source image vertically */
+            FLIP_V    = 0x02,
+            /* rotate source image 90 degrees */
+            ROT_90    = 0x04,
+            /* rotate source image 180 degrees */
+            ROT_180   = 0x03,
+            /* rotate source image 270 degrees */
+            ROT_270   = 0x07,
+        };
+        BufferHeap();
+        
+        BufferHeap(uint32_t w, uint32_t h,
+                int32_t hor_stride, int32_t ver_stride, 
+                PixelFormat format, const sp<IMemoryHeap>& heap);
+        
+        BufferHeap(uint32_t w, uint32_t h,
+                int32_t hor_stride, int32_t ver_stride, 
+                PixelFormat format, uint32_t transform, uint32_t flags,
+                const sp<IMemoryHeap>& heap);
+        
+        ~BufferHeap(); 
+        
+        uint32_t w;
+        uint32_t h;
+        int32_t hor_stride;
+        int32_t ver_stride;
+        PixelFormat format;
+        uint32_t transform;
+        uint32_t flags;
+        sp<IMemoryHeap> heap;
+    };
+    
+    virtual status_t registerBuffers(const BufferHeap& buffers) = 0;
 
     virtual void postBuffer(ssize_t offset) = 0; // one-way
 
diff --git a/include/ui/Overlay.h b/include/ui/Overlay.h
index f8454fd..66514b4 100644
--- a/include/ui/Overlay.h
+++ b/include/ui/Overlay.h
@@ -91,6 +91,7 @@
     int32_t getFormat() const;
     int32_t getWidthStride() const;
     int32_t getHeightStride() const;
+    int32_t getBufferCount() const;
     status_t getStatus() const;
     
 private:
diff --git a/include/ui/PixelFormat.h b/include/ui/PixelFormat.h
index b65c959..14af823 100644
--- a/include/ui/PixelFormat.h
+++ b/include/ui/PixelFormat.h
@@ -71,6 +71,10 @@
 
     PIXEL_FORMAT_YCbCr_422_SP= GGL_PIXEL_FORMAT_YCbCr_422_SP,
     PIXEL_FORMAT_YCbCr_420_SP= GGL_PIXEL_FORMAT_YCbCr_420_SP,
+    PIXEL_FORMAT_YCbCr_422_P = GGL_PIXEL_FORMAT_YCbCr_422_P,
+    PIXEL_FORMAT_YCbCr_420_P = GGL_PIXEL_FORMAT_YCbCr_420_P,
+    PIXEL_FORMAT_YCbCr_422_I = GGL_PIXEL_FORMAT_YCbCr_422_I,
+    PIXEL_FORMAT_YCbCr_420_I = GGL_PIXEL_FORMAT_YCbCr_420_I,
 
     // New formats can be added if they're also defined in
     // pixelflinger/format.h
@@ -80,7 +84,19 @@
 
 struct PixelFormatInfo
 {
+    enum { // components
+        ALPHA               = 1,
+        RGB                 = 2,
+        RGBA                = 3,
+        LUMINANCE           = 4,
+        LUMINANCE_ALPHA     = 5,
+        Y_CB_CR_SP          = 6,
+        Y_CB_CR_P           = 7,
+        Y_CB_CR_I           = 8,
+    };
+
     inline PixelFormatInfo() : version(sizeof(PixelFormatInfo)) { }
+    size_t getScanlineSize(unsigned int width) const;
     size_t      version;
     PixelFormat format;
     size_t      bytesPerPixel;
@@ -93,7 +109,9 @@
     uint8_t     l_green;
     uint8_t     h_blue;
     uint8_t     l_blue;
-    uint32_t    reserved[2];
+    uint8_t     components;
+    uint8_t     reserved0[3];
+    uint32_t    reserved1;
 };
 
 // Consider caching the results of these functions are they're not