1 | /* GDK - The GIMP Drawing Kit |
2 | * |
3 | * gdkvulkancontext-x11.c: X11 specific Vulkan wrappers |
4 | * |
5 | * Copyright © 2016 Benjamin Otte |
6 | * |
7 | * This library is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU Library General Public |
9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. |
11 | * |
12 | * This library is distributed in the hope that it will be useful, |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | * Library General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU Library General Public |
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
19 | */ |
20 | |
21 | #include "config.h" |
22 | |
23 | #include "gdkconfig.h" |
24 | |
25 | #ifdef GDK_RENDERING_VULKAN |
26 | |
27 | #include "gdkvulkancontext-x11.h" |
28 | |
29 | #include "gdkdisplay-x11.h" |
30 | #include "gdksurface-x11.h" |
31 | |
32 | G_DEFINE_TYPE (GdkX11VulkanContext, gdk_x11_vulkan_context, GDK_TYPE_VULKAN_CONTEXT) |
33 | |
34 | static VkResult |
35 | gdk_x11_vulkan_context_create_surface (GdkVulkanContext *context, |
36 | VkSurfaceKHR *surface) |
37 | { |
38 | GdkSurface *window = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context)); |
39 | GdkDisplay *display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context)); |
40 | |
41 | /* This is necessary so that Vulkan sees the Window. |
42 | * Usually, vkCreateXlibSurfaceKHR() will not cause a problem to happen as |
43 | * it just creates resources, but further calls with the resulting surface |
44 | * do cause issues. |
45 | */ |
46 | gdk_display_sync (display); |
47 | |
48 | return GDK_VK_CHECK (vkCreateXlibSurfaceKHR, gdk_vulkan_context_get_instance (context), |
49 | &(VkXlibSurfaceCreateInfoKHR) { |
50 | VK_STRUCTURE_TYPE_XLIB_SURFACE_CREATE_INFO_KHR, |
51 | NULL, |
52 | 0, |
53 | gdk_x11_display_get_xdisplay (display), |
54 | gdk_x11_surface_get_xid (window) |
55 | }, |
56 | NULL, |
57 | surface); |
58 | } |
59 | |
60 | static void |
61 | gdk_x11_vulkan_context_end_frame (GdkDrawContext *context, |
62 | cairo_region_t *painted) |
63 | { |
64 | GdkSurface *surface = gdk_draw_context_get_surface (context); |
65 | |
66 | gdk_x11_surface_pre_damage (surface); |
67 | |
68 | GDK_DRAW_CONTEXT_CLASS (gdk_x11_vulkan_context_parent_class)->end_frame (context, painted); |
69 | } |
70 | |
71 | static void |
72 | gdk_x11_vulkan_context_class_init (GdkX11VulkanContextClass *klass) |
73 | { |
74 | GdkVulkanContextClass *context_class = GDK_VULKAN_CONTEXT_CLASS (klass); |
75 | GdkDrawContextClass *draw_context_class = GDK_DRAW_CONTEXT_CLASS (klass); |
76 | |
77 | draw_context_class->end_frame = gdk_x11_vulkan_context_end_frame; |
78 | |
79 | context_class->create_surface = gdk_x11_vulkan_context_create_surface; |
80 | } |
81 | |
82 | static void |
83 | gdk_x11_vulkan_context_init (GdkX11VulkanContext *self) |
84 | { |
85 | } |
86 | |
87 | #endif /* GDK_RENDERING_VULKAN */ |
88 | |
89 | |