Merge "hwc: mdpcomp: Use actual usable mixer stages from driver"
diff --git a/Android.mk b/Android.mk
index 4a951c8..b3015af 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,14 +1,13 @@
 # This flag will be set to true during migration to Snapdragon Display Engine.
 TARGET_USES_SDE = false
 
-display-hals := libgralloc libcopybit liblight libmemtrack
+display-hals := libgralloc libcopybit liblight libmemtrack libqservice
 
 ifeq ($(TARGET_USES_SDE), true)
     sde-libs := displayengine/libs
     display-hals += $(sde-libs)/utils $(sde-libs)/core $(sde-libs)/hwc
 else
     display-hals += libgenlock libhwcomposer liboverlay libqdutils libhdmi
-    display-hals += libqservice
 endif
 
 ifeq ($(call is-vendor-board-platform,QCOM),true)
diff --git a/displayengine/include/core/core_interface.h b/displayengine/include/core/core_interface.h
old mode 100644
new mode 100755
index 45d9c8c..2229d1e
--- a/displayengine/include/core/core_interface.h
+++ b/displayengine/include/core/core_interface.h
@@ -35,20 +35,20 @@
 #include <stdint.h>
 
 #include "display_interface.h"
-#include "display_types.h"
+#include "sde_types.h"
 
-/*! @brief Display core interface version.
+/*! @brief Display engine interface version.
 
-  @details Display core interfaces are version tagged to maintain backward compatibility. This
+  @details Display engine interfaces are version tagged to maintain backward compatibility. This
   version is supplied as a default argument during display core initialization.
 
-  Client may use an older version of interfaces and link to a higher version of display core
+  Client may use an older version of interfaces and link to a higher version of display engine
   library, but vice versa is not allowed.
 
   A 32-bit client must use 32-bit display core library and a 64-bit client must use 64-bit display
   core library.
 
-  Display core interfaces follow default data structures alignment. Client must not override the
+  Display engine interfaces follow default data structures alignment. Client must not override the
   default padding rules while using these interfaces.
 
   @warning It is assumed that client upgrades or downgrades display core interface all at once
@@ -57,11 +57,11 @@
 
   @sa CoreInterface::CreateCore
 */
-#define CORE_REVISION_MAJOR (1)
-#define CORE_REVISION_MINOR (0)
+#define SDE_REVISION_MAJOR (1)
+#define SDE_REVISION_MINOR (0)
 
-#define CORE_VERSION_TAG ((uint32_t) ((CORE_REVISION_MAJOR << 24) | (CORE_REVISION_MINOR << 16) \
-                    | (sizeof(DisplayCompatibility) << 8) | sizeof(int *)))
+#define SDE_VERSION_TAG ((uint32_t) ((SDE_REVISION_MAJOR << 24) | (SDE_REVISION_MINOR << 16) | \
+                                    (sizeof(SDECompatibility) << 8) | sizeof(int *)))
 
 namespace sde {
 
@@ -120,15 +120,16 @@
     This interface shall be called only once.
 
     @param[in] event_handler \link CoreEventHandler \endlink
+    @param[in] log_handler \link LogHandler \endlink
     @param[out] interface \link CoreInterface \endlink
-    @param[in] version \link CORE_VERSION_TAG \endlink. Client must not override this argument.
+    @param[in] version \link SDE_VERSION_TAG \endlink. Client must not override this argument.
 
     @return \link DisplayError \endlink
 
     @sa DestroyCore
   */
-  static DisplayError CreateCore(CoreEventHandler *event_handler, CoreInterface **interface,
-                                 uint32_t version = CORE_VERSION_TAG);
+  static DisplayError CreateCore(CoreEventHandler *event_handler, LogHandler *log_handler,
+                                 CoreInterface **interface, uint32_t version = SDE_VERSION_TAG);
 
   /*! @brief Method to release handle to display core interface.
 
@@ -159,7 +160,7 @@
     @sa DestroyDisplay
   */
   virtual DisplayError CreateDisplay(DisplayType type, DisplayEventHandler *event_handler,
-                                    DisplayInterface **interface) = 0;
+                                     DisplayInterface **interface) = 0;
 
   /*! @brief Method to destroy a display device.
 
diff --git a/displayengine/include/core/display_interface.h b/displayengine/include/core/display_interface.h
old mode 100644
new mode 100755
index bb03921..dfe161b
--- a/displayengine/include/core/display_interface.h
+++ b/displayengine/include/core/display_interface.h
@@ -36,7 +36,7 @@
 #include <stdint.h>
 
 #include "layer_stack.h"
-#include "display_types.h"
+#include "sde_types.h"
 
 namespace sde {
 
diff --git a/displayengine/include/core/display_types.h b/displayengine/include/core/display_types.h
deleted file mode 100644
index 128e7d9..0000000
--- a/displayengine/include/core/display_types.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
-* Copyright (c) 2014, The Linux Foundation. All rights reserved.
-*
-* Redistribution and use in source and binary forms, with or without modification, are permitted
-* provided that the following conditions are met:
-*    * Redistributions of source code must retain the above copyright notice, this list of
-*      conditions and the following disclaimer.
-*    * Redistributions in binary form must reproduce the above copyright notice, this list of
-*      conditions and the following disclaimer in the documentation and/or other materials provided
-*      with the distribution.
-*    * Neither the name of The Linux Foundation nor the names of its contributors may be used to
-*      endorse or promote products derived from this software without specific prior written
-*      permission.
-*
-* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-* NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
-* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
-* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-*/
-
-/*! @file display_types.h
-  @brief This file contains miscellaneous data types used across display interfaces.
-*/
-#ifndef __DISPLAY_TYPES_H__
-#define __DISPLAY_TYPES_H__
-
-namespace sde {
-
-/*! @brief This enum represents different error codes that display interfaces may return.
-*/
-enum DisplayError {
-  kErrorNone = 0,         //!< Call executed successfully.
-  kErrorUndefined,        //!< An unspecified error has occured.
-  kErrorNotSupported,     //!< Requested operation is not supported.
-  kErrorVersion,          //!< Client is using advanced version of interfaces and calling into an
-                          //!< older version of display library.
-  kErrorDataAlignment,    //!< Client data structures are not aligned on naturual boundaries.
-  kErrorInstructionSet,   //!< 32-bit client is calling into 64-bit library or vice versa.
-  kErrorParameters,       //!< Invalid parameters passed to a method.
-  kErrorFileDescriptor,   //!< Invalid file descriptor.
-  kErrorMemory,           //!< System is running low on memory.
-  kErrorResources,        //!< Not enough hardware resources available to execute call.
-  kErrorHardware,         //!< A hardware error has occured.
-  kErrorTimeOut,          //!< The operation has timed out to prevent client from waiting forever.
-};
-
-/*! @brief This structure is defined for client and library compatibility check purpose only. This
-  structure is used in CORE_VERSION_TAG definition only. Client should not refer it directly for
-  any purpose.
-*/
-struct DisplayCompatibility {
-  char c1;
-  int i1;
-  char c2;
-  int i2;
-};
-
-}  // namespace sde
-
-#endif  // __DISPLAY_TYPES_H__
-
diff --git a/displayengine/include/core/dump_interface.h b/displayengine/include/core/dump_interface.h
old mode 100644
new mode 100755
index acdc71f..20ab748
--- a/displayengine/include/core/dump_interface.h
+++ b/displayengine/include/core/dump_interface.h
@@ -31,7 +31,7 @@
 
 #include <stdint.h>
 
-#include "display_types.h"
+#include "sde_types.h"
 
 namespace sde {
 
diff --git a/displayengine/include/core/layer_buffer.h b/displayengine/include/core/layer_buffer.h
old mode 100644
new mode 100755
index 421ab87..5e813ea
--- a/displayengine/include/core/layer_buffer.h
+++ b/displayengine/include/core/layer_buffer.h
@@ -31,7 +31,7 @@
 
 #include <stdint.h>
 
-#include "display_types.h"
+#include "sde_types.h"
 
 namespace sde {
 
@@ -76,6 +76,10 @@
                                       //!<    v(0), u(0), v(2), u(2) ... v(n-1), u(n-1)
                                       //!< aka NV21.
 
+  kFormatYCbCr420SemiPlanarVenus,     //!< Y-plane: y(0), y(1), y(2) ... y(n)
+                                      //!< 2x2 subsampled interleaved UV-plane:
+                                      //!<    u(0), v(0), u(2), v(2) ... u(n-1), v(n-1)
+
   /* All YUV-Packed formats, Any new format will be added towards end of this group to maintain
      backward compatibility.
   */
diff --git a/displayengine/include/core/layer_stack.h b/displayengine/include/core/layer_stack.h
old mode 100644
new mode 100755
index 74c1960..aa15753
--- a/displayengine/include/core/layer_stack.h
+++ b/displayengine/include/core/layer_stack.h
@@ -34,7 +34,7 @@
 #include <stdint.h>
 
 #include "layer_buffer.h"
-#include "display_types.h"
+#include "sde_types.h"
 
 namespace sde {
 
@@ -43,7 +43,7 @@
   @sa Layer
 */
 enum LayerBlending {
-  kBlendingNone = 0,        //!< Blend operation is not specified.
+  kBlendingNone,            //!< Blend operation is not specified.
 
   kBlendingOpaque,          //!< Pixel color is expressed using straight alpha in color tuples. It
                             //!< is constant blend operation. The layer would appear opaque if plane
@@ -217,7 +217,7 @@
   uint32_t layer_count;   //!< Total number of layers.
   LayerStackFlags flags;  //!< Flags associated with this layer set.
 
-  LayerStack() : output_buffer(NULL) { }
+  LayerStack() : output_buffer(NULL), layers(NULL), layer_count(0) { }
 };
 
 }  // namespace sde
diff --git a/displayengine/include/core/sde_types.h b/displayengine/include/core/sde_types.h
new file mode 100755
index 0000000..6090889
--- /dev/null
+++ b/displayengine/include/core/sde_types.h
@@ -0,0 +1,118 @@
+/*
+* Copyright (c) 2014, The Linux Foundation. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*    * Redistributions of source code must retain the above copyright notice, this list of
+*      conditions and the following disclaimer.
+*    * Redistributions in binary form must reproduce the above copyright notice, this list of
+*      conditions and the following disclaimer in the documentation and/or other materials provided
+*      with the distribution.
+*    * Neither the name of The Linux Foundation nor the names of its contributors may be used to
+*      endorse or promote products derived from this software without specific prior written
+*      permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*! @file sde_types.h
+  @brief This file contains miscellaneous data types used across display interfaces.
+*/
+#ifndef __SDE_TYPES_H__
+#define __SDE_TYPES_H__
+
+namespace sde {
+
+/*! @brief This enum represents different error codes that display interfaces may return.
+*/
+enum DisplayError {
+  kErrorNone,             //!< Call executed successfully.
+  kErrorUndefined,        //!< An unspecified error has occured.
+  kErrorNotSupported,     //!< Requested operation is not supported.
+  kErrorVersion,          //!< Client is using advanced version of interfaces and calling into an
+                          //!< older version of display library.
+  kErrorDataAlignment,    //!< Client data structures are not aligned on naturual boundaries.
+  kErrorInstructionSet,   //!< 32-bit client is calling into 64-bit library or vice versa.
+  kErrorParameters,       //!< Invalid parameters passed to a method.
+  kErrorFileDescriptor,   //!< Invalid file descriptor.
+  kErrorMemory,           //!< System is running low on memory.
+  kErrorResources,        //!< Not enough hardware resources available to execute call.
+  kErrorHardware,         //!< A hardware error has occured.
+  kErrorTimeOut,          //!< The operation has timed out to prevent client from waiting forever.
+};
+
+/*! @brief This enum represents different modules/logical unit tags that a log message may be
+  associated with. Client may use this to filter messages for dynamic logging.
+
+  @sa DisplayLogHandler
+*/
+enum LogTag {
+  kTagNone,             //!< Log is not tagged. This type of logs should always be printed.
+  kTagResources,        //!< Log is tagged for resource management.
+  kTagStrategy,         //!< Log is tagged for strategy decisions.
+};
+
+/*! @brief Display log handler class.
+
+  @details This class defines display log handler. The handle contains methods which client should
+  implement to get different levels of logging from display engine. Display engine will call into
+  these methods at appropriate times to send logging information.
+
+  @sa CoreInterface::CreateCore
+*/
+class LogHandler {
+ public:
+  /*! @brief Method to handle error messages.
+
+    @param[in] tag \link LogTag \endlink
+    @param[in] format \link message format with variable argument list \endlink
+  */
+  virtual void Error(LogTag tag, const char *format, ...) = 0;
+
+  /*! @brief Method to handle warning messages.
+
+    @param[in] tag \link LogTag \endlink
+    @param[in] format \link message format with variable argument list \endlink
+  */
+  virtual void Warning(LogTag tag, const char *format, ...) = 0;
+
+  /*! @brief Method to handle informative messages.
+
+    @param[in] tag \link LogTag \endlink
+    @param[in] format \link message format with variable argument list \endlink
+  */
+  virtual void Info(LogTag tag, const char *format, ...) = 0;
+
+  /*! @brief Method to handle verbose messages.
+
+    @param[in] tag \link LogTag \endlink
+    @param[in] format \link message format with variable argument list \endlink
+  */
+  virtual void Verbose(LogTag tag, const char *format, ...) = 0;
+
+ protected:
+  virtual ~LogHandler() { }
+};
+
+/*! @brief This structure is defined for client and library compatibility check purpose only. This
+  structure is used in SDE_VERSION_TAG definition only. Client should not refer it directly for
+  any purpose.
+*/
+struct SDECompatibility {
+  char c1;
+  int i1;
+  char c2;
+  int i2;
+};
+
+}  // namespace sde
+
+#endif  // __SDE_TYPES_H__
+
diff --git a/displayengine/include/private/strategy_interface.h b/displayengine/include/private/strategy_interface.h
old mode 100644
new mode 100755
index 8a3b789..ee9763e
--- a/displayengine/include/private/strategy_interface.h
+++ b/displayengine/include/private/strategy_interface.h
@@ -29,7 +29,7 @@
 #ifndef __STRATEGY_INTERFACE_H__
 #define __STRATEGY_INTERFACE_H__
 
-#include <core/display_types.h>
+#include <core/sde_types.h>
 
 namespace sde {
 
@@ -38,32 +38,69 @@
     @details This macro defines name for the composition strategy library. This macro shall be used
     to load library using dlopen().
 
-    @sa GetStrategyInterface
+    @sa CreateStrategyInterface
+    @sa DestoryStrategyInterface
 */
 #define STRATEGY_LIBRARY_NAME "libsdestrategy.so"
 
-/*! @brief Function name to get composer strategy interface
+/*! @brief Function name to create composer strategy interface
 
-    @details This macro defines function name for GetStrategyInterface() which will be implemented
+    @details This macro defines function name for CreateStrategyInterface() which is implemented
     in the composition strategy library. This macro shall be used to specify name of the function
     in dlsym().
 
-    @sa GetStrategyInterface
+    @sa CreateStrategyInterface
 */
-#define GET_STRATEGY_INTERFACE_NAME "GetStrategyInterface"
+#define CREATE_STRATEGY_INTERFACE_NAME "CreateStrategyInterface"
+
+/*! @brief Function name to destroy composer strategy interface
+
+    @details This macro defines function name for DestroyStrategyInterface() which is implemented
+    in the composition strategy library. This macro shall be used to specify name of the function
+    in dlsym().
+
+    @sa DestroyStrategyInterface
+*/
+#define DESTROY_STRATEGY_INTERFACE_NAME "DestroyStrategyInterface"
+
+/*! @brief Strategy interface version.
+
+  @details Strategy interface is version tagged to maintain backward compatibility. This version is
+  supplied as a default argument during strategy library initialization.
+
+  Client may use an older version of interfaces and link to a higher version of strategy library,
+  but vice versa is not allowed.
+
+  @sa CreateStrategyInterface
+*/
+#define STRATEGY_REVISION_MAJOR (1)
+#define STRATEGY_REVISION_MINOR (0)
+
+#define STRATEGY_VERSION_TAG ((uint16_t) ((STRATEGY_REVISION_MAJOR << 8) | STRATEGY_REVISION_MINOR))
 
 class StrategyInterface;
 
-/*! @brief Function to get composer strategy interface.
+/*! @brief Function to create composer strategy interface.
 
-    @details This function is used to get StrategyInterface object which resides in the composer
+    @details This function is used to create StrategyInterface object which resides in the composer
     strategy library loaded at runtime.
 
+    @param[out] version \link STRATEGY_VERSION_TAG \endlink
     @param[out] interface \link StrategyInterface \endlink
 
     @return \link DisplayError \endlink
 */
-typedef DisplayError (*GetStrategyInterface)(StrategyInterface **interface);
+typedef DisplayError (*CreateStrategyInterface)(uint16_t version, StrategyInterface **interface);
+
+/*! @brief Function to destroy composer strategy interface.
+
+    @details This function is used to destroy StrategyInterface object.
+
+    @param[in] interface \link StrategyInterface \endlink
+
+    @return \link DisplayError \endlink
+*/
+typedef DisplayError (*DestroyStrategyInterface)(StrategyInterface *interface);
 
 /*! @brief Maximum number of layers that can be handled by hardware in a given layer stack.
 */
@@ -78,16 +115,13 @@
   bool safe_mode;         //!< In this mode, strategy manager chooses the composition strategy
                           //!< that requires minimum number of pipe for the current frame. i.e.,
                           //!< video only composition, secure only composition or GPU composition
+
   uint32_t max_layers;    //!< Maximum number of layers that shall be programmed on hardware for the
                           //!< given layer stack.
 
   StrategyConstraints() : safe_mode(false), max_layers(kMaxSDELayers) { }
 };
 
-/*! @brief Flag to denote that GPU composition is performed for the given layer stack.
-*/
-const uint32_t kFlagGPU = 0x1;
-
 /*! @brief This structure encapsulates information about the input layer stack and the layers which
     shall be programmed on hardware.
 
@@ -99,12 +133,13 @@
   uint32_t index[kMaxSDELayers];
                             //!< Indexes of the layers from the layer stack which need to be
                             //!< programmed on hardware.
+
   uint32_t count;           //!< Total number of layers which need to be set on hardware.
-  uint32_t flags;           //!< Strategy flags. There is one flag set for each of the strategy
-                            //!< that has been selected for this layer stack. This flag is preserved
-                            //!< between multiple GetNextStrategy() calls. Composition manager
-                            //!< relies on the total flag count to check the number of strategies
-                            //!< that are attempted for this layer stack.
+
+  uint32_t flags;           //!< Strategy flags. Caller must reset it to 0 for a new layer stack.
+                            //!< A non-zero flag value indicates that a strategy has been selected
+                            //!< previously for the current layer stack. This flag must be
+                            //!< preserved between multiple GetNextStrategy() calls.
 
   HWLayersInfo() {
     Reset();
diff --git a/displayengine/include/utils/constants.h b/displayengine/include/utils/constants.h
index 7d7a39c..44b6896 100644
--- a/displayengine/include/utils/constants.h
+++ b/displayengine/include/utils/constants.h
@@ -43,8 +43,9 @@
 
 #define ROUND_UP(number, step) ((((number) + ((step) - 1)) / (step)) * (step))
 
-#define SET_BIT(value, bit) ((value) | (1 << (bit)))
-#define CLEAR_BIT(value, bit) ((value) & (~(1 << (bit))))
+#define SET_BIT(value, bit) (value |= (1 << (bit)))
+#define CLEAR_BIT(value, bit) (value &= (~(1 << (bit))))
+#define IS_BIT_SET(value, bit) (value & (1 << (bit)))
 
 namespace sde {
 
diff --git a/displayengine/include/utils/debug.h b/displayengine/include/utils/debug.h
old mode 100644
new mode 100755
index 0691dfc..8fbfb71
--- a/displayengine/include/utils/debug.h
+++ b/displayengine/include/utils/debug.h
@@ -25,45 +25,44 @@
 #ifndef __DEBUG_H__
 #define __DEBUG_H__
 
-#ifndef SDE_LOG_TAG
-#define SDE_LOG_TAG kLogTagNone
-#endif
+#include <core/sde_types.h>
 
-#ifndef SDE_MODULE_NAME
-#define SDE_MODULE_NAME "SDE"
-#endif
+#define DLOG(tag, method, format, ...) Debug::GetLogHandler()->method(tag, \
+                                            __CLASS__ "::%s: " format, __FUNCTION__, ##__VA_ARGS__)
 
-#define DLOG(method, format, ...) Debug::method(SDE_LOG_TAG, SDE_MODULE_NAME ": " format, \
-                                                ##__VA_ARGS__)
+#define DLOGE_IF(tag, format, ...) DLOG(tag, Error, format, ##__VA_ARGS__)
+#define DLOGW_IF(tag, format, ...) DLOG(tag, Warning, format, ##__VA_ARGS__)
+#define DLOGI_IF(tag, format, ...) DLOG(tag, Info, format, ##__VA_ARGS__)
+#define DLOGV_IF(tag, format, ...) DLOG(tag, Verbose, format, ##__VA_ARGS__)
 
-// SDE_LOG_TAG and SDE_MODULE_NAME must be defined before #include this header file in
-// respective module, else default definitions are used.
-#define DLOGE(format, ...) DLOG(Error, format, ##__VA_ARGS__)
-#define DLOGW(format, ...) DLOG(Warning, format, ##__VA_ARGS__)
-#define DLOGI(format, ...) DLOG(Info, format, ##__VA_ARGS__)
-#define DLOGV(format, ...) DLOG(Verbose, format, ##__VA_ARGS__)
+#define DLOGE(format, ...) DLOGE_IF(kTagNone, format, ##__VA_ARGS__)
+#define DLOGW(format, ...) DLOGW_IF(kTagNone, format, ##__VA_ARGS__)
+#define DLOGI(format, ...) DLOGI_IF(kTagNone, format, ##__VA_ARGS__)
+#define DLOGV(format, ...) DLOGV_IF(kTagNone, format, ##__VA_ARGS__)
 
 namespace sde {
 
-enum LogTag {
-  kTagNone = 0,   // Log tag name is not specified.
-  kTagCore,       // Log is tagged for display core.
-  kTagStrategy,   // Log is tagged for composition strategy.
-};
-
 class Debug {
  public:
-  // Log handlers
-  static void Error(const LogTag &tag, const char *format, ...);
-  static void Warning(const LogTag &tag, const char *format, ...);
-  static void Info(const LogTag &tag, const char *format, ...);
-  static void Verbose(const LogTag &tag, const char *format, ...);
-
-  // Debug properties
-  static bool IsVirtualDriver() { return debug_.virtual_driver_; }
+  static inline void SetLogHandler(LogHandler *log_handler) { debug_.log_handler_ = log_handler; }
+  static inline LogHandler* GetLogHandler() { return debug_.log_handler_; }
+  static inline bool IsVirtualDriver() { return debug_.virtual_driver_; }
 
  private:
   Debug();
+
+  // By default, drop any log messages coming from Display Engine. It will be overriden by Display
+  // Engine client when core is successfully initialized.
+  class DefaultLogHandler : public LogHandler {
+   public:
+    virtual void Error(LogTag /*tag*/, const char */*format*/, ...) { }
+    virtual void Warning(LogTag /*tag*/, const char */*format*/, ...) { }
+    virtual void Info(LogTag /*tag*/, const char */*format*/, ...) { }
+    virtual void Verbose(LogTag /*tag*/, const char */*format*/, ...) { }
+  };
+
+  DefaultLogHandler default_log_handler_;
+  LogHandler *log_handler_;
   bool virtual_driver_;
   static Debug debug_;
 };
diff --git a/displayengine/libs/common.mk b/displayengine/libs/common.mk
deleted file mode 100644
index 79ba738..0000000
--- a/displayengine/libs/common.mk
+++ /dev/null
@@ -1,39 +0,0 @@
-#Common headers
-common_includes := hardware/qcom/display/displayengine/include/
-common_includes += hardware/qcom/display/libgralloc/
-common_includes += hardware/qcom/display/libcopybit/
-
-common_header_export_path := qcom/display
-
-#Common libraries external to display HAL
-common_libs := liblog libutils libcutils libhardware
-
-#Common C flags
-common_flags := -DDEBUG_CALC_FPS -Wno-missing-field-initializers
-common_flags += -Wconversion -Wall -Werror
-common_flags += -Wno-unused-parameter -Wno-unused-variable
-
-ifeq ($(ARCH_ARM_HAVE_NEON),true)
-    common_flags += -D__ARM_HAVE_NEON
-endif
-
-ifeq ($(call is-board-platform-in-list, $(MSM_VIDC_TARGET_LIST)), true)
-    common_flags += -DVENUS_COLOR_FORMAT
-endif
-
-ifeq ($(call is-board-platform-in-list, msm8994), true)
-    common_flags += -DMDSS_TARGET
-endif
-
-common_deps  :=
-kernel_includes :=
-
-ifeq ($(call is-vendor-board-platform,QCOM),true)
-# This check is to pick the kernel headers from the right location.
-# If the macro above is defined, we make the assumption that we have the kernel
-# available in the build tree.
-# If the macro is not present, the headers are picked from hardware/qcom/msmXXXX
-# failing which, they are picked from bionic.
-    common_deps += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
-    kernel_includes += $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
-endif
diff --git a/displayengine/libs/core/Android.mk b/displayengine/libs/core/Android.mk
index 337cb73..92569a5 100644
--- a/displayengine/libs/core/Android.mk
+++ b/displayengine/libs/core/Android.mk
@@ -1,13 +1,15 @@
 LOCAL_PATH := $(call my-dir)
-include hardware/qcom/display/displayengine/libs/common.mk
 include $(CLEAR_VARS)
 
 LOCAL_MODULE                  := libsde
 LOCAL_MODULE_TAGS             := optional
-LOCAL_C_INCLUDES              := $(common_includes) $(kernel_includes)
-LOCAL_CFLAGS                  := $(common_flags) -DLOG_TAG=\"SDE\"
-LOCAL_SHARED_LIBRARIES        := $(common_libs) libdl libsdeutils
-LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
+LOCAL_C_INCLUDES              := hardware/qcom/display/displayengine/include/ \
+                                 $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr/include
+LOCAL_CFLAGS                  := -Wno-missing-field-initializers -Wno-unused-parameter \
+                                 -Wconversion -Wall -Werror \
+                                 -DLOG_TAG=\"SDE\"
+LOCAL_SHARED_LIBRARIES        := libdl libsdeutils
+LOCAL_ADDITIONAL_DEPENDENCIES := $(TARGET_OUT_INTERMEDIATES)/KERNEL_OBJ/usr
 LOCAL_SRC_FILES               := core_interface.cpp \
                                  core_impl.cpp \
                                  display_base.cpp \
diff --git a/displayengine/libs/core/comp_manager.cpp b/displayengine/libs/core/comp_manager.cpp
old mode 100644
new mode 100755
index 0d51bb0..916d558
--- a/displayengine/libs/core/comp_manager.cpp
+++ b/displayengine/libs/core/comp_manager.cpp
@@ -22,16 +22,14 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-// SDE_LOG_TAG definition must precede debug.h include.
-#define SDE_LOG_TAG kTagCore
-#define SDE_MODULE_NAME "CompManager"
-#include <utils/debug.h>
-
 #include <dlfcn.h>
 #include <utils/constants.h>
+#include <utils/debug.h>
 
 #include "comp_manager.h"
 
+#define __CLASS__ "CompManager"
+
 namespace sde {
 
 CompManager::CompManager() : strategy_lib_(NULL), strategy_intf_(NULL), registered_displays_(0),
@@ -44,27 +42,27 @@
   DisplayError error = kErrorNone;
 
   error = res_mgr_.Init(hw_res_info);
-  if (UNLIKELY(error != kErrorNone)) {
+  if (error != kErrorNone) {
     return error;
   }
 
   // Try to load strategy library & get handle to its interface.
   // Default to GPU only composition on failure.
   strategy_lib_ = ::dlopen(STRATEGY_LIBRARY_NAME, RTLD_NOW);
-  if (UNLIKELY(!strategy_lib_)) {
+  if (!strategy_lib_) {
     DLOGW("Unable to load = %s", STRATEGY_LIBRARY_NAME);
   } else {
-    GetStrategyInterface get_strategy_intf = NULL;
-    void **sym = reinterpret_cast<void **>(&get_strategy_intf);
-    *sym = ::dlsym(strategy_lib_, GET_STRATEGY_INTERFACE_NAME);
-    if (UNLIKELY(!get_strategy_intf)) {
-      DLOGW("Unable to find symbol for %s", GET_STRATEGY_INTERFACE_NAME);
-    } else if (UNLIKELY(get_strategy_intf(&strategy_intf_) != kErrorNone)) {
-      DLOGW("Unable to get handle to strategy interface");
+    CreateStrategyInterface create_strategy_intf = NULL;
+    void **sym = reinterpret_cast<void **>(&create_strategy_intf);
+    *sym = ::dlsym(strategy_lib_, CREATE_STRATEGY_INTERFACE_NAME);
+    if (!create_strategy_intf) {
+      DLOGW("Unable to find symbol for %s", CREATE_STRATEGY_INTERFACE_NAME);
+    } else if (create_strategy_intf(STRATEGY_VERSION_TAG, &strategy_intf_) != kErrorNone) {
+      DLOGW("Unable to create strategy interface");
     }
   }
 
-  if (UNLIKELY(!strategy_intf_)) {
+  if (!strategy_intf_) {
     DLOGI("Using GPU only composition");
     if (strategy_lib_) {
       ::dlclose(strategy_lib_);
@@ -80,8 +78,17 @@
   SCOPE_LOCK(locker_);
 
   if (strategy_lib_) {
+    DestroyStrategyInterface destroy_strategy_intf = NULL;
+    void **sym = reinterpret_cast<void **>(&destroy_strategy_intf);
+    *sym = ::dlsym(strategy_lib_, DESTROY_STRATEGY_INTERFACE_NAME);
+    if (!destroy_strategy_intf) {
+      DLOGW("Unable to find symbol for %s", DESTROY_STRATEGY_INTERFACE_NAME);
+    } else if (destroy_strategy_intf(strategy_intf_) != kErrorNone) {
+      DLOGW("Unable to destroy strategy interface");
+    }
     ::dlclose(strategy_lib_);
   }
+
   res_mgr_.Deinit();
 
   return kErrorNone;
@@ -134,7 +141,7 @@
 
   constraints->safe_mode = safe_mode_;
   // If validation for the best available composition strategy with driver has failed, just
-  // fallback to GPU composition.
+  // fallback to safe mode composition e.g. GPU or video only.
   if (UNLIKELY(hw_layers->info.flags)) {
     constraints->safe_mode = true;
     return;
@@ -160,7 +167,7 @@
       // Composition strategies exhausted. Resource Manager could not allocate resources even for
       // GPU composition. This will never happen.
       DLOGE("Unexpected failure. Composition strategies exhausted.");
-      return error;
+      break;
     }
 
     error = res_mgr_.Acquire(display_resource_ctx, hw_layers);
@@ -174,7 +181,7 @@
   }
   res_mgr_.Stop(display_resource_ctx);
 
-  return kErrorNone;
+  return error;
 }
 
 void CompManager::PostPrepare(Handle display_ctx, HWLayers *hw_layers) {
diff --git a/displayengine/libs/core/comp_manager.h b/displayengine/libs/core/comp_manager.h
index 492500a..13452b8 100644
--- a/displayengine/libs/core/comp_manager.h
+++ b/displayengine/libs/core/comp_manager.h
@@ -52,6 +52,7 @@
 
  private:
   void PrepareStrategyConstraints(Handle display_ctx, HWLayers *hw_layers);
+
   struct DisplayCompositionContext {
     StrategyConstraints constraints;
     Handle display_resource_ctx;
diff --git a/displayengine/libs/core/core_impl.cpp b/displayengine/libs/core/core_impl.cpp
old mode 100644
new mode 100755
index a3dfde1..0669f9f
--- a/displayengine/libs/core/core_impl.cpp
+++ b/displayengine/libs/core/core_impl.cpp
@@ -22,19 +22,17 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-// SDE_LOG_TAG definition must precede debug.h include.
-#define SDE_LOG_TAG kTagCore
-#define SDE_MODULE_NAME "CoreImpl"
-#include <utils/debug.h>
-
 #include <utils/locker.h>
 #include <utils/constants.h>
+#include <utils/debug.h>
 
 #include "core_impl.h"
 #include "display_primary.h"
 #include "display_hdmi.h"
 #include "display_virtual.h"
 
+#define __CLASS__ "CoreImpl"
+
 namespace sde {
 
 CoreImpl::CoreImpl(CoreEventHandler *event_handler)
diff --git a/displayengine/libs/core/core_interface.cpp b/displayengine/libs/core/core_interface.cpp
old mode 100644
new mode 100755
index 7cd85b0..fb8700a
--- a/displayengine/libs/core/core_interface.cpp
+++ b/displayengine/libs/core/core_interface.cpp
@@ -22,16 +22,14 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-// SDE_LOG_TAG definition must precede debug.h include.
-#define SDE_LOG_TAG kTagCore
-#define SDE_MODULE_NAME "CoreInterface"
-#include <utils/debug.h>
-
 #include <utils/locker.h>
 #include <utils/constants.h>
+#include <utils/debug.h>
 
 #include "core_impl.h"
 
+#define __CLASS__ "CoreInterface"
+
 #define GET_REVISION(version) (version >> 16)
 #define GET_DATA_ALIGNMENT(version) ((version >> 8) & 0xFF)
 #define GET_INSTRUCTION_SET(version) (version & 0xFF)
@@ -47,19 +45,17 @@
   Locker locker;
 } g_core;
 
-DisplayError CoreInterface::CreateCore(CoreEventHandler *event_handler, CoreInterface **interface,
-                                 uint32_t client_version) {
+DisplayError CoreInterface::CreateCore(CoreEventHandler *event_handler, LogHandler *log_handler,
+                                       CoreInterface **interface, uint32_t client_version) {
   SCOPE_LOCK(g_core.locker);
 
-  if (UNLIKELY(!event_handler || !interface)) {
+  if (UNLIKELY(!event_handler || !log_handler || !interface)) {
     return kErrorParameters;
   }
 
   // Check compatibility of client and core.
-  uint32_t lib_version = CORE_VERSION_TAG;
-  if (UNLIKELY(!interface)) {
-    return kErrorParameters;
-  } else if (UNLIKELY(GET_REVISION(client_version) > GET_REVISION(lib_version))) {
+  uint32_t lib_version = SDE_VERSION_TAG;
+  if (UNLIKELY(GET_REVISION(client_version) > GET_REVISION(lib_version))) {
     return kErrorVersion;
   } else if (UNLIKELY(GET_DATA_ALIGNMENT(client_version) != GET_DATA_ALIGNMENT(lib_version))) {
     return kErrorDataAlignment;
@@ -69,10 +65,11 @@
 
   CoreImpl *&core_impl = g_core.core_impl;
   if (UNLIKELY(core_impl)) {
-    DLOGE("Only one display core session is supported at present.");
     return kErrorUndefined;
   }
 
+  Debug::SetLogHandler(log_handler);
+
   // Create appropriate CoreImpl object based on client version.
   if (GET_REVISION(client_version) == CoreImpl::kRevision) {
     core_impl = new CoreImpl(event_handler);
@@ -84,11 +81,11 @@
     return kErrorMemory;
   }
 
-  DisplayError displayError = core_impl->Init();
-  if (UNLIKELY(displayError != kErrorNone)) {
+  DisplayError error = core_impl->Init();
+  if (UNLIKELY(error != kErrorNone)) {
     delete core_impl;
     core_impl = NULL;
-    return displayError;
+    return error;
   }
 
   *interface = core_impl;
diff --git a/displayengine/libs/core/display_base.cpp b/displayengine/libs/core/display_base.cpp
old mode 100644
new mode 100755
index 5b2d0af..6099231
--- a/displayengine/libs/core/display_base.cpp
+++ b/displayengine/libs/core/display_base.cpp
@@ -22,20 +22,18 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-// SDE_LOG_TAG definition must precede debug.h include.
-#define SDE_LOG_TAG kTagCore
-#define SDE_MODULE_NAME "DisplayBase"
+#include <utils/constants.h>
 #include <utils/debug.h>
 
-#include <utils/constants.h>
-
 #include "display_base.h"
 
+#define __CLASS__ "DisplayBase"
+
 namespace sde {
 
 DisplayBase::DisplayBase(DisplayType display_type, DisplayEventHandler *event_handler,
-                       HWBlockType hw_block_type, HWInterface *hw_intf, CompManager *comp_manager)
-  : display_type_(display_type), event_handler_(event_handler), hw_block_type_(hw_block_type),
+             HWDeviceType hw_device_type, HWInterface *hw_intf, CompManager *comp_manager)
+  : display_type_(display_type), event_handler_(event_handler), hw_device_type_(hw_device_type),
     hw_intf_(hw_intf), comp_manager_(comp_manager), state_(kStateOff), hw_device_(0),
     display_comp_ctx_(0), display_attributes_(NULL), num_modes_(0), active_mode_index_(0),
     pending_commit_(false), vsync_enable_(false) {
@@ -46,7 +44,7 @@
 
   DisplayError error = kErrorNone;
 
-  error = hw_intf_->Open(hw_block_type_, &hw_device_, this);
+  error = hw_intf_->Open(hw_device_type_, &hw_device_, this);
   if (UNLIKELY(error != kErrorNone)) {
     return error;
   }
@@ -224,7 +222,7 @@
 
   DisplayError error = kErrorNone;
 
-  DLOGI("Set state: %d", state);
+  DLOGI("Set state = %d", state);
 
   if (UNLIKELY(state == state_)) {
     DLOGI("Same state transition is requested.");
@@ -233,6 +231,7 @@
 
   switch (state) {
   case kStateOff:
+    hw_layers_.info.count = 0;
     comp_manager_->Purge(display_comp_ctx_);
     error = hw_intf_->PowerOff(hw_device_);
     break;
@@ -250,7 +249,7 @@
     break;
 
   default:
-    DLOGE("Spurious state %d transition requested.", state);
+    DLOGE("Spurious state = %d transition requested.", state);
     break;
   }
 
diff --git a/displayengine/libs/core/display_base.h b/displayengine/libs/core/display_base.h
index 5eaac37..7eaa044 100644
--- a/displayengine/libs/core/display_base.h
+++ b/displayengine/libs/core/display_base.h
@@ -37,7 +37,7 @@
 class DisplayBase : public DisplayInterface, HWEventHandler, DumpImpl {
  public:
   DisplayBase(DisplayType display_type, DisplayEventHandler *event_handler,
-             HWBlockType hw_block_type, HWInterface *hw_intf, CompManager *comp_manager);
+              HWDeviceType hw_device_type, HWInterface *hw_intf, CompManager *comp_manager);
   virtual ~DisplayBase() { }
   virtual DisplayError Init();
   virtual DisplayError Deinit();
@@ -64,7 +64,7 @@
   Locker locker_;
   DisplayType display_type_;
   DisplayEventHandler *event_handler_;
-  HWBlockType hw_block_type_;
+  HWDeviceType hw_device_type_;
   HWInterface *hw_intf_;
   CompManager *comp_manager_;
   DisplayState state_;
diff --git a/displayengine/libs/core/display_hdmi.cpp b/displayengine/libs/core/display_hdmi.cpp
old mode 100644
new mode 100755
index b44bc87..48208bf
--- a/displayengine/libs/core/display_hdmi.cpp
+++ b/displayengine/libs/core/display_hdmi.cpp
@@ -22,20 +22,18 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-// SDE_LOG_TAG definition must precede debug.h include.
-#define SDE_LOG_TAG kTagCore
-#define SDE_MODULE_NAME "DisplayHDMI"
+#include <utils/constants.h>
 #include <utils/debug.h>
 
-#include <utils/constants.h>
-
 #include "display_hdmi.h"
 
+#define __CLASS__ "DisplayHDMI"
+
 namespace sde {
 
 DisplayHDMI::DisplayHDMI(DisplayEventHandler *event_handler, HWInterface *hw_intf,
                          CompManager *comp_manager)
-  : DisplayBase(kHDMI, event_handler, kHWHDMI, hw_intf, comp_manager) {
+  : DisplayBase(kHDMI, event_handler, kDeviceHDMI, hw_intf, comp_manager) {
 }
 
 }  // namespace sde
diff --git a/displayengine/libs/core/display_primary.cpp b/displayengine/libs/core/display_primary.cpp
old mode 100644
new mode 100755
index 96ff08a..e4bd031
--- a/displayengine/libs/core/display_primary.cpp
+++ b/displayengine/libs/core/display_primary.cpp
@@ -22,20 +22,18 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-// SDE_LOG_TAG definition must precede debug.h include.
-#define SDE_LOG_TAG kTagCore
-#define SDE_MODULE_NAME "DisplayPrimary"
+#include <utils/constants.h>
 #include <utils/debug.h>
 
-#include <utils/constants.h>
-
 #include "display_primary.h"
 
+#define __CLASS__ "DisplayPrimary"
+
 namespace sde {
 
 DisplayPrimary::DisplayPrimary(DisplayEventHandler *event_handler, HWInterface *hw_intf,
                                CompManager *comp_manager)
-  : DisplayBase(kPrimary, event_handler, kHWPrimary, hw_intf, comp_manager) {
+  : DisplayBase(kPrimary, event_handler, kDevicePrimary, hw_intf, comp_manager) {
 }
 
 }  // namespace sde
diff --git a/displayengine/libs/core/display_virtual.cpp b/displayengine/libs/core/display_virtual.cpp
old mode 100644
new mode 100755
index dc18146..2fef178
--- a/displayengine/libs/core/display_virtual.cpp
+++ b/displayengine/libs/core/display_virtual.cpp
@@ -22,20 +22,18 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-// SDE_LOG_TAG definition must precede debug.h include.
-#define SDE_LOG_TAG kTagCore
-#define SDE_MODULE_NAME "DisplayVirtual"
+#include <utils/constants.h>
 #include <utils/debug.h>
 
-#include <utils/constants.h>
-
 #include "display_virtual.h"
 
+#define __CLASS__ "DisplayVirtual"
+
 namespace sde {
 
 DisplayVirtual::DisplayVirtual(DisplayEventHandler *event_handler, HWInterface *hw_intf,
                                CompManager *comp_manager)
-  : DisplayBase(kVirtual, event_handler, kHWBlockMax, hw_intf, comp_manager) {
+  : DisplayBase(kVirtual, event_handler, kDeviceVirtual, hw_intf, comp_manager) {
 }
 
 }  // namespace sde
diff --git a/displayengine/libs/core/dump_impl.cpp b/displayengine/libs/core/dump_impl.cpp
old mode 100644
new mode 100755
index b000ea7..a5aca81
--- a/displayengine/libs/core/dump_impl.cpp
+++ b/displayengine/libs/core/dump_impl.cpp
@@ -22,11 +22,6 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-// SDE_LOG_TAG definition must precede debug.h include.
-#define SDE_LOG_TAG kTagCore
-#define SDE_MODULE_NAME "DumpInterface"
-#include <utils/debug.h>
-
 #include <stdarg.h>
 #include <stdio.h>
 #include <string.h>
diff --git a/displayengine/libs/core/hw_framebuffer.cpp b/displayengine/libs/core/hw_framebuffer.cpp
old mode 100644
new mode 100755
index 63adf8c..69b4a58
--- a/displayengine/libs/core/hw_framebuffer.cpp
+++ b/displayengine/libs/core/hw_framebuffer.cpp
@@ -22,11 +22,7 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-// SDE_LOG_TAG definition must precede debug.h include.
-#define SDE_LOG_TAG kTagCore
-#define SDE_MODULE_NAME "HWFrameBuffer"
 #define __STDC_FORMAT_MACROS
-#include <utils/debug.h>
 
 #include <math.h>
 #include <fcntl.h>
@@ -39,9 +35,12 @@
 #include <sys/prctl.h>
 #include <pthread.h>
 #include <utils/constants.h>
+#include <utils/debug.h>
 
 #include "hw_framebuffer.h"
 
+#define __CLASS__ "HWFrameBuffer"
+
 #define IOCTL_LOGE(ioctl) DLOGE("ioctl %s, errno = %d, desc = %s", #ioctl, errno, strerror(errno))
 
 #ifdef DISPLAY_CORE_VIRTUAL_DRIVER
@@ -53,8 +52,6 @@
 extern FILE* virtual_fopen(const char *fname, const char *mode);
 extern int virtual_fclose(FILE* fileptr);
 extern ssize_t virtual_getline(char **lineptr, size_t *linelen, FILE *stream);
-
-
 #endif
 
 namespace sde {
@@ -84,7 +81,7 @@
     getline_ = virtual_getline;
   }
 #endif
-  for (int i = 0; i < kHWBlockMax; i ++) {
+  for (int i = 0; i < kDeviceMax; i++) {
     fb_node_index_[i] = -1;
   }
 }
@@ -182,7 +179,7 @@
   return kErrorNone;
 }
 
-DisplayError HWFrameBuffer::Open(HWBlockType type, Handle *device, HWEventHandler* eventhandler) {
+DisplayError HWFrameBuffer::Open(HWDeviceType type, Handle *device, HWEventHandler* eventhandler) {
   DisplayError error = kErrorNone;
 
   HWContext *hw_context = new HWContext();
@@ -190,17 +187,20 @@
     return kErrorMemory;
   }
 
-  int device_id = 0;
-  switch (type) {
-  case kHWPrimary:
-    device_id = 0;
-    break;
-  default:
-    break;
-  }
-
   char device_name[64] = {0};
-  snprintf(device_name, sizeof(device_name), "%s%d", "/dev/graphics/fb", device_id);
+
+  switch (type) {
+    case kDevicePrimary:
+    case kDeviceHDMI:
+      // Store EventHandlers for two Physical displays, i.e., Primary and HDMI
+      // TODO(user): Need to revisit for HDMI as Primary usecase
+      event_handler_[type] = eventhandler;
+    case kDeviceVirtual:
+      snprintf(device_name, sizeof(device_name), "%s%d", "/dev/graphics/fb", fb_node_index_[type]);
+      break;
+    default:
+      break;
+  }
 
   hw_context->device_fd = open_(device_name, O_RDWR);
   if (UNLIKELY(hw_context->device_fd < 0)) {
@@ -208,13 +208,10 @@
     error = kErrorResources;
     delete hw_context;
   }
+  hw_context->type = type;
 
   *device = hw_context;
 
-  // Store EventHandlers for two Physical displays
-  if (device_id < kNumPhysicalDisplays)
-    event_handler_[device_id] = eventhandler;
-
   return error;
 }
 
@@ -272,9 +269,12 @@
   display_attributes->vsync_period_ns =
                  UINT32(1000000000L / FLOAT(meta_data.data.panel_frame_rate));
 
-  // TODO(user): set panel information from sysfs
-  display_attributes->is_device_split = true;
-  display_attributes->split_left = display_attributes->x_pixels / 2;
+  display_attributes->is_device_split = ((var_screeninfo.xres > hw_resource_.max_mixer_width) ||
+        (hw_resource_.split_info.right_split)) ? true : false;
+  if (display_attributes->is_device_split) {
+    display_attributes->split_left = hw_resource_.split_info.left_split ?
+        hw_resource_.split_info.left_split : display_attributes->x_pixels / 2;
+  }
 
   return kErrorNone;
 }
@@ -325,28 +325,18 @@
 }
 
 DisplayError HWFrameBuffer::Validate(Handle device, HWLayers *hw_layers) {
+  DisplayError error = kErrorNone;
   HWContext *hw_context = reinterpret_cast<HWContext *>(device);
 
-  return kErrorNone;
-}
-
-DisplayError HWFrameBuffer::Commit(Handle device, HWLayers *hw_layers) {
-  HWContext *hw_context = reinterpret_cast<HWContext *>(device);
+  hw_context->ResetMDPCommit();
 
   HWLayersInfo &hw_layer_info = hw_layers->info;
-
-  // Assuming left & right both pipe are required, maximum possible number of overlays.
-  uint32_t max_overlay_count = hw_layer_info.count * 2;
-
-  int acquire_fences[hw_layer_info.count];  // NOLINT
-  int release_fence = -1;
-  int retire_fence = -1;
-  uint32_t acquire_fence_count = 0;
-  STRUCT_VAR_ARRAY(mdp_overlay, overlay_array, max_overlay_count);
-  STRUCT_VAR_ARRAY(msmfb_overlay_data, data_array, max_overlay_count);
-
   LayerStack *stack = hw_layer_info.stack;
-  uint32_t num_overlays = 0;
+
+  mdp_layer_commit_v1 &mdp_commit = hw_context->mdp_commit.commit_v1;
+  mdp_input_layer *mdp_layers = hw_context->mdp_layers;
+  uint32_t &mdp_layer_count = mdp_commit.input_layer_cnt;
+
   for (uint32_t i = 0; i < hw_layer_info.count; i++) {
     uint32_t layer_index = hw_layer_info.index[i];
     Layer &layer = stack->layers[layer_index];
@@ -355,110 +345,135 @@
     HWPipeInfo &left_pipe = config.left_pipe;
 
     // Configure left pipe
-    mdp_overlay &left_overlay = overlay_array[num_overlays];
-    msmfb_overlay_data &left_data = data_array[num_overlays];
+    mdp_input_layer &mdp_layer_left = mdp_layers[mdp_layer_count];
+    mdp_layer_left.alpha = layer.plane_alpha;
+    mdp_layer_left.z_order = static_cast<uint16_t>(i);
+    mdp_layer_left.transp_mask = 0xffffffff;
+    SetBlending(layer.blending, &mdp_layer_left.blend_op);
+    SetRect(left_pipe.src_roi, &mdp_layer_left.src_rect);
+    SetRect(left_pipe.dst_roi, &mdp_layer_left.dst_rect);
+    mdp_layer_left.pipe_ndx = left_pipe.pipe_id;
 
-    left_overlay.id = left_pipe.pipe_id;
-    left_overlay.flags |= MDP_BLEND_FG_PREMULT;
-    left_overlay.transp_mask = 0xffffffff;
-    left_overlay.z_order = i;
-    left_overlay.alpha = layer.plane_alpha;
-    left_overlay.src.width = input_buffer->planes[0].stride;
-    left_overlay.src.height = input_buffer->height;
-    SetBlending(&left_overlay.blend_op, layer.blending);
-    SetFormat(&left_overlay.src.format, layer.input_buffer->format);
-    SetRect(&left_overlay.src_rect, left_pipe.src_roi);
-    SetRect(&left_overlay.dst_rect, left_pipe.dst_roi);
-    left_data.id = left_pipe.pipe_id;
-    left_data.data.memory_id = input_buffer->planes[0].fd;
-    left_data.data.offset = input_buffer->planes[0].offset;
+    mdp_layer_buffer &mdp_buffer_left = mdp_layer_left.buffer;
+    mdp_buffer_left.width = input_buffer->width;
+    mdp_buffer_left.height = input_buffer->height;
 
-    num_overlays++;
+    error = SetFormat(layer.input_buffer->format, &mdp_buffer_left.format);
+    if (error != kErrorNone) {
+      return error;
+    }
+
+    mdp_layer_count++;
 
     // Configure right pipe
     if (config.is_right_pipe) {
       HWPipeInfo &right_pipe = config.right_pipe;
-      mdp_overlay &right_overlay = overlay_array[num_overlays];
-      msmfb_overlay_data &right_data = data_array[num_overlays];
+      mdp_input_layer &mdp_layer_right = mdp_layers[mdp_layer_count];
 
-      right_overlay = left_overlay;
-      right_data = left_data;
-      right_overlay.id = right_pipe.pipe_id;
-      right_data.id = right_pipe.pipe_id;
-      SetRect(&right_overlay.src_rect, right_pipe.src_roi);
-      SetRect(&right_overlay.dst_rect, right_pipe.dst_roi);
+      mdp_layer_right = mdp_layer_left;
 
-      num_overlays++;
-    }
+      mdp_layer_right.pipe_ndx = right_pipe.pipe_id;
+      SetRect(right_pipe.src_roi, &mdp_layer_right.src_rect);
+      SetRect(right_pipe.dst_roi, &mdp_layer_right.dst_rect);
 
-    if (input_buffer->acquire_fence_fd >= 0) {
-      acquire_fences[acquire_fence_count] = input_buffer->acquire_fence_fd;
-      acquire_fence_count++;
+      mdp_layer_count++;
     }
   }
 
-  mdp_overlay *overlay_list[num_overlays];
-  msmfb_overlay_data *data_list[num_overlays];
-  for (uint32_t i = 0; i < num_overlays; i++) {
-    overlay_list[i] = &overlay_array[i];
-    data_list[i] = &data_array[i];
+  mdp_commit.flags |= MDP_VALIDATE_LAYER;
+  if (ioctl_(hw_context->device_fd, MSMFB_ATOMIC_COMMIT, &hw_context->mdp_commit) == -1) {
+    IOCTL_LOGE(MSMFB_ATOMIC_COMMIT);
+    return kErrorHardware;
   }
 
-  // TODO(user): Replace with Atomic commit call.
-  STRUCT_VAR(mdp_atomic_commit, atomic_commit);
-  atomic_commit.overlay_list = overlay_list;
-  atomic_commit.data_list = data_list;
-  atomic_commit.num_overlays = num_overlays;
-  atomic_commit.buf_sync.acq_fen_fd = acquire_fences;
-  atomic_commit.buf_sync.acq_fen_fd_cnt = acquire_fence_count;
-  atomic_commit.buf_sync.rel_fen_fd = &release_fence;
-  atomic_commit.buf_sync.retire_fen_fd = &retire_fence;
-  atomic_commit.buf_sync.flags = MDP_BUF_SYNC_FLAG_RETIRE_FENCE;
+  return kErrorNone;
+}
 
-  if (UNLIKELY(ioctl_(hw_context->device_fd, MSMFB_ATOMIC_COMMIT, &atomic_commit) == -1)) {
+DisplayError HWFrameBuffer::Commit(Handle device, HWLayers *hw_layers) {
+  HWContext *hw_context = reinterpret_cast<HWContext *>(device);
+  HWLayersInfo &hw_layer_info = hw_layers->info;
+  LayerStack *stack = hw_layer_info.stack;
+
+  mdp_layer_commit_v1 &mdp_commit = hw_context->mdp_commit.commit_v1;
+  mdp_input_layer *mdp_layers = hw_context->mdp_layers;
+  uint32_t mdp_layer_index = 0;
+
+  for (uint32_t i = 0; i < hw_layer_info.count; i++) {
+    uint32_t layer_index = hw_layer_info.index[i];
+    LayerBuffer *input_buffer = stack->layers[layer_index].input_buffer;
+
+    uint32_t split_count = hw_layers->config[i].is_right_pipe ? 2 : 1;
+    for (uint32_t j = 0; j < split_count; j++) {
+      mdp_layer_buffer &mdp_buffer = mdp_layers[mdp_layer_index].buffer;
+
+      if (input_buffer->planes[0].fd >= 0) {
+        mdp_buffer.plane_count = 1;
+        mdp_buffer.planes[0].fd = input_buffer->planes[0].fd;
+        mdp_buffer.planes[0].offset = input_buffer->planes[0].offset;
+        mdp_buffer.planes[0].stride = input_buffer->planes[0].stride;
+      } else {
+        DLOGW("Invalid buffer fd, setting plane count to 0");
+        mdp_buffer.plane_count = 0;
+      }
+
+      mdp_buffer.fence = input_buffer->acquire_fence_fd;
+      mdp_layer_index++;
+    }
+  }
+
+  mdp_commit.flags |= MDP_COMMIT_RETIRE_FENCE;
+  mdp_commit.flags &= ~MDP_VALIDATE_LAYER;
+  if (ioctl_(hw_context->device_fd, MSMFB_ATOMIC_COMMIT, &hw_context->mdp_commit) == -1) {
     IOCTL_LOGE(MSMFB_ATOMIC_COMMIT);
     return kErrorHardware;
   }
 
   // MDP returns only one release fence for the entire layer stack. Duplicate this fence into all
   // layers being composed by MDP.
-  stack->retire_fence_fd = retire_fence;
+  stack->retire_fence_fd = mdp_commit.retire_fence;
   for (uint32_t i = 0; i < hw_layer_info.count; i++) {
     uint32_t layer_index = hw_layer_info.index[i];
-    Layer &layer = stack->layers[layer_index];
-    LayerBuffer *input_buffer = layer.input_buffer;
-    input_buffer->release_fence_fd = dup(release_fence);
+    LayerBuffer *input_buffer = stack->layers[layer_index].input_buffer;
+
+    input_buffer->release_fence_fd = dup(mdp_commit.release_fence);
   }
-  close(release_fence);
+  close(mdp_commit.release_fence);
 
   return kErrorNone;
 }
 
-void HWFrameBuffer::SetFormat(uint32_t *target, const LayerBufferFormat &source) {
+DisplayError HWFrameBuffer::SetFormat(const LayerBufferFormat &source, uint32_t *target) {
   switch (source) {
+  case kFormatARGB8888:                 *target = MDP_ARGB_8888;         break;
+  case kFormatRGBA8888:                 *target = MDP_RGBA_8888;         break;
+  case kFormatBGRA8888:                 *target = MDP_BGRA_8888;         break;
+  case kFormatRGBX8888:                 *target = MDP_RGBX_8888;         break;
+  case kFormatBGRX8888:                 *target = MDP_BGRX_8888;         break;
+  case kFormatRGB888:                   *target = MDP_RGB_888;           break;
+  case kFormatRGB565:                   *target = MDP_RGB_565;           break;
+  case kFormatYCbCr420Planar:           *target = MDP_Y_CB_CR_H2V2;      break;
+  case kFormatYCrCb420Planar:           *target = MDP_Y_CR_CB_H2V2;      break;
+  case kFormatYCbCr420SemiPlanar:       *target = MDP_Y_CBCR_H2V2;       break;
+  case kFormatYCrCb420SemiPlanar:       *target = MDP_Y_CRCB_H2V2;       break;
+  case kFormatYCbCr422Packed:           *target = MDP_YCBYCR_H2V1;       break;
+  case kFormatYCbCr420SemiPlanarVenus:  *target = MDP_Y_CBCR_H2V2_VENUS; break;
   default:
-    *target = MDP_RGBA_8888;
-    break;
+    DLOGE("Unsupported format type %d", source);
+    return kErrorParameters;
+  }
+
+  return kErrorNone;
+}
+
+void HWFrameBuffer::SetBlending(const LayerBlending &source, mdss_mdp_blend_op *target) {
+  switch (source) {
+  case kBlendingPremultiplied:  *target = BLEND_OP_PREMULTIPLIED;   break;
+  case kBlendingCoverage:       *target = BLEND_OP_COVERAGE;        break;
+  default:                      *target = BLEND_OP_NOT_DEFINED;     break;
   }
 }
 
-void HWFrameBuffer::SetBlending(uint32_t *target, const LayerBlending &source) {
-  switch (source) {
-  case kBlendingPremultiplied:
-    *target = BLEND_OP_PREMULTIPLIED;
-    break;
-
-  case kBlendingCoverage:
-    *target = BLEND_OP_COVERAGE;
-    break;
-
-  default:
-    *target = BLEND_OP_NOT_DEFINED;
-    break;
-  }
-}
-
-void HWFrameBuffer::SetRect(mdp_rect *target, const LayerRect &source) {
+void HWFrameBuffer::SetRect(const LayerRect &source, mdp_rect *target) {
   target->x = INT(ceilf(source.left));
   target->y = INT(ceilf(source.top));
   target->w = INT(floorf(source.right)) - target->x;
@@ -492,20 +507,20 @@
       uint64_t ts = uint64_t(time_now.tv_sec)*1000000000LL +uint64_t(time_now.tv_usec)*1000LL;
 
       // Send Vsync event for primary display(0)
-      event_handler_[0]->VSync(ts);
+      event_handler_[kDevicePrimary]->VSync(ts);
     }
 
     pthread_exit(0);
   }
 
-  typedef void (HWFrameBuffer::*EventHandler)(int, char*);
+  typedef void (HWFrameBuffer::*EventHandler)(int, char *);
   EventHandler event_handler[kNumDisplayEvents] = { &HWFrameBuffer::HandleVSync,
                                                     &HWFrameBuffer::HandleBlank };
 
   while (!exit_threads_) {
     int error = poll_(poll_fds_[0], kNumPhysicalDisplays * kNumDisplayEvents, -1);
     if (error < 0) {
-      DLOGE("poll failed errno: %s", strerror(errno));
+      DLOGW("poll failed. error = %s", strerror(errno));
       continue;
     }
 
@@ -517,7 +532,8 @@
           ssize_t length = pread_(poll_fd.fd, data, kMaxStringLength, 0);
           if (length < 0) {
             // If the read was interrupted - it is not a fatal error, just continue.
-            DLOGE("Failed to read event:%d for display=%d: %s", event, display, strerror(errno));
+            DLOGW("pread failed. event = %d, display = %d, error = %s",
+                                                      event, display, strerror(errno));
             continue;
           }
 
@@ -538,29 +554,25 @@
     timestamp = strtoull(data + strlen("VSYNC="), NULL, 0);
   }
   event_handler_[display_id]->VSync(timestamp);
-
-  return;
 }
 
-void HWFrameBuffer::HandleBlank(int display_id, char* data) {
+void HWFrameBuffer::HandleBlank(int display_id, char *data) {
   // TODO(user): Need to send blank Event
-  return;
 }
 
 void HWFrameBuffer::PopulateFBNodeIndex() {
   char stringbuffer[kMaxStringLength];
   DisplayError error = kErrorNone;
-  HWBlockType hwblock = kHWPrimary;
   char *line = stringbuffer;
   size_t len = kMaxStringLength;
   ssize_t read;
 
 
-  for (int i = 0; i < kHWBlockMax; i++) {
+  for (int i = 0; i < kDeviceMax; i++) {
     snprintf(stringbuffer, sizeof(stringbuffer), "%s%d/msm_fb_type", fb_path_, i);
     FILE* fileptr = fopen_(stringbuffer, "r");
     if (fileptr == NULL) {
-      DLOGE("File not found %s", stringbuffer);
+      DLOGW("File not found %s", stringbuffer);
       continue;
     }
     read = getline_(&line, &len, fileptr);
@@ -572,24 +584,23 @@
     // Need more concrete info from driver
     if ((strncmp(line, "mipi dsi cmd panel", strlen("mipi dsi cmd panel")) == 0)) {
       pri_panel_info_.type = kCommandModePanel;
-      hwblock = kHWPrimary;
+      fb_node_index_[kDevicePrimary] = i;
     } else if ((strncmp(line, "mipi dsi video panel", strlen("mipi dsi video panel")) == 0))  {
       pri_panel_info_.type = kVideoModePanel;
-      hwblock = kHWPrimary;
+      fb_node_index_[kDevicePrimary] = i;
     } else if ((strncmp(line, "lvds panel", strlen("lvds panel")) == 0)) {
       pri_panel_info_.type = kLVDSPanel;
-      hwblock = kHWPrimary;
+      fb_node_index_[kDevicePrimary] = i;
     } else if ((strncmp(line, "edp panel", strlen("edp panel")) == 0)) {
       pri_panel_info_.type = kEDPPanel;
-      hwblock = kHWPrimary;
+      fb_node_index_[kDevicePrimary] = i;
     } else if ((strncmp(line, "dtv panel", strlen("dtv panel")) == 0)) {
-      hwblock = kHWHDMI;
+      fb_node_index_[kDeviceHDMI] = i;
     } else if ((strncmp(line, "writeback panel", strlen("writeback panel")) == 0)) {
-      hwblock = kHWWriteback0;
+      fb_node_index_[kDeviceVirtual] = i;
     } else {
-      DLOGE("Unknown panel type = %s index = %d", line, i);
+      DLOGW("Unknown panel type = %s index = %d", line, i);
     }
-    fb_node_index_[hwblock] = i;
     fclose_(fileptr);
   }
 }
@@ -600,7 +611,7 @@
   snprintf(stringbuffer, sizeof(stringbuffer), "%s%d/msm_fb_panel_info", fb_path_, fb_index);
   fileptr = fopen_(stringbuffer, "r");
   if (fileptr == NULL) {
-    DLOGE("Failed to open msm_fb_panel_info node");
+    DLOGW("Failed to open msm_fb_panel_info node");
     return;
   }
 
@@ -739,18 +750,18 @@
     }
   }
 
-  DLOGI("SDE Version: %d SDE Revision: %x RGB : %d, VIG: %d DMA: %d Cursor: %d",
+  DLOGI("SDE Version = %d, SDE Revision = %x, RGB = %d, VIG = %d, DMA = %d, Cursor = %d",
         hw_resource_.hw_version, hw_resource_.hw_revision, hw_resource_.num_rgb_pipe,
         hw_resource_.num_vig_pipe, hw_resource_.num_dma_pipe, hw_resource_.num_cursor_pipe);
-  DLOGI("Upscale Ratio: %d Downscale Ratio: %d Blending Stages: %d", hw_resource_.max_scale_up,
+  DLOGI("Upscale Ratio = %d, Downscale Ratio = %d, Blending Stages = %d", hw_resource_.max_scale_up,
         hw_resource_.max_scale_down, hw_resource_.num_blending_stages);
-  DLOGI("BWC: %d Decimation: %d Tile Format: %d: Rotator Downscale: %d",  hw_resource_.has_bwc,
+  DLOGI("BWC = %d, Decimation = %d, Tile Format = %d, Rotator Downscale = %d", hw_resource_.has_bwc,
         hw_resource_.has_decimation, hw_resource_.has_macrotile,
         hw_resource_.has_rotator_downscale);
-  DLOGI("Left Split: %d Right Split: %d", hw_resource_.split_info.left_split,
+  DLOGI("Left Split = %d, Right Split = %d", hw_resource_.split_info.left_split,
         hw_resource_.split_info.right_split);
-  DLOGI("SourceSplit: %d Always: %d", hw_resource_.is_src_split, hw_resource_.always_src_split);
-  DLOGI("MaxLowBw: %"PRIu64" MaxHighBw: %"PRIu64"", hw_resource_.max_bandwidth_low,
+  DLOGI("SourceSplit = %d, Always = %d", hw_resource_.is_src_split, hw_resource_.always_src_split);
+  DLOGI("MaxLowBw = %"PRIu64", MaxHighBw = %"PRIu64"", hw_resource_.max_bandwidth_low,
         hw_resource_.max_bandwidth_high);
 
   return error;
diff --git a/displayengine/libs/core/hw_framebuffer.h b/displayengine/libs/core/hw_framebuffer.h
index d74d03e..b70b5be 100644
--- a/displayengine/libs/core/hw_framebuffer.h
+++ b/displayengine/libs/core/hw_framebuffer.h
@@ -27,7 +27,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <linux/msm_mdp.h>
+#include <linux/msm_mdp_ext.h>
 #include <poll.h>
 #include <pthread.h>
 
@@ -41,7 +41,7 @@
   DisplayError Init();
   DisplayError Deinit();
   virtual DisplayError GetHWCapabilities(HWResourceInfo *hw_res_info);
-  virtual DisplayError Open(HWBlockType type, Handle *device, HWEventHandler *eventhandler);
+  virtual DisplayError Open(HWDeviceType type, Handle *device, HWEventHandler *eventhandler);
   virtual DisplayError Close(Handle device);
   virtual DisplayError GetNumDisplayAttributes(Handle device, uint32_t *count);
   virtual DisplayError GetDisplayAttributes(Handle device, HWDisplayAttributes *display_attributes,
@@ -56,8 +56,21 @@
 
  private:
   struct HWContext {
-    HWBlockType type;
+    HWDeviceType type;
     int device_fd;
+    mdp_layer_commit mdp_commit;
+    mdp_input_layer mdp_layers[kMaxSDELayers * 2];   // split panel (left + right) for worst case
+
+    HWContext() : type(kDeviceMax), device_fd(-1) {
+      ResetMDPCommit();
+    }
+
+    void ResetMDPCommit() {
+      memset(&mdp_commit, 0, sizeof(mdp_commit));
+      memset(&mdp_layers, 0, sizeof(mdp_layers));
+      mdp_commit.version = MDP_COMMIT_VERSION_1_0;
+      mdp_commit.commit_v1.input_layers = mdp_layers;
+    }
   };
 
   enum PanelType {
@@ -100,9 +113,9 @@
   static const int kNumDisplayEvents = 2;
   static const int kHWMdssVersion5 = 500;  // MDSS_V5
 
-  inline void SetFormat(uint32_t *target, const LayerBufferFormat &source);
-  inline void SetBlending(uint32_t *target, const LayerBlending &source);
-  inline void SetRect(mdp_rect *target, const LayerRect &source);
+  inline DisplayError SetFormat(const LayerBufferFormat &source, uint32_t *target);
+  inline void SetBlending(const LayerBlending &source, mdss_mdp_blend_op *target);
+  inline void SetRect(const LayerRect &source, mdp_rect *target);
 
   // Event Thread to receive vsync/blank events
   static void* DisplayEventThread(void *context);
@@ -137,7 +150,7 @@
   bool fake_vsync_;
   bool exit_threads_;
   HWResourceInfo hw_resource_;
-  int fb_node_index_[kHWBlockMax];
+  int fb_node_index_[kDeviceMax];
   const char* fb_path_;
   PanelInfo pri_panel_info_;
 };
diff --git a/displayengine/libs/core/hw_interface.cpp b/displayengine/libs/core/hw_interface.cpp
old mode 100644
new mode 100755
index f39cc21..3ab0c7e
--- a/displayengine/libs/core/hw_interface.cpp
+++ b/displayengine/libs/core/hw_interface.cpp
@@ -22,11 +22,6 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-// SDE_LOG_TAG definition must precede debug.h include.
-#define SDE_LOG_TAG kTagCore
-#define SDE_MODULE_NAME "HWInterface"
-#include <utils/debug.h>
-
 #include <utils/constants.h>
 
 #include "hw_interface.h"
diff --git a/displayengine/libs/core/hw_interface.h b/displayengine/libs/core/hw_interface.h
index a9bdb96..6748538 100644
--- a/displayengine/libs/core/hw_interface.h
+++ b/displayengine/libs/core/hw_interface.h
@@ -40,6 +40,13 @@
   kHWBlockMax
 };
 
+enum HWDeviceType {
+  kDevicePrimary,
+  kDeviceHDMI,
+  kDeviceVirtual,
+  kDeviceMax
+};
+
 struct HWResourceInfo {
   uint32_t hw_version;
   uint32_t hw_revision;
@@ -124,7 +131,7 @@
   static DisplayError Create(HWInterface **intf);
   static DisplayError Destroy(HWInterface *intf);
   virtual DisplayError GetHWCapabilities(HWResourceInfo *hw_res_info) = 0;
-  virtual DisplayError Open(HWBlockType type, Handle *device, HWEventHandler *eventhandler) = 0;
+  virtual DisplayError Open(HWDeviceType type, Handle *device, HWEventHandler *eventhandler) = 0;
   virtual DisplayError Close(Handle device) = 0;
   virtual DisplayError GetNumDisplayAttributes(Handle device, uint32_t *count) = 0;
   virtual DisplayError GetDisplayAttributes(Handle device,
diff --git a/displayengine/libs/core/offline_ctrl.cpp b/displayengine/libs/core/offline_ctrl.cpp
old mode 100644
new mode 100755
index be01cef..c380d52
--- a/displayengine/libs/core/offline_ctrl.cpp
+++ b/displayengine/libs/core/offline_ctrl.cpp
@@ -22,15 +22,13 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-// SDE_LOG_TAG definition must precede debug.h include.
-#define SDE_LOG_TAG kTagCore
-#define SDE_MODULE_NAME "OfflineCtrl"
+#include <utils/constants.h>
 #include <utils/debug.h>
 
-#include <utils/constants.h>
-
 #include "offline_ctrl.h"
 
+#define __CLASS__ "OfflineCtrl"
+
 namespace sde {
 
 OfflineCtrl::OfflineCtrl() : hw_intf_(NULL) {
diff --git a/displayengine/libs/core/res_config.cpp b/displayengine/libs/core/res_config.cpp
old mode 100644
new mode 100755
index 6e642ed..e1b5320
--- a/displayengine/libs/core/res_config.cpp
+++ b/displayengine/libs/core/res_config.cpp
@@ -22,16 +22,14 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-// SDE_LOG_TAG definition must precede debug.h include.
-#define SDE_LOG_TAG kTagCore
-#define SDE_MODULE_NAME "ResConfig"
+#include <math.h>
+#include <utils/constants.h>
 #include <utils/debug.h>
 
-#include <utils/constants.h>
-#include <math.h>
-
 #include "res_manager.h"
 
+#define __CLASS__ "ResManager"
+
 namespace sde {
 
 DisplayError ResManager::Config(DisplayResourceContext *display_resource_ctx, HWLayers *hw_layers) {
@@ -64,7 +62,7 @@
     pipe_info = &hw_layers->config[i].right_pipe;
     if ((dstRight.right - dstRight.left) > kMaxInterfaceWidth ||
          crop_width > kMaxInterfaceWidth ||
-        ((hw_block_id == kHWPrimary) && hw_res_info_.is_src_split &&
+        ((hw_block_id == kHWPrimary) &&
          (crop_width > display_attributes.split_left))) {
       scissor.left = FLOAT(display_attributes.split_left);
       scissor.top = 0.0f;
diff --git a/displayengine/libs/core/res_manager.cpp b/displayengine/libs/core/res_manager.cpp
old mode 100644
new mode 100755
index 3f5bd32..ee1b25f
--- a/displayengine/libs/core/res_manager.cpp
+++ b/displayengine/libs/core/res_manager.cpp
@@ -22,15 +22,13 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-// SDE_LOG_TAG definition must precede debug.h include.
-#define SDE_LOG_TAG kTagCore
-#define SDE_MODULE_NAME "ResManager"
+#include <utils/constants.h>
 #include <utils/debug.h>
 
-#include <utils/constants.h>
-
 #include "res_manager.h"
 
+#define __CLASS__ "ResManager"
+
 namespace sde {
 
 ResManager::ResManager()
@@ -38,8 +36,6 @@
 }
 
 DisplayError ResManager::Init(const HWResourceInfo &hw_res_info) {
-  DLOGV("Init");
-
   hw_res_info_ = hw_res_info;
 
   DisplayError error = kErrorNone;
@@ -195,10 +191,6 @@
   DisplayError error = kErrorNone;
   const struct HWLayersInfo &layer_info = hw_layers->info;
 
-  if (UNLIKELY(!layer_info.count)) {
-    return kErrorNone;
-  }
-
   if (UNLIKELY(layer_info.count > num_pipe_)) {
     return kErrorResources;
   }
@@ -284,21 +276,21 @@
   HWBlockType hw_block_id = display_resource_ctx->hw_block_id;
   uint64_t frame_count = display_resource_ctx->frame_count;
 
-  DLOGV("Resource for hw_block=%d frame_count=%d", hw_block_id, frame_count);
+  DLOGV_IF(kTagResources, "Resource for hw_block = %d, frame_count = %d", hw_block_id, frame_count);
 
   for (uint32_t i = 0; i < num_pipe_; i++) {
     if (src_pipes_[i].reserved) {
       src_pipes_[i].hw_block_id = hw_block_id;
       src_pipes_[i].state = kPipeStateAcquired;
       src_pipes_[i].state_frame_count = frame_count;
-      DLOGV("Pipe acquired index=%d type=%d pipe_id=%x", i, src_pipes_[i].type,
-            src_pipes_[i].mdss_pipe_id);
+      DLOGV_IF(kTagResources, "Pipe acquired index = %d, type = %d, pipe_id = %x", i,
+            src_pipes_[i].type, src_pipes_[i].mdss_pipe_id);
     } else if ((src_pipes_[i].hw_block_id == hw_block_id) &&
                (src_pipes_[i].state == kPipeStateAcquired)) {
       src_pipes_[i].state = kPipeStateToRelease;
       src_pipes_[i].state_frame_count = frame_count;
-      DLOGV("Pipe to release index=%d type=%d pipe_id=%x", i, src_pipes_[i].type,
-            src_pipes_[i].mdss_pipe_id);
+      DLOGV_IF(kTagResources, "Pipe to release index = %d, type = %d, pipe_id = %x", i,
+            src_pipes_[i].type, src_pipes_[i].mdss_pipe_id);
     }
   }
 
diff --git a/displayengine/libs/core/strategy_default.cpp b/displayengine/libs/core/strategy_default.cpp
old mode 100644
new mode 100755
index d05b9b8..6963c6c
--- a/displayengine/libs/core/strategy_default.cpp
+++ b/displayengine/libs/core/strategy_default.cpp
@@ -22,19 +22,22 @@
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */
 
-// SDE_LOG_TAG definition must precede debug.h include.
-#define SDE_LOG_TAG kTagCore
-#define SDE_MODULE_NAME "StrategyDefault"
+#include <utils/constants.h>
 #include <utils/debug.h>
 
-#include <utils/constants.h>
-
 #include "strategy_default.h"
 
+#define __CLASS__ "StrategyDefault"
+
 namespace sde {
 
 DisplayError StrategyDefault::GetNextStrategy(StrategyConstraints *constraints,
                                               HWLayersInfo *hw_layers_info) {
+  if (hw_layers_info->flags) {
+    DLOGW("All strategies exhausted.");
+    return kErrorUndefined;
+  }
+
   // Mark all layers for GPU composition. Find GPU target buffer and store its index for programming
   // the hardware.
   LayerStack *layer_stack = hw_layers_info->stack;
@@ -55,7 +58,7 @@
     return kErrorParameters;
   }
 
-  hw_layers_info->flags |= kFlagGPU;
+  hw_layers_info->flags = 1;
 
   return kErrorNone;
 }
diff --git a/displayengine/libs/hwc/Android.mk b/displayengine/libs/hwc/Android.mk
old mode 100644
new mode 100755
index c32337a..1271e00
--- a/displayengine/libs/hwc/Android.mk
+++ b/displayengine/libs/hwc/Android.mk
@@ -1,20 +1,22 @@
 LOCAL_PATH := $(call my-dir)
-include hardware/qcom/display/displayengine/libs/common.mk
 include $(CLEAR_VARS)
 
 LOCAL_MODULE                  := hwcomposer.$(TARGET_BOARD_PLATFORM)
 LOCAL_MODULE_RELATIVE_PATH    := hw
 LOCAL_MODULE_TAGS             := optional
-LOCAL_C_INCLUDES              := $(common_includes) $(kernel_includes)
-LOCAL_CFLAGS                  := $(common_flags) -DLOG_TAG=\"HWComposer\"
-LOCAL_SHARED_LIBRARIES        := $(common_libs) libEGL libhardware_legacy \
-                                 libdl libsync \
-                                 libbinder libmedia libskia libsde
-LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
+LOCAL_C_INCLUDES              := hardware/qcom/display/displayengine/include/ \
+                                 hardware/qcom/display/libgralloc/ \
+                                 hardware/qcom/display/libqservice/
+LOCAL_CFLAGS                  := -Wno-missing-field-initializers -Wno-unused-parameter \
+                                 -Wconversion -Wall -Werror \
+                                 -DLOG_TAG=\"SDE\"
+LOCAL_SHARED_LIBRARIES        := libsde libqservice libbinder libhardware libhardware_legacy \
+                                 libutils libcutils
 LOCAL_SRC_FILES               := hwc_session.cpp \
                                  hwc_display.cpp \
                                  hwc_display_primary.cpp \
                                  hwc_display_external.cpp \
-                                 hwc_display_virtual.cpp
+                                 hwc_display_virtual.cpp \
+                                 hwc_logger.cpp
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/displayengine/libs/hwc/hwc_display.cpp b/displayengine/libs/hwc/hwc_display.cpp
index 66ffcd8..801c0da 100644
--- a/displayengine/libs/hwc/hwc_display.cpp
+++ b/displayengine/libs/hwc/hwc_display.cpp
@@ -26,11 +26,10 @@
 #include <gralloc_priv.h>
 #include <utils/constants.h>
 
-// HWC_MODULE_NAME definition must precede hwc_logger.h include.
-#define HWC_MODULE_NAME "HWCDisplay"
+#include "hwc_display.h"
 #include "hwc_logger.h"
 
-#include "hwc_display.h"
+#define __CLASS__ "HWCDisplay"
 
 namespace sde {
 
@@ -42,7 +41,7 @@
 int HWCDisplay::Init() {
   DisplayError error = core_intf_->CreateDisplay(type_, this, &display_intf_);
   if (UNLIKELY(error != kErrorNone)) {
-    DLOGE("Display device create failed. Error = %d", error);
+    DLOGE("Display create failed. Error = %d", error);
     return -EINVAL;
   }
 
@@ -52,12 +51,12 @@
 int HWCDisplay::Deinit() {
   DisplayError error = core_intf_->DestroyDisplay(display_intf_);
   if (UNLIKELY(error != kErrorNone)) {
-    DLOGE("Display device destroy failed. Error = %d", error);
+    DLOGE("Display destroy failed. Error = %d", error);
     return -EINVAL;
   }
 
-  if (LIKELY(layer_stack_.raw)) {
-    delete[] layer_stack_.raw;
+  if (LIKELY(layer_stack_memory_.raw)) {
+    delete[] layer_stack_memory_.raw;
   }
 
   return 0;
@@ -70,13 +69,15 @@
   case HWC_EVENT_VSYNC:
     error = display_intf_->SetVSyncState(enable);
     break;
-
+  case HWC_EVENT_ORIENTATION:
+    // TODO(user): Need to handle this case
+    break;
   default:
-    DLOGE("Unsupported event control type : %d", event);
+    DLOGW("Unsupported event = %d", event);
   }
 
   if (UNLIKELY(error != kErrorNone)) {
-    DLOGE("EventControl failed. event = %d, enable = %d, error = %d", event, enable, error);
+    DLOGE("Failed. event = %d, enable = %d, error = %d", event, enable, error);
     return -EINVAL;
   }
 
@@ -84,7 +85,7 @@
 }
 
 int HWCDisplay::Blank(int blank) {
-  DLOGI("Blank : %d, display : %d", blank, id_);
+  DLOGI("blank = %d, display = %d", blank, id_);
   DisplayState state = blank ? kStateOff : kStateOn;
   return SetState(state);
 }
@@ -129,7 +130,7 @@
       values[i] = INT32(true); // For backward compatibility. All Physical displays are secure
       break;
     default:
-      DLOGE("Spurious attribute type %d", attributes[i]);
+      DLOGW("Spurious attribute type = %d", attributes[i]);
       return -EINVAL;
     }
   }
@@ -177,27 +178,28 @@
 
   // Layer array may be large enough to hold current number of layers.
   // If not, re-allocate it now.
-  if (UNLIKELY(layer_stack_.size < required_size)) {
-    if (LIKELY(layer_stack_.raw)) {
-      delete[] layer_stack_.raw;
-      layer_stack_.size = 0;
+  if (UNLIKELY(layer_stack_memory_.size < required_size)) {
+    if (LIKELY(layer_stack_memory_.raw)) {
+      delete[] layer_stack_memory_.raw;
+      layer_stack_memory_.size = 0;
     }
 
     // Allocate in multiple of kSizeSteps.
-    required_size = ROUND_UP(required_size, layer_stack_.kSizeSteps);
+    required_size = ROUND_UP(required_size, layer_stack_memory_.kSizeSteps);
 
-    layer_stack_.raw = new uint8_t[required_size];
-    if (UNLIKELY(!layer_stack_.raw)) {
+    layer_stack_memory_.raw = new uint8_t[required_size];
+    if (UNLIKELY(!layer_stack_memory_.raw)) {
       return -ENOMEM;
     }
 
-    layer_stack_.size = required_size;
+    layer_stack_memory_.size = required_size;
   }
 
   // Assign memory addresses now.
-  uint8_t *current_address = layer_stack_.raw;
+  uint8_t *current_address = layer_stack_memory_.raw;
 
   // Layer array address
+  layer_stack_ = LayerStack();
   layer_stack_.layers = reinterpret_cast<Layer *>(current_address);
   layer_stack_.layer_count = static_cast<uint32_t>(num_hw_layers);
   current_address += num_hw_layers * sizeof(Layer);
@@ -205,19 +207,25 @@
   for (size_t i = 0; i < num_hw_layers; i++) {
     hwc_layer_1_t &hwc_layer = content_list->hwLayers[i];
     Layer &layer = layer_stack_.layers[i];
+    layer = Layer();
 
     // Layer buffer handle address
     layer.input_buffer = reinterpret_cast<LayerBuffer *>(current_address);
+    *layer.input_buffer = LayerBuffer();
     current_address += sizeof(LayerBuffer);
 
     // Visible rectangle address
     layer.visible_regions.rect = reinterpret_cast<LayerRect *>(current_address);
     layer.visible_regions.count = static_cast<uint32_t>(hwc_layer.visibleRegionScreen.numRects);
+    for (size_t i = 0; i < layer.visible_regions.count; i++) {
+      *layer.visible_regions.rect = LayerRect();
+    }
     current_address += hwc_layer.visibleRegionScreen.numRects * sizeof(LayerRect);
 
     // Dirty rectangle address
     layer.dirty_regions.rect = reinterpret_cast<LayerRect *>(current_address);
     layer.dirty_regions.count = 1;
+    *layer.dirty_regions.rect = LayerRect();
     current_address += sizeof(LayerRect);
   }
 
@@ -226,13 +234,10 @@
 
 int HWCDisplay::PrepareLayerStack(hwc_display_contents_1_t *content_list) {
   size_t num_hw_layers = content_list->numHwLayers;
-  if (UNLIKELY(num_hw_layers <= 1)) {
+  if (num_hw_layers <= 1) {
     return 0;
   }
 
-  // Reset Layer stack flags
-  layer_stack_.flags = LayerStackFlags();
-
   // Configure each layer
   for (size_t i = 0; i < num_hw_layers; i++) {
     hwc_layer_1_t &hwc_layer = content_list->hwLayers[i];
@@ -242,15 +247,12 @@
     LayerBuffer *layer_buffer = layer.input_buffer;
 
     if (pvt_handle) {
-      if (UNLIKELY(SetFormat(&layer_buffer->format, pvt_handle->format))) {
+      if (SetFormat(pvt_handle->format, &layer_buffer->format)) {
         return -EINVAL;
       }
 
       layer_buffer->width = pvt_handle->width;
       layer_buffer->height = pvt_handle->height;
-      layer_buffer->planes[0].fd = pvt_handle->fd;
-      layer_buffer->planes[0].offset = pvt_handle->offset;
-      layer_buffer->planes[0].stride = pvt_handle->width;
       if (pvt_handle->bufferType == BUFFER_TYPE_VIDEO) {
         layer_stack_.flags.video_present = true;
       }
@@ -259,20 +261,20 @@
       }
     }
 
-    SetRect(&layer.dst_rect, hwc_layer.displayFrame);
-    SetRect(&layer.src_rect, hwc_layer.sourceCropf);
+    SetRect(hwc_layer.displayFrame, &layer.dst_rect);
+    SetRect(hwc_layer.sourceCropf, &layer.src_rect);
     for (size_t j = 0; j < hwc_layer.visibleRegionScreen.numRects; j++) {
-        SetRect(&layer.visible_regions.rect[j], hwc_layer.visibleRegionScreen.rects[j]);
+        SetRect(hwc_layer.visibleRegionScreen.rects[j], &layer.visible_regions.rect[j]);
     }
-    SetRect(&layer.dirty_regions.rect[0], hwc_layer.dirtyRect);
-    SetComposition(&layer.composition, hwc_layer.compositionType);
-    SetBlending(&layer.blending, hwc_layer.blending);
+    SetRect(hwc_layer.dirtyRect, &layer.dirty_regions.rect[0]);
+    SetComposition(hwc_layer.compositionType, &layer.composition);
+    SetBlending(hwc_layer.blending, &layer.blending);
 
     LayerTransform &layer_transform = layer.transform;
     uint32_t &hwc_transform = hwc_layer.transform;
     layer_transform.flip_horizontal = ((hwc_transform & HWC_TRANSFORM_FLIP_H) > 0);
     layer_transform.flip_vertical = ((hwc_transform & HWC_TRANSFORM_FLIP_V) > 0);
-    layer_transform.rotation = ((hwc_transform& HWC_TRANSFORM_ROT_90) ? 90.0f : 0.0f);
+    layer_transform.rotation = ((hwc_transform & HWC_TRANSFORM_ROT_90) ? 90.0f : 0.0f);
 
     layer.plane_alpha = hwc_layer.planeAlpha;
     layer.flags.skip = ((hwc_layer.flags & HWC_SKIP_LAYER) > 0);
@@ -297,10 +299,16 @@
   for (size_t i = 0; i < num_hw_layers; i++) {
     hwc_layer_1_t &hwc_layer = content_list->hwLayers[i];
     Layer &layer = layer_stack_.layers[i];
-    // if current frame does not need frame buffer redraw, then mark them for HWC_OVERLAY
-    LayerComposition composition = needs_fb_refresh ? layer.composition : kCompositionSDE;
-    SetComposition(&hwc_layer.compositionType, composition);
+    LayerComposition composition = layer.composition;
+
+    // If current layer does not need frame buffer redraw, then mark it as HWC_OVERLAY
+    if (!needs_fb_refresh && (composition != kCompositionGPUTarget)) {
+      composition = kCompositionSDE;
+    }
+
+    SetComposition(composition, &hwc_layer.compositionType);
   }
+
   // Cache the current layer stack information like layer_count, composition type and layer handle
   // for the future.
   CacheLayerStackInfo(content_list);
@@ -308,55 +316,33 @@
   return 0;
 }
 
-void HWCDisplay::CacheLayerStackInfo(hwc_display_contents_1_t *content_list) {
-  uint32_t layer_count = layer_stack_.layer_count;
-
-  for (size_t i = 0; i < layer_count; i++) {
-    Layer &layer = layer_stack_.layers[i];
-    layer_stack_cache_.layer_cache[i].handle = content_list->hwLayers[i].handle;
-    layer_stack_cache_.layer_cache[i].composition = layer.composition;
-  }
-  layer_stack_cache_.layer_count = layer_count;
-}
-
-bool HWCDisplay::NeedsFrameBufferRefresh(hwc_display_contents_1_t *content_list) {
-  uint32_t layer_count = layer_stack_.layer_count;
-
-  // Frame buffer needs to be refreshed for the following reasons:
-  // 1. Any layer is marked skip in the current layer stack.
-  // 2. Any layer is added/removed/layer properties changes in the current layer stack.
-  // 3. Any layer handle is changed and it is marked for GPU composition
-  // 4. Any layer's current composition is different from previous composition.
-  if ((layer_stack_cache_.layer_count != layer_count) || layer_stack_.flags.skip_present ||
-       layer_stack_.flags.geometry_changed) {
-    return true;
-  }
-
-  for (size_t i = 0; i < layer_count; i++) {
-    hwc_layer_1_t &hwc_layer = content_list->hwLayers[i];
-    Layer &layer = layer_stack_.layers[i];
-    LayerCache &layer_cache = layer_stack_cache_.layer_cache[i];
-    if (layer_cache.composition != layer.composition) {
-      return true;
-    }
-    if ((layer.composition == kCompositionGPU) && (layer_cache.handle != hwc_layer.handle)) {
-      return true;
-    }
-  }
-
-  return false;
-}
-
 int HWCDisplay::CommitLayerStack(hwc_display_contents_1_t *content_list) {
   size_t num_hw_layers = content_list->numHwLayers;
-  if (UNLIKELY(num_hw_layers <= 1)) {
+  if (num_hw_layers <= 1) {
+    if (!num_hw_layers) {
+      return 0;
+    }
+
+    // TODO(user): handle if only 1 layer(fb target) is received.
+    int &acquireFenceFd = content_list->hwLayers[0].acquireFenceFd;
+    if (acquireFenceFd >= 0) {
+      close(acquireFenceFd);
+    }
+
     return 0;
   }
 
   for (size_t i = 0; i < num_hw_layers; i++) {
     hwc_layer_1_t &hwc_layer = content_list->hwLayers[i];
+    const private_handle_t *pvt_handle = static_cast<const private_handle_t *>(hwc_layer.handle);
     LayerBuffer *layer_buffer = layer_stack_.layers[i].input_buffer;
 
+    if (pvt_handle) {
+      layer_buffer->planes[0].fd = pvt_handle->fd;
+      layer_buffer->planes[0].offset = pvt_handle->offset;
+      layer_buffer->planes[0].stride = pvt_handle->width;
+    }
+
     layer_buffer->acquire_fence_fd = hwc_layer.acquireFenceFd;
   }
 
@@ -383,81 +369,105 @@
   return 0;
 }
 
-void HWCDisplay::SetRect(LayerRect *target, const hwc_rect_t &source) {
+bool HWCDisplay::NeedsFrameBufferRefresh(hwc_display_contents_1_t *content_list) {
+  uint32_t layer_count = layer_stack_.layer_count;
+
+  // Frame buffer needs to be refreshed for the following reasons:
+  // 1. Any layer is marked skip in the current layer stack.
+  // 2. Any layer is added/removed/layer properties changes in the current layer stack.
+  // 3. Any layer handle is changed and it is marked for GPU composition
+  // 4. Any layer's current composition is different from previous composition.
+  if ((layer_stack_cache_.layer_count != layer_count) || layer_stack_.flags.skip_present ||
+       layer_stack_.flags.geometry_changed) {
+    return true;
+  }
+
+  for (uint32_t i = 0; i < layer_count; i++) {
+    hwc_layer_1_t &hwc_layer = content_list->hwLayers[i];
+    Layer &layer = layer_stack_.layers[i];
+    LayerCache &layer_cache = layer_stack_cache_.layer_cache[i];
+
+    if (layer.composition == kCompositionGPUTarget) {
+      continue;
+    }
+
+    if (layer_cache.composition != layer.composition) {
+      return true;
+    }
+
+    if ((layer.composition == kCompositionGPU) && (layer_cache.handle != hwc_layer.handle)) {
+      return true;
+    }
+  }
+
+  return false;
+}
+
+void HWCDisplay::CacheLayerStackInfo(hwc_display_contents_1_t *content_list) {
+  uint32_t layer_count = layer_stack_.layer_count;
+
+  for (uint32_t i = 0; i < layer_count; i++) {
+    Layer &layer = layer_stack_.layers[i];
+
+    if (layer.composition == kCompositionGPUTarget) {
+      continue;
+    }
+
+    layer_stack_cache_.layer_cache[i].handle = content_list->hwLayers[i].handle;
+    layer_stack_cache_.layer_cache[i].composition = layer.composition;
+  }
+
+  layer_stack_cache_.layer_count = layer_count;
+}
+
+void HWCDisplay::SetRect(const hwc_rect_t &source, LayerRect *target) {
   target->left = FLOAT(source.left);
   target->top = FLOAT(source.top);
   target->right = FLOAT(source.right);
   target->bottom = FLOAT(source.bottom);
 }
 
-void HWCDisplay::SetRect(LayerRect *target, const hwc_frect_t &source) {
+void HWCDisplay::SetRect(const hwc_frect_t &source, LayerRect *target) {
   target->left = source.left;
   target->top = source.top;
   target->right = source.right;
   target->bottom = source.bottom;
 }
 
-void HWCDisplay::SetComposition(LayerComposition *target, const int32_t &source) {
+void HWCDisplay::SetComposition(const int32_t &source, LayerComposition *target) {
   switch (source) {
-  case HWC_FRAMEBUFFER_TARGET:
-    *target = kCompositionGPUTarget;
-    break;
-  default:
-    *target = kCompositionSDE;
-    break;
+  case HWC_FRAMEBUFFER_TARGET:  *target = kCompositionGPUTarget;  break;
+  default:                      *target = kCompositionSDE;        break;
   }
 }
 
-void HWCDisplay::SetComposition(int32_t *target, const LayerComposition &source) {
+void HWCDisplay::SetComposition(const int32_t &source, int32_t *target) {
   switch (source) {
-  case kCompositionGPUTarget:
-    *target = HWC_FRAMEBUFFER_TARGET;
-    break;
-  case kCompositionSDE:
-    *target = HWC_OVERLAY;
-    break;
-  default:
-    *target = HWC_FRAMEBUFFER;
-    break;
+  case kCompositionGPUTarget:   *target = HWC_FRAMEBUFFER_TARGET; break;
+  case kCompositionSDE:         *target = HWC_OVERLAY;            break;
+  default:                      *target = HWC_FRAMEBUFFER;        break;
   }
 }
 
-void HWCDisplay::SetBlending(LayerBlending *target, const int32_t &source) {
+void HWCDisplay::SetBlending(const int32_t &source, LayerBlending *target) {
   switch (source) {
-  case HWC_BLENDING_PREMULT:
-    *target = kBlendingPremultiplied;
-    break;
-  case HWC_BLENDING_COVERAGE:
-    *target = kBlendingCoverage;
-    break;
-  default:
-    *target = kBlendingNone;
-    break;
+  case HWC_BLENDING_PREMULT:    *target = kBlendingPremultiplied;   break;
+  case HWC_BLENDING_COVERAGE:   *target = kBlendingCoverage;        break;
+  default:                      *target = kBlendingNone;            break;
   }
 }
 
-int HWCDisplay::SetFormat(LayerBufferFormat *target, const int &source) {
+int HWCDisplay::SetFormat(const int32_t &source, LayerBufferFormat *target) {
   switch (source) {
-  case HAL_PIXEL_FORMAT_RGBA_8888:
-    *target = kFormatRGBA8888;
-    break;
-  case HAL_PIXEL_FORMAT_BGRA_8888:
-    *target = kFormatBGRA8888;
-    break;
-  case HAL_PIXEL_FORMAT_RGBX_8888:
-    *target = kFormatRGBX8888;
-    break;
-  case HAL_PIXEL_FORMAT_BGRX_8888:
-    *target = kFormatBGRX8888;
-    break;
-  case HAL_PIXEL_FORMAT_RGB_888:
-    *target = kFormatRGB888;
-    break;
-  case HAL_PIXEL_FORMAT_RGB_565:
-    *target = kFormatRGB565;
-    break;
+  case HAL_PIXEL_FORMAT_RGBA_8888:            *target = kFormatRGBA8888;                  break;
+  case HAL_PIXEL_FORMAT_BGRA_8888:            *target = kFormatBGRA8888;                  break;
+  case HAL_PIXEL_FORMAT_RGBX_8888:            *target = kFormatRGBX8888;                  break;
+  case HAL_PIXEL_FORMAT_BGRX_8888:            *target = kFormatBGRX8888;                  break;
+  case HAL_PIXEL_FORMAT_RGB_888:              *target = kFormatRGB888;                    break;
+  case HAL_PIXEL_FORMAT_RGB_565:              *target = kFormatRGB565;                    break;
+  case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:   *target = kFormatYCbCr420SemiPlanarVenus;   break;
   default:
-    DLOGE("Unsupported format type %d", source);
+    DLOGW("Unsupported format type = %d", source);
     return -EINVAL;
   }
 
diff --git a/displayengine/libs/hwc/hwc_display.h b/displayengine/libs/hwc/hwc_display.h
index 67356af..2ad1987 100644
--- a/displayengine/libs/hwc/hwc_display.h
+++ b/displayengine/libs/hwc/hwc_display.h
@@ -47,39 +47,14 @@
   static const uint32_t kMaxLayerCount = 32;
 
   // Structure to track memory allocation for layer stack (layers, rectangles) object.
-  struct LayerStackMemory : LayerStack {
-    static const size_t kSizeSteps = 4096;  // Default memory allocation.
+  struct LayerStackMemory {
+    static const size_t kSizeSteps = 1024;  // Default memory allocation.
     uint8_t *raw;  // Pointer to byte array.
     size_t size;  // Current number of allocated bytes.
 
     LayerStackMemory() : raw(NULL), size(0) { }
   };
 
-  HWCDisplay(CoreInterface *core_intf, hwc_procs_t const **hwc_procs, DisplayType type, int id);
-  virtual ~HWCDisplay() { }
-
-  // DisplayEventHandler methods
-  virtual DisplayError VSync(const DisplayEventVSync &vsync);
-  virtual DisplayError Refresh();
-
-  virtual int AllocateLayerStack(hwc_display_contents_1_t *content_list);
-  virtual int PrepareLayerStack(hwc_display_contents_1_t *content_list);
-  virtual int CommitLayerStack(hwc_display_contents_1_t *content_list);
-  inline void SetRect(LayerRect *target, const hwc_rect_t &source);
-  inline void SetRect(LayerRect *target, const hwc_frect_t &source);
-  inline void SetComposition(LayerComposition *target, const int32_t &source);
-  inline void SetComposition(int32_t *target, const LayerComposition &source);
-  inline void SetBlending(LayerBlending *target, const int32_t &source);
-  inline int SetFormat(LayerBufferFormat *target, const int &source);
-
-  LayerStackMemory layer_stack_;
-  CoreInterface *core_intf_;
-  hwc_procs_t const **hwc_procs_;
-  DisplayType type_;
-  int id_;
-  DisplayInterface *display_intf_;
-
- private:
   struct LayerCache {
     buffer_handle_t handle;
     LayerComposition composition;
@@ -94,10 +69,33 @@
     LayerStackCache() : layer_count(0) { }
   };
 
+  HWCDisplay(CoreInterface *core_intf, hwc_procs_t const **hwc_procs, DisplayType type, int id);
+  virtual ~HWCDisplay() { }
+
+  // DisplayEventHandler methods
+  virtual DisplayError VSync(const DisplayEventVSync &vsync);
+  virtual DisplayError Refresh();
+
+  virtual int AllocateLayerStack(hwc_display_contents_1_t *content_list);
+  virtual int PrepareLayerStack(hwc_display_contents_1_t *content_list);
+  virtual int CommitLayerStack(hwc_display_contents_1_t *content_list);
   bool NeedsFrameBufferRefresh(hwc_display_contents_1_t *content_list);
   void CacheLayerStackInfo(hwc_display_contents_1_t *content_list);
+  inline void SetRect(const hwc_rect_t &source, LayerRect *target);
+  inline void SetRect(const hwc_frect_t &source, LayerRect *target);
+  inline void SetComposition(const int32_t &source, LayerComposition *target);
+  inline void SetComposition(const int32_t &source, int32_t *target);
+  inline void SetBlending(const int32_t &source, LayerBlending *target);
+  inline int SetFormat(const int32_t &source, LayerBufferFormat *target);
 
+  LayerStackMemory layer_stack_memory_;
+  LayerStack layer_stack_;
   LayerStackCache layer_stack_cache_;
+  CoreInterface *core_intf_;
+  hwc_procs_t const **hwc_procs_;
+  DisplayType type_;
+  int id_;
+  DisplayInterface *display_intf_;
 };
 
 }  // namespace sde
diff --git a/displayengine/libs/hwc/hwc_display_external.cpp b/displayengine/libs/hwc/hwc_display_external.cpp
old mode 100644
new mode 100755
index 369d286..386e713
--- a/displayengine/libs/hwc/hwc_display_external.cpp
+++ b/displayengine/libs/hwc/hwc_display_external.cpp
@@ -24,11 +24,10 @@
 
 #include <utils/constants.h>
 
-// HWC_MODULE_NAME definition must precede hwc_logger.h include.
-#define HWC_MODULE_NAME "HWCDisplayExternal"
+#include "hwc_display_external.h"
 #include "hwc_logger.h"
 
-#include "hwc_display_external.h"
+#define __CLASS__ "HWCDisplayExternal"
 
 namespace sde {
 
@@ -45,10 +44,33 @@
 }
 
 int HWCDisplayExternal::Prepare(hwc_display_contents_1_t *content_list) {
+  int status = 0;
+
+  status = AllocateLayerStack(content_list);
+  if (UNLIKELY(status)) {
+    return status;
+  }
+
+  layer_stack_.retire_fence_fd = -1;
+
+  status = PrepareLayerStack(content_list);
+  if (UNLIKELY(status)) {
+    return status;
+  }
+
   return 0;
 }
 
 int HWCDisplayExternal::Commit(hwc_display_contents_1_t *content_list) {
+  int status = 0;
+
+  status = HWCDisplay::CommitLayerStack(content_list);
+  if (UNLIKELY(status)) {
+    return status;
+  }
+
+  content_list->retireFenceFd = layer_stack_.retire_fence_fd;
+
   return 0;
 }
 
diff --git a/displayengine/libs/hwc/hwc_display_primary.cpp b/displayengine/libs/hwc/hwc_display_primary.cpp
old mode 100644
new mode 100755
index d0c0734..95dc97e
--- a/displayengine/libs/hwc/hwc_display_primary.cpp
+++ b/displayengine/libs/hwc/hwc_display_primary.cpp
@@ -24,11 +24,10 @@
 
 #include <utils/constants.h>
 
-// HWC_MODULE_NAME definition must precede hwc_logger.h include.
-#define HWC_MODULE_NAME "HWCDisplayPrimary"
+#include "hwc_display_primary.h"
 #include "hwc_logger.h"
 
-#include "hwc_display_primary.h"
+#define __CLASS__ "HWCDisplayPrimary"
 
 namespace sde {
 
@@ -52,6 +51,8 @@
     return status;
   }
 
+  layer_stack_.retire_fence_fd = -1;
+
   status = PrepareLayerStack(content_list);
   if (UNLIKELY(status)) {
     return status;
diff --git a/displayengine/libs/hwc/hwc_display_virtual.cpp b/displayengine/libs/hwc/hwc_display_virtual.cpp
old mode 100644
new mode 100755
index 62e4d2f..3ac2376
--- a/displayengine/libs/hwc/hwc_display_virtual.cpp
+++ b/displayengine/libs/hwc/hwc_display_virtual.cpp
@@ -24,11 +24,10 @@
 
 #include <utils/constants.h>
 
-// HWC_MODULE_NAME definition must precede hwc_logger.h include.
-#define HWC_MODULE_NAME "HWCDisplayVirtual"
+#include "hwc_display_virtual.h"
 #include "hwc_logger.h"
 
-#include "hwc_display_virtual.h"
+#define __CLASS__ "HWCDisplayVirtual"
 
 namespace sde {
 
diff --git a/displayengine/libs/hwc/hwc_logger.cpp b/displayengine/libs/hwc/hwc_logger.cpp
new file mode 100755
index 0000000..9d65e1c
--- /dev/null
+++ b/displayengine/libs/hwc/hwc_logger.cpp
@@ -0,0 +1,87 @@
+/*
+* Copyright (c) 2014, The Linux Foundation. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without modification, are permitted
+* provided that the following conditions are met:
+*    * Redistributions of source code must retain the above copyright notice, this list of
+*      conditions and the following disclaimer.
+*    * Redistributions in binary form must reproduce the above copyright notice, this list of
+*      conditions and the following disclaimer in the documentation and/or other materials provided
+*      with the distribution.
+*    * Neither the name of The Linux Foundation nor the names of its contributors may be used to
+*      endorse or promote products derived from this software without specific prior written
+*      permission.
+*
+* THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+* NON-INFRINGEMENT ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
+* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+#include <utils/constants.h>
+
+#include "hwc_logger.h"
+
+namespace sde {
+
+HWCLogHandler HWCLogHandler::log_handler_;
+uint32_t HWCLogHandler::log_flags_ = 0x1;
+
+void HWCLogHandler::LogAll(bool enable) {
+  if (enable) {
+    log_flags_ = 0xFFFFFFFF;
+  } else {
+    log_flags_ = 0x1;   // kTagNone should always be printed.
+  }
+}
+
+void HWCLogHandler::LogResources(bool enable) {
+  if (enable) {
+    SET_BIT(log_flags_, kTagResources);
+  } else {
+    CLEAR_BIT(log_flags_, kTagResources);
+  }
+}
+
+void HWCLogHandler::LogStrategy(bool enable) {
+  if (enable) {
+    SET_BIT(log_flags_, kTagStrategy);
+  } else {
+    CLEAR_BIT(log_flags_, kTagStrategy);
+  }
+}
+
+void HWCLogHandler::Error(LogTag /*tag*/, const char *format, ...) {
+  va_list list;
+  va_start(list, format);
+  __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, list);
+}
+
+void HWCLogHandler::Warning(LogTag /*tag*/, const char *format, ...) {
+  va_list list;
+  va_start(list, format);
+  __android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, format, list);
+}
+
+void HWCLogHandler::Info(LogTag tag, const char *format, ...) {
+  if (IS_BIT_SET(log_flags_, tag)) {
+    va_list list;
+    va_start(list, format);
+    __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, list);
+  }
+}
+
+void HWCLogHandler::Verbose(LogTag tag, const char *format, ...) {
+  if (IS_BIT_SET(log_flags_, tag)) {
+    va_list list;
+    va_start(list, format);
+    __android_log_vprint(ANDROID_LOG_VERBOSE, LOG_TAG, format, list);
+  }
+}
+
+}  // namespace sde
+
diff --git a/displayengine/libs/hwc/hwc_logger.h b/displayengine/libs/hwc/hwc_logger.h
old mode 100644
new mode 100755
index cee38e9..7568990
--- a/displayengine/libs/hwc/hwc_logger.h
+++ b/displayengine/libs/hwc/hwc_logger.h
@@ -25,20 +25,36 @@
 #ifndef __HWC_LOGGER_H__
 #define __HWC_LOGGER_H__
 
+#include <core/sde_types.h>
 #include <cutils/log.h>
 
-#ifndef HWC_MODULE_NAME
-#define HWC_MODULE_NAME "HWComposer"
-#endif
+#define DLOG(Macro, format, ...) Macro(__CLASS__ "::%s: " format, __FUNCTION__, ##__VA_ARGS__)
 
-#define HWC_LOG(Macro, format, ...) Macro(HWC_MODULE_NAME ": " format, ##__VA_ARGS__)
+#define DLOGE(format, ...) DLOG(ALOGE, format, ##__VA_ARGS__)
+#define DLOGW(format, ...) DLOG(ALOGW, format, ##__VA_ARGS__)
+#define DLOGI(format, ...) DLOG(ALOGI, format, ##__VA_ARGS__)
+#define DLOGV(format, ...) DLOG(ALOGV, format, ##__VA_ARGS__)
 
-// HWC_MODULE_NAME must be defined before #include this header file in respective
-// module, else default definition is used.
-#define DLOGE(format, ...) HWC_LOG(ALOGE, format, ##__VA_ARGS__)
-#define DLOGW(format, ...) HWC_LOG(ALOGW, format, ##__VA_ARGS__)
-#define DLOGI(format, ...) HWC_LOG(ALOGI, format, ##__VA_ARGS__)
-#define DLOGV(format, ...) HWC_LOG(ALOGV, format, ##__VA_ARGS__)
+namespace sde {
+
+class HWCLogHandler : public LogHandler {
+ public:
+  static inline LogHandler* Get() { return &log_handler_; }
+  static void LogAll(bool enable);
+  static void LogResources(bool enable);
+  static void LogStrategy(bool enable);
+
+  virtual void Error(LogTag tag, const char *format, ...);
+  virtual void Warning(LogTag tag, const char *format, ...);
+  virtual void Info(LogTag tag, const char *format, ...);
+  virtual void Verbose(LogTag tag, const char *format, ...);
+
+ private:
+  static HWCLogHandler log_handler_;
+  static uint32_t log_flags_;
+};
+
+}  // namespace sde
 
 #endif  // __HWC_LOGGER_H__
 
diff --git a/displayengine/libs/hwc/hwc_session.cpp b/displayengine/libs/hwc/hwc_session.cpp
old mode 100644
new mode 100755
index 9749fb1..64cd7e1
--- a/displayengine/libs/hwc/hwc_session.cpp
+++ b/displayengine/libs/hwc/hwc_session.cpp
@@ -24,12 +24,14 @@
 
 #include <core/dump_interface.h>
 #include <utils/constants.h>
-
-// HWC_MODULE_NAME definition must precede hwc_logger.h include.
-#define HWC_MODULE_NAME "HWCSession"
-#include "hwc_logger.h"
+#include <utils/String16.h>
+#include <binder/Parcel.h>
+#include <QService.h>
 
 #include "hwc_session.h"
+#include "hwc_logger.h"
+
+#define __CLASS__ "HWCSession"
 
 static sde::HWCSession::HWCModuleMethods g_hwc_module_methods;
 
@@ -68,14 +70,27 @@
 }
 
 int HWCSession::Init() {
-  DisplayError error = CoreInterface::CreateCore(this, &core_intf_);
+  int status = -EINVAL;
+  const char *qservice_name = "display.qservice";
+
+  // Start QService and connect to it.
+  qService::QService::init();
+  android::sp<qService::IQService> qservice = android::interface_cast<qService::IQService>(
+                android::defaultServiceManager()->getService(android::String16(qservice_name)));
+
+  if (qservice.get()) {
+    qservice->connect(this);
+  } else {
+    DLOGE("Failed to acquire %s", qservice_name);
+    return -EINVAL;
+  }
+
+  DisplayError error = CoreInterface::CreateCore(this, HWCLogHandler::Get(), &core_intf_);
   if (UNLIKELY(error != kErrorNone)) {
     DLOGE("Display core initialization failed. Error = %d", error);
     return -EINVAL;
   }
 
-  int status = -EINVAL;
-
   // Create and power on primary display
   display_primary_ = new HWCDisplayPrimary(core_intf_, &hwc_procs_);
   if (UNLIKELY(!display_primary_)) {
@@ -116,7 +131,7 @@
 
 int HWCSession::Open(const hw_module_t *module, const char *name, hw_device_t **device) {
   if (UNLIKELY(!module || !name || !device)) {
-    DLOGE("::%s Invalid parameters.", __FUNCTION__);
+    DLOGE("Invalid parameters.");
     return -EINVAL;
   }
 
@@ -167,7 +182,7 @@
   for (size_t i = 0; i < num_displays; i++) {
     hwc_display_contents_1_t *content_list = displays[i];
     if (UNLIKELY(!content_list || !content_list->numHwLayers)) {
-      DLOGE("::%s Invalid content list.", __FUNCTION__);
+      DLOGW("Invalid content list.");
       return -EINVAL;
     }
 
@@ -201,7 +216,7 @@
   for (size_t i = 0; i < num_displays; i++) {
     hwc_display_contents_1_t *content_list = displays[i];
     if (UNLIKELY(!content_list || !content_list->numHwLayers)) {
-      DLOGE("::%s Invalid content list.", __FUNCTION__);
+      DLOGW("Invalid content list.");
       return -EINVAL;
     }
 
@@ -334,5 +349,47 @@
   return kErrorNone;
 }
 
+android::status_t HWCSession::notifyCallback(uint32_t command, const android::Parcel *input_parcel,
+                                             android::Parcel */*output_parcel*/) {
+  switch (command) {
+  case qService::IQService::DYNAMIC_DEBUG:
+    DynamicDebug(input_parcel);
+    break;
+
+  case qService::IQService::SCREEN_REFRESH:
+    hwc_procs_->invalidate(hwc_procs_);
+    break;
+
+  default:
+    DLOGW("QService command = %d is not supported", command);
+    return -EINVAL;
+  }
+
+  return 0;
+}
+
+void HWCSession::DynamicDebug(const android::Parcel *input_parcel) {
+  int type = input_parcel->readInt32();
+  bool enable = (input_parcel->readInt32() > 0);
+  DLOGI("type = %d enable = %d", type, enable);
+
+  switch (type) {
+  case qService::IQService::DEBUG_ALL:
+    HWCLogHandler::LogAll(enable);
+    break;
+
+  case qService::IQService::DEBUG_MDPCOMP:
+    HWCLogHandler::LogStrategy(enable);
+    break;
+
+  case qService::IQService::DEBUG_PIPE_LIFECYCLE:
+    HWCLogHandler::LogResources(enable);
+    break;
+
+  default:
+    DLOGW("type = %d is not supported", type);
+  }
+}
+
 }  // namespace sde
 
diff --git a/displayengine/libs/hwc/hwc_session.h b/displayengine/libs/hwc/hwc_session.h
index 6b3346b..9e37eed 100644
--- a/displayengine/libs/hwc/hwc_session.h
+++ b/displayengine/libs/hwc/hwc_session.h
@@ -28,12 +28,13 @@
 #include <hardware/hwcomposer.h>
 #include <core/core_interface.h>
 #include <utils/locker.h>
+#include <IQClient.h>
 
 #include "hwc_display_primary.h"
 
 namespace sde {
 
-class HWCSession : public hwc_composer_device_1_t, public CoreEventHandler {
+class HWCSession : hwc_composer_device_1_t, CoreEventHandler, public qClient::BnQClient {
  public:
   struct HWCModuleMethods : public hw_module_methods_t {
     HWCModuleMethods() {
@@ -66,6 +67,11 @@
   // CoreEventHandler methods
   virtual DisplayError Hotplug(const CoreEventHotplug &hotplug);
 
+  // QClient methods
+  virtual android::status_t notifyCallback(uint32_t command, const android::Parcel *input_parcel,
+                                           android::Parcel *output_parcel);
+  void DynamicDebug(const android::Parcel *input_parcel);
+
   static Locker locker_;
   CoreInterface *core_intf_;
   hwc_procs_t const *hwc_procs_;
diff --git a/displayengine/libs/utils/Android.mk b/displayengine/libs/utils/Android.mk
index d5ba512..db97dd5 100644
--- a/displayengine/libs/utils/Android.mk
+++ b/displayengine/libs/utils/Android.mk
@@ -1,13 +1,13 @@
 LOCAL_PATH := $(call my-dir)
-include hardware/qcom/display/displayengine/libs/common.mk
 include $(CLEAR_VARS)
 
 LOCAL_MODULE                  := libsdeutils
 LOCAL_MODULE_TAGS             := optional
-LOCAL_C_INCLUDES              := $(common_includes) $(kernel_includes)
-LOCAL_CFLAGS                  := $(common_flags) -DLOG_TAG=\"SDE\"
-LOCAL_SHARED_LIBRARIES        := $(common_libs)
-LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
+LOCAL_C_INCLUDES              := hardware/qcom/display/displayengine/include/
+LOCAL_CFLAGS                  := -Wno-missing-field-initializers -Wno-unused-parameter \
+                                 -Wconversion -Wall -Werror \
+                                 -DLOG_TAG=\"SDE\"
+LOCAL_SHARED_LIBRARIES        := libcutils
 LOCAL_SRC_FILES               := debug_android.cpp
 
 include $(BUILD_SHARED_LIBRARY)
diff --git a/displayengine/libs/utils/debug_android.cpp b/displayengine/libs/utils/debug_android.cpp
old mode 100644
new mode 100755
index 09b32fe..23da9fe
--- a/displayengine/libs/utils/debug_android.cpp
+++ b/displayengine/libs/utils/debug_android.cpp
@@ -31,36 +31,12 @@
 
 Debug Debug::debug_;
 
-Debug::Debug() : virtual_driver_(false) {
+Debug::Debug() : log_handler_(&default_log_handler_), virtual_driver_(false) {
   char property[PROPERTY_VALUE_MAX];
   if (property_get("displaycore.virtualdriver", property, NULL) > 0) {
     virtual_driver_ = (atoi(property) == 1);
   }
 }
 
-void Debug::Error(const LogTag & /*tag*/, const char *format, ...) {
-  va_list list;
-  va_start(list, format);
-  __android_log_vprint(ANDROID_LOG_ERROR, LOG_TAG, format, list);
-}
-
-void Debug::Warning(const LogTag & /*tag*/, const char *format, ...) {
-  va_list list;
-  va_start(list, format);
-  __android_log_vprint(ANDROID_LOG_WARN, LOG_TAG, format, list);
-}
-
-void Debug::Info(const LogTag & /*tag*/, const char *format, ...) {
-  va_list list;
-  va_start(list, format);
-  __android_log_vprint(ANDROID_LOG_INFO, LOG_TAG, format, list);
-}
-
-void Debug::Verbose(const LogTag & /*tag*/, const char *format, ...) {
-  va_list list;
-  va_start(list, format);
-  __android_log_vprint(ANDROID_LOG_VERBOSE, LOG_TAG, format, list);
-}
-
 }  // namespace sde
 
diff --git a/libhwcomposer/hwc_mdpcomp.cpp b/libhwcomposer/hwc_mdpcomp.cpp
index 4e7d101..ba7793e 100644
--- a/libhwcomposer/hwc_mdpcomp.cpp
+++ b/libhwcomposer/hwc_mdpcomp.cpp
@@ -26,6 +26,7 @@
 #include "hwc_ad.h"
 #include <overlayRotator.h>
 #include "hwc_copybit.h"
+#include "qd_utils.h"
 
 using namespace overlay;
 using namespace qdutils;
@@ -48,6 +49,7 @@
 bool MDPComp::sSrcSplitEnabled = false;
 int MDPComp::sMaxSecLayers = 1;
 bool MDPComp::enablePartialUpdateForMDP3 = false;
+bool MDPComp::sIsPartialUpdateActive = true;
 MDPComp* MDPComp::getObject(hwc_context_t *ctx, const int& dpy) {
     if(qdutils::MDPVersion::getInstance().isSrcSplit()) {
         sSrcSplitEnabled = true;
@@ -1262,7 +1264,7 @@
         hwc_display_contents_1_t* list){
     if(!qdutils::MDPVersion::getInstance().isPartialUpdateEnabled() ||
             isSkipPresent(ctx, mDpy) || (list->flags & HWC_GEOMETRY_CHANGED) ||
-            mDpy ) {
+            !sIsPartialUpdateActive || mDpy ) {
         return false;
     }
     if(ctx->listStats[mDpy].secureUI)
@@ -2735,5 +2737,27 @@
     return 0;
 }
 
+int MDPComp::setPartialUpdatePref(hwc_context_t *ctx, bool enable) {
+    Locker::Autolock _l(ctx->mDrawLock);
+    const int fbNum = Overlay::getFbForDpy(Overlay::DPY_PRIMARY);
+    char path[MAX_SYSFS_FILE_PATH];
+    snprintf (path, sizeof(path), "sys/class/graphics/fb%d/dyn_pu", fbNum);
+    int fd = open(path, O_WRONLY);
+    if(fd < 0) {
+        ALOGE("%s: Failed to open sysfd node", __FUNCTION__);
+        return -1;
+    }
+    char value[4];
+    snprintf(value, sizeof(value), "%d", (int)enable);
+    ssize_t ret = write(fd, value, strlen(value));
+    if(ret <= 0) {
+        ALOGE("%s: Failed to write to sysfd nodes", __FUNCTION__);
+        close(fd);
+        return -1;
+    }
+    close(fd);
+    sIsPartialUpdateActive = enable;
+    return 0;
+}
 }; //namespace
 
diff --git a/libhwcomposer/hwc_mdpcomp.h b/libhwcomposer/hwc_mdpcomp.h
index 8929c40..4ae7aa7 100644
--- a/libhwcomposer/hwc_mdpcomp.h
+++ b/libhwcomposer/hwc_mdpcomp.h
@@ -56,6 +56,7 @@
     static void dynamicDebug(bool enable){ sDebugLogs = enable; }
     static void setIdleTimeout(const uint32_t& timeout);
     static void setMaxPipesPerMixer(const uint32_t value);
+    static int setPartialUpdatePref(hwc_context_t *ctx, bool enable);
 
 protected:
     enum ePipeType {
@@ -257,6 +258,7 @@
     static bool sSrcSplitEnabled;
     static IdleInvalidator *sIdleInvalidator;
     static int sMaxSecLayers;
+    static bool sIsPartialUpdateActive;
     struct FrameInfo mCurrentFrame;
     struct LayerCache mCachedFrame;
     //Enable 4kx2k yuv layer split
diff --git a/libhwcomposer/hwc_qclient.cpp b/libhwcomposer/hwc_qclient.cpp
index b0ebb3a..add5dc8 100644
--- a/libhwcomposer/hwc_qclient.cpp
+++ b/libhwcomposer/hwc_qclient.cpp
@@ -306,6 +306,13 @@
     }
 }
 
+static status_t setPartialUpdatePref(hwc_context_t *ctx, uint32_t enable) {
+    ALOGD("%s: enable: %d", __FUNCTION__, enable);
+    if(qhwc::MDPComp::setPartialUpdatePref(ctx, (bool)enable) < 0)
+        return NO_INIT;
+    return NO_ERROR;
+}
+
 status_t QClient::notifyCallback(uint32_t command, const Parcel* inParcel,
         Parcel* outParcel) {
     status_t ret = NO_ERROR;
@@ -353,6 +360,8 @@
             break;
         case IQService::SET_MAX_PIPES_PER_MIXER:
             setMaxPipesPerMixer(mHwcContext, inParcel);
+        case IQService::SET_PARTIAL_UPDATE:
+            ret = setPartialUpdatePref(mHwcContext, inParcel->readInt32());
             break;
         case IQService::TOGGLE_BWC:
             toggleBWC(mHwcContext, inParcel);
diff --git a/libqservice/IQService.h b/libqservice/IQService.h
index 683c93c..a935131 100644
--- a/libqservice/IQService.h
+++ b/libqservice/IQService.h
@@ -55,8 +55,9 @@
         DYNAMIC_DEBUG = 15,     // Enable more logging on the fly
         SET_IDLE_TIMEOUT = 16,  // Set idle timeout for GPU fallback
         TOGGLE_BWC = 17,           // Toggle BWC On/Off on targets that support
+        SET_PARTIAL_UPDATE = 18,   // Preference on partial update feature
         /* Enable/Disable/Set refresh rate dynamically */
-        CONFIGURE_DYN_REFRESH_RATE = 18,
+        CONFIGURE_DYN_REFRESH_RATE = 19,
         COMMAND_LIST_END = 400,
     };
 
diff --git a/libqservice/QServiceUtils.h b/libqservice/QServiceUtils.h
index f53d140..5b61c8e 100644
--- a/libqservice/QServiceUtils.h
+++ b/libqservice/QServiceUtils.h
@@ -74,6 +74,10 @@
     return sendSingleParam(qService::IQService::SCREEN_REFRESH, 1);
 }
 
+inline android::status_t setPartialUpdate(uint32_t enable) {
+    return sendSingleParam(qService::IQService::SET_PARTIAL_UPDATE, enable);
+}
+
 inline android::status_t setExtOrientation(uint32_t orientation) {
     return sendSingleParam(qService::IQService::EXTERNAL_ORIENTATION,
             orientation);