memoryformat: fast-path copies of the same format

Basically, memcpy() asap if possible.

This happens a lot in Vulkan, where we gdk_memory_conert() image
data from memory textures straight into the VulkanBuffer.

And usually we support the format.
This commit is contained in:
Benjamin Otte 2023-07-19 06:45:00 +02:00
parent 4d9e7d30b0
commit 2cbe89de7d

View File

@ -700,6 +700,26 @@ gdk_memory_convert (guchar *dest_data,
g_assert (dest_format < GDK_MEMORY_N_FORMATS);
g_assert (src_format < GDK_MEMORY_N_FORMATS);
if (src_format == dest_format)
{
gsize bytes_per_row = src_desc->bytes_per_pixel * width;
if (bytes_per_row == src_stride && bytes_per_row == dest_stride)
{
memcpy (dest_data, src_data, bytes_per_row * height);
}
else
{
for (y = 0; y < height; y++)
{
memcpy (dest_data, src_data, bytes_per_row);
src_data += src_stride;
dest_data += dest_stride;
}
}
return;
}
if (src_format == GDK_MEMORY_R8G8B8A8 && dest_format == GDK_MEMORY_R8G8B8A8_PREMULTIPLIED)
func = r8g8b8a8_to_r8g8b8a8_premultiplied;
else if (src_format == GDK_MEMORY_B8G8R8A8 && dest_format == GDK_MEMORY_R8G8B8A8_PREMULTIPLIED)