memoryformat: Introduce new (private) API

Add gdk_memory_format_get_premultiplied() and
gdk_memory_format_get_straight() which return the matching
premultiplied/straight format.

Use this to pick the premultiplied format when uploading GL textures.

And remove the duplication in the dmabuf code, where we can now use
these functions instead of tracking both the premultiplied and straight
alpha versions.
This commit is contained in:
Benjamin Otte 2023-12-11 04:20:32 +01:00
parent 0889037959
commit 0f5fda2277
4 changed files with 218 additions and 132 deletions

View File

@ -36,8 +36,7 @@ typedef struct _GdkDrmFormatInfo GdkDrmFormatInfo;
struct _GdkDrmFormatInfo
{
guint32 fourcc;
GdkMemoryFormat premultiplied_memory_format;
GdkMemoryFormat unpremultiplied_memory_format;
GdkMemoryFormat memory_format;
void (* download) (guchar *dst_data,
gsize dst_stride,
GdkMemoryFormat dst_format,
@ -372,145 +371,145 @@ download_yuyv (guchar *dst_data,
static const GdkDrmFormatInfo supported_formats[] = {
#if 0
/* palette formats?! */
{ DRM_FORMAT_C1, GDK_MEMORY_, GDK_MEMORY_, NULL },
{ DRM_FORMAT_C2, GDK_MEMORY_, GDK_MEMORY_, NULL },
{ DRM_FORMAT_C4, GDK_MEMORY_, GDK_MEMORY_, NULL },
{ DRM_FORMAT_C8, GDK_MEMORY_, GDK_MEMORY_, NULL },
{ DRM_FORMAT_C1, GDK_MEMORY_, NULL },
{ DRM_FORMAT_C2, GDK_MEMORY_, NULL },
{ DRM_FORMAT_C4, GDK_MEMORY_, NULL },
{ DRM_FORMAT_C8, GDK_MEMORY_, NULL },
#endif
/* darkness */
{ DRM_FORMAT_D1, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_D2, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_D4, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_D8, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_D1, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_D2, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_D4, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_D8, GDK_MEMORY_G8, NULL },
/* red only - we treat this as gray */
{ DRM_FORMAT_R1, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_R2, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_R4, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_R8, GDK_MEMORY_G8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_R10, GDK_MEMORY_G16, GDK_MEMORY_G16, NULL },
{ DRM_FORMAT_R12, GDK_MEMORY_G16, GDK_MEMORY_G16, NULL },
{ DRM_FORMAT_R16, GDK_MEMORY_G16, GDK_MEMORY_G16, NULL },
{ DRM_FORMAT_R1, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_R2, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_R4, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_R8, GDK_MEMORY_G8, NULL },
{ DRM_FORMAT_R10, GDK_MEMORY_G16, NULL },
{ DRM_FORMAT_R12, GDK_MEMORY_G16, NULL },
{ DRM_FORMAT_R16, GDK_MEMORY_G16, NULL },
/* 2 channels - FIXME: Should this be gray + alpha? */
{ DRM_FORMAT_RG88, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_GR88, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_RG1616, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_GR1616, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_RG88, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_GR88, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_RG1616, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_GR1616, GDK_MEMORY_R16G16B16, NULL },
/* <8bit per channel RGB(A) */
{ DRM_FORMAT_RGB332, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_BGR233, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_XRGB4444, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_XBGR4444, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_RGBX4444, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_BGRX4444, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_ARGB4444, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, GDK_MEMORY_B8G8R8A8, NULL },
{ DRM_FORMAT_ABGR4444, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, NULL },
{ DRM_FORMAT_RGBA4444, GDK_MEMORY_A8B8G8R8_PREMULTIPLIED, GDK_MEMORY_A8B8G8R8, NULL },
{ DRM_FORMAT_BGRA4444, GDK_MEMORY_A8R8G8B8_PREMULTIPLIED, GDK_MEMORY_A8R8G8B8, NULL },
{ DRM_FORMAT_XRGB1555, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_XBGR1555, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_RGBX5551, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_BGRX5551, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_ARGB1555, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, GDK_MEMORY_B8G8R8A8, NULL },
{ DRM_FORMAT_ABGR1555, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, NULL },
{ DRM_FORMAT_RGBA5551, GDK_MEMORY_A8B8G8R8_PREMULTIPLIED, GDK_MEMORY_A8B8G8R8, NULL },
{ DRM_FORMAT_BGRA5551, GDK_MEMORY_A8R8G8B8_PREMULTIPLIED, GDK_MEMORY_A8R8G8B8, NULL },
{ DRM_FORMAT_RGB565, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_BGR565, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_RGB332, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_BGR233, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_XRGB4444, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_XBGR4444, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_RGBX4444, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_BGRX4444, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_ARGB4444, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, NULL },
{ DRM_FORMAT_ABGR4444, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, NULL },
{ DRM_FORMAT_RGBA4444, GDK_MEMORY_A8B8G8R8_PREMULTIPLIED, NULL },
{ DRM_FORMAT_BGRA4444, GDK_MEMORY_A8R8G8B8_PREMULTIPLIED, NULL },
{ DRM_FORMAT_XRGB1555, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_XBGR1555, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_RGBX5551, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_BGRX5551, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_ARGB1555, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, NULL },
{ DRM_FORMAT_ABGR1555, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, NULL },
{ DRM_FORMAT_RGBA5551, GDK_MEMORY_A8B8G8R8_PREMULTIPLIED, NULL },
{ DRM_FORMAT_BGRA5551, GDK_MEMORY_A8R8G8B8_PREMULTIPLIED, NULL },
{ DRM_FORMAT_RGB565, GDK_MEMORY_B8G8R8, NULL },
{ DRM_FORMAT_BGR565, GDK_MEMORY_R8G8B8, NULL },
/* 8bit RGB */
{ DRM_FORMAT_RGB888, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_memcpy },
{ DRM_FORMAT_BGR888, GDK_MEMORY_B8G8R8, GDK_MEMORY_B8G8R8, download_memcpy },
{ DRM_FORMAT_RGB888, GDK_MEMORY_R8G8B8, download_memcpy },
{ DRM_FORMAT_BGR888, GDK_MEMORY_B8G8R8, download_memcpy },
/* 8bit RGBA */
{ DRM_FORMAT_BGRA8888, GDK_MEMORY_A8R8G8B8_PREMULTIPLIED, GDK_MEMORY_A8R8G8B8, download_memcpy },
{ DRM_FORMAT_ABGR8888, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, download_memcpy },
{ DRM_FORMAT_ARGB8888, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, GDK_MEMORY_B8G8R8A8, download_memcpy },
{ DRM_FORMAT_RGBA8888, GDK_MEMORY_A8B8G8R8_PREMULTIPLIED, GDK_MEMORY_A8B8G8R8, download_memcpy },
{ DRM_FORMAT_BGRX8888, GDK_MEMORY_X8R8G8B8, GDK_MEMORY_X8R8G8B8, download_memcpy },
{ DRM_FORMAT_XBGR8888, GDK_MEMORY_R8G8B8X8, GDK_MEMORY_R8G8B8X8, download_memcpy },
{ DRM_FORMAT_XRGB8888, GDK_MEMORY_B8G8R8X8, GDK_MEMORY_B8G8R8X8, download_memcpy },
{ DRM_FORMAT_RGBX8888, GDK_MEMORY_X8B8G8R8, GDK_MEMORY_X8B8G8R8, download_memcpy },
{ DRM_FORMAT_ABGR16161616F, GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16_FLOAT, download_memcpy },
{ DRM_FORMAT_BGRA8888, GDK_MEMORY_A8R8G8B8_PREMULTIPLIED, download_memcpy },
{ DRM_FORMAT_ABGR8888, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, download_memcpy },
{ DRM_FORMAT_ARGB8888, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, download_memcpy },
{ DRM_FORMAT_RGBA8888, GDK_MEMORY_A8B8G8R8_PREMULTIPLIED, download_memcpy },
{ DRM_FORMAT_BGRX8888, GDK_MEMORY_X8R8G8B8, download_memcpy },
{ DRM_FORMAT_XBGR8888, GDK_MEMORY_R8G8B8X8, download_memcpy },
{ DRM_FORMAT_XRGB8888, GDK_MEMORY_B8G8R8X8, download_memcpy },
{ DRM_FORMAT_RGBX8888, GDK_MEMORY_X8B8G8R8, download_memcpy },
{ DRM_FORMAT_ABGR16161616F, GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED, download_memcpy },
/* 10bit RGB(A) */
{ DRM_FORMAT_XRGB2101010, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XBGR2101010, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_RGBX1010102, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_BGRX1010102, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_ARGB2101010, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16, NULL },
{ DRM_FORMAT_ABGR2101010, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16, NULL },
{ DRM_FORMAT_RGBA1010102, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16, NULL },
{ DRM_FORMAT_BGRA1010102, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16, NULL },
{ DRM_FORMAT_XRGB2101010, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XBGR2101010, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_RGBX1010102, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_BGRX1010102, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_ARGB2101010, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, NULL },
{ DRM_FORMAT_ABGR2101010, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, NULL },
{ DRM_FORMAT_RGBA1010102, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, NULL },
{ DRM_FORMAT_BGRA1010102, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, NULL },
/* 16bit RGB(A) */
{ DRM_FORMAT_XRGB16161616, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XBGR16161616, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_ARGB16161616, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16, NULL },
{ DRM_FORMAT_ABGR16161616, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16, NULL },
{ DRM_FORMAT_XRGB16161616F, GDK_MEMORY_R16G16B16_FLOAT, GDK_MEMORY_R16G16B16_FLOAT, NULL },
{ DRM_FORMAT_XBGR16161616F, GDK_MEMORY_R16G16B16_FLOAT, GDK_MEMORY_R16G16B16_FLOAT, NULL },
{ DRM_FORMAT_ARGB16161616F, GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16_FLOAT, NULL },
{ DRM_FORMAT_ABGR16161616F, GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16_FLOAT, NULL },
{ DRM_FORMAT_AXBXGXRX106106106106, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, GDK_MEMORY_R16G16B16A16, NULL },
{ DRM_FORMAT_XRGB16161616, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XBGR16161616, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_ARGB16161616, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, NULL },
{ DRM_FORMAT_ABGR16161616, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, NULL },
{ DRM_FORMAT_XRGB16161616F, GDK_MEMORY_R16G16B16_FLOAT, NULL },
{ DRM_FORMAT_XBGR16161616F, GDK_MEMORY_R16G16B16_FLOAT, NULL },
{ DRM_FORMAT_ARGB16161616F, GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED, NULL },
{ DRM_FORMAT_ABGR16161616F, GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED, NULL },
{ DRM_FORMAT_AXBXGXRX106106106106, GDK_MEMORY_R16G16B16A16_PREMULTIPLIED, NULL },
/* 1-plane YUV formats */
{ DRM_FORMAT_YUYV, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_YVYU, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_VYUY, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_UYVY, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_AYUV, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, NULL },
{ DRM_FORMAT_AVUY8888, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, NULL },
{ DRM_FORMAT_XYUV8888, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_XVUY8888, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_VUY888, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_VUY101010, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y210, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y212, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y216, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y410, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y412, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y416, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XVYU2101010, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XVYU12_16161616, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XVYU16161616, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_YUYV, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_YVYU, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_VYUY, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_UYVY, GDK_MEMORY_R8G8B8, download_yuyv },
{ DRM_FORMAT_AYUV, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, NULL },
{ DRM_FORMAT_AVUY8888, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, NULL },
{ DRM_FORMAT_XYUV8888, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_XVUY8888, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_VUY888, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_VUY101010, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y210, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y212, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y216, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y410, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y412, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y416, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XVYU2101010, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XVYU12_16161616, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_XVYU16161616, GDK_MEMORY_R16G16B16, NULL },
/* tiled YUV */
{ DRM_FORMAT_Y0L0, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_X0L0, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_Y0L2, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_X0L2, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Y0L0, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_X0L0, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_Y0L2, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_X0L2, GDK_MEMORY_R16G16B16, NULL },
/* non-linear YUV */
{ DRM_FORMAT_YUV420_8BIT, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_YUV420_10BIT, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_YUV420_8BIT, GDK_MEMORY_R8G8B8, NULL },
{ DRM_FORMAT_YUV420_10BIT, GDK_MEMORY_R16G16B16, NULL },
/* 2 plane RGB + A */
{ DRM_FORMAT_BGRX8888_A8, GDK_MEMORY_A8R8G8B8_PREMULTIPLIED, GDK_MEMORY_A8R8G8B8, download_memcpy_3_1 },
{ DRM_FORMAT_RGBX8888_A8, GDK_MEMORY_A8B8G8R8_PREMULTIPLIED, GDK_MEMORY_A8B8G8R8, download_memcpy_3_1 },
{ DRM_FORMAT_XBGR8888_A8, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, download_memcpy_3_1 },
{ DRM_FORMAT_XRGB8888_A8, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, GDK_MEMORY_B8G8R8A8, download_memcpy_3_1 },
{ DRM_FORMAT_RGB888_A8, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, NULL },
{ DRM_FORMAT_BGR888_A8, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, GDK_MEMORY_B8G8R8A8, NULL },
{ DRM_FORMAT_RGB565_A8, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, GDK_MEMORY_R8G8B8A8, NULL },
{ DRM_FORMAT_BGR565_A8, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, GDK_MEMORY_B8G8R8A8, NULL },
{ DRM_FORMAT_BGRX8888_A8, GDK_MEMORY_A8R8G8B8_PREMULTIPLIED, download_memcpy_3_1 },
{ DRM_FORMAT_RGBX8888_A8, GDK_MEMORY_A8B8G8R8_PREMULTIPLIED, download_memcpy_3_1 },
{ DRM_FORMAT_XBGR8888_A8, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, download_memcpy_3_1 },
{ DRM_FORMAT_XRGB8888_A8, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, download_memcpy_3_1 },
{ DRM_FORMAT_RGB888_A8, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, NULL },
{ DRM_FORMAT_BGR888_A8, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, NULL },
{ DRM_FORMAT_RGB565_A8, GDK_MEMORY_R8G8B8A8_PREMULTIPLIED, NULL },
{ DRM_FORMAT_BGR565_A8, GDK_MEMORY_B8G8R8A8_PREMULTIPLIED, NULL },
/* 2-plane YUV formats */
{ DRM_FORMAT_NV12, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV21, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV16, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV61, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV24, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV42, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV15, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P210, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P010, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P012, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P016, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P030, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_NV12, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV21, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV16, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV61, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV24, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV42, GDK_MEMORY_R8G8B8, download_nv12 },
{ DRM_FORMAT_NV15, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P210, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P010, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P012, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P016, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_P030, GDK_MEMORY_R16G16B16, NULL },
/* 3-plane YUV */
{ DRM_FORMAT_Q410, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Q401, GDK_MEMORY_R16G16B16, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_YUV410, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YVU410, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YUV411, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YVU411, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YUV420, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YVU420, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YUV422, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YVU422, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YUV444, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YVU444, GDK_MEMORY_R8G8B8, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_Q410, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_Q401, GDK_MEMORY_R16G16B16, NULL },
{ DRM_FORMAT_YUV410, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YVU410, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YUV411, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YVU411, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YUV420, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YVU420, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YUV422, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YVU422, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YUV444, GDK_MEMORY_R8G8B8, download_yuv_3 },
{ DRM_FORMAT_YVU444, GDK_MEMORY_R8G8B8, download_yuv_3 },
};
static const GdkDrmFormatInfo *
@ -536,9 +535,9 @@ gdk_dmabuf_get_memory_format (guint32 fourcc,
return FALSE;
if (premultiplied)
*out_format = info->premultiplied_memory_format;
*out_format = gdk_memory_format_get_premultiplied (info->memory_format);
else
*out_format = info->unpremultiplied_memory_format;
*out_format = gdk_memory_format_get_straight (info->memory_format);
return TRUE;
}
@ -689,8 +688,10 @@ gdk_dmabuf_direct_downloader_supports (const GdkDmabufDownloader *downloader,
return FALSE;
}
*out_format = premultiplied ? info->premultiplied_memory_format
: info->unpremultiplied_memory_format;
if (premultiplied)
*out_format = gdk_memory_format_get_premultiplied (info->memory_format);
else
*out_format = gdk_memory_format_get_straight (info->memory_format);
return TRUE;
}

View File

@ -326,6 +326,8 @@ ADD_ALPHA_FUNC(r8g8b8_to_a8b8g8r8, 0, 1, 2, 3, 2, 1, 0)
struct _GdkMemoryFormatDescription
{
GdkMemoryAlpha alpha;
GdkMemoryFormat premultiplied;
GdkMemoryFormat straight;
gsize bytes_per_pixel;
gsize alignment;
GdkMemoryDepth depth;
@ -355,6 +357,8 @@ struct _GdkMemoryFormatDescription
static const GdkMemoryFormatDescription memory_formats[] = {
[GDK_MEMORY_B8G8R8A8_PREMULTIPLIED] = {
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_B8G8R8A8_PREMULTIPLIED,
.straight = GDK_MEMORY_B8G8R8A8,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -371,6 +375,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_A8R8G8B8_PREMULTIPLIED] = {
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_A8R8G8B8_PREMULTIPLIED,
.straight = GDK_MEMORY_A8R8G8B8,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -387,6 +393,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_R8G8B8A8_PREMULTIPLIED] = {
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
.straight = GDK_MEMORY_R8G8B8A8,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -402,6 +410,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_A8B8G8R8_PREMULTIPLIED] = {
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_A8B8G8R8_PREMULTIPLIED,
.straight = GDK_MEMORY_A8B8G8R8,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -418,6 +428,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_B8G8R8A8] = {
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_B8G8R8A8_PREMULTIPLIED,
.straight = GDK_MEMORY_B8G8R8A8,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -434,6 +446,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_A8R8G8B8] = {
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_A8R8G8B8_PREMULTIPLIED,
.straight = GDK_MEMORY_A8R8G8B8,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -450,6 +464,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_R8G8B8A8] = {
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_R8G8B8A8_PREMULTIPLIED,
.straight = GDK_MEMORY_R8G8B8A8,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -465,6 +481,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_A8B8G8R8] = {
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_A8B8G8R8_PREMULTIPLIED,
.straight = GDK_MEMORY_A8B8G8R8,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -481,6 +499,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_B8G8R8X8] = {
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_B8G8R8X8,
.straight = GDK_MEMORY_B8G8R8X8,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -497,6 +517,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_X8R8G8B8] = {
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_X8R8G8B8,
.straight = GDK_MEMORY_X8R8G8B8,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -513,6 +535,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_R8G8B8X8] = {
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_R8G8B8X8,
.straight = GDK_MEMORY_R8G8B8X8,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -528,6 +552,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_X8B8G8R8] = {
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_X8B8G8R8,
.straight = GDK_MEMORY_X8B8G8R8,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -544,6 +570,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_R8G8B8] = {
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_R8G8B8,
.straight = GDK_MEMORY_R8G8B8,
.bytes_per_pixel = 3,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -559,6 +587,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_B8G8R8] = {
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_B8G8R8,
.straight = GDK_MEMORY_B8G8R8,
.bytes_per_pixel = 3,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -575,6 +605,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_R16G16B16] = {
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_R16G16B16,
.straight = GDK_MEMORY_R16G16B16,
.bytes_per_pixel = 6,
.alignment = G_ALIGNOF (guint16),
.depth = GDK_MEMORY_U16,
@ -590,6 +622,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_R16G16B16A16_PREMULTIPLIED] = {
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_R16G16B16A16_PREMULTIPLIED,
.straight = GDK_MEMORY_R16G16B16A16,
.bytes_per_pixel = 8,
.alignment = G_ALIGNOF (guint16),
.depth = GDK_MEMORY_U16,
@ -605,6 +639,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_R16G16B16A16] = {
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_R16G16B16A16_PREMULTIPLIED,
.straight = GDK_MEMORY_R16G16B16A16,
.bytes_per_pixel = 8,
.alignment = G_ALIGNOF (guint16),
.depth = GDK_MEMORY_U16,
@ -620,6 +656,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_R16G16B16_FLOAT] = {
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_R16G16B16_FLOAT,
.straight = GDK_MEMORY_R16G16B16_FLOAT,
.bytes_per_pixel = 6,
.alignment = G_ALIGNOF (guint16),
.depth = GDK_MEMORY_FLOAT16,
@ -635,6 +673,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED] = {
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED,
.straight = GDK_MEMORY_R16G16B16A16_FLOAT,
.bytes_per_pixel = 8,
.alignment = G_ALIGNOF (guint16),
.depth = GDK_MEMORY_FLOAT16,
@ -650,6 +690,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_R16G16B16A16_FLOAT] = {
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_R16G16B16A16_FLOAT_PREMULTIPLIED,
.straight = GDK_MEMORY_R16G16B16A16_FLOAT,
.bytes_per_pixel = 8,
.alignment = G_ALIGNOF (guint16),
.depth = GDK_MEMORY_FLOAT16,
@ -665,6 +707,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_R32G32B32_FLOAT] = {
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_R32G32B32_FLOAT,
.straight = GDK_MEMORY_R32G32B32_FLOAT,
12,
.alignment = G_ALIGNOF (float),
.depth = GDK_MEMORY_FLOAT32,
@ -680,6 +724,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED] = {
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED,
.straight = GDK_MEMORY_R32G32B32A32_FLOAT,
16,
.alignment = G_ALIGNOF (float),
.depth = GDK_MEMORY_FLOAT32,
@ -695,6 +741,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_R32G32B32A32_FLOAT] = {
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_R32G32B32A32_FLOAT_PREMULTIPLIED,
.straight = GDK_MEMORY_R32G32B32A32_FLOAT,
16,
.alignment = G_ALIGNOF (float),
.depth = GDK_MEMORY_FLOAT32,
@ -710,6 +758,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_G8A8_PREMULTIPLIED] = {
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_G8A8_PREMULTIPLIED,
.straight = GDK_MEMORY_G8A8,
.bytes_per_pixel = 2,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -725,6 +775,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_G8A8] = {
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_G8A8_PREMULTIPLIED,
.straight = GDK_MEMORY_G8A8,
.bytes_per_pixel = 2,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -740,6 +792,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_G8] = {
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_G8,
.straight = GDK_MEMORY_G8,
.bytes_per_pixel = 1,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -755,6 +809,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_G16A16_PREMULTIPLIED] = {
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_G16A16_PREMULTIPLIED,
.straight = GDK_MEMORY_G16A16,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (guint16),
.depth = GDK_MEMORY_U16,
@ -770,6 +826,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_G16A16] = {
.alpha = GDK_MEMORY_ALPHA_STRAIGHT,
.premultiplied = GDK_MEMORY_G16A16_PREMULTIPLIED,
.straight = GDK_MEMORY_G16A16,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (guint16),
.depth = GDK_MEMORY_U16,
@ -785,6 +843,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_G16] = {
.alpha = GDK_MEMORY_ALPHA_OPAQUE,
.premultiplied = GDK_MEMORY_G16,
.straight = GDK_MEMORY_G16,
.bytes_per_pixel = 2,
.alignment = G_ALIGNOF (guint16),
.depth = GDK_MEMORY_U16,
@ -800,6 +860,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_A8] = {
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_A8,
.straight = GDK_MEMORY_A8,
.bytes_per_pixel = 1,
.alignment = G_ALIGNOF (guchar),
.depth = GDK_MEMORY_U8,
@ -815,6 +877,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_A16] = {
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_A16,
.straight = GDK_MEMORY_A16,
.bytes_per_pixel = 2,
.alignment = G_ALIGNOF (guint16),
.depth = GDK_MEMORY_U16,
@ -830,6 +894,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_A16_FLOAT] = {
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_A16_FLOAT,
.straight = GDK_MEMORY_A16_FLOAT,
.bytes_per_pixel = 2,
.alignment = G_ALIGNOF (guint16),
.depth = GDK_MEMORY_FLOAT16,
@ -845,6 +911,8 @@ static const GdkMemoryFormatDescription memory_formats[] = {
},
[GDK_MEMORY_A32_FLOAT] = {
.alpha = GDK_MEMORY_ALPHA_PREMULTIPLIED,
.premultiplied = GDK_MEMORY_A32_FLOAT,
.straight = GDK_MEMORY_A32_FLOAT,
.bytes_per_pixel = 4,
.alignment = G_ALIGNOF (float),
.depth = GDK_MEMORY_FLOAT32,
@ -875,6 +943,18 @@ gdk_memory_format_alpha (GdkMemoryFormat format)
return memory_formats[format].alpha;
}
GdkMemoryFormat
gdk_memory_format_get_premultiplied (GdkMemoryFormat format)
{
return memory_formats[format].premultiplied;
}
GdkMemoryFormat
gdk_memory_format_get_straight (GdkMemoryFormat format)
{
return memory_formats[format].straight;
}
gsize
gdk_memory_format_alignment (GdkMemoryFormat format)
{

View File

@ -42,6 +42,8 @@ typedef enum {
gsize gdk_memory_format_alignment (GdkMemoryFormat format) G_GNUC_CONST;
GdkMemoryAlpha gdk_memory_format_alpha (GdkMemoryFormat format) G_GNUC_CONST;
gsize gdk_memory_format_bytes_per_pixel (GdkMemoryFormat format) G_GNUC_CONST;
GdkMemoryFormat gdk_memory_format_get_premultiplied (GdkMemoryFormat format) G_GNUC_CONST;
GdkMemoryFormat gdk_memory_format_get_straight (GdkMemoryFormat format) G_GNUC_CONST;
GdkMemoryDepth gdk_memory_format_get_depth (GdkMemoryFormat format) G_GNUC_CONST;
GdkMemoryDepth gdk_memory_depth_merge (GdkMemoryDepth depth1,
GdkMemoryDepth depth2) G_GNUC_CONST;

View File

@ -1486,10 +1486,13 @@ memory_format_gl_format (GdkMemoryFormat data_format,
GdkMemoryDepth depth;
GdkMemoryFormat alt_format;
/* No support for straight formats yet */
if (gdk_memory_format_alpha (data_format) == GDK_MEMORY_ALPHA_STRAIGHT)
data_format = gdk_memory_format_get_premultiplied (data_format);
/* First, try the format itself */
flags = gdk_gl_context_get_format_flags (context, data_format);
if (((flags & (GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE)) == (GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE)) &&
gdk_memory_format_alpha (data_format) != GDK_MEMORY_ALPHA_STRAIGHT)
if ((flags & (GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE)) == (GDK_GL_FORMAT_USABLE | GDK_GL_FORMAT_FILTERABLE))
{
gdk_memory_format_gl_format (data_format,
gl_internalformat,