Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit bbf77003 authored by Victor Khimenko's avatar Victor Khimenko
Browse files

Add fallback case to layers_extensions.cpp

Bug: http://b/79940628

Test: cts-tradefed run commandAndExit cts -m CtsGpuToolsHostTestCases

Change-Id: If1485e3f845b781464eca9c6d2a6453baf61a4f5
Merged-In: I2881ff08cce5c129fd4b261814462d71d2c29a89
parent 5239def8
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -56,7 +56,7 @@ void GraphicsEnv::setDriverPath(const std::string path) {
    mDriverPath = 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()) {
    if (mLayerPaths.empty()) {
        mLayerPaths = layerPaths;
        mLayerPaths = layerPaths;
        mAppNamespace = appNamespace;
        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;
    return mAppNamespace;
}
}


+5 −3
Original line number Original line Diff line number Diff line
@@ -23,6 +23,8 @@ struct android_namespace_t;


namespace android {
namespace android {


class NativeLoaderNamespace;

class GraphicsEnv {
class GraphicsEnv {
public:
public:
    static GraphicsEnv& getInstance();
    static GraphicsEnv& getInstance();
@@ -35,8 +37,8 @@ public:
    void setDriverPath(const std::string path);
    void setDriverPath(const std::string path);
    android_namespace_t* getDriverNamespace();
    android_namespace_t* getDriverNamespace();


    void setLayerPaths(android_namespace_t* appNamespace, const std::string layerPaths);
    void setLayerPaths(NativeLoaderNamespace* appNamespace, const std::string layerPaths);
    android_namespace_t* getAppNamespace();
    NativeLoaderNamespace* getAppNamespace();
    const std::string getLayerPaths();
    const std::string getLayerPaths();


    void setDebugLayers(const std::string layers);
    void setDebugLayers(const std::string layers);
@@ -48,7 +50,7 @@ private:
    std::string mDebugLayers;
    std::string mDebugLayers;
    std::string mLayerPaths;
    std::string mLayerPaths;
    android_namespace_t* mDriverNamespace = nullptr;
    android_namespace_t* mDriverNamespace = nullptr;
    android_namespace_t* mAppNamespace = nullptr;
    NativeLoaderNamespace* mAppNamespace = nullptr;
};
};


} // namespace android
} // namespace android
+2 −0
Original line number Original line Diff line number Diff line
@@ -81,6 +81,8 @@ cc_library_shared {
        "libutils",
        "libutils",
        "libcutils",
        "libcutils",
        "libz",
        "libz",
        "libnativebridge",
        "libnativeloader",
        "libnativewindow",
        "libnativewindow",
        "android.hardware.graphics.common@1.0",
        "android.hardware.graphics.common@1.0",
    ],
    ],
+42 −22
Original line number Original line Diff line number Diff line
@@ -31,6 +31,8 @@
#include <cutils/properties.h>
#include <cutils/properties.h>
#include <graphicsenv/GraphicsEnv.h>
#include <graphicsenv/GraphicsEnv.h>
#include <log/log.h>
#include <log/log.h>
#include <nativebridge/native_bridge.h>
#include <nativeloader/native_loader.h>
#include <ziparchive/zip_archive.h>
#include <ziparchive/zip_archive.h>


// TODO(jessehall): The whole way we deal with extensions is pretty hokey, and
// TODO(jessehall): The whole way we deal with extensions is pretty hokey, and
@@ -73,12 +75,14 @@ class LayerLibrary {
        : path_(path),
        : path_(path),
          filename_(filename),
          filename_(filename),
          dlhandle_(nullptr),
          dlhandle_(nullptr),
          native_bridge_(false),
          refcount_(0) {}
          refcount_(0) {}


    LayerLibrary(LayerLibrary&& other)
    LayerLibrary(LayerLibrary&& other)
        : path_(std::move(other.path_)),
        : path_(std::move(other.path_)),
          filename_(std::move(other.filename_)),
          filename_(std::move(other.filename_)),
          dlhandle_(other.dlhandle_),
          dlhandle_(other.dlhandle_),
          native_bridge_(other.native_bridge_),
          refcount_(other.refcount_) {
          refcount_(other.refcount_) {
        other.dlhandle_ = nullptr;
        other.dlhandle_ = nullptr;
        other.refcount_ = 0;
        other.refcount_ = 0;
@@ -101,6 +105,17 @@ class LayerLibrary {
    const std::string GetFilename() { return filename_; }
    const std::string GetFilename() { return filename_; }


   private:
   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_;
    const std::string path_;


    // Track the filename alone so we can detect duplicates
    // Track the filename alone so we can detect duplicates
@@ -108,6 +123,7 @@ class LayerLibrary {


    std::mutex mutex_;
    std::mutex mutex_;
    void* dlhandle_;
    void* dlhandle_;
    bool native_bridge_;
    size_t refcount_;
    size_t refcount_;
};
};


@@ -123,14 +139,17 @@ bool LayerLibrary::Open() {
        auto app_namespace = android::GraphicsEnv::getInstance().getAppNamespace();
        auto app_namespace = android::GraphicsEnv::getInstance().getAppNamespace();
        if (app_namespace &&
        if (app_namespace &&
            !android::base::StartsWith(path_, kSystemLayerLibraryDir)) {
            !android::base::StartsWith(path_, kSystemLayerLibraryDir)) {
            android_dlextinfo dlextinfo = {};
            std::string error_msg;
            dlextinfo.flags = ANDROID_DLEXT_USE_NAMESPACE;
            dlhandle_ = OpenNativeLibrary(
            dlextinfo.library_namespace = app_namespace;
                app_namespace, path_.c_str(), &native_bridge_, &error_msg);
            dlhandle_ = android_dlopen_ext(path_.c_str(), RTLD_NOW | RTLD_LOCAL,
            if (!dlhandle_) {
                                           &dlextinfo);
                ALOGE("failed to load layer library '%s': %s", path_.c_str(),
                      error_msg.c_str());
                refcount_ = 0;
                return false;
            }
        } else {
        } else {
          dlhandle_ = dlopen(path_.c_str(), RTLD_NOW | RTLD_LOCAL);
          dlhandle_ = dlopen(path_.c_str(), RTLD_NOW | RTLD_LOCAL);
        }
            if (!dlhandle_) {
            if (!dlhandle_) {
                ALOGE("failed to load layer library '%s': %s", path_.c_str(),
                ALOGE("failed to load layer library '%s': %s", path_.c_str(),
                      dlerror());
                      dlerror());
@@ -138,6 +157,7 @@ bool LayerLibrary::Open() {
                return false;
                return false;
            }
            }
        }
        }
    }
    return true;
    return true;
}
}


@@ -153,11 +173,11 @@ void LayerLibrary::Close() {
bool LayerLibrary::EnumerateLayers(size_t library_idx,
bool LayerLibrary::EnumerateLayers(size_t library_idx,
                                   std::vector<Layer>& instance_layers) const {
                                   std::vector<Layer>& instance_layers) const {
    PFN_vkEnumerateInstanceLayerProperties enumerate_instance_layers =
    PFN_vkEnumerateInstanceLayerProperties enumerate_instance_layers =
        reinterpret_cast<PFN_vkEnumerateInstanceLayerProperties>(
        GetTrampoline<PFN_vkEnumerateInstanceLayerProperties>(
            dlsym(dlhandle_, "vkEnumerateInstanceLayerProperties"));
            "vkEnumerateInstanceLayerProperties");
    PFN_vkEnumerateInstanceExtensionProperties enumerate_instance_extensions =
    PFN_vkEnumerateInstanceExtensionProperties enumerate_instance_extensions =
        reinterpret_cast<PFN_vkEnumerateInstanceExtensionProperties>(
        GetTrampoline<PFN_vkEnumerateInstanceExtensionProperties>(
            dlsym(dlhandle_, "vkEnumerateInstanceExtensionProperties"));
            "vkEnumerateInstanceExtensionProperties");
    if (!enumerate_instance_layers || !enumerate_instance_extensions) {
    if (!enumerate_instance_layers || !enumerate_instance_extensions) {
        ALOGE("layer library '%s' missing some instance enumeration functions",
        ALOGE("layer library '%s' missing some instance enumeration functions",
              path_.c_str());
              path_.c_str());
@@ -166,11 +186,11 @@ bool LayerLibrary::EnumerateLayers(size_t library_idx,


    // device functions are optional
    // device functions are optional
    PFN_vkEnumerateDeviceLayerProperties enumerate_device_layers =
    PFN_vkEnumerateDeviceLayerProperties enumerate_device_layers =
        reinterpret_cast<PFN_vkEnumerateDeviceLayerProperties>(
        GetTrampoline<PFN_vkEnumerateDeviceLayerProperties>(
            dlsym(dlhandle_, "vkEnumerateDeviceLayerProperties"));
            "vkEnumerateDeviceLayerProperties");
    PFN_vkEnumerateDeviceExtensionProperties enumerate_device_extensions =
    PFN_vkEnumerateDeviceExtensionProperties enumerate_device_extensions =
        reinterpret_cast<PFN_vkEnumerateDeviceExtensionProperties>(
        GetTrampoline<PFN_vkEnumerateDeviceExtensionProperties>(
            dlsym(dlhandle_, "vkEnumerateDeviceExtensionProperties"));
            "vkEnumerateDeviceExtensionProperties");


    // get layer counts
    // get layer counts
    uint32_t num_instance_layers = 0;
    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));
    char* name = static_cast<char*>(alloca(layer_name_len + gpa_name_len + 1));
    strcpy(name, layer.properties.layerName);
    strcpy(name, layer.properties.layerName);
    strcpy(name + layer_name_len, gpa_name);
    strcpy(name + layer_name_len, gpa_name);
    if (!(gpa = dlsym(dlhandle_, name))) {
    if (!(gpa = GetTrampoline(name))) {
        strcpy(name, "vk");
        strcpy(name, "vk");
        strcpy(name + 2, gpa_name);
        strcpy(name + 2, gpa_name);
        gpa = dlsym(dlhandle_, name);
        gpa = GetTrampoline(name);
    }
    }
    return gpa;
    return gpa;
}
}