am 219b6962: Display: power consumption saving

* commit '219b6962f08cc66bd6227f4647388c26f486a4dd':
  Display: power consumption saving
diff --git a/merrifield/test/Android.mk b/merrifield/test/Android.mk
index b0a262e..0c9fe4a 100644
--- a/merrifield/test/Android.mk
+++ b/merrifield/test/Android.mk
@@ -15,18 +15,12 @@
 	libbinder \
 	libcutils \
 	libgui \
-	libstlport \
 	libui \
 	libutils \
 
 LOCAL_C_INCLUDES := \
-    bionic \
-    $(call include-path-for, libstdc++) \
     $(call include-path-for, gtest) \
-    $(call include-path-for, stlport)
 
 # Build the binary to $(TARGET_OUT_DATA_NATIVE_TESTS)/$(LOCAL_MODULE)
 # to integrate with auto-test framework.
 include $(BUILD_EXECUTABLE)
-
-
diff --git a/moorefield_hdmi/Android.mk b/moorefield_hdmi/Android.mk
index b75d32d..2d70051 100644
--- a/moorefield_hdmi/Android.mk
+++ b/moorefield_hdmi/Android.mk
@@ -20,6 +20,9 @@
 # hw/<OVERLAY_HARDWARE_MODULE_ID>.<ro.product.board>.so
 include $(CLEAR_VARS)
 
+# HwcModule.cpp uses GNU old-style field designator extension.
+LOCAL_CLANG_CFLAGS += -Wno-gnu-designator
+
 LOCAL_MODULE_PATH := $(TARGET_OUT_SHARED_LIBRARIES)/hw
 LOCAL_MODULE_TAGS := optional
 LOCAL_MODULE := hwcomposer.$(TARGET_BOARD_PLATFORM)
@@ -97,8 +100,10 @@
    LOCAL_CFLAGS += -DINTEL_SUPPORT_HDMI_PRIMARY
 endif
 
-LOCAL_COPY_HEADERS:=include/pvr/hal/hal_public.h
-LOCAL_COPY_HEADERS_TO:=pvr/hal
+LOCAL_COPY_HEADERS := \
+ include/pvr/hal/hal_public.h \
+ include/pvr/hal/img_gralloc_public.h
+LOCAL_COPY_HEADERS_TO := pvr/hal
 
 include $(BUILD_SHARED_LIBRARY)
 
diff --git a/moorefield_hdmi/common/base/Drm.cpp b/moorefield_hdmi/common/base/Drm.cpp
index 007d308..3e5138a 100755
--- a/moorefield_hdmi/common/base/Drm.cpp
+++ b/moorefield_hdmi/common/base/Drm.cpp
@@ -199,6 +199,7 @@
         if (output->crtc->mode_valid) {
             ILOGTRACE("mode is valid, kernel mode settings");
             memcpy(&output->mode, &output->crtc->mode, sizeof(drmModeModeInfo));
+            //output->fbId = output->crtc->buffer_id;
             ret = true;
         } else {
             ELOGTRACE("mode is invalid. Kernel mode setting is not completed");
@@ -608,8 +609,10 @@
 {
     DrmOutput *output = &mOutputs[index];
 
-    int oldFbId =0;
+    int oldFbId = 0;
     int oldFbHandle = 0;
+    // reuse current frame buffer if there is no resolution change
+    int fbId = -1;
 
     drmModeModeInfo currentMode;
     memcpy(&currentMode, &output->mode, sizeof(drmModeModeInfo));
@@ -617,55 +620,53 @@
     if (isSameDrmMode(mode, &currentMode))
         return true;
 
+    if (currentMode.hdisplay != mode->hdisplay ||
+        currentMode.vdisplay != mode->vdisplay) {
 
-    if (output->fbId) {
-        oldFbId = output->fbId ;
-        output->fbId = 0;
-    }
-
-    if (output->fbHandle) {
+        oldFbId = output->fbId;
         oldFbHandle = output->fbHandle;
-        output->fbHandle = 0;
-    }
 
-    // allocate frame buffer
-    int stride = 0;
+        // allocate frame buffer
+        int stride = 0;
 #ifdef INTEL_SUPPORT_HDMI_PRIMARY
-    output->fbHandle = Hwcomposer::getInstance().getBufferManager()->allocFrameBuffer(
-        DEFAULT_DRM_FB_WIDTH, DEFAULT_DRM_FB_HEIGHT, &stride);
+        output->fbHandle = Hwcomposer::getInstance().getBufferManager()->allocFrameBuffer(
+            DEFAULT_DRM_FB_WIDTH, DEFAULT_DRM_FB_HEIGHT, &stride);
 #else
-    output->fbHandle = Hwcomposer::getInstance().getBufferManager()->allocFrameBuffer(
-        mode->hdisplay, mode->vdisplay, &stride);
+        output->fbHandle = Hwcomposer::getInstance().getBufferManager()->allocFrameBuffer(
+            mode->hdisplay, mode->vdisplay, &stride);
 #endif
-    if (output->fbHandle == 0) {
-        ELOGTRACE("failed to allocate frame buffer");
-        return false;
-    }
+        if (output->fbHandle == 0) {
+            ELOGTRACE("failed to allocate frame buffer");
+            return false;
+        }
 
-    int ret = 0;
-    ret = drmModeAddFB(
-        mDrmFd,
+        int ret = 0;
+        ret = drmModeAddFB(
+            mDrmFd,
 #ifdef INTEL_SUPPORT_HDMI_PRIMARY
-        DEFAULT_DRM_FB_WIDTH,
-        DEFAULT_DRM_FB_HEIGHT,
+            DEFAULT_DRM_FB_WIDTH,
+            DEFAULT_DRM_FB_HEIGHT,
 #else
-        mode->hdisplay,
-        mode->vdisplay,
+            mode->hdisplay,
+            mode->vdisplay,
 #endif
-        DrmConfig::getFrameBufferDepth(),
-        DrmConfig::getFrameBufferBpp(),
-        stride,
-        output->fbHandle,
-        &output->fbId);
-    if (ret != 0) {
-        ELOGTRACE("drmModeAddFB failed, error: %d", ret);
-        return false;
+            DrmConfig::getFrameBufferDepth(),
+            DrmConfig::getFrameBufferBpp(),
+            stride,
+            output->fbHandle,
+            &output->fbId);
+        if (ret != 0) {
+            ELOGTRACE("drmModeAddFB failed, error: %d", ret);
+            return false;
+        }
+        fbId = output->fbId;
     }
 
     ILOGTRACE("mode set: %dx%d@%dHz", mode->hdisplay, mode->vdisplay, mode->vrefresh);
 
-    ret = drmModeSetCrtc(mDrmFd, output->crtc->crtc_id, output->fbId, 0, 0,
+    int ret = drmModeSetCrtc(mDrmFd, output->crtc->crtc_id, fbId, 0, 0,
                    &output->connector->connector_id, 1, mode);
+
     if (ret == 0) {
         //save mode
         memcpy(&output->mode, mode, sizeof(drmModeModeInfo));
diff --git a/moorefield_hdmi/common/base/HwcLayerList.cpp b/moorefield_hdmi/common/base/HwcLayerList.cpp
index 171cf85..5185e98 100755
--- a/moorefield_hdmi/common/base/HwcLayerList.cpp
+++ b/moorefield_hdmi/common/base/HwcLayerList.cpp
@@ -114,7 +114,6 @@
 
 bool HwcLayerList::checkRgbOverlaySupported(HwcLayer *hwcLayer)
 {
-    bool valid = false;
     hwc_layer_1_t& layer = *(hwcLayer->getLayer());
 
     // if layer was forced to use FB
@@ -146,7 +145,6 @@
         return false;
     }
 
-    uint32_t h = hwcLayer->getBufferHeight();
     const stride_t& stride = hwcLayer->getBufferStride();
     if (stride.rgb.stride > 4096) {
         return false;
@@ -176,7 +174,6 @@
 
 bool HwcLayerList::checkCursorSupported(HwcLayer *hwcLayer)
 {
-    bool valid = false;
     hwc_layer_1_t& layer = *(hwcLayer->getLayer());
 
     // if layer was forced to use FB
@@ -260,7 +257,6 @@
     mOverlayCandidates.setCapacity(mLayerCount);
     mCursorCandidates.setCapacity(mLayerCount);
     mZOrderConfig.setCapacity(mLayerCount);
-    Hwcomposer& hwc = Hwcomposer::getInstance();
 
     PriorityVector rgbOverlayLayers;
     rgbOverlayLayers.setCapacity(mLayerCount);
@@ -794,8 +790,6 @@
 
 bool HwcLayerList::update(hwc_display_contents_1_t *list)
 {
-    bool ret;
-
     // basic check to make sure the consistance
     if (!list) {
         ELOGTRACE("null layer list");
diff --git a/moorefield_hdmi/common/base/HwcModule.cpp b/moorefield_hdmi/common/base/HwcModule.cpp
index ce8d478..152f8e4 100644
--- a/moorefield_hdmi/common/base/HwcModule.cpp
+++ b/moorefield_hdmi/common/base/HwcModule.cpp
@@ -124,19 +124,6 @@
     return 0;
 }
 
-static int hwc_blank(hwc_composer_device_1_t *dev, int disp, int blank)
-{
-    ATRACE_CALL();
-    GET_HWC_RETURN_ERROR_IF_NULL();
-    bool ret = hwc->blank(disp, blank);
-    if (ret == false) {
-        ELOGTRACE("failed to blank disp %d, blank %d", disp, blank);
-        return -EINVAL;
-    }
-
-    return 0;
-}
-
 static int hwc_getDisplayConfigs(hwc_composer_device_1_t *dev,
                                      int disp,
                                      uint32_t *configs,
@@ -222,6 +209,8 @@
     return 0;
 }
 
+// Todo: add hwc_setCursorPositionAsync after supporting patches
+/*
 static int hwc_setCursorPositionAsync(hwc_composer_device_1_t *dev, int disp, int x, int y)
 {
     ATRACE_CALL();
@@ -234,6 +223,7 @@
 
     return 0;
 }
+*/
 
 //------------------------------------------------------------------------------
 
diff --git a/moorefield_hdmi/common/base/Hwcomposer.cpp b/moorefield_hdmi/common/base/Hwcomposer.cpp
index eac1448..824781a 100755
--- a/moorefield_hdmi/common/base/Hwcomposer.cpp
+++ b/moorefield_hdmi/common/base/Hwcomposer.cpp
@@ -334,13 +334,11 @@
 {
     RETURN_VOID_IF_NOT_INIT();
 
-#ifndef INTEL_SUPPORT_HDMI_PRIMARY
     if (mProcs && mProcs->hotplug) {
         DLOGTRACE("report hotplug on disp %d, connected %d", disp, connected);
         mProcs->hotplug(const_cast<hwc_procs_t*>(mProcs), disp, connected);
         DLOGTRACE("hotplug callback processed and returned!");
     }
-#endif
 
     mDisplayAnalyzer->postHotplugEvent(connected);
 }
diff --git a/moorefield_hdmi/common/devices/DummyDevice.cpp b/moorefield_hdmi/common/devices/DummyDevice.cpp
index d763a70..7c9355e 100755
--- a/moorefield_hdmi/common/devices/DummyDevice.cpp
+++ b/moorefield_hdmi/common/devices/DummyDevice.cpp
@@ -21,11 +21,11 @@
 
 namespace android {
 namespace intel {
-DummyDevice::DummyDevice(uint32_t type, Hwcomposer& hwc)
+DummyDevice::DummyDevice(uint32_t disp, Hwcomposer& hwc)
     : mInitialized(false),
       mConnected(false),
       mBlank(false),
-      mType(type),
+      mDisp(disp),
       mHwc(hwc),
       mVsyncObserver(NULL),
       mName("Dummy")
@@ -54,7 +54,7 @@
 {
     RETURN_FALSE_IF_NOT_INIT();
 
-    if (!display || mType >= DEVICE_VIRTUAL) {
+    if (!display || mDisp >= DEVICE_VIRTUAL) {
         return true;
     }
 
@@ -205,7 +205,7 @@
 
 int DummyDevice::getType() const
 {
-    return mType;
+    return mDisp;
 }
 
 void DummyDevice::onVsync(int64_t timestamp)
@@ -213,7 +213,7 @@
     if (!mConnected)
         return;
 
-    mHwc.vsync(mType, timestamp);
+    mHwc.vsync(mDisp, timestamp);
 }
 
 void DummyDevice::dump(Dump& d)
diff --git a/moorefield_hdmi/common/devices/ExternalDevice.cpp b/moorefield_hdmi/common/devices/ExternalDevice.cpp
index 2430c15..75f8700 100755
--- a/moorefield_hdmi/common/devices/ExternalDevice.cpp
+++ b/moorefield_hdmi/common/devices/ExternalDevice.cpp
@@ -23,13 +23,12 @@
 namespace android {
 namespace intel {
 
-ExternalDevice::ExternalDevice(Hwcomposer& hwc, DisplayPlaneManager& dpm)
-    : PhysicalDevice(DEVICE_EXTERNAL, hwc, dpm),
+ExternalDevice::ExternalDevice(uint32_t disp, Hwcomposer& hwc, DisplayPlaneManager& dpm)
+    : PhysicalDevice(disp, DEVICE_EXTERNAL, hwc, dpm),
       mHdcpControl(NULL),
       mAbortModeSettingCond(),
       mPendingDrmMode(),
-      mHotplugEventPending(false),
-      mExpectedRefreshRate(0)
+      mHotplugEventPending(false)
 {
     CTRACE();
 }
@@ -147,7 +146,7 @@
     Drm *drm = Hwcomposer::getInstance().getDrm();
 
     mConnected = false;
-    mHwc.hotplug(mType, false);
+    mHwc.hotplug(mDisp, false);
 
     {
         Mutex::Autolock lock(mLock);
@@ -156,7 +155,7 @@
         status_t err = mAbortModeSettingCond.waitRelative(mLock, milliseconds(20));
         if (err != -ETIMEDOUT) {
             ILOGTRACE("Mode settings is interrupted");
-            mHwc.hotplug(mType, true);
+            mHwc.hotplug(mDisp, true);
             return;
         }
     }
@@ -165,13 +164,13 @@
     mHdcpControl->stopHdcp();
     if (!drm->setDrmMode(mType, mPendingDrmMode)) {
         ELOGTRACE("failed to set Drm mode");
-        mHwc.hotplug(mType, true);
+        mHwc.hotplug(mDisp, true);
         return;
     }
 
     if (!PhysicalDevice::updateDisplayConfigs()) {
         ELOGTRACE("failed to update display configs");
-        mHwc.hotplug(mType, true);
+        mHwc.hotplug(mDisp, true);
         return;
     }
     mConnected = true;
@@ -180,9 +179,8 @@
     if (mHdcpControl->startHdcpAsync(HdcpLinkStatusListener, this) == false) {
         ELOGTRACE("startHdcpAsync() failed; HDCP is not enabled");
         mHotplugEventPending = false;
-        mHwc.hotplug(mType, true);
+        mHwc.hotplug(mDisp, true);
     }
-    mExpectedRefreshRate = 0;
 }
 
 
@@ -200,7 +198,7 @@
 {
     if (mHotplugEventPending) {
         DLOGTRACE("HDCP authentication status %d, sending hotplug event...", success);
-        mHwc.hotplug(mType, mConnected);
+        mHwc.hotplug(mDisp, mConnected);
         mHotplugEventPending = false;
     }
 }
@@ -242,7 +240,7 @@
     if (mConnected == false) {
         mHotplugEventPending = false;
         mHdcpControl->stopHdcp();
-        mHwc.hotplug(mType, mConnected);
+        mHwc.hotplug(mDisp, mConnected);
     } else {
         DLOGTRACE("start HDCP asynchronously...");
         // delay sending hotplug event till HDCP is authenticated.
@@ -251,7 +249,7 @@
         if (ret == false) {
             ELOGTRACE("failed to start HDCP");
             mHotplugEventPending = false;
-            mHwc.hotplug(mType, mConnected);
+            mHwc.hotplug(mDisp, mConnected);
         }
     }
     mActiveDisplayConfig = 0;
@@ -279,13 +277,6 @@
     if (hz == (int)mode.vrefresh)
         return;
 
-    if (mExpectedRefreshRate != 0 &&
-            mExpectedRefreshRate == hz && mHotplugEventPending) {
-        ILOGTRACE("Ignore a new refresh setting event because there is a same event is handling");
-        return;
-    }
-    mExpectedRefreshRate = hz;
-
     ILOGTRACE("changing refresh rate from %d to %d", mode.vrefresh, hz);
 
     mHdcpControl->stopHdcp();
diff --git a/moorefield_hdmi/common/devices/PhysicalDevice.cpp b/moorefield_hdmi/common/devices/PhysicalDevice.cpp
index b4e8fa0..6b477ae 100755
--- a/moorefield_hdmi/common/devices/PhysicalDevice.cpp
+++ b/moorefield_hdmi/common/devices/PhysicalDevice.cpp
@@ -21,8 +21,9 @@
 namespace android {
 namespace intel {
 
-PhysicalDevice::PhysicalDevice(uint32_t type, Hwcomposer& hwc, DisplayPlaneManager& dpm)
-    : mType(type),
+PhysicalDevice::PhysicalDevice(uint32_t disp, uint32_t type, Hwcomposer& hwc, DisplayPlaneManager& dpm)
+    : mDisp(disp),
+      mType(type),
       mHwc(hwc),
       mDisplayPlaneManager(dpm),
       mActiveDisplayConfig(-1),
@@ -62,7 +63,7 @@
         return;
     }
 
-    ALOGTRACE("disp = %d, layer number = %d", mType, list->numHwLayers);
+    ALOGTRACE("disp = %d, layer number = %d", mDisp, list->numHwLayers);
 
     // NOTE: should NOT be here
     if (mLayerList) {
@@ -131,7 +132,7 @@
 {
     RETURN_FALSE_IF_NOT_INIT();
 
-    ALOGTRACE("disp = %d, enabled = %d", mType, enabled);
+    ALOGTRACE("disp = %d, enabled = %d", mDisp, enabled);
     return mVsyncObserver->control(enabled);
 }
 
@@ -140,7 +141,7 @@
     RETURN_FALSE_IF_NOT_INIT();
 
     mBlank = blank;
-    bool ret = mBlankControl->blank(mType, blank);
+    bool ret = mBlankControl->blank(mDisp, blank);
     if (ret == false) {
         ELOGTRACE("failed to blank device");
         return false;
diff --git a/moorefield_hdmi/common/devices/PrimaryDevice.cpp b/moorefield_hdmi/common/devices/PrimaryDevice.cpp
index 62a573c..6f0126e 100755
--- a/moorefield_hdmi/common/devices/PrimaryDevice.cpp
+++ b/moorefield_hdmi/common/devices/PrimaryDevice.cpp
@@ -22,8 +22,8 @@
 namespace android {
 namespace intel {
 
-PrimaryDevice::PrimaryDevice(Hwcomposer& hwc, DisplayPlaneManager& dpm)
-    : PhysicalDevice(DEVICE_PRIMARY, hwc, dpm)
+PrimaryDevice::PrimaryDevice(uint32_t disp, Hwcomposer& hwc, DisplayPlaneManager& dpm)
+    : PhysicalDevice(disp, DEVICE_PRIMARY, hwc, dpm)
 {
     CTRACE();
 }
diff --git a/moorefield_hdmi/common/observers/SoftVsyncObserver.cpp b/moorefield_hdmi/common/observers/SoftVsyncObserver.cpp
index e62ed93..0174676 100644
--- a/moorefield_hdmi/common/observers/SoftVsyncObserver.cpp
+++ b/moorefield_hdmi/common/observers/SoftVsyncObserver.cpp
@@ -16,11 +16,7 @@
 #include <common/utils/HwcTrace.h>
 #include <common/observers/SoftVsyncObserver.h>
 #include <IDisplayDevice.h>
-
-extern "C" int clock_nanosleep(clockid_t clock_id, int flags,
-                           const struct timespec *request,
-                           struct timespec *remain);
-
+#include <time.h>
 
 namespace android {
 namespace intel {
diff --git a/moorefield_hdmi/common/utils/HwcTrace.h b/moorefield_hdmi/common/utils/HwcTrace.h
index f966eaa..790cf5e 100644
--- a/moorefield_hdmi/common/utils/HwcTrace.h
+++ b/moorefield_hdmi/common/utils/HwcTrace.h
@@ -26,11 +26,11 @@
 #endif
 
 // Helper to automatically preappend classname::functionname to the log message
-#define VLOGTRACE(fmt,...)     ALOGV("%s: "fmt, __func__, ##__VA_ARGS__)
-#define DLOGTRACE(fmt,...)     ALOGD("%s: "fmt, __func__, ##__VA_ARGS__)
-#define ILOGTRACE(fmt,...)     ALOGI("%s: "fmt, __func__, ##__VA_ARGS__)
-#define WLOGTRACE(fmt,...)     ALOGW("%s: "fmt, __func__, ##__VA_ARGS__)
-#define ELOGTRACE(fmt,...)     ALOGE("%s: "fmt, __func__, ##__VA_ARGS__)
+#define VLOGTRACE(fmt,...)     ALOGV("%s: " fmt, __func__, ##__VA_ARGS__)
+#define DLOGTRACE(fmt,...)     ALOGD("%s: " fmt, __func__, ##__VA_ARGS__)
+#define ILOGTRACE(fmt,...)     ALOGI("%s: " fmt, __func__, ##__VA_ARGS__)
+#define WLOGTRACE(fmt,...)     ALOGW("%s: " fmt, __func__, ##__VA_ARGS__)
+#define ELOGTRACE(fmt,...)     ALOGE("%s: " fmt, __func__, ##__VA_ARGS__)
 
 
 // Function call tracing
@@ -45,7 +45,7 @@
 
 // Arguments tracing
 #if 0
-#define ALOGTRACE(fmt,...)     ALOGV("%s(args): "fmt, __func__, ##__VA_ARGS__);
+#define ALOGTRACE(fmt,...)     ALOGV("%s(args): " fmt, __func__, ##__VA_ARGS__);
 #else
 #define ALOGTRACE(fmt,...)     ((void)0)
 #endif
diff --git a/moorefield_hdmi/include/DummyDevice.h b/moorefield_hdmi/include/DummyDevice.h
index 74625a9..9bae6e4 100755
--- a/moorefield_hdmi/include/DummyDevice.h
+++ b/moorefield_hdmi/include/DummyDevice.h
@@ -26,7 +26,7 @@
 
 class DummyDevice : public IDisplayDevice {
 public:
-    DummyDevice(uint32_t type, Hwcomposer& hwc);
+    DummyDevice(uint32_t disp, Hwcomposer& hwc);
     virtual ~DummyDevice();
 
 public:
@@ -61,7 +61,7 @@
     bool mInitialized;
     bool mConnected;
     bool mBlank;
-    uint32_t mType;
+    uint32_t mDisp;
     Hwcomposer& mHwc;
     SoftVsyncObserver *mVsyncObserver;
 
diff --git a/moorefield_hdmi/include/ExternalDevice.h b/moorefield_hdmi/include/ExternalDevice.h
index 6cf7332..a88f7eb 100755
--- a/moorefield_hdmi/include/ExternalDevice.h
+++ b/moorefield_hdmi/include/ExternalDevice.h
@@ -27,7 +27,7 @@
 class ExternalDevice : public PhysicalDevice {
 
 public:
-    ExternalDevice(Hwcomposer& hwc, DisplayPlaneManager& dpm);
+    ExternalDevice(uint32_t disp, Hwcomposer& hwc, DisplayPlaneManager& dpm);
     virtual ~ExternalDevice();
 public:
     virtual bool initialize();
@@ -63,7 +63,6 @@
     Condition mAbortModeSettingCond;
     drmModeModeInfo mPendingDrmMode;
     bool mHotplugEventPending;
-    int mExpectedRefreshRate;
 
 private:
     DECLARE_THREAD(ModeSettingThread, ExternalDevice);
diff --git a/moorefield_hdmi/include/PhysicalDevice.h b/moorefield_hdmi/include/PhysicalDevice.h
index f271021..795fb9b 100755
--- a/moorefield_hdmi/include/PhysicalDevice.h
+++ b/moorefield_hdmi/include/PhysicalDevice.h
@@ -32,7 +32,7 @@
 // Base class for primary and external devices
 class PhysicalDevice : public IDisplayDevice {
 public:
-    PhysicalDevice(uint32_t type, Hwcomposer& hwc, DisplayPlaneManager& dpm);
+    PhysicalDevice(uint32_t disp, uint32_t type, Hwcomposer& hwc, DisplayPlaneManager& dpm);
     virtual ~PhysicalDevice();
 public:
     virtual bool prePrepare(hwc_display_contents_1_t *display);
@@ -78,6 +78,7 @@
     friend class VsyncEventObserver;
 
 protected:
+    uint32_t mDisp;
     uint32_t mType;
     const char *mName;
 
diff --git a/moorefield_hdmi/include/PrimaryDevice.h b/moorefield_hdmi/include/PrimaryDevice.h
index 5ed6e93..00ab621 100755
--- a/moorefield_hdmi/include/PrimaryDevice.h
+++ b/moorefield_hdmi/include/PrimaryDevice.h
@@ -29,7 +29,7 @@
 
 class PrimaryDevice : public PhysicalDevice {
 public:
-    PrimaryDevice(Hwcomposer& hwc, DisplayPlaneManager& dpm);
+    PrimaryDevice(uint32_t disp, Hwcomposer& hwc, DisplayPlaneManager& dpm);
     virtual ~PrimaryDevice();
 public:
     virtual bool initialize();
diff --git a/moorefield_hdmi/include/pvr/hal/hal_public.h b/moorefield_hdmi/include/pvr/hal/hal_public.h
index 6de4a9b..5575719 100644
--- a/moorefield_hdmi/include/pvr/hal/hal_public.h
+++ b/moorefield_hdmi/include/pvr/hal/hal_public.h
@@ -21,262 +21,38 @@
  * THE SOFTWARE.
  */
 
-#ifndef HAL_PUBLIC_H
-#define HAL_PUBLIC_H
-
-/* Authors of third party hardware composer (HWC) modules will need to include
- * this header to access functionality in the gralloc HAL.
- */
+#ifndef __HAL_PUBLIC_H
+#define __HAL_PUBLIC_H
 
 #define PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC
-//#define SUPPORT_ANDROID_MEMTRACK_HAL
 
-#include <hardware/gralloc.h>
-#include <hardware/hwcomposer.h>
+#include "img_gralloc_public.h"
 
-#define ALIGN(x,a)		(((x) + (a) - 1L) & ~((a) - 1L))
-#define HW_ALIGN		32
-#define CAMERA_ALIGN    64
+#undef HAL_PIXEL_FORMAT_NV12
 
-/** YV12 specific (to handle different alignment) ****************************/
-
-/* We must align YV12 to a multiple of 32bytes as NEON optimizations
- * in stagefright require the YV12 planes to be 128bit aligned.
- * while display controller requires 64 bytes alignement
- */
-#define YV12_ALIGN 128
-
-#define HAL_PIXEL_FORMAT_BGRX_8888 0x101 // Keep consistent with android_utils.h 
-enum {
-	HAL_PIXEL_FORMAT_NV12   = 0x3231564E, // YCrCb 4:2:0 SP
-	HAL_PIXEL_FORMAT_NV21   = 0x3132564E, // YCrCb 4:2:0 SP
-	HAL_PIXEL_FORMAT_I420   = 0x30323449,
-	HAL_PIXEL_FORMAT_YUY2   = 0x32595559,
-	HAL_PIXEL_FORMAT_UYVY   = 0x59565955,
-
-	// Intel video decode formats
-	HAL_PIXEL_FORMAT_NV12_VED = 0x7FA00E00, //OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar
-	HAL_PIXEL_FORMAT_NV12_VEDT = 0x7FA00F00, //OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar_Tiled
-
-	HAL_PIXEL_FORMAT_YCbCr_422_P        = 0x12, // IYUV
-	HAL_PIXEL_FORMAT_YCbCr_420_P        = 0x13, // YUV9
-	HAL_PIXEL_FORMAT_YCbCr_420_I        = 0x15,
-
-	HAL_PIXEL_FORMAT_INTEL_UYVY  		= 0x107,
-	HAL_PIXEL_FORMAT_YCbCr_420_SP       = 0x108,
-	HAL_PIXEL_FORMAT_ZSL                = 0x109,
-};
-
-/* This can be tuned down as appropriate for the SOC.
- *
- * IMG formats are usually a single sub-alloc.
- * Some OEM video formats are two sub-allocs (Y, UV planes).
- * Future OEM video formats might be three sub-allocs (Y, U, V planes).
- */
-#define MAX_SUB_ALLOCS 3
-
-
-/* This defines the maximum server sync objects used per allocation. */
-
-/* Note: It's unfortunate that we have to change the handle size dependent
- * on a build option, but we have no choice because 'fd' fields must all
- * be utilized so they are valid to be dup'ed, and we don't need some of
- * the extra fds in a native_fence_sync build.
- */
-#if defined(PVR_ANDROID_NATIVE_WINDOW_HAS_SYNC)
-#define MAX_SRV_SYNC_OBJS    2
-#else
-#define MAX_SRV_SYNC_OBJS    4
-#endif
-
-typedef struct
+typedef struct _IMG_gralloc_module_
 {
-	native_handle_t base;
-
-	/* These fields can be sent cross process. They are also valid
-	 * to duplicate within the same process.
-	 *
-	 * A table is stored within psPrivateData on gralloc_module_t (this
-	 * is obviously per-process) which maps stamps to a mapped
-	 * PVRSRV_MEMDESC in that process. Each map entry has a lock
-	 * count associated with it, satisfying the requirements of the
-	 * Android API. This also prevents us from leaking maps/allocations.
-	 *
-	 * This table has entries inserted either by alloc()
-	 * (alloc_device_t) or map() (gralloc_module_t). Entries are removed
-	 * by free() (alloc_device_t) and unmap() (gralloc_module_t).
-	 */
-
-#define IMG_NATIVE_HANDLE_NUMFDS (MAX_SRV_SYNC_OBJS + MAX_SUB_ALLOCS)
-	/* The `syncfd' field is used to export PVRSRV_CLIENT_SYNC_PRIM to
-	 * another process. Its producer/consumer rules should match the
-	 * PVRSRV_MEMDESC handles, except that there is only one sync
-	 * per N memdesc objects.
-	 *
-	 * This should be listed before `fd' because it is not variable
-	 * width. The problem with variable width is that in the case we
-	 * export framebuffer allocations, we may want to patch some of
-	 * the fds to (unused) ints, so we can't leave gaps.
-	 */
-	int aiSyncFD[MAX_SRV_SYNC_OBJS];
-
-	/* The `fd' field is used to "export" a meminfo to another process.
-	 * Therefore, it is allocated by alloc_device_t, and consumed by
-	 * gralloc_module_t.
-	 */
-	int fd[MAX_SUB_ALLOCS];
-
-#define IMG_NATIVE_HANDLE_NUMINTS ((sizeof(unsigned long long) / sizeof(int)) + 5)
-	/* A KERNEL unique identifier for any exported kernel meminfo. Each
-	 * exported kernel meminfo will have a unique stamp, but note that in
-	 * userspace, several meminfos across multiple processes could have
-	 * the same stamp. As the native_handle can be dup(2)'d, there could be
-	 * multiple handles with the same stamp but different file descriptors.
-	 */
-	unsigned long long ui64Stamp;
-
-	/* This is used for buffer usage validation when locking a buffer,
-	 * and also in WSEGL (for the composition bypass feature).
-	 */
-	int usage;
-
-	/* In order to do efficient cache flushes we need the buffer dimensions
-	 * and format. These are available on the ANativeWindowBuffer,
-	 * but the platform doesn't pass them down to the graphics HAL.
-	 *
-	 * These fields are also used in the composition bypass. In this
-	 * capacity, these are the "real" values for the backing allocation.
-	 */
-	int iWidth;
-	int iHeight;
-	int iFormat;
-	unsigned int uiBpp;
+	IMG_gralloc_module_public_t base;
+	void *(*GetDisplayDevice)(struct _IMG_gralloc_module_ *psGrallocModule);
+	int (*GetDisplayStatus)(struct _IMG_gralloc_module_ *psGrallocModule,
+							buffer_handle_t handle, uint32_t *pui32Status);
+	int (*GetBufferCPUAddresses)(gralloc_module_t const* module,
+								 buffer_handle_t buffer,
+								 void **ppvCpuVirtAddr, size_t *puSize);
+	int (*PutBufferCPUAddresses)(gralloc_module_t const* module,
+								 buffer_handle_t buffer);
 }
-__attribute__((aligned(sizeof(int)),packed)) IMG_native_handle_t;
+IMG_gralloc_module_t;
 
-typedef struct
-{
-	int l, t, w, h;
-}
-IMG_write_lock_rect_t;
+#define HAL_PIXEL_FORMAT_UYVY         0x107
+#define HAL_PIXEL_FORMAT_INTEL_ZSL    0x109
+#define HAL_PIXEL_FORMAT_NV12         0x3231564E
+#define HAL_PIXEL_FORMAT_NV21         0x3132564E
+#define HAL_PIXEL_FORMAT_I420         0x30323449
+#define HAL_PIXEL_FORMAT_YUY2         0x32595559
+#define HAL_PIXEL_FORMAT_NV12_VED     0x7FA00E00
+#define HAL_PIXEL_FORMAT_NV12_VEDT    0x7FA00F00
 
-/* Keep this in sync with SGX */
-typedef int (*IMG_buffer_format_compute_params_pfn)(
-	unsigned int uiPlane, int *piWidth, int *piHeight, int *piStride,
-	int *piVStride, unsigned long *pulPlaneOffset);
+#define GRALLOC_MODULE_GET_DISPLAY_STATUS_IMG 1001
 
-#define IMG_BFF_YUV					(1 << 0)
-#define IMG_BFF_UVCbCrORDERING		(1 << 1)
-#define IMG_BFF_CPU_CLEAR			(1 << 2)
-#define IMG_BFF_DONT_GPU_CLEAR		(1 << 3)
-#define IMG_BFF_PARTIAL_ALLOC		(1 << 4)
-#define IMG_BFF_NEVER_COMPRESS		(1 << 5)
-
-/* Keep this in sync with SGX */
-typedef struct IMG_buffer_format_public_t
-{
-	/* Buffer formats are returned as a linked list */
-	struct IMG_buffer_format_public_t *psNext;
-
-	/* HAL_PIXEL_FORMAT_... enumerant */
-	int iHalPixelFormat;
-
-	/* IMG_PIXFMT_... enumerant */
-	int iIMGPixelFormat;
-
-	/* Friendly name for format */
-	const char *const szName;
-
-	/* Bits (not bytes) per pixel */
-	unsigned int uiBpp;
-
-	/* Supported HW usage bits. If this is GRALLOC_USAGE_HW_MASK, all usages
-	 * are supported. Used for HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED.
-	 */
-	int iSupportedUsage;
-
-	/* Allocation description flags */
-	unsigned int uiFlags;
-
-	/* Utility function for adjusting YUV per-plane parameters */
-	IMG_buffer_format_compute_params_pfn pfnComputeParams;
-}
-IMG_buffer_format_public_t;
-
-#if defined(SUPPORT_ANDROID_MEMTRACK_HAL)
-
-#include <hardware/memtrack.h>
-
-typedef struct
-{
-	/* Base memtrack record, copied to caller */
-	struct memtrack_record	base;
-
-	/* Record type, for filtering cached records */
-	enum memtrack_type		eType;
-
-	/* Process ID, for filtering cached records */
-	pid_t					pid;
-}
-IMG_memtrack_record_public_t;
-
-#endif /* defined(SUPPORT_ANDROID_MEMTRACK_HAL) */
-
-typedef struct
-{
-	/* The original hwc layer */
-	hwc_layer_1_t *psLayer;
-
-	/* Custom data for the display engine */
-	uint32_t custom;
-}
-IMG_hwc_layer_t;
-
-typedef struct IMG_display_device_public_t {
-	int (*post)(struct IMG_display_device_public_t *dev, IMG_hwc_layer_t *layers,
-				int num_layers, int *releaseFenceFd);
-} IMG_display_device_public_t;
-
-typedef struct IMG_gralloc_module_public_t
-{
-	gralloc_module_t base;
-	IMG_display_device_public_t *psDisplayDevice;
-
-	/* Gets the head of the linked list of all registered formats */
-	const IMG_buffer_format_public_t *(*GetBufferFormats)(void);
-
-	/* Functionality before this point should be in sync with SGX.
-	 * After this point will be different.
-	 */
-
-	/* Custom-blit components in lieu of overlay hardware */
-	int (*Blit)(struct IMG_gralloc_module_public_t const *module,
-				 buffer_handle_t src, buffer_handle_t dest,
-				 int w, int h, int x, int y,
-				 int transform,
-				 int async);
-
-	int (*Blit3)(struct IMG_gralloc_module_public_t const *module,
-				 unsigned long long ui64SrcStamp, int iSrcWidth,
-				 int iSrcHeight, int iSrcFormat, int eSrcRotation,
-				 buffer_handle_t dest, int eDestRotation);
-
-#if defined(SUPPORT_ANDROID_MEMTRACK_HAL)
-	int (*GetMemTrackRecords)(struct IMG_gralloc_module_public_t const *module,
-							  IMG_memtrack_record_public_t **ppsRecords,
-							  size_t *puNumRecords);
-#endif /* defined(SUPPORT_ANDROID_MEMTRACK_HAL) */
-
-	/* Walk the above list and return only the specified format */
-	const IMG_buffer_format_public_t *(*GetBufferFormat)(int iFormat);
-/* intel hwc extension */
-	int (*getCpuAddress)(struct IMG_gralloc_module_public_t const *module,
-				buffer_handle_t handle,
-				void **virt, uint32_t *size);
-	int (*putCpuAddress)(struct IMG_gralloc_module_public_t const *module,
-			buffer_handle_t handle);
-	IMG_display_device_public_t *(*getDisplayDevice)(struct IMG_gralloc_module_public_t *module);
-}
-IMG_gralloc_module_public_t;
-
-#endif /* HAL_PUBLIC_H */
+#endif /* __HAL_PUBLIC_H */
diff --git a/moorefield_hdmi/include/pvr/hal/img_gralloc_public.h b/moorefield_hdmi/include/pvr/hal/img_gralloc_public.h
new file mode 100644
index 0000000..1b6ca50
--- /dev/null
+++ b/moorefield_hdmi/include/pvr/hal/img_gralloc_public.h
@@ -0,0 +1,302 @@
+/* Copyright (c) Imagination Technologies Ltd.
+ *
+ * The contents of this file are subject to the MIT license as set out below.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef HAL_PUBLIC_H
+#define HAL_PUBLIC_H
+
+/* Authors of third party hardware composer (HWC) modules will need to include
+ * this header to access functionality in the gralloc HAL.
+ */
+
+#include <hardware/gralloc.h>
+
+#define ALIGN(x,a)	(((x) + (a) - 1L) & ~((a) - 1L))
+#define HW_ALIGN	32
+
+/* Use bits [0-3] of "vendor format" bits as real format. Customers should
+ * use *only* the unassigned bits below for custom pixel formats, YUV or RGB.
+ *
+ * If there are no bits set in this part of the field, or other bits are set
+ * in the format outside of the "vendor format" mask, the non-extension format
+ * is used instead. Reserve 0 for this purpose.
+ */
+
+#define HAL_PIXEL_FORMAT_VENDOR_EXT(fmt) (0x100 | (fmt & 0xF))
+
+/*      Reserved ** DO NOT USE **    HAL_PIXEL_FORMAT_VENDOR_EXT(0) */
+#define HAL_PIXEL_FORMAT_BGRX_8888   HAL_PIXEL_FORMAT_VENDOR_EXT(1)
+#define HAL_PIXEL_FORMAT_sBGR_A_8888 HAL_PIXEL_FORMAT_VENDOR_EXT(2)
+#define HAL_PIXEL_FORMAT_sBGR_X_8888 HAL_PIXEL_FORMAT_VENDOR_EXT(3)
+/*      HAL_PIXEL_FORMAT_RGB_565     HAL_PIXEL_FORMAT_VENDOR_EXT(4) */
+/*      HAL_PIXEL_FORMAT_BGRA_8888   HAL_PIXEL_FORMAT_VENDOR_EXT(5) */
+#define HAL_PIXEL_FORMAT_NV12        HAL_PIXEL_FORMAT_VENDOR_EXT(6)
+/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(7) */
+/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(8) */
+/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(9) */
+/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(10) */
+/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(11) */
+/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(12) */
+/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(13) */
+/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(14) */
+/*      Free for customer use        HAL_PIXEL_FORMAT_VENDOR_EXT(15) */
+
+/* One of the below compression modes is OR'ed into bits [4-6] of the 8 bit
+ * "vendor format" field. If no bits are set in this "compression mask", the
+ * normal memory format for the pixel format is used. Otherwise the pixel
+ * data will be compressed in memory with the Rogue framebuffer compressor.
+ */
+
+#define HAL_FB_COMPRESSION_NONE                0
+#define HAL_FB_COMPRESSION_DIRECT_8x8          1
+#define HAL_FB_COMPRESSION_DIRECT_16x4         2
+#define HAL_FB_COMPRESSION_DIRECT_32x2         3
+#define HAL_FB_COMPRESSION_INDIRECT_8x8        4
+#define HAL_FB_COMPRESSION_INDIRECT_16x4       5
+#define HAL_FB_COMPRESSION_INDIRECT_4TILE_8x8  6
+#define HAL_FB_COMPRESSION_INDIRECT_4TILE_16x4 7
+
+/* The memory layout is OR'ed into bit 7 (top bit) of the 8 bit "vendor
+ * format" field. Only STRIDED and TWIDDLED are supported; there is no space
+ * for PAGETILED.
+ */
+#define HAL_FB_MEMLAYOUT_STRIDED               0
+#define HAL_FB_MEMLAYOUT_TWIDDLED              1
+
+/* This can be tuned down as appropriate for the SOC.
+ *
+ * IMG formats are usually a single sub-alloc.
+ * Some OEM video formats are two sub-allocs (Y, UV planes).
+ * Future OEM video formats might be three sub-allocs (Y, U, V planes).
+ */
+#define MAX_SUB_ALLOCS (3)
+
+typedef struct
+{
+	native_handle_t base;
+
+	/* These fields can be sent cross process. They are also valid
+	 * to duplicate within the same process.
+	 *
+	 * A table is stored within psPrivateData on gralloc_module_t (this
+	 * is obviously per-process) which maps stamps to a mapped
+	 * PVRSRV_MEMDESC in that process. Each map entry has a lock
+	 * count associated with it, satisfying the requirements of the
+	 * Android API. This also prevents us from leaking maps/allocations.
+	 *
+	 * This table has entries inserted either by alloc()
+	 * (alloc_device_t) or map() (gralloc_module_t). Entries are removed
+	 * by free() (alloc_device_t) and unmap() (gralloc_module_t).
+	 */
+
+#define IMG_NATIVE_HANDLE_NUMFDS (MAX_SUB_ALLOCS)
+	/* The `fd' field is used to "export" a meminfo to another process.
+	 * Therefore, it is allocated by alloc_device_t, and consumed by
+	 * gralloc_module_t.
+	 */
+	int fd[IMG_NATIVE_HANDLE_NUMFDS];
+
+	/* This define should represent the number of packed 'int's required to
+	 * represent the fields following it. If you add a data type that is
+	 * 64-bit, for example using 'unsigned long long', you should write that
+	 * as "sizeof(unsigned long long) / sizeof(int)". Please keep the order
+	 * of the additions the same as the defined field order.
+	 */
+#define IMG_NATIVE_HANDLE_NUMINTS \
+	(sizeof(unsigned long long) / sizeof(int) + \
+	 6 + MAX_SUB_ALLOCS + MAX_SUB_ALLOCS + \
+	 sizeof(unsigned long long) / sizeof(int) * MAX_SUB_ALLOCS + \
+	 1)
+	/* A KERNEL unique identifier for any exported kernel meminfo. Each
+	 * exported kernel meminfo will have a unique stamp, but note that in
+	 * userspace, several meminfos across multiple processes could have
+	 * the same stamp. As the native_handle can be dup(2)'d, there could be
+	 * multiple handles with the same stamp but different file descriptors.
+	 */
+	unsigned long long ui64Stamp;
+
+	/* This is used for buffer usage validation */
+	int usage;
+
+	/* In order to do efficient cache flushes we need the buffer dimensions,
+	 * format and bits per pixel. There are ANativeWindow queries for the
+	 * width, height and format, but the graphics HAL might have remapped the
+	 * request to different values at allocation time. These are the 'true'
+	 * values of the buffer allocation.
+	 */
+	int iWidth;
+	int iHeight;
+	int iFormat;
+	unsigned int uiBpp;
+
+	/* Planes are not the same as the `fd' suballocs. A multi-planar YUV
+	 * allocation has different planes (interleaved = 1, semi-planar = 2,
+	 * fully-planar = 3) but might be spread across 1, 2 or 3 independent
+	 * memory allocations (or not).
+	 */
+	int iPlanes;
+
+	/* For multi-planar allocations, there will be multiple hstrides */
+	int aiStride[MAX_SUB_ALLOCS];
+
+	/* For multi-planar allocations, there will be multiple vstrides */
+	int aiVStride[MAX_SUB_ALLOCS];
+
+	/* These byte offsets are reconciled with the number of sub-allocs used
+	 * for a multi-planar allocation. If there is a 1:1 mapping between the
+	 * number of planes and the number of sub-allocs, these will all be zero.
+	 *
+	 * Otherwise, normally the zeroth entry will be zero, and the latter
+	 * entries will be non-zero.
+	 */
+	unsigned long long aulPlaneOffset[MAX_SUB_ALLOCS];
+
+	/* This records the number of MAX_SUB_ALLOCS fds actually used by the
+	 * buffer allocation. File descriptors up to fd[iNumSubAllocs - 1] are
+	 * guaranteed to be valid. (This does not have any bearing on the aiStride,
+	 * aiVStride or aulPlaneOffset fields, as `iPlanes' of those arrays should
+	 * be initialized, not `iNumSubAllocs'.)
+	 */
+	int iNumSubAllocs;
+}
+__attribute__((aligned(sizeof(int)),packed)) IMG_native_handle_t;
+
+typedef struct
+{
+	int l, t, w, h;
+}
+IMG_write_lock_rect_t;
+
+#define IMG_BFF_YUV					(1 << 0)
+#define IMG_BFF_UVCbCrORDERING		(1 << 1)
+#define IMG_BFF_CPU_CLEAR			(1 << 2)
+#define IMG_BFF_DONT_GPU_CLEAR		(1 << 3)
+#define IMG_BFF_PARTIAL_ALLOC		(1 << 4)
+#define IMG_BFF_NEVER_COMPRESS		(1 << 5)
+
+/* Keep this in sync with SGX */
+typedef struct IMG_buffer_format_public_t
+{
+	/* Buffer formats are returned as a linked list */
+	struct IMG_buffer_format_public_t *psNext;
+
+	/* HAL_PIXEL_FORMAT_... enumerant */
+	int iHalPixelFormat;
+
+	/* IMG_PIXFMT_... enumerant */
+	int iIMGPixelFormat;
+
+	/* Friendly name for format */
+	const char *const szName;
+
+	/* Bits (not bytes) per pixel */
+	unsigned int uiBpp;
+
+	/* Supported HW usage bits. If this is GRALLOC_USAGE_HW_MASK, all usages
+	 * are supported. Used for HAL_PIXEL_FORMAT_IMPLEMENTATION_DEFINED.
+	 */
+	int iSupportedUsage;
+
+	/* Allocation description flags */
+	unsigned int uiFlags;
+}
+IMG_buffer_format_public_t;
+
+/* NOTE: This interface is deprecated. Use module->perform() instead. */
+typedef struct IMG_gralloc_module_public_t
+{
+	gralloc_module_t base;
+
+	/* Gets the head of the linked list of all registered formats */
+	const IMG_buffer_format_public_t *(*GetBufferFormats)(void);
+
+	/* Custom-blit components in lieu of overlay hardware */
+	int (*Blit)(struct IMG_gralloc_module_public_t const *module,
+				 buffer_handle_t src, buffer_handle_t dest,
+				 int w, int h, int x, int y, int transform,
+				 int iInputFenceFd, int *piOutputFenceFd);
+
+	int (*Blit3)(struct IMG_gralloc_module_public_t const *module,
+				 unsigned long long ui64SrcStamp, int iSrcWidth,
+				 int iSrcHeight, int iSrcFormat, int iSrcStrideInPixels,
+				 int eSrcRotation, buffer_handle_t dest, int eDestRotation,
+				 int iInputFenceFd, int *piOutputFenceFd);
+
+	/* Walk the above list and return only the specified format */
+	const IMG_buffer_format_public_t *(*GetBufferFormat)(int iFormat);
+}
+IMG_gralloc_module_public_t;
+
+/* Helpers for using the non-type-safe perform() extension functions. Use
+ * these helpers instead of calling perform() directly in your application.
+ */
+
+#define GRALLOC_MODULE_GET_BUFFER_FORMAT_IMG     1
+#define GRALLOC_MODULE_GET_BUFFER_FORMATS_IMG    2
+#define GRALLOC_MODULE_BLIT_HANDLE_TO_HANDLE_IMG 3
+#define GRALLOC_MODULE_BLIT_STAMP_TO_HANDLE_IMG  4
+
+static inline int
+gralloc_module_get_buffer_format_img(const gralloc_module_t *module,
+									 int format,
+									 const IMG_buffer_format_public_t **v)
+{
+	return module->perform(module, GRALLOC_MODULE_GET_BUFFER_FORMAT_IMG,
+						   format, v);
+}
+
+static inline int
+gralloc_module_get_buffer_formats_img(const gralloc_module_t *module,
+									  const IMG_buffer_format_public_t **v)
+{
+	return module->perform(module, GRALLOC_MODULE_GET_BUFFER_FORMATS_IMG, v);
+}
+
+static inline int
+gralloc_module_blit_handle_to_handle_img(const gralloc_module_t *module,
+										 buffer_handle_t src,
+										 buffer_handle_t dest,
+										 int w, int h, int x, int y,
+										 int transform, int input_fence,
+										 int *output_fence)
+{
+	return module->perform(module, GRALLOC_MODULE_BLIT_HANDLE_TO_HANDLE_IMG,
+						   src, dest, w, h, x, y, transform, input_fence,
+						   output_fence);
+}
+
+static inline int
+gralloc_module_blit_stamp_to_handle(const gralloc_module_t *module,
+									unsigned long long src_stamp,
+									int src_width, int src_height,
+									int src_format, int src_stride_in_pixels,
+									int src_rotation, buffer_handle_t dest,
+									int dest_rotation, int input_fence,
+									int *output_fence)
+{
+	return module->perform(module, GRALLOC_MODULE_BLIT_STAMP_TO_HANDLE_IMG,
+						   src_stamp, src_width, src_height, src_format,
+						   src_stride_in_pixels, src_rotation, dest,
+						   dest_rotation, input_fence, output_fence);
+}
+
+#endif /* HAL_PUBLIC_H */
diff --git a/moorefield_hdmi/ips/anniedale/AnnCursorPlane.cpp b/moorefield_hdmi/ips/anniedale/AnnCursorPlane.cpp
index e85a529..6280490 100644
--- a/moorefield_hdmi/ips/anniedale/AnnCursorPlane.cpp
+++ b/moorefield_hdmi/ips/anniedale/AnnCursorPlane.cpp
@@ -97,8 +97,6 @@
     // setup plane position
     int dstX = mPosition.x;
     int dstY = mPosition.y;
-    int dstW = mPosition.w;
-    int dstH = mPosition.h;
 
     if (h < w) {
         cursorSize = h;
@@ -148,7 +146,6 @@
     uint8_t *p = (uint8_t *)(mapper.getCpuAddress(0));
     uint8_t *srcPixel;
     uint32_t stride = mapper.getStride().rgb.stride;
-    uint8_t temp;
     if (!p) {
         return false;
     }
@@ -158,7 +155,6 @@
         for (int i = 0; i < cursorSize; i++) {
             for (int j = 0; j < cursorSize; j++) {
                 srcPixel = p + i*stride + j*4;
-                temp = srcPixel[0];
                 if (i >= mCrop.h || j >= mCrop.w) {
                     if (srcPixel[0] == 0 &&
                         srcPixel[3] == 0xff)
diff --git a/moorefield_hdmi/ips/anniedale/AnnOverlayPlane.cpp b/moorefield_hdmi/ips/anniedale/AnnOverlayPlane.cpp
index bfef06f..eca4d1e 100755
--- a/moorefield_hdmi/ips/anniedale/AnnOverlayPlane.cpp
+++ b/moorefield_hdmi/ips/anniedale/AnnOverlayPlane.cpp
@@ -190,7 +190,6 @@
 
     uint32_t yStride = mapper.getStride().yuv.yStride;
     uint32_t uvStride = mapper.getStride().yuv.uvStride;
-    uint32_t w = mapper.getWidth();
     uint32_t h = mapper.getHeight();
     uint32_t srcX= mapper.getCrop().x;
     uint32_t srcY= mapper.getCrop().y;
@@ -407,7 +406,7 @@
 
     if (format == HAL_PIXEL_FORMAT_BGRX_8888 ||
         format == HAL_PIXEL_FORMAT_BGRA_8888) {
-        backBuffer->YRGBSCALE = 1 << 15 | 0 << 3 || 0 << 20;
+        backBuffer->YRGBSCALE = 1 << 15 | 0 << 3 | 0 << 20;
         backBuffer->UVSCALEV = (1 << 16);
         return true;
     }
@@ -420,6 +419,14 @@
           dstWidth, dstHeight,
           mTransform);
 
+    if (mBobDeinterlace) {
+        float scaleY = (float)(srcHeight >> 1) / dstHeight;
+        if (scaleY > 4 || scaleY < 0.25) {
+            VLOGTRACE("Exceed scale limit for interlace, return false");
+            return false;
+        }
+    }
+
     // switch destination width/height for scale factor calculation
     // for 90/270 transformation
     if (mUseOverlayRotation && ((mTransform == HWC_TRANSFORM_ROT_90) ||
diff --git a/moorefield_hdmi/ips/anniedale/PlaneCapabilities.cpp b/moorefield_hdmi/ips/anniedale/PlaneCapabilities.cpp
index 736fff1..98901e7 100755
--- a/moorefield_hdmi/ips/anniedale/PlaneCapabilities.cpp
+++ b/moorefield_hdmi/ips/anniedale/PlaneCapabilities.cpp
@@ -77,8 +77,6 @@
 bool PlaneCapabilities::isSizeSupported(int planeType, HwcLayer *hwcLayer)
 {
     uint32_t format = hwcLayer->getFormat();
-    uint32_t w = hwcLayer->getBufferWidth();
-    uint32_t h = hwcLayer->getBufferHeight();
     const stride_t& stride = hwcLayer->getBufferStride();
 
     bool isYUVPacked;
@@ -138,7 +136,6 @@
 bool PlaneCapabilities::isBlendingSupported(int planeType, HwcLayer *hwcLayer)
 {
     uint32_t blending = (uint32_t)hwcLayer->getLayer()->blending;
-    uint8_t planeAlpha = hwcLayer->getLayer()->planeAlpha;
 
     if (planeType == DisplayPlane::PLANE_SPRITE || planeType == DisplayPlane::PLANE_PRIMARY) {
         // support premultipled & none blanding
@@ -227,7 +224,6 @@
         switch (trans) {
         case 0:
         case HAL_TRANSFORM_ROT_90:
-        case HAL_TRANSFORM_ROT_180:
         case HAL_TRANSFORM_ROT_270:
             return true;
         default:
diff --git a/moorefield_hdmi/ips/common/DrmConfig.cpp b/moorefield_hdmi/ips/common/DrmConfig.cpp
index 8575edb..79d3685 100644
--- a/moorefield_hdmi/ips/common/DrmConfig.cpp
+++ b/moorefield_hdmi/ips/common/DrmConfig.cpp
@@ -30,7 +30,7 @@
 uint32_t DrmConfig::getDrmConnector(int device)
 {
     if (device == IDisplayDevice::DEVICE_PRIMARY)
-        return DRM_MODE_CONNECTOR_MIPI;
+        return DRM_MODE_CONNECTOR_DSI;
     else if (device == IDisplayDevice::DEVICE_EXTERNAL)
         return DRM_MODE_CONNECTOR_DVID;
     return DRM_MODE_CONNECTOR_Unknown;
@@ -39,7 +39,7 @@
 uint32_t DrmConfig::getDrmEncoder(int device)
 {
     if (device == IDisplayDevice::DEVICE_PRIMARY)
-        return DRM_MODE_ENCODER_MIPI;
+        return DRM_MODE_ENCODER_DSI;
     else if (device == IDisplayDevice::DEVICE_EXTERNAL)
         return DRM_MODE_ENCODER_TMDS;
     return DRM_MODE_ENCODER_NONE;
diff --git a/moorefield_hdmi/ips/common/OverlayPlaneBase.cpp b/moorefield_hdmi/ips/common/OverlayPlaneBase.cpp
index 2a41177..173f194 100755
--- a/moorefield_hdmi/ips/common/OverlayPlaneBase.cpp
+++ b/moorefield_hdmi/ips/common/OverlayPlaneBase.cpp
@@ -345,9 +345,7 @@
     uint32_t yStride, uvStride;
     stride_t stride;
     int srcX, srcY, srcW, srcH;
-    int tmp;
 
-    DataBuffer *buf;
     ssize_t index;
     TTMBufferMapper *mapper;
     bool ret;
@@ -667,7 +665,6 @@
     uint32_t gttOffsetInBytes = (mapper.getGttOffsetInPage(0) << 12);
     uint32_t yStride = mapper.getStride().yuv.yStride;
     uint32_t uvStride = mapper.getStride().yuv.uvStride;
-    uint32_t w = mapper.getWidth();
     uint32_t h = mapper.getHeight();
     uint32_t srcX= mapper.getCrop().x;
     uint32_t srcY= mapper.getCrop().y;
@@ -1115,6 +1112,56 @@
     return true;
 }
 
+bool OverlayPlaneBase::colorSetup(BufferMapper& mapper)
+{
+    CTRACE();
+
+    OverlayBackBufferBlk *backBuffer = mBackBuffer[mCurrent]->buf;
+    if (!backBuffer) {
+        ELOGTRACE("invalid back buffer");
+        return false;
+    }
+
+    uint32_t format = mapper.getFormat();
+    if (format != OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar &&
+        format != OMX_INTEL_COLOR_FormatYUV420PackedSemiPlanar_Tiled) {
+
+        VLOGTRACE("Not video layer, use default color setting");
+        backBuffer->OCLRC0 = (OVERLAY_INIT_CONTRAST << 18) |
+                         (OVERLAY_INIT_BRIGHTNESS & 0xff);
+        backBuffer->OCLRC1 = OVERLAY_INIT_SATURATION;
+        backBuffer->OCONFIG &= ~(1 << 5);
+
+        return true;
+    }
+
+    struct VideoPayloadBuffer *payload;
+    payload = (struct VideoPayloadBuffer *)mapper.getCpuAddress(SUB_BUFFER1);
+    // check payload
+    if (!payload) {
+        ELOGTRACE("no payload found");
+        return false;
+    }
+
+    // BT.601 or BT.709
+    backBuffer->OCONFIG &= ~(1 << 5);
+    backBuffer->OCONFIG |= (payload->csc_mode << 5);
+
+    // no level expansion for video on HDMI
+    if (payload->video_range || mPipeConfig == (0x2 << 6)) {
+        // full range, no need to do level expansion
+        backBuffer->OCLRC0 = 0x1000000;
+        backBuffer->OCLRC1 = 0x80;
+    } else {
+        // level expansion for limited range
+        backBuffer->OCLRC0 = (OVERLAY_INIT_CONTRAST << 18) |
+                         (OVERLAY_INIT_BRIGHTNESS & 0xff);
+        backBuffer->OCLRC1 = OVERLAY_INIT_SATURATION;
+    }
+
+    return true;
+}
+
 bool OverlayPlaneBase::setDataBuffer(BufferMapper& grallocMapper)
 {
     BufferMapper *mapper;
@@ -1184,6 +1231,16 @@
         backBuffer->OCMD |= FIELD0;
         backBuffer->OCMD &= ~(BUFFER_SELECT);
         backBuffer->OCMD |= BUFFER0;
+    } else {
+        backBuffer->OCMD &= ~BUF_TYPE;
+        backBuffer->OCMD &= ~FIELD_SELECT;
+        backBuffer->OCMD &= ~(BUFFER_SELECT);
+    }
+
+    ret = colorSetup(*mapper);
+    if (ret == false) {
+        ELOGTRACE("failed to set up color parameters");
+        return false;
     }
 
     // add to active ttm buffers if it's a rotated buffer
diff --git a/moorefield_hdmi/ips/common/OverlayPlaneBase.h b/moorefield_hdmi/ips/common/OverlayPlaneBase.h
index 8f2572c..7229151 100644
--- a/moorefield_hdmi/ips/common/OverlayPlaneBase.h
+++ b/moorefield_hdmi/ips/common/OverlayPlaneBase.h
@@ -67,6 +67,7 @@
                                 bool isHoriz, bool isY,
                                 coeffPtr pCoeff);
     virtual bool scalingSetup(BufferMapper& mapper);
+    virtual bool colorSetup(BufferMapper& mapper);
     virtual void checkPosition(int& x, int& y, int& w, int& h);
     virtual void checkCrop(int& x, int& y, int& w, int& h, int coded_width, int coded_height);
 
diff --git a/moorefield_hdmi/ips/common/RotationBufferProvider.cpp b/moorefield_hdmi/ips/common/RotationBufferProvider.cpp
index 22fdf60..3c23b6b 100644
--- a/moorefield_hdmi/ips/common/RotationBufferProvider.cpp
+++ b/moorefield_hdmi/ips/common/RotationBufferProvider.cpp
@@ -380,7 +380,6 @@
     uint32_t setup_Begin = getMilliseconds();
 #endif
     VAStatus vaStatus;
-    int stride;
     bool ret = false;
 
     if (payload->format != VA_FOURCC_NV12 || payload->width == 0 || payload->height == 0) {
@@ -513,7 +512,7 @@
 
 bool RotationBufferProvider::prepareBufferInfo(int w, int h, int stride, VideoPayloadBuffer *payload, void *user_pt)
 {
-    int chroma_offset, size;
+    int size;
     void *buf = NULL;
 
     payload->width = payload->crop_width = w;
@@ -525,7 +524,6 @@
     payload->chroma_v_stride = stride;
     payload->client_transform = 0;
 
-    chroma_offset = stride * h;
     size = stride * h + stride * h / 2;
 
     ssize_t index;
diff --git a/moorefield_hdmi/ips/common/VideoPayloadBuffer.h b/moorefield_hdmi/ips/common/VideoPayloadBuffer.h
index 48dc273..e6b1879 100644
--- a/moorefield_hdmi/ips/common/VideoPayloadBuffer.h
+++ b/moorefield_hdmi/ips/common/VideoPayloadBuffer.h
@@ -63,6 +63,8 @@
 
     uint32_t coded_width;
     uint32_t coded_height;
+    uint32_t csc_mode;
+    uint32_t video_range;
 };
 
 
diff --git a/moorefield_hdmi/ips/common/WsbmWrapper.c b/moorefield_hdmi/ips/common/WsbmWrapper.c
index 08ddefc..8d7c275 100644
--- a/moorefield_hdmi/ips/common/WsbmWrapper.c
+++ b/moorefield_hdmi/ips/common/WsbmWrapper.c
@@ -14,6 +14,8 @@
 // limitations under the License.
 */
 
+#include <malloc.h>
+#include <string.h>
 #include <wsbm_pool.h>
 #include <wsbm_driver.h>
 #include <wsbm_manager.h>
@@ -156,7 +158,6 @@
 {
     struct _WsbmBufferObject * wsbmBuf = NULL;
     int ret = 0;
-    int offset = 0;
 
     ALOGTRACE("size %d", align_to(size, 4096));
 
@@ -177,7 +178,7 @@
 
     ret = wsbmBODataUB(wsbmBuf,
                        align_to(size, 4096), NULL, NULL, 0,
-                       user_pt);
+                       user_pt, -1);
 
     if(ret) {
         ELOGTRACE("wsbmBOData failed with error code %d", ret);
@@ -195,7 +196,6 @@
 {
     struct _WsbmBufferObject * wsbmBuf = NULL;
     int ret = 0;
-    int offset = 0;
 
     ALOGTRACE("size %d", align_to(size, 4096));
 
@@ -296,7 +296,7 @@
     }
 
     wsbmBuf = (struct _WsbmBufferObject *)buf;
-    ret = wsbmBODataUB(wsbmBuf, size, NULL, NULL, 0, vaddr);
+    ret = wsbmBODataUB(wsbmBuf, size, NULL, NULL, 0, vaddr, -1);
     if (ret) {
         ELOGTRACE("wsbmBODataUB failed with error code %d", ret);
         return ret;
diff --git a/moorefield_hdmi/ips/tangier/TngDisplayContext.cpp b/moorefield_hdmi/ips/tangier/TngDisplayContext.cpp
index f745700..285f408 100755
--- a/moorefield_hdmi/ips/tangier/TngDisplayContext.cpp
+++ b/moorefield_hdmi/ips/tangier/TngDisplayContext.cpp
@@ -21,7 +21,6 @@
 #include <common/base/HwcLayerList.h>
 #include <ips/tangier/TngDisplayContext.h>
 
-
 namespace android {
 namespace intel {
 
@@ -51,7 +50,7 @@
     }
 
     // init IMG display device
-    mIMGDisplayDevice = (((IMG_gralloc_module_public_t *)module)->getDisplayDevice((IMG_gralloc_module_public_t *)module));
+    mIMGDisplayDevice = (IMG_display_device_public_t *)(((IMG_gralloc_module_t *)module)->GetDisplayDevice((IMG_gralloc_module_t *)module));
     if (!mIMGDisplayDevice) {
         ELOGTRACE("failed to get display device");
         return false;
diff --git a/moorefield_hdmi/ips/tangier/TngDisplayContext.h b/moorefield_hdmi/ips/tangier/TngDisplayContext.h
index fa526d7..00bef17 100755
--- a/moorefield_hdmi/ips/tangier/TngDisplayContext.h
+++ b/moorefield_hdmi/ips/tangier/TngDisplayContext.h
@@ -19,6 +19,20 @@
 #include <IDisplayContext.h>
 #include <hal_public.h>
 
+typedef struct
+{
+	hwc_layer_1_t *psLayer;
+	uint32_t custom;
+}
+IMG_hwc_layer_t;
+
+typedef struct IMG_display_device_public
+{
+	int (*post)(struct IMG_display_device_public *dev,
+				IMG_hwc_layer_t *layers, int num_layers, int *releaseFenceFd);
+}
+IMG_display_device_public_t;
+
 namespace android {
 namespace intel {
 
diff --git a/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.cpp b/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.cpp
index c46ccbd..1495379 100644
--- a/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.cpp
+++ b/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.cpp
@@ -25,7 +25,7 @@
 TngGrallocBufferMapper::TngGrallocBufferMapper(IMG_gralloc_module_public_t& module,
                                                     DataBuffer& buffer)
     : GrallocBufferMapperBase(buffer),
-      mIMGGrallocModule(module),
+      mIMGGrallocModule(reinterpret_cast<IMG_gralloc_module_t&>(module)),
       mBufferObject(0)
 {
     CTRACE();
@@ -34,7 +34,7 @@
 
     mClonedHandle = native_handle_create(h->numFds, h->numInts);
     if (mClonedHandle == 0) {
-        ALOGE("%s:Failed to create handle, out of memory!");
+        ELOGTRACE("Failed to create handle, out of memory!");
         return;
     }
     for (int i = 0; i < h->numFds; i++)
@@ -122,10 +122,11 @@
 
     CTRACE();
     // get virtual address
-    err = mIMGGrallocModule.getCpuAddress(&mIMGGrallocModule,
-                                          (buffer_handle_t)mClonedHandle,
-                                          vaddr,
-                                          size);
+    err = mIMGGrallocModule.GetBufferCPUAddresses(
+                                  (gralloc_module_t const*)&mIMGGrallocModule,
+                                  (buffer_handle_t)mClonedHandle,
+                                  vaddr,
+                                  size);
     if (err) {
         ELOGTRACE("failed to map. err = %d", err);
         return false;
@@ -161,8 +162,9 @@
         }
     }
 
-    err = mIMGGrallocModule.putCpuAddress(&mIMGGrallocModule,
-                                    (buffer_handle_t)mClonedHandle);
+    err = mIMGGrallocModule.PutBufferCPUAddresses(
+                                  (gralloc_module_t const*)&mIMGGrallocModule,
+                                  (buffer_handle_t)mClonedHandle);
     return false;
 }
 
@@ -182,8 +184,9 @@
         mSize[i] = 0;
     }
 
-    err = mIMGGrallocModule.putCpuAddress(&mIMGGrallocModule,
-                                    (buffer_handle_t)mClonedHandle);
+    err = mIMGGrallocModule.PutBufferCPUAddresses(
+                                  (gralloc_module_t const*)&mIMGGrallocModule,
+                                  (buffer_handle_t)mClonedHandle);
     if (err) {
         ELOGTRACE("failed to unmap. err = %d", err);
     }
@@ -236,10 +239,11 @@
     }
 
     // get virtual address
-    err = mIMGGrallocModule.getCpuAddress(&mIMGGrallocModule,
-                                          (buffer_handle_t)mClonedHandle,
-                                          vaddr,
-                                          size);
+    err = mIMGGrallocModule.GetBufferCPUAddresses(
+                                  (gralloc_module_t const*)&mIMGGrallocModule,
+                                  (buffer_handle_t)mClonedHandle,
+                                  vaddr,
+                                  size);
     if (err) {
         ELOGTRACE("failed to map. err = %d", err);
         return 0;
@@ -250,8 +254,9 @@
 
 void TngGrallocBufferMapper::putFbHandle()
 {
-    int err = mIMGGrallocModule.putCpuAddress(&mIMGGrallocModule,
-                                    (buffer_handle_t)mClonedHandle);
+    int err = mIMGGrallocModule.PutBufferCPUAddresses(
+                                  (gralloc_module_t const*)&mIMGGrallocModule,
+                                  (buffer_handle_t)mClonedHandle);
     if (err) {
         ELOGTRACE("failed to unmap. err = %d", err);
     }
diff --git a/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.h b/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.h
index 6525c3c..e3c15a8 100644
--- a/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.h
+++ b/moorefield_hdmi/ips/tangier/TngGrallocBufferMapper.h
@@ -40,7 +40,7 @@
     bool mapKhandle();
 
 private:
-    IMG_gralloc_module_public_t& mIMGGrallocModule;
+    IMG_gralloc_module_t& mIMGGrallocModule;
     void* mBufferObject;
     native_handle_t* mClonedHandle;
 };
diff --git a/moorefield_hdmi/platforms/merrifield_plus/PlatfBufferManager.cpp b/moorefield_hdmi/platforms/merrifield_plus/PlatfBufferManager.cpp
index 764c47b..69a30db 100755
--- a/moorefield_hdmi/platforms/merrifield_plus/PlatfBufferManager.cpp
+++ b/moorefield_hdmi/platforms/merrifield_plus/PlatfBufferManager.cpp
@@ -17,6 +17,7 @@
 #include <platforms/merrifield_plus/PlatfBufferManager.h>
 #include <ips/tangier/TngGrallocBuffer.h>
 #include <ips/tangier/TngGrallocBufferMapper.h>
+#include <sync/sync.h>
 
 namespace android {
 namespace intel {
@@ -63,13 +64,20 @@
 
 {
     IMG_gralloc_module_public_t *imgGrallocModule = (IMG_gralloc_module_public_t *) mGrallocModule;
+    int fenceFd;
+
     if (imgGrallocModule->Blit(imgGrallocModule, (buffer_handle_t)srcHandle,
                                 (buffer_handle_t)dstHandle,
                                 srcCrop.w, srcCrop.h, srcCrop.x,
-                                srcCrop.y, 0, async)) {
+                                srcCrop.y, 0, -1, &fenceFd)) {
         ELOGTRACE("Blit failed");
         return false;
     }
+
+    if (!async) {
+        sync_wait(fenceFd, -1);
+    }
+    close(fenceFd);
     return true;
 }
 
diff --git a/moorefield_hdmi/platforms/merrifield_plus/PlatfExternalDevice.cpp b/moorefield_hdmi/platforms/merrifield_plus/PlatfExternalDevice.cpp
index 8c36743..9def68d 100755
--- a/moorefield_hdmi/platforms/merrifield_plus/PlatfExternalDevice.cpp
+++ b/moorefield_hdmi/platforms/merrifield_plus/PlatfExternalDevice.cpp
@@ -23,9 +23,9 @@
 namespace android {
 namespace intel {
 
-PlatfExternalDevice::PlatfExternalDevice(Hwcomposer& hwc,
+PlatfExternalDevice::PlatfExternalDevice(uint32_t disp, Hwcomposer& hwc,
                                        DisplayPlaneManager& dpm)
-    : ExternalDevice(hwc, dpm)
+    : ExternalDevice(disp, hwc, dpm)
 {
     CTRACE();
 }
diff --git a/moorefield_hdmi/platforms/merrifield_plus/PlatfExternalDevice.h b/moorefield_hdmi/platforms/merrifield_plus/PlatfExternalDevice.h
index 7289260..edadd9a 100755
--- a/moorefield_hdmi/platforms/merrifield_plus/PlatfExternalDevice.h
+++ b/moorefield_hdmi/platforms/merrifield_plus/PlatfExternalDevice.h
@@ -23,7 +23,7 @@
 
 class PlatfExternalDevice : public ExternalDevice {
 public:
-    PlatfExternalDevice(Hwcomposer& hwc,
+    PlatfExternalDevice(uint32_t disp, Hwcomposer& hwc,
                         DisplayPlaneManager& dpm);
     virtual ~PlatfExternalDevice();
 
diff --git a/moorefield_hdmi/platforms/merrifield_plus/PlatfHwcomposer.cpp b/moorefield_hdmi/platforms/merrifield_plus/PlatfHwcomposer.cpp
index a681579..311cfca 100755
--- a/moorefield_hdmi/platforms/merrifield_plus/PlatfHwcomposer.cpp
+++ b/moorefield_hdmi/platforms/merrifield_plus/PlatfHwcomposer.cpp
@@ -59,16 +59,16 @@
     switch (disp) {
         case IDisplayDevice::DEVICE_PRIMARY:
 #ifdef INTEL_SUPPORT_HDMI_PRIMARY
-            return new PlatfExternalDevice(*this, dpm);
+            return new PlatfExternalDevice((uint32_t)disp, *this, dpm);
 #else
-            return new PlatfPrimaryDevice(*this, dpm);
+            return new PlatfPrimaryDevice((uint32_t)disp, *this, dpm);
 #endif
 
         case IDisplayDevice::DEVICE_EXTERNAL:
 #ifdef INTEL_SUPPORT_HDMI_PRIMARY
             return new DummyDevice((uint32_t)disp, *this);
 #else
-            return new PlatfExternalDevice(*this, dpm);
+            return new PlatfExternalDevice((uint32_t)disp, *this, dpm);
 #endif
 
         case IDisplayDevice::DEVICE_VIRTUAL:
diff --git a/moorefield_hdmi/platforms/merrifield_plus/PlatfPrimaryDevice.cpp b/moorefield_hdmi/platforms/merrifield_plus/PlatfPrimaryDevice.cpp
index d819e75..cd64246 100755
--- a/moorefield_hdmi/platforms/merrifield_plus/PlatfPrimaryDevice.cpp
+++ b/moorefield_hdmi/platforms/merrifield_plus/PlatfPrimaryDevice.cpp
@@ -22,9 +22,9 @@
 namespace android {
 namespace intel {
 
-PlatfPrimaryDevice::PlatfPrimaryDevice(Hwcomposer& hwc,
+PlatfPrimaryDevice::PlatfPrimaryDevice(uint32_t disp, Hwcomposer& hwc,
                                        DisplayPlaneManager& dpm)
-    : PrimaryDevice(hwc, dpm)
+    : PrimaryDevice(disp, hwc, dpm)
 {
     CTRACE();
 }
diff --git a/moorefield_hdmi/platforms/merrifield_plus/PlatfPrimaryDevice.h b/moorefield_hdmi/platforms/merrifield_plus/PlatfPrimaryDevice.h
index 14404d2..8684370 100755
--- a/moorefield_hdmi/platforms/merrifield_plus/PlatfPrimaryDevice.h
+++ b/moorefield_hdmi/platforms/merrifield_plus/PlatfPrimaryDevice.h
@@ -24,7 +24,7 @@
 
 class PlatfPrimaryDevice : public PrimaryDevice {
 public:
-    PlatfPrimaryDevice(Hwcomposer& hwc,
+    PlatfPrimaryDevice(uint32_t disp, Hwcomposer& hwc,
                         DisplayPlaneManager& dpm);
     virtual ~PlatfPrimaryDevice();