vulkan: move driver::OpenHAL

Move it from loader.cpp to driver.cpp.  HAL loading is now done in
driver.cpp while HAL extension queries are still done in loader.cpp.

Change-Id: I15d7ead98497adacb1bd798522f057ff6bf16909
diff --git a/vulkan/libvulkan/driver.cpp b/vulkan/libvulkan/driver.cpp
index 26c1923..09811a0 100644
--- a/vulkan/libvulkan/driver.cpp
+++ b/vulkan/libvulkan/driver.cpp
@@ -17,13 +17,52 @@
 #include <sys/prctl.h>
 
 #include "driver.h"
+#include "loader.h"
 
 namespace vulkan {
 namespace driver {
 
+namespace {
+
+hwvulkan_device_t* g_hwdevice = nullptr;
+
+}  // anonymous namespace
+
 bool Debuggable() {
     return (prctl(PR_GET_DUMPABLE, 0, 0, 0, 0) >= 0);
 }
 
+bool OpenHAL() {
+    if (g_hwdevice)
+        return true;
+
+    const hwvulkan_module_t* module;
+    int result =
+        hw_get_module("vulkan", reinterpret_cast<const hw_module_t**>(&module));
+    if (result != 0) {
+        ALOGE("failed to load vulkan hal: %s (%d)", strerror(-result), result);
+        return false;
+    }
+
+    hwvulkan_device_t* device;
+    result =
+        module->common.methods->open(&module->common, HWVULKAN_DEVICE_0,
+                                     reinterpret_cast<hw_device_t**>(&device));
+    if (result != 0) {
+        ALOGE("failed to open vulkan driver: %s (%d)", strerror(-result),
+              result);
+        return false;
+    }
+
+    if (!InitLoader(device)) {
+        device->common.close(&device->common);
+        return false;
+    }
+
+    g_hwdevice = device;
+
+    return true;
+}
+
 }  // namespace driver
 }  // namespace vulkan