Merge "display: Update new qdcm xml file on trinket"
diff --git a/config/display-board.mk b/config/display-board.mk
index 6f7a86a..854564a 100644
--- a/config/display-board.mk
+++ b/config/display-board.mk
@@ -15,4 +15,5 @@
 TARGET_USES_DISPLAY_RENDER_INTENTS := true
 TARGET_USE_COLOR_MANAGEMENT := true
 SF_WCG_COMPOSITION_DATA_SPACE := 143261696
+TARGET_USES_QTI_MAPPER_1_1 := true
 
diff --git a/config/display-product.mk b/config/display-product.mk
index 6a58da0..99930b5 100644
--- a/config/display-product.mk
+++ b/config/display-product.mk
@@ -8,10 +8,10 @@
     android.hardware.memtrack@1.0-service \
     android.hardware.light@2.0-impl \
     android.hardware.light@2.0-service \
-    gralloc.qcom \
-    lights.qcom \
-    hwcomposer.qcom \
-    memtrack.qcom \
+    gralloc.$(TARGET_BOARD_PLATFORM) \
+    lights.$(TARGET_BOARD_PLATFORM) \
+    hwcomposer.$(TARGET_BOARD_PLATFORM) \
+    memtrack.$(TARGET_BOARD_PLATFORM) \
     libqdMetaData.vendor \
     vendor.display.config@1.0.vendor \
     vendor.display.config@1.1.vendor \
@@ -19,6 +19,9 @@
     vendor.display.config@1.3.vendor \
     vendor.display.config@1.4.vendor \
     vendor.display.config@1.5.vendor \
+    vendor.display.config@1.6.vendor \
+    vendor.display.config@1.7.vendor \
+    vendor.display.config@1.8.vendor \
     modetest
 
 #QDCM calibration xml file for 2k panel
diff --git a/config/talos.mk b/config/talos.mk
index 6fa1360..48a2237 100644
--- a/config/talos.mk
+++ b/config/talos.mk
@@ -9,10 +9,10 @@
     android.hardware.memtrack@1.0-service \
     android.hardware.light@2.0-impl \
     android.hardware.light@2.0-service \
-    gralloc.qcom \
-    lights.qcom \
-    hwcomposer.qcom \
-    memtrack.qcom \
+    gralloc.talos \
+    lights.talos \
+    hwcomposer.talos \
+    memtrack.talos \
     libqdutils \
     libqdMetaData \
     libqdMetaData.system \
@@ -49,6 +49,7 @@
 TARGET_USES_QCOM_DISPLAY_BSP := true
 TARGET_USES_COLOR_METADATA := true
 TARGET_USES_DISPLAY_RENDER_INTENTS := true
+TARGET_USES_QTI_MAPPER_1_1 := true
 
 PRODUCT_PROPERTY_OVERRIDES += \
     persist.demo.hdmirotationlock=false \
diff --git a/config/trinket.mk b/config/trinket.mk
index 8af56ac..cfcba97 100644
--- a/config/trinket.mk
+++ b/config/trinket.mk
@@ -9,10 +9,10 @@
     android.hardware.memtrack@1.0-service \
     android.hardware.light@2.0-impl \
     android.hardware.light@2.0-service \
-    gralloc.qcom \
-    lights.qcom \
-    hwcomposer.qcom \
-    memtrack.qcom \
+    gralloc.trinket \
+    lights.trinket \
+    hwcomposer.trinket \
+    memtrack.trinket \
     libqdutils \
     libqdMetaData \
     libqdMetaData.system \
diff --git a/gralloc/Android.mk b/gralloc/Android.mk
index 400b245..9dc043f 100644
--- a/gralloc/Android.mk
+++ b/gralloc/Android.mk
@@ -3,7 +3,7 @@
 include $(LOCAL_PATH)/../common.mk
 include $(CLEAR_VARS)
 
-LOCAL_MODULE                  := gralloc.qcom
+LOCAL_MODULE                  := gralloc.$(TARGET_BOARD_PLATFORM)
 LOCAL_VENDOR_MODULE           := true
 LOCAL_MODULE_RELATIVE_PATH    := hw
 LOCAL_MODULE_TAGS             := optional
@@ -53,6 +53,10 @@
 LOCAL_SRC_FILES               := gr_allocator.cpp gr_buf_mgr.cpp gr_ion_alloc.cpp
 include $(BUILD_SHARED_LIBRARY)
 
+#Get the display mapper version available
+qti_mapper1_1_version := $(shell \
+    if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/mapper/1.1" ];\
+    then echo QTI_MAPPER_1_1; fi)
 
 qti_mapper_version := $(shell \
     if [ -d "$(TOP)/vendor/qcom/opensource/interfaces/display/mapper/1.0" ];\
@@ -82,6 +86,10 @@
                                   android.hardware.graphics.mapper@2.0 \
                                   android.hardware.graphics.mapper@2.1
 LOCAL_CFLAGS                  := $(common_flags) -DLOG_TAG=\"qdgralloc\" -Wno-sign-conversion
+ifeq ($(qti_mapper1_1_version), QTI_MAPPER_1_1)
+LOCAL_SHARED_LIBRARIES        += vendor.qti.hardware.display.mapper@1.1
+LOCAL_CFLAGS                  += -DQTI_MAPPER_1_1
+endif
 LOCAL_ADDITIONAL_DEPENDENCIES := $(common_deps)
 LOCAL_SRC_FILES               := QtiMapper.cpp
 include $(BUILD_SHARED_LIBRARY)
diff --git a/gralloc/QtiMapper.cpp b/gralloc/QtiMapper.cpp
index a885a7b..dc1b40c 100644
--- a/gralloc/QtiMapper.cpp
+++ b/gralloc/QtiMapper.cpp
@@ -40,7 +40,6 @@
 namespace hardware {
 namespace display {
 namespace mapper {
-namespace V1_0 {
 namespace implementation {
 
 using gralloc::BufferInfo;
@@ -393,6 +392,152 @@
   return err;
 }
 
+#ifdef QTI_MAPPER_1_1
+Return<void> QtiMapper::getFd(void *buffer, getFd_cb hidl_cb) {
+  auto err = Error::BAD_BUFFER;
+  int fd = 0;
+  auto hnd = static_cast<private_handle_t *>(buffer);
+  if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
+    err = Error::NONE;
+    fd = hnd->fd;
+  }
+  hidl_cb(err, fd);
+  return Void();
+}
+
+Return<void> QtiMapper::getWidth(void *buffer, getWidth_cb hidl_cb) {
+  auto err = Error::BAD_BUFFER;
+  int width = 0;
+  auto hnd = static_cast<private_handle_t *>(buffer);
+  if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
+    err = Error::NONE;
+    width = hnd->width;
+  }
+  hidl_cb(err, width);
+  return Void();
+}
+
+Return<void> QtiMapper::getHeight(void *buffer, getHeight_cb hidl_cb) {
+  auto err = Error::BAD_BUFFER;
+  int height = 0;
+  auto hnd = static_cast<private_handle_t *>(buffer);
+  if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
+    err = Error::NONE;
+    height = hnd->height;
+  }
+  hidl_cb(err, height);
+  return Void();
+}
+
+Return<void> QtiMapper::getFormat(void *buffer, getFormat_cb hidl_cb) {
+  auto err = Error::BAD_BUFFER;
+  int format = 0;
+  auto hnd = static_cast<private_handle_t *>(buffer);
+  if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
+    err = Error::NONE;
+    format = hnd->format;
+  }
+  hidl_cb(err, format);
+  return Void();
+}
+
+Return<void> QtiMapper::getPrivateFlags(void *buffer, getPrivateFlags_cb hidl_cb) {
+  auto err = Error::BAD_BUFFER;
+  int flags = 0;
+  auto hnd = static_cast<private_handle_t *>(buffer);
+  if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
+    err = Error::NONE;
+    flags = hnd->flags;
+  }
+  hidl_cb(err, flags);
+  return Void();
+}
+
+Return<void> QtiMapper::getUnalignedWidth(void *buffer, getUnalignedWidth_cb hidl_cb) {
+  auto err = Error::BAD_BUFFER;
+  int unaligned_width = 0;
+  auto hnd = static_cast<private_handle_t *>(buffer);
+  if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
+    err = Error::NONE;
+    unaligned_width = hnd->unaligned_width;
+  }
+  hidl_cb(err, unaligned_width);
+  return Void();
+}
+
+Return<void> QtiMapper::getUnalignedHeight(void *buffer, getUnalignedHeight_cb hidl_cb) {
+  auto err = Error::BAD_BUFFER;
+  int unaligned_height = 0;
+  auto hnd = static_cast<private_handle_t *>(buffer);
+  if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
+    err = Error::NONE;
+    unaligned_height = hnd->unaligned_height;
+  }
+  hidl_cb(err, unaligned_height);
+  return Void();
+}
+
+Return<void> QtiMapper::getLayerCount(void *buffer, getLayerCount_cb hidl_cb) {
+  auto err = Error::BAD_BUFFER;
+  unsigned int layer_count = 0;
+  auto hnd = static_cast<private_handle_t *>(buffer);
+  if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
+    err = Error::NONE;
+    layer_count = hnd->layer_count;
+  }
+  hidl_cb(err, layer_count);
+  return Void();
+}
+
+Return<void> QtiMapper::getId(void *buffer, getId_cb hidl_cb) {
+  auto err = Error::BAD_BUFFER;
+  uint64_t id = 0;
+  auto hnd = static_cast<private_handle_t *>(buffer);
+  if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
+    err = Error::NONE;
+    id = hnd->id;
+  }
+  hidl_cb(err, id);
+  return Void();
+}
+
+Return<void> QtiMapper::getUsageFlags(void *buffer, getUsageFlags_cb hidl_cb) {
+  auto err = Error::BAD_BUFFER;
+  uint64_t usage = 0;
+  auto hnd = static_cast<private_handle_t *>(buffer);
+  if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
+    err = Error::NONE;
+    usage = hnd->usage;
+  }
+  hidl_cb(err, usage);
+  return Void();
+}
+
+Return<void> QtiMapper::getSize(void *buffer, getSize_cb hidl_cb) {
+  auto err = Error::BAD_BUFFER;
+  unsigned int size = 0;
+  auto hnd = static_cast<private_handle_t *>(buffer);
+  if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
+    err = Error::NONE;
+    size = hnd->size;
+  }
+  hidl_cb(err, size);
+  return Void();
+}
+
+Return<void> QtiMapper::getOffset(void *buffer, getOffset_cb hidl_cb) {
+  auto err = Error::BAD_BUFFER;
+  unsigned int offset = 0;
+  auto hnd = static_cast<private_handle_t *>(buffer);
+  if (buffer != nullptr && private_handle_t::validate(hnd) == 0) {
+    err = Error::NONE;
+    offset = hnd->offset;
+  }
+  hidl_cb(err, offset);
+  return Void();
+}
+#endif
+
 // Methods from ::android::hidl::base::V1_0::IBase follow.
 
 // When we are in passthrough mode, this method is used
@@ -409,7 +554,6 @@
 }
 
 }  // namespace implementation
-}  // namespace V1_0
 }  // namespace mapper
 }  // namespace display
 }  // namespace hardware
diff --git a/gralloc/QtiMapper.h b/gralloc/QtiMapper.h
index b132a67..a17870c 100644
--- a/gralloc/QtiMapper.h
+++ b/gralloc/QtiMapper.h
@@ -32,7 +32,11 @@
 
 #include <hidl/MQDescriptor.h>
 #include <hidl/Status.h>
+#ifdef QTI_MAPPER_1_1
+#include <vendor/qti/hardware/display/mapper/1.1/IQtiMapper.h>
+#else
 #include <vendor/qti/hardware/display/mapper/1.0/IQtiMapper.h>
+#endif
 
 #include "gr_buf_mgr.h"
 namespace vendor {
@@ -40,7 +44,6 @@
 namespace hardware {
 namespace display {
 namespace mapper {
-namespace V1_0 {
 namespace implementation {
 
 using ::android::hardware::Return;
@@ -57,7 +60,11 @@
 using ::android::hidl::base::V1_0::DebugInfo;
 using ::android::hidl::base::V1_0::IBase;
 using ::android::sp;
+#ifdef QTI_MAPPER_1_1
+using ::vendor::qti::hardware::display::mapper::V1_1::IQtiMapper;
+#else
 using ::vendor::qti::hardware::display::mapper::V1_0::IQtiMapper;
+#endif
 using gralloc::BufferManager;
 
 using IMapper_2_1 = android::hardware::graphics::mapper::V2_1::IMapper;
@@ -101,6 +108,22 @@
   Return<void> getYuvPlaneInfo(void *buffer, getYuvPlaneInfo_cb _hidl_cb) override;
   Return<Error> setSingleBufferMode(void *buffer, bool enable) override;
 
+#ifdef QTI_MAPPER_1_1
+  // Getters for fields present in private handle structure.
+  Return<void> getFd(void *buffer, getFd_cb _hidl_cb) override;
+  Return<void> getWidth(void *buffer, getWidth_cb _hidl_cb) override;
+  Return<void> getHeight(void *buffer, getHeight_cb _hidl_cb) override;
+  Return<void> getOffset(void *buffer, getOffset_cb _hidl_cb) override;
+  Return<void> getSize(void *buffer, getSize_cb _hidl_cb) override;
+  Return<void> getFormat(void *buffer, getFormat_cb _hidl_cb) override;
+  Return<void> getPrivateFlags(void *buffer, getPrivateFlags_cb _hidl_cb) override;
+  Return<void> getUnalignedWidth(void *buffer, getUnalignedWidth_cb _hidl_cb) override;
+  Return<void> getUnalignedHeight(void *buffer, getUnalignedHeight_cb _hidl_cb) override;
+  Return<void> getLayerCount(void *buffer, getLayerCount_cb _hidl_cb) override;
+  Return<void> getId(void *buffer, getId_cb _hidl_cb) override;
+  Return<void> getUsageFlags(void *buffer, getUsageFlags_cb _hidl_cb) override;
+#endif
+
  private:
   BufferManager *buf_mgr_ = nullptr;
   Error CreateDescriptor(const BufferDescriptorInfo_2_1& descriptor_info,
@@ -115,7 +138,6 @@
 extern "C" IQtiMapper *HIDL_FETCH_IQtiMapper(const char *name);
 
 }  // namespace implementation
-}  // namespace V1_0
 }  // namespace mapper
 }  // namespace display
 }  // namespace hardware
diff --git a/hdmi_cec/Android.mk b/hdmi_cec/Android.mk
index 45bc9f7..a333654 100644
--- a/hdmi_cec/Android.mk
+++ b/hdmi_cec/Android.mk
@@ -2,7 +2,7 @@
 include $(LOCAL_PATH)/../common.mk
 include $(CLEAR_VARS)
 
-LOCAL_MODULE                  := hdmi_cec.qcom
+LOCAL_MODULE                  := hdmi_cec.$(TARGET_BOARD_PLATFORM)
 LOCAL_VENDOR_MODULE           := true
 LOCAL_MODULE_RELATIVE_PATH    := hw
 LOCAL_MODULE_TAGS             := optional
diff --git a/liblight/Android.mk b/liblight/Android.mk
index cefd9fd..d7060c8 100644
--- a/liblight/Android.mk
+++ b/liblight/Android.mk
@@ -26,7 +26,7 @@
     LOCAL_CFLAGS += --compile-and-analyze --analyzer-perf --analyzer-Werror
 endif
 LOCAL_CLANG  := true
-LOCAL_MODULE := lights.qcom
+LOCAL_MODULE := lights.$(TARGET_BOARD_PLATFORM)
 LOCAL_MODULE_TAGS := optional
 LOCAL_VENDOR_MODULE := true
 
diff --git a/libmemtrack/Android.mk b/libmemtrack/Android.mk
index 683666b..10fd40a 100644
--- a/libmemtrack/Android.mk
+++ b/libmemtrack/Android.mk
@@ -26,5 +26,5 @@
 LOCAL_SHARED_LIBRARIES := liblog
 LOCAL_HEADER_LIBRARIES := libhardware_headers
 LOCAL_SRC_FILES := memtrack_msm.c kgsl.c
-LOCAL_MODULE := memtrack.qcom
+LOCAL_MODULE := memtrack.$(TARGET_BOARD_PLATFORM)
 include $(BUILD_SHARED_LIBRARY)
diff --git a/sdm/include/private/hw_info_types.h b/sdm/include/private/hw_info_types.h
index 2973f54..a161a5d 100644
--- a/sdm/include/private/hw_info_types.h
+++ b/sdm/include/private/hw_info_types.h
@@ -670,12 +670,18 @@
   uint32_t rot_clock_hz = 0;
 };
 
+enum UpdateType {
+  kUpdateResources,  // Indicates Strategy & RM execution, which can update resources.
+  kUpdateMax,
+};
+
 struct HWLayers {
   HWLayersInfo info {};
   HWLayerConfig config[kMaxSDELayers] {};
   float output_compression = 1.0f;
   HWQosData qos_data = {};
   HWAVRInfo hw_avr_info = {};
+  std::bitset<kUpdateMax> updates_mask = 0;
 };
 
 struct HWDisplayAttributes : DisplayConfigVariableInfo {
diff --git a/sdm/libs/core/comp_manager.cpp b/sdm/libs/core/comp_manager.cpp
index eadb497..325d7f5 100644
--- a/sdm/libs/core/comp_manager.cpp
+++ b/sdm/libs/core/comp_manager.cpp
@@ -193,6 +193,7 @@
                                              const DisplayConfigVariableInfo &fb_config,
                                              uint32_t *default_clk_hz) {
   SCOPE_LOCK(locker_);
+  DTRACE_SCOPED();
 
   DisplayError error = kErrorNone;
   DisplayCompositionContext *display_comp_ctx =
@@ -285,6 +286,7 @@
 DisplayError CompManager::Prepare(Handle display_ctx, HWLayers *hw_layers) {
   SCOPE_LOCK(locker_);
 
+  DTRACE_SCOPED();
   DisplayCompositionContext *display_comp_ctx =
                              reinterpret_cast<DisplayCompositionContext *>(display_ctx);
   Handle &display_resource_ctx = display_comp_ctx->display_resource_ctx;
@@ -353,6 +355,7 @@
 DisplayError CompManager::ReConfigure(Handle display_ctx, HWLayers *hw_layers) {
   SCOPE_LOCK(locker_);
 
+  DTRACE_SCOPED();
   DisplayCompositionContext *display_comp_ctx =
                              reinterpret_cast<DisplayCompositionContext *>(display_ctx);
   Handle &display_resource_ctx = display_comp_ctx->display_resource_ctx;
diff --git a/sdm/libs/core/display_base.cpp b/sdm/libs/core/display_base.cpp
index 5a94374..d5879da 100644
--- a/sdm/libs/core/display_base.cpp
+++ b/sdm/libs/core/display_base.cpp
@@ -283,6 +283,7 @@
   DisplayError error = kErrorNone;
   needs_validate_ = true;
 
+  DTRACE_SCOPED();
   if (!active_) {
     return kErrorPermission;
   }
@@ -308,6 +309,7 @@
     disable_pu_one_frame_ = false;
   }
 
+  hw_layers_.updates_mask.set(kUpdateResources);
   comp_manager_->PrePrepare(display_comp_ctx_, &hw_layers_);
   while (true) {
     error = comp_manager_->Prepare(display_comp_ctx_, &hw_layers_);
@@ -1116,6 +1118,8 @@
   HWPanelInfo hw_panel_info;
   uint32_t active_index = 0;
 
+  DTRACE_SCOPED();
+
   error = hw_intf_->GetActiveConfig(&active_index);
   if (error != kErrorNone) {
     return error;
@@ -1202,6 +1206,7 @@
   lock_guard<recursive_mutex> obj(recursive_mutex_);
   DisplayError error = kErrorNone;
 
+  DTRACE_SCOPED();
   if (!width || !height) {
     return kErrorParameters;
   }
diff --git a/sdm/libs/core/display_builtin.cpp b/sdm/libs/core/display_builtin.cpp
index c8496ac..82a5725 100644
--- a/sdm/libs/core/display_builtin.cpp
+++ b/sdm/libs/core/display_builtin.cpp
@@ -128,6 +128,7 @@
   uint32_t display_width = display_attributes_.x_pixels;
   uint32_t display_height = display_attributes_.y_pixels;
 
+  DTRACE_SCOPED();
   if (NeedsMixerReconfiguration(layer_stack, &new_mixer_width, &new_mixer_height)) {
     error = ReconfigureMixer(new_mixer_width, new_mixer_height);
     if (error != kErrorNone) {
@@ -147,6 +148,8 @@
   DisplayError error = kErrorNone;
   uint32_t app_layer_count = hw_layers_.info.app_layer_count;
 
+  DTRACE_SCOPED();
+
   // Enabling auto refresh is async and needs to happen before commit ioctl
   if (hw_panel_info_.mode == kModeCommand) {
     bool enable = (app_layer_count == 1) && layer_stack->flags.single_buffered_layer_present;
diff --git a/sdm/libs/core/drm/hw_device_drm.cpp b/sdm/libs/core/drm/hw_device_drm.cpp
index 1f8e65a..2bc627f 100644
--- a/sdm/libs/core/drm/hw_device_drm.cpp
+++ b/sdm/libs/core/drm/hw_device_drm.cpp
@@ -983,6 +983,7 @@
     return;
   }
 
+  DTRACE_SCOPED();
   HWLayersInfo &hw_layer_info = hw_layers->info;
   uint32_t hw_layer_count = UINT32(hw_layer_info.hw_layers.size());
   HWQosData &qos_data = hw_layers->qos_data;
@@ -992,9 +993,11 @@
   uint64_t current_bit_clk = connector_info_.modes[index].bit_clk_rate;
 
   solid_fills_.clear();
+  bool resource_update = hw_layers->updates_mask.test(kUpdateResources);
+  bool update_config = resource_update || hw_layer_info.stack->flags.geometry_changed;
 
   // TODO(user): Once destination scalar is enabled we can always send ROIs if driver allows
-  if (hw_panel_info_.partial_update) {
+  if (hw_panel_info_.partial_update && update_config) {
     const int kNumMaxROIs = 4;
     DRMRect crtc_rects[kNumMaxROIs] = {{0, 0, mixer_attributes_.width, mixer_attributes_.height}};
     DRMRect conn_rects[kNumMaxROIs] = {{0, 0, display_attributes_[index].x_pixels,
@@ -1048,84 +1051,103 @@
 
       if (pipe_info->valid && fb_id) {
         uint32_t pipe_id = pipe_info->pipe_id;
-        drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ALPHA, pipe_id, layer.plane_alpha);
 
-        drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ZORDER, pipe_id, pipe_info->z_order);
-        DRMBlendType blending = {};
-        SetBlending(layer.blending, &blending);
-        drm_atomic_intf_->Perform(DRMOps::PLANE_SET_BLEND_TYPE, pipe_id, blending);
-        DRMRect src = {};
-        SetRect(pipe_info->src_roi, &src);
-        drm_atomic_intf_->Perform(DRMOps::PLANE_SET_SRC_RECT, pipe_id, src);
-        DRMRect rot_dst = {0, 0, 0, 0};
-        if (hw_rotator_session->mode == kRotatorInline && hw_rotate_info->valid) {
-          SetRect(hw_rotate_info->dst_roi, &rot_dst);
-          drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ROTATION_DST_RECT, pipe_id, rot_dst);
-          if (hw_rotator_session->output_buffer.planes[0].fd >= 0) {
-            uint32_t rot_fb_id = registry_.GetFbId(&layer,
-                                                   hw_rotator_session->output_buffer.handle_id);
-            if (rot_fb_id) {
-              drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ROT_FB_ID, pipe_id, rot_fb_id);
+        if (update_config) {
+          drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ALPHA, pipe_id, layer.plane_alpha);
+
+          drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ZORDER, pipe_id, pipe_info->z_order);
+
+          DRMBlendType blending = {};
+          SetBlending(layer.blending, &blending);
+          drm_atomic_intf_->Perform(DRMOps::PLANE_SET_BLEND_TYPE, pipe_id, blending);
+
+          DRMRect src = {};
+          SetRect(pipe_info->src_roi, &src);
+          drm_atomic_intf_->Perform(DRMOps::PLANE_SET_SRC_RECT, pipe_id, src);
+
+          DRMRect rot_dst = {0, 0, 0, 0};
+          if (hw_rotator_session->mode == kRotatorInline && hw_rotate_info->valid) {
+            SetRect(hw_rotate_info->dst_roi, &rot_dst);
+            drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ROTATION_DST_RECT, pipe_id, rot_dst);
+            if (hw_rotator_session->output_buffer.planes[0].fd >= 0) {
+              uint32_t rot_fb_id = registry_.GetFbId(&layer,
+                                                     hw_rotator_session->output_buffer.handle_id);
+              if (rot_fb_id) {
+                drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ROT_FB_ID, pipe_id, rot_fb_id);
+              }
             }
           }
-        }
-        DRMRect dst = {};
-        SetRect(pipe_info->dst_roi, &dst);
-        drm_atomic_intf_->Perform(DRMOps::PLANE_SET_DST_RECT, pipe_id, dst);
-        DRMRect excl = {};
-        SetRect(pipe_info->excl_rect, &excl);
-        drm_atomic_intf_->Perform(DRMOps::PLANE_SET_EXCL_RECT, pipe_id, excl);
-        uint32_t rot_bit_mask = 0;
-        SetRotation(layer.transform, hw_rotator_session->mode, &rot_bit_mask);
-        drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ROTATION, pipe_id, rot_bit_mask);
-        drm_atomic_intf_->Perform(DRMOps::PLANE_SET_H_DECIMATION, pipe_id,
-                                  pipe_info->horizontal_decimation);
-        drm_atomic_intf_->Perform(DRMOps::PLANE_SET_V_DECIMATION, pipe_id,
-                                  pipe_info->vertical_decimation);
 
-        DRMSecureMode fb_secure_mode;
-        DRMSecurityLevel security_level;
-        SetSecureConfig(layer.input_buffer, &fb_secure_mode, &security_level);
-        drm_atomic_intf_->Perform(DRMOps::PLANE_SET_FB_SECURE_MODE, pipe_id, fb_secure_mode);
-        if (security_level > crtc_security_level) {
-          crtc_security_level = security_level;
+          DRMRect dst = {};
+          SetRect(pipe_info->dst_roi, &dst);
+          drm_atomic_intf_->Perform(DRMOps::PLANE_SET_DST_RECT, pipe_id, dst);
+
+          DRMRect excl = {};
+          SetRect(pipe_info->excl_rect, &excl);
+          drm_atomic_intf_->Perform(DRMOps::PLANE_SET_EXCL_RECT, pipe_id, excl);
+
+          uint32_t rot_bit_mask = 0;
+          SetRotation(layer.transform, hw_rotator_session->mode, &rot_bit_mask);
+          drm_atomic_intf_->Perform(DRMOps::PLANE_SET_ROTATION, pipe_id, rot_bit_mask);
+
+          drm_atomic_intf_->Perform(DRMOps::PLANE_SET_H_DECIMATION, pipe_id,
+                                    pipe_info->horizontal_decimation);
+          drm_atomic_intf_->Perform(DRMOps::PLANE_SET_V_DECIMATION, pipe_id,
+                                    pipe_info->vertical_decimation);
+
+          DRMSecureMode fb_secure_mode;
+          DRMSecurityLevel security_level;
+          SetSecureConfig(layer.input_buffer, &fb_secure_mode, &security_level);
+          drm_atomic_intf_->Perform(DRMOps::PLANE_SET_FB_SECURE_MODE, pipe_id, fb_secure_mode);
+          if (security_level > crtc_security_level) {
+            crtc_security_level = security_level;
+          }
+
+          uint32_t config = 0;
+          SetSrcConfig(layer.input_buffer, hw_rotator_session->mode, &config);
+          drm_atomic_intf_->Perform(DRMOps::PLANE_SET_SRC_CONFIG, pipe_id, config);
+
+          if (hw_scale_) {
+            SDEScaler scaler_output = {};
+            hw_scale_->SetScaler(pipe_info->scale_data, &scaler_output);
+            // TODO(user): Remove qseed3 and add version check, then send appropriate scaler object
+            if (hw_resource_.has_qseed3) {
+              drm_atomic_intf_->Perform(DRMOps::PLANE_SET_SCALER_CONFIG, pipe_id,
+                                        reinterpret_cast<uint64_t>(&scaler_output.scaler_v2));
+            }
+          }
+
+          DRMCscType csc_type = DRMCscType::kCscTypeMax;
+          SelectCscType(layer.input_buffer, &csc_type);
+          drm_atomic_intf_->Perform(DRMOps::PLANE_SET_CSC_CONFIG, pipe_id, &csc_type);
+
+          DRMMultiRectMode multirect_mode;
+          SetMultiRectMode(pipe_info->flags, &multirect_mode);
+          drm_atomic_intf_->Perform(DRMOps::PLANE_SET_MULTIRECT_MODE, pipe_id, multirect_mode);
+
+          SetSsppTonemapFeatures(pipe_info);
         }
 
-        uint32_t config = 0;
-        SetSrcConfig(layer.input_buffer, hw_rotator_session->mode, &config);
-        drm_atomic_intf_->Perform(DRMOps::PLANE_SET_SRC_CONFIG, pipe_id, config);;
         drm_atomic_intf_->Perform(DRMOps::PLANE_SET_FB_ID, pipe_id, fb_id);
         drm_atomic_intf_->Perform(DRMOps::PLANE_SET_CRTC, pipe_id, token_.crtc_id);
+
         if (!validate && input_buffer->acquire_fence_fd >= 0) {
           drm_atomic_intf_->Perform(DRMOps::PLANE_SET_INPUT_FENCE, pipe_id,
                                     input_buffer->acquire_fence_fd);
         }
-        if (hw_scale_) {
-          SDEScaler scaler_output = {};
-          hw_scale_->SetScaler(pipe_info->scale_data, &scaler_output);
-          // TODO(user): Remove qseed3 and add version check, then send appropriate scaler object
-          if (hw_resource_.has_qseed3) {
-            drm_atomic_intf_->Perform(DRMOps::PLANE_SET_SCALER_CONFIG, pipe_id,
-                                      reinterpret_cast<uint64_t>(&scaler_output.scaler_v2));
-          }
-        }
-
-        DRMCscType csc_type = DRMCscType::kCscTypeMax;
-        SelectCscType(layer.input_buffer, &csc_type);
-        drm_atomic_intf_->Perform(DRMOps::PLANE_SET_CSC_CONFIG, pipe_id, &csc_type);
-
-        DRMMultiRectMode multirect_mode;
-        SetMultiRectMode(pipe_info->flags, &multirect_mode);
-        drm_atomic_intf_->Perform(DRMOps::PLANE_SET_MULTIRECT_MODE, pipe_id, multirect_mode);
-
-        SetSsppTonemapFeatures(pipe_info);
       }
     }
   }
 
-  SetSolidfillStages();
-  SetQOSData(qos_data);
-  drm_atomic_intf_->Perform(DRMOps::CRTC_SET_SECURITY_LEVEL, token_.crtc_id, crtc_security_level);
+  if (update_config) {
+    SetSolidfillStages();
+    SetQOSData(qos_data);
+    drm_atomic_intf_->Perform(DRMOps::CRTC_SET_SECURITY_LEVEL, token_.crtc_id, crtc_security_level);
+    sde_drm::DRMQsyncMode mode = hw_layers->hw_avr_info.enable ? sde_drm::DRMQsyncMode::CONTINUOUS :
+                                                                 sde_drm::DRMQsyncMode::NONE;
+    drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_QSYNC_MODE, token_.conn_id, mode);
+  }
+
   drm_atomic_intf_->Perform(DRMOps::DPPS_COMMIT_FEATURE, 0 /* argument is not used */);
 
   if (!validate) {
@@ -1192,10 +1214,6 @@
   if (hw_panel_info_.mode == kModeCommand) {
     drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_AUTOREFRESH, token_.conn_id, autorefresh_);
   }
-
-  sde_drm::DRMQsyncMode mode = hw_layers->hw_avr_info.enable ? sde_drm::DRMQsyncMode::CONTINUOUS :
-                                                               sde_drm::DRMQsyncMode::NONE;
-  drm_atomic_intf_->Perform(DRMOps::CONNECTOR_SET_QSYNC_MODE, token_.conn_id, mode);
 }
 
 void HWDeviceDRM::AddSolidfillStage(const HWSolidfillStage &sf, uint32_t plane_alpha) {
@@ -1388,6 +1406,7 @@
 
   first_cycle_ = false;
   update_mode_ = false;
+  hw_layers->updates_mask = 0;
 
   return kErrorNone;
 }
@@ -1525,6 +1544,11 @@
 }
 
 DisplayError HWDeviceDRM::SetPPFeatures(PPFeaturesConfig *feature_list) {
+  if (pending_doze_) {
+    DLOGI("Doze state pending!! Skip for now");
+    return kErrorNone;
+  }
+
   int ret = 0;
   PPFeatureInfo *feature = NULL;
 
diff --git a/sdm/libs/hwc2/Android.mk b/sdm/libs/hwc2/Android.mk
index 9e11411..55feeeb 100644
--- a/sdm/libs/hwc2/Android.mk
+++ b/sdm/libs/hwc2/Android.mk
@@ -4,7 +4,7 @@
 
 ifeq ($(use_hwc2),true)
 
-LOCAL_MODULE                  := hwcomposer.qcom
+LOCAL_MODULE                  := hwcomposer.$(TARGET_BOARD_PLATFORM)
 LOCAL_VENDOR_MODULE           := true
 LOCAL_MODULE_RELATIVE_PATH    := hw
 LOCAL_MODULE_TAGS             := optional
diff --git a/sdm/libs/hwc2/hwc_color_manager.cpp b/sdm/libs/hwc2/hwc_color_manager.cpp
index 5dd6a4b..4fb047f 100644
--- a/sdm/libs/hwc2/hwc_color_manager.cpp
+++ b/sdm/libs/hwc2/hwc_color_manager.cpp
@@ -370,6 +370,7 @@
   int err = -1;
   PPPendingParams pending_action;
   PPDisplayAPIPayload req_payload;
+  DTRACE_SCOPED();
 
   pending_action.action = kGetDetailedEnhancerData;
   pending_action.params = NULL;
diff --git a/sdm/libs/hwc2/hwc_display.cpp b/sdm/libs/hwc2/hwc_display.cpp
index 1d0c8cd..602a57e 100644
--- a/sdm/libs/hwc2/hwc_display.cpp
+++ b/sdm/libs/hwc2/hwc_display.cpp
@@ -678,6 +678,7 @@
   layer_stack_.flags.animating = animating_;
   layer_stack_.flags.fast_path = fast_path_enabled_ && fast_path_composition_;
 
+  DTRACE_SCOPED();
   // Add one layer for fb target
   // TODO(user): Add blit target layers
   for (auto hwc_layer : layer_set_) {
@@ -1173,6 +1174,8 @@
 }
 
 HWC2::Error HWCDisplay::SetActiveConfig(hwc2_config_t config) {
+  DTRACE_SCOPED();
+
   if (SetActiveDisplayConfig(config) != kErrorNone) {
     return HWC2::Error::BadConfig;
   }
@@ -1268,6 +1271,7 @@
   layer_requests_.clear();
   has_client_composition_ = false;
 
+  DTRACE_SCOPED();
   if (shutdown_pending_) {
     validated_ = false;
     return HWC2::Error::BadDisplay;
@@ -1472,6 +1476,8 @@
     return HWC2::Error::None;
   }
 
+  DTRACE_SCOPED();
+
   if (!validated_) {
     DLOGV_IF(kTagClient, "Display %d is not validated", id_);
     return HWC2::Error::NotValidated;
@@ -1592,6 +1598,7 @@
     dump_frame_index_++;
   }
 
+  layer_stack_.flags.geometry_changed = false;
   geometry_changes_ = GeometryChanges::kNone;
   flush_ = false;
 
diff --git a/sdm/libs/hwc2/hwc_display_builtin.cpp b/sdm/libs/hwc2/hwc_display_builtin.cpp
index ce72f3d..6fc0944 100644
--- a/sdm/libs/hwc2/hwc_display_builtin.cpp
+++ b/sdm/libs/hwc2/hwc_display_builtin.cpp
@@ -129,6 +129,7 @@
   auto status = HWC2::Error::None;
   DisplayError error = kErrorNone;
 
+  DTRACE_SCOPED();
   if (display_paused_) {
     MarkLayersForGPUBypass();
     return status;
@@ -193,6 +194,8 @@
 
 HWC2::Error HWCDisplayBuiltIn::Present(int32_t *out_retire_fence) {
   auto status = HWC2::Error::None;
+
+  DTRACE_SCOPED();
   if (display_paused_) {
     DisplayError error = display_intf_->Flush(&layer_stack_);
     validated_ = false;
@@ -769,6 +772,7 @@
     return HWC2::Error::Unsupported;
   }
 
+  validated_ = false;
   return HWC2::Error::None;
 }
 
diff --git a/sdm/libs/hwc2/hwc_session.cpp b/sdm/libs/hwc2/hwc_session.cpp
index 1913553..00444fe 100644
--- a/sdm/libs/hwc2/hwc_session.cpp
+++ b/sdm/libs/hwc2/hwc_session.cpp
@@ -732,10 +732,26 @@
 
   hwc_session->HandlePowerOnPending(display, *out_retire_fence);
   hwc_session->HandleHotplugPending(display, *out_retire_fence);
+  hwc_session->HandlePendingRefresh();
 
   return INT32(status);
 }
 
+void HWCSession::HandlePendingRefresh() {
+  if (pending_refresh_.none()) {
+    return;
+  }
+
+  for (size_t i = 0; i < pending_refresh_.size(); i++) {
+    if (pending_refresh_.test(i)) {
+      Refresh(i);
+    }
+    break;
+  }
+
+  pending_refresh_.reset();
+}
+
 int32_t HWCSession::RegisterCallback(hwc2_device_t *device, int32_t descriptor,
                                      hwc2_callback_data_t callback_data,
                                      hwc2_function_pointer_t pointer) {
@@ -978,6 +994,8 @@
   // Trigger refresh for doze mode to take effect.
   if (mode == HWC2::PowerMode::Doze) {
     hwc_session->Refresh(display);
+    // Trigger one more refresh for PP features to take effect.
+    hwc_session->pending_refresh_.set(UINT32(display));
   }
 
   return HWC2_ERROR_NONE;
@@ -2774,6 +2792,8 @@
 HWC2::Error HWCSession::ValidateDisplayInternal(hwc2_display_t display, uint32_t *out_num_types,
                                                 uint32_t *out_num_requests) {
   HWCDisplay *hwc_display = hwc_display_[display];
+
+  DTRACE_SCOPED();
   if (hwc_display->IsInternalValidateState()) {
     // Internal Validation has already been done on display, get the Output params.
     return hwc_display->GetValidateDisplayOutput(out_num_types, out_num_requests);
@@ -2796,6 +2816,8 @@
 
 HWC2::Error HWCSession::PresentDisplayInternal(hwc2_display_t display, int32_t *out_retire_fence) {
   HWCDisplay *hwc_display = hwc_display_[display];
+
+  DTRACE_SCOPED();
   // If display is in Skip-Validate state and Validate cannot be skipped, do Internal
   // Validation to optimize for the frames which don't require the Client composition.
   if (hwc_display->IsSkipValidateState() && !hwc_display->CanSkipValidate()) {
diff --git a/sdm/libs/hwc2/hwc_session.h b/sdm/libs/hwc2/hwc_session.h
index 97fc019..2db5288 100644
--- a/sdm/libs/hwc2/hwc_session.h
+++ b/sdm/libs/hwc2/hwc_session.h
@@ -401,6 +401,7 @@
   DisplayClass GetDisplayClass(hwc2_display_t display_id);
   bool IsPluggableDisplayConnected();
   hwc2_display_t GetActiveBuiltinDisplay();
+  void HandlePendingRefresh();
 
   CoreInterface *core_intf_ = nullptr;
   HWCDisplay *hwc_display_[kNumDisplays] = {nullptr};
@@ -437,6 +438,7 @@
   int32_t registered_builtin_displays_ = 0;
   int32_t disable_hotplug_bwcheck_ = 0;
   int32_t disable_mask_layer_hint_ = 0;
+  std::bitset<kNumDisplays> pending_refresh_;
 };
 
 }  // namespace sdm