Shrink shadow extents

Long time ago, Cairo shadows in both GTK3 and 4 were drawn at a size about
twice their radius. Eventually this was fixed but the shadow extents are
still calculated for the previous size and appear unreasonably large: for
example, 141px for a 50px radius shadow. This can get very noticeable in
places such as invisible window frame which gets included into screenshots.

https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/3419 just divides the
radius by 2 when drawing a shadow with Cairo, do the same when calculating
extents.

See https://gitlab.gnome.org/GNOME/gtk/-/issues/3841
This commit is contained in:
Alexander Mikhaylenko 2021-08-04 14:24:35 +05:00
parent cc6ecc8b62
commit 46a9538b6a
2 changed files with 7 additions and 7 deletions

View File

@ -2146,7 +2146,7 @@ gsk_outset_shadow_get_extents (GskOutsetShadowNode *self,
{
float clip_radius;
clip_radius = gsk_cairo_blur_compute_pixels (self->blur_radius);
clip_radius = gsk_cairo_blur_compute_pixels (self->blur_radius / 2.0);
*top = MAX (0, clip_radius + self->spread - self->dy);
*right = MAX (0, ceil (clip_radius + self->spread + self->dx));
*bottom = MAX (0, ceil (clip_radius + self->spread + self->dy));
@ -3852,7 +3852,7 @@ gsk_shadow_node_diff (GskRenderNode *node1,
return;
}
clip_radius = gsk_cairo_blur_compute_pixels (shadow1->radius);
clip_radius = gsk_cairo_blur_compute_pixels (shadow1->radius / 2.0);
top = MAX (top, ceil (clip_radius - shadow1->dy));
right = MAX (right, ceil (clip_radius + shadow1->dx));
bottom = MAX (bottom, ceil (clip_radius + shadow1->dy));
@ -3886,7 +3886,7 @@ gsk_shadow_node_get_bounds (GskShadowNode *self,
for (i = 0; i < self->n_shadows; i++)
{
float clip_radius = gsk_cairo_blur_compute_pixels (self->shadows[i].radius);
float clip_radius = gsk_cairo_blur_compute_pixels (self->shadows[i].radius / 2.0);
top = MAX (top, clip_radius - self->shadows[i].dy);
right = MAX (right, clip_radius + self->shadows[i].dx);
bottom = MAX (bottom, clip_radius + self->shadows[i].dy);
@ -4813,7 +4813,7 @@ gsk_blur_node_diff (GskRenderNode *node1,
cairo_region_t *sub;
int i, n, clip_radius;
clip_radius = ceil (gsk_cairo_blur_compute_pixels (self1->radius));
clip_radius = ceil (gsk_cairo_blur_compute_pixels (self1->radius / 2.0));
sub = cairo_region_create ();
gsk_render_node_diff (self1->child, self2->child, sub);
@ -4860,7 +4860,7 @@ gsk_blur_node_new (GskRenderNode *child,
self->child = gsk_render_node_ref (child);
self->radius = radius;
clip_radius = gsk_cairo_blur_compute_pixels (radius);
clip_radius = gsk_cairo_blur_compute_pixels (radius / 2.0);
graphene_rect_init_from_rect (&node->bounds, &child->bounds);
graphene_rect_inset (&self->render_node.bounds,

View File

@ -542,8 +542,8 @@ gtk_css_shadow_value_get_extents (const GtkCssValue *value,
spread = _gtk_css_number_value_get (shadow->spread, 0);
radius = _gtk_css_number_value_get (shadow->radius, 0);
if (value->is_filter)
radius = radius * 2;
if (!value->is_filter)
radius = radius / 2.0;
clip_radius = gsk_cairo_blur_compute_pixels (radius);
hoffset = _gtk_css_number_value_get (shadow->hoffset, 0);
voffset = _gtk_css_number_value_get (shadow->voffset, 0);