diff options
author | 2018-08-28 13:55:11 -0700 | |
---|---|---|
committer | 2018-08-28 13:55:11 -0700 | |
commit | edc39e36e980247e3f7ed02a0c570b5ddafb5a2c (patch) | |
tree | 5a5d90a0bbb46625343a37ac5047d401904beda7 | |
parent | f43073af5bb559ba3481689793b997cc3b009049 (diff) | |
parent | a78bdeb2288cde6c9bef48ef83675ffdd8f14e55 (diff) |
Merge "Add fallback case to layers_extensions.cpp" am: c3260262ae
am: a78bdeb228
Change-Id: I5565286bb7de790aa595e007ef186d81ddfe7ea3
-rw-r--r-- | libs/graphicsenv/GraphicsEnv.cpp | 4 | ||||
-rw-r--r-- | libs/graphicsenv/include/graphicsenv/GraphicsEnv.h | 8 | ||||
-rw-r--r-- | vulkan/libvulkan/Android.bp | 2 | ||||
-rw-r--r-- | vulkan/libvulkan/layers_extensions.cpp | 64 |
4 files changed, 51 insertions, 27 deletions
diff --git a/libs/graphicsenv/GraphicsEnv.cpp b/libs/graphicsenv/GraphicsEnv.cpp index 961f1011e0..a8ef7a051d 100644 --- a/libs/graphicsenv/GraphicsEnv.cpp +++ b/libs/graphicsenv/GraphicsEnv.cpp @@ -56,7 +56,7 @@ void GraphicsEnv::setDriverPath(const std::string path) { mDriverPath = path; } -void GraphicsEnv::setLayerPaths(android_namespace_t* appNamespace, const std::string layerPaths) { +void GraphicsEnv::setLayerPaths(NativeLoaderNamespace* appNamespace, const std::string layerPaths) { if (mLayerPaths.empty()) { mLayerPaths = layerPaths; mAppNamespace = appNamespace; @@ -66,7 +66,7 @@ void GraphicsEnv::setLayerPaths(android_namespace_t* appNamespace, const std::st } } -android_namespace_t* GraphicsEnv::getAppNamespace() { +NativeLoaderNamespace* GraphicsEnv::getAppNamespace() { return mAppNamespace; } diff --git a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h index 213580c20b..17e8f6ba47 100644 --- a/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h +++ b/libs/graphicsenv/include/graphicsenv/GraphicsEnv.h @@ -23,6 +23,8 @@ struct android_namespace_t; namespace android { +class NativeLoaderNamespace; + class GraphicsEnv { public: static GraphicsEnv& getInstance(); @@ -35,8 +37,8 @@ public: void setDriverPath(const std::string path); android_namespace_t* getDriverNamespace(); - void setLayerPaths(android_namespace_t* appNamespace, const std::string layerPaths); - android_namespace_t* getAppNamespace(); + void setLayerPaths(NativeLoaderNamespace* appNamespace, const std::string layerPaths); + NativeLoaderNamespace* getAppNamespace(); const std::string getLayerPaths(); void setDebugLayers(const std::string layers); @@ -48,7 +50,7 @@ private: std::string mDebugLayers; std::string mLayerPaths; android_namespace_t* mDriverNamespace = nullptr; - android_namespace_t* mAppNamespace = nullptr; + NativeLoaderNamespace* mAppNamespace = nullptr; }; } // namespace android diff --git a/vulkan/libvulkan/Android.bp b/vulkan/libvulkan/Android.bp index cbba5f48fb..7eaf7b2d73 100644 --- a/vulkan/libvulkan/Android.bp +++ b/vulkan/libvulkan/Android.bp @@ -81,6 +81,8 @@ cc_library_shared { "libutils", "libcutils", "libz", + "libnativebridge", + "libnativeloader", "libnativewindow", "android.hardware.graphics.common@1.0", ], diff --git a/vulkan/libvulkan/layers_extensions.cpp b/vulkan/libvulkan/layers_extensions.cpp index 3a59208446..96c556393c 100644 --- a/vulkan/libvulkan/layers_extensions.cpp +++ b/vulkan/libvulkan/layers_extensions.cpp @@ -31,6 +31,8 @@ #include <cutils/properties.h> #include <graphicsenv/GraphicsEnv.h> #include <log/log.h> +#include <nativebridge/native_bridge.h> +#include <nativeloader/native_loader.h> #include <ziparchive/zip_archive.h> // TODO(jessehall): The whole way we deal with extensions is pretty hokey, and @@ -73,12 +75,14 @@ class LayerLibrary { : path_(path), filename_(filename), dlhandle_(nullptr), + native_bridge_(false), refcount_(0) {} LayerLibrary(LayerLibrary&& other) : path_(std::move(other.path_)), filename_(std::move(other.filename_)), dlhandle_(other.dlhandle_), + native_bridge_(other.native_bridge_), refcount_(other.refcount_) { other.dlhandle_ = nullptr; other.refcount_ = 0; @@ -101,6 +105,17 @@ class LayerLibrary { const std::string GetFilename() { return filename_; } private: + // TODO(b/79940628): remove that adapter when we could use NativeBridgeGetTrampoline + // for native libraries. + template<typename Func = void*> + Func GetTrampoline(const char* name) const { + if (native_bridge_) { + return reinterpret_cast<Func>(android::NativeBridgeGetTrampoline( + dlhandle_, name, nullptr, 0)); + } + return reinterpret_cast<Func>(dlsym(dlhandle_, name)); + } + const std::string path_; // Track the filename alone so we can detect duplicates @@ -108,6 +123,7 @@ class LayerLibrary { std::mutex mutex_; void* dlhandle_; + bool native_bridge_; size_t refcount_; }; @@ -123,19 +139,23 @@ bool LayerLibrary::Open() { auto app_namespace = android::GraphicsEnv::getInstance().getAppNamespace(); if (app_namespace && !android::base::StartsWith(path_, kSystemLayerLibraryDir)) { - android_dlextinfo dlextinfo = {}; - dlextinfo.flags = ANDROID_DLEXT_USE_NAMESPACE; - dlextinfo.library_namespace = app_namespace; - dlhandle_ = android_dlopen_ext(path_.c_str(), RTLD_NOW | RTLD_LOCAL, - &dlextinfo); + std::string error_msg; + dlhandle_ = OpenNativeLibrary( + app_namespace, path_.c_str(), &native_bridge_, &error_msg); + if (!dlhandle_) { + ALOGE("failed to load layer library '%s': %s", path_.c_str(), + error_msg.c_str()); + refcount_ = 0; + return false; + } } else { - dlhandle_ = dlopen(path_.c_str(), RTLD_NOW | RTLD_LOCAL); - } - if (!dlhandle_) { - ALOGE("failed to load layer library '%s': %s", path_.c_str(), - dlerror()); - refcount_ = 0; - return false; + dlhandle_ = dlopen(path_.c_str(), RTLD_NOW | RTLD_LOCAL); + if (!dlhandle_) { + ALOGE("failed to load layer library '%s': %s", path_.c_str(), + dlerror()); + refcount_ = 0; + return false; + } } } return true; @@ -153,11 +173,11 @@ void LayerLibrary::Close() { bool LayerLibrary::EnumerateLayers(size_t library_idx, std::vector<Layer>& instance_layers) const { PFN_vkEnumerateInstanceLayerProperties enumerate_instance_layers = - reinterpret_cast<PFN_vkEnumerateInstanceLayerProperties>( - dlsym(dlhandle_, "vkEnumerateInstanceLayerProperties")); + GetTrampoline<PFN_vkEnumerateInstanceLayerProperties>( + "vkEnumerateInstanceLayerProperties"); PFN_vkEnumerateInstanceExtensionProperties enumerate_instance_extensions = - reinterpret_cast<PFN_vkEnumerateInstanceExtensionProperties>( - dlsym(dlhandle_, "vkEnumerateInstanceExtensionProperties")); + GetTrampoline<PFN_vkEnumerateInstanceExtensionProperties>( + "vkEnumerateInstanceExtensionProperties"); if (!enumerate_instance_layers || !enumerate_instance_extensions) { ALOGE("layer library '%s' missing some instance enumeration functions", path_.c_str()); @@ -166,11 +186,11 @@ bool LayerLibrary::EnumerateLayers(size_t library_idx, // device functions are optional PFN_vkEnumerateDeviceLayerProperties enumerate_device_layers = - reinterpret_cast<PFN_vkEnumerateDeviceLayerProperties>( - dlsym(dlhandle_, "vkEnumerateDeviceLayerProperties")); + GetTrampoline<PFN_vkEnumerateDeviceLayerProperties>( + "vkEnumerateDeviceLayerProperties"); PFN_vkEnumerateDeviceExtensionProperties enumerate_device_extensions = - reinterpret_cast<PFN_vkEnumerateDeviceExtensionProperties>( - dlsym(dlhandle_, "vkEnumerateDeviceExtensionProperties")); + GetTrampoline<PFN_vkEnumerateDeviceExtensionProperties>( + "vkEnumerateDeviceExtensionProperties"); // get layer counts uint32_t num_instance_layers = 0; @@ -301,10 +321,10 @@ void* LayerLibrary::GetGPA(const Layer& layer, char* name = static_cast<char*>(alloca(layer_name_len + gpa_name_len + 1)); strcpy(name, layer.properties.layerName); strcpy(name + layer_name_len, gpa_name); - if (!(gpa = dlsym(dlhandle_, name))) { + if (!(gpa = GetTrampoline(name))) { strcpy(name, "vk"); strcpy(name + 2, gpa_name); - gpa = dlsym(dlhandle_, name); + gpa = GetTrampoline(name); } return gpa; } |