Shrink shadow extents
authorAlexander Mikhaylenko <alexm@gnome.org>
Wed, 4 Aug 2021 09:24:35 +0000 (14:24 +0500)
committerAlexander Mikhaylenko <alexm@gnome.org>
Wed, 4 Aug 2021 09:47:17 +0000 (14:47 +0500)
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

gsk/gskrendernodeimpl.c
gtk/gtkcssshadowvalue.c

index 9a9705d0fde61c7eb826b34a5a7e20bdcc620cd7..8412f4696c42d86a007edafa1b6e219529d26b53 100644 (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,
index 94fccffd820a9be07ff5a753b2c90b593c69f52c..ba74f321adcd4e8d8dee16d7a924e36d1868edb2 100644 (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);