sdm: Add debug method to DebugHandler

Add method to handle debug messages to DebugHandle class.

Change-Id: Ic15c8c227036e038969cce6439c59959c028a1b3
diff --git a/sdm/include/core/debug_interface.h b/sdm/include/core/debug_interface.h
index 1d7f43b..373d8a0 100644
--- a/sdm/include/core/debug_interface.h
+++ b/sdm/include/core/debug_interface.h
@@ -82,6 +82,13 @@
   */
   virtual void Info(DebugTag tag, const char *format, ...) = 0;
 
+  /*! @brief Method to handle debug messages.
+
+    @param[in] tag \link DebugTag \endlink
+    @param[in] format \link message format with variable argument list \endlink
+  */
+  virtual void Debug(DebugTag tag, const char *format, ...) = 0;
+
   /*! @brief Method to handle verbose messages.
 
     @param[in] tag \link DebugTag \endlink
diff --git a/sdm/include/utils/debug.h b/sdm/include/utils/debug.h
index 61c258a..a5a10cd 100644
--- a/sdm/include/utils/debug.h
+++ b/sdm/include/utils/debug.h
@@ -41,12 +41,12 @@
 #define DLOGE_IF(tag, format, ...) DLOG(tag, Error, format, ##__VA_ARGS__)
 #define DLOGW_IF(tag, format, ...) DLOG(tag, Warning, format, ##__VA_ARGS__)
 #define DLOGI_IF(tag, format, ...) DLOG(tag, Info, format, ##__VA_ARGS__)
+#define DLOGD_IF(tag, format, ...) DLOG(tag, Debug, format, ##__VA_ARGS__)
 #define DLOGV_IF(tag, format, ...) DLOG(tag, Verbose, format, ##__VA_ARGS__)
 
 #define DLOGE(format, ...) DLOGE_IF(kTagNone, format, ##__VA_ARGS__)
 #define DLOGW(format, ...) DLOGW_IF(kTagNone, format, ##__VA_ARGS__)
 #define DLOGI(format, ...) DLOGI_IF(kTagNone, format, ##__VA_ARGS__)
-#define DLOGV(format, ...) DLOGV_IF(kTagNone, format, ##__VA_ARGS__)
 
 #define DTRACE_BEGIN(custom_string) Debug::Get()->BeginTrace(__CLASS__, __FUNCTION__, custom_string)
 #define DTRACE_END() Debug::Get()->EndTrace()
@@ -79,6 +79,7 @@
     virtual void Error(DebugTag /*tag*/, const char */*format*/, ...) { }
     virtual void Warning(DebugTag /*tag*/, const char */*format*/, ...) { }
     virtual void Info(DebugTag /*tag*/, const char */*format*/, ...) { }
+    virtual void Debug(DebugTag /*tag*/, const char */*format*/, ...) { }
     virtual void Verbose(DebugTag /*tag*/, const char */*format*/, ...) { }
     virtual void BeginTrace(const char */*class_name*/, const char */*function_name*/,
                             const char */*custom_string*/) { }
diff --git a/sdm/libs/core/display_base.cpp b/sdm/libs/core/display_base.cpp
index cbb238c..d18f53c 100644
--- a/sdm/libs/core/display_base.cpp
+++ b/sdm/libs/core/display_base.cpp
@@ -275,7 +275,7 @@
     comp_manager_->Purge(display_comp_ctx_);
     pending_commit_ = false;
   } else {
-    DLOGV("Failed to flush device.");
+    DLOGW("Unable to flush display = %d", display_type_);
   }
 
   return error;
diff --git a/sdm/libs/core/fb/hw_primary.cpp b/sdm/libs/core/fb/hw_primary.cpp
index 639e5d3..ee59bae 100644
--- a/sdm/libs/core/fb/hw_primary.cpp
+++ b/sdm/libs/core/fb/hw_primary.cpp
@@ -531,7 +531,7 @@
         break;
 
     if (feature) {
-      DLOGV("feature_id = %d", feature->feature_id_);
+      DLOGV_IF(kTagDriverConfig, "feature_id = %d", feature->feature_id_);
 
       if ((feature->feature_id_ < kMaxNumPPFeatures)) {
 
diff --git a/sdm/libs/hwc/hwc_debugger.cpp b/sdm/libs/hwc/hwc_debugger.cpp
index a3b3cb0..4b5c659 100644
--- a/sdm/libs/hwc/hwc_debugger.cpp
+++ b/sdm/libs/hwc/hwc_debugger.cpp
@@ -36,60 +36,75 @@
 
 HWCDebugHandler HWCDebugHandler::debug_handler_;
 uint32_t HWCDebugHandler::debug_flags_ = 0x1;
+uint32_t HWCDebugHandler::verbose_level_ = 0x0;
 
-void HWCDebugHandler::DebugAll(bool enable) {
+void HWCDebugHandler::DebugAll(bool enable, int verbose_level) {
   if (enable) {
     debug_flags_ = 0xFFFFFFFF;
+    verbose_level_ = verbose_level;
   } else {
     debug_flags_ = 0x1;   // kTagNone should always be printed.
+    verbose_level_ = 0;
   }
 }
 
-void HWCDebugHandler::DebugResources(bool enable) {
+void HWCDebugHandler::DebugResources(bool enable, int verbose_level) {
   if (enable) {
     SET_BIT(debug_flags_, kTagResources);
+    verbose_level_ = verbose_level;
   } else {
     CLEAR_BIT(debug_flags_, kTagResources);
+    verbose_level_ = 0;
   }
 }
 
-void HWCDebugHandler::DebugStrategy(bool enable) {
+void HWCDebugHandler::DebugStrategy(bool enable, int verbose_level) {
   if (enable) {
     SET_BIT(debug_flags_, kTagStrategy);
+    verbose_level_ = verbose_level;
   } else {
     CLEAR_BIT(debug_flags_, kTagStrategy);
+    verbose_level_ = 0;
   }
 }
 
-void HWCDebugHandler::DebugCompManager(bool enable) {
+void HWCDebugHandler::DebugCompManager(bool enable, int verbose_level) {
   if (enable) {
     SET_BIT(debug_flags_, kTagCompManager);
+    verbose_level_ = verbose_level;
   } else {
     CLEAR_BIT(debug_flags_, kTagCompManager);
+    verbose_level_ = 0;
   }
 }
 
-void HWCDebugHandler::DebugDriverConfig(bool enable) {
+void HWCDebugHandler::DebugDriverConfig(bool enable, int verbose_level) {
   if (enable) {
     SET_BIT(debug_flags_, kTagDriverConfig);
+    verbose_level_ = verbose_level;
   } else {
     CLEAR_BIT(debug_flags_, kTagDriverConfig);
+    verbose_level_ = 0;
   }
 }
 
-void HWCDebugHandler::DebugRotator(bool enable) {
+void HWCDebugHandler::DebugRotator(bool enable, int verbose_level) {
   if (enable) {
     SET_BIT(debug_flags_, kTagRotator);
+    verbose_level_ = verbose_level;
   } else {
     CLEAR_BIT(debug_flags_, kTagRotator);
+    verbose_level_ = 0;
   }
 }
 
-void HWCDebugHandler::DebugQdcm(bool enable) {
+void HWCDebugHandler::DebugQdcm(bool enable, int verbose_level) {
   if (enable) {
     SET_BIT(debug_flags_, kTagQDCM);
+    verbose_level_ = verbose_level;
   } else {
     CLEAR_BIT(debug_flags_, kTagQDCM);
+    verbose_level_ = 0;
   }
 }
 
@@ -113,10 +128,18 @@
   }
 }
 
-void HWCDebugHandler::Verbose(DebugTag tag, const char *format, ...) {
+void HWCDebugHandler::Debug(DebugTag tag, const char *format, ...) {
   if (IS_BIT_SET(debug_flags_, tag)) {
     va_list list;
     va_start(list, format);
+    __android_log_vprint(ANDROID_LOG_DEBUG, LOG_TAG, format, list);
+  }
+}
+
+void HWCDebugHandler::Verbose(DebugTag tag, const char *format, ...) {
+  if (IS_BIT_SET(debug_flags_, tag)  && verbose_level_) {
+    va_list list;
+    va_start(list, format);
     __android_log_vprint(ANDROID_LOG_VERBOSE, LOG_TAG, format, list);
   }
 }
diff --git a/sdm/libs/hwc/hwc_debugger.h b/sdm/libs/hwc/hwc_debugger.h
index 3386377..9fedb80 100644
--- a/sdm/libs/hwc/hwc_debugger.h
+++ b/sdm/libs/hwc/hwc_debugger.h
@@ -42,6 +42,7 @@
 #define DLOGE(format, ...) DLOG(ALOGE, format, ##__VA_ARGS__)
 #define DLOGW(format, ...) DLOG(ALOGW, format, ##__VA_ARGS__)
 #define DLOGI(format, ...) DLOG(ALOGI, format, ##__VA_ARGS__)
+#define DLOGD(format, ...) DLOG(ALOGI, format, ##__VA_ARGS__)
 #define DLOGV(format, ...) DLOG(ALOGV, format, ##__VA_ARGS__)
 
 #define DTRACE_BEGIN(custom_string) HWCDebugHandler::Get()->BeginTrace(__CLASS__, __FUNCTION__, \
@@ -54,17 +55,19 @@
 class HWCDebugHandler : public DebugHandler {
  public:
   static inline DebugHandler* Get() { return &debug_handler_; }
-  static void DebugAll(bool enable);
-  static void DebugResources(bool enable);
-  static void DebugStrategy(bool enable);
-  static void DebugCompManager(bool enable);
-  static void DebugDriverConfig(bool enable);
-  static void DebugRotator(bool enable);
-  static void DebugQdcm(bool enable);
+
+  static void DebugAll(bool enable, int verbose_level);
+  static void DebugResources(bool enable, int verbose_level);
+  static void DebugStrategy(bool enable, int verbose_level);
+  static void DebugCompManager(bool enable, int verbose_level);
+  static void DebugDriverConfig(bool enable, int verbose_level);
+  static void DebugRotator(bool enable, int verbose_level);
+  static void DebugQdcm(bool enable, int verbose_level);
 
   virtual void Error(DebugTag tag, const char *format, ...);
   virtual void Warning(DebugTag tag, const char *format, ...);
   virtual void Info(DebugTag tag, const char *format, ...);
+  virtual void Debug(DebugTag tag, const char *format, ...);
   virtual void Verbose(DebugTag tag, const char *format, ...);
   virtual void BeginTrace(const char *class_name, const char *function_name,
                           const char *custom_string);
@@ -74,6 +77,7 @@
  private:
   static HWCDebugHandler debug_handler_;
   static uint32_t debug_flags_;
+  static uint32_t verbose_level_;
 };
 
 }  // namespace sdm
diff --git a/sdm/libs/hwc/hwc_session.cpp b/sdm/libs/hwc/hwc_session.cpp
index 49626db..227de55 100644
--- a/sdm/libs/hwc/hwc_session.cpp
+++ b/sdm/libs/hwc/hwc_session.cpp
@@ -600,33 +600,34 @@
   int type = input_parcel->readInt32();
   bool enable = (input_parcel->readInt32() > 0);
   DLOGI("type = %d enable = %d", type, enable);
+  int verbose_level = input_parcel->readInt32();
 
   switch (type) {
   case qService::IQService::DEBUG_ALL:
-    HWCDebugHandler::DebugAll(enable);
+    HWCDebugHandler::DebugAll(enable, verbose_level);
     break;
 
   case qService::IQService::DEBUG_MDPCOMP:
-    HWCDebugHandler::DebugStrategy(enable);
-    HWCDebugHandler::DebugCompManager(enable);
+    HWCDebugHandler::DebugStrategy(enable, verbose_level);
+    HWCDebugHandler::DebugCompManager(enable, verbose_level);
     break;
 
   case qService::IQService::DEBUG_PIPE_LIFECYCLE:
-    HWCDebugHandler::DebugResources(enable);
+    HWCDebugHandler::DebugResources(enable, verbose_level);
     break;
 
   case qService::IQService::DEBUG_DRIVER_CONFIG:
-    HWCDebugHandler::DebugDriverConfig(enable);
+    HWCDebugHandler::DebugDriverConfig(enable, verbose_level);
     break;
 
   case qService::IQService::DEBUG_ROTATOR:
-    HWCDebugHandler::DebugResources(enable);
-    HWCDebugHandler::DebugDriverConfig(enable);
-    HWCDebugHandler::DebugRotator(enable);
+    HWCDebugHandler::DebugResources(enable, verbose_level);
+    HWCDebugHandler::DebugDriverConfig(enable, verbose_level);
+    HWCDebugHandler::DebugRotator(enable, verbose_level);
     break;
 
   case qService::IQService::DEBUG_QDCM:
-    HWCDebugHandler::DebugQdcm(enable);
+    HWCDebugHandler::DebugQdcm(enable, verbose_level);
     break;
 
   default: