Merge branch 'matthiasc/for-main' into 'main'

wayland: Switch to v4 of the color management protocol

See merge request GNOME/gtk!7489
This commit is contained in:
Matthias Clasen 2024-07-24 06:24:20 +00:00
commit b435f3c543
3 changed files with 663 additions and 422 deletions

View File

@ -2,27 +2,27 @@
#include "gdkwaylandcolor-private.h"
#include "gdksurface-wayland-private.h"
#include <gdk/wayland/xx-color-management-v2-client-protocol.h>
#include <gdk/wayland/xx-color-management-v4-client-protocol.h>
struct _GdkWaylandColor
{
struct xx_color_manager_v2 *color_manager;
struct xx_color_manager_v4 *color_manager;
struct {
unsigned int intents;
unsigned int features;
unsigned int transfers;
unsigned int primaries;
} color_manager_supported;
struct xx_image_description_v2 *srgb;
struct xx_image_description_v2 *srgb_linear;
struct xx_image_description_v2 *rec2100_pq;
struct xx_image_description_v2 *rec2100_linear;
struct xx_image_description_v4 *srgb;
struct xx_image_description_v4 *srgb_linear;
struct xx_image_description_v4 *rec2100_pq;
struct xx_image_description_v4 *rec2100_linear;
};
static void
xx_color_manager_v2_supported_intent (void *data,
struct xx_color_manager_v2 *xx_color_manager_v2,
xx_color_manager_v4_supported_intent (void *data,
struct xx_color_manager_v4 *xx_color_manager_v2,
uint32_t render_intent)
{
GdkWaylandColor *color = data;
@ -31,8 +31,8 @@ xx_color_manager_v2_supported_intent (void *data,
}
static void
xx_color_manager_v2_supported_feature (void *data,
struct xx_color_manager_v2 *xx_color_manager_v2,
xx_color_manager_v4_supported_feature (void *data,
struct xx_color_manager_v4 *xx_color_manager_v2,
uint32_t feature)
{
GdkWaylandColor *color = data;
@ -41,8 +41,8 @@ xx_color_manager_v2_supported_feature (void *data,
}
static void
xx_color_manager_v2_supported_tf_named (void *data,
struct xx_color_manager_v2 *xx_color_manager_v2,
xx_color_manager_v4_supported_tf_named (void *data,
struct xx_color_manager_v4 *xx_color_manager_v2,
uint32_t tf)
{
GdkWaylandColor *color = data;
@ -51,8 +51,8 @@ xx_color_manager_v2_supported_tf_named (void *data,
}
static void
xx_color_manager_v2_supported_primaries_named (void *data,
struct xx_color_manager_v2 *xx_color_manager_v2,
xx_color_manager_v4_supported_primaries_named (void *data,
struct xx_color_manager_v4 *xx_color_manager_v2,
uint32_t primaries)
{
GdkWaylandColor *color = data;
@ -60,11 +60,11 @@ xx_color_manager_v2_supported_primaries_named (void *data,
color->color_manager_supported.primaries |= (1 << primaries);
}
static struct xx_color_manager_v2_listener color_manager_listener = {
xx_color_manager_v2_supported_intent,
xx_color_manager_v2_supported_feature,
xx_color_manager_v2_supported_tf_named,
xx_color_manager_v2_supported_primaries_named,
static struct xx_color_manager_v4_listener color_manager_listener = {
xx_color_manager_v4_supported_intent,
xx_color_manager_v4_supported_feature,
xx_color_manager_v4_supported_tf_named,
xx_color_manager_v4_supported_primaries_named,
};
GdkWaylandColor *
@ -78,10 +78,10 @@ gdk_wayland_color_new (struct wl_registry *registry,
color->color_manager = wl_registry_bind (registry,
id,
&xx_color_manager_v2_interface,
&xx_color_manager_v4_interface,
MIN (version, 2));
xx_color_manager_v2_add_listener (color->color_manager,
xx_color_manager_v4_add_listener (color->color_manager,
&color_manager_listener,
color);
@ -91,11 +91,11 @@ gdk_wayland_color_new (struct wl_registry *registry,
void
gdk_wayland_color_free (GdkWaylandColor *color)
{
g_clear_pointer (&color->color_manager, xx_color_manager_v2_destroy);
g_clear_pointer (&color->srgb, xx_image_description_v2_destroy);
g_clear_pointer (&color->srgb_linear, xx_image_description_v2_destroy);
g_clear_pointer (&color->rec2100_pq, xx_image_description_v2_destroy);
g_clear_pointer (&color->rec2100_linear, xx_image_description_v2_destroy);
g_clear_pointer (&color->color_manager, xx_color_manager_v4_destroy);
g_clear_pointer (&color->srgb, xx_image_description_v4_destroy);
g_clear_pointer (&color->srgb_linear, xx_image_description_v4_destroy);
g_clear_pointer (&color->rec2100_pq, xx_image_description_v4_destroy);
g_clear_pointer (&color->rec2100_linear, xx_image_description_v4_destroy);
g_free (color);
}
@ -107,25 +107,25 @@ gdk_wayland_color_get_color_manager (GdkWaylandColor *color)
static void
std_image_desc_failed (void *data,
struct xx_image_description_v2 *desc,
struct xx_image_description_v4 *desc,
uint32_t cause,
const char *msg)
{
g_warning ("Failed to get one of the standard image descriptions: %s", msg);
xx_image_description_v2_destroy (desc);
xx_image_description_v4_destroy (desc);
}
static void
std_image_desc_ready (void *data,
struct xx_image_description_v2 *desc,
struct xx_image_description_v4 *desc,
uint32_t identity)
{
struct xx_image_description_v2 **ptr = data;
struct xx_image_description_v4 **ptr = data;
*ptr = desc;
}
static struct xx_image_description_v2_listener std_image_desc_listener = {
static struct xx_image_description_v4_listener std_image_desc_listener = {
std_image_desc_failed,
std_image_desc_ready,
};
@ -134,19 +134,19 @@ static void
create_image_desc (GdkWaylandColor *color,
uint32_t primaries,
uint32_t tf,
struct xx_image_description_v2 **out_desc)
struct xx_image_description_v4 **out_desc)
{
struct xx_image_description_creator_params_v2 *creator;
struct xx_image_description_v2 *desc;
struct xx_image_description_creator_params_v4 *creator;
struct xx_image_description_v4 *desc;
creator = xx_color_manager_v2_new_parametric_creator (color->color_manager);
creator = xx_color_manager_v4_new_parametric_creator (color->color_manager);
xx_image_description_creator_params_v2_set_primaries_named (creator, primaries);
xx_image_description_creator_params_v2_set_tf_named (creator, tf);
xx_image_description_creator_params_v4_set_primaries_named (creator, primaries);
xx_image_description_creator_params_v4_set_tf_named (creator, tf);
desc = xx_image_description_creator_params_v2_create (creator);
desc = xx_image_description_creator_params_v4_create (creator);
xx_image_description_v2_add_listener (desc, &std_image_desc_listener, out_desc);
xx_image_description_v4_add_listener (desc, &std_image_desc_listener, out_desc);
}
gboolean
@ -158,7 +158,7 @@ gdk_wayland_color_prepare (GdkWaylandColor *color)
"perceptual", "relative", "saturation", "absolute", "relative-bpc"
};
const char *features[] = {
"icc-v2-v4", "parametric", "set-primaries", "set-tf-power",
"icc-v4-v4", "parametric", "set-primaries", "set-tf-power",
"set-mastering-display-primaries", "extended-target-volume"
};
const char *tf[] = {
@ -196,47 +196,47 @@ gdk_wayland_color_prepare (GdkWaylandColor *color)
}
if (color->color_manager &&
!(color->color_manager_supported.intents & (1 << XX_COLOR_MANAGER_V2_RENDER_INTENT_PERCEPTUAL)))
!(color->color_manager_supported.intents & (1 << XX_COLOR_MANAGER_V4_RENDER_INTENT_PERCEPTUAL)))
{
GDK_DEBUG (MISC, "Not using color management: Missing perceptual render intent");
g_clear_pointer (&color->color_manager, xx_color_manager_v2_destroy);
g_clear_pointer (&color->color_manager, xx_color_manager_v4_destroy);
}
if (color->color_manager &&
(!(color->color_manager_supported.features & (1 << XX_COLOR_MANAGER_V2_FEATURE_PARAMETRIC)) ||
!(color->color_manager_supported.transfers & (1 << XX_COLOR_MANAGER_V2_TRANSFER_FUNCTION_SRGB)) ||
!(color->color_manager_supported.primaries & (1 << XX_COLOR_MANAGER_V2_PRIMARIES_SRGB))))
(!(color->color_manager_supported.features & (1 << XX_COLOR_MANAGER_V4_FEATURE_PARAMETRIC)) ||
!(color->color_manager_supported.transfers & (1 << XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_SRGB)) ||
!(color->color_manager_supported.primaries & (1 << XX_COLOR_MANAGER_V4_PRIMARIES_SRGB))))
{
GDK_DEBUG (MISC, "Not using color management: Can't create srgb image description");
g_clear_pointer (&color->color_manager, xx_color_manager_v2_destroy);
g_clear_pointer (&color->color_manager, xx_color_manager_v4_destroy);
}
if (color->color_manager)
{
create_image_desc (color,
XX_COLOR_MANAGER_V2_PRIMARIES_SRGB,
XX_COLOR_MANAGER_V2_TRANSFER_FUNCTION_SRGB,
XX_COLOR_MANAGER_V4_PRIMARIES_SRGB,
XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_SRGB,
&color->srgb);
if (color->color_manager_supported.transfers & (1 << XX_COLOR_MANAGER_V2_TRANSFER_FUNCTION_LINEAR))
if (color->color_manager_supported.transfers & (1 << XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_LINEAR))
create_image_desc (color,
XX_COLOR_MANAGER_V2_PRIMARIES_SRGB,
XX_COLOR_MANAGER_V2_TRANSFER_FUNCTION_LINEAR,
XX_COLOR_MANAGER_V4_PRIMARIES_SRGB,
XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_LINEAR,
&color->srgb_linear);
if (color->color_manager_supported.primaries & (1 << XX_COLOR_MANAGER_V2_PRIMARIES_BT2020))
if (color->color_manager_supported.primaries & (1 << XX_COLOR_MANAGER_V4_PRIMARIES_BT2020))
{
if (color->color_manager_supported.transfers & (1 << XX_COLOR_MANAGER_V2_TRANSFER_FUNCTION_ST2084_PQ))
if (color->color_manager_supported.transfers & (1 << XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_ST2084_PQ))
create_image_desc (color,
XX_COLOR_MANAGER_V2_PRIMARIES_BT2020,
XX_COLOR_MANAGER_V2_TRANSFER_FUNCTION_ST2084_PQ,
XX_COLOR_MANAGER_V4_PRIMARIES_BT2020,
XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_ST2084_PQ,
&color->rec2100_pq);
if (color->color_manager_supported.transfers & (1 << XX_COLOR_MANAGER_V2_TRANSFER_FUNCTION_LINEAR))
if (color->color_manager_supported.transfers & (1 << XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_LINEAR))
create_image_desc (color,
XX_COLOR_MANAGER_V2_PRIMARIES_BT2020,
XX_COLOR_MANAGER_V2_TRANSFER_FUNCTION_LINEAR,
XX_COLOR_MANAGER_V4_PRIMARIES_BT2020,
XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_LINEAR,
&color->rec2100_linear);
}
}
@ -247,7 +247,8 @@ gdk_wayland_color_prepare (GdkWaylandColor *color)
struct _GdkWaylandColorSurface
{
GdkWaylandColor *color;
struct xx_color_management_surface_v2 *surface;
struct xx_color_management_surface_v4 *surface;
struct xx_color_management_feedback_surface_v4 *feedback;
GdkColorStateChanged callback;
gpointer data;
};
@ -256,16 +257,17 @@ typedef struct
{
GdkWaylandColorSurface *surface;
struct xx_image_description_v2 *image_desc;
struct xx_image_description_info_v2 *info;
struct xx_image_description_v4 *image_desc;
struct xx_image_description_info_v4 *info;
int32_t icc;
uint32_t icc_size;
uint32_t r_x, r_y, g_x, g_y, b_x, b_y, w_x, w_y;
int32_t r_x, r_y, g_x, g_y, b_x, b_y, w_x, w_y;
uint32_t primaries;
uint32_t tf_power;
uint32_t tf_named;
uint32_t target_r_x, target_r_y, target_g_x, target_g_y, target_b_x, target_b_y, target_w_x, target_w_y;
uint32_t min_lum, max_lum, ref_lum;
int32_t target_r_x, target_r_y, target_g_x, target_g_y, target_b_x, target_b_y, target_w_x, target_w_y;
uint32_t target_min_lum, target_max_lum;
uint32_t target_max_cll, target_max_fall;
@ -274,6 +276,7 @@ typedef struct
unsigned int has_primaries_named : 1;
unsigned int has_tf_power : 1;
unsigned int has_tf_named : 1;
unsigned int has_luminances : 1;
unsigned int has_target_primaries : 1;
unsigned int has_target_luminance : 1;
unsigned int has_target_max_cll : 1;
@ -287,23 +290,23 @@ gdk_color_state_from_image_description_bits (ImageDescription *desc)
if (desc->has_primaries_named && desc->has_tf_named)
{
if (desc->primaries == XX_COLOR_MANAGER_V2_PRIMARIES_SRGB &&
desc->tf_named == XX_COLOR_MANAGER_V2_TRANSFER_FUNCTION_SRGB)
if (desc->primaries == XX_COLOR_MANAGER_V4_PRIMARIES_SRGB &&
desc->tf_named == XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_SRGB)
{
cs = GDK_COLOR_STATE_SRGB;
}
else if (desc->primaries == XX_COLOR_MANAGER_V2_PRIMARIES_SRGB &&
desc->tf_named == XX_COLOR_MANAGER_V2_TRANSFER_FUNCTION_LINEAR)
else if (desc->primaries == XX_COLOR_MANAGER_V4_PRIMARIES_SRGB &&
desc->tf_named == XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_LINEAR)
{
cs = GDK_COLOR_STATE_SRGB_LINEAR;
}
else if (desc->primaries == XX_COLOR_MANAGER_V2_PRIMARIES_BT2020 &&
desc->tf_named == XX_COLOR_MANAGER_V2_TRANSFER_FUNCTION_ST2084_PQ)
else if (desc->primaries == XX_COLOR_MANAGER_V4_PRIMARIES_BT2020 &&
desc->tf_named == XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_ST2084_PQ)
{
cs = GDK_COLOR_STATE_REC2100_PQ;
}
else if (desc->primaries == XX_COLOR_MANAGER_V2_PRIMARIES_BT2020 &&
desc->tf_named == XX_COLOR_MANAGER_V2_TRANSFER_FUNCTION_LINEAR)
else if (desc->primaries == XX_COLOR_MANAGER_V4_PRIMARIES_BT2020 &&
desc->tf_named == XX_COLOR_MANAGER_V4_TRANSFER_FUNCTION_LINEAR)
{
cs = GDK_COLOR_STATE_REC2100_LINEAR;
}
@ -314,7 +317,7 @@ gdk_color_state_from_image_description_bits (ImageDescription *desc)
static void
image_desc_info_done (void *data,
struct xx_image_description_info_v2 *info)
struct xx_image_description_info_v4 *info)
{
ImageDescription *desc = data;
GdkWaylandColorSurface *self = desc->surface;
@ -327,14 +330,14 @@ image_desc_info_done (void *data,
gdk_color_state_unref (cs);
xx_image_description_v2_destroy (desc->image_desc);
xx_image_description_info_v2_destroy (desc->info);
xx_image_description_v4_destroy (desc->image_desc);
xx_image_description_info_v4_destroy (desc->info);
g_free (desc);
}
static void
image_desc_info_icc_file (void *data,
struct xx_image_description_info_v2 *info,
struct xx_image_description_info_v4 *info,
int32_t icc,
uint32_t icc_size)
{
@ -347,11 +350,11 @@ image_desc_info_icc_file (void *data,
static void
image_desc_info_primaries (void *data,
struct xx_image_description_info_v2 *info,
uint32_t r_x, uint32_t r_y,
uint32_t g_x, uint32_t g_y,
uint32_t b_x, uint32_t b_y,
uint32_t w_x, uint32_t w_y)
struct xx_image_description_info_v4 *info,
int32_t r_x, int32_t r_y,
int32_t g_x, int32_t g_y,
int32_t b_x, int32_t b_y,
int32_t w_x, int32_t w_y)
{
ImageDescription *desc = data;
@ -364,7 +367,7 @@ image_desc_info_primaries (void *data,
static void
image_desc_info_primaries_named (void *data,
struct xx_image_description_info_v2 *info,
struct xx_image_description_info_v4 *info,
uint32_t primaries)
{
ImageDescription *desc = data;
@ -375,7 +378,7 @@ image_desc_info_primaries_named (void *data,
static void
image_desc_info_tf_power (void *data,
struct xx_image_description_info_v2 *info,
struct xx_image_description_info_v4 *info,
uint32_t tf_power)
{
ImageDescription *desc = data;
@ -386,7 +389,7 @@ image_desc_info_tf_power (void *data,
static void
image_desc_info_tf_named (void *data,
struct xx_image_description_info_v2 *info,
struct xx_image_description_info_v4 *info,
uint32_t tf)
{
ImageDescription *desc = data;
@ -395,13 +398,28 @@ image_desc_info_tf_named (void *data,
desc->has_tf_named = 1;
}
static void
image_desc_info_luminances (void *data,
struct xx_image_description_info_v4 *info,
uint32_t min_lum,
uint32_t max_lum,
uint32_t ref_lum)
{
ImageDescription *desc = data;
desc->min_lum = min_lum;
desc->max_lum = max_lum;
desc->ref_lum = ref_lum;
desc->has_luminances = 1;
}
static void
image_desc_info_target_primaries (void *data,
struct xx_image_description_info_v2 *info,
uint32_t r_x, uint32_t r_y,
uint32_t g_x, uint32_t g_y,
uint32_t b_x, uint32_t b_y,
uint32_t w_x, uint32_t w_y)
struct xx_image_description_info_v4 *info,
int32_t r_x, int32_t r_y,
int32_t g_x, int32_t g_y,
int32_t b_x, int32_t b_y,
int32_t w_x, int32_t w_y)
{
ImageDescription *desc = data;
@ -414,7 +432,7 @@ image_desc_info_target_primaries (void *data,
static void
image_desc_info_target_luminance (void *data,
struct xx_image_description_info_v2 *info,
struct xx_image_description_info_v4 *info,
uint32_t min_lum,
uint32_t max_lum)
{
@ -427,7 +445,7 @@ image_desc_info_target_luminance (void *data,
static void
image_desc_info_target_max_cll (void *data,
struct xx_image_description_info_v2 *info,
struct xx_image_description_info_v4 *info,
uint32_t max_cll)
{
ImageDescription *desc = data;
@ -438,7 +456,7 @@ image_desc_info_target_max_cll (void *data,
static void
image_desc_info_target_max_fall (void *data,
struct xx_image_description_info_v2 *info,
struct xx_image_description_info_v4 *info,
uint32_t max_fall)
{
ImageDescription *desc = data;
@ -447,13 +465,14 @@ image_desc_info_target_max_fall (void *data,
desc->has_target_max_fall = 1;
}
static struct xx_image_description_info_v2_listener info_listener = {
static struct xx_image_description_info_v4_listener info_listener = {
image_desc_info_done,
image_desc_info_icc_file,
image_desc_info_primaries,
image_desc_info_primaries_named,
image_desc_info_tf_power,
image_desc_info_tf_named,
image_desc_info_luminances,
image_desc_info_target_primaries,
image_desc_info_target_luminance,
image_desc_info_target_max_cll,
@ -462,7 +481,7 @@ static struct xx_image_description_info_v2_listener info_listener = {
static void
image_desc_failed (void *data,
struct xx_image_description_v2 *image_desc,
struct xx_image_description_v4 *image_desc,
uint32_t cause,
const char *msg)
{
@ -471,30 +490,30 @@ image_desc_failed (void *data,
self->callback (self, GDK_COLOR_STATE_SRGB, self->data);
xx_image_description_v2_destroy (desc->image_desc);
xx_image_description_v4_destroy (desc->image_desc);
g_free (desc);
}
static void
image_desc_ready (void *data,
struct xx_image_description_v2 *image_desc,
struct xx_image_description_v4 *image_desc,
uint32_t identity)
{
ImageDescription *desc = data;
desc->info = xx_image_description_v2_get_information (image_desc);
desc->info = xx_image_description_v4_get_information (image_desc);
xx_image_description_info_v2_add_listener (desc->info, &info_listener, desc);
xx_image_description_info_v4_add_listener (desc->info, &info_listener, desc);
}
static const struct xx_image_description_v2_listener image_desc_listener = {
static const struct xx_image_description_v4_listener image_desc_listener = {
image_desc_failed,
image_desc_ready
};
static void
preferred_changed (void *data,
struct xx_color_management_surface_v2 *color_mgmt_surface)
struct xx_color_management_feedback_surface_v4 *feedback)
{
GdkWaylandColorSurface *self = data;
ImageDescription *desc;
@ -503,12 +522,12 @@ preferred_changed (void *data,
desc->surface = self;
desc->image_desc = xx_color_management_surface_v2_get_preferred (self->surface);
desc->image_desc = xx_color_management_feedback_surface_v4_get_preferred (self->feedback);
xx_image_description_v2_add_listener (desc->image_desc, &image_desc_listener, desc);
xx_image_description_v4_add_listener (desc->image_desc, &image_desc_listener, desc);
}
static const struct xx_color_management_surface_v2_listener color_listener = {
static const struct xx_color_management_feedback_surface_v4_listener color_listener = {
preferred_changed,
};
@ -524,12 +543,13 @@ gdk_wayland_color_surface_new (GdkWaylandColor *color,
self->color = color;
self->surface = xx_color_manager_v2_get_surface (color->color_manager, wl_surface);
self->surface = xx_color_manager_v4_get_surface (color->color_manager, wl_surface);
self->feedback = xx_color_manager_v4_get_feedback_surface (color->color_manager, wl_surface);
self->callback = callback;
self->data = data;
xx_color_management_surface_v2_add_listener (self->surface, &color_listener, self);
xx_color_management_feedback_surface_v4_add_listener (self->feedback, &color_listener, self);
return self;
}
@ -537,13 +557,14 @@ gdk_wayland_color_surface_new (GdkWaylandColor *color,
void
gdk_wayland_color_surface_free (GdkWaylandColorSurface *self)
{
xx_color_management_surface_v2_destroy (self->surface);
xx_color_management_surface_v4_destroy (self->surface);
xx_color_management_feedback_surface_v4_destroy (self->feedback);
g_free (self);
}
static struct xx_image_description_v2 *
static struct xx_image_description_v4 *
gdk_wayland_color_get_image_description (GdkWaylandColor *color,
GdkColorState *cs)
{
@ -563,16 +584,16 @@ void
gdk_wayland_color_surface_set_color_state (GdkWaylandColorSurface *self,
GdkColorState *cs)
{
struct xx_image_description_v2 *desc;
struct xx_image_description_v4 *desc;
desc = gdk_wayland_color_get_image_description (self->color, cs);
if (desc)
xx_color_management_surface_v2_set_image_description (self->surface,
xx_color_management_surface_v4_set_image_description (self->surface,
desc,
XX_COLOR_MANAGER_V2_RENDER_INTENT_PERCEPTUAL);
XX_COLOR_MANAGER_V4_RENDER_INTENT_PERCEPTUAL);
else
xx_color_management_surface_v2_unset_image_description (self->surface);
xx_color_management_surface_v4_unset_image_description (self->surface);
}
gboolean

View File

@ -149,7 +149,7 @@ proto_sources = [
{
'name': 'xx-color-management',
'stability': 'private',
'version': 2,
'version': 4,
},
]