sdm: disable SSPP color processing features during TUI transition

When switch between LA and LE VM, disable the DMA IGC/GC and VIG
gamut/GC features during the first commit to clear the HW settings.

Change-Id: Iec610ff6861ed89f08c95a3adb6094c7b8cd5cc6
diff --git a/sde-drm/Makefile.am b/sde-drm/Makefile.am
index 104d9d5..df767cf 100644
--- a/sde-drm/Makefile.am
+++ b/sde-drm/Makefile.am
@@ -18,6 +18,6 @@
 libsdedrm_la_CC = @CC@
 libsdedrm_la_SOURCES = $(cpp_sources)
 libsdedrm_la_CFLAGS = $(AM_CFLAGS) -DLOG_TAG=\"SDE_DRM\"
-libsdedrm_la_CPPFLAGS = $(AM_CPPFLAGS)
+libsdedrm_la_CPPFLAGS = $(AM_CPPFLAGS) -DPP_DRM_ENABLE
 libsdedrm_la_LIBADD = ../libdrmutils/libdrmutils.la ../libdebug/libdisplaydebug.la -ldrm
 libsdedrm_la_LDFLAGS = -shared -avoid-version
diff --git a/sde-drm/drm_atomic_req.cpp b/sde-drm/drm_atomic_req.cpp
index 6935ed0..84d5b6d 100644
--- a/sde-drm/drm_atomic_req.cpp
+++ b/sde-drm/drm_atomic_req.cpp
@@ -1,5 +1,5 @@
 /*
-* Copyright (c) 2019, The Linux Foundation. All rights reserved.
+* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
@@ -135,7 +135,7 @@
       drm_mgr_->GetDppsMgrIntf()->CommitDppsFeatures(drm_atomic_req_, token_);
     } break;
     case DRMOps::PLANES_RESET_CACHE: {
-      drm_mgr_->GetPlaneMgr()->ResetCache(obj_id);
+      drm_mgr_->GetPlaneMgr()->ResetCache(drm_atomic_req_, obj_id);
     } break;
     default:
       DRM_LOGE("Invalid opcode %d", opcode);
diff --git a/sde-drm/drm_plane.cpp b/sde-drm/drm_plane.cpp
index bee1922..e2177f7 100644
--- a/sde-drm/drm_plane.cpp
+++ b/sde-drm/drm_plane.cpp
@@ -403,14 +403,15 @@
   }
 }
 
-void DRMPlaneManager::ResetCache(uint32_t crtc_id) {
+void DRMPlaneManager::ResetCache(drmModeAtomicReq *req, uint32_t crtc_id) {
   lock_guard<mutex> lock(lock_);
   for (auto &plane : plane_pool_) {
     uint32_t assigned_crtc = 0;
     plane.second->GetAssignedCrtc(&assigned_crtc);
-    if (assigned_crtc == crtc_id) {
-      plane.second->ResetCache();
-    }
+#ifndef TRUSTED_VM
+    if (assigned_crtc == crtc_id)
+#endif
+      plane.second->ResetCache(req);
   }
 }
 
@@ -1189,4 +1190,42 @@
   pp_mgr_->SetPPFeature(req, drm_plane_->plane_id, pp_feature_info);
 }
 
+
+void DRMPlane::ResetCache(drmModeAtomicReq *req) {
+  tmp_prop_val_map_.clear();
+  committed_prop_val_map_.clear();
+
+  for (int i = 0; i <= (int32_t)(DRMTonemapLutType::VIG_3D_GAMUT); i++) {
+    auto itr = plane_type_info_.tonemap_lut_version_map.find(static_cast<DRMTonemapLutType>(i));
+    if (itr != plane_type_info_.tonemap_lut_version_map.end()) {
+      DRMPlaneLutState *lut_state = nullptr;
+      DRMPPFeatureID feature_id = {};
+      switch (static_cast<DRMTonemapLutType>(i)) {
+        case DRMTonemapLutType::DMA_1D_GC:
+          lut_state = &dgm_1d_lut_gc_state_;
+          feature_id = kFeatureDgmGc;
+          break;
+        case DRMTonemapLutType::DMA_1D_IGC:
+          lut_state = &dgm_1d_lut_igc_state_;
+          feature_id = kFeatureDgmIgc;
+          break;
+        case DRMTonemapLutType::VIG_1D_IGC:
+          lut_state = &vig_1d_lut_igc_state_;
+          feature_id = kFeatureVigIgc;
+          break;
+        case DRMTonemapLutType::VIG_3D_GAMUT:
+          lut_state = &vig_3d_lut_gamut_state_;
+          feature_id = kFeatureVigGamut;
+          break;
+        default:
+          DLOGE("Invalid lut type = %d", i);
+          return;
+      }
+
+      *lut_state = kDirty;
+      ResetColorLUT(feature_id, req);
+    }
+  }
+}
+
 }  // namespace sde_drm
diff --git a/sde-drm/drm_plane.h b/sde-drm/drm_plane.h
index fc464be..c827489 100644
--- a/sde-drm/drm_plane.h
+++ b/sde-drm/drm_plane.h
@@ -84,10 +84,7 @@
   void ResetColorLUTs(bool is_commit, drmModeAtomicReq *req);
   void ResetColorLUTState(DRMTonemapLutType lut_type, bool is_commit, drmModeAtomicReq *req);
   void ResetColorLUT(DRMPPFeatureID id, drmModeAtomicReq *req);
-  void ResetCache() {
-    tmp_prop_val_map_.clear();
-    committed_prop_val_map_.clear();
-  }
+  void ResetCache(drmModeAtomicReq *req);
 
  private:
   typedef std::map<DRMProperty, std::tuple<uint64_t, drmModePropertyRes *>> PropertyMap;
@@ -137,7 +134,7 @@
   void UnsetScalerLUT();
   void PostValidate(uint32_t crtc_id, bool success);
   void PostCommit(uint32_t crtc_id, bool success);
-  void ResetCache(uint32_t crtc_id);
+  void ResetCache(drmModeAtomicReq *req, uint32_t crtc_id);
 
  private:
   void Perform(DRMOps code, drmModeAtomicReq *req, uint32_t obj_id, ...);
diff --git a/sdm/libs/core/Makefile.am b/sdm/libs/core/Makefile.am
index 697cecd..415a3a6 100644
--- a/sdm/libs/core/Makefile.am
+++ b/sdm/libs/core/Makefile.am
@@ -41,6 +41,6 @@
 libsdmcore_la_CC = @CC@
 libsdmcore_la_SOURCES = $(c_sources)
 libsdmcore_la_CFLAGS = $(COMMON_CFLAGS) -DLOG_TAG=\"SDM\"
-libsdmcore_la_CPPFLAGS = $(AM_CPPFLAGS)
+libsdmcore_la_CPPFLAGS = $(AM_CPPFLAGS) -DPP_DRM_ENABLE
 libsdmcore_la_LIBADD = ../utils/libsdmutils.la ../../../sde-drm/libsdedrm.la -ldl -ldisplaydebug
 libsdmcore_la_LDFLAGS = -shared -avoid-version
diff --git a/sdm/libs/core/drm/hw_device_drm.cpp b/sdm/libs/core/drm/hw_device_drm.cpp
index a125d24..2a30d6f 100644
--- a/sdm/libs/core/drm/hw_device_drm.cpp
+++ b/sdm/libs/core/drm/hw_device_drm.cpp
@@ -1141,6 +1141,11 @@
     }
   }
 
+#ifdef TRUSTED_VM
+  if (first_cycle_)
+    drm_atomic_intf_->Perform(sde_drm::DRMOps::PLANES_RESET_CACHE, token_.crtc_id);
+#endif
+
   for (uint32_t i = 0; i < hw_layer_count; i++) {
     Layer &layer = hw_layer_info.hw_layers.at(i);
     LayerBuffer *input_buffer = &layer.input_buffer;