dmabuf: Make NULL the default colorstate in the builder

YUV dmabufs are not sRGB.

So instead of making the dmabuf builder have sRGB as the default
colorstate, add a NULL default option that makes the builder choose
the colorstate based on fourcc when build() is called.

If that happens, we pick sRGB usually, but for YUV we pick narrow range
BT601, like we did in versions before colorstates.
This commit is contained in:
Benjamin Otte 2024-07-21 03:07:14 +02:00
parent b58e89f380
commit 2e1686091f
2 changed files with 28 additions and 9 deletions

View File

@ -182,6 +182,7 @@ gdk_dmabuf_texture_new_from_builder (GdkDmabufTextureBuilder *builder,
GdkTexture *update_texture;
GdkDisplay *display;
GdkDmabuf dmabuf;
GdkColorState *color_state;
GError *local_error = NULL;
int width, height;
gboolean premultiplied;
@ -201,10 +202,24 @@ gdk_dmabuf_texture_new_from_builder (GdkDmabufTextureBuilder *builder,
gdk_display_init_dmabuf (display);
color_state = gdk_dmabuf_texture_builder_get_color_state (builder);
if (color_state == NULL)
{
gboolean is_yuv;
if (gdk_dmabuf_fourcc_is_yuv (dmabuf.fourcc, &is_yuv) && is_yuv)
{
g_warning_once ("FIXME: Implement the proper colorstate for YUV dmabufs");
color_state = gdk_color_state_get_srgb ();
}
else
color_state = gdk_color_state_get_srgb ();
}
self = g_object_new (GDK_TYPE_DMABUF_TEXTURE,
"width", width,
"height", height,
"color-state", gdk_dmabuf_texture_builder_get_color_state (builder),
"color-state", color_state,
NULL);
g_set_object (&self->display, display);

View File

@ -409,7 +409,7 @@ gdk_dmabuf_texture_builder_init (GdkDmabufTextureBuilder *self)
for (int i = 0; i < GDK_DMABUF_MAX_PLANES; i++)
self->dmabuf.planes[i].fd = -1;
self->color_state = gdk_color_state_ref (gdk_color_state_get_srgb ());
self->color_state = NULL;
}
/**
@ -876,7 +876,7 @@ gdk_dmabuf_texture_builder_set_offset (GdkDmabufTextureBuilder *self,
*
* Gets the color state previously set via gdk_dmabuf_texture_builder_set_color_state().
*
* Returns: the color state
* Returns: (nullable): the color state
*
* Since: 4.16
*/
@ -891,12 +891,13 @@ gdk_dmabuf_texture_builder_get_color_state (GdkDmabufTextureBuilder *self)
/**
* gdk_dmabuf_texture_builder_set_color_state: (attributes org.gtk.Method.set_property=color-state)
* @self: a `GdkDmabufTextureBuilder`
* @color_state: a `GdkColorState`
* @color_state: (nullable): a `GdkColorState` or `NULL` to unset the colorstate.
*
* Sets the color state for the texture.
*
* By default, the sRGB colorstate is used. If you don't know what
* colorstates are, this is probably the right thing.
* By default, the colorstate is `NULL`. In that case, GTK will choose the
* correct colorstate based on the format.
* If you don't know what colorstates are, this is probably the right thing.
*
* Since: 4.16
*/
@ -905,13 +906,16 @@ gdk_dmabuf_texture_builder_set_color_state (GdkDmabufTextureBuilder *self,
GdkColorState *color_state)
{
g_return_if_fail (GDK_IS_DMABUF_TEXTURE_BUILDER (self));
g_return_if_fail (color_state != NULL);
if (gdk_color_state_equal (self->color_state, color_state))
if (self->color_state == color_state ||
(self->color_state != NULL && color_state != NULL && gdk_color_state_equal (self->color_state, color_state)))
return;
g_clear_pointer (&self->color_state, gdk_color_state_unref);
self->color_state = gdk_color_state_ref (color_state);
self->color_state = color_state;
if (color_state)
gdk_color_state_ref (color_state);
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_COLOR_STATE]);
}