diff --git a/gdk/gdkcolorprivate.h b/gdk/gdkcolorprivate.h index cb4185b006..93369100a9 100644 --- a/gdk/gdkcolorprivate.h +++ b/gdk/gdkcolorprivate.h @@ -65,7 +65,7 @@ G_STATIC_ASSERT (G_STRUCT_OFFSET (GdkColor, b) == G_STRUCT_OFFSET (GdkColor, val G_STATIC_ASSERT (G_STRUCT_OFFSET (GdkColor, a) == G_STRUCT_OFFSET (GdkColor, values[3])); #endif -#define GDK_COLOR_INIT_SRGB(r,g,b,a) { \ +#define GDK_COLOR_SRGB(r,g,b,a) (GdkColor) { \ .color_state = GDK_COLOR_STATE_SRGB, \ .values = { (r), (g), (b), (a) } \ } diff --git a/gsk/gpu/gskgpunodeprocessor.c b/gsk/gpu/gskgpunodeprocessor.c index c281dc545b..2cdb7b5b7e 100644 --- a/gsk/gpu/gskgpunodeprocessor.c +++ b/gsk/gpu/gskgpunodeprocessor.c @@ -2521,16 +2521,13 @@ static void gsk_gpu_node_processor_add_gl_shader_node (GskGpuNodeProcessor *self, GskRenderNode *node) { - GdkColor pink = GDK_COLOR_INIT_SRGB (1, 105/255., 180/255., 1); - gsk_gpu_color_op (self->frame, gsk_gpu_clip_get_shader_clip (&self->clip, &self->offset, &node->bounds), self->ccs, self->opacity, &self->offset, &node->bounds, - &pink); - gdk_color_finish (&pink); + &GDK_COLOR_SRGB (1, 105/255., 180/255., 1)); } static void diff --git a/gsk/gskrendernodeparser.c b/gsk/gskrendernodeparser.c index 9f70510049..6ff2ced496 100644 --- a/gsk/gskrendernodeparser.c +++ b/gsk/gskrendernodeparser.c @@ -1635,6 +1635,51 @@ gtk_css_parser_consume_number_or_percentage (GtkCssParser *parser, } } +typedef struct { + Context *context; + GdkColor *color; +} ColorArgData; + +static guint +parse_color_arg (GtkCssParser *parser, + guint arg, + gpointer data) +{ + ColorArgData *d = data; + GdkColorState *color_state; + float values[4]; + + if (!parse_color_state (parser, d->context, &color_state)) + return 0; + + for (int i = 0; i < 3; i++) + { + double number; + + if (!gtk_css_parser_consume_number_or_percentage (parser, 0, 1, &number)) + return 0; + + values[i] = number; + } + + if (gtk_css_parser_try_delim (parser, '/')) + { + double number; + + if (!gtk_css_parser_consume_number_or_percentage (parser, 0, 1, &number)) + return 0; + + values[3] = number; + } + else + { + values[3] = 1; + } + + gdk_color_init (d->color, color_state, values); + return 1; +} + static gboolean parse_color2 (GtkCssParser *parser, Context *context, @@ -1644,50 +1689,11 @@ parse_color2 (GtkCssParser *parser, if (gtk_css_parser_has_function (parser, "color")) { - GdkColorState *color_state; - float values[4]; + ColorArgData data = { context, color }; - gtk_css_parser_start_block (parser); + if (!gtk_css_parser_consume_function (parser, 1, 1, parse_color_arg, &data)) + return FALSE; - if (!parse_color_state (parser, context, &color_state)) - { - gtk_css_parser_end_block (parser); - return FALSE; - } - - for (int i = 0; i < 3; i++) - { - double number; - - if (!gtk_css_parser_consume_number_or_percentage (parser, 0, 1, &number)) - { - gtk_css_parser_end_block (parser); - return FALSE; - } - - values[i] = number; - } - - if (gtk_css_parser_try_delim (parser, '/')) - { - double number; - - if (!gtk_css_parser_consume_number_or_percentage (parser, 0, 1, &number)) - { - gtk_css_parser_end_block (parser); - return FALSE; - } - - values[3] = number; - } - else - { - values[3] = 1; - } - - gtk_css_parser_end_block (parser); - - gdk_color_init ((GdkColor *) color, color_state, values); return TRUE; } else if (gdk_rgba_parser_parse (parser, &rgba)) @@ -1704,7 +1710,7 @@ parse_color_node (GtkCssParser *parser, Context *context) { graphene_rect_t bounds = GRAPHENE_RECT_INIT (0, 0, 50, 50); - GdkColor color = GDK_COLOR_INIT_SRGB (1, 0, 0.8, 1); + GdkColor color = GDK_COLOR_SRGB (1, 0, 0.8, 1); const Declaration declarations[] = { { "bounds", parse_rect, NULL, &bounds }, { "color", parse_color2, NULL, &color }, diff --git a/testsuite/gsk/meson.build b/testsuite/gsk/meson.build index d3a959632f..4f449957e0 100644 --- a/testsuite/gsk/meson.build +++ b/testsuite/gsk/meson.build @@ -325,6 +325,7 @@ node_parser_tests = [ 'color.node', 'color2.node', 'color3.node', + 'color4.node', 'conic-gradient.node', 'conic-gradient.ref.node', 'crash1.errors', diff --git a/testsuite/gsk/nodeparser/color4.errors b/testsuite/gsk/nodeparser/color4.errors new file mode 100644 index 0000000000..f6574d0778 --- /dev/null +++ b/testsuite/gsk/nodeparser/color4.errors @@ -0,0 +1 @@ +:2:27-28: error: GTK_CSS_PARSER_ERROR_SYNTAX diff --git a/testsuite/gsk/nodeparser/color4.node b/testsuite/gsk/nodeparser/color4.node new file mode 100644 index 0000000000..a2bbe4b7d4 --- /dev/null +++ b/testsuite/gsk/nodeparser/color4.node @@ -0,0 +1,3 @@ +color { + color: color(srgb 1 2 3 4 5 6); +} diff --git a/testsuite/gsk/nodeparser/color4.ref.node b/testsuite/gsk/nodeparser/color4.ref.node new file mode 100644 index 0000000000..15a0f7553a --- /dev/null +++ b/testsuite/gsk/nodeparser/color4.ref.node @@ -0,0 +1,4 @@ +color { + bounds: 0 0 50 50; + color: rgb(255,255,255); +}