| /* | |
| * Copyright (C) 2026 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. | |
| */ | |
| #ifndef ANDROID_VULKAN_LAYERS_DISCOVERED_LAYER_LIBRARY_H | |
| #define ANDROID_VULKAN_LAYERS_DISCOVERED_LAYER_LIBRARY_H | |
| #pragma once | |
| #include <map> | |
| #include <memory> | |
| #include <mutex> | |
| #include <string> | |
| namespace vulkan { | |
| namespace layers { | |
| class LayerEnvironment; | |
| class DynamicLibrary; | |
| enum class LayerType { Explicit, Implicit, System }; | |
| // Well-known paths that some layer libraries live in | |
| inline const char kSystemDebugLayerLibraryDir[] = "/data/local/debug/vulkan"; | |
| #if defined(__LP64__) | |
| #define LIBDIR "lib64" | |
| #else | |
| #define LIBDIR "lib" | |
| #endif | |
| const char kSystemPlatformLayerLibraryDir[] = "/system/" LIBDIR "/vulkan"; | |
| const char kSystemSoCLayerLibraryDir[] = "/system_ext/" LIBDIR "/vulkan"; | |
| const char kSystemOEMLayerLibraryDir[] = "/product/" LIBDIR "/vulkan"; | |
| const char kGraphicsMainlineModuleDir[] = "/apex/com.android.graphics/" LIBDIR; | |
| // This class encapsulates an individual layer library file that the loader | |
| // discovered. | |
| class DiscoveredLayerLibrary { | |
| public: | |
| DiscoveredLayerLibrary(std::string path, | |
| std::string filename, | |
| LayerType type) | |
| : path_(std::move(path)), filename_(std::move(filename)), type_(type) {} | |
| const std::string& GetPath() const { return path_; } | |
| const std::string& GetFilename() const { return filename_; } | |
| LayerType GetType() const { return type_; } | |
| void AddLayer(int order, std::string name) { | |
| layer_names_.insert({order, std::move(name)}); | |
| } | |
| const std::multimap<int, std::string>& GetLayerNames() const { | |
| return layer_names_; | |
| } | |
| // An automatic unloading (RAII) design pattern is used, so that only an | |
| // Open() method is needed (Close() happens implicitly). | |
| std::shared_ptr<DynamicLibrary> Open(const LayerEnvironment& env) const; | |
| private: | |
| std::string path_; | |
| std::string filename_; | |
| LayerType type_; | |
| // For system layers, maps order to layer name. | |
| std::multimap<int, std::string> layer_names_; | |
| mutable std::mutex mutex_; | |
| // This is the smart pointer used as part of the RAII design pattern | |
| mutable std::weak_ptr<DynamicLibrary> loaded_lib_; | |
| }; | |
| } // namespace layers | |
| } // namespace vulkan | |
| #endif // ANDROID_VULKAN_LAYERS_DISCOVERED_LAYER_LIBRARY_H |