Merge branch 'LA.BF.1.1.3_rb1.5' of git://codeaurora.org/platform/hardware/qcom/display into cm-13.0
diff --git a/Android.mk b/Android.mk
index 9876350..67a49a1 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,6 +1,11 @@
-display-hals := libgralloc libgenlock libcopybit liblight libvirtual
+ifeq ($(call my-dir),$(call project-path-for,qcom-display))
+
+display-hals := libgralloc libgenlock libcopybit libvirtual
 display-hals += libhwcomposer liboverlay libqdutils libhdmi libqservice
 display-hals += libmemtrack
+ifneq ($(TARGET_PROVIDES_LIBLIGHT),true)
+display-hals += liblight
+endif
 ifeq ($(call is-vendor-board-platform,QCOM),true)
     include $(call all-named-subdir-makefiles,$(display-hals))
 else
@@ -9,3 +14,5 @@
     include $(call all-named-subdir-makefiles,$(display-hals))
 endif
 endif
+
+endif
diff --git a/common.mk b/common.mk
index cdf660c..93bd35e 100644
--- a/common.mk
+++ b/common.mk
@@ -1,13 +1,13 @@
 #Common headers
-common_includes := hardware/qcom/display/libgralloc
-common_includes += hardware/qcom/display/liboverlay
-common_includes += hardware/qcom/display/libcopybit
-common_includes += hardware/qcom/display/libqdutils
-common_includes += hardware/qcom/display/libhwcomposer
-common_includes += hardware/qcom/display/libexternal
-common_includes += hardware/qcom/display/libqservice
-common_includes += hardware/qcom/display/libvirtual
-common_includes += hardware/qcom/display/libhdmi
+common_includes := $(call project-path-for,qcom-display)/libgralloc
+common_includes += $(call project-path-for,qcom-display)/liboverlay
+common_includes += $(call project-path-for,qcom-display)/libcopybit
+common_includes += $(call project-path-for,qcom-display)/libqdutils
+common_includes += $(call project-path-for,qcom-display)/libhwcomposer
+common_includes += $(call project-path-for,qcom-display)/libexternal
+common_includes += $(call project-path-for,qcom-display)/libqservice
+common_includes += $(call project-path-for,qcom-display)/libvirtual
+common_includes += $(call project-path-for,qcom-display)/libhdmi
 
 ifeq ($(TARGET_USES_POST_PROCESSING),true)
     common_flags     += -DUSES_POST_PROCESSING
diff --git a/libcopybit/copybit.cpp b/libcopybit/copybit.cpp
index 8a44f3c..0811c35 100644
--- a/libcopybit/copybit.cpp
+++ b/libcopybit/copybit.cpp
@@ -73,22 +73,22 @@
                         struct hw_device_t** device);
 
 static struct hw_module_methods_t copybit_module_methods = {
-open:  open_copybit
+    .open = open_copybit
 };
 
 /*
  * The COPYBIT Module
  */
 struct copybit_module_t HAL_MODULE_INFO_SYM = {
-common: {
-tag: HARDWARE_MODULE_TAG,
-     version_major: 1,
-     version_minor: 0,
-     id: COPYBIT_HARDWARE_MODULE_ID,
-     name: "QCT MSM7K COPYBIT Module",
-     author: "Google, Inc.",
-     methods: &copybit_module_methods
-        }
+    .common = {
+        .tag = HARDWARE_MODULE_TAG,
+        .version_major = 1,
+        .version_minor = 0,
+        .id = COPYBIT_HARDWARE_MODULE_ID,
+        .name = "QCT MSM7K COPYBIT Module",
+        .author = "Google, Inc.",
+        .methods = &copybit_module_methods
+    }
 };
 
 /******************************************************************************/
diff --git a/libcopybit/copybit_c2d.cpp b/libcopybit/copybit_c2d.cpp
index bbc21fa..f6ebdd7 100644
--- a/libcopybit/copybit_c2d.cpp
+++ b/libcopybit/copybit_c2d.cpp
@@ -194,22 +194,22 @@
                         struct hw_device_t** device);
 
 static struct hw_module_methods_t copybit_module_methods = {
-open:  open_copybit
+    .open = open_copybit
 };
 
 /*
  * The COPYBIT Module
  */
 struct copybit_module_t HAL_MODULE_INFO_SYM = {
-common: {
-tag: HARDWARE_MODULE_TAG,
-     version_major: 1,
-     version_minor: 0,
-     id: COPYBIT_HARDWARE_MODULE_ID,
-     name: "QCT COPYBIT C2D 2.0 Module",
-     author: "Qualcomm",
-     methods: &copybit_module_methods
-        }
+    .common = {
+        .tag = HARDWARE_MODULE_TAG,
+        .version_major = 1,
+        .version_minor = 0,
+        .id = COPYBIT_HARDWARE_MODULE_ID,
+        .name = "QCT COPYBIT C2D 2.0 Module",
+        .author = "Qualcomm",
+        .methods = &copybit_module_methods
+    }
 };
 
 
diff --git a/libgralloc/Android.mk b/libgralloc/Android.mk
index a879c5c..a1937d1 100644
--- a/libgralloc/Android.mk
+++ b/libgralloc/Android.mk
@@ -29,6 +29,10 @@
 LOCAL_COPY_HEADERS_TO         := $(common_header_export_path)
 LOCAL_COPY_HEADERS            := gralloc_priv.h
 
+ifeq ($(TARGET_USE_COMPAT_GRALLOC_PERFORM),true)
+LOCAL_CFLAGS += -DGRALLOC_PERFORM_COMPAT
+endif
+
 include $(BUILD_SHARED_LIBRARY)
 
 # MemAlloc Library
diff --git a/libgralloc/alloc_controller.cpp b/libgralloc/alloc_controller.cpp
index 72bb39a..ff62c6e 100644
--- a/libgralloc/alloc_controller.cpp
+++ b/libgralloc/alloc_controller.cpp
@@ -159,7 +159,7 @@
                 aligned_w = LINK_adreno_compute_padding(width, bpp,
                                      surface_tile_height, raster_mode,
                                      padding_threshold);
-                ALOGW("%s: Warning!! Old GFX API is used to calculate stride",
+                ALOGV("%s: Warning!! Old GFX API is used to calculate stride",
                                                             __FUNCTION__);
             } else {
                 ALOGW("%s: Warning!! Symbols compute_surface_padding and " \
diff --git a/libgralloc/framebuffer.cpp b/libgralloc/framebuffer.cpp
index a7a58dc..f0fb850 100644
--- a/libgralloc/framebuffer.cpp
+++ b/libgralloc/framebuffer.cpp
@@ -99,7 +99,7 @@
     return 0;
 }
 
-static int fb_compositionComplete(struct framebuffer_device_t* dev)
+static int fb_compositionComplete(struct framebuffer_device_t* /*dev*/)
 {
     // TODO: Properly implement composition complete callback
     glFinish();
diff --git a/libgralloc/gpu.cpp b/libgralloc/gpu.cpp
index 75f20b9..fbdf882 100644
--- a/libgralloc/gpu.cpp
+++ b/libgralloc/gpu.cpp
@@ -66,8 +66,9 @@
 
     /* force 1MB alignment selectively for secure buffers, MDP5 onwards */
 #ifdef MDSS_TARGET
-    if (usage & GRALLOC_USAGE_PROTECTED) {
-        data.align = ALIGN(data.align, SZ_1M);
+    if ((usage & GRALLOC_USAGE_PROTECTED) &&
+        (usage & GRALLOC_USAGE_PRIVATE_MM_HEAP)) {
+        data.align = ALIGN((int) data.align, SZ_1M);
         size = ALIGN(size, data.align);
     }
 #endif
@@ -186,7 +187,7 @@
     }
 }
 
-int gpu_context_t::gralloc_alloc_framebuffer_locked(size_t size, int usage,
+int gpu_context_t::gralloc_alloc_framebuffer_locked(size_t /*size*/, int usage,
                                                     buffer_handle_t* pHandle)
 {
     private_module_t* m = reinterpret_cast<private_module_t*>(common.module);
diff --git a/libgralloc/gralloc.cpp b/libgralloc/gralloc.cpp
index 6334450..942ed8a 100644
--- a/libgralloc/gralloc.cpp
+++ b/libgralloc/gralloc.cpp
@@ -63,37 +63,37 @@
 
 // HAL module methods
 static struct hw_module_methods_t gralloc_module_methods = {
-    open: gralloc_device_open
+    .open = gralloc_device_open
 };
 
 // HAL module initialize
 struct private_module_t HAL_MODULE_INFO_SYM = {
-    base: {
-        common: {
-            tag: HARDWARE_MODULE_TAG,
-            version_major: 1,
-            version_minor: 0,
-            id: GRALLOC_HARDWARE_MODULE_ID,
-            name: "Graphics Memory Allocator Module",
-            author: "The Android Open Source Project",
-            methods: &gralloc_module_methods,
-            dso: 0,
-            reserved: {0},
+    .base = {
+        .common = {
+            .tag = HARDWARE_MODULE_TAG,
+            .version_major = 1,
+            .version_minor = 0,
+            .id = GRALLOC_HARDWARE_MODULE_ID,
+            .name = "Graphics Memory Allocator Module",
+            .author = "The Android Open Source Project",
+            .methods = &gralloc_module_methods,
+            .dso = 0,
+            .reserved = {0},
         },
-        registerBuffer: gralloc_register_buffer,
-        unregisterBuffer: gralloc_unregister_buffer,
-        lock: gralloc_lock,
-        unlock: gralloc_unlock,
-        perform: gralloc_perform,
-        lock_ycbcr: gralloc_lock_ycbcr,
+        .registerBuffer = gralloc_register_buffer,
+        .unregisterBuffer = gralloc_unregister_buffer,
+        .lock = gralloc_lock,
+        .unlock = gralloc_unlock,
+        .perform = gralloc_perform,
+        .lock_ycbcr = gralloc_lock_ycbcr,
     },
-    framebuffer: 0,
-    fbFormat: 0,
-    flags: 0,
-    numBuffers: 0,
-    bufferMask: 0,
-    lock: PTHREAD_MUTEX_INITIALIZER,
-    currentBuffer: 0,
+    .framebuffer = 0,
+    .fbFormat = 0,
+    .flags = 0,
+    .numBuffers = 0,
+    .bufferMask = 0,
+    .lock = PTHREAD_MUTEX_INITIALIZER,
+    .currentBuffer = 0,
 };
 
 // Open Gralloc device
diff --git a/libgralloc/mapper.cpp b/libgralloc/mapper.cpp
index bf698e6..8464d86 100644
--- a/libgralloc/mapper.cpp
+++ b/libgralloc/mapper.cpp
@@ -55,7 +55,7 @@
     return memalloc;
 }
 
-static int gralloc_map(gralloc_module_t const* module,
+static int gralloc_map(gralloc_module_t const* /*module*/,
                        buffer_handle_t handle)
 {
     private_handle_t* hnd = (private_handle_t*)handle;
@@ -89,7 +89,7 @@
     return 0;
 }
 
-static int gralloc_unmap(gralloc_module_t const* module,
+static int gralloc_unmap(gralloc_module_t const* /*module*/,
                          buffer_handle_t handle)
 {
     private_handle_t* hnd = (private_handle_t*)handle;
@@ -261,7 +261,7 @@
     return err;
 }
 
-int gralloc_unlock(gralloc_module_t const* module,
+int gralloc_unlock(gralloc_module_t const* /*module*/,
                    buffer_handle_t handle)
 {
     if (private_handle_t::validate(handle) < 0)
@@ -282,7 +282,7 @@
 
 /*****************************************************************************/
 
-int gralloc_perform(struct gralloc_module_t const* module,
+int gralloc_perform(struct gralloc_module_t const* /*module*/,
                     int operation, ... )
 {
     int res = -EINVAL;
@@ -333,17 +333,23 @@
             {
                 private_handle_t* hnd =  va_arg(args, private_handle_t*);
                 int *stride = va_arg(args, int *);
+#ifndef GRALLOC_PERFORM_COMPAT
                 int *height = va_arg(args, int *);
+#endif
                 if (private_handle_t::validate(hnd)) {
                     return res;
                 }
                 MetaData_t *metadata = (MetaData_t *)hnd->base_metadata;
                 if(metadata && metadata->operation & UPDATE_BUFFER_GEOMETRY) {
                     *stride = metadata->bufferDim.sliceWidth;
+#ifndef GRALLOC_PERFORM_COMPAT
                     *height = metadata->bufferDim.sliceHeight;
+#endif
                 } else {
                     *stride = hnd->width;
+#ifndef GRALLOC_PERFORM_COMPAT
                     *height = hnd->height;
+#endif
                 }
                 res = 0;
             } break;
diff --git a/libhwcomposer/hwc.cpp b/libhwcomposer/hwc.cpp
index a02b3f6..2d2dbfd 100644
--- a/libhwcomposer/hwc.cpp
+++ b/libhwcomposer/hwc.cpp
@@ -52,22 +52,22 @@
                            struct hw_device_t** device);
 
 static struct hw_module_methods_t hwc_module_methods = {
-    open: hwc_device_open
+    .open = hwc_device_open
 };
 
 static void reset_panel(struct hwc_composer_device_1* dev);
 
 hwc_module_t HAL_MODULE_INFO_SYM = {
-    common: {
-        tag: HARDWARE_MODULE_TAG,
-        version_major: 2,
-        version_minor: 0,
-        id: HWC_HARDWARE_MODULE_ID,
-        name: "Qualcomm Hardware Composer Module",
-        author: "CodeAurora Forum",
-        methods: &hwc_module_methods,
-        dso: 0,
-        reserved: {0},
+    .common = {
+        .tag = HARDWARE_MODULE_TAG,
+        .version_major = 2,
+        .version_minor = 0,
+        .id = HWC_HARDWARE_MODULE_ID,
+        .name = "Qualcomm Hardware Composer Module",
+        .author = "CodeAurora Forum",
+        .methods = &hwc_module_methods,
+        .dso = 0,
+        .reserved = {0},
     }
 };
 
@@ -426,8 +426,15 @@
             value = FB_BLANK_POWERDOWN;
             break;
         case HWC_POWER_MODE_DOZE:
+            // FB_BLANK_NORMAL is being used here to map to doze mode
+            // This definition is specific to our fbdev implementation
+            value = FB_BLANK_NORMAL;
+            break;
         case HWC_POWER_MODE_DOZE_SUSPEND:
-            //Need to set valid power mode - FB_BLANK_VSYNC_SUSPEND
+            // FB_BLANK_VSYNC_SUSPEND is being used here to map to doze_suspend
+            // This definition is specific to our fbdev implementation
+            value = FB_BLANK_VSYNC_SUSPEND;
+            break;
         case HWC_POWER_MODE_NORMAL:
             value = FB_BLANK_UNBLANK;
             break;
@@ -448,7 +455,8 @@
             ctx->mHPDEnabled = true;
         }
 
-        ctx->dpyAttr[dpy].isActive =  not(mode == HWC_POWER_MODE_OFF);
+        ctx->dpyAttr[dpy].isActive = not(mode == HWC_POWER_MODE_OFF ||
+                mode == HWC_POWER_MODE_DOZE_SUSPEND);
 
         if(ctx->mVirtualonExtActive) {
             /* if mVirtualonExtActive is true, display hal will
@@ -461,24 +469,6 @@
         //Deliberate fall through since there is no explicit power mode for
         //virtual displays.
     case HWC_DISPLAY_VIRTUAL:
-        /* There are two ways to reach this block of code.
-
-         * Display hal has received unblank call on HWC_DISPLAY_EXTERNAL
-         and ctx->mVirtualonExtActive is true. In this case, non-hybrid
-         WFD is active. If so, getDpyforExternalDisplay will return dpy
-         as HWC_DISPLAY_VIRTUAL.
-
-         * Display hal has received unblank call on HWC_DISPLAY_PRIMARY
-         and since SF is not aware of VIRTUAL DISPLAY being handle by HWC,
-         it wont send blank / unblank events for it. We piggyback on
-         PRIMARY DISPLAY events to release mdp pipes and
-         activate/deactivate VIRTUAL DISPLAY.
-
-         * TODO: This separate case statement is not needed once we have
-         WFD client working on top of Google API's.
-
-         */
-
         if(ctx->dpyAttr[HWC_DISPLAY_VIRTUAL].connected) {
             const int dpy = HWC_DISPLAY_VIRTUAL;
             if(mode == HWC_POWER_MODE_OFF and
diff --git a/libhwcomposer/hwc_ad.cpp b/libhwcomposer/hwc_ad.cpp
index d3aee80..e591401 100644
--- a/libhwcomposer/hwc_ad.cpp
+++ b/libhwcomposer/hwc_ad.cpp
@@ -256,12 +256,12 @@
     return true;
 }
 
-int AssertiveDisplay::getDstFd(hwc_context_t *ctx) const {
+int AssertiveDisplay::getDstFd(hwc_context_t * /*ctx*/) const {
     overlay::Writeback *wb = overlay::Writeback::getInstance();
     return wb->getDstFd();
 }
 
-uint32_t AssertiveDisplay::getDstOffset(hwc_context_t *ctx) const {
+uint32_t AssertiveDisplay::getDstOffset(hwc_context_t * /*ctx*/) const {
     overlay::Writeback *wb = overlay::Writeback::getInstance();
     return wb->getOffset();
 }
diff --git a/libhwcomposer/hwc_copybit.cpp b/libhwcomposer/hwc_copybit.cpp
index cc17a67..e2b45af 100644
--- a/libhwcomposer/hwc_copybit.cpp
+++ b/libhwcomposer/hwc_copybit.cpp
@@ -764,7 +764,7 @@
 
 
 int  CopyBit::drawLayerUsingCopybit(hwc_context_t *dev, hwc_layer_1_t *layer,
-                          private_handle_t *renderBuffer, int dpy, bool isFG)
+                          private_handle_t *renderBuffer, int /*dpy*/, bool isFG)
 {
     hwc_context_t* ctx = (hwc_context_t*)(dev);
     int err = 0, acquireFd;
diff --git a/libhwcomposer/hwc_dump_layers.cpp b/libhwcomposer/hwc_dump_layers.cpp
index 9977367..680c259 100644
--- a/libhwcomposer/hwc_dump_layers.cpp
+++ b/libhwcomposer/hwc_dump_layers.cpp
@@ -373,65 +373,65 @@
 
     switch(format) {
         case HAL_PIXEL_FORMAT_RGBA_8888:
-            strlcpy(pixFormatStr, "RGBA_8888", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "RGBA_8888", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_RGBX_8888:
-            strlcpy(pixFormatStr, "RGBX_8888", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "RGBX_8888", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_RGB_888:
-            strlcpy(pixFormatStr, "RGB_888", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "RGB_888", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_RGB_565:
-            strlcpy(pixFormatStr, "RGB_565", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "RGB_565", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_BGRA_8888:
-            strlcpy(pixFormatStr, "BGRA_8888", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "BGRA_8888", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_YV12:
-            strlcpy(pixFormatStr, "YV12", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "YV12", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_YCbCr_422_SP:
-            strlcpy(pixFormatStr, "YCbCr_422_SP_NV16", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "YCbCr_422_SP_NV16", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_YCrCb_420_SP:
-            strlcpy(pixFormatStr, "YCrCb_420_SP_NV21", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "YCrCb_420_SP_NV21", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_YCbCr_422_I:
-            strlcpy(pixFormatStr, "YCbCr_422_I_YUY2", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "YCbCr_422_I_YUY2", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_YCrCb_422_I:
-            strlcpy(pixFormatStr, "YCrCb_422_I_YVYU", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "YCrCb_422_I_YVYU", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
-            strlcpy(pixFormatStr, "NV12_ENCODEABLE", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "NV12_ENCODEABLE", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
             strlcpy(pixFormatStr, "YCbCr_420_SP_TILED_TILE_4x2",
-                   sizeof(pixFormatStr));
+                   strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_YCbCr_420_SP:
-            strlcpy(pixFormatStr, "YCbCr_420_SP", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "YCbCr_420_SP", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
-            strlcpy(pixFormatStr, "YCrCb_420_SP_ADRENO", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "YCrCb_420_SP_ADRENO", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_YCrCb_422_SP:
-            strlcpy(pixFormatStr, "YCrCb_422_SP", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "YCrCb_422_SP", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_R_8:
-            strlcpy(pixFormatStr, "R_8", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "R_8", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_RG_88:
-            strlcpy(pixFormatStr, "RG_88", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "RG_88", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_INTERLACE:
-            strlcpy(pixFormatStr, "INTERLACE", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "INTERLACE", strlen(pixFormatStr));
             break;
         case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
-            strlcpy(pixFormatStr, "YCbCr_420_SP_VENUS", sizeof(pixFormatStr));
+            strlcpy(pixFormatStr, "YCbCr_420_SP_VENUS", strlen(pixFormatStr));
             break;
         default:
-            size_t len = sizeof(pixFormatStr);
+            size_t len = strlen(pixFormatStr);
             snprintf(pixFormatStr, len, "Unknown0x%X", format);
             break;
     }
diff --git a/libhwcomposer/hwc_fbupdate.cpp b/libhwcomposer/hwc_fbupdate.cpp
index d94ca88..cdcf79a 100644
--- a/libhwcomposer/hwc_fbupdate.cpp
+++ b/libhwcomposer/hwc_fbupdate.cpp
@@ -95,8 +95,7 @@
             mRot = NULL;
             return false;
         }
-        info.format = (mRot)->getDstFormat();
-        updateSource(orient, info, sourceCrop);
+        updateSource(orient, info, sourceCrop, mRot);
         rotFlags |= ovutils::ROT_PREROTATED;
     }
     return true;
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index c713ab8..d921f8f 100755
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -28,6 +28,8 @@
 #include <overlayRotator.h>
 #include "hwc_copybit.h"
 
+#include <utils/Vector.h>
+
 using namespace overlay;
 using namespace qdutils;
 using namespace overlay::utils;
@@ -114,9 +116,13 @@
             sDebugLogs = true;
     }
 
-    if(property_get("persist.hwc.partialupdate", property, NULL) > 0) {
-        if((atoi(property) != 0) && ctx->mMDP.panel == MIPI_CMD_PANEL &&
-           qdutils::MDPVersion::getInstance().is8x74v2())
+    // We read from drivers if panel supports partial updating
+    // and we enable partial update computations if supported.
+    // Keeping this property to disable partial update for
+    // debugging by setting below property to 0 & only 0.
+    property_get("persist.hwc.partialupdate", property, "-1");
+    if((atoi(property) != 0) &&
+        qdutils::MDPVersion::getInstance().isPartialUpdateEnabled()) {
             sEnablePartialFrameUpdate = true;
     }
     ALOGE_IF(isDebug(), "%s: Partial Update applicable?: %d",__FUNCTION__,
@@ -240,11 +246,12 @@
 }
 
 MDPComp::FrameInfo::FrameInfo() {
+    memset(&mdpToLayer, 0, sizeof(mdpToLayer));
     reset(0);
 }
 
 void MDPComp::FrameInfo::reset(const int& numLayers) {
-    for(int i = 0 ; i < MAX_PIPES_PER_MIXER && numLayers; i++ ) {
+    for(int i = 0; i < MAX_PIPES_PER_MIXER; i++) {
         if(mdpToLayer[i].pipeInfo) {
             delete mdpToLayer[i].pipeInfo;
             mdpToLayer[i].pipeInfo = NULL;
@@ -331,9 +338,9 @@
 bool MDPComp::isSupportedForMDPComp(hwc_context_t *ctx, hwc_layer_1_t* layer) {
     private_handle_t *hnd = (private_handle_t *)layer->handle;
     if((not isYuvBuffer(hnd) and has90Transform(layer)) or
-        (not isValidDimension(ctx,layer))
-        //More conditions here, SKIP, sRGB+Blend etc
-        ) {
+        (not isValidDimension(ctx,layer)) ||
+        isSkipLayer(layer)) {
+        //More conditions here, sRGB+Blend etc
         return false;
     }
     return true;
@@ -348,7 +355,7 @@
             // Color layer
             return true;
         }
-        ALOGE("%s: layer handle is NULL", __FUNCTION__);
+        ALOGD_IF(isDebug(), "%s: layer handle is NULL", __FUNCTION__);
         return false;
     }
 
@@ -595,13 +602,6 @@
         return false;
     }
 
-    if(isSkipPresent(ctx, mDpy)) {
-        ALOGD_IF(isDebug(),"%s: SKIP present: %d",
-                __FUNCTION__,
-                isSkipPresent(ctx, mDpy));
-        return false;
-    }
-
     if(!mDpy && isSecondaryAnimating(ctx) &&
        (isYuvPresent(ctx,HWC_DISPLAY_EXTERNAL) ||
        isYuvPresent(ctx,HWC_DISPLAY_VIRTUAL)) ) {
@@ -821,7 +821,7 @@
         return false;
     }
     private_handle_t *renderBuf = ctx->mCopyBit[mDpy]->getCurrentRenderBuffer();
-    Whf layerWhf[numPTORLayersFound]; // To store w,h,f of PTOR layers
+    Vector<Whf> layerWhf; // To store w,h,f of PTOR layers
 
     // Store the blending mode, planeAlpha, and transform of PTOR layers
     int32_t blending[numPTORLayersFound];
@@ -841,7 +841,7 @@
         // Store & update w, h, format of PTOR layer
         private_handle_t *hnd = (private_handle_t *)layer->handle;
         Whf whf(hnd->width, hnd->height, hnd->format, hnd->size);
-        layerWhf[j] = whf;
+        layerWhf.insertAt(whf, j);
         hnd->width = renderBuf->width;
         hnd->height = renderBuf->height;
         hnd->format = renderBuf->format;
@@ -904,9 +904,10 @@
         int idx = ctx->mPtorInfo.layerIndex[i];
         hwc_layer_1_t* layer = &list->hwLayers[idx];
         private_handle_t *hnd = (private_handle_t *)list->hwLayers[idx].handle;
-        hnd->width = layerWhf[i].w;
-        hnd->height = layerWhf[i].h;
-        hnd->format = layerWhf[i].format;
+        Whf whf = layerWhf.itemAt(i);
+        hnd->width = whf.w;
+        hnd->height = whf.h;
+        hnd->format = whf.format;
         layer->blending = blending[i];
         layer->planeAlpha = planeAlpha[i];
         layer->transform = transform[i];
@@ -934,7 +935,8 @@
     }
 
     bool ret = false;
-    if(list->flags & HWC_GEOMETRY_CHANGED) { //Try load based first
+    if(isSkipPresent(ctx, mDpy) or list->flags & HWC_GEOMETRY_CHANGED) {
+        //Try load based first
         ret =   loadBasedComp(ctx, list) or
                 cacheBasedComp(ctx, list);
     } else {
@@ -1082,9 +1084,8 @@
 }
 
 bool MDPComp::isLoadBasedCompDoable(hwc_context_t *ctx,
-        hwc_display_contents_1_t* list) {
-    if(mDpy or isSecurePresent(ctx, mDpy) or
-            isYuvPresent(ctx, mDpy)) {
+        hwc_display_contents_1_t* /*list*/) {
+    if(mDpy or isSecurePresent(ctx, mDpy)) {
         return false;
     }
     return true;
@@ -1462,8 +1463,8 @@
     return true;
 }
 
-bool MDPComp::resourceCheck(hwc_context_t *ctx,
-        hwc_display_contents_1_t *list) {
+bool MDPComp::resourceCheck(hwc_context_t * /*ctx*/,
+        hwc_display_contents_1_t * /*list*/) {
     const bool fbUsed = mCurrentFrame.fbCount;
     if(mCurrentFrame.mdpCount > sMaxPipesPerMixer - fbUsed) {
         ALOGD_IF(isDebug(), "%s: Exceeds MAX_PIPES_PER_MIXER",__FUNCTION__);
diff --git a/libhwcomposer/hwc_qclient.cpp b/libhwcomposer/hwc_qclient.cpp
index 8daf3cb..a73c73c 100644
--- a/libhwcomposer/hwc_qclient.cpp
+++ b/libhwcomposer/hwc_qclient.cpp
@@ -96,13 +96,17 @@
     return result;
 }
 
-static android::status_t vpuCommand(hwc_context_t *ctx,
+static android::status_t vpuCommand(hwc_context_t * /*ctx*/,
         uint32_t command,
         const Parcel* inParcel,
         Parcel* outParcel) {
     status_t result = NO_INIT;
 #ifdef VPU_TARGET
     result = ctx->mVPUClient->processCommand(command, inParcel, outParcel);
+#else
+    (void)command;
+    (void)inParcel;
+    (void)outParcel;
 #endif
     return result;
 }
@@ -128,7 +132,7 @@
     //XXX: Need to check what to return for HDMI
     outParcel->writeInt32(ctx->mMDP.panel);
 }
-static void setHSIC(hwc_context_t* ctx, const Parcel* inParcel) {
+static void setHSIC(hwc_context_t* /*ctx*/, const Parcel* inParcel) {
     int dpy = inParcel->readInt32();
     HSICData_t hsic_data;
     hsic_data.hue = inParcel->readInt32();
diff --git a/libhwcomposer/hwc_utils.cpp b/libhwcomposer/hwc_utils.cpp
index 036651b..7f9aab1 100644
--- a/libhwcomposer/hwc_utils.cpp
+++ b/libhwcomposer/hwc_utils.cpp
@@ -403,12 +403,42 @@
 #endif
 }
 
-//Helper to roundoff the refreshrates
+uint32_t getRefreshRate(hwc_context_t* ctx, uint32_t requestedRefreshRate) {
+
+    qdutils::MDPVersion& mdpHw = qdutils::MDPVersion::getInstance();
+    int dpy = HWC_DISPLAY_PRIMARY;
+    uint32_t defaultRefreshRate = ctx->dpyAttr[dpy].refreshRate;
+    uint32_t rate = defaultRefreshRate;
+
+    if(!requestedRefreshRate)
+        return defaultRefreshRate;
+
+    uint32_t maxNumIterations =
+            (uint32_t)ceil(
+                    (float)mdpHw.getMaxFpsSupported()/
+                    (float)requestedRefreshRate);
+
+    for(uint32_t i = 1; i <= maxNumIterations; i++) {
+        rate = i * roundOff(requestedRefreshRate);
+        if(rate < mdpHw.getMinFpsSupported()) {
+            continue;
+        } else if((rate >= mdpHw.getMinFpsSupported() &&
+                   rate <= mdpHw.getMaxFpsSupported())) {
+            break;
+        } else {
+            rate = defaultRefreshRate;
+            break;
+        }
+    }
+    return rate;
+}
+
+//Helper to roundoff the refreshrates to the std refresh-rates
 uint32_t roundOff(uint32_t refreshRate) {
     int count =  (int) (sizeof(stdRefreshRates)/sizeof(stdRefreshRates[0]));
     uint32_t rate = refreshRate;
     for(int i=0; i< count; i++) {
-        if(abs(stdRefreshRates[i] - refreshRate) < 2) {
+        if((stdRefreshRates[i] - refreshRate) < 2) {
             // Most likely used for video, the fps can fluctuate
             // Ex: b/w 29 and 30 for 30 fps clip
             rate = stdRefreshRates[i];
@@ -970,21 +1000,18 @@
 
 #ifdef DYNAMIC_FPS
         if (!dpy && mdpHw.isDynFpsSupported() && ctx->mUseMetaDataRefreshRate){
-            //dyn fps: get refreshrate from metadata
-            //Support multiple refresh rates if they are same
-            //else set to  default
+            /* Dyn fps: get refreshrate from metadata */
             MetaData_t *mdata = hnd ? (MetaData_t *)hnd->base_metadata : NULL;
             if (mdata && (mdata->operation & UPDATE_REFRESH_RATE)) {
                 // Valid refreshRate in metadata and within the range
-                uint32_t rate = roundOff(mdata->refreshrate);
-                if((rate >= mdpHw.getMinFpsSupported() &&
-                                rate <= mdpHw.getMaxFpsSupported())) {
-                    if (!refreshRate) {
-                        refreshRate = rate;
-                    } else if(refreshRate != rate) {
-                        // multiple refreshrate requests, set to default
-                        refreshRate = ctx->dpyAttr[dpy].refreshRate;
-                    }
+                uint32_t rate = getRefreshRate(ctx, mdata->refreshrate);
+                if (!refreshRate) {
+                    refreshRate = rate;
+                } else if(refreshRate != rate) {
+                    /* Support multiple refresh rates if they are same
+                     * else set to default.
+                     */
+                    refreshRate = ctx->dpyAttr[dpy].refreshRate;
                 }
             }
         }
@@ -1291,8 +1318,8 @@
    return res;
 }
 
-void optimizeLayerRects(hwc_context_t *ctx,
-                        const hwc_display_contents_1_t *list, const int& dpy) {
+void optimizeLayerRects(hwc_context_t * /*ctx*/,
+                        const hwc_display_contents_1_t *list, const int& /*dpy*/) {
     int i=list->numHwLayers-2;
     hwc_rect_t irect;
     while(i > 0) {
@@ -1639,18 +1666,8 @@
 
     if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
         qdutils::MDSS_V5) {
-        uint32_t crop_w = (crop.right - crop.left);
-        uint32_t crop_h = (crop.bottom - crop.top);
-        if (ovutils::isYuv(whf.format)) {
-            ovutils::normalizeCrop((uint32_t&)crop.left, crop_w);
-            ovutils::normalizeCrop((uint32_t&)crop.top, crop_h);
-            // For interlaced, crop.h should be 4-aligned
-            if ((mdpFlags & ovutils::OV_MDP_DEINTERLACE) && (crop_h % 4))
-                crop_h = ovutils::aligndown(crop_h, 4);
-            crop.right = crop.left + crop_w;
-            crop.bottom = crop.top + crop_h;
-        }
-        Dim rotCrop(crop.left, crop.top, crop_w, crop_h);
+         Dim rotCrop(crop.left, crop.top, crop.right - crop.left,
+                crop.bottom - crop.top);
         rot->setCrop(rotCrop);
     }
 
@@ -1725,28 +1742,27 @@
 }
 
 void updateSource(eTransform& orient, Whf& whf,
-        hwc_rect_t& crop) {
-    Dim srcCrop(crop.left, crop.top,
+        hwc_rect_t& crop, Rotator *rot) {
+    Dim transformedCrop(crop.left, crop.top,
             crop.right - crop.left,
             crop.bottom - crop.top);
-    orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
-    preRotateSource(orient, whf, srcCrop);
     if (qdutils::MDPVersion::getInstance().getMDPVersion() >=
         qdutils::MDSS_V5) {
-        // Source for overlay will be the cropped (and rotated)
-        crop.left = 0;
-        crop.top = 0;
-        crop.right = srcCrop.w;
-        crop.bottom = srcCrop.h;
-        // Set width & height equal to sourceCrop w & h
-        whf.w = srcCrop.w;
-        whf.h = srcCrop.h;
+        //B-family rotator internally could modify destination dimensions if
+        //downscaling is supported
+        whf = rot->getDstWhf();
+        transformedCrop = rot->getDstDimensions();
     } else {
-        crop.left = srcCrop.x;
-        crop.top = srcCrop.y;
-        crop.right = srcCrop.x + srcCrop.w;
-        crop.bottom = srcCrop.y + srcCrop.h;
+        //A-family rotator rotates entire buffer irrespective of crop, forcing
+        //us to recompute the crop based on transform
+        orient = static_cast<eTransform>(ovutils::getMdpOrient(orient));
+        preRotateSource(orient, whf, transformedCrop);
     }
+
+    crop.left = transformedCrop.x;
+    crop.top = transformedCrop.y;
+    crop.right = transformedCrop.x + transformedCrop.w;
+    crop.bottom = transformedCrop.y + transformedCrop.h;
 }
 
 int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer,
@@ -1811,8 +1827,7 @@
             ALOGE("%s: configRotator failed!", __FUNCTION__);
             return -1;
         }
-        whf.format = (*rot)->getDstFormat();
-        updateSource(orient, whf, crop);
+        updateSource(orient, whf, crop, *rot);
         rotFlags |= ovutils::ROT_PREROTATED;
     }
 
@@ -1918,8 +1933,7 @@
             ALOGE("%s: configRotator failed!", __FUNCTION__);
             return -1;
         }
-        whf.format = (*rot)->getDstFormat();
-        updateSource(orient, whf, crop);
+        updateSource(orient, whf, crop, *rot);
         rotFlags |= ROT_PREROTATED;
     }
 
@@ -1931,14 +1945,17 @@
 
     const int lSplit = getLeftSplit(ctx, dpy);
 
-    if(lDest != OV_INVALID) {
+    // Calculate Left rects
+    if(dst.left < lSplit) {
         tmp_cropL = crop;
         tmp_dstL = dst;
         hwc_rect_t scissor = {0, 0, lSplit, hw_h };
         scissor = getIntersection(ctx->mViewFrame[dpy], scissor);
         qhwc::calculate_crop_rects(tmp_cropL, tmp_dstL, scissor, 0);
     }
-    if(rDest != OV_INVALID) {
+
+    // Calculate Right rects
+    if(dst.right > lSplit) {
         tmp_cropR = crop;
         tmp_dstR = dst;
         hwc_rect_t scissor = {lSplit, 0, hw_w, hw_h };
@@ -1951,8 +1968,8 @@
     //When buffer is H-flipped, contents of mixer config also needs to swapped
     //Not needed if the layer is confined to one half of the screen.
     //If rotator has been used then it has also done the flips, so ignore them.
-    if((orient & OVERLAY_TRANSFORM_FLIP_H) && lDest != OV_INVALID
-            && rDest != OV_INVALID && (*rot) == NULL) {
+    if((orient & OVERLAY_TRANSFORM_FLIP_H) && (dst.left < lSplit) &&
+            (dst.right > lSplit) && (*rot) == NULL) {
         hwc_rect_t new_cropR;
         new_cropR.left = tmp_cropL.left;
         new_cropR.right = new_cropR.left + (tmp_cropR.right - tmp_cropR.left);
@@ -2048,8 +2065,7 @@
             ALOGE("%s: configRotator failed!", __FUNCTION__);
             return -1;
         }
-        whf.format = (*rot)->getDstFormat();
-        updateSource(orient, whf, crop);
+        updateSource(orient, whf, crop, *rot);
         rotFlags |= ROT_PREROTATED;
     }
 
@@ -2226,8 +2242,7 @@
             EGLint attr_list[] = {EGL_GPU_HINT_1,
                                   EGL_GPU_LEVEL_3,
                                   EGL_NONE };
-            if((gpuHint->mCurrGPUPerfMode != EGL_GPU_LEVEL_3) &&
-                !((*(ctx->mpfn_eglGpuPerfHintQCOM))(gpuHint->mEGLDisplay,
+            if (!((*(ctx->mpfn_eglGpuPerfHintQCOM))(gpuHint->mEGLDisplay,
                                     gpuHint->mEGLContext, attr_list))) {
                 ALOGW("eglGpuPerfHintQCOM failed for Built in display");
             } else {
@@ -2286,7 +2301,7 @@
     ctx->layerProp[dpy] = new LayerProp[numAppLayers];
 }
 
-void BwcPM::setBwc(hwc_context_t *ctx, const hwc_rect_t& crop,
+void BwcPM::setBwc(hwc_context_t * /*ctx*/, const hwc_rect_t& crop,
             const hwc_rect_t& dst, const int& transform,
             ovutils::eMdpFlags& mdpFlags) {
     //Target doesnt support Bwc
diff --git a/libhwcomposer/hwc_utils.h b/libhwcomposer/hwc_utils.h
index cdf1115..7e27f83 100644
--- a/libhwcomposer/hwc_utils.h
+++ b/libhwcomposer/hwc_utils.h
@@ -222,11 +222,11 @@
 }
 
 inline hwc_rect_t integerizeSourceCrop(const hwc_frect_t& cropF) {
-    hwc_rect_t cropI = {0};
-    cropI.left = int(ceilf(cropF.left));
-    cropI.top = int(ceilf(cropF.top));
-    cropI.right = int(floorf(cropF.right));
-    cropI.bottom = int(floorf(cropF.bottom));
+    hwc_rect_t cropI = {0,0,0,0};
+    cropI.left = int(floorf(cropF.left));
+    cropI.top = int(floorf(cropF.top));
+    cropI.right = int(ceilf(cropF.right));
+    cropI.bottom = int(ceilf(cropF.bottom));
     return cropI;
 }
 
@@ -303,6 +303,8 @@
 void getAspectRatioPosition(hwc_context_t* ctx, int dpy, int extOrientation,
                                 hwc_rect_t& inRect, hwc_rect_t& outRect);
 
+uint32_t getRefreshRate(hwc_context_t* ctx, uint32_t requestedRefreshRate);
+
 uint32_t roundOff(uint32_t refreshRate);
 
 void setRefreshRate(hwc_context_t *ctx, int dpy, uint32_t refreshRate);
@@ -359,7 +361,7 @@
         ovutils::eIsFg& isFg, const ovutils::eDest& dest);
 
 void updateSource(ovutils::eTransform& orient, ovutils::Whf& whf,
-        hwc_rect_t& crop);
+        hwc_rect_t& crop, overlay::Rotator *rot);
 
 //Routine to configure low resolution panels (<= 2048 width)
 int configureNonSplit(hwc_context_t *ctx, hwc_layer_1_t *layer, const int& dpy,
diff --git a/libhwcomposer/hwc_virtual.h b/libhwcomposer/hwc_virtual.h
index 9ef5106..0adde5b 100644
--- a/libhwcomposer/hwc_virtual.h
+++ b/libhwcomposer/hwc_virtual.h
@@ -86,7 +86,7 @@
     // instantiates mdpcomp, copybit and fbupdate objects and initialize those
     // objects for virtual display during virtual display connect. This function
     // is no-op for V4L2 design
-    virtual void init(hwc_context_t *ctx) {};
+    virtual void init(hwc_context_t * /*ctx*/) {};
     // Destroys mdpcomp, copybit and fbupdate objects and for virtual display
     // during virtual display disconnect. This function is no-op for V4L2 design
     virtual void destroy(hwc_context_t *, size_t ,
diff --git a/libhwcomposer/hwc_vsync.cpp b/libhwcomposer/hwc_vsync.cpp
index 106f4f0..62868d0 100644
--- a/libhwcomposer/hwc_vsync.cpp
+++ b/libhwcomposer/hwc_vsync.cpp
@@ -19,6 +19,7 @@
  */
 
 #include <cutils/properties.h>
+#include <cutils/iosched_policy.h>
 #include <utils/Log.h>
 #include <fcntl.h>
 #include <sys/ioctl.h>
@@ -95,6 +96,7 @@
     prctl(PR_SET_NAME, (unsigned long) &thread_name, 0, 0, 0);
     setpriority(PRIO_PROCESS, 0, HAL_PRIORITY_URGENT_DISPLAY +
                 android::PRIORITY_MORE_FAVORABLE);
+    android_set_rt_ioprio(0, 1);
 
     char vdata[MAX_DATA];
     //Number of physical displays
diff --git a/liboverlay/overlay.cpp b/liboverlay/overlay.cpp
index 8e40b07..4c3ed54 100644
--- a/liboverlay/overlay.cpp
+++ b/liboverlay/overlay.cpp
@@ -195,10 +195,13 @@
 bool Overlay::queueBuffer(int fd, uint32_t offset,
         utils::eDest dest) {
     bool ret = false;
-    validate((int)dest);
-    //Queue only if commit() has succeeded (and the bit set)
-    if(PipeBook::isUsed((int)dest)) {
-        ret = mPipeBook[dest].mPipe->queueBuffer(fd, offset);
+
+    if (mPipeBook[dest].valid()) {
+        validate((int)dest);
+        //Queue only if commit() has succeeded (and the bit set)
+        if(PipeBook::isUsed((int)dest)) {
+            ret = mPipeBook[dest].mPipe->queueBuffer(fd, offset);
+        }
     }
     return ret;
 }
@@ -356,10 +359,18 @@
     struct mdp_display_commit info;
     memset(&info, 0, sizeof(struct mdp_display_commit));
     info.flags = MDP_DISPLAY_COMMIT_OVERLAY;
+
+#ifdef DUAL_DSI // new kernel api
+    info.l_roi.x = roi.x;
+    info.l_roi.y = roi.y;
+    info.l_roi.w = roi.w;
+    info.l_roi.h = roi.h;
+#else
     info.roi.x = roi.x;
     info.roi.y = roi.y;
     info.roi.w = roi.w;
     info.roi.h = roi.h;
+#endif
 
     if(!mdp_wrapper::displayCommit(fd, info)) {
         ALOGE("%s: commit failed", __func__);
diff --git a/liboverlay/overlayMdpRot.cpp b/liboverlay/overlayMdpRot.cpp
index 1feffff..b6089fb 100755
--- a/liboverlay/overlayMdpRot.cpp
+++ b/liboverlay/overlayMdpRot.cpp
@@ -19,6 +19,7 @@
 
 #include "overlayUtils.h"
 #include "overlayRotator.h"
+#include "gr.h"
 
 namespace ovutils = overlay::utils;
 
@@ -47,6 +48,24 @@
     return mRotImgInfo.dst.format;
 }
 
+//Added for completeness. Not expected to be called.
+utils::Whf MdpRot::getDstWhf() const {
+    int alW = 0, alH = 0;
+    int halFormat = ovutils::getHALFormat(mRotImgInfo.dst.format);
+    getBufferSizeAndDimensions(mRotImgInfo.dst.width, mRotImgInfo.dst.height,
+            halFormat, alW, alH);
+    return utils::Whf(alW, alH, mRotImgInfo.dst.format);
+}
+
+//Added for completeness. Not expected to be called.
+utils::Dim MdpRot::getDstDimensions() const {
+    int alW = 0, alH = 0;
+    int halFormat = ovutils::getHALFormat(mRotImgInfo.dst.format);
+    getBufferSizeAndDimensions(mRotImgInfo.dst.width, mRotImgInfo.dst.height,
+            halFormat, alW, alH);
+    return utils::Dim(0, 0, alW, alH);
+}
+
 uint32_t MdpRot::getSessId() const { return mRotImgInfo.session_id; }
 
 void MdpRot::setDownscale(int ds) {
diff --git a/liboverlay/overlayMdssRot.cpp b/liboverlay/overlayMdssRot.cpp
index 74c45cc..2843f49 100644
--- a/liboverlay/overlayMdssRot.cpp
+++ b/liboverlay/overlayMdssRot.cpp
@@ -61,6 +61,21 @@
     return mRotInfo.src.format;
 }
 
+utils::Whf MdssRot::getDstWhf() const {
+    //For Mdss dst_rect itself represents buffer dimensions. We ignore actual
+    //aligned values during buffer allocation. Also the driver overwrites the
+    //src.format field if destination format is different.
+    //This implementation detail makes it possible to retrieve w,h even before
+    //buffer allocation, which happens in queueBuffer.
+    return utils::Whf(mRotInfo.dst_rect.w, mRotInfo.dst_rect.h,
+            mRotInfo.src.format);
+}
+
+utils::Dim MdssRot::getDstDimensions() const {
+    return utils::Dim(mRotInfo.dst_rect.x, mRotInfo.dst_rect.y,
+            mRotInfo.dst_rect.w, mRotInfo.dst_rect.h);
+}
+
 uint32_t MdssRot::getSessId() const { return mRotInfo.id; }
 
 bool MdssRot::init() {
@@ -93,16 +108,10 @@
 }
 
 void MdssRot::setCrop(const utils::Dim& crop) {
-
     mRotInfo.src_rect.x = crop.x;
     mRotInfo.src_rect.y = crop.y;
     mRotInfo.src_rect.w = crop.w;
     mRotInfo.src_rect.h = crop.h;
-
-    mRotInfo.dst_rect.x = 0;
-    mRotInfo.dst_rect.y = 0;
-    mRotInfo.dst_rect.w = crop.w;
-    mRotInfo.dst_rect.h = crop.h;
 }
 
 void MdssRot::setDownscale(int ds) {}
@@ -129,7 +138,22 @@
 }
 
 bool MdssRot::commit() {
+    if (utils::isYuv(mRotInfo.src.format)) {
+        utils::normalizeCrop(mRotInfo.src_rect.x, mRotInfo.src_rect.w);
+        utils::normalizeCrop(mRotInfo.src_rect.y, mRotInfo.src_rect.h);
+        // For interlaced, crop.h should be 4-aligned
+        if ((mRotInfo.flags & utils::OV_MDP_DEINTERLACE) and
+                (mRotInfo.src_rect.h % 4))
+            mRotInfo.src_rect.h = utils::aligndown(mRotInfo.src_rect.h, 4);
+    }
+
+    mRotInfo.dst_rect.x = 0;
+    mRotInfo.dst_rect.y = 0;
+    mRotInfo.dst_rect.w = mRotInfo.src_rect.w;
+    mRotInfo.dst_rect.h = mRotInfo.src_rect.h;
+
     doTransform();
+
     mRotInfo.flags |= MDSS_MDP_ROT_ONLY;
     mEnabled = true;
     if(!overlay::mdp_wrapper::setOverlay(mFd.getFD(), mRotInfo)) {
diff --git a/liboverlay/overlayRotator.h b/liboverlay/overlayRotator.h
index 7d25f3a..0b55bae 100644
--- a/liboverlay/overlayRotator.h
+++ b/liboverlay/overlayRotator.h
@@ -75,9 +75,14 @@
     virtual void setTransform(const utils::eTransform& rot) = 0;
     virtual bool commit() = 0;
     virtual void setDownscale(int ds) = 0;
+    //Mem id and offset should be retrieved only after rotator kickoff
     virtual int getDstMemId() const = 0;
     virtual uint32_t getDstOffset() const = 0;
+    //Destination width, height, format, position should be retrieved only after
+    //rotator configuration is committed via commit API
     virtual uint32_t getDstFormat() const = 0;
+    virtual utils::Whf getDstWhf() const = 0;
+    virtual utils::Dim getDstDimensions() const = 0;
     virtual uint32_t getSessId() const = 0;
     virtual bool queueBuffer(int fd, uint32_t offset) = 0;
     virtual void dump() const = 0;
@@ -114,6 +119,8 @@
     virtual int getDstMemId() const;
     virtual uint32_t getDstOffset() const;
     virtual uint32_t getDstFormat() const;
+    virtual utils::Whf getDstWhf() const;
+    virtual utils::Dim getDstDimensions() const;
     virtual uint32_t getSessId() const;
     virtual bool queueBuffer(int fd, uint32_t offset);
     virtual void dump() const;
@@ -172,6 +179,8 @@
     virtual int getDstMemId() const;
     virtual uint32_t getDstOffset() const;
     virtual uint32_t getDstFormat() const;
+    virtual utils::Whf getDstWhf() const;
+    virtual utils::Dim getDstDimensions() const;
     virtual uint32_t getSessId() const;
     virtual bool queueBuffer(int fd, uint32_t offset);
     virtual void dump() const;
diff --git a/liboverlay/overlayUtils.h b/liboverlay/overlayUtils.h
index 7947e9c..44f8ca1 100644
--- a/liboverlay/overlayUtils.h
+++ b/liboverlay/overlayUtils.h
@@ -696,6 +696,14 @@
         value--;
 }
 
+/* Prerotation adjusts crop co-ordinates to the new transformed values within
+ * destination buffer. This is necessary only when the entire buffer is rotated
+ * irrespective of crop (A-family). If only the crop portion of the buffer is
+ * rotated into a destination buffer matching the size of crop, we don't need to
+ * use this helper (B-family).
+ * @Deprecated as of now, retained for the case where a full buffer needs
+ * transform and also as a reference.
+ */
 void preRotateSource(const eTransform& tr, Whf& whf, Dim& srcCrop);
 void getDump(char *buf, size_t len, const char *prefix, const mdp_overlay& ov);
 void getDump(char *buf, size_t len, const char *prefix, const msmfb_img& ov);
diff --git a/liboverlay/overlayWriteback.cpp b/liboverlay/overlayWriteback.cpp
index 08af00f..de18e55 100644
--- a/liboverlay/overlayWriteback.cpp
+++ b/liboverlay/overlayWriteback.cpp
@@ -101,8 +101,12 @@
 
 bool Writeback::stopSession() {
     if(mFd.valid()) {
+        if(!Overlay::displayCommit(mFd.getFD())) {
+            ALOGE("%s: displayCommit failed", __func__);
+            return false;
+        }
         if(!mdp_wrapper::wbStopTerminate(mFd.getFD())) {
-            ALOGE("%s failed", __func__);
+            ALOGE("%s: wbStopTerminate failed", __func__);
             return false;
         }
     } else {
diff --git a/libqdutils/mdp_version.h b/libqdutils/mdp_version.h
index f7c9064..ffe2a32 100644
--- a/libqdutils/mdp_version.h
+++ b/libqdutils/mdp_version.h
@@ -128,7 +128,10 @@
     bool supportsBWC();
     int getLeftSplit() { return mSplit.left(); }
     int getRightSplit() { return mSplit.right(); }
-    int isPartialUpdateEnabled() { return mPanelInfo.mPartialUpdateEnable; }
+    bool isPartialUpdateEnabled() {
+        return mPanelInfo.mPartialUpdateEnable &&
+                mPanelInfo.mType == MIPI_CMD_PANEL;
+    }
     int getLeftAlign() { return mPanelInfo.mLeftAlign; }
     int getWidthAlign() { return mPanelInfo.mWidthAlign; }
     int getTopAlign() { return mPanelInfo.mTopAlign; }