drm_hwcomposer: add non hwfb import filter

This patch adds non hwfb filter to generic drm importer
with additional property "hwc.drm.exclude_non_hwfb_imports".
By default this is set to false, and no logic changes are
happening. On setting this option to 1 the filter is being
activated on Init() function.

Change-Id: I7a718a66cb6214c051335a4589d60b5833e5c545
Signed-off-by: Mykhailo Sopiha <mykhailo.sopiha@linaro.org>
diff --git a/platform/platformdrmgeneric.cpp b/platform/platformdrmgeneric.cpp
index 2fcbe40..9ac601f 100644
--- a/platform/platformdrmgeneric.cpp
+++ b/platform/platformdrmgeneric.cpp
@@ -24,6 +24,7 @@
 #include <xf86drm.h>
 #include <xf86drmMode.h>
 
+#include <cutils/properties.h>
 #include <gralloc_handle.h>
 #include <hardware/gralloc.h>
 #include <log/log.h>
@@ -47,7 +48,8 @@
 }
 #endif
 
-DrmGenericImporter::DrmGenericImporter(DrmDevice *drm) : drm_(drm) {
+DrmGenericImporter::DrmGenericImporter(DrmDevice *drm)
+    : drm_(drm), exclude_non_hwfb_(false) {
 }
 
 DrmGenericImporter::~DrmGenericImporter() {
@@ -64,6 +66,10 @@
   ALOGI("Using %s gralloc module: %s\n", gralloc_->common.name,
         gralloc_->common.author);
 
+  char exclude_non_hwfb_prop[PROPERTY_VALUE_MAX];
+  property_get("hwc.drm.exclude_non_hwfb_imports", exclude_non_hwfb_prop, "0");
+  exclude_non_hwfb_ = static_cast<bool>(strncmp(exclude_non_hwfb_prop, "0", 1));
+
   return 0;
 }
 
@@ -168,6 +174,12 @@
 bool DrmGenericImporter::CanImportBuffer(buffer_handle_t handle) {
   if (handle == NULL)
     return false;
+
+  if (exclude_non_hwfb_) {
+    gralloc_handle_t *hnd = gralloc_handle(handle);
+    return hnd->usage & GRALLOC_USAGE_HW_FB;
+  }
+
   return true;
 }