vulkan: Move some code

Add gsk_vulkan_image_new_from_texture() and use it.

Also rewrite the actual code from using Cairo surfaces to using
GdkTextureDownloader.
This commit is contained in:
Benjamin Otte 2023-06-13 08:02:06 +02:00
parent e7c86f4608
commit cb4e92946b
3 changed files with 24 additions and 8 deletions

View File

@ -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,

View File

@ -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,

View File

@ -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;