diff --git a/gdk/gdkvulkancontext.c b/gdk/gdkvulkancontext.c index a035d8005d..1217deeaa6 100644 --- a/gdk/gdkvulkancontext.c +++ b/gdk/gdkvulkancontext.c @@ -399,6 +399,15 @@ gdk_vulkan_context_dispose (GObject *gobject) G_OBJECT_CLASS (gdk_vulkan_context_parent_class)->dispose (gobject); } +static void +gdk_vulkan_context_get_image_size (GdkVulkanContext *context, + VkExtent2D *size) +{ + GDK_VULKAN_CONTEXT_GET_CLASS (context)->get_image_size (context, + &size->width, + &size->height); +} + static gboolean gdk_vulkan_context_check_swapchain (GdkVulkanContext *context, GError **error) @@ -458,7 +467,6 @@ gdk_vulkan_context_check_swapchain (GdkVulkanContext *context, capabilities.currentExtent.width, capabilities.currentExtent.height); - /* * Per https://www.khronos.org/registry/vulkan/specs/1.0-wsi_extensions/xhtml/vkspec.html#VkSurfaceCapabilitiesKHR * the current extent may assume a special value, meaning that the extent should assume whatever @@ -466,10 +474,7 @@ gdk_vulkan_context_check_swapchain (GdkVulkanContext *context, */ if (capabilities.currentExtent.width == -1 || capabilities.currentExtent.height == -1) { - double scale = gdk_surface_get_scale (surface); - - capabilities.currentExtent.width = MAX (1, (int) ceil (gdk_surface_get_width (surface) * scale)); - capabilities.currentExtent.height = MAX (1, (int) ceil (gdk_surface_get_height (surface) * scale)); + gdk_vulkan_context_get_image_size (context, &capabilities.currentExtent); GDK_DEBUG (VULKAN, "Effective extent %dx%d", capabilities.currentExtent.width, @@ -832,6 +837,20 @@ gdk_vulkan_context_surface_resized (GdkDrawContext *draw_context) } } +static void +gdk_vulkan_context_get_default_image_size (GdkVulkanContext *context, + uint32_t *width, + uint32_t *height) +{ + GdkSurface *surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (context)); + double scale; + + scale = gdk_surface_get_scale (surface); + + *width = MAX (1, (uint32_t) ceil (gdk_surface_get_width (surface) * scale)); + *height = MAX (1, (uint32_t) ceil (gdk_surface_get_height (surface) * scale)); +} + static void gdk_vulkan_context_class_init (GdkVulkanContextClass *klass) { @@ -844,6 +863,8 @@ gdk_vulkan_context_class_init (GdkVulkanContextClass *klass) draw_context_class->end_frame = gdk_vulkan_context_end_frame; draw_context_class->surface_resized = gdk_vulkan_context_surface_resized; + klass->get_image_size = gdk_vulkan_context_get_default_image_size; + /** * GdkVulkanContext::images-updated: * @context: the object on which the signal is emitted diff --git a/gdk/gdkvulkancontextprivate.h b/gdk/gdkvulkancontextprivate.h index 7baeda1de1..f9d0ba95b6 100644 --- a/gdk/gdkvulkancontextprivate.h +++ b/gdk/gdkvulkancontextprivate.h @@ -50,14 +50,18 @@ struct _GdkVulkanContextClass GdkDrawContextClass parent_class; #ifdef GDK_RENDERING_VULKAN - VkResult (* create_surface) (GdkVulkanContext *context, - VkSurfaceKHR *surface); + VkResult (* create_surface) (GdkVulkanContext *context, + VkSurfaceKHR *surface); + void (* get_image_size) (GdkVulkanContext *context, + uint32_t *out_width, + uint32_t *out_height); + #endif }; #ifdef GDK_RENDERING_VULKAN -const char * gdk_vulkan_strerror (VkResult result); +const char * gdk_vulkan_strerror (VkResult result); static inline VkResult gdk_vulkan_handle_result (VkResult res,