Commit 321a2101 authored by Benjamin Otte's avatar Benjamin Otte
Browse files

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

Wip/otte/for master

See merge request !860
parents fc2dc82b 63a8144e
Pipeline #83174 passed with stages
in 21 minutes and 41 seconds
......@@ -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);
......
......@@ -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:
......
......@@ -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
......
......@@ -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,
......
......@@ -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)
{
GskTextNode *self = (GskTextNode *) node;
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_TEXT_NODE), 0.0);
return (float)self->x;
}
float
gsk_text_node_get_y (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->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;
......
This diff is collapsed.
......@@ -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
......@@ -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',
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
......
......@@ -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);
......
......@@ -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);
}
......
......@@ -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);
/* Now compare the two */
diff_surface = reftest_compare_surfaces (rendered_surface, reference_surface);
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);
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;
}
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;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment