drm_hwcomposer: clean Importer inherited classes

Move some common logic from Importer class implementations
into DrmGenericImporter class:
 - reused generic constructors and destructors for derived
   classes
 - formed common Init() logic for all derived classes
 - removed unused gralloc_ and drm_ variables from derived
   classes
 - made drm_ protected for base class to be reused in derived

Signed-off-by: Mykhailo Sopiha <mykhailo.sopiha@linaro.org>
diff --git a/platformdrmgeneric.cpp b/platformdrmgeneric.cpp
index 503c04a..2fcbe40 100644
--- a/platformdrmgeneric.cpp
+++ b/platformdrmgeneric.cpp
@@ -60,6 +60,10 @@
     ALOGE("Failed to open gralloc module");
     return ret;
   }
+
+  ALOGI("Using %s gralloc module: %s\n", gralloc_->common.name,
+        gralloc_->common.author);
+
   return 0;
 }
 
diff --git a/platformdrmgeneric.h b/platformdrmgeneric.h
index 233ba55..c6d2be6 100644
--- a/platformdrmgeneric.h
+++ b/platformdrmgeneric.h
@@ -38,9 +38,10 @@
   uint32_t ConvertHalFormatToDrm(uint32_t hal_format);
   uint32_t DrmFormatToBitsPerPixel(uint32_t drm_format);
 
- private:
+ protected:
   DrmDevice *drm_;
 
+ private:
   const gralloc_module_t *gralloc_;
 };
 }  // namespace android
diff --git a/platformhisi.cpp b/platformhisi.cpp
index e022010..64b410b 100644
--- a/platformhisi.cpp
+++ b/platformhisi.cpp
@@ -48,28 +48,6 @@
   return importer;
 }
 
-HisiImporter::HisiImporter(DrmDevice *drm)
-    : DrmGenericImporter(drm), drm_(drm) {
-}
-
-HisiImporter::~HisiImporter() {
-}
-
-int HisiImporter::Init() {
-  int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
-                          (const hw_module_t **)&gralloc_);
-  if (ret) {
-    ALOGE("Failed to open gralloc module %d", ret);
-    return ret;
-  }
-
-  if (strcasecmp(gralloc_->common.author, "ARM Ltd."))
-    ALOGW("Using non-ARM gralloc module: %s/%s\n", gralloc_->common.name,
-          gralloc_->common.author);
-
-  return 0;
-}
-
 #if defined(MALI_GRALLOC_INTFMT_AFBC_BASIC) && \
     defined(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16)
 uint64_t HisiImporter::ConvertGrallocFormatToDrmModifiers(uint64_t flags,
diff --git a/platformhisi.h b/platformhisi.h
index 14a58b9..9dfea89 100644
--- a/platformhisi.h
+++ b/platformhisi.h
@@ -29,23 +29,15 @@
 
 class HisiImporter : public DrmGenericImporter {
  public:
-  HisiImporter(DrmDevice *drm);
-  ~HisiImporter() override;
-
-  int Init();
+  using DrmGenericImporter::DrmGenericImporter;
 
   int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
-
   bool CanImportBuffer(buffer_handle_t handle) override;
 
  private:
   uint64_t ConvertGrallocFormatToDrmModifiers(uint64_t flags, bool is_rgb);
 
   bool IsDrmFormatRgb(uint32_t drm_format);
-
-  DrmDevice *drm_;
-
-  const gralloc_module_t *gralloc_;
 };
 }  // namespace android
 
diff --git a/platformminigbm.cpp b/platformminigbm.cpp
index dce1d11..ad0a373 100644
--- a/platformminigbm.cpp
+++ b/platformminigbm.cpp
@@ -45,28 +45,6 @@
   return importer;
 }
 
-DrmMinigbmImporter::DrmMinigbmImporter(DrmDevice *drm)
-    : DrmGenericImporter(drm), drm_(drm) {
-}
-
-DrmMinigbmImporter::~DrmMinigbmImporter() {
-}
-
-int DrmMinigbmImporter::Init() {
-  int ret = hw_get_module(GRALLOC_HARDWARE_MODULE_ID,
-                          (const hw_module_t **)&gralloc_);
-  if (ret) {
-    ALOGE("Failed to open gralloc module %d", ret);
-    return ret;
-  }
-
-  if (strcasecmp(gralloc_->common.author, "Chrome OS"))
-    ALOGW("Using non-minigbm gralloc module: %s/%s\n", gralloc_->common.name,
-          gralloc_->common.author);
-
-  return 0;
-}
-
 int DrmMinigbmImporter::ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) {
   cros_gralloc_handle *gr_handle = (cros_gralloc_handle *)handle;
   if (!gr_handle)
diff --git a/platformminigbm.h b/platformminigbm.h
index 25f8404..ff69f14 100644
--- a/platformminigbm.h
+++ b/platformminigbm.h
@@ -27,17 +27,8 @@
 
 class DrmMinigbmImporter : public DrmGenericImporter {
  public:
-  DrmMinigbmImporter(DrmDevice *drm);
-  ~DrmMinigbmImporter() override;
-
-  int Init();
-
+  using DrmGenericImporter::DrmGenericImporter;
   int ImportBuffer(buffer_handle_t handle, hwc_drm_bo_t *bo) override;
-
- private:
-  DrmDevice *drm_;
-
-  const gralloc_module_t *gralloc_;
 };
 
 }  // namespace android