hwc: Update HAL to AU_LINUX_ANDROID_LA.HB.1.3.9.06.00.01.213.229

Includes changes from display SU 31.

Bug: 29945684
Bug: 27346522
Change-Id: Ie798d1123208be69c401a6308f14a7b4a4b46963
diff --git a/msm8996/sdm/libs/core/core_impl.cpp b/msm8996/sdm/libs/core/core_impl.cpp
index da85c9e..66eb846 100644
--- a/msm8996/sdm/libs/core/core_impl.cpp
+++ b/msm8996/sdm/libs/core/core_impl.cpp
@@ -71,31 +71,25 @@
     goto CleanupOnError;
   }
 
-  hw_resource_ = new HWResourceInfo();
-  if (!hw_resource_) {
-    error = kErrorMemory;
-    goto CleanupOnError;
-  }
-
-  error = hw_info_intf_->GetHWResourceInfo(hw_resource_);
+  error = hw_info_intf_->GetHWResourceInfo(&hw_resource_);
   if (error != kErrorNone) {
     goto CleanupOnError;
   }
 
-  error = comp_mgr_.Init(*hw_resource_, extension_intf_, buffer_sync_handler_);
+  error = comp_mgr_.Init(hw_resource_, extension_intf_, buffer_sync_handler_);
   if (error != kErrorNone) {
     goto CleanupOnError;
   }
 
-  if (extension_intf_ && hw_resource_->hw_rot_info.num_rotator) {
-    error = extension_intf_->CreateRotator(hw_resource_->hw_rot_info, buffer_allocator_,
+  if (extension_intf_ && hw_resource_.hw_rot_info.num_rotator) {
+    error = extension_intf_->CreateRotator(hw_resource_.hw_rot_info, buffer_allocator_,
                                            buffer_sync_handler_, &rotator_intf_);
     if (error != kErrorNone) {
       DLOGW("rotation is not supported");
     }
   }
 
-  error = ColorManagerProxy::Init(*hw_resource_);
+  error = ColorManagerProxy::Init(hw_resource_);
   // if failed, doesn't affect display core functionalities.
   if (error != kErrorNone) {
     DLOGW("Unable creating color manager and continue without it.");
@@ -108,17 +102,13 @@
     HWInfoInterface::Destroy(hw_info_intf_);
   }
 
-  if (hw_resource_) {
-    delete hw_resource_;
-  }
-
   return error;
 }
 
 DisplayError CoreImpl::Deinit() {
   SCOPE_LOCK(locker_);
 
-  if (extension_intf_ && hw_resource_->hw_rot_info.num_rotator) {
+  if (extension_intf_ && hw_resource_.hw_rot_info.num_rotator) {
     extension_intf_->DestroyRotator(rotator_intf_);
   }
 
@@ -127,10 +117,6 @@
   comp_mgr_.Deinit();
   HWInfoInterface::Destroy(hw_info_intf_);
 
-  if (hw_resource_) {
-    delete hw_resource_;
-  }
-
   return kErrorNone;
 }
 
diff --git a/msm8996/sdm/libs/core/core_impl.h b/msm8996/sdm/libs/core/core_impl.h
index 2d0e2d2..c2e98c3 100644
--- a/msm8996/sdm/libs/core/core_impl.h
+++ b/msm8996/sdm/libs/core/core_impl.h
@@ -65,7 +65,7 @@
   Locker locker_;
   BufferAllocator *buffer_allocator_;
   BufferSyncHandler *buffer_sync_handler_;
-  HWResourceInfo *hw_resource_ = NULL;
+  HWResourceInfo hw_resource_;
   CompManager comp_mgr_;
   HWInfoInterface *hw_info_intf_ = NULL;
   RotatorInterface *rotator_intf_ = NULL;
diff --git a/msm8996/sdm/libs/core/display_base.cpp b/msm8996/sdm/libs/core/display_base.cpp
index 84a137c..3589680 100644
--- a/msm8996/sdm/libs/core/display_base.cpp
+++ b/msm8996/sdm/libs/core/display_base.cpp
@@ -49,6 +49,7 @@
 }
 
 DisplayError DisplayBase::Init() {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
   hw_panel_info_ = HWPanelInfo();
   hw_intf_->GetHWPanelInfo(&hw_panel_info_);
@@ -118,14 +119,11 @@
 }
 
 DisplayError DisplayBase::Deinit() {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   if (rotator_intf_) {
     rotator_intf_->UnregisterDisplay(display_rotator_ctx_);
   }
 
-  if (color_modes_) {
-    delete[] color_modes_;
-  }
-
   if (color_mgr_) {
     delete color_mgr_;
     color_mgr_ = NULL;
@@ -196,7 +194,8 @@
 }
 
 DisplayError DisplayBase::Prepare(LayerStack *layer_stack) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
+  DisplayError error = kErrorNone;
 
   if (!active_) {
     return kErrorPermission;
@@ -206,19 +205,13 @@
     return kErrorParameters;
   }
 
-  return PrepareLocked(layer_stack);
-}
-
-DisplayError DisplayBase::PrepareLocked(LayerStack *layer_stack) {
-  DisplayError error = kErrorNone;
-
   error = ValidateGPUTarget(layer_stack);
   if (error != kErrorNone) {
     return error;
   }
 
   if (color_mgr_ && color_mgr_->NeedsPartialUpdateDisable()) {
-    DisablePartialUpdateOneFrameLocked();
+    DisablePartialUpdateOneFrame();
   }
 
   if (partial_update_control_ == false || disable_pu_one_frame_) {
@@ -270,7 +263,8 @@
 }
 
 DisplayError DisplayBase::Commit(LayerStack *layer_stack) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
+  DisplayError error = kErrorNone;
 
   if (!active_) {
     pending_commit_ = false;
@@ -288,12 +282,6 @@
 
   pending_commit_ = false;
 
-  return CommitLocked(layer_stack);
-}
-
-DisplayError DisplayBase::CommitLocked(LayerStack *layer_stack) {
-  DisplayError error = kErrorNone;
-
   // Layer stack attributes has changed, need to Reconfigure, currently in use for Hybrid Comp
   if (layer_stack->flags.attributes_changed) {
     error = comp_manager_->ReConfigure(display_comp_ctx_, &hw_layers_);
@@ -347,6 +335,7 @@
 }
 
 DisplayError DisplayBase::Flush() {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
 
   if (!active_) {
@@ -376,6 +365,7 @@
 }
 
 DisplayError DisplayBase::GetDisplayState(DisplayState *state) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   if (!state) {
     return kErrorParameters;
   }
@@ -385,10 +375,12 @@
 }
 
 DisplayError DisplayBase::GetNumVariableInfoConfigs(uint32_t *count) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   return hw_intf_->GetNumDisplayAttributes(count);
 }
 
 DisplayError DisplayBase::GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   HWDisplayAttributes attrib;
   if (hw_intf_->GetDisplayAttributes(index, &attrib) == kErrorNone) {
     *variable_info = attrib;
@@ -399,10 +391,12 @@
 }
 
 DisplayError DisplayBase::GetActiveConfig(uint32_t *index) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   return hw_intf_->GetActiveConfig(index);
 }
 
 DisplayError DisplayBase::GetVSyncState(bool *enabled) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   if (!enabled) {
     return kErrorParameters;
   }
@@ -412,11 +406,8 @@
   return kErrorNone;
 }
 
-bool DisplayBase::IsUnderscanSupported() {
-  return underscan_supported_;
-}
-
 DisplayError DisplayBase::SetDisplayState(DisplayState state) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
   bool active = false;
 
@@ -479,11 +470,7 @@
 }
 
 DisplayError DisplayBase::SetActiveConfig(uint32_t index) {
-  SCOPE_LOCK(locker_);
-  return SetActiveConfigLocked(index);
-}
-
-DisplayError DisplayBase::SetActiveConfigLocked(uint32_t index) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
   uint32_t active_index = 0;
 
@@ -501,12 +488,8 @@
   return ReconfigureDisplay();
 }
 
-DisplayError DisplayBase::SetActiveConfig(DisplayConfigVariableInfo *variable_info) {
-  SCOPE_LOCK(locker_);
-  return SetActiveConfigLocked(variable_info);
-}
-
 DisplayError DisplayBase::SetMaxMixerStages(uint32_t max_mixer_stages) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
 
   error = comp_manager_->SetMaxMixerStages(display_comp_ctx_, max_mixer_stages);
@@ -518,29 +501,8 @@
   return error;
 }
 
-DisplayError DisplayBase::ControlPartialUpdate(bool enable, uint32_t *pending) {
-  SCOPE_LOCK(locker_);
-  return ControlPartialUpdateLocked(enable, pending);
-}
-
-DisplayError DisplayBase::DisablePartialUpdateOneFrame() {
-  SCOPE_LOCK(locker_);
-  return DisablePartialUpdateOneFrameLocked();
-}
-
-DisplayError DisplayBase::SetDisplayMode(uint32_t mode) {
-  return kErrorNotSupported;
-}
-
-DisplayError DisplayBase::SetPanelBrightness(int level) {
-  return kErrorNotSupported;
-}
-
-DisplayError DisplayBase::OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) {
-  return kErrorNotSupported;
-}
-
 void DisplayBase::AppendDump(char *buffer, uint32_t length) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   HWDisplayAttributes attrib;
   uint32_t active_index = 0;
   uint32_t num_modes = 0;
@@ -677,6 +639,7 @@
 }
 
 bool DisplayBase::IsRotationRequired(HWLayers *hw_layers) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   HWLayersInfo &layer_info = hw_layers->info;
 
   for (uint32_t i = 0; i < layer_info.count; i++) {
@@ -706,6 +669,7 @@
 DisplayError DisplayBase::ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload,
                                                PPDisplayAPIPayload *out_payload,
                                                PPPendingParams *pending_action) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   if (color_mgr_)
     return color_mgr_->ColorSVCRequestRoute(in_payload, out_payload, pending_action);
   else
@@ -713,6 +677,7 @@
 }
 
 DisplayError DisplayBase::GetColorModeCount(uint32_t *mode_count) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   if (!mode_count) {
     return kErrorParameters;
   }
@@ -734,6 +699,7 @@
 
 DisplayError DisplayBase::GetColorModes(uint32_t *mode_count,
                                         std::vector<std::string> *color_modes) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   if (!mode_count || !color_modes) {
     return kErrorParameters;
   }
@@ -742,14 +708,15 @@
     return kErrorNotSupported;
   }
 
-  if (color_modes_ == NULL) {
-    color_modes_ = new SDEDisplayMode[num_color_modes_];
+  if (!color_modes_.size()) {
+    color_modes_.resize(num_color_modes_);
 
-    DisplayError error = color_mgr_->ColorMgrGetModes(&num_color_modes_, color_modes_);
+    DisplayError error = color_mgr_->ColorMgrGetModes(&num_color_modes_, color_modes_.data());
     if (error != kErrorNone) {
       DLOGE("Failed");
       return error;
     }
+
     for (uint32_t i = 0; i < num_color_modes_; i++) {
       DLOGV_IF(kTagQDCM, "Color Mode[%d]: Name = %s mode_id = %d", i, color_modes_[i].name,
                color_modes_[i].id);
@@ -767,6 +734,7 @@
 }
 
 DisplayError DisplayBase::SetColorMode(const std::string &color_mode) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   if (!color_mgr_) {
     return kErrorNotSupported;
   }
@@ -780,10 +748,6 @@
   }
 
   SDEDisplayMode *sde_display_mode = it->second;
-  if (color_mode_ == sde_display_mode->id) {
-    DLOGV_IF(kTagQDCM, "Same mode requested");
-    return kErrorNone;
-  }
 
   DLOGV_IF(kTagQDCM, "Color Mode Name = %s corresponding mode_id = %d", sde_display_mode->name,
            sde_display_mode->id);
@@ -794,12 +758,11 @@
     return error;
   }
 
-  color_mode_ = sde_display_mode->id;
-
   return error;
 }
 
 DisplayError DisplayBase::SetColorTransform(const uint32_t length, const double *color_transform) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   if (!color_mgr_) {
     return kErrorNotSupported;
   }
@@ -812,6 +775,7 @@
 }
 
 DisplayError DisplayBase::ApplyDefaultDisplayMode() {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   if (color_mgr_)
     return color_mgr_->ApplyDefaultDisplayMode();
   else
@@ -819,6 +783,7 @@
 }
 
 DisplayError DisplayBase::SetCursorPosition(int x, int y) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   if (state_ != kStateOn) {
     return kErrorNotSupported;
   }
@@ -833,6 +798,7 @@
 
 DisplayError DisplayBase::GetRefreshRateRange(uint32_t *min_refresh_rate,
                                               uint32_t *max_refresh_rate) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   // The min and max refresh rates will be same when the HWPanelInfo does not contain valid rates.
   // Usually for secondary displays, command mode panels
   HWDisplayAttributes display_attributes;
@@ -849,11 +815,8 @@
   return error;
 }
 
-DisplayError DisplayBase::GetPanelBrightness(int *level) {
-  return kErrorNotSupported;
-}
-
 DisplayError DisplayBase::SetVSyncState(bool enable) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
   if (vsync_enable_ != enable) {
     error = hw_intf_->SetVSyncState(enable);
@@ -865,6 +828,7 @@
 }
 
 DisplayError DisplayBase::ReconfigureDisplay() {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
   HWDisplayAttributes display_attributes;
   HWMixerAttributes mixer_attributes;
@@ -903,7 +867,7 @@
   }
 
   if (mixer_attributes != mixer_attributes_) {
-    DisablePartialUpdateOneFrameLocked();
+    DisablePartialUpdateOneFrame();
   }
 
   display_attributes_ = display_attributes;
@@ -914,20 +878,12 @@
 }
 
 DisplayError DisplayBase::SetMixerResolution(uint32_t width, uint32_t height) {
-  SCOPE_LOCK(locker_);
-  return SetMixerResolutionLocked(width, height);
-}
-
-DisplayError DisplayBase::SetMixerResolutionLocked(uint32_t width, uint32_t height) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   return ReconfigureMixer(width, height);
 }
 
 DisplayError DisplayBase::GetMixerResolution(uint32_t *width, uint32_t *height) {
-  SCOPE_LOCK(locker_);
-  return GetMixerResolutionLocked(width, height);
-}
-
-DisplayError DisplayBase::GetMixerResolutionLocked(uint32_t *width, uint32_t *height) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   if (!width || !height) {
     return kErrorParameters;
   }
@@ -939,6 +895,7 @@
 }
 
 DisplayError DisplayBase::ReconfigureMixer(uint32_t width, uint32_t height) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
 
   HWMixerAttributes mixer_attributes;
@@ -955,6 +912,7 @@
 
 bool DisplayBase::NeedsMixerReconfiguration(LayerStack *layer_stack, uint32_t *new_mixer_width,
                                             uint32_t *new_mixer_height) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   uint32_t layer_count = UINT32(layer_stack->layers.size());
 
   uint32_t fb_width  = fb_config_.x_pixels;
@@ -1022,12 +980,7 @@
 }
 
 DisplayError DisplayBase::SetFrameBufferConfig(const DisplayConfigVariableInfo &variable_info) {
-  SCOPE_LOCK(locker_);
-  return SetFrameBufferConfigLocked(variable_info);
-}
-
-DisplayError DisplayBase::SetFrameBufferConfigLocked(
-                                   const DisplayConfigVariableInfo &variable_info) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   uint32_t width = variable_info.x_pixels;
   uint32_t height = variable_info.y_pixels;
 
@@ -1063,11 +1016,7 @@
 }
 
 DisplayError DisplayBase::GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info) {
-  SCOPE_LOCK(locker_);
-  return GetFrameBufferConfigLocked(variable_info);
-}
-
-DisplayError DisplayBase::GetFrameBufferConfigLocked(DisplayConfigVariableInfo *variable_info) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   if (!variable_info) {
     return kErrorParameters;
   }
@@ -1078,17 +1027,13 @@
 }
 
 DisplayError DisplayBase::SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data) {
-  SCOPE_LOCK(locker_);
-  return SetDetailEnhancerDataLocked(de_data);
-}
-
-DisplayError DisplayBase::SetDetailEnhancerDataLocked(const DisplayDetailEnhancerData &de_data) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = comp_manager_->SetDetailEnhancerData(display_comp_ctx_, de_data);
   if (error != kErrorNone) {
     return error;
   }
 
-  DisablePartialUpdateOneFrameLocked();
+  DisablePartialUpdateOneFrame();
 
   return kErrorNone;
 }
diff --git a/msm8996/sdm/libs/core/display_base.h b/msm8996/sdm/libs/core/display_base.h
index a9f1c3d..7fdb714 100644
--- a/msm8996/sdm/libs/core/display_base.h
+++ b/msm8996/sdm/libs/core/display_base.h
@@ -29,9 +29,9 @@
 #include <private/strategy_interface.h>
 #include <private/rotator_interface.h>
 #include <private/color_interface.h>
-#include <utils/locker.h>
 
 #include <map>
+#include <mutex>
 #include <string>
 #include <vector>
 
@@ -42,10 +42,13 @@
 
 namespace sdm {
 
+using std::recursive_mutex;
+using std::lock_guard;
+
 class RotatorCtrl;
 class HWInfoInterface;
 
-class DisplayBase : public DisplayInterface {
+class DisplayBase : public DisplayInterface, DumpImpl {
  public:
   DisplayBase(DisplayType display_type, DisplayEventHandler *event_handler,
               HWDeviceType hw_device_type, BufferSyncHandler *buffer_sync_handler,
@@ -54,8 +57,8 @@
   virtual ~DisplayBase() { }
   virtual DisplayError Init();
   virtual DisplayError Deinit();
-  DisplayError Prepare(LayerStack *layer_stack) final;
-  DisplayError Commit(LayerStack *layer_stack) final;
+  DisplayError Prepare(LayerStack *layer_stack);
+  DisplayError Commit(LayerStack *layer_stack);
   virtual DisplayError Flush();
   virtual DisplayError GetDisplayState(DisplayState *state);
   virtual DisplayError GetNumVariableInfoConfigs(uint32_t *count);
@@ -63,15 +66,29 @@
   virtual DisplayError GetActiveConfig(uint32_t *index);
   virtual DisplayError GetVSyncState(bool *enabled);
   virtual DisplayError SetDisplayState(DisplayState state);
-  DisplayError SetActiveConfig(uint32_t index) final;
-  DisplayError SetActiveConfig(DisplayConfigVariableInfo *variable_info) final;
+  virtual DisplayError SetActiveConfig(uint32_t index);
+  virtual DisplayError SetActiveConfig(DisplayConfigVariableInfo *variable_info) {
+    return kErrorNotSupported;
+  }
   virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages);
-  DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) final;
-  DisplayError DisablePartialUpdateOneFrame() final;
-  virtual DisplayError SetDisplayMode(uint32_t mode);
-  virtual bool IsUnderscanSupported();
-  virtual DisplayError SetPanelBrightness(int level);
-  virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level);
+  virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending) {
+    return kErrorNotSupported;
+  }
+  virtual DisplayError DisablePartialUpdateOneFrame() {
+    return kErrorNotSupported;
+  }
+  virtual DisplayError SetDisplayMode(uint32_t mode) {
+    return kErrorNotSupported;
+  }
+  virtual bool IsUnderscanSupported() {
+    return false;
+  }
+  virtual DisplayError SetPanelBrightness(int level) {
+    return kErrorNotSupported;
+  }
+  virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) {
+    return kErrorNotSupported;
+  }
   virtual DisplayError ColorSVCRequestRoute(const PPDisplayAPIPayload &in_payload,
                                             PPDisplayAPIPayload *out_payload,
                                             PPPendingParams *pending_action);
@@ -82,33 +99,18 @@
   virtual DisplayError ApplyDefaultDisplayMode(void);
   virtual DisplayError SetCursorPosition(int x, int y);
   virtual DisplayError GetRefreshRateRange(uint32_t *min_refresh_rate, uint32_t *max_refresh_rate);
-  virtual DisplayError GetPanelBrightness(int *level);
+  virtual DisplayError GetPanelBrightness(int *level) {
+    return kErrorNotSupported;
+  }
   virtual DisplayError SetVSyncState(bool enable);
-  DisplayError SetMixerResolution(uint32_t width, uint32_t height) final;
-  DisplayError GetMixerResolution(uint32_t *width, uint32_t *height) final;
-  DisplayError SetFrameBufferConfig(const DisplayConfigVariableInfo &variable_info) final;
-  DisplayError GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info) final;
-  DisplayError SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data) final;
+  virtual void SetIdleTimeoutMs(uint32_t timeout_ms) {}
+  virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height);
+  virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height);
+  virtual DisplayError SetFrameBufferConfig(const DisplayConfigVariableInfo &variable_info);
+  virtual DisplayError GetFrameBufferConfig(DisplayConfigVariableInfo *variable_info);
+  virtual DisplayError SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data);
 
  protected:
-  virtual DisplayError PrepareLocked(LayerStack *layer_stack);
-  virtual DisplayError CommitLocked(LayerStack *layer_stack);
-  virtual DisplayError SetActiveConfigLocked(uint32_t index);
-  virtual DisplayError SetActiveConfigLocked(DisplayConfigVariableInfo *variable_info) {
-    return kErrorNotSupported;
-  }
-  virtual DisplayError ControlPartialUpdateLocked(bool enable, uint32_t *pending) {
-    return kErrorNotSupported;
-  }
-  virtual DisplayError DisablePartialUpdateOneFrameLocked() {
-    return kErrorNotSupported;
-  }
-  virtual DisplayError SetMixerResolutionLocked(uint32_t width, uint32_t height);
-  virtual DisplayError GetMixerResolutionLocked(uint32_t *width, uint32_t *height);
-  virtual DisplayError SetFrameBufferConfigLocked(const DisplayConfigVariableInfo &variable_info);
-  virtual DisplayError GetFrameBufferConfigLocked(DisplayConfigVariableInfo *variable_info);
-  virtual DisplayError SetDetailEnhancerDataLocked(const DisplayDetailEnhancerData &de_data);
-
   // DumpImpl method
   void AppendDump(char *buffer, uint32_t length);
 
@@ -120,8 +122,7 @@
                                  uint32_t *new_mixer_height);
   DisplayError ReconfigureMixer(uint32_t width, uint32_t height);
 
-
-  Locker locker_;
+  recursive_mutex recursive_mutex_;
   DisplayType display_type_;
   DisplayEventHandler *event_handler_ = NULL;
   HWDeviceType hw_device_type_;
@@ -138,7 +139,6 @@
   HWLayers hw_layers_;
   bool pending_commit_ = false;
   bool vsync_enable_ = false;
-  bool underscan_supported_ = false;
   uint32_t max_mixer_stages_ = 0;
   HWInfoInterface *hw_info_intf_ = NULL;
   ColorManagerProxy *color_mgr_ = NULL;  // each display object owns its ColorManagerProxy
@@ -146,8 +146,7 @@
   HWEventsInterface *hw_events_intf_ = NULL;
   bool disable_pu_one_frame_ = false;
   uint32_t num_color_modes_ = 0;
-  SDEDisplayMode *color_modes_ = NULL;
-  int32_t color_mode_ = 0;
+  std::vector<SDEDisplayMode> color_modes_;
   typedef std::map<std::string, SDEDisplayMode *> ColorModeMap;
   ColorModeMap color_mode_map_ = {};
   HWDisplayAttributes display_attributes_ = {};
diff --git a/msm8996/sdm/libs/core/display_hdmi.cpp b/msm8996/sdm/libs/core/display_hdmi.cpp
index a53995b..e09959f 100644
--- a/msm8996/sdm/libs/core/display_hdmi.cpp
+++ b/msm8996/sdm/libs/core/display_hdmi.cpp
@@ -26,6 +26,7 @@
 #include <utils/debug.h>
 #include <map>
 #include <utility>
+#include <vector>
 
 #include "display_hdmi.h"
 #include "hw_interface.h"
@@ -44,7 +45,7 @@
 }
 
 DisplayError DisplayHDMI::Init() {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
 
   DisplayError error = HWHDMI::Create(&hw_intf_, hw_info_intf_,
                                       DisplayBase::buffer_sync_handler_);
@@ -98,7 +99,7 @@
 }
 
 DisplayError DisplayHDMI::Deinit() {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
 
   DisplayError error = DisplayBase::Deinit();
   HWHDMI::Destroy(hw_intf_);
@@ -106,7 +107,8 @@
   return error;
 }
 
-DisplayError DisplayHDMI::PrepareLocked(LayerStack *layer_stack) {
+DisplayError DisplayHDMI::Prepare(LayerStack *layer_stack) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
   uint32_t new_mixer_width = 0;
   uint32_t new_mixer_height = 0;
@@ -122,64 +124,12 @@
 
   SetS3DMode(layer_stack);
 
-  return DisplayBase::PrepareLocked(layer_stack);
-}
-
-DisplayError DisplayHDMI::Flush() {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::Flush();
-}
-
-DisplayError DisplayHDMI::GetDisplayState(DisplayState *state) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::GetDisplayState(state);
-}
-
-DisplayError DisplayHDMI::GetNumVariableInfoConfigs(uint32_t *count) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::GetNumVariableInfoConfigs(count);
-}
-
-DisplayError DisplayHDMI::GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::GetConfig(index, variable_info);
-}
-
-DisplayError DisplayHDMI::GetActiveConfig(uint32_t *index) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::GetActiveConfig(index);
-}
-
-DisplayError DisplayHDMI::GetVSyncState(bool *enabled) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::GetVSyncState(enabled);
-}
-
-DisplayError DisplayHDMI::SetDisplayState(DisplayState state) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::SetDisplayState(state);
-}
-
-DisplayError DisplayHDMI::SetVSyncState(bool enable) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::SetVSyncState(enable);
-}
-
-void DisplayHDMI::SetIdleTimeoutMs(uint32_t timeout_ms) { }
-
-DisplayError DisplayHDMI::SetMaxMixerStages(uint32_t max_mixer_stages) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::SetMaxMixerStages(max_mixer_stages);
-}
-
-DisplayError DisplayHDMI::SetDisplayMode(uint32_t mode) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::SetDisplayMode(mode);
+  return DisplayBase::Prepare(layer_stack);
 }
 
 DisplayError DisplayHDMI::GetRefreshRateRange(uint32_t *min_refresh_rate,
                                               uint32_t *max_refresh_rate) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
 
   if (hw_panel_info_.min_fps && hw_panel_info_.max_fps) {
@@ -193,7 +143,7 @@
 }
 
 DisplayError DisplayHDMI::SetRefreshRate(uint32_t refresh_rate) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
 
   if (!active_) {
     return kErrorPermission;
@@ -208,17 +158,12 @@
 }
 
 bool DisplayHDMI::IsUnderscanSupported() {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::IsUnderscanSupported();
-}
-
-DisplayError DisplayHDMI::SetPanelBrightness(int level) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::SetPanelBrightness(level);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
+  return underscan_supported_;
 }
 
 DisplayError DisplayHDMI::OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   return hw_intf_->OnMinHdcpEncryptionLevelChange(min_enc_level);
 }
 
@@ -230,7 +175,7 @@
   hw_intf_->GetNumDisplayAttributes(&num_modes);
 
   // Get display attribute for each mode
-  HWDisplayAttributes *attrib = new HWDisplayAttributes[num_modes];
+  std::vector<HWDisplayAttributes> attrib(num_modes);
   for (index = 0; index < num_modes; index++) {
     hw_intf_->GetDisplayAttributes(index, &attrib[index]);
   }
@@ -265,7 +210,6 @@
     DLOGW("%s, could not support S3D mode from EDID info. S3D mode is %d",
           __FUNCTION__, s3d_mode);
   }
-  delete[] attrib;
 
   // Used for changing HDMI Resolution - override the best with user set config
   uint32_t user_config = UINT32(Debug::GetHDMIResolution());
@@ -313,16 +257,6 @@
   }
 }
 
-void DisplayHDMI::AppendDump(char *buffer, uint32_t length) {
-  SCOPE_LOCK(locker_);
-  DisplayBase::AppendDump(buffer, length);
-}
-
-DisplayError DisplayHDMI::SetCursorPosition(int x, int y) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::SetCursorPosition(x, y);
-}
-
 void DisplayHDMI::SetS3DMode(LayerStack *layer_stack) {
   uint32_t s3d_layer_count = 0;
   HWS3DMode s3d_mode = kS3DModeNone;
diff --git a/msm8996/sdm/libs/core/display_hdmi.h b/msm8996/sdm/libs/core/display_hdmi.h
index b3ec9af..3a3c0dc 100644
--- a/msm8996/sdm/libs/core/display_hdmi.h
+++ b/msm8996/sdm/libs/core/display_hdmi.h
@@ -35,31 +35,18 @@
 
 class HWHDMIInterface;
 
-class DisplayHDMI : public DisplayBase, DumpImpl, HWEventHandler {
+class DisplayHDMI : public DisplayBase, HWEventHandler {
  public:
   DisplayHDMI(DisplayEventHandler *event_handler, HWInfoInterface *hw_info_intf,
               BufferSyncHandler *buffer_sync_handler, CompManager *comp_manager,
               RotatorInterface *rotator_intf);
   virtual DisplayError Init();
   virtual DisplayError Deinit();
-  virtual DisplayError Flush();
-  virtual DisplayError GetDisplayState(DisplayState *state);
-  virtual DisplayError GetNumVariableInfoConfigs(uint32_t *count);
-  virtual DisplayError GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info);
-  virtual DisplayError GetActiveConfig(uint32_t *index);
-  virtual DisplayError GetVSyncState(bool *enabled);
-  virtual DisplayError SetDisplayState(DisplayState state);
-  virtual DisplayError SetVSyncState(bool enable);
-  virtual void SetIdleTimeoutMs(uint32_t timeout_ms);
-  virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages);
-  virtual DisplayError SetDisplayMode(uint32_t mode);
+  virtual DisplayError Prepare(LayerStack *layer_stack);
   virtual DisplayError GetRefreshRateRange(uint32_t *min_refresh_rate, uint32_t *max_refresh_rate);
   virtual DisplayError SetRefreshRate(uint32_t refresh_rate);
   virtual bool IsUnderscanSupported();
-  virtual DisplayError SetPanelBrightness(int level);
   virtual DisplayError OnMinHdcpEncryptionLevelChange(uint32_t min_enc_level);
-  virtual void AppendDump(char *buffer, uint32_t length);
-  virtual DisplayError SetCursorPosition(int x, int y);
 
   // Implement the HWEventHandlers
   virtual DisplayError VSync(int64_t timestamp);
@@ -69,11 +56,11 @@
   virtual void CECMessage(char *message);
 
  private:
-  virtual DisplayError PrepareLocked(LayerStack *layer_stack);
-  virtual uint32_t GetBestConfig(HWS3DMode s3d_mode);
-  virtual void GetScanSupport();
-  virtual void SetS3DMode(LayerStack *layer_stack);
+  uint32_t GetBestConfig(HWS3DMode s3d_mode);
+  void GetScanSupport();
+  void SetS3DMode(LayerStack *layer_stack);
 
+  bool underscan_supported_ = false;
   HWScanSupport scan_support_;
   std::map<LayerBufferS3DFormat, HWS3DMode> s3d_format_to_mode_;
   std::vector<const char *> event_list_ = {"vsync_event", "idle_notify", "cec/rd_msg",
diff --git a/msm8996/sdm/libs/core/display_primary.cpp b/msm8996/sdm/libs/core/display_primary.cpp
index 41e4c29..ad1d3d6 100644
--- a/msm8996/sdm/libs/core/display_primary.cpp
+++ b/msm8996/sdm/libs/core/display_primary.cpp
@@ -47,7 +47,7 @@
 }
 
 DisplayError DisplayPrimary::Init() {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
 
   DisplayError error = HWPrimary::Create(&hw_intf_, hw_info_intf_,
                                          DisplayBase::buffer_sync_handler_);
@@ -83,7 +83,7 @@
 }
 
 DisplayError DisplayPrimary::Deinit() {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
 
   DisplayError error = DisplayBase::Deinit();
   HWPrimary::Destroy(hw_intf_);
@@ -91,7 +91,8 @@
   return error;
 }
 
-DisplayError DisplayPrimary::PrepareLocked(LayerStack *layer_stack) {
+DisplayError DisplayPrimary::Prepare(LayerStack *layer_stack) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
   uint32_t new_mixer_width = 0;
   uint32_t new_mixer_height = 0;
@@ -105,10 +106,11 @@
     }
   }
 
-  return DisplayBase::PrepareLocked(layer_stack);
+  return DisplayBase::Prepare(layer_stack);
 }
 
-DisplayError DisplayPrimary::CommitLocked(LayerStack *layer_stack) {
+DisplayError DisplayPrimary::Commit(LayerStack *layer_stack) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
 
   // Enabling auto refresh is async and needs to happen before commit ioctl
@@ -118,7 +120,7 @@
 
   bool set_idle_timeout = comp_manager_->CanSetIdleTimeout(display_comp_ctx_);
 
-  error = DisplayBase::CommitLocked(layer_stack);
+  error = DisplayBase::Commit(layer_stack);
   if (error != kErrorNone) {
     return error;
   }
@@ -136,43 +138,8 @@
   return error;
 }
 
-DisplayError DisplayPrimary::Flush() {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::Flush();
-}
-
-DisplayError DisplayPrimary::GetDisplayState(DisplayState *state) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::GetDisplayState(state);
-}
-
-DisplayError DisplayPrimary::GetNumVariableInfoConfigs(uint32_t *count) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::GetNumVariableInfoConfigs(count);
-}
-
-DisplayError DisplayPrimary::GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::GetConfig(index, variable_info);
-}
-
-DisplayError DisplayPrimary::GetActiveConfig(uint32_t *index) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::GetActiveConfig(index);
-}
-
-DisplayError DisplayPrimary::GetVSyncState(bool *enabled) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::GetVSyncState(enabled);
-}
-
-bool DisplayPrimary::IsUnderscanSupported() {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::IsUnderscanSupported();
-}
-
 DisplayError DisplayPrimary::SetDisplayState(DisplayState state) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
   error = DisplayBase::SetDisplayState(state);
   if (error != kErrorNone) {
@@ -187,13 +154,8 @@
   return kErrorNone;
 }
 
-DisplayError DisplayPrimary::SetVSyncState(bool enable) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::SetVSyncState(enable);
-}
-
 void DisplayPrimary::SetIdleTimeoutMs(uint32_t timeout_ms) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
 
   // Idle fallback feature is supported only for video mode panel.
   if (hw_panel_info_.mode == kModeVideo) {
@@ -202,13 +164,8 @@
   idle_timeout_ms_ = timeout_ms;
 }
 
-DisplayError DisplayPrimary::SetMaxMixerStages(uint32_t max_mixer_stages) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::SetMaxMixerStages(max_mixer_stages);
-}
-
 DisplayError DisplayPrimary::SetDisplayMode(uint32_t mode) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
   HWDisplayMode hw_display_mode = static_cast<HWDisplayMode>(mode);
   uint32_t pending = 0;
@@ -237,10 +194,10 @@
   }
 
   if (mode == kModeVideo) {
-    ControlPartialUpdateLocked(false /* enable */, &pending);
+    ControlPartialUpdate(false /* enable */, &pending);
     hw_intf_->SetIdleTimeoutMs(idle_timeout_ms_);
   } else if (mode == kModeCommand) {
-    ControlPartialUpdateLocked(true /* enable */, &pending);
+    ControlPartialUpdate(true /* enable */, &pending);
     hw_intf_->SetIdleTimeoutMs(0);
   }
 
@@ -248,13 +205,13 @@
 }
 
 DisplayError DisplayPrimary::SetPanelBrightness(int level) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   return hw_intf_->SetPanelBrightness(level);
 }
 
 DisplayError DisplayPrimary::GetRefreshRateRange(uint32_t *min_refresh_rate,
                                                  uint32_t *max_refresh_rate) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
 
   if (hw_panel_info_.min_fps && hw_panel_info_.max_fps) {
@@ -268,7 +225,7 @@
 }
 
 DisplayError DisplayPrimary::SetRefreshRate(uint32_t refresh_rate) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
 
   if (!active_ || !hw_panel_info_.dynamic_fps) {
     return kErrorNotSupported;
@@ -287,11 +244,6 @@
   return DisplayBase::ReconfigureDisplay();
 }
 
-void DisplayPrimary::AppendDump(char *buffer, uint32_t length) {
-  SCOPE_LOCK(locker_);
-  DisplayBase::AppendDump(buffer, length);
-}
-
 DisplayError DisplayPrimary::VSync(int64_t timestamp) {
   if (vsync_enable_) {
     DisplayEventVSync vsync;
@@ -302,32 +254,23 @@
   return kErrorNone;
 }
 
-DisplayError DisplayPrimary::SetCursorPosition(int x, int y) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::SetCursorPosition(x, y);
-}
-
-DisplayError DisplayPrimary::Blank(bool blank) {
-  SCOPE_LOCK(locker_);
-  return kErrorNone;
-}
-
 void DisplayPrimary::IdleTimeout() {
   event_handler_->Refresh();
   comp_manager_->ProcessIdleTimeout(display_comp_ctx_);
 }
 
 void DisplayPrimary::ThermalEvent(int64_t thermal_level) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   comp_manager_->ProcessThermalEvent(display_comp_ctx_, thermal_level);
 }
 
 DisplayError DisplayPrimary::GetPanelBrightness(int *level) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   return hw_intf_->GetPanelBrightness(level);
 }
 
-DisplayError DisplayPrimary::ControlPartialUpdateLocked(bool enable, uint32_t *pending) {
+DisplayError DisplayPrimary::ControlPartialUpdate(bool enable, uint32_t *pending) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   if (!pending) {
     return kErrorParameters;
   }
@@ -355,7 +298,8 @@
   return kErrorNone;
 }
 
-DisplayError DisplayPrimary::DisablePartialUpdateOneFrameLocked() {
+DisplayError DisplayPrimary::DisablePartialUpdateOneFrame() {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   disable_pu_one_frame_ = true;
 
   return kErrorNone;
diff --git a/msm8996/sdm/libs/core/display_primary.h b/msm8996/sdm/libs/core/display_primary.h
index 92e6c88..962f00c 100644
--- a/msm8996/sdm/libs/core/display_primary.h
+++ b/msm8996/sdm/libs/core/display_primary.h
@@ -34,45 +34,33 @@
 
 class HWPrimaryInterface;
 
-class DisplayPrimary : public DisplayBase, DumpImpl, HWEventHandler {
+class DisplayPrimary : public DisplayBase, HWEventHandler {
  public:
   DisplayPrimary(DisplayEventHandler *event_handler, HWInfoInterface *hw_info_intf,
                  BufferSyncHandler *buffer_sync_handler, CompManager *comp_manager,
                  RotatorInterface *rotator_intf);
   virtual DisplayError Init();
   virtual DisplayError Deinit();
-  virtual DisplayError Flush();
-  virtual DisplayError GetDisplayState(DisplayState *state);
-  virtual DisplayError GetNumVariableInfoConfigs(uint32_t *count);
-  virtual DisplayError GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info);
-  virtual DisplayError GetActiveConfig(uint32_t *index);
-  virtual DisplayError GetVSyncState(bool *enabled);
+  virtual DisplayError Prepare(LayerStack *layer_stack);
+  virtual DisplayError Commit(LayerStack *layer_stack);
+  virtual DisplayError ControlPartialUpdate(bool enable, uint32_t *pending);
+  virtual DisplayError DisablePartialUpdateOneFrame();
   virtual DisplayError SetDisplayState(DisplayState state);
-  virtual DisplayError SetVSyncState(bool enable);
   virtual void SetIdleTimeoutMs(uint32_t timeout_ms);
-  virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages);
   virtual DisplayError SetDisplayMode(uint32_t mode);
   virtual DisplayError GetRefreshRateRange(uint32_t *min_refresh_rate, uint32_t *max_refresh_rate);
   virtual DisplayError SetRefreshRate(uint32_t refresh_rate);
-  virtual bool IsUnderscanSupported();
   virtual DisplayError SetPanelBrightness(int level);
-  virtual void AppendDump(char *buffer, uint32_t length);
-  virtual DisplayError SetCursorPosition(int x, int y);
   virtual DisplayError GetPanelBrightness(int *level);
 
   // Implement the HWEventHandlers
   virtual DisplayError VSync(int64_t timestamp);
-  virtual DisplayError Blank(bool blank);
+  virtual DisplayError Blank(bool blank) { return kErrorNone; }
   virtual void IdleTimeout();
   virtual void ThermalEvent(int64_t thermal_level);
   virtual void CECMessage(char *message) { }
 
  private:
-  virtual DisplayError PrepareLocked(LayerStack *layer_stack);
-  virtual DisplayError CommitLocked(LayerStack *layer_stack);
-  virtual DisplayError ControlPartialUpdateLocked(bool enable, uint32_t *pending);
-  virtual DisplayError DisablePartialUpdateOneFrameLocked();
-
   uint32_t idle_timeout_ms_ = 0;
   std::vector<const char *> event_list_ = {"vsync_event", "show_blank_event", "idle_notify",
                                            "msm_fb_thermal_level", "thread_exit"};
diff --git a/msm8996/sdm/libs/core/display_virtual.cpp b/msm8996/sdm/libs/core/display_virtual.cpp
index a2e5009..f835ea4 100644
--- a/msm8996/sdm/libs/core/display_virtual.cpp
+++ b/msm8996/sdm/libs/core/display_virtual.cpp
@@ -42,7 +42,7 @@
 }
 
 DisplayError DisplayVirtual::Init() {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
 
   DisplayError error = HWVirtual::Create(&hw_intf_, hw_info_intf_,
                                          DisplayBase::buffer_sync_handler_);
@@ -61,7 +61,7 @@
 }
 
 DisplayError DisplayVirtual::Deinit() {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
 
   DisplayError error = DisplayBase::Deinit();
   HWVirtual::Destroy(hw_intf_);
@@ -69,56 +69,32 @@
   return error;
 }
 
-DisplayError DisplayVirtual::Flush() {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::Flush();
-}
-
-DisplayError DisplayVirtual::GetDisplayState(DisplayState *state) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::GetDisplayState(state);
-}
-
 DisplayError DisplayVirtual::GetNumVariableInfoConfigs(uint32_t *count) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   *count = 1;
   return kErrorNone;
 }
 
 DisplayError DisplayVirtual::GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   *variable_info = display_attributes_;
   return kErrorNone;
 }
 
 DisplayError DisplayVirtual::GetActiveConfig(uint32_t *index) {
-  SCOPE_LOCK(locker_);
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
   *index = 0;
   return kErrorNone;
 }
 
-DisplayError DisplayVirtual::GetVSyncState(bool *enabled) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::GetVSyncState(enabled);
-}
-
-bool DisplayVirtual::IsUnderscanSupported() {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::IsUnderscanSupported();
-}
-
-DisplayError DisplayVirtual::SetDisplayState(DisplayState state) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::SetDisplayState(state);
-}
-
-DisplayError DisplayVirtual::SetActiveConfigLocked(DisplayConfigVariableInfo *variable_info) {
-  DisplayError error = kErrorNone;
+DisplayError DisplayVirtual::SetActiveConfig(DisplayConfigVariableInfo *variable_info) {
+  lock_guard<recursive_mutex> obj(recursive_mutex_);
 
   if (!variable_info) {
     return kErrorParameters;
   }
 
+  DisplayError error = kErrorNone;
   HWDisplayAttributes display_attributes;
   HWMixerAttributes mixer_attributes;
   DisplayConfigVariableInfo fb_config = *variable_info;
@@ -164,48 +140,5 @@
   return kErrorNone;
 }
 
-DisplayError DisplayVirtual::SetVSyncState(bool enable) {
-  SCOPE_LOCK(locker_);
-  return kErrorNotSupported;
-}
-
-void DisplayVirtual::SetIdleTimeoutMs(uint32_t timeout_ms) { }
-
-DisplayError DisplayVirtual::SetMaxMixerStages(uint32_t max_mixer_stages) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::SetMaxMixerStages(max_mixer_stages);
-}
-
-DisplayError DisplayVirtual::SetDisplayMode(uint32_t mode) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::SetDisplayMode(mode);
-}
-
-DisplayError DisplayVirtual::GetRefreshRateRange(uint32_t *min_refresh_rate,
-                                                 uint32_t *max_refresh_rate) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::GetRefreshRateRange(min_refresh_rate, max_refresh_rate);
-}
-
-DisplayError DisplayVirtual::SetRefreshRate(uint32_t refresh_rate) {
-  SCOPE_LOCK(locker_);
-  return kErrorNotSupported;
-}
-
-DisplayError DisplayVirtual::SetPanelBrightness(int level) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::SetPanelBrightness(level);
-}
-
-void DisplayVirtual::AppendDump(char *buffer, uint32_t length) {
-  SCOPE_LOCK(locker_);
-  DisplayBase::AppendDump(buffer, length);
-}
-
-DisplayError DisplayVirtual::SetCursorPosition(int x, int y) {
-  SCOPE_LOCK(locker_);
-  return DisplayBase::SetCursorPosition(x, y);
-}
-
 }  // namespace sdm
 
diff --git a/msm8996/sdm/libs/core/display_virtual.h b/msm8996/sdm/libs/core/display_virtual.h
index 59334a7..69af7f0 100644
--- a/msm8996/sdm/libs/core/display_virtual.h
+++ b/msm8996/sdm/libs/core/display_virtual.h
@@ -33,43 +33,33 @@
 
 class HWVirtualInterface;
 
-class DisplayVirtual : public DisplayBase, DumpImpl {
+class DisplayVirtual : public DisplayBase {
  public:
   DisplayVirtual(DisplayEventHandler *event_handler, HWInfoInterface *hw_info_intf,
                  BufferSyncHandler *buffer_sync_handler, CompManager *comp_manager,
                  RotatorInterface *rotator_intf);
   virtual DisplayError Init();
   virtual DisplayError Deinit();
-  virtual DisplayError Flush();
-  virtual DisplayError GetDisplayState(DisplayState *state);
   virtual DisplayError GetNumVariableInfoConfigs(uint32_t *count);
   virtual DisplayError GetConfig(uint32_t index, DisplayConfigVariableInfo *variable_info);
   virtual DisplayError GetActiveConfig(uint32_t *index);
-  virtual DisplayError GetVSyncState(bool *enabled);
-  virtual DisplayError SetDisplayState(DisplayState state);
-  virtual DisplayError SetVSyncState(bool enable);
-  virtual void SetIdleTimeoutMs(uint32_t timeout_ms);
-  virtual DisplayError SetMaxMixerStages(uint32_t max_mixer_stages);
-  virtual DisplayError SetDisplayMode(uint32_t mode);
-  virtual DisplayError GetRefreshRateRange(uint32_t *min_refresh_rate, uint32_t *max_refresh_rate);
-  virtual DisplayError SetRefreshRate(uint32_t refresh_rate);
-  virtual bool IsUnderscanSupported();
-  virtual DisplayError SetPanelBrightness(int level);
-  virtual void AppendDump(char *buffer, uint32_t length);
-  virtual DisplayError SetCursorPosition(int x, int y);
-
- private:
-  virtual DisplayError SetActiveConfigLocked(uint32_t index) {
+  virtual DisplayError SetActiveConfig(uint32_t index) {
     return kErrorNotSupported;
   }
-  virtual DisplayError SetActiveConfigLocked(DisplayConfigVariableInfo *variable_info);
-  virtual DisplayError SetMixerResolutionLocked(uint32_t width, uint32_t height) {
+  virtual DisplayError SetActiveConfig(DisplayConfigVariableInfo *variable_info);
+  virtual DisplayError SetMixerResolution(uint32_t width, uint32_t height) {
     return kErrorNotSupported;
   }
-  virtual DisplayError GetMixerResolutionLocked(uint32_t *width, uint32_t *height) {
+  virtual DisplayError SetVSyncState(bool enable) {
     return kErrorNotSupported;
   }
-  virtual DisplayError SetDetailEnhancerDataLocked(const DisplayDetailEnhancerData &de_data) {
+  virtual DisplayError SetRefreshRate(uint32_t refresh_rate) {
+    return kErrorNotSupported;
+  }
+  virtual DisplayError GetMixerResolution(uint32_t *width, uint32_t *height) {
+    return kErrorNotSupported;
+  }
+  virtual DisplayError SetDetailEnhancerData(const DisplayDetailEnhancerData &de_data) {
     return kErrorNotSupported;
   }
 };
diff --git a/msm8996/sdm/libs/core/fb/hw_device.cpp b/msm8996/sdm/libs/core/fb/hw_device.cpp
index 3092740..c707847 100644
--- a/msm8996/sdm/libs/core/fb/hw_device.cpp
+++ b/msm8996/sdm/libs/core/fb/hw_device.cpp
@@ -954,7 +954,6 @@
 }
 
 void HWDevice::ResetDisplayParams() {
-  uint32_t dst_scalar_cnt = hw_resource_.hw_dest_scalar_info.count;
   memset(&mdp_disp_commit_, 0, sizeof(mdp_disp_commit_));
   memset(&mdp_in_layers_, 0, sizeof(mdp_in_layers_));
   memset(&mdp_out_layer_, 0, sizeof(mdp_out_layer_));
@@ -963,8 +962,8 @@
   memset(&pp_params_, 0, sizeof(pp_params_));
   memset(&igc_lut_data_, 0, sizeof(igc_lut_data_));
 
-  if (mdp_dest_scalar_data_) {
-    memset(mdp_dest_scalar_data_, 0, sizeof(mdp_dest_scalar_data_) * dst_scalar_cnt);
+  for (size_t i = 0; i < mdp_dest_scalar_data_.size(); i++) {
+    mdp_dest_scalar_data_[i] = {};
   }
 
   for (uint32_t i = 0; i < kMaxSDELayers * 2; i++) {
@@ -976,7 +975,7 @@
   mdp_disp_commit_.commit_v1.output_layer = &mdp_out_layer_;
   mdp_disp_commit_.commit_v1.release_fence = -1;
   mdp_disp_commit_.commit_v1.retire_fence = -1;
-  mdp_disp_commit_.commit_v1.dest_scaler = mdp_dest_scalar_data_;
+  mdp_disp_commit_.commit_v1.dest_scaler = mdp_dest_scalar_data_.data();
 }
 
 void HWDevice::SetCSC(LayerCSC source, mdp_color_space *color_space) {
diff --git a/msm8996/sdm/libs/core/fb/hw_device.h b/msm8996/sdm/libs/core/fb/hw_device.h
index 033e2bc..40f4f63 100644
--- a/msm8996/sdm/libs/core/fb/hw_device.h
+++ b/msm8996/sdm/libs/core/fb/hw_device.h
@@ -29,6 +29,7 @@
 #include <linux/msm_mdp_ext.h>
 #include <linux/mdss_rotator.h>
 #include <pthread.h>
+#include <vector>
 
 #include "hw_interface.h"
 #include "hw_scale.h"
@@ -145,7 +146,7 @@
   bool synchronous_commit_;
   HWDisplayAttributes display_attributes_ = {};
   HWMixerAttributes mixer_attributes_ = {};
-  mdp_destination_scaler_data *mdp_dest_scalar_data_ = NULL;
+  std::vector<mdp_destination_scaler_data> mdp_dest_scalar_data_;
 };
 
 }  // namespace sdm
diff --git a/msm8996/sdm/libs/core/fb/hw_events.cpp b/msm8996/sdm/libs/core/fb/hw_events.cpp
index 5a656cc..5ae53a4 100755
--- a/msm8996/sdm/libs/core/fb/hw_events.cpp
+++ b/msm8996/sdm/libs/core/fb/hw_events.cpp
@@ -141,14 +141,14 @@
 }
 
 DisplayError HWEvents::Init(int fb_num, HWEventHandler *event_handler,
-                            std::vector<const char *> *event_list) {
+                            vector<const char *> *event_list) {
   if (!event_handler)
     return kErrorParameters;
 
   event_handler_ = event_handler;
   fb_num_ = fb_num;
   event_list_ = event_list;
-  poll_fds_ = new pollfd[event_list_->size()];
+  poll_fds_.resize(event_list_->size());
   event_thread_name_ += " - " + std::to_string(fb_num_);
 
   PopulateHWEventData();
@@ -178,10 +178,6 @@
     poll_fds_[i].fd = -1;
   }
 
-  delete [] poll_fds_;
-
-  poll_fds_ = 0;
-
   return kErrorNone;
 }
 
@@ -200,7 +196,7 @@
   setpriority(PRIO_PROCESS, 0, kThreadPriorityUrgent);
 
   while (!exit_threads_) {
-    int error = Sys::poll_(poll_fds_, UINT32(event_list_->size()), -1);
+    int error = Sys::poll_(poll_fds_.data(), UINT32(event_list_->size()), -1);
 
     if (error <= 0) {
       DLOGW("poll failed. error = %s", strerror(errno));
diff --git a/msm8996/sdm/libs/core/fb/hw_events.h b/msm8996/sdm/libs/core/fb/hw_events.h
index 5d7d23d..bcc5ef6 100755
--- a/msm8996/sdm/libs/core/fb/hw_events.h
+++ b/msm8996/sdm/libs/core/fb/hw_events.h
@@ -36,10 +36,12 @@
 
 namespace sdm {
 
+using std::vector;
+
 class HWEvents : public HWEventsInterface {
  public:
   DisplayError Init(int fb_num, HWEventHandler *event_handler,
-                    std::vector<const char *> *event_list);
+                    vector<const char *> *event_list);
   DisplayError Deinit();
 
  private:
@@ -65,9 +67,9 @@
   pollfd InitializePollFd(HWEventData *event_data);
 
   HWEventHandler *event_handler_ = NULL;
-  std::vector<const char *> *event_list_ = NULL;
-  std::vector<HWEventData> event_data_list_ = {};
-  pollfd *poll_fds_ = NULL;
+  vector<const char *> *event_list_ = NULL;
+  vector<HWEventData> event_data_list_ = {};
+  vector<pollfd> poll_fds_;
   pthread_t event_thread_;
   std::string event_thread_name_ = "SDM_EventThread";
   bool exit_threads_ = false;
diff --git a/msm8996/sdm/libs/core/fb/hw_hdmi.cpp b/msm8996/sdm/libs/core/fb/hw_hdmi.cpp
index 6140d0f..d9116e6 100644
--- a/msm8996/sdm/libs/core/fb/hw_hdmi.cpp
+++ b/msm8996/sdm/libs/core/fb/hw_hdmi.cpp
@@ -120,10 +120,7 @@
     return error;
   }
 
-  uint32_t dest_scalar_count = hw_resource_.hw_dest_scalar_info.count;
-  if (dest_scalar_count) {
-    mdp_dest_scalar_data_ = new mdp_destination_scaler_data[dest_scalar_count];
-  }
+  mdp_dest_scalar_data_.resize(hw_resource_.hw_dest_scalar_info.count);
 
   error = ReadEDIDInfo();
   if (error != kErrorNone) {
@@ -136,13 +133,6 @@
     return kErrorHardware;
   }
 
-  // Mode look-up table for HDMI
-  supported_video_modes_ = new msm_hdmi_mode_timing_info[hdmi_mode_count_];
-  if (!supported_video_modes_) {
-    Deinit();
-    return kErrorMemory;
-  }
-
   error = ReadTimingInfo();
   if (error != kErrorNone) {
     Deinit();
@@ -166,18 +156,11 @@
 }
 
 DisplayError HWHDMI::Deinit() {
-  hdmi_mode_count_ = 0;
-  if (supported_video_modes_) {
-    delete[] supported_video_modes_;
-  }
-
-  delete [] mdp_dest_scalar_data_;
-
   return HWDevice::Deinit();
 }
 
 DisplayError HWHDMI::GetNumDisplayAttributes(uint32_t *count) {
-  *count = hdmi_mode_count_;
+  *count = UINT32(hdmi_modes_.size());
   if (*count <= 0) {
     return kErrorHardware;
   }
@@ -219,8 +202,14 @@
     char *ptr = edid_str;
     const uint32_t edid_count_max = 128;
     char *tokens[edid_count_max] = { NULL };
-    ParseLine(ptr, tokens, edid_count_max, &hdmi_mode_count_);
-    for (uint32_t i = 0; i < hdmi_mode_count_; i++) {
+    uint32_t hdmi_mode_count = 0;
+
+    ParseLine(ptr, tokens, edid_count_max, &hdmi_mode_count);
+
+    supported_video_modes_.resize(hdmi_mode_count);
+
+    hdmi_modes_.resize(hdmi_mode_count);
+    for (uint32_t i = 0; i < hdmi_mode_count; i++) {
       hdmi_modes_[i] = UINT32(atoi(tokens[i]));
     }
   }
@@ -232,13 +221,13 @@
                                           HWDisplayAttributes *display_attributes) {
   DTRACE_SCOPED();
 
-  if (index > hdmi_mode_count_) {
+  if (index >= hdmi_modes_.size()) {
     return kErrorNotSupported;
   }
 
   // Get the resolution info from the look up table
   msm_hdmi_mode_timing_info *timing_mode = &supported_video_modes_[0];
-  for (uint32_t i = 0; i < hdmi_mode_count_; i++) {
+  for (uint32_t i = 0; i < hdmi_modes_.size(); i++) {
     msm_hdmi_mode_timing_info *cur = &supported_video_modes_[i];
     if (cur->video_format == hdmi_modes_[index]) {
       timing_mode = cur;
@@ -274,7 +263,7 @@
 DisplayError HWHDMI::SetDisplayAttributes(uint32_t index) {
   DTRACE_SCOPED();
 
-  if (index > hdmi_mode_count_) {
+  if (index > hdmi_modes_.size()) {
     return kErrorNotSupported;
   }
 
@@ -291,7 +280,7 @@
         vscreeninfo.upper_margin, vscreeninfo.pixclock/1000000);
 
   msm_hdmi_mode_timing_info *timing_mode = &supported_video_modes_[0];
-  for (uint32_t i = 0; i < hdmi_mode_count_; i++) {
+  for (uint32_t i = 0; i < hdmi_modes_.size(); i++) {
     msm_hdmi_mode_timing_info *cur = &supported_video_modes_[i];
     if (cur->video_format == hdmi_modes_[index]) {
       timing_mode = cur;
@@ -345,7 +334,7 @@
 
 DisplayError HWHDMI::GetConfigIndex(uint32_t mode, uint32_t *index) {
   // Check if the mode is valid and return corresponding index
-  for (uint32_t i = 0; i < hdmi_mode_count_; i++) {
+  for (uint32_t i = 0; i < hdmi_modes_.size(); i++) {
     if (hdmi_modes_[i] == mode) {
       *index = i;
       DLOGI("Index = %d for config = %d", *index, mode);
@@ -371,7 +360,7 @@
 }
 
 DisplayError HWHDMI::GetVideoFormat(uint32_t config_index, uint32_t *video_format) {
-  if (config_index > hdmi_mode_count_) {
+  if (config_index > hdmi_modes_.size()) {
     return kErrorNotSupported;
   }
 
@@ -531,7 +520,7 @@
       break;
     }
 
-    while (info->video_format && size < kPageSize && config_index < hdmi_mode_count_) {
+    while (info->video_format && size < kPageSize && config_index < hdmi_modes_.size()) {
       supported_video_modes_[config_index] = *info;
       size += sizeof(msm_hdmi_mode_timing_info);
 
@@ -601,7 +590,7 @@
   char edid_s3d_path[kMaxStringLength] = {'\0'};
   snprintf(edid_s3d_path, sizeof(edid_s3d_path), "%s%d/edid_3d_modes", fb_path_, fb_node_index_);
 
-  if (index > hdmi_mode_count_) {
+  if (index > hdmi_modes_.size()) {
     return kErrorNotSupported;
   }
 
diff --git a/msm8996/sdm/libs/core/fb/hw_hdmi.h b/msm8996/sdm/libs/core/fb/hw_hdmi.h
index 2845708..d2bd658 100644
--- a/msm8996/sdm/libs/core/fb/hw_hdmi.h
+++ b/msm8996/sdm/libs/core/fb/hw_hdmi.h
@@ -33,6 +33,8 @@
 
 namespace sdm {
 
+using std::vector;
+
 class HWHDMI : public HWDevice {
  public:
   static DisplayError Create(HWInterface **intf, HWInfoInterface *hw_info_intf,
@@ -85,14 +87,13 @@
   bool IsSupportedS3DMode(HWS3DMode s3d_mode);
   void UpdateMixerAttributes();
 
-  uint32_t hdmi_mode_count_;
-  uint32_t hdmi_modes_[256];
+  vector<uint32_t> hdmi_modes_;
   // Holds the hdmi timing information. Ex: resolution, fps etc.,
-  msm_hdmi_mode_timing_info *supported_video_modes_;
+  vector<msm_hdmi_mode_timing_info> supported_video_modes_;
   HWScanInfo hw_scan_info_;
   uint32_t active_config_index_;
   std::map<HWS3DMode, msm_hdmi_s3d_mode> s3d_mode_sdm_to_mdp_;
-  std::vector<HWS3DMode> supported_s3d_modes_;
+  vector<HWS3DMode> supported_s3d_modes_;
   int active_mdp_s3d_mode_ = HDMI_S3D_NONE;
   uint32_t frame_rate_ = 0;
 };
diff --git a/msm8996/sdm/libs/core/fb/hw_info.cpp b/msm8996/sdm/libs/core/fb/hw_info.cpp
index 77d3b6a..dc01e39 100644
--- a/msm8996/sdm/libs/core/fb/hw_info.cpp
+++ b/msm8996/sdm/libs/core/fb/hw_info.cpp
@@ -522,8 +522,10 @@
     DLOGI("First display is internal display");
   }
 
+  fs.close();
   fs.open("/sys/devices/virtual/graphics/fb0/connected", fstream::in);
   if (!fs.is_open()) {
+    // If fb0 is for a DSI/connected panel, then connected node will not exist.
     hw_disp_info->is_connected = true;
   } else {
     if (!Sys::getline_(fs, line)) {
diff --git a/msm8996/sdm/libs/core/fb/hw_primary.cpp b/msm8996/sdm/libs/core/fb/hw_primary.cpp
index d17f670..09e7f80 100644
--- a/msm8996/sdm/libs/core/fb/hw_primary.cpp
+++ b/msm8996/sdm/libs/core/fb/hw_primary.cpp
@@ -102,10 +102,7 @@
     return error;
   }
 
-  uint32_t dest_scalar_count = hw_resource_.hw_dest_scalar_info.count;
-  if (dest_scalar_count) {
-    mdp_dest_scalar_data_ = new mdp_destination_scaler_data[dest_scalar_count];
-  }
+  mdp_dest_scalar_data_.resize(hw_resource_.hw_dest_scalar_info.count);
 
   error = PopulateDisplayAttributes();
   if (error != kErrorNone) {
@@ -192,8 +189,6 @@
 }
 
 DisplayError HWPrimary::Deinit() {
-  delete [] mdp_dest_scalar_data_;
-
   return HWDevice::Deinit();
 }
 
diff --git a/msm8996/sdm/libs/core/resource_default.cpp b/msm8996/sdm/libs/core/resource_default.cpp
index c5907be..4fc3ce4 100644
--- a/msm8996/sdm/libs/core/resource_default.cpp
+++ b/msm8996/sdm/libs/core/resource_default.cpp
@@ -47,7 +47,7 @@
     return kErrorParameters;
   }
 
-  src_pipes_ = new SourcePipe[num_pipe_];
+  src_pipes_.resize(num_pipe_);
   hw_res_info_ = hw_res_info;
 
   // Priority order of pipes: VIG, RGB, DMA
@@ -100,7 +100,6 @@
 }
 
 DisplayError ResourceDefault::Deinit() {
-  delete[] src_pipes_;
   return kErrorNone;
 }
 
diff --git a/msm8996/sdm/libs/core/resource_default.h b/msm8996/sdm/libs/core/resource_default.h
index b57ce94..79e7dcd 100644
--- a/msm8996/sdm/libs/core/resource_default.h
+++ b/msm8996/sdm/libs/core/resource_default.h
@@ -28,6 +28,7 @@
 #include <core/display_interface.h>
 #include <private/resource_interface.h>
 #include <utils/locker.h>
+#include <vector>
 
 #include "hw_interface.h"
 
@@ -132,7 +133,7 @@
   Locker locker_;
   HWResourceInfo hw_res_info_;
   HWBlockContext hw_block_ctx_[kHWBlockMax];
-  SourcePipe *src_pipes_ = NULL;
+  std::vector<SourcePipe> src_pipes_;
   uint32_t num_pipe_ = 0;
 };
 
diff --git a/msm8996/sdm/libs/hwc/hwc_display_primary.cpp b/msm8996/sdm/libs/hwc/hwc_display_primary.cpp
index f92ab43..f4775b1 100644
--- a/msm8996/sdm/libs/hwc/hwc_display_primary.cpp
+++ b/msm8996/sdm/libs/hwc/hwc_display_primary.cpp
@@ -86,15 +86,11 @@
                                      hwc_procs_t const **hwc_procs,
                                      qService::QService *qservice)
   : HWCDisplay(core_intf, hwc_procs, kPrimary, HWC_DISPLAY_PRIMARY, true, qservice,
-               DISPLAY_CLASS_PRIMARY), buffer_allocator_(buffer_allocator), cpu_hint_(NULL) {
+               DISPLAY_CLASS_PRIMARY), buffer_allocator_(buffer_allocator) {
 }
 
 int HWCDisplayPrimary::Init() {
-  cpu_hint_ = new CPUHint();
-  if (cpu_hint_->Init(static_cast<HWCDebugHandler*>(HWCDebugHandler::Get())) != kErrorNone) {
-    delete cpu_hint_;
-    cpu_hint_ = NULL;
-  }
+  cpu_hint_.Init(static_cast<HWCDebugHandler*>(HWCDebugHandler::Get()));
 
   use_metadata_refresh_rate_ = true;
   int disable_metadata_dynfps = 0;
@@ -289,14 +285,10 @@
 }
 
 void HWCDisplayPrimary::ToggleCPUHint(bool set) {
-  if (!cpu_hint_) {
-    return;
-  }
-
   if (set) {
-    cpu_hint_->Set();
+    cpu_hint_.Set();
   } else {
-    cpu_hint_->Reset();
+    cpu_hint_.Reset();
   }
 }
 
diff --git a/msm8996/sdm/libs/hwc/hwc_display_primary.h b/msm8996/sdm/libs/hwc/hwc_display_primary.h
index 81e510f..f25a877 100644
--- a/msm8996/sdm/libs/hwc/hwc_display_primary.h
+++ b/msm8996/sdm/libs/hwc/hwc_display_primary.h
@@ -74,7 +74,7 @@
   DisplayError GetMixerResolution(uint32_t *width, uint32_t *height);
 
   BufferAllocator *buffer_allocator_ = nullptr;
-  CPUHint *cpu_hint_ = nullptr;
+  CPUHint cpu_hint_;
   bool handle_idle_timeout_ = false;
 
   // Primary output buffer configuration
diff --git a/msm8996/sdm/libs/hwc/hwc_session.cpp b/msm8996/sdm/libs/hwc/hwc_session.cpp
index 8a6787a..95da143 100644
--- a/msm8996/sdm/libs/hwc/hwc_session.cpp
+++ b/msm8996/sdm/libs/hwc/hwc_session.cpp
@@ -129,20 +129,8 @@
     return -EINVAL;
   }
 
-  buffer_allocator_ = new HWCBufferAllocator();
-  if (buffer_allocator_ == NULL) {
-    DLOGE("Display core initialization failed due to no memory");
-    return -ENOMEM;
-  }
-
-  buffer_sync_handler_ = new HWCBufferSyncHandler();
-  if (buffer_sync_handler_ == NULL) {
-    DLOGE("Display core initialization failed due to no memory");
-    return -ENOMEM;
-  }
-
-  DisplayError error = CoreInterface::CreateCore(HWCDebugHandler::Get(), buffer_allocator_,
-                                                 buffer_sync_handler_, &core_intf_);
+  DisplayError error = CoreInterface::CreateCore(HWCDebugHandler::Get(), &buffer_allocator_,
+                                                 &buffer_sync_handler_, &core_intf_);
   if (error != kErrorNone) {
     DLOGE("Display core initialization failed. Error = %d", error);
     return -EINVAL;
@@ -169,12 +157,12 @@
       }
     } else {
       // Create and power on primary display
-      status = HWCDisplayPrimary::Create(core_intf_, buffer_allocator_, &hwc_procs_, qservice_,
+      status = HWCDisplayPrimary::Create(core_intf_, &buffer_allocator_, &hwc_procs_, qservice_,
                                          &hwc_display_[HWC_DISPLAY_PRIMARY]);
     }
   } else {
     // Create and power on primary display
-    status = HWCDisplayPrimary::Create(core_intf_, buffer_allocator_, &hwc_procs_, qservice_,
+    status = HWCDisplayPrimary::Create(core_intf_, &buffer_allocator_, &hwc_procs_, qservice_,
                                        &hwc_display_[HWC_DISPLAY_PRIMARY]);
   }
 
diff --git a/msm8996/sdm/libs/hwc/hwc_session.h b/msm8996/sdm/libs/hwc/hwc_session.h
index 2bdae2b..2a732b2 100644
--- a/msm8996/sdm/libs/hwc/hwc_session.h
+++ b/msm8996/sdm/libs/hwc/hwc_session.h
@@ -133,8 +133,8 @@
   pthread_t uevent_thread_;
   bool uevent_thread_exit_ = false;
   const char *uevent_thread_name_ = "HWC_UeventThread";
-  HWCBufferAllocator *buffer_allocator_ = NULL;
-  HWCBufferSyncHandler *buffer_sync_handler_ = NULL;
+  HWCBufferAllocator buffer_allocator_;
+  HWCBufferSyncHandler buffer_sync_handler_;
   HWCColorManager *color_mgr_ = NULL;
   bool reset_panel_ = false;
   bool secure_display_active_ = false;
diff --git a/msm8996/sdm/libs/hwc2/hwc_session.cpp b/msm8996/sdm/libs/hwc2/hwc_session.cpp
index 91e57c5..9344ed6 100644
--- a/msm8996/sdm/libs/hwc2/hwc_session.cpp
+++ b/msm8996/sdm/libs/hwc2/hwc_session.cpp
@@ -94,20 +94,8 @@
     return -EINVAL;
   }
 
-  buffer_allocator_ = new HWCBufferAllocator();
-  if (buffer_allocator_ == NULL) {
-    DLOGE("Display core initialization failed due to no memory");
-    return -ENOMEM;
-  }
-
-  buffer_sync_handler_ = new HWCBufferSyncHandler();
-  if (buffer_sync_handler_ == NULL) {
-    DLOGE("Display core initialization failed due to no memory");
-    return -ENOMEM;
-  }
-
-  DisplayError error = CoreInterface::CreateCore(HWCDebugHandler::Get(), buffer_allocator_,
-                                                 buffer_sync_handler_, &core_intf_);
+  DisplayError error = CoreInterface::CreateCore(HWCDebugHandler::Get(), &buffer_allocator_,
+                                                 &buffer_sync_handler_, &core_intf_);
   if (error != kErrorNone) {
     DLOGE("Display core initialization failed. Error = %d", error);
     return -EINVAL;
@@ -125,7 +113,7 @@
                                         &hwc_display_[HWC_DISPLAY_PRIMARY]);
   } else {
     // Create and power on primary display
-    status = HWCDisplayPrimary::Create(core_intf_, buffer_allocator_, &callbacks_, qservice_,
+    status = HWCDisplayPrimary::Create(core_intf_, &buffer_allocator_, &callbacks_, qservice_,
                                        &hwc_display_[HWC_DISPLAY_PRIMARY]);
   }
 
diff --git a/msm8996/sdm/libs/hwc2/hwc_session.h b/msm8996/sdm/libs/hwc2/hwc_session.h
index 6af9da5..ce3e27f 100644
--- a/msm8996/sdm/libs/hwc2/hwc_session.h
+++ b/msm8996/sdm/libs/hwc2/hwc_session.h
@@ -175,8 +175,8 @@
   pthread_t uevent_thread_;
   bool uevent_thread_exit_ = false;
   const char *uevent_thread_name_ = "HWC_UeventThread";
-  HWCBufferAllocator *buffer_allocator_ = NULL;
-  HWCBufferSyncHandler *buffer_sync_handler_ = NULL;
+  HWCBufferAllocator buffer_allocator_;
+  HWCBufferSyncHandler buffer_sync_handler_;
   HWCColorManager *color_mgr_ = NULL;
   bool reset_panel_ = false;
   bool secure_display_active_ = false;