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

stroke: Turn stroke copy intialization into a macro

See merge request GNOME/gtk!6698
This commit is contained in:
Benjamin Otte
2023-12-28 07:01:07 +00:00
20 changed files with 189 additions and 29 deletions

View File

@@ -122,8 +122,11 @@ _g_string_append_float (GString *string,
const char *prefix,
float f)
{
char buf[G_ASCII_DTOSTR_BUF_SIZE];
g_string_append (string, prefix);
g_string_append_printf (string, "%.*g", FLT_DECIMAL_DIG, f);
g_ascii_formatd (buf, G_ASCII_DTOSTR_BUF_SIZE, "%.9g", f);
g_string_append (string, buf);
}
static void

View File

@@ -4523,8 +4523,6 @@ gsk_fill_node_draw (GskRenderNode *node,
{
GskFillNode *self = (GskFillNode *) node;
cairo_save (cr);
switch (self->fill_rule)
{
case GSK_FILL_RULE_WINDING:
@@ -4549,8 +4547,6 @@ gsk_fill_node_draw (GskRenderNode *node,
cairo_clip (cr);
gsk_render_node_draw (self->child, cr);
}
cairo_restore (cr);
}
static void
@@ -4829,7 +4825,7 @@ gsk_stroke_node_new (GskRenderNode *child,
self->child = gsk_render_node_ref (child);
self->path = gsk_path_ref (path);
gsk_stroke_init_copy (&self->stroke, stroke);
self->stroke = GSK_STROKE_INIT_COPY (stroke);
if (gsk_path_get_stroke_bounds (self->path, &self->stroke, &stroke_bounds))
gsk_rect_intersection (&stroke_bounds, &child->bounds, &node->bounds);

View File

@@ -46,22 +46,12 @@
#include <math.h>
static void
gsk_rounded_rect_normalize_in_place (GskRoundedRect *self)
static float
gsk_rounded_rect_get_corner_scale_factor (GskRoundedRect *self)
{
float factor = 1.0;
float corners;
guint i;
graphene_rect_normalize (&self->bounds);
for (i = 0; i < 4; i++)
{
self->corner[i].width = MAX (self->corner[i].width, 0);
self->corner[i].height = MAX (self->corner[i].height, 0);
}
/* clamp border radius, following CSS specs */
corners = self->corner[GSK_CORNER_TOP_LEFT].width + self->corner[GSK_CORNER_TOP_RIGHT].width;
if (corners > self->bounds.size.width)
factor = MIN (factor, self->bounds.size.width / corners);
@@ -78,6 +68,26 @@ gsk_rounded_rect_normalize_in_place (GskRoundedRect *self)
if (corners > self->bounds.size.height)
factor = MIN (factor, self->bounds.size.height / corners);
return factor;
}
static void
gsk_rounded_rect_normalize_in_place (GskRoundedRect *self)
{
float factor;
guint i;
graphene_rect_normalize (&self->bounds);
for (i = 0; i < 4; i++)
{
self->corner[i].width = MAX (self->corner[i].width, 0);
self->corner[i].height = MAX (self->corner[i].height, 0);
}
/* clamp border radius, following CSS specs */
factor = gsk_rounded_rect_get_corner_scale_factor (self);
for (i = 0; i < 4; i++)
graphene_size_scale (&self->corner[i], factor, &self->corner[i]);
}
@@ -812,7 +822,8 @@ gsk_rounded_rect_intersection (const GskRoundedRect *a,
check_corner (a, b,
GSK_CORNER_BOTTOM_RIGHT,
right, bottom,
result))
result) &&
gsk_rounded_rect_get_corner_scale_factor (result) >= 1.0)
return GSK_INTERSECTION_NONEMPTY;
return GSK_INTERSECTION_NOT_REPRESENTABLE;

View File

@@ -79,7 +79,7 @@ gsk_stroke_copy (const GskStroke *other)
self = g_new (GskStroke, 1);
gsk_stroke_init_copy (self, other);
*self = GSK_STROKE_INIT_COPY (other);
return self;
}

View File

@@ -37,14 +37,16 @@ struct _GskStroke
float dash_offset;
};
static inline void
gsk_stroke_init_copy (GskStroke *stroke,
const GskStroke *other)
{
*stroke = *other;
stroke->dash = g_memdup (other->dash, stroke->n_dash * sizeof (float));
}
#define GSK_STROKE_INIT_COPY(_stroke) ((GskStroke) {\
.line_width = _stroke->line_width, \
.line_cap = _stroke->line_cap, \
.line_join = _stroke->line_join, \
.miter_limit = _stroke->miter_limit, \
.dash = g_memdup (_stroke->dash, _stroke->n_dash * sizeof (float)), \
.n_dash = _stroke->n_dash, \
.dash_length = _stroke->dash_length, \
.dash_offset = _stroke->dash_offset, \
})
static inline void
gsk_stroke_clear (GskStroke *stroke)

View File

@@ -1301,7 +1301,7 @@ gtk_snapshot_push_stroke (GtkSnapshot *snapshot,
gtk_snapshot_clear_stroke);
state->data.stroke.path = gsk_path_ref (path);
gsk_stroke_init_copy (&state->data.stroke.stroke, stroke);
state->data.stroke.stroke = GSK_STROKE_INIT_COPY (stroke);
}
static GskRenderNode *

View File

@@ -0,0 +1,26 @@
opacity {
child: fill {
child: opacity {
opacity: 0.4;
child: color {
bounds: 0 0 50 50;
color: rgb(0,255,0);
}
}
path: "\
M 10 0\
L 40 0\
L 40 10\
L 50 10\
L 50 40\
L 40 40\
L 40 50\
L 10 50\
L 10 40\
L 0 40\
L 0 10\
L 10 10\
Z";
fill-rule: winding;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 117 B

View File

@@ -0,0 +1,24 @@
fill {
child: transform {
transform: translate3d(0, 0, 1);
child: color {
bounds: 0 0 50 50;
color: rgb(0,255,0);
}
}
path: "\
M 10 0\
L 40 0\
L 40 10\
L 50 10\
L 50 40\
L 40 40\
L 40 50\
L 10 50\
L 10 40\
L 0 40\
L 0 10\
L 10 10\
Z";
fill-rule: winding;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

View File

@@ -0,0 +1,7 @@
repeating-radial-gradient {
bounds: 0 0 100 100;
center: 50 50;
hradius: 50;
vradius: 50;
stops: 0 rgb(255,0,0), 0.03125 rgb(255,0,0), 0.0625 rgb(255,0,0), 0.09375 rgb(255,0,0), 0.125 rgb(255,0,0), 0.15625 rgb(255,0,0), 0.1875 rgb(255,0,0), 0.21875 rgb(255,0,0), 0.25 rgb(255,0,0), 0.28125 rgb(255,0,0), 0.3125 rgb(255,0,0), 0.34375 rgb(255,0,0), 0.375 rgb(255,0,0), 0.40625 rgb(255,0,0), 0.4375 rgb(255,0,0), 0.46875 rgb(255,0,0), 0.5 rgb(255,0,0), 0.53125 rgb(255,0,0), 0.5625 rgb(255,0,0), 0.59375 rgb(255,0,0), 0.625 rgb(255,0,0), 0.65625 rgb(255,0,0), 0.6875 rgb(255,0,0), 0.71875 rgb(255,0,0), 0.75 rgb(255,0,0), 0.78125 rgb(255,0,0), 0.8125 rgb(255,0,0), 0.84375 rgb(255,0,0), 0.875 rgb(255,0,0), 0.90625 rgb(255,0,0), 0.9375 rgb(255,0,0), 0.96875 rgb(255,0,0), 1 rgb(255,0,0);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

@@ -0,0 +1,26 @@
color {
bounds: 0 0 50 50;
color: black;
}
clip {
clip: 0 0 50 50;
child: rounded-clip {
clip: -4780 -4780 32768 32768 / 16384;
child: container {
color {
bounds: 0 0 50 50;
color: black;
}
mask {
source: color {
bounds: 25 25 32768 32768;
color: red;
}
mask: color {
bounds: 25 25 32768 32768;
color: blue;
}
}
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 94 B

View File

@@ -0,0 +1,28 @@
opacity {
child: stroke {
child: opacity {
opacity: 0.4;
child: color {
bounds: 0 0 50 50;
color: rgb(255,0,0);
}
}
path: "\
M 15 5\
L 35 5\
L 35 15\
L 45 15\
L 45 35\
L 35 35\
L 35 45\
L 15 45\
L 15 35\
L 5 35\
L 5 15\
L 15 15\
Z";
line-width: 10;
line-cap: butt;
line-join: miter;
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 129 B

View File

@@ -0,0 +1,26 @@
stroke {
child: transform {
transform: translate3d(0, 0, 1);
child: color {
bounds: 0 0 50 50;
color: rgb(255,0,0);
}
}
path: "\
M 15 5\
L 35 5\
L 35 15\
L 45 15\
L 45 35\
L 35 35\
L 35 45\
L 15 45\
L 15 35\
L 5 35\
L 5 15\
L 15 15\
Z";
line-width: 10;
line-cap: butt;
line-join: miter;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 B

View File

@@ -66,6 +66,8 @@ compare_render_tests = [
'empty-texture',
'empty-transform',
'fill',
'fill-opacity',
'fill-with-3d-contents-nogl-nocairo',
'huge-height',
'huge-width',
'inset-shadow-multiple',
@@ -90,6 +92,7 @@ compare_render_tests = [
'outset_shadow_offset_y',
'outset_shadow_rounded_top',
'outset_shadow_simple',
'radial-gradient-with-64-colorstops',
'repeat',
'repeating-linear-gradient-edge-colors',
'repeating-radial-gradient-edge-colors',
@@ -103,6 +106,7 @@ compare_render_tests = [
'repeat-scaling',
'repeat-texture',
'repeating-gradient-scaled',
'rounded-clip-with-huge-bounds-nogl',
'scale-textures-negative-ngl',
'scale-up-down',
'scaled-cairo',
@@ -115,6 +119,8 @@ compare_render_tests = [
'shadow-opacity',
'shrink-rounded-border',
'stroke',
'stroke-opacity',
'stroke-with-3d-contents-nogl-nocairo',
'texture-coords',
'texture-scale-filters-nocairo',
'texture-scale-magnify-10000x',

View File

@@ -346,6 +346,11 @@ test_intersect (void)
ROUNDED_RECT_INIT_UNIFORM(0, 0, 21, 21, 21, 0, 0, 0),
GSK_INTERSECTION_NOT_REPRESENTABLE,
},
{
ROUNDED_RECT_INIT_UNIFORM(0, 0, 50, 50, 50, 0, 50, 0),
ROUNDED_RECT_INIT_UNIFORM(0, 0, 50, 50, 0, 50, 0, 50),
GSK_INTERSECTION_NOT_REPRESENTABLE,
},
};
gsize i;