Merge "sdm: Issue two null commits for command mode panels"
diff --git a/sdm/libs/hwc/hwc_display.cpp b/sdm/libs/hwc/hwc_display.cpp
index 383aaa9..3327ed9 100644
--- a/sdm/libs/hwc/hwc_display.cpp
+++ b/sdm/libs/hwc/hwc_display.cpp
@@ -621,7 +621,7 @@
 
   size_t num_hw_layers = content_list->numHwLayers;
 
-  if (!skip_prepare_) {
+  if (!skip_prepare_cnt) {
     DisplayError error = display_intf_->Prepare(&layer_stack_);
     if (error != kErrorNone) {
       if (error == kErrorShutDown) {
@@ -639,7 +639,7 @@
   } else {
     // Skip is not set
     MarkLayersForGPUBypass(content_list);
-    skip_prepare_ = false;
+    skip_prepare_cnt = skip_prepare_cnt - 1;
     DLOGI("SecureDisplay %s, Skip Prepare/Commit and Flush", secure_display_active_ ? "Starting" :
           "Stopping");
     flush_ = true;
diff --git a/sdm/libs/hwc/hwc_display.h b/sdm/libs/hwc/hwc_display.h
index 47f2390..7dab6d5 100644
--- a/sdm/libs/hwc/hwc_display.h
+++ b/sdm/libs/hwc/hwc_display.h
@@ -210,7 +210,7 @@
   bool shutdown_pending_ = false;
   bool use_blit_comp_ = false;
   bool secure_display_active_ = false;
-  bool skip_prepare_ = false;
+  uint32_t skip_prepare_cnt = 0;
   bool solid_fill_enable_ = false;
   bool disable_animation_ = false;
   uint32_t solid_fill_color_ = 0;
diff --git a/sdm/libs/hwc/hwc_display_primary.cpp b/sdm/libs/hwc/hwc_display_primary.cpp
index 0028ed9..51402d7 100644
--- a/sdm/libs/hwc/hwc_display_primary.cpp
+++ b/sdm/libs/hwc/hwc_display_primary.cpp
@@ -303,14 +303,25 @@
     DLOGI("SecureDisplay state changed from %d to %d Needs Flush!!", secure_display_active_,
            secure_display_active);
     secure_display_active_ = secure_display_active;
-    skip_prepare_ = true;
+    skip_prepare_cnt = 1;
 
-    // Avoid flush for command mode panels when no external displays are connected
+    // Issue two null commits for command mode panels when external displays are connected.
+    // Two null commits are required to handle non secure to secure transitions at 30fps.
+    // TODO(user): Need two null commits on video mode also to handle transition cases of
+    // primary at higher fps (ex60) and external at lower fps.
+
+    // Avoid flush for command mode panels when no external displays are connected.
+    // This is to avoid flicker/blink on primary during transitions.
     DisplayConfigFixedInfo display_config;
     display_intf_->GetConfig(&display_config);
-    if ((display_config.is_cmdmode) && (force_flush == false)) {
-      DLOGI("Avoid flush for command mode panel");
-      skip_prepare_ = false;
+    if (display_config.is_cmdmode) {
+      if (force_flush) {
+        DLOGI("Issue two null commits for command mode panels");
+        skip_prepare_cnt = 2;
+      } else {
+        DLOGI("Avoid flush for command mode panel when no external displays are connected");
+        skip_prepare_cnt = 0;
+      }
     }
   }
 }