From 4278a30e6396d69e721fd6620efcb33f9d38acc6 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 13 Apr 2021 00:54:09 +0200 Subject: [PATCH] winevulkan: Move registration functions to new loader.c file. Signed-off-by: Jacek Caban Signed-off-by: Alexandre Julliard --- dlls/winevulkan/Makefile.in | 1 + dlls/winevulkan/loader.c | 104 ++++++++++++++++++++++++++++++++++++ dlls/winevulkan/vulkan.c | 75 -------------------------- 3 files changed, 105 insertions(+), 75 deletions(-) create mode 100644 dlls/winevulkan/loader.c diff --git a/dlls/winevulkan/Makefile.in b/dlls/winevulkan/Makefile.in index 61ab6a127a5..1ba76407f91 100644 --- a/dlls/winevulkan/Makefile.in +++ b/dlls/winevulkan/Makefile.in @@ -4,6 +4,7 @@ IMPORTS = user32 gdi32 advapi32 setupapi EXTRALIBS = $(PTHREAD_LIBS) C_SRCS = \ + loader.c \ vulkan.c \ vulkan_thunks.c diff --git a/dlls/winevulkan/loader.c b/dlls/winevulkan/loader.c new file mode 100644 index 00000000000..f40b058e0ee --- /dev/null +++ b/dlls/winevulkan/loader.c @@ -0,0 +1,104 @@ +/* Wine Vulkan ICD implementation + * + * Copyright 2017 Roderick Colenbrander + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include + +#include "windef.h" +#include "winbase.h" +#include "winreg.h" +#include "winuser.h" + +#include "vulkan_private.h" + +WINE_DEFAULT_DEBUG_CHANNEL(vulkan); + +static HINSTANCE hinstance; + +BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, void *reserved) +{ + TRACE("%p, %u, %p\n", hinst, reason, reserved); + + switch (reason) + { + case DLL_PROCESS_ATTACH: + hinstance = hinst; + DisableThreadLibraryCalls(hinst); + break; + } + return TRUE; +} + +static const WCHAR winevulkan_json_resW[] = {'w','i','n','e','v','u','l','k','a','n','_','j','s','o','n',0}; +static const WCHAR winevulkan_json_pathW[] = {'\\','w','i','n','e','v','u','l','k','a','n','.','j','s','o','n',0}; +static const WCHAR vulkan_driversW[] = {'S','o','f','t','w','a','r','e','\\','K','h','r','o','n','o','s','\\', + 'V','u','l','k','a','n','\\','D','r','i','v','e','r','s',0}; + +HRESULT WINAPI DllRegisterServer(void) +{ + WCHAR json_path[MAX_PATH]; + HRSRC rsrc; + const char *data; + DWORD datalen, written, zero = 0; + HANDLE file; + HKEY key; + + /* Create the JSON manifest and registry key to register this ICD with the official Vulkan loader. */ + TRACE("\n"); + rsrc = FindResourceW(hinstance, winevulkan_json_resW, (const WCHAR *)RT_RCDATA); + data = LockResource(LoadResource(hinstance, rsrc)); + datalen = SizeofResource(hinstance, rsrc); + + GetSystemDirectoryW(json_path, ARRAY_SIZE(json_path)); + lstrcatW(json_path, winevulkan_json_pathW); + file = CreateFileW(json_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); + if (file == INVALID_HANDLE_VALUE) + { + ERR("Unable to create JSON manifest.\n"); + return E_UNEXPECTED; + } + WriteFile(file, data, datalen, &written, NULL); + CloseHandle(file); + + if (!RegCreateKeyExW(HKEY_LOCAL_MACHINE, vulkan_driversW, 0, NULL, 0, KEY_SET_VALUE, NULL, &key, NULL)) + { + RegSetValueExW(key, json_path, 0, REG_DWORD, (const BYTE *)&zero, sizeof(zero)); + RegCloseKey(key); + } + return S_OK; +} + +HRESULT WINAPI DllUnregisterServer(void) +{ + WCHAR json_path[MAX_PATH]; + HKEY key; + + /* Remove the JSON manifest and registry key */ + TRACE("\n"); + GetSystemDirectoryW(json_path, ARRAY_SIZE(json_path)); + lstrcatW(json_path, winevulkan_json_pathW); + DeleteFileW(json_path); + + if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, vulkan_driversW, 0, KEY_SET_VALUE, &key) == ERROR_SUCCESS) + { + RegDeleteValueW(key, json_path); + RegCloseKey(key); + } + + return S_OK; +} diff --git a/dlls/winevulkan/vulkan.c b/dlls/winevulkan/vulkan.c index 0b47aa1d3e2..aff2cb933af 100644 --- a/dlls/winevulkan/vulkan.c +++ b/dlls/winevulkan/vulkan.c @@ -73,7 +73,6 @@ static uint32_t wine_vk_count_struct_(void *s, VkStructureType t) static void *wine_vk_get_global_proc_addr(const char *name); -static HINSTANCE hinstance; static const struct vulkan_funcs *vk_funcs; static VkResult (*p_vkEnumerateInstanceVersion)(uint32_t *version); @@ -2105,20 +2104,6 @@ VkResult WINAPI wine_vkDebugMarkerSetObjectNameEXT(VkDevice device, const VkDebu return thunk_vkDebugMarkerSetObjectNameEXT(device, &wine_name_info); } -BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, void *reserved) -{ - TRACE("%p, %u, %p\n", hinst, reason, reserved); - - switch (reason) - { - case DLL_PROCESS_ATTACH: - hinstance = hinst; - DisableThreadLibraryCalls(hinst); - break; - } - return TRUE; -} - static const struct vulkan_func vk_global_dispatch_table[] = { /* These functions must call wine_vk_init_once() before accessing vk_funcs. */ @@ -2157,63 +2142,3 @@ void *native_vkGetInstanceProcAddrWINE(VkInstance instance, const char *name) return vk_funcs->p_vkGetInstanceProcAddr(instance, name); } - - -static const WCHAR winevulkan_json_resW[] = {'w','i','n','e','v','u','l','k','a','n','_','j','s','o','n',0}; -static const WCHAR winevulkan_json_pathW[] = {'\\','w','i','n','e','v','u','l','k','a','n','.','j','s','o','n',0}; -static const WCHAR vulkan_driversW[] = {'S','o','f','t','w','a','r','e','\\','K','h','r','o','n','o','s','\\', - 'V','u','l','k','a','n','\\','D','r','i','v','e','r','s',0}; - -HRESULT WINAPI DllRegisterServer(void) -{ - WCHAR json_path[MAX_PATH]; - HRSRC rsrc; - const char *data; - DWORD datalen, written, zero = 0; - HANDLE file; - HKEY key; - - /* Create the JSON manifest and registry key to register this ICD with the official Vulkan loader. */ - TRACE("\n"); - rsrc = FindResourceW(hinstance, winevulkan_json_resW, (const WCHAR *)RT_RCDATA); - data = LockResource(LoadResource(hinstance, rsrc)); - datalen = SizeofResource(hinstance, rsrc); - - GetSystemDirectoryW(json_path, ARRAY_SIZE(json_path)); - lstrcatW(json_path, winevulkan_json_pathW); - file = CreateFileW(json_path, GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL); - if (file == INVALID_HANDLE_VALUE) - { - ERR("Unable to create JSON manifest.\n"); - return E_UNEXPECTED; - } - WriteFile(file, data, datalen, &written, NULL); - CloseHandle(file); - - if (!RegCreateKeyExW(HKEY_LOCAL_MACHINE, vulkan_driversW, 0, NULL, 0, KEY_SET_VALUE, NULL, &key, NULL)) - { - RegSetValueExW(key, json_path, 0, REG_DWORD, (const BYTE *)&zero, sizeof(zero)); - RegCloseKey(key); - } - return S_OK; -} - -HRESULT WINAPI DllUnregisterServer(void) -{ - WCHAR json_path[MAX_PATH]; - HKEY key; - - /* Remove the JSON manifest and registry key */ - TRACE("\n"); - GetSystemDirectoryW(json_path, ARRAY_SIZE(json_path)); - lstrcatW(json_path, winevulkan_json_pathW); - DeleteFileW(json_path); - - if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, vulkan_driversW, 0, KEY_SET_VALUE, &key) == ERROR_SUCCESS) - { - RegDeleteValueW(key, json_path); - RegCloseKey(key); - } - - return S_OK; -}