Merge "hwc: Log if vsync read takes more than 2 expected vsyncs"
diff --git a/Android.mk b/Android.mk
index 1e8cdda..b62e45b 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,7 +1,10 @@
-ifeq ($(call is-vendor-board-platform,QCOM),true)
-
 display-hals := libgralloc libgenlock libcopybit liblight
 display-hals += libhwcomposer liboverlay libqdutils libexternal libqservice
-
-include $(call all-named-subdir-makefiles,$(display-hals))
+ifeq ($(call is-vendor-board-platform,QCOM),true)
+    include $(call all-named-subdir-makefiles,$(display-hals))
+else
+ifneq ($(filter msm8960,$(TARGET_BOARD_PLATFORM)),)
+    #This is for mako since it doesn't have the QCOM make functions
+    include $(call all-named-subdir-makefiles,$(display-hals))
+endif
 endif
diff --git a/common.mk b/common.mk
index ebfc8ec..78b48dd 100644
--- a/common.mk
+++ b/common.mk
@@ -32,8 +32,9 @@
 common_deps  :=
 kernel_includes :=
 
-#Kernel includes. Not being executed on JB+
+# Executed only on QCOM BSPs
 ifeq ($(call is-vendor-board-platform,QCOM),true)
+    common_flags += -DQCOM_BSP
     common_deps += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
     kernel_includes += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
 endif
diff --git a/libexternal/external.cpp b/libexternal/external.cpp
index 3ae8c4d..1c8f170 100644
--- a/libexternal/external.cpp
+++ b/libexternal/external.cpp
@@ -525,7 +525,7 @@
     int mode = atoi(property_value);
     // We dont support interlaced modes
     if(isValidMode(mode) && !isInterlacedMode(mode)) {
-        ALOGD_IF("%s: setting the HDMI mode = %d", __FUNCTION__, mode);
+        ALOGD_IF(DEBUG, "%s: setting the HDMI mode = %d", __FUNCTION__, mode);
         return mode;
     }
     return -1;
diff --git a/libgralloc/gpu.cpp b/libgralloc/gpu.cpp
index 3bacdbf..f1af045 100644
--- a/libgralloc/gpu.cpp
+++ b/libgralloc/gpu.cpp
@@ -47,7 +47,9 @@
     common.module  = const_cast<hw_module_t*>(&module->base.common);
     common.close   = gralloc_close;
     alloc          = gralloc_alloc;
+#ifdef QCOM_BSP
     allocSize      = gralloc_alloc_size;
+#endif
     free           = gralloc_free;
 
 }
diff --git a/libgralloc/gralloc_priv.h b/libgralloc/gralloc_priv.h
index ea3fcdc..2c50e77 100644
--- a/libgralloc/gralloc_priv.h
+++ b/libgralloc/gralloc_priv.h
@@ -84,8 +84,7 @@
 enum {
     /* Gralloc perform enums
     */
-    GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER =
-                                    GRALLOC_MODULE_PERFORM_PRIVATE_START,
+    GRALLOC_MODULE_PERFORM_CREATE_HANDLE_FROM_BUFFER = 1,
 };
 
 #define GRALLOC_HEAP_MASK   (GRALLOC_USAGE_PRIVATE_UI_CONTIG_HEAP |\
diff --git a/libgralloc/ionalloc.cpp b/libgralloc/ionalloc.cpp
index 7aec73f..49e687e 100644
--- a/libgralloc/ionalloc.cpp
+++ b/libgralloc/ionalloc.cpp
@@ -40,6 +40,9 @@
 using gralloc::IonAlloc;
 
 #define ION_DEVICE "/dev/ion"
+#ifdef QCOM_BSP
+#define NEW_ION_API
+#endif
 
 int IonAlloc::open_device()
 {
@@ -66,6 +69,10 @@
 {
     Locker::Autolock _l(mLock);
     int err = 0;
+#ifndef NEW_ION_API
+    int ionSyncFd = FD_INIT;
+    int iFd = FD_INIT;
+#endif
     struct ion_handle_data handle_data;
     struct ion_fd_data fd_data;
     struct ion_allocation_data ionAllocData;
@@ -73,9 +80,12 @@
 
     ionAllocData.len = data.size;
     ionAllocData.align = data.align;
+#ifndef NEW_ION_API
+    ionAllocData.flags = data.flags;
+#else
     ionAllocData.heap_mask = data.flags & ~ION_SECURE;
     ionAllocData.flags = data.uncached ? 0 : ION_FLAG_CACHED;
-
+#endif
     // ToDo: replace usage of alloc data structure with
     //  ionallocdata structure.
     if (data.flags & ION_SECURE)
@@ -84,10 +94,32 @@
     err = open_device();
     if (err)
         return err;
+#ifndef NEW_ION_API
+    if(data.uncached) {
+        // Use the sync FD to alloc and map 93
+        // when we need uncached memory 94
+        ionSyncFd = open(ION_DEVICE, O_RDONLY|O_DSYNC);
+        if(ionSyncFd < 0) {
+            ALOGE("%s: Failed to open ion device - %s",
+                  __FUNCTION__, strerror(errno));
+            return -errno;
+        }
+        iFd = ionSyncFd;
+    } else {
+        iFd = mIonFd;
+    }
 
+    if(ioctl(iFd, ION_IOC_ALLOC, &ionAllocData)) {
+#else
     if(ioctl(mIonFd, ION_IOC_ALLOC, &ionAllocData)) {
+#endif
         err = -errno;
         ALOGE("ION_IOC_ALLOC failed with error - %s", strerror(errno));
+#ifndef NEW_ION_API
+        if(ionSyncFd >= 0)
+            close(ionSyncFd);
+        ionSyncFd = FD_INIT;
+#endif
         return err;
     }
 
@@ -203,11 +235,15 @@
     flush_data.offset  = offset;
     flush_data.length  = size;
 
+#ifdef NEW_ION_API
     struct ion_custom_data d;
     d.cmd = ION_IOC_CLEAN_INV_CACHES;
     d.arg = (unsigned long int)&flush_data;
 
     if(ioctl(mIonFd, ION_IOC_CUSTOM, &d)) {
+#else
+    if(ioctl(mIonFd, ION_IOC_CLEAN_INV_CACHES, &flush_data)) {
+#endif
         err = -errno;
         ALOGE("%s: ION_IOC_CLEAN_INV_CACHES failed with error - %s",
 
diff --git a/libgralloc/mapper.cpp b/libgralloc/mapper.cpp
index b8e1526..4f28877 100644
--- a/libgralloc/mapper.cpp
+++ b/libgralloc/mapper.cpp
@@ -353,6 +353,7 @@
                 break;
 
             }
+#ifdef QCOM_BSP
         case GRALLOC_MODULE_PERFORM_UPDATE_BUFFER_GEOMETRY:
             {
                 int width = va_arg(args, int);
@@ -368,6 +369,7 @@
                 res = 0;
             }
             break;
+#endif
         default:
             break;
     }
diff --git a/libhwcomposer/hwc_copybit.cpp b/libhwcomposer/hwc_copybit.cpp
index e764c69..8ce9f0d 100644
--- a/libhwcomposer/hwc_copybit.cpp
+++ b/libhwcomposer/hwc_copybit.cpp
@@ -24,6 +24,11 @@
 #include "hwc_copybit.h"
 #include "comptype.h"
 
+//XXX: Remove HWC_BLIT
+#ifndef QCOM_BSP
+#define HWC_BLIT 4
+#endif
+
 namespace qhwc {
 
 struct range {
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index c51a6aa..3a241c8 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -418,7 +418,7 @@
     overlay::Overlay& ov = *ctx->mOverlay;
     int availablePipes = ov.availablePipes(dpy);
 
-    if(numAppLayers < 1 || numAppLayers > (uint32_t)availablePipes) {
+    if(numAppLayers < 1 || numAppLayers > availablePipes) {
         ALOGD_IF(isDebug(), "%s: Unsupported number of layers",__FUNCTION__);
         return false;
     }
diff --git a/liboverlay/overlayCtrlData.h b/liboverlay/overlayCtrlData.h
index c0d4c6d..0c49bdd 100644
--- a/liboverlay/overlayCtrlData.h
+++ b/liboverlay/overlayCtrlData.h
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2012, The Linux Foundation. All rights reserved.
+* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -93,6 +93,8 @@
     /* Get downscale factor */
     int getDownscalefactor();
 
+    /* Update the src format */
+    void updateSrcformat(const uint32_t& inputsrcFormat);
 
 private:
     /* Retrieve screen info from underlying mdp */
@@ -187,6 +189,10 @@
     return mMdp.getFd();
 }
 
+inline void Ctrl::updateSrcformat(const uint32_t& inputsrcFormat) {
+    mMdp.updateSrcformat(inputsrcFormat);
+}
+
 inline utils::ScreenInfo Ctrl::getScreenInfo() const {
     return mInfo;
 }
diff --git a/liboverlay/overlayMdp.cpp b/liboverlay/overlayMdp.cpp
index ee1aae7..8bca85f 100644
--- a/liboverlay/overlayMdp.cpp
+++ b/liboverlay/overlayMdp.cpp
@@ -1,6 +1,6 @@
 /*
 * Copyright (C) 2008 The Android Open Source Project
-* Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
+* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -15,6 +15,7 @@
 * limitations under the License.
 */
 
+#include <mdp_version.h>
 #include "overlayUtils.h"
 #include "overlayMdp.h"
 
@@ -249,10 +250,24 @@
             whf.w = utils::alignup(whf.w, 64);
             whf.h = utils::alignup(whf.h, 32);
         }
-        //For example: If original format is tiled, rotator outputs non-tiled,
-        //so update mdp's src fmt to that.
+        /*For example: If original format is tiled, rotator outputs non-tiled,
+         *so update mdp's src fmt to that.
+         */
         whf.format = utils::getRotOutFmt(whf.format);
         setSrcWhf(whf);
+        /* The above format will be overwritten in function updateSrcformat
+         * after doing rotator start. Format is then set depending on
+         * whether the fastyuv mode is used by the rotator.
+         */
+    }
+}
+
+void MdpCtrl::updateSrcformat(const uint32_t& inputformat) {
+    int version = qdutils::MDPVersion::getInstance().getMDPVersion();
+    if ((version >= qdutils::MDP_V4_2) && (version < qdutils::MDSS_V5)) {
+        utils::Whf whf = getSrcWhf();
+        whf.format =  inputformat;
+        setSrcWhf(whf);
     }
 }
 
diff --git a/liboverlay/overlayMdp.h b/liboverlay/overlayMdp.h
index 9df1a04..c1684fc 100644
--- a/liboverlay/overlayMdp.h
+++ b/liboverlay/overlayMdp.h
@@ -1,6 +1,6 @@
 /*
 * Copyright (C) 2008 The Android Open Source Project
-* Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
+* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
@@ -153,6 +153,9 @@
     /* Get downscale factor */
     int getDownscalefactor();
 
+    /* Update the src format */
+    void updateSrcformat(const uint32_t& inputsrcFormat);
+
 private:
 
     /* helper functions for overlayTransform */
diff --git a/liboverlay/overlayMdpRot.cpp b/liboverlay/overlayMdpRot.cpp
index 5052bc8..d0242d6 100644
--- a/liboverlay/overlayMdpRot.cpp
+++ b/liboverlay/overlayMdpRot.cpp
@@ -1,6 +1,6 @@
 /*
  * Copyright (C) 2008 The Android Open Source Project
- * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
+ * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
  * Not a Contribution, Apache license notifications and license are retained
  * for attribution purposes only.
  *
@@ -31,25 +31,29 @@
 
 MdpRot::~MdpRot() { close(); }
 
-void MdpRot::setEnable() { mRotImgInfo.enable = 1; }
+inline void MdpRot::setEnable() { mRotImgInfo.enable = 1; }
 
-void MdpRot::setDisable() { mRotImgInfo.enable = 0; }
+inline void MdpRot::setDisable() { mRotImgInfo.enable = 0; }
 
-bool MdpRot::enabled() const { return mRotImgInfo.enable; }
+inline bool MdpRot::enabled() const { return mRotImgInfo.enable; }
 
-void MdpRot::setRotations(uint32_t r) { mRotImgInfo.rotations = r; }
+inline void MdpRot::setRotations(uint32_t r) { mRotImgInfo.rotations = r; }
 
-int MdpRot::getDstMemId() const {
+inline int MdpRot::getDstMemId() const {
     return mRotDataInfo.dst.memory_id;
 }
 
-uint32_t MdpRot::getDstOffset() const {
+inline uint32_t MdpRot::getDstOffset() const {
     return mRotDataInfo.dst.offset;
 }
 
-uint32_t MdpRot::getSessId() const { return mRotImgInfo.session_id; }
+inline uint32_t MdpRot::getDstFormat() const {
+    return mRotImgInfo.dst.format;
+}
 
-void MdpRot::setSrcFB() {
+inline uint32_t MdpRot::getSessId() const { return mRotImgInfo.session_id; }
+
+inline void MdpRot::setSrcFB() {
     mRotDataInfo.src.flags |= MDP_MEMORY_ID_TYPE_FB;
 }
 
@@ -67,11 +71,11 @@
     mRotImgInfo.downscale_ratio = ds;
 }
 
-void MdpRot::save() {
+inline void MdpRot::save() {
     mLSRotImgInfo = mRotImgInfo;
 }
 
-bool MdpRot::rotConfChanged() const {
+inline bool MdpRot::rotConfChanged() const {
     // 0 means same
     if(0 == ::memcmp(&mRotImgInfo, &mLSRotImgInfo,
                 sizeof (msm_rotator_img_info))) {
@@ -111,13 +115,13 @@
     mBufSize = awhf.size;
 }
 
-void MdpRot::setFlags(const utils::eMdpFlags& flags) {
+inline void MdpRot::setFlags(const utils::eMdpFlags& flags) {
     mRotImgInfo.secure = 0;
     if(flags & utils::OV_MDP_SECURE_OVERLAY_SESSION)
         mRotImgInfo.secure = 1;
 }
 
-void MdpRot::setTransform(const utils::eTransform& rot)
+inline void MdpRot::setTransform(const utils::eTransform& rot)
 {
     int r = utils::getMdpOrient(rot);
     setRotations(r);
@@ -127,14 +131,14 @@
     ALOGE_IF(DEBUG_OVERLAY, "%s: r=%d", __FUNCTION__, r);
 }
 
-void MdpRot::setRotatorUsed(const bool& rotUsed) {
+inline void MdpRot::setRotatorUsed(const bool& rotUsed) {
     setDisable();
     if(rotUsed) {
         setEnable();
     }
 }
 
-void MdpRot::doTransform() {
+inline void MdpRot::doTransform() {
     if(mOrientation & utils::OVERLAY_TRANSFORM_ROT_90)
         utils::swap(mRotImgInfo.dst.width, mRotImgInfo.dst.height);
 }
diff --git a/liboverlay/overlayMdssRot.cpp b/liboverlay/overlayMdssRot.cpp
index c00e732..d9cdc03 100644
--- a/liboverlay/overlayMdssRot.cpp
+++ b/liboverlay/overlayMdssRot.cpp
@@ -43,29 +43,34 @@
 
 MdssRot::~MdssRot() { close(); }
 
-void MdssRot::setEnable() { mEnabled = true; }
+inline void MdssRot::setEnable() { mEnabled = true; }
 
-void MdssRot::setDisable() { mEnabled = false; }
+inline void MdssRot::setDisable() { mEnabled = false; }
 
-bool MdssRot::enabled() const { return mEnabled; }
+inline bool MdssRot::enabled() const { return mEnabled; }
 
-void MdssRot::setRotations(uint32_t flags) { mRotInfo.flags |= flags; }
+inline void MdssRot::setRotations(uint32_t flags) { mRotInfo.flags |= flags; }
 
-int MdssRot::getDstMemId() const {
+inline int MdssRot::getDstMemId() const {
     return mRotData.dst_data.memory_id;
 }
 
-uint32_t MdssRot::getDstOffset() const {
+inline uint32_t MdssRot::getDstOffset() const {
     return mRotData.dst_data.offset;
 }
 
-uint32_t MdssRot::getSessId() const { return mRotInfo.id; }
+inline uint32_t MdssRot::getDstFormat() const {
+    //For mdss src and dst formats are same
+    return mRotInfo.src.format;
+}
 
-void MdssRot::setSrcFB() {
+inline uint32_t MdssRot::getSessId() const { return mRotInfo.id; }
+
+inline void MdssRot::setSrcFB() {
     mRotData.data.flags |= MDP_MEMORY_ID_TYPE_FB;
 }
 
-bool MdssRot::init() {
+inline bool MdssRot::init() {
     if(!utils::openDev(mFd, 0, Res::fbPath, O_RDWR)) {
         ALOGE("MdssRot failed to init fb0");
         return false;
@@ -95,14 +100,13 @@
     mBufSize = awhf.size;
 }
 
-void MdssRot::setDownscale(int ds) {
-}
+inline void MdssRot::setDownscale(int ds) {}
 
-void MdssRot::setFlags(const utils::eMdpFlags& flags) {
+inline void MdssRot::setFlags(const utils::eMdpFlags& flags) {
     mRotInfo.flags |= flags;
 }
 
-void MdssRot::setTransform(const utils::eTransform& rot)
+inline void MdssRot::setTransform(const utils::eTransform& rot)
 {
     int flags = utils::getMdpOrient(rot);
     if (flags != -1)
@@ -113,14 +117,14 @@
     ALOGE_IF(DEBUG_OVERLAY, "%s: rot=%d", __FUNCTION__, flags);
 }
 
-void MdssRot::setRotatorUsed(const bool& rotUsed) {
+inline void MdssRot::setRotatorUsed(const bool& rotUsed) {
     setDisable();
     if(rotUsed) {
         setEnable();
     }
 }
 
-void MdssRot::doTransform() {
+inline void MdssRot::doTransform() {
     if(mOrientation & utils::OVERLAY_TRANSFORM_ROT_90)
         utils::swap(mRotInfo.dst_rect.w, mRotInfo.dst_rect.h);
 }
@@ -261,10 +265,22 @@
 }
 
 void MdssRot::setBufSize(int format) {
-    if (format == MDP_Y_CBCR_H2V2_VENUS) {
-        mBufSize = VENUS_BUFFER_SIZE(COLOR_FMT_NV12, mRotInfo.dst_rect.w,
-                                     mRotInfo.dst_rect.h);
+
+    switch (format) {
+        case MDP_Y_CBCR_H2V2_VENUS:
+            mBufSize = VENUS_BUFFER_SIZE(COLOR_FMT_NV12, mRotInfo.dst_rect.w,
+                                         mRotInfo.dst_rect.h);
+            break;
+
+        case MDP_Y_CR_CB_GH2V2:
+            int alignedw = utils::align(mRotInfo.dst_rect.w, 16);
+            int alignedh = mRotInfo.dst_rect.h;
+            mBufSize = (alignedw*alignedh) +
+                (utils::align(alignedw/2, 16) * (alignedh/2))*2;
+            mBufSize = utils::align(mBufSize, 4096);
+            break;
     }
+
     if (mRotInfo.flags & utils::OV_MDP_SECURE_OVERLAY_SESSION)
         mBufSize = utils::align(mBufSize, SIZE_1M);
 }
diff --git a/liboverlay/overlayRotator.h b/liboverlay/overlayRotator.h
index 118f71f..f1a60e1 100644
--- a/liboverlay/overlayRotator.h
+++ b/liboverlay/overlayRotator.h
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2011, The Linux Foundation. All rights reserved.
+* Copyright (c) 2011,2013 The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -55,6 +55,7 @@
     virtual void setDownscale(int ds) = 0;
     virtual int getDstMemId() const = 0;
     virtual uint32_t getDstOffset() const = 0;
+    virtual uint32_t getDstFormat() const = 0;
     virtual void setEnable() = 0;
     virtual void setDisable() = 0;
     virtual bool enabled () const = 0;
@@ -125,6 +126,7 @@
     virtual void setDownscale(int ds);
     virtual int getDstMemId() const;
     virtual uint32_t getDstOffset() const;
+    virtual uint32_t getDstFormat() const;
     virtual void setEnable();
     virtual void setDisable();
     virtual bool enabled () const;
@@ -186,6 +188,7 @@
     virtual void setDownscale(int ds);
     virtual int getDstMemId() const;
     virtual uint32_t getDstOffset() const;
+    virtual uint32_t getDstFormat() const;
     virtual void setEnable();
     virtual void setDisable();
     virtual bool enabled () const;
diff --git a/liboverlay/overlayUtils.cpp b/liboverlay/overlayUtils.cpp
index 49a1eaf..9bffff0 100644
--- a/liboverlay/overlayUtils.cpp
+++ b/liboverlay/overlayUtils.cpp
@@ -330,6 +330,11 @@
     return fmt3D;
 }
 
+bool isMdssRotator() {
+    int mdpVersion = qdutils::MDPVersion::getInstance().getMDPVersion();
+    return (mdpVersion >= qdutils::MDSS_V5);
+}
+
 } // utils
 
 } // overlay
diff --git a/liboverlay/overlayUtils.h b/liboverlay/overlayUtils.h
index 2f6832d..2f83374 100644
--- a/liboverlay/overlayUtils.h
+++ b/liboverlay/overlayUtils.h
@@ -178,6 +178,7 @@
 bool send3DInfoPacket (uint32_t fmt);
 bool enableBarrier (uint32_t orientation);
 uint32_t getS3DFormat(uint32_t fmt);
+bool isMdssRotator();
 
 template <int CHAN>
 bool getPositionS3D(const Whf& whf, Dim& out);
@@ -587,6 +588,10 @@
 }
 
 inline int getRotOutFmt(uint32_t format) {
+
+    if (isMdssRotator())
+        return format;
+
     switch (format) {
         case MDP_Y_CRCB_H2V2_TILE:
             return MDP_Y_CRCB_H2V2;
diff --git a/liboverlay/pipes/overlayGenPipe.cpp b/liboverlay/pipes/overlayGenPipe.cpp
index aaaa0f1..0b864df 100644
--- a/liboverlay/pipes/overlayGenPipe.cpp
+++ b/liboverlay/pipes/overlayGenPipe.cpp
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2012, The Linux Foundation. All rights reserved.
+* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -166,6 +166,11 @@
             pipeState = CLOSED;
             return false;
         }
+        /* Set the mdp src format to the output format of the rotator.
+         * The output format of the rotator might be different depending on
+         * whether fastyuv mode is enabled in the rotator.
+         */
+        mCtrlData.ctrl.updateSrcformat(mRot->getDstFormat());
     }
 
     ret = mCtrlData.ctrl.commit();