Add support for loading layers from the apk.

Added the vulkan_layer_path interface which is used to set the path from
ThreadedRenderer. The vulkan loader then uses this path to search for layer
libraries that come preinstalled with the app.

Change-Id: Iee7d56c1950296ba5ece3a119741406d705479a8
(cherry picked from commit 1f920c1e52bbd59405761e5403def5dbc22e331b)
diff --git a/vulkan/libvulkan/Android.mk b/vulkan/libvulkan/Android.mk
index bcb1e8b..7a2eb64 100644
--- a/vulkan/libvulkan/Android.mk
+++ b/vulkan/libvulkan/Android.mk
@@ -33,7 +33,8 @@
 	entry.cpp \
 	get_proc_addr.cpp \
 	loader.cpp \
-	swapchain.cpp
+	swapchain.cpp \
+	vulkan_loader_data.cpp
 LOCAL_ADDITIONAL_DEPENDENCIES := $(LOCAL_PATH)/Android.mk
 
 LOCAL_SHARED_LIBRARIES := libhardware liblog libsync libcutils
diff --git a/vulkan/libvulkan/loader.cpp b/vulkan/libvulkan/loader.cpp
index ca33be1..97ceb4a 100644
--- a/vulkan/libvulkan/loader.cpp
+++ b/vulkan/libvulkan/loader.cpp
@@ -35,6 +35,7 @@
 #include <hardware/hwvulkan.h>
 #include <log/log.h>
 #include <vulkan/vk_debug_report_lunarg.h>
+#include <vulkan/vulkan_loader_data.h>
 
 using namespace vulkan;
 
@@ -753,13 +754,16 @@
     instance->message = VK_NULL_HANDLE;
 
     // Scan layers
-    // TODO: Add more directories to scan
     UnorderedMap<String, SharedLibraryHandle> layers(
         CallbackAllocator<std::pair<String, SharedLibraryHandle> >(
             instance->alloc));
     CallbackAllocator<char> string_allocator(instance->alloc);
     String dir_name("/data/local/tmp/vulkan/", string_allocator);
     FindLayersInDirectory(*instance, layers, dir_name);
+    const std::string& path = LoaderData::GetInstance().layer_path;
+    dir_name.assign(path.c_str(), path.size());
+    dir_name.append("/");
+    FindLayersInDirectory(*instance, layers, dir_name);
 
     // Load layers
     {
diff --git a/vulkan/libvulkan/vulkan_loader_data.cpp b/vulkan/libvulkan/vulkan_loader_data.cpp
new file mode 100644
index 0000000..a6a0295
--- /dev/null
+++ b/vulkan/libvulkan/vulkan_loader_data.cpp
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2015 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 <vulkan/vulkan_loader_data.h>
+
+using namespace vulkan;
+
+LoaderData& LoaderData::GetInstance() {
+    static LoaderData loader_data;
+    return loader_data;
+}