From 3ac50b81f241b980ff7de073e4695797c92d1e5a Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Sun, 7 Jan 2024 13:54:49 +0100 Subject: [PATCH] vulkan: Make gdk_display_create_vulkan_context() take a surface This is so we can deprecate gdk_surface_create_vulkan_context() which is public API in the next commit. --- gdk/gdkdisplay.c | 29 ++++++++++++++++++++++------- gdk/gdkdisplayprivate.h | 1 + gsk/gpu/gskvulkanrenderer.c | 6 +----- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/gdk/gdkdisplay.c b/gdk/gdkdisplay.c index 00182bfba2..9f51bce222 100644 --- a/gdk/gdkdisplay.c +++ b/gdk/gdkdisplay.c @@ -1267,12 +1267,14 @@ gdk_display_get_keymap (GdkDisplay *display) /* * gdk_display_create_vulkan_context: * @self: a `GdkDisplay` + * @surface: (nullable): the `GdkSurface` to use or %NULL for a surfaceless + * context * @error: return location for an error * * Creates a new `GdkVulkanContext` for use with @display. * - * The context can not be used to draw to surfaces, it can only be - * used for custom rendering or compute. + * If @surface is NULL, the context can not be used to draw to surfaces, + * it can only be used for custom rendering or compute. * * If the creation of the `GdkVulkanContext` failed, @error will be set. * @@ -1281,9 +1283,11 @@ gdk_display_get_keymap (GdkDisplay *display) */ GdkVulkanContext * gdk_display_create_vulkan_context (GdkDisplay *self, + GdkSurface *surface, GError **error) { g_return_val_if_fail (GDK_IS_DISPLAY (self), NULL); + g_return_val_if_fail (surface == NULL || GDK_IS_SURFACE (surface), NULL); g_return_val_if_fail (error == NULL || *error == NULL, NULL); if (gdk_display_get_debug_flags (self) & GDK_DEBUG_VULKAN_DISABLE) @@ -1300,11 +1304,22 @@ gdk_display_create_vulkan_context (GdkDisplay *self, return FALSE; } - return g_initable_new (GDK_DISPLAY_GET_CLASS (self)->vk_context_type, - NULL, - error, - "display", self, - NULL); + if (surface) + { + return g_initable_new (GDK_DISPLAY_GET_CLASS (self)->vk_context_type, + NULL, + error, + "surface", surface, + NULL); + } + else + { + return g_initable_new (GDK_DISPLAY_GET_CLASS (self)->vk_context_type, + NULL, + error, + "display", self, + NULL); + } } gboolean diff --git a/gdk/gdkdisplayprivate.h b/gdk/gdkdisplayprivate.h index a655ed33b3..0c2f9355f7 100644 --- a/gdk/gdkdisplayprivate.h +++ b/gdk/gdkdisplayprivate.h @@ -236,6 +236,7 @@ void gdk_display_init_dmabuf (GdkDisplay *self); gboolean gdk_display_has_vulkan_feature (GdkDisplay *self, GdkVulkanFeatures feature); GdkVulkanContext * gdk_display_create_vulkan_context (GdkDisplay *self, + GdkSurface *surface, GError **error); GdkGLContext * gdk_display_get_gl_context (GdkDisplay *display); diff --git a/gsk/gpu/gskvulkanrenderer.c b/gsk/gpu/gskvulkanrenderer.c index eee7ec26b5..997a6d9448 100644 --- a/gsk/gpu/gskvulkanrenderer.c +++ b/gsk/gpu/gskvulkanrenderer.c @@ -89,11 +89,7 @@ gsk_vulkan_renderer_create_context (GskGpuRenderer *renderer, GskVulkanRenderer *self = GSK_VULKAN_RENDERER (renderer); GdkVulkanContext *context; - if (surface) - context = gdk_surface_create_vulkan_context (surface, error); - else - context = gdk_display_create_vulkan_context (display, error); - + context = gdk_display_create_vulkan_context (display, surface, error); if (context == NULL) return NULL;