Merge branch 'matthiasc/for-main' into 'main'
rewrite color parsing in the node parser See merge request GNOME/gtk!7560
This commit is contained in:
@@ -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) } \
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 },
|
||||
|
||||
@@ -325,6 +325,7 @@ node_parser_tests = [
|
||||
'color.node',
|
||||
'color2.node',
|
||||
'color3.node',
|
||||
'color4.node',
|
||||
'conic-gradient.node',
|
||||
'conic-gradient.ref.node',
|
||||
'crash1.errors',
|
||||
|
||||
1
testsuite/gsk/nodeparser/color4.errors
Normal file
1
testsuite/gsk/nodeparser/color4.errors
Normal file
@@ -0,0 +1 @@
|
||||
<data>:2:27-28: error: GTK_CSS_PARSER_ERROR_SYNTAX
|
||||
3
testsuite/gsk/nodeparser/color4.node
Normal file
3
testsuite/gsk/nodeparser/color4.node
Normal file
@@ -0,0 +1,3 @@
|
||||
color {
|
||||
color: color(srgb 1 2 3 4 5 6);
|
||||
}
|
||||
4
testsuite/gsk/nodeparser/color4.ref.node
Normal file
4
testsuite/gsk/nodeparser/color4.ref.node
Normal file
@@ -0,0 +1,4 @@
|
||||
color {
|
||||
bounds: 0 0 50 50;
|
||||
color: rgb(255,255,255);
|
||||
}
|
||||
Reference in New Issue
Block a user