drm_hwcomposer: Wrap the importers in a class

This will allow us to move the importer functionality into the
drmcompositor.

Change-Id: I4274ebd1776c4d7879342c54a2b7c4095ebc50f4
Signed-off-by: Sean Paul <seanpaul@chromium.org>
diff --git a/hwcomposer.cpp b/hwcomposer.cpp
index c9452b6..06c0931 100644
--- a/hwcomposer.cpp
+++ b/hwcomposer.cpp
@@ -18,6 +18,7 @@
 
 #include "drm_hwcomposer.h"
 #include "drmresources.h"
+#include "importer.h"
 
 #include <errno.h>
 #include <fcntl.h>
@@ -75,14 +76,21 @@
   typedef std::map<int, hwc_drm_display_t> DisplayMap;
   typedef DisplayMap::iterator DisplayMapIter;
 
+  hwc_context_t() : procs(NULL), importer(NULL) {
+  }
+
+  ~hwc_context_t() {
+    delete importer;
+  }
+
   hwc_composer_device_1_t device;
   hwc_procs_t const *procs;
-  struct hwc_import_context *import_ctx;
 
   struct hwc_worker event_worker;
 
   DisplayMap displays;
   DrmResources drm;
+  Importer *importer;
 };
 
 static int hwc_prepare_layer(hwc_layer_1_t *layer) {
@@ -318,8 +326,7 @@
     return ret;
   }
 
-  if (hwc_import_bo_release(hd->ctx->drm.fd(), hd->ctx->import_ctx,
-                            &hd->front)) {
+  if (!hd->ctx->importer->ReleaseBuffer(buf)) {
     struct drm_gem_close args;
     memset(&args, 0, sizeof(args));
     for (int i = 0; i < ARRAY_SIZE(hd->front.gem_handles); ++i) {
@@ -469,9 +476,7 @@
   }
 
   struct hwc_drm_bo buf;
-  memset(&buf, 0, sizeof(buf));
-  ret =
-      hwc_import_bo_create(ctx->drm.fd(), ctx->import_ctx, layer->handle, &buf);
+  ret = ctx->importer->ImportBuffer(layer->handle, &buf);
   if (ret) {
     ALOGE("Failed to import handle to drm bo %d", ret);
     hwc_close_fences(display_contents);
@@ -754,12 +759,7 @@
   if (hwc_destroy_worker(&ctx->event_worker))
     ALOGE("Destroy event worker failed");
 
-  int ret = hwc_import_destroy(ctx->import_ctx);
-  if (ret)
-    ALOGE("Could not destroy import %d", ret);
-
   delete ctx;
-
   return 0;
 }
 
@@ -912,9 +912,9 @@
     return ret;
   }
 
-  ret = hwc_import_init(&ctx->import_ctx);
-  if (ret) {
-    ALOGE("Failed to initialize import context");
+  ctx->importer = Importer::CreateInstance(&ctx->drm);
+  if (!ctx->importer) {
+    ALOGE("Failed to create importer instance");
     delete ctx;
     return ret;
   }