From: Benjamin Otte Date: Wed, 19 Jul 2023 04:45:00 +0000 (+0200) Subject: memoryformat: fast-path copies of the same format X-Git-Tag: archive/raspbian/4.12.3+ds-1+rpi1~1^2^2^2~22^2~1^2~58^2~1 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=2cbe89de7d78759c47f9f2cda9b2194a30d7e601;p=gtk4.git 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. --- diff --git a/gdk/gdkmemoryformat.c b/gdk/gdkmemoryformat.c index 893624efcb..c4cb2b7d22 100644 --- a/gdk/gdkmemoryformat.c +++ b/gdk/gdkmemoryformat.c @@ -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)