1 /* GDK - The GIMP Drawing Kit
2 *
3 * gdkvulkancontextprivate.h: 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 #ifndef __GDK_VULKAN_CONTEXT_PRIVATE__
22 #define __GDK_VULKAN_CONTEXT_PRIVATE__
23
24 #include "gdkvulkancontext.h"
25
26 #include "gdkdrawcontextprivate.h"
27 #include "gdkinternals.h"
28
29 #ifdef GDK_RENDERING_VULKAN
30 #include <vulkan/vulkan.h>
31 #endif
32
33 G_BEGIN_DECLS
34
35 #define GDK_VULKAN_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GDK_TYPE_VULKAN_CONTEXT, GdkVulkanContextClass))
36 #define GDK_IS_VULKAN_CONTEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GDK_TYPE_VULKAN_CONTEXT))
37 #define GDK_VULKAN_CONTEXT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GDK_TYPE_VULKAN_CONTEXT, GdkVulkanContextClass))
38
39 typedef struct _GdkVulkanContextClass GdkVulkanContextClass;
40
41 struct _GdkVulkanContext
42 {
43 GdkDrawContext parent_instance;
44 };
45
46 struct _GdkVulkanContextClass
47 {
48 GdkDrawContextClass parent_class;
49
50 #ifdef GDK_RENDERING_VULKAN
51 VkResult (* create_surface) (GdkVulkanContext *context,
52 VkSurfaceKHR *surface);
53 #endif
54 };
55
56 #ifdef GDK_RENDERING_VULKAN
57
58 static inline VkResult
gdk_vulkan_handle_result(VkResult res,const char * called_function)59 gdk_vulkan_handle_result (VkResult res,
60 const char *called_function)
61 {
62 if (res != VK_SUCCESS)
63 {
64 GDK_NOTE (VULKAN, g_printerr ("%s(): %s (%d)\n", called_function, gdk_vulkan_strerror (res), res));
65 }
66
67 return res;
68 }
69
70 #define GDK_VK_CHECK(func, ...) gdk_vulkan_handle_result (func (__VA_ARGS__), G_STRINGIFY (func))
71
72 gboolean gdk_display_ref_vulkan (GdkDisplay *display,
73 GError **error);
74 void gdk_display_unref_vulkan (GdkDisplay *display);
75
76 #else /* !GDK_RENDERING_VULKAN */
77
78
79 static inline gboolean
gdk_display_ref_vulkan(GdkDisplay * display,GError ** error)80 gdk_display_ref_vulkan (GdkDisplay *display,
81 GError **error)
82 {
83 GDK_DISPLAY_NOTE (display, VULKAN, g_message ("Support for Vulkan disabled at compile-time"));
84 g_set_error_literal (error, GDK_VULKAN_ERROR, GDK_VULKAN_ERROR_UNSUPPORTED,
85 "Vulkan support was not enabled at compile time.");
86
87 return FALSE;
88 }
89
90 #endif /* !GDK_RENDERING_VULKAN */
91
92 G_END_DECLS
93
94 #endif /* __GDK__VULKAN_CONTEXT_PRIVATE__ */
95