diff --git a/gsk/vulkan/gskvulkanimage.c b/gsk/vulkan/gskvulkanimage.c index 63d00b8786..f10ad5a1d1 100644 --- a/gsk/vulkan/gskvulkanimage.c +++ b/gsk/vulkan/gskvulkanimage.c @@ -529,6 +529,27 @@ gsk_vulkan_image_new_from_data_directly (GskVulkanUploader *uploader, return self; } +GskVulkanImage * +gsk_vulkan_image_new_from_texture (GskVulkanUploader *uploader, + GdkTexture *texture) +{ + GdkTextureDownloader *downloader; + GskVulkanImage *result; + GBytes *bytes; + gsize stride; + + downloader = gdk_texture_downloader_new (texture); + bytes = gdk_texture_downloader_download_bytes (downloader, &stride); + result = gsk_vulkan_image_new_from_data (uploader, + g_bytes_get_data (bytes, NULL), + gdk_texture_get_width (texture), + gdk_texture_get_height (texture), + stride); + g_bytes_unref (bytes); + gdk_texture_downloader_free (downloader); + return result; +} + GskVulkanImage * gsk_vulkan_image_new_from_data (GskVulkanUploader *uploader, const guchar *data, diff --git a/gsk/vulkan/gskvulkanimageprivate.h b/gsk/vulkan/gskvulkanimageprivate.h index d793e46e60..07f988bc66 100644 --- a/gsk/vulkan/gskvulkanimageprivate.h +++ b/gsk/vulkan/gskvulkanimageprivate.h @@ -24,6 +24,8 @@ GskVulkanImage * gsk_vulkan_image_new_for_swapchain (GdkVulk VkFormat format, gsize width, gsize height); +GskVulkanImage * gsk_vulkan_image_new_from_texture (GskVulkanUploader *uploader, + GdkTexture *texture); GskVulkanImage * gsk_vulkan_image_new_from_data (GskVulkanUploader *uploader, const guchar *data, gsize width, diff --git a/gsk/vulkan/gskvulkanrenderer.c b/gsk/vulkan/gskvulkanrenderer.c index 8c1b88c315..aa94c1dab1 100644 --- a/gsk/vulkan/gskvulkanrenderer.c +++ b/gsk/vulkan/gskvulkanrenderer.c @@ -422,20 +422,13 @@ gsk_vulkan_renderer_ref_texture_image (GskVulkanRenderer *self, GskVulkanUploader *uploader) { GskVulkanTextureData *data; - cairo_surface_t *surface; GskVulkanImage *image; data = gdk_texture_get_render_data (texture, self); if (data) return g_object_ref (data->image); - surface = gdk_texture_download_surface (texture); - image = gsk_vulkan_image_new_from_data (uploader, - cairo_image_surface_get_data (surface), - cairo_image_surface_get_width (surface), - cairo_image_surface_get_height (surface), - cairo_image_surface_get_stride (surface)); - cairo_surface_destroy (surface); + image = gsk_vulkan_image_new_from_texture (uploader, texture); data = g_new0 (GskVulkanTextureData, 1); data->image = image;