gralloc/qdutils: Remove unused gralloc code, add driver type check

Remove unused code related to macro tiling from galloc and qdutils.
Add API to check for driver type and query caps based on driver.

Change-Id: I36cfa5529395c69deb886080be1c904ff5c9ad15
CRs-fixed: 1109207
diff --git a/libqdutils/qd_utils.cpp b/libqdutils/qd_utils.cpp
index b84ae87..170b1d8 100644
--- a/libqdutils/qd_utils.cpp
+++ b/libqdutils/qd_utils.cpp
@@ -27,6 +27,7 @@
  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include <unistd.h>
 #include "qd_utils.h"
 
 namespace qdutils {
@@ -81,7 +82,31 @@
     return -1;
 }
 
-int querySDEInfo(HWQueryType type, int *value) {
+static int querySDEInfoDRM(HWQueryType type, int *value) {
+    char property[PROPERTY_VALUE_MAX] = {0};
+
+    // TODO(user): If future targets don't support WB UBWC, add separate
+    // properties in target specific system.prop and have clients like WFD
+    // directly rely on those.
+    switch(type) {
+    case HAS_UBWC:
+    case HAS_WB_UBWC:  // WFD stack still uses this
+        *value = 1;
+        property_get("debug.gralloc.gfx_ubwc_disable", property, "0");
+        if(!(strncmp(property, "1", PROPERTY_VALUE_MAX)) ||
+                !(strncmp(property, "true", PROPERTY_VALUE_MAX))) {
+            *value = 0;
+        }
+        break;
+    default:
+        ALOGE("Invalid query type %d", type);
+        return -EINVAL;
+    }
+
+    return 0;
+}
+
+static int querySDEInfoFB(HWQueryType type, int *value) {
     FILE *fileptr = NULL;
     const char *featureName;
     char stringBuffer[MAX_STRING_LENGTH];
@@ -90,9 +115,6 @@
     char *tokens[maxCount] = { NULL };
 
     switch(type) {
-    case HAS_MACRO_TILE:
-        featureName = "tile_format";
-        break;
     case HAS_UBWC:
         featureName = "ubwc";
         break;
@@ -134,6 +156,18 @@
     return 0;
 }
 
+int querySDEInfo(HWQueryType type, int *value) {
+    if (!value) {
+        return -EINVAL;
+    }
+
+    if (getDriverType() ==  DriverType::DRM) {
+        return querySDEInfoDRM(type, value);
+    }
+
+    return querySDEInfoFB(type, value);
+}
+
 int getHDMINode(void) {
     return getExternalNode("dtv panel");
 }
@@ -241,4 +275,10 @@
     return 0;
 }
 
+DriverType getDriverType() {
+    const char *fb_caps = "/sys/devices/virtual/graphics/fb0/mdp/caps";
+    // 0 - File exists
+    return access(fb_caps, F_OK) ? DriverType::DRM : DriverType::FB;
+}
+
 }; //namespace qdutils