Merge 150d4e700e2e25136eeb3657e4fd647fe2f1946d on remote branch

Change-Id: Ia670a834f3a9d66073c394eee8013e036130ee26
diff --git a/composer/hwc_layers.cpp b/composer/hwc_layers.cpp
index 842269f..b6bdb21 100644
--- a/composer/hwc_layers.cpp
+++ b/composer/hwc_layers.cpp
@@ -1079,6 +1079,9 @@
   if (gralloc::GetMetaDataValue(handle, qtigralloc::MetadataType_LinearFormat.value,
                                 &linear_format) == gralloc::Error::NONE) {
     layer_buffer->format = GetSDMFormat(INT32(linear_format), 0);
+    if (layer_buffer->format == kFormatInvalid) {
+      return kErrorNotSupported;
+    }
   }
 
   if ((interlace != layer_buffer->flags.interlace) || (frame_rate != layer->frame_rate)) {
@@ -1099,6 +1102,9 @@
       gralloc::Error::NONE) {
     // Only copy top layer for now as only top field for interlaced is used
     GetUBWCStatsFromMetaData(&cr_stats[0], &(layer_buffer->ubwc_crstats[0]));
+    if (cr_stats[0].version < 0 || cr_stats[0].version >= UBWC_MAX_VERSION) {
+      return kErrorNotSupported;
+    }
   }
 
   uint32_t single_buffer = 0;
diff --git a/sdm/libs/core/display_base.cpp b/sdm/libs/core/display_base.cpp
index 6642ca8..54996f2 100644
--- a/sdm/libs/core/display_base.cpp
+++ b/sdm/libs/core/display_base.cpp
@@ -1422,15 +1422,9 @@
 
   disp_layer_stack_.info.retire_fence_offset = retire_fence_offset_;
   // Regiser for power events on first cycle in unified draw.
-  if (first_cycle_ && display_type_ != kVirtual) {
+  if (first_cycle_ && display_type_ == kBuiltIn) {
     // Register for panel dead since notification is sent at any time
     hw_events_intf_->SetEventState(HWEvent::PANEL_DEAD, true);
-
-    if (draw_method_ != kDrawDefault && !hw_panel_info_.is_primary_panel &&
-        display_type_ != kHDMI) {
-      DLOGI("Registering for power events");
-      hw_events_intf_->SetEventState(HWEvent::POWER_EVENT, true);
-    }
   }
 
   // Allow commit as pending doze/pending_power_on is handled as a part of draw cycle
@@ -1860,10 +1854,6 @@
     break;
 
   case kStateOn:
-    if (display_type_ == kHDMI && first_cycle_) {
-      hw_events_intf_->SetEventState(HWEvent::POWER_EVENT, true);
-    }
-
     cached_qos_data_.clock_hz =
       std::max(cached_qos_data_.clock_hz, disp_layer_stack_.info.qos_data.clock_hz);
     error = hw_intf_->PowerOn(cached_qos_data_, &sync_points);
@@ -1931,7 +1921,7 @@
     return kErrorParameters;
   }
 
-  if ((pending_power_state_ == kPowerStateNone) && (!first_cycle_ || display_type_ == kHDMI)) {
+  if ((pending_power_state_ == kPowerStateNone) && !first_cycle_) {
     CacheRetireFence();
     SyncPoints sync = {};
     sync.retire_fence = retire_fence_;
@@ -3970,32 +3960,6 @@
 
 void DisplayBase::WaitForCompletion(SyncPoints *sync_points) {
   DTRACE_SCOPED();
-  // Wait on current retire fence.
-  if (draw_method_ == kDrawDefault || display_type_ == kVirtual) {
-    DLOGI("Wait for current retire fence");
-    Fence::Wait(sync_points->retire_fence);
-    DLOGI("Received retire fence");
-    return;
-  }
-
-  // Wait for CRTC power event on first cycle.
-  if (first_cycle_) {
-    if (hw_panel_info_.is_primary_panel) {
-      DLOGI("Sync commit on primary");
-      return;
-    }
-    DLOGI("Wait for CRTC power event on first cycle");
-    std::unique_lock<std::mutex> lck(power_mutex_);
-    while (!transition_done_) {
-      cv_.wait(lck);
-    }
-
-    DLOGI("Received CRTC power event on first cycle");
-    // Unregister power events.
-    hw_events_intf_->SetEventState(HWEvent::POWER_EVENT, false);
-    return;
-  }
-
   // For displays in unified draw, wait on cached retire fence in steady state.
   shared_ptr<Fence> retire_fence = sync_points->retire_fence;
   DLOGI("Wait for cached retire fence to be in steady state");
diff --git a/sdm/libs/dal/hw_device_drm.cpp b/sdm/libs/dal/hw_device_drm.cpp
index 5f04967..b5f9987 100644
--- a/sdm/libs/dal/hw_device_drm.cpp
+++ b/sdm/libs/dal/hw_device_drm.cpp
@@ -1158,7 +1158,10 @@
   drm_atomic_intf_->Perform(DRMOps::CRTC_GET_RELEASE_FENCE, token_.crtc_id, &release_fence_fd);
   drm_atomic_intf_->Perform(DRMOps::CONNECTOR_GET_RETIRE_FENCE, token_.conn_id, &retire_fence_fd);
 
-  int ret = NullCommit(false /* synchronous */, true /* retain_planes */);
+  // On the first boot up of the display, make the power call synchronous. This is only applicable
+  // to pluggable displays. Check HWPeripheralDRM::PowerOn. For builtin first power call defered
+  // and handled in commit(synchronous for first cycle).
+  int ret = NullCommit(first_cycle_ /* synchronous */, true /* retain_planes */);
   if (ret) {
     DLOGE("Failed with error: %d", ret);
     return kErrorHardware;