vulkan: Build hal; minimal stub

bug: 117932393

Just get the HAL building, and make sure Android Vulkan loader can get
to CreateInstance.

Change-Id: I31e1b739a6a0de12b4e47deeec6547ddf46570ee
diff --git a/Android.mk b/Android.mk
index be7551e..39b8144 100644
--- a/Android.mk
+++ b/Android.mk
@@ -135,4 +135,6 @@
 
 include $(GOLDFISH_OPENGL_PATH)/system/egl/Android.mk
 
+include $(GOLDFISH_OPENGL_PATH)/system/vulkan/Android.mk
+
 endif
diff --git a/system/vulkan/Android.mk b/system/vulkan/Android.mk
new file mode 100644
index 0000000..b48a536
--- /dev/null
+++ b/system/vulkan/Android.mk
@@ -0,0 +1,35 @@
+ifeq (true,$(GOLDFISH_OPENGL_SHOULD_BUILD))
+ifeq ($(shell test $(PLATFORM_SDK_VERSION) -gt 23 && echo isApi24OrHigher),isApi24OrHigher)
+
+LOCAL_PATH := $(call my-dir)
+
+$(call emugl-begin-shared-library,vulkan.ranchu)
+$(call emugl-export,C_INCLUDES,$(LOCAL_PATH))
+$(call emugl-import,libOpenglSystemCommon)
+$(call emugl-import,libOpenglCodecCommon$(GOLDFISH_OPENGL_LIB_SUFFIX))
+
+# Vulkan include dir
+ifeq (true,$(GOLDFISH_OPENGL_BUILD_FOR_HOST))
+LOCAL_C_INCLUDES += $(HOST_EMUGL_PATH)/host/include
+endif
+
+ifneq (true,$(GOLDFISH_OPENGL_BUILD_FOR_HOST))
+LOCAL_HEADER_LIBRARIES += \
+    vulkan_headers \
+
+endif
+
+LOCAL_CFLAGS += \
+    -DLOG_TAG=\"goldfish_vulkan\" \
+    -Wno-missing-field-initializers \
+    -fvisibility=hidden \
+    -fstrict-aliasing \
+    -DVK_USE_PLATFORM_ANDROID_KHR \
+    -DVK_NO_PROTOTYPES \
+
+LOCAL_SRC_FILES := goldfish_vulkan.cpp
+
+$(call emugl-end-module)
+
+endif # API 24 or later
+endif # GOLDFISH_OPENGL_SHOULD_BUILD
diff --git a/system/vulkan/goldfish_vulkan.cpp b/system/vulkan/goldfish_vulkan.cpp
new file mode 100644
index 0000000..7b39eb6
--- /dev/null
+++ b/system/vulkan/goldfish_vulkan.cpp
@@ -0,0 +1,98 @@
+// Copyright (C) 2018 The Android Open Source Project
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+#include <hardware/hwvulkan.h>
+
+#include <log/log.h>
+
+#include <errno.h>
+#include <string.h>
+
+namespace {
+
+int OpenDevice(const hw_module_t* module, const char* id, hw_device_t** device);
+
+hw_module_methods_t goldfish_vulkan_module_methods = {
+    .open = OpenDevice
+};
+
+extern "C" __attribute__((visibility("default"))) hwvulkan_module_t HAL_MODULE_INFO_SYM = {
+    .common = {
+        .tag = HARDWARE_MODULE_TAG,
+        .module_api_version = HWVULKAN_MODULE_API_VERSION_0_1,
+        .hal_api_version = HARDWARE_HAL_API_VERSION,
+        .id = HWVULKAN_HARDWARE_MODULE_ID,
+        .name = "Goldfish Vulkan Driver",
+        .author = "The Android Open Source Project",
+        .methods = &goldfish_vulkan_module_methods,
+    },
+};
+
+int CloseDevice(struct hw_device_t* /*device*/) {
+    // nothing to do - opening a device doesn't allocate any resources
+    return 0;
+}
+
+VKAPI_ATTR
+VkResult EnumerateInstanceExtensionProperties(
+    const char* layer_name,
+    uint32_t* count,
+    VkExtensionProperties* properties) {
+
+    if (layer_name) {
+        ALOGW(
+            "Driver vkEnumerateInstanceExtensionProperties shouldn't be called "
+            "with a layer name ('%s')",
+            layer_name);
+    }
+
+    *count = 0;
+    return VK_SUCCESS;
+}
+
+VKAPI_ATTR
+VkResult CreateInstance(const VkInstanceCreateInfo* create_info,
+                        const VkAllocationCallbacks* allocator,
+                        VkInstance* out_instance) {
+    ALOGD("%s: goldfish vkCreateInstance\n", __func__);
+    return VK_ERROR_OUT_OF_HOST_MEMORY;
+}
+
+VKAPI_ATTR
+PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name) {
+    return nullptr;
+}
+
+hwvulkan_device_t goldfish_vulkan_device = {
+    .common = {
+        .tag = HARDWARE_DEVICE_TAG,
+        .version = HWVULKAN_DEVICE_API_VERSION_0_1,
+        .module = &HAL_MODULE_INFO_SYM.common,
+        .close = CloseDevice,
+    },
+    .EnumerateInstanceExtensionProperties = EnumerateInstanceExtensionProperties,
+    .CreateInstance = CreateInstance,
+    .GetInstanceProcAddr = GetInstanceProcAddr,
+};
+
+int OpenDevice(const hw_module_t* /*module*/,
+               const char* id,
+               hw_device_t** device) {
+    if (strcmp(id, HWVULKAN_DEVICE_0) == 0) {
+        *device = &goldfish_vulkan_device.common;
+        return 0;
+    }
+    return -ENOENT;
+}
+
+} // namespace
\ No newline at end of file