display: Support for S3D video

1. Add support to set HDMI to 3D mode
2. Add binder API to force 3D mode
3. Switch to 3D mode based on metadata
4. Configure pipes appropriately
5. Only side-by-side and top-bottom formats are currently supported

Change-Id: Iae579ecfa45aae088ff543d4143e5025e8c682fa
diff --git a/libhwcomposer/hwc_utils.h b/libhwcomposer/hwc_utils.h
index 4f1b5e6..52b22b1 100644
--- a/libhwcomposer/hwc_utils.h
+++ b/libhwcomposer/hwc_utils.h
@@ -117,6 +117,18 @@
     uint32_t xres_new;
     uint32_t yres_new;
 
+    // This is the 3D mode to which the TV is set
+    // The mode may be set via the appearance of a layer with 3D format
+    // or by forcing the mode via binder.
+    // If the mode is set via binder, the s3dModeForced flag is set, so that the
+    // mode is not changed back when the 3D video layer drops out.
+    // If the forced mode is different from the one in 3D video, the results
+    // are unpredictable. The assumption is made here that the caller forcing
+    // the mode via binder knows the right formats to use.
+    // The s3dModeForced flag is also used to force 2D if the s3dMode is
+    // HDMI_S3D_NONE
+    int s3dMode;
+    bool s3dModeForced;
 };
 
 struct ListStats {
@@ -411,6 +423,15 @@
         const ovutils::eDest& lDest,
         const ovutils::eDest& rDest, overlay::Rotator **rot);
 
+//Check if the current round needs 3D composition
+bool needs3DComposition(hwc_context_t* ctx, int dpy);
+
+//Routine to configure 3D video
+int configure3DVideo(hwc_context_t *ctx, hwc_layer_1_t *layer, const int& dpy,
+        ovutils::eMdpFlags& mdpFlags, ovutils::eZorder& z,
+        const ovutils::eDest& lDest,
+        const ovutils::eDest& rDest, overlay::Rotator **rot);
+
 //Routine to split and configure high resolution YUV layer (> 2048 width)
 int configureSourceSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
         const int& dpy,
@@ -444,6 +465,16 @@
 // Checks if boot animation has completed and applies default mode
 void processBootAnimCompleted(hwc_context_t *ctx);
 
+//The gralloc API and driver have different formats
+//The format needs to be converted before passing to libhdmi
+int convertS3DFormatToMode(int s3DFormat);
+
+//Configure resources for 3D mode
+void setup3DMode(hwc_context_t* ctx, int dpy, int s3dMode);
+
+//Checks if this display supports 3D
+bool displaySupports3D(hwc_context_t* ctx, int dpy);
+
 // Inline utility functions
 static inline bool isSkipLayer(const hwc_layer_1_t* l) {
     return (UNLIKELY(l && (l->flags & HWC_SKIP_LAYER)));
@@ -489,6 +520,14 @@
     return (hnd && (hnd->flags & private_handle_t::PRIV_FLAGS_SECURE_DISPLAY));
 }
 
+static inline uint32_t get3DFormat(const private_handle_t* hnd) {
+    MetaData_t *metadata = reinterpret_cast<MetaData_t*>(hnd->base_metadata);
+    if(isYuvBuffer(hnd) && metadata && metadata->operation & S3D_FORMAT) {
+        return metadata->s3dFormat;
+    }
+    return HAL_NO_3D;
+}
+
 static inline int getWidth(const private_handle_t* hnd) {
     MetaData_t *metadata = reinterpret_cast<MetaData_t*>(hnd->base_metadata);
     if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
@@ -644,7 +683,7 @@
     bool mBWCEnabled;
     // Provides a way for OEM's to disable setting dynfps via metadata.
     bool mUseMetaDataRefreshRate;
-   // Stores the hpd enabled status- avoids re-enabling HDP on suspend resume.
+    // Stores the hpd enabled status- avoids re-enabling HDP on suspend resume.
     bool mHPDEnabled;
     //Used to notify that boot has completed
     bool mBootAnimCompleted;