[gtk/wip/exalm/shadow-extents] Shrink shadow extents




commit 46a9538b6a8b866d07e63c2ecf28c2046196f53b
Author: Alexander Mikhaylenko <alexm gnome org>
Date:   Wed Aug 4 14:24:35 2021 +0500

    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

 gsk/gskrendernodeimpl.c | 10 +++++-----
 gtk/gtkcssshadowvalue.c |  4 ++--
 2 files changed, 7 insertions(+), 7 deletions(-)
---
diff --git a/gsk/gskrendernodeimpl.c b/gsk/gskrendernodeimpl.c
index 9a9705d0fd..8412f4696c 100644
--- a/gsk/gskrendernodeimpl.c
+++ b/gsk/gskrendernodeimpl.c
@@ -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,
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index 94fccffd82..ba74f321ad 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -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);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]