1 | /* gdkvulkancontext-wayland.c |
2 | * |
3 | * gdkvulkancontext-wayland.c: Wayland specific Vulkan wrappers |
4 | * |
5 | * Copyright (C) 2017 Georges Basile Stavracas Neto <georges.stavracas@gmail.com> |
6 | * |
7 | * This file is free software; you can redistribute it and/or modify it |
8 | * under the terms of the GNU Lesser General Public License as |
9 | * published by the Free Software Foundation; either version 2 of the |
10 | * License, or (at your option) any later version. |
11 | * |
12 | * This file is distributed in the hope that it will be useful, but |
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
15 | * Lesser General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU General Public License |
18 | * along with this program. 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-wayland.h" |
28 | |
29 | #include "gdkwaylanddisplay.h" |
30 | #include "gdkwaylandsurface.h" |
31 | #include "gdkprivate-wayland.h" |
32 | |
33 | G_DEFINE_TYPE (GdkWaylandVulkanContext, gdk_wayland_vulkan_context, GDK_TYPE_VULKAN_CONTEXT) |
34 | |
35 | static VkResult |
36 | gdk_wayland_vulkan_context_create_surface (GdkVulkanContext *context, |
37 | VkSurfaceKHR *vr_surface) |
38 | { |
39 | GdkSurface *surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context)); |
40 | GdkDisplay *display = gdk_draw_context_get_display (GDK_DRAW_CONTEXT (context)); |
41 | |
42 | /* This is necessary so that Vulkan sees the Surface. |
43 | * Usually, vkCreateXlibSurfaceKHR() will not cause a problem to happen as |
44 | * it just creates resources, but further calls with the resulting surface |
45 | * do cause issues. |
46 | */ |
47 | gdk_display_sync (display); |
48 | |
49 | return GDK_VK_CHECK (vkCreateWaylandSurfaceKHR, gdk_vulkan_context_get_instance (context), |
50 | &(VkWaylandSurfaceCreateInfoKHR) { |
51 | VK_STRUCTURE_TYPE_WAYLAND_SURFACE_CREATE_INFO_KHR, |
52 | NULL, |
53 | 0, |
54 | gdk_wayland_display_get_wl_display (display), |
55 | gdk_wayland_surface_get_wl_surface (surface) |
56 | }, |
57 | NULL, |
58 | vr_surface); |
59 | } |
60 | |
61 | static void |
62 | gdk_vulkan_context_wayland_end_frame (GdkDrawContext *context, |
63 | cairo_region_t *painted) |
64 | { |
65 | GdkSurface *surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context)); |
66 | |
67 | gdk_wayland_surface_sync (surface); |
68 | gdk_wayland_surface_request_frame (surface); |
69 | |
70 | GDK_DRAW_CONTEXT_CLASS (gdk_wayland_vulkan_context_parent_class)->end_frame (context, painted); |
71 | |
72 | gdk_wayland_surface_notify_committed (surface); |
73 | } |
74 | |
75 | static void |
76 | gdk_wayland_vulkan_context_class_init (GdkWaylandVulkanContextClass *klass) |
77 | { |
78 | GdkVulkanContextClass *vulkan_context_class = GDK_VULKAN_CONTEXT_CLASS (klass); |
79 | GdkDrawContextClass *draw_context_class = GDK_DRAW_CONTEXT_CLASS (klass); |
80 | |
81 | vulkan_context_class->create_surface = gdk_wayland_vulkan_context_create_surface; |
82 | draw_context_class->end_frame = gdk_vulkan_context_wayland_end_frame; |
83 | } |
84 | |
85 | static void |
86 | gdk_wayland_vulkan_context_init (GdkWaylandVulkanContext *self) |
87 | { |
88 | } |
89 | |
90 | #endif /* GDK_RENDERING_VULKAN */ |
91 | |
92 | |