From 4cc738f609faff68bf4c67d5618174fa87ab3cdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20H=C3=A4dicke?= Date: Wed, 10 Jul 2019 22:19:31 +0200 Subject: [PATCH] winex11.drv: Support child window rendering for Vulkan via XComposite MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45277 Signed-off-by: Felix Hädicke --- dlls/winex11.drv/vulkan.c | 56 ++++++++++++++++++++++++++++++++------- 1 file changed, 47 insertions(+), 9 deletions(-) diff --git a/dlls/winex11.drv/vulkan.c b/dlls/winex11.drv/vulkan.c index 28ae1a9e0e8..3b0bf58c107 100644 --- a/dlls/winex11.drv/vulkan.c +++ b/dlls/winex11.drv/vulkan.c @@ -32,6 +32,7 @@ #include "wine/debug.h" #include "wine/heap.h" #include "x11drv.h" +#include "xcomposite.h" #define VK_NO_PROTOTYPES #define WINE_VK_HOST @@ -56,6 +57,7 @@ static CRITICAL_SECTION context_section = { &critsect_debug, -1, 0, 0, 0, 0 }; static XContext vulkan_hwnd_context; +static XContext vulkan_swapchain_surface_context; #define VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR 1000004000 @@ -63,6 +65,7 @@ { LONG ref; Window window; + HDC child_window_dc; VkSurfaceKHR surface; /* native surface */ }; @@ -95,6 +98,7 @@ static VkBool32 (*pvkGetPhysicalDeviceXlibPresentationSupportKHR)(VkPhysicalDevice, uint32_t, Display *, VisualID); static VkResult (*pvkGetSwapchainImagesKHR)(VkDevice, VkSwapchainKHR, uint32_t *, VkImage *); static VkResult (*pvkQueuePresentKHR)(VkQueue, const VkPresentInfoKHR *); +static VkResult (*pvkQueueWaitIdle)(VkQueue); static void *X11DRV_get_vk_device_proc_addr(const char *name); static void *X11DRV_get_vk_instance_proc_addr(VkInstance instance, const char *name); @@ -142,12 +146,14 @@ LOAD_FUNCPTR(vkGetPhysicalDeviceXlibPresentationSupportKHR); LOAD_FUNCPTR(vkGetSwapchainImagesKHR); LOAD_FUNCPTR(vkQueuePresentKHR); + LOAD_FUNCPTR(vkQueueWaitIdle); LOAD_OPTIONAL_FUNCPTR(vkGetDeviceGroupSurfacePresentModesKHR); LOAD_OPTIONAL_FUNCPTR(vkGetPhysicalDevicePresentRectanglesKHR); #undef LOAD_FUNCPTR #undef LOAD_OPTIONAL_FUNCPTR vulkan_hwnd_context = XUniqueContext(); + vulkan_swapchain_surface_context = XUniqueContext(); return TRUE; @@ -265,16 +271,24 @@ const VkSwapchainCreateInfoKHR *create_info, const VkAllocationCallbacks *allocator, VkSwapchainKHR *swapchain) { + VkResult res; VkSwapchainCreateInfoKHR create_info_host; + struct wine_vk_surface *x11_surface = surface_from_handle(create_info->surface); + TRACE("%p %p %p %p\n", device, create_info, allocator, swapchain); if (allocator) FIXME("Support for allocation callbacks not implemented yet\n"); create_info_host = *create_info; - create_info_host.surface = surface_from_handle(create_info->surface)->surface; + create_info_host.surface = x11_surface->surface; - return pvkCreateSwapchainKHR(device, &create_info_host, NULL /* allocator */, swapchain); + res = pvkCreateSwapchainKHR(device, &create_info_host, NULL /* allocator */, swapchain); + if (res == VK_SUCCESS) + { + XSaveContext(gdi_display, (XID)(*swapchain), vulkan_swapchain_surface_context, (char *)x11_surface); + } + return res; } static VkResult X11DRV_vkCreateWin32SurfaceKHR(VkInstance instance, @@ -290,13 +304,6 @@ if (allocator) FIXME("Support for allocation callbacks not implemented yet\n"); - /* TODO: support child window rendering. */ - if (GetAncestor(create_info->hwnd, GA_PARENT) != GetDesktopWindow()) - { - FIXME("Application requires child window rendering, which is not implemented yet!\n"); - return VK_ERROR_INCOMPATIBLE_DRIVER; - } - x11_surface = heap_alloc_zero(sizeof(*x11_surface)); if (!x11_surface) return VK_ERROR_OUT_OF_HOST_MEMORY; @@ -313,6 +320,23 @@ goto err; } + /* child window rendering. */ + if (GetAncestor(create_info->hwnd, GA_PARENT) != GetDesktopWindow()) + { +#ifdef SONAME_LIBXCOMPOSITE + if (usexcomposite) + { + pXCompositeRedirectWindow(gdi_display, x11_surface->window, CompositeRedirectManual); + x11_surface->child_window_dc = GetDC(create_info->hwnd); + } + else +#endif + { + FIXME("Child window rendering is not supported without X Composite Extension!\n"); + return VK_ERROR_INCOMPATIBLE_DRIVER; + } + } + create_info_host.sType = VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR; create_info_host.pNext = NULL; create_info_host.flags = 0; /* reserved */ @@ -382,6 +406,7 @@ FIXME("Support for allocation callbacks not implemented yet\n"); pvkDestroySwapchainKHR(device, swapchain, NULL /* allocator */); + XDeleteContext(gdi_display, (XID)swapchain, vulkan_swapchain_surface_context); } static VkResult X11DRV_vkEnumerateInstanceExtensionProperties(const char *layer_name, @@ -608,6 +633,22 @@ } } + for (uint32_t i = 0 ; i < present_info->swapchainCount; ++i) + { + struct wine_vk_surface *x11_surface; + if (!XFindContext(gdi_display, (XID)present_info->pSwapchains[i], + vulkan_swapchain_surface_context, (char **)&x11_surface) && + x11_surface->child_window_dc) + { + struct x11drv_escape_flush_gl_drawable escape; + escape.code = X11DRV_FLUSH_GL_DRAWABLE; + escape.gl_drawable = x11_surface->window; + escape.flush = TRUE; + pvkQueueWaitIdle(queue); + ExtEscape(x11_surface->child_window_dc, X11DRV_ESCAPE, sizeof(escape), (LPSTR)&escape, 0, NULL); + } + } + return res; }