1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 #ifndef LIBVULKAN_DRIVER_LOADER_H 16 #define LIBVULKAN_DRIVER_LOADER_H 17 18 #include <string> 19 20 #include "hardware/hdi_vulkan.h" 21 namespace vulkan { 22 namespace driver { 23 typedef int32_t (*PFN_VulkanInitialize)(VulkanFuncs **funcs); 24 typedef int32_t (*PFN_VulkanUnInitialize)(VulkanFuncs *funcs); 25 class DriverLoader { 26 public: 27 static bool Load(); 28 static bool Unload(); 29 static bool LoadDriver(); 30 static bool UnloadDriver(); 31 static bool LoadDriverFromFile(std::string path); 32 Get()33static const DriverLoader& Get() 34 { 35 return loader_; 36 } 37 GetVulkanFuncs()38static const VulkanFuncs& GetVulkanFuncs() 39 { 40 return *Get().vulkanFuncs_; 41 } 42 IsSupportedVulkan()43static bool IsSupportedVulkan() 44 { 45 return Get().supported_; 46 } 47 48 private: DriverLoader()49DriverLoader() : vulkanFuncs_(nullptr), vulkanUnInitializeFunc_(nullptr) {} 50 DriverLoader(const DriverLoader&) = delete; 51 DriverLoader& operator=(const DriverLoader&) = delete; 52 53 static DriverLoader loader_; 54 void* handle_; 55 56 bool supported_; 57 VulkanFuncs* vulkanFuncs_; 58 PFN_VulkanUnInitialize vulkanUnInitializeFunc_; 59 }; 60 } // namespace driver 61 } // namespace vulkan 62 #endif // LIBVULKAN_DRIVER_LOADER_H 63