Merge branch 'wip/otte/for-master' into 'master'

Wip/otte/for master

See merge request GNOME/gtk!860
This commit is contained in:
Benjamin Otte 2019-05-21 05:22:41 +00:00
commit 321a21015e
116 changed files with 2447 additions and 1718 deletions

View File

@ -24,6 +24,17 @@
#include "gtk/css/gtkcssparserprivate.h"
#define _GDK_RGBA_DECODE(c) ((unsigned)(((c) >= 'A' && (c) <= 'F') ? ((c)-'A'+10) : \
((c) >= 'a' && (c) <= 'f') ? ((c)-'a'+10) : \
((c) >= '0' && (c) <= '9') ? ((c)-'0') : \
-1))
#define _GDK_RGBA_SELECT_COLOR(_str, index3, index6) _GDK_RGBA_DECODE (sizeof(_str) <= 4 ? (_str)[index3] : (_str)[index6])
#define GDK_RGBA(str) ((GdkRGBA) {\
((_GDK_RGBA_SELECT_COLOR(str, 0, 0) << 4) | _GDK_RGBA_SELECT_COLOR(str, 0, 1)) / 255., \
((_GDK_RGBA_SELECT_COLOR(str, 1, 2) << 4) | _GDK_RGBA_SELECT_COLOR(str, 1, 3)) / 255., \
((_GDK_RGBA_SELECT_COLOR(str, 2, 4) << 4) | _GDK_RGBA_SELECT_COLOR(str, 2, 5)) / 255., \
((sizeof(str) % 4 == 1) ? ((_GDK_RGBA_SELECT_COLOR(str, 3, 6) << 4) | _GDK_RGBA_SELECT_COLOR(str, 3, 7)) : 0xFF) / 255 })
gboolean gdk_rgba_parser_parse (GtkCssParser *parser,
GdkRGBA *rgba);

View File

@ -527,8 +527,9 @@ render_text_node (GskGLRenderer *self,
guint num_glyphs = gsk_text_node_get_num_glyphs (node);
int i;
int x_position = 0;
float x = gsk_text_node_get_x (node) + builder->dx;
float y = gsk_text_node_get_y (node) + builder->dy;
const graphene_point_t *offset = gsk_text_node_get_offset (node);
float x = offset->x + builder->dx;
float y = offset->y + builder->dy;
/* If the font has color glyphs, we don't need to recolor anything */
if (!force_color && font_has_color_glyphs (font))
@ -2605,11 +2606,16 @@ gsk_gl_renderer_add_render_ops (GskGLRenderer *self,
break;
case GSK_DEBUG_NODE:
ops_push_debug_group (builder, gsk_debug_node_get_message (node));
gsk_gl_renderer_add_render_ops (self,
gsk_debug_node_get_child (node),
builder);
ops_pop_debug_group (builder);
{
const char *message = gsk_debug_node_get_message (node);
if (message)
ops_push_debug_group (builder, message);
gsk_gl_renderer_add_render_ops (self,
gsk_debug_node_get_child (node),
builder);
if (message)
ops_pop_debug_group (builder);
}
break;
case GSK_COLOR_NODE:

View File

@ -310,34 +310,6 @@ gsk_render_node_diff (GskRenderNode *node1,
#define GSK_RENDER_NODE_SERIALIZATION_VERSION 0
#define GSK_RENDER_NODE_SERIALIZATION_ID "GskRenderNode"
/**
* gsk_render_node_serialize:
* @node: a #GskRenderNode
*
* Serializes the @node for later deserialization via
* gsk_render_node_deserialize(). No guarantees are made about the format
* used other than that the same version of GTK+ will be able to deserialize
* the result of a call to gsk_render_node_serialize() and
* gsk_render_node_deserialize() will correctly reject files it cannot open
* that were created with previous versions of GTK+.
*
* The intended use of this functions is testing, benchmarking and debugging.
* The format is not meant as a permanent storage format.
*
* Returns: a #GBytes representing the node.
**/
GBytes *
gsk_render_node_serialize (GskRenderNode *node)
{
GBytes *result;
char *str;
str = gsk_render_node_serialize_to_string (node);
result = g_bytes_new_take (str, strlen (str));
return result;
}
/**
* gsk_render_node_write_to_file:
* @node: a #GskRenderNode

View File

@ -292,10 +292,9 @@ GDK_AVAILABLE_IN_ALL
GskRenderNode * gsk_text_node_new (PangoFont *font,
PangoGlyphString *glyphs,
const GdkRGBA *color,
float x,
float y);
const graphene_point_t *offset);
GDK_AVAILABLE_IN_ALL
const PangoFont * gsk_text_node_peek_font (GskRenderNode *node);
PangoFont * gsk_text_node_peek_font (GskRenderNode *node);
GDK_AVAILABLE_IN_ALL
guint gsk_text_node_get_num_glyphs (GskRenderNode *node);
GDK_AVAILABLE_IN_ALL
@ -303,9 +302,7 @@ const PangoGlyphInfo *gsk_text_node_peek_glyphs (GskRenderNode
GDK_AVAILABLE_IN_ALL
const GdkRGBA * gsk_text_node_peek_color (GskRenderNode *node);
GDK_AVAILABLE_IN_ALL
float gsk_text_node_get_x (GskRenderNode *node);
GDK_AVAILABLE_IN_ALL
float gsk_text_node_get_y (GskRenderNode *node);
const graphene_point_t *gsk_text_node_get_offset (GskRenderNode *node);
GDK_AVAILABLE_IN_ALL
GskRenderNode * gsk_blur_node_new (GskRenderNode *child,

View File

@ -3429,8 +3429,7 @@ struct _GskTextNode
PangoFont *font;
GdkRGBA color;
double x;
double y;
graphene_point_t offset;
guint num_glyphs;
PangoGlyphInfo glyphs[];
@ -3464,7 +3463,7 @@ gsk_text_node_draw (GskRenderNode *node,
cairo_save (cr);
gdk_cairo_set_source_rgba (cr, &self->color);
cairo_translate (cr, self->x, self->y);
cairo_translate (cr, self->offset.x, self->offset.y);
pango_cairo_show_glyph_string (cr, self->font, &glyphs);
cairo_restore (cr);
@ -3480,8 +3479,7 @@ gsk_text_node_diff (GskRenderNode *node1,
if (self1->font == self2->font &&
gdk_rgba_equal (&self1->color, &self2->color) &&
self1->x == self2->x &&
self1->y == self2->y &&
graphene_point_equal (&self1->offset, &self2->offset) &&
self1->num_glyphs == self2->num_glyphs)
{
guint i;
@ -3523,8 +3521,7 @@ static const GskRenderNodeClass GSK_TEXT_NODE_CLASS = {
* @font: the #PangoFont containing the glyphs
* @glyphs: the #PangoGlyphString to render
* @color: the foreground color to render with
* @x: the x coordinate at which to put the baseline
* @y: the y coordinate at wihch to put the baseline
* @offset: offset of the baseline
*
* Creates a render node that renders the given glyphs,
* Note that @color may not be used if the font contains
@ -3533,11 +3530,10 @@ static const GskRenderNodeClass GSK_TEXT_NODE_CLASS = {
* Returns: (nullable): a new text node, or %NULL
*/
GskRenderNode *
gsk_text_node_new (PangoFont *font,
PangoGlyphString *glyphs,
const GdkRGBA *color,
float x,
float y)
gsk_text_node_new (PangoFont *font,
PangoGlyphString *glyphs,
const GdkRGBA *color,
const graphene_point_t *offset)
{
GskTextNode *self;
PangoRectangle ink_rect;
@ -3553,14 +3549,13 @@ gsk_text_node_new (PangoFont *font,
self->font = g_object_ref (font);
self->color = *color;
self->x = x;
self->y = y;
self->offset = *offset;
self->num_glyphs = glyphs->num_glyphs;
memcpy (self->glyphs, glyphs->glyphs, sizeof (PangoGlyphInfo) * glyphs->num_glyphs);
graphene_rect_init (&self->render_node.bounds,
x + ink_rect.x - 1,
y + ink_rect.y - 1,
offset->x + ink_rect.x - 1,
offset->y + ink_rect.y - 1,
ink_rect.width + 2,
ink_rect.height + 2);
@ -3577,7 +3572,7 @@ gsk_text_node_peek_color (GskRenderNode *node)
return &self->color;
}
const PangoFont *
PangoFont *
gsk_text_node_peek_font (GskRenderNode *node)
{
GskTextNode *self = (GskTextNode *) node;
@ -3607,24 +3602,14 @@ gsk_text_node_peek_glyphs (GskRenderNode *node)
return self->glyphs;
}
float
gsk_text_node_get_x (GskRenderNode *node)
const graphene_point_t *
gsk_text_node_get_offset (GskRenderNode *node)
{
GskTextNode *self = (GskTextNode *) node;
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_TEXT_NODE), 0.0);
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_TEXT_NODE), NULL);
return (float)self->x;
}
float
gsk_text_node_get_y (GskRenderNode *node)
{
GskTextNode *self = (GskTextNode *) node;
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_TEXT_NODE), 0.0);
return (float)self->y;
return &self->offset;
}
/*** GSK_BLUR_NODE ***/
@ -3681,6 +3666,7 @@ blur_once (cairo_surface_t *src,
r += c1[0];
g += c1[1];
b += c1[2];
a += c1[3];
}
p_dest_row = p_dest;
for (x = 0; x < width; x++)
@ -3689,6 +3675,7 @@ blur_once (cairo_surface_t *src,
p_dest_row[0] = div_kernel_size[r];
p_dest_row[1] = div_kernel_size[g];
p_dest_row[2] = div_kernel_size[b];
p_dest_row[3] = div_kernel_size[a];
p_dest_row += n_channels;
/* the pixel to add to the kernel */
@ -3707,6 +3694,7 @@ blur_once (cairo_surface_t *src,
r += c1[0] - c2[0];
g += c1[1] - c2[1];
b += c1[2] - c2[2];
a += c1[3] - c2[3];
}
p_src += src_rowstride;
@ -3730,6 +3718,7 @@ blur_once (cairo_surface_t *src,
r += c1[0];
g += c1[1];
b += c1[2];
a += c1[3];
}
p_dest_col = p_dest;
@ -3740,6 +3729,7 @@ blur_once (cairo_surface_t *src,
p_dest_col[0] = div_kernel_size[r];
p_dest_col[1] = div_kernel_size[g];
p_dest_col[2] = div_kernel_size[b];
p_dest_col[3] = div_kernel_size[a];
p_dest_col += dest_rowstride;
/* the pixel to add to the kernel */
@ -3757,6 +3747,7 @@ blur_once (cairo_surface_t *src,
r += c1[0] - c2[0];
g += c1[1] - c2[1];
b += c1[2] - c2[2];
a += c1[3] - c2[3];
}
p_src += n_channels;

File diff suppressed because it is too large Load Diff

View File

@ -7,6 +7,5 @@
GskRenderNode * gsk_render_node_deserialize_from_bytes (GBytes *bytes,
GskParseErrorFunc error_func,
gpointer user_data);
char * gsk_render_node_serialize_to_string (GskRenderNode *root);
#endif

View File

@ -26,6 +26,7 @@ gsk_public_sources = files([
'gskrenderer.c',
'gskrendernode.c',
'gskrendernodeimpl.c',
'gskrendernodeparser.c',
'gskroundedrect.c',
'gsktransform.c',
'gl/gskglrenderer.c',
@ -36,7 +37,6 @@ gsk_private_sources = files([
'gskdebug.c',
'gskprivate.c',
'gskprofiler.c',
'gskrendernodeparser.c',
'gl/gskshaderbuilder.c',
'gl/gskglprofiler.c',
'gl/gskglglyphcache.c',

View File

@ -100,8 +100,7 @@ gsk_vulkan_color_text_pipeline_collect_vertex_data (GskVulkanColorTextPipeline *
PangoFont *font,
guint total_glyphs,
const PangoGlyphInfo *glyphs,
float x,
float y,
const graphene_point_t *offset,
guint start_glyph,
guint num_glyphs,
float scale)
@ -132,8 +131,8 @@ gsk_vulkan_color_text_pipeline_collect_vertex_data (GskVulkanColorTextPipeline *
instance->tex_rect[2] = glyph->tw;
instance->tex_rect[3] = glyph->th;
instance->rect[0] = x + cx + glyph->draw_x;
instance->rect[1] = y + cy + glyph->draw_y;
instance->rect[0] = offset->x + cx + glyph->draw_x;
instance->rect[1] = offset->y + cy + glyph->draw_y;
instance->rect[2] = glyph->draw_width;
instance->rect[3] = glyph->draw_height;

View File

@ -28,8 +28,7 @@ void gsk_vulkan_color_text_pipeline_collect_vertex_data (Gs
PangoFont *font,
guint total_glyphs,
const PangoGlyphInfo *glyphs,
float x,
float y,
const graphene_point_t *offset,
guint start_glyph,
guint num_glyphs,
float scale);

View File

@ -1206,8 +1206,7 @@ gsk_vulkan_render_pass_collect_vertex_data (GskVulkanRenderPass *self,
gsk_text_node_get_num_glyphs (op->text.node),
gsk_text_node_peek_glyphs (op->text.node),
gsk_text_node_peek_color (op->text.node),
gsk_text_node_get_x (op->text.node),
gsk_text_node_get_y (op->text.node),
gsk_text_node_get_offset (op->text.node),
op->text.start_glyph,
op->text.num_glyphs,
op->text.scale);
@ -1225,8 +1224,7 @@ gsk_vulkan_render_pass_collect_vertex_data (GskVulkanRenderPass *self,
(PangoFont *)gsk_text_node_peek_font (op->text.node),
gsk_text_node_get_num_glyphs (op->text.node),
gsk_text_node_peek_glyphs (op->text.node),
gsk_text_node_get_x (op->text.node),
gsk_text_node_get_y (op->text.node),
gsk_text_node_get_offset (op->text.node),
op->text.start_glyph,
op->text.num_glyphs,
op->text.scale);

View File

@ -108,8 +108,7 @@ gsk_vulkan_text_pipeline_collect_vertex_data (GskVulkanTextPipeline *pipeline,
guint total_glyphs,
const PangoGlyphInfo *glyphs,
const GdkRGBA *color,
float x,
float y,
const graphene_point_t *offset,
guint start_glyph,
guint num_glyphs,
float scale)
@ -140,8 +139,8 @@ gsk_vulkan_text_pipeline_collect_vertex_data (GskVulkanTextPipeline *pipeline,
instance->tex_rect[2] = glyph->tw;
instance->tex_rect[3] = glyph->th;
instance->rect[0] = x + cx + glyph->draw_x;
instance->rect[1] = y + cy + glyph->draw_y;
instance->rect[0] = offset->x + cx + glyph->draw_x;
instance->rect[1] = offset->y + cy + glyph->draw_y;
instance->rect[2] = glyph->draw_width;
instance->rect[3] = glyph->draw_height;

View File

@ -29,8 +29,7 @@ void gsk_vulkan_text_pipeline_collect_vertex_data (GskVulka
guint total_glyphs,
const PangoGlyphInfo *glyphs,
const GdkRGBA *color,
float x,
float y,
const graphene_point_t *offset,
guint start_glyph,
guint num_glyphs,
float scale);

View File

@ -1724,8 +1724,7 @@ gtk_snapshot_append_text (GtkSnapshot *snapshot,
node = gsk_text_node_new (font,
glyphs,
color,
x + dx,
y + dy);
&GRAPHENE_POINT_INIT (x + dx, y + dy));
if (node == NULL)
return;

View File

@ -636,8 +636,7 @@ populate_render_node_properties (GtkListStore *store,
const PangoGlyphInfo *glyphs = gsk_text_node_peek_glyphs (node);
const GdkRGBA *color = gsk_text_node_peek_color (node);
guint num_glyphs = gsk_text_node_get_num_glyphs (node);
float x = gsk_text_node_get_x (node);
float y = gsk_text_node_get_y (node);
const graphene_point_t *offset = gsk_text_node_get_offset (node);
PangoFontDescription *desc;
GString *s;
int i;
@ -654,7 +653,7 @@ populate_render_node_properties (GtkListStore *store,
add_text_row (store, "Glyphs", s->str);
g_string_free (s, TRUE);
tmp = g_strdup_printf ("%.2f %.2f", x, y);
tmp = g_strdup_printf ("%.2f %.2f", offset->x, offset->y);
add_text_row (store, "Position", tmp);
g_free (tmp);

View File

@ -426,7 +426,7 @@ text (guint n)
{
GskRenderNode *node;
node = gsk_text_node_new (font, run->glyphs, &color, x, y);
node = gsk_text_node_new (font, run->glyphs, &color, &GRAPHENE_POINT_INIT (x, y));
if (node)
g_ptr_array_add (nodes, node);
}

View File

@ -61,8 +61,8 @@ deserialize_error_func (const GtkCssSection *section,
{
char *section_str = gtk_css_section_to_string (section);
g_test_message ("Error at %s: %s", section_str, error->message);
g_test_fail ();
g_print ("Error at %s: %s", section_str, error->message);
*((gboolean *) user_data) = FALSE;
free (section_str);
}
@ -84,6 +84,7 @@ main (int argc, char **argv)
GskRenderNode *node;
const char *node_file;
const char *png_file;
gboolean success = TRUE;
g_assert (argc == 3);
@ -109,12 +110,11 @@ main (int argc, char **argv)
{
g_print ("Could not open node file: %s\n", error->message);
g_clear_error (&error);
g_test_fail ();
return -1;
return 1;
}
bytes = g_bytes_new_take (contents, len);
node = gsk_render_node_deserialize (bytes, deserialize_error_func, NULL);
node = gsk_render_node_deserialize (bytes, deserialize_error_func, &success);
g_bytes_unref (bytes);
g_assert_no_error (error);
@ -135,15 +135,30 @@ main (int argc, char **argv)
/* Load the given reference png file */
reference_surface = cairo_image_surface_create_from_png (png_file);
g_assert (reference_surface != NULL);
if (cairo_surface_status (reference_surface))
{
g_print ("Error loading reference surface: %s\n",
cairo_status_to_string (cairo_surface_status (reference_surface)));
success = FALSE;
}
else
{
/* Now compare the two */
diff_surface = reftest_compare_surfaces (rendered_surface, reference_surface);
/* Now compare the two */
diff_surface = reftest_compare_surfaces (rendered_surface, reference_surface);
if (diff_surface)
{
save_image (diff_surface, node_file, ".diff.png");
cairo_surface_destroy (diff_surface);
success = FALSE;
}
}
save_image (rendered_surface, node_file, ".out.png");
if (diff_surface)
save_image (diff_surface, node_file, ".diff.png");
cairo_surface_destroy (reference_surface);
cairo_surface_destroy (rendered_surface);
g_object_unref (texture);
return diff_surface == NULL ? 0 : 1;
return success ? 0 : 1;
}

View File

@ -0,0 +1 @@
blend { }

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

View File

@ -0,0 +1,20 @@
blur { }
/* The blur algorithm isn't specified, so
don't test it. */
color {
bounds: -3 -3 50 6;
color: black;
}
color {
bounds: 47 -3 6 50;
color: black;
}
color {
bounds: 3 47 50 6;
color: black;
}
color {
bounds: -3 3 6 50;
color: black;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 167 B

View File

@ -0,0 +1 @@
border { }

Binary file not shown.

After

Width:  |  Height:  |  Size: 169 B

View File

@ -0,0 +1 @@
clip { }

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

View File

@ -0,0 +1 @@
color-matrix { }

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

View File

@ -0,0 +1 @@
color { }

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

View File

@ -0,0 +1,8 @@
container { }
/* We need to contain something because 0x0 nodes
cause NULL textures */
color {
bounds: -1 -1 1 1;
color: transparent;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 B

View File

@ -0,0 +1,9 @@
cross-fade { }
/* This is not very useful as a test, because the
resulting color is undefined, because 0.5 * 255
can be rounded to either 127 or 128 by the renderers.
But at least we know they get the size right... */
color {
color: black;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

View File

@ -0,0 +1 @@
debug { }

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

View File

@ -0,0 +1 @@
inset-shadow { }

Binary file not shown.

After

Width:  |  Height:  |  Size: 164 B

View File

@ -0,0 +1 @@
linear-gradient { }

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 B

View File

@ -0,0 +1,9 @@
opacity { }
/* This is not very useful as a test, because the
resulting color is undefined, because 0.5 * 255
can be rounded to either 127 or 128 by the renderers.
But at least we know they get the size right... */
color {
color: black;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 105 B

View File

@ -0,0 +1 @@
outset-shadow { }

Binary file not shown.

After

Width:  |  Height:  |  Size: 168 B

View File

@ -0,0 +1 @@
repeat { }

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

View File

@ -0,0 +1 @@
rounded-clip { }

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

View File

@ -0,0 +1 @@
shadow { }

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 B

View File

@ -0,0 +1 @@
text { }

Binary file not shown.

After

Width:  |  Height:  |  Size: 405 B

View File

@ -0,0 +1,12 @@
texture { }
/* The bilinear filtering code can differ
between implementations, so cover it */
color {
bounds: 21 0 10 50;
color: black;
}
color {
bounds: 0 21 50 10;
color: black;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 B

View File

@ -0,0 +1 @@
transform { }

Binary file not shown.

After

Width:  |  Height:  |  Size: 153 B

View File

@ -17,14 +17,6 @@ node_parser = executable(
install_dir: testexecdir
)
serialize_deserialize = executable(
'serialize-deserialize',
['serialize-deserialize.c'],
dependencies: libgtk_dep,
install: get_option('install-tests'),
install_dir: testexecdir,
)
compare_render_tests = [
'blend-normal',
'blend-difference',
@ -32,6 +24,25 @@ compare_render_tests = [
'clipped_rounded_clip',
'color-blur0',
'cross-fade-in-opacity',
'empty-blend',
'empty-blur',
'empty-border',
'empty-clip',
'empty-color',
'empty-color-matrix',
'empty-container',
'empty-cross-fade',
'empty-debug',
'empty-inset-shadow',
'empty-linear-gradient',
'empty-opacity',
'empty-outset-shadow',
'empty-repeat',
'empty-rounded-clip',
'empty-shadow',
'empty-text',
'empty-texture',
'empty-transform',
'opacity_clip',
'outset_shadow_offset_both',
'outset_shadow_offset_x',
@ -69,47 +80,78 @@ foreach renderer : renderers
endforeach
node_parser_tests = [
'crash1',
'crash2',
'crash3',
'crash4',
'blend.node',
'border.node',
'color.node',
'crash1.errors',
'crash1.node',
'crash1.ref.node',
'crash2.errors',
'crash2.node',
'crash2.ref.node',
'crash3.node',
'crash3.ref.node',
'crash4.errors',
'crash4.node',
'crash4.ref.node',
'debug.node',
'empty-blend.node',
'empty-blend.ref.node',
'empty-blur.node',
'empty-blur.ref.node',
'empty-border.node',
'empty-border.ref.node',
'empty-clip.node',
'empty-clip.ref.node',
'empty-color.node',
'empty-color.ref.node',
'empty-color-matrix.node',
'empty-color-matrix.ref.node',
'empty-container.node',
'empty-container.ref.node',
'empty-cross-fade.node',
'empty-cross-fade.ref.node',
'empty-debug.node',
'empty-debug.ref.node',
'empty-inset-shadow.node',
'empty-inset-shadow.ref.node',
'empty-linear-gradient.node',
'empty-linear-gradient.ref.node',
'empty-opacity.node',
'empty-opacity.ref.node',
'empty-outset-shadow.node',
'empty-outset-shadow.ref.node',
'empty-repeat.node',
'empty-repeat.ref.node',
'empty-rounded-clip.node',
'empty-rounded-clip.ref.node',
'empty-shadow.node',
'empty-shadow.ref.node',
'empty-text.node',
'empty-text.ref.node',
'empty-texture.node',
'empty-texture.ref.node',
'empty-transform.node',
'empty-transform.ref.node',
'rounded-rect.node',
'shadow.node',
'testswitch.node',
'widgetfactory.node',
]
foreach test : node_parser_tests
test('parser ' + test, node_parser,
args: [join_paths(meson.current_source_dir(), 'nodeparser', test + '.node')],
env: [ 'GIO_USE_VOLUME_MONITOR=unix',
'GSETTINGS_BACKEND=memory',
'GTK_CSD=1',
'G_ENABLE_DIAGNOSTIC=0',
'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()),
'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
'GSK_RENDERER=opengl'
],
suite: 'gsk')
endforeach
serialize_deserialize_tests = [
'blend',
'border',
'color',
'debug',
'rounded-rect',
'shadow',
'testswitch',
'widgetfactory',
]
foreach test : serialize_deserialize_tests
test('serialize-deserialize ' + test, serialize_deserialize,
args: [join_paths(meson.current_source_dir(), 'serializedeserialize', test + '.node')],
env: [ 'GIO_USE_VOLUME_MONITOR=unix',
'GSETTINGS_BACKEND=memory',
'GTK_CSD=1',
'G_ENABLE_DIAGNOSTIC=0',
'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()),
'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
'GSK_RENDERER=opengl'
],
suite: 'gsk')
if test.endswith('.node') and not test.endswith('.ref.node')
test('parser ' + test, node_parser,
args: [ join_paths(meson.current_source_dir(), 'nodeparser', test)
],
env: [ 'GIO_USE_VOLUME_MONITOR=unix',
'GSETTINGS_BACKEND=memory',
'GTK_CSD=1',
'G_ENABLE_DIAGNOSTIC=0',
'G_TEST_SRCDIR=@0@'.format(meson.current_source_dir()),
'G_TEST_BUILDDIR=@0@'.format(meson.current_build_dir()),
'GSK_RENDERER=opengl'
],
suite: 'gsk')
endif
endforeach

View File

@ -1,44 +1,343 @@
/*
* Copyright (C) 2011 Red Hat Inc.
*
* Author:
* Benjamin Otte <otte@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gtk/gtk.h>
static char *
test_get_reference_file (const char *node_file)
{
GString *file = g_string_new (NULL);
if (g_str_has_suffix (node_file, ".node"))
g_string_append_len (file, node_file, strlen (node_file) - 5);
else
g_string_append (file, node_file);
g_string_append (file, ".ref.node");
if (!g_file_test (file->str, G_FILE_TEST_EXISTS))
{
g_string_free (file, TRUE);
return g_strdup (node_file);
}
return g_string_free (file, FALSE);
}
static char *
test_get_errors_file (const char *node_file)
{
GString *file = g_string_new (NULL);
if (g_str_has_suffix (node_file, ".node"))
g_string_append_len (file, node_file, strlen (node_file) - 5);
else
g_string_append (file, node_file);
g_string_append (file, ".errors");
if (!g_file_test (file->str, G_FILE_TEST_EXISTS))
{
g_string_free (file, TRUE);
return NULL;
}
return g_string_free (file, FALSE);
}
static GBytes *
diff_with_file (const char *file1,
GBytes *input,
GError **error)
{
GSubprocess *process;
GBytes *output;
process = g_subprocess_new (G_SUBPROCESS_FLAGS_STDIN_PIPE
| G_SUBPROCESS_FLAGS_STDOUT_PIPE,
error,
"diff", "-u", file1, "-", NULL);
if (process == NULL)
return NULL;
if (!g_subprocess_communicate (process,
input,
NULL,
&output,
NULL,
error))
{
g_object_unref (process);
return NULL;
}
return output;
}
static void
append_error_value (GString *string,
GType enum_type,
guint value)
{
GEnumClass *enum_class;
GEnumValue *enum_value;
enum_class = g_type_class_ref (enum_type);
enum_value = g_enum_get_value (enum_class, value);
g_string_append (string, enum_value->value_name);
g_type_class_unref (enum_class);
}
static void
deserialize_error_func (const GtkCssSection *section,
const GError *error,
gpointer user_data)
{
char *section_str = gtk_css_section_to_string (section);
GString *errors = user_data;
char *section_string;
/* We want to parse invalid node files in this test and simply assert that the
* parser doesn't crash. So, just g_message() here instead of a warning or error. */
g_message ("Error at %s: %s", section_str, error->message);
section_string = gtk_css_section_to_string (section);
free (section_str);
g_string_append_printf (errors,
"%s: error: ",
section_string);
g_free (section_string);
if (error->domain == GTK_CSS_PARSER_ERROR)
append_error_value (errors, GTK_TYPE_CSS_PARSER_ERROR, error->code);
else if (error->domain == GTK_CSS_PARSER_WARNING)
append_error_value (errors, GTK_TYPE_CSS_PARSER_WARNING, error->code);
else
g_string_append_printf (errors,
"%s %u\n",
g_quark_to_string (error->domain),
error->code);
g_string_append_c (errors, '\n');
}
static gboolean
parse_node_file (GFile *file, gboolean generate)
{
char *node_file, *reference_file, *errors_file;
GskRenderNode *node;
GString *errors;
GBytes *diff, *bytes;
GError *error = NULL;
gboolean result = TRUE;
bytes = g_file_load_bytes (file, NULL, NULL, &error);
if (error)
{
g_print ("Error loading file: %s\n", error->message);
g_clear_error (&error);
return FALSE;
}
g_assert (bytes != NULL);
errors = g_string_new ("");
node = gsk_render_node_deserialize (bytes, deserialize_error_func, errors);
g_bytes_unref (bytes);
bytes = gsk_render_node_serialize (node);
gsk_render_node_unref (node);
if (generate)
{
g_print ("%s", (char *) g_bytes_get_data (bytes, NULL));
g_bytes_unref (bytes);
g_string_free (errors, TRUE);
return TRUE;
}
node_file = g_file_get_path (file);
reference_file = test_get_reference_file (node_file);
diff = diff_with_file (reference_file, bytes, &error);
g_assert_no_error (error);
if (diff && g_bytes_get_size (diff) > 0)
{
g_print ("Resulting file doesn't match reference:\n%s\n",
(const char *) g_bytes_get_data (diff, NULL));
result = FALSE;
}
g_free (reference_file);
g_clear_pointer (&diff, g_bytes_unref);
errors_file = test_get_errors_file (node_file);
if (errors_file)
{
GBytes *error_bytes = g_string_free_to_bytes (errors);
diff = diff_with_file (errors_file, error_bytes, &error);
g_assert_no_error (error);
if (diff && g_bytes_get_size (diff) > 0)
{
g_print ("Errors don't match expected errors:\n%s\n",
(const char *) g_bytes_get_data (diff, NULL));
result = FALSE;
}
g_clear_pointer (&diff, g_bytes_unref);
g_clear_pointer (&error_bytes, g_bytes_unref);
}
else if (errors->str[0])
{
g_print ("Unexpected errors:\n%s\n", errors->str);
result = FALSE;
g_string_free (errors, TRUE);
}
else
{
g_string_free (errors, TRUE);
}
g_free (errors_file);
g_free (node_file);
g_bytes_unref (bytes);
return result;
}
static gboolean
test_file (GFile *file)
{
return parse_node_file (file, FALSE);
}
static int
compare_files (gconstpointer a, gconstpointer b)
{
GFile *file1 = G_FILE (a);
GFile *file2 = G_FILE (b);
char *path1, *path2;
int result;
path1 = g_file_get_path (file1);
path2 = g_file_get_path (file2);
result = strcmp (path1, path2);
g_free (path1);
g_free (path2);
return result;
}
static gboolean
test_files_in_directory (GFile *dir)
{
GFileEnumerator *enumerator;
GFileInfo *info;
GList *l, *files;
GError *error = NULL;
gboolean result = TRUE;
enumerator = g_file_enumerate_children (dir, G_FILE_ATTRIBUTE_STANDARD_NAME, 0, NULL, &error);
g_assert_no_error (error);
files = NULL;
while ((info = g_file_enumerator_next_file (enumerator, NULL, &error)))
{
const char *filename;
filename = g_file_info_get_name (info);
if (!g_str_has_suffix (filename, ".node") ||
g_str_has_suffix (filename, ".out.node") ||
g_str_has_suffix (filename, ".ref.node"))
{
g_object_unref (info);
continue;
}
files = g_list_prepend (files, g_file_get_child (dir, filename));
g_object_unref (info);
}
g_assert_no_error (error);
g_object_unref (enumerator);
files = g_list_sort (files, compare_files);
for (l = files; l; l = l->next)
{
result &= test_file (l->data);
}
g_list_free_full (files, g_object_unref);
return result;
}
int
main (int argc, char **argv)
{
GError *error = NULL;
GskRenderNode *node;
GBytes *bytes;
GFile *file;
gboolean success;
g_assert (argc == 2);
gtk_test_init (&argc, &argv);
gtk_init ();
if (argc < 2)
{
const char *basedir;
GFile *dir;
file = g_file_new_for_commandline_arg (argv[1]);
bytes = g_file_load_bytes (file, NULL, NULL, &error);
g_assert_no_error (error);
g_assert (bytes != NULL);
basedir = g_test_get_dir (G_TEST_DIST);
dir = g_file_new_for_path (basedir);
success = test_files_in_directory (dir);
node = gsk_render_node_deserialize (bytes, deserialize_error_func, NULL);
if (error)
g_test_message ("Error: %s\n", error->message);
g_object_unref (dir);
}
else if (strcmp (argv[1], "--generate") == 0)
{
if (argc >= 3)
{
GFile *file = g_file_new_for_commandline_arg (argv[2]);
g_clear_error (&error);
g_clear_pointer (&node, gsk_render_node_unref);
g_bytes_unref (bytes);
g_object_unref (file);
success = parse_node_file (file, TRUE);
return 0;
g_object_unref (file);
}
else
success = FALSE;
}
else
{
guint i;
success = TRUE;
for (i = 1; i < argc; i++)
{
GFile *file = g_file_new_for_commandline_arg (argv[i]);
success &= test_file (file);
g_object_unref (file);
}
}
return success ? 0 : 1;
}

View File

@ -0,0 +1,24 @@
blend {
bottom: container {
}
top: container {
}
}
blend {
bottom: container {
}
mode: color-dodge;
top: container {
}
}
blend {
bottom: color {
bounds: 0 0 50 50;
color: rgb(255,0,204);
}
mode: difference;
top: color {
bounds: 0 0 50 50;
color: rgb(255,0,204);
}
}

View File

@ -0,0 +1,4 @@
border {
colors: rgb(213,208,204);
outline: -1 -1 50 26 / 13;
}

View File

@ -0,0 +1,4 @@
color {
bounds: 100 100 200 300;
color: rgb(255,0,0);
}

View File

@ -0,0 +1,3 @@
<data>:2:9-10: error: GTK_CSS_PARSER_ERROR_SYNTAX
<data>:2:17-3:1: error: GTK_CSS_PARSER_WARNING_SYNTAX
<data>:1:1-3:1: error: GTK_CSS_PARSER_WARNING_SYNTAX

View File

@ -0,0 +1,6 @@
opacity {
child: color {
bounds: 0 0 50 50;
color: rgb(255,0,204);
}
}

View File

@ -0,0 +1,3 @@
<data>:2:3-7: error: GTK_CSS_PARSER_ERROR_SYNTAX
<data>:2:15-4:1: error: GTK_CSS_PARSER_WARNING_SYNTAX
<data>:1:1-4:1: error: GTK_CSS_PARSER_WARNING_SYNTAX

View File

@ -0,0 +1,10 @@
cross-fade {
end: color {
bounds: 0 0 50 50;
color: rgb(255,0,204);
}
start: color {
bounds: 0 0 50 50;
color: rgb(170,255,0);
}
}

View File

@ -0,0 +1,17 @@
cross-fade {
end: color {
bounds: 5 5 10 10;
color: rgb(0,0,255);
}
progress: 0.2;
start: container {
color {
bounds: 0 0 10 10;
color: rgb(255,0,0);
}
color {
bounds: 10 10 10 10;
color: rgb(0,128,0);
}
}
}

View File

@ -0,0 +1 @@
<data>:6:3-7:1: error: GTK_CSS_PARSER_WARNING_SYNTAX

View File

@ -0,0 +1,7 @@
blur {
blur: 40;
child: color {
bounds: 100 100 100 100;
color: rgb(255,0,204);
}
}

View File

@ -1,4 +1,5 @@
debug {
child: container {
}
message: "I'm a debug node.";
child: container {}
}

View File

@ -0,0 +1 @@
blend { }

View File

@ -0,0 +1,10 @@
blend {
bottom: color {
bounds: 0 0 50 50;
color: rgb(170,255,0);
}
top: color {
bounds: 0 0 50 50;
color: rgb(255,0,204);
}
}

View File

@ -0,0 +1 @@
blur { }

View File

@ -0,0 +1,6 @@
blur {
child: color {
bounds: 0 0 50 50;
color: rgb(255,0,204);
}
}

View File

@ -0,0 +1 @@
border { }

View File

@ -0,0 +1,3 @@
border {
outline: 0 0 50 50;
}

View File

@ -0,0 +1 @@
clip { }

View File

@ -0,0 +1,7 @@
clip {
child: color {
bounds: 0 0 50 50;
color: rgb(255,0,204);
}
clip: 0 0 50 50;
}

View File

@ -0,0 +1 @@
color-matrix { }

View File

@ -0,0 +1,6 @@
color-matrix {
child: color {
bounds: 0 0 50 50;
color: rgb(255,0,204);
}
}

View File

@ -0,0 +1 @@
color { }

View File

@ -0,0 +1,4 @@
color {
bounds: 0 0 50 50;
color: rgb(255,0,204);
}

View File

@ -0,0 +1 @@
container { }

View File

@ -0,0 +1 @@
cross-fade { }

View File

@ -0,0 +1,10 @@
cross-fade {
end: color {
bounds: 0 0 50 50;
color: rgb(255,0,204);
}
start: color {
bounds: 0 0 50 50;
color: rgb(170,255,0);
}
}

View File

@ -0,0 +1 @@
debug { }

View File

@ -0,0 +1,6 @@
debug {
child: color {
bounds: 0 0 50 50;
color: rgb(255,0,204);
}
}

View File

@ -0,0 +1 @@
inset-shadow { }

View File

@ -0,0 +1,3 @@
inset-shadow {
outline: 0 0 50 50;
}

View File

@ -0,0 +1 @@
linear-gradient { }

View File

@ -0,0 +1,6 @@
linear-gradient {
bounds: 0 0 50 50;
end: 0 50;
start: 0 0;
stops: 0 rgb(170,255,0), 1 rgb(255,0,204);
}

View File

@ -0,0 +1 @@
opacity { }

View File

@ -0,0 +1,6 @@
opacity {
child: color {
bounds: 0 0 50 50;
color: rgb(255,0,204);
}
}

View File

@ -0,0 +1 @@
outset-shadow { }

View File

@ -0,0 +1,3 @@
outset-shadow {
outline: 0 0 50 50;
}

View File

@ -0,0 +1 @@
repeat { }

View File

@ -0,0 +1,6 @@
repeat {
child: color {
bounds: 0 0 50 50;
color: rgb(255,0,204);
}
}

View File

@ -0,0 +1 @@
rounded-clip { }

Some files were not shown because too many files have changed in this diff Show More