[gtk+/wip/ebassi/gsk-renderer: 184/194] Make outer shadows work again



commit ae5244a6c8751dfd08b2f1b97a35fdd21c82e418
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Aug 12 17:13:52 2016 -0400

    Make outer shadows work again
    
    Change get_render_node to return nodes that are sized to the clip
    area and expect to be placed at the clip position; change
    gtk_container_propagate_render_node to place child render nodes
    accordingly, and change gtk_css_gadget_get_render_node to return
    nodes that are sized accordingly as well.

 gtk/gtkcontainer.c |    4 +-
 gtk/gtkcssgadget.c |   62 ++++++++++++++++++++++++++-------------------------
 gtk/gtkwidget.c    |   14 ++---------
 3 files changed, 37 insertions(+), 43 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 486abb6..429348f 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -3905,7 +3905,7 @@ propagate_render_node (GtkWidget *child,
   /* translate coordinates. Ugly business, that. */
   if (!_gtk_widget_get_has_window (GTK_WIDGET (data->container)))
     {
-      _gtk_widget_get_allocation (GTK_WIDGET (data->container), &allocation);
+      gtk_widget_get_clip (GTK_WIDGET (data->container), &allocation);
       x = -allocation.x;
       y = -allocation.y;
     }
@@ -3933,7 +3933,7 @@ propagate_render_node (GtkWidget *child,
 
   if (!_gtk_widget_get_has_window (child))
     {
-      _gtk_widget_get_allocation (child, &allocation);
+      gtk_widget_get_clip (child, &allocation);
       x += allocation.x;
       y += allocation.y;
     }
diff --git a/gtk/gtkcssgadget.c b/gtk/gtkcssgadget.c
index 3151f45..2efac8d 100644
--- a/gtk/gtkcssgadget.c
+++ b/gtk/gtkcssgadget.c
@@ -67,6 +67,7 @@ struct _GtkCssGadgetPrivate {
   GtkWidget     *owner;
   GtkAllocation  allocated_size;
   gint           allocated_baseline;
+  GtkAllocation  clip;
 };
 
 enum {
@@ -742,6 +743,7 @@ gtk_css_gadget_allocate (GtkCssGadget        *gadget,
       out_clip->y = 0;
       out_clip->width = 0;
       out_clip->height = 0;
+      priv->clip = *out_clip;
       return;
     }
 
@@ -806,6 +808,8 @@ gtk_css_gadget_allocate (GtkCssGadget        *gadget,
                                              allocation->height - margin.top - margin.bottom,
                                              &tmp_clip))
     gdk_rectangle_union (&tmp_clip, out_clip, out_clip);
+
+  priv->clip = *out_clip;
 }
 
 GskRenderNode *
@@ -814,27 +818,30 @@ gtk_css_gadget_get_render_node (GtkCssGadget  *gadget,
                                 gboolean       draw_focus)
 {
   GtkCssGadgetPrivate *priv = gtk_css_gadget_get_instance_private (gadget);
-  GtkBorder margin, border, padding;
+  GtkBorder clip, margin, border, padding;
   GtkCssStyle *style;
   cairo_t *cr;
   GskRenderNode *box_node, *bg_node, *border_node;
   graphene_rect_t bounds;
-  graphene_point3d_t p;
-  graphene_matrix_t m;
-  int x, y, width, height;
+  int width, height;
   int contents_x, contents_y, contents_width, contents_height;
   GtkAllocation margin_box;
+  GtkAllocation clip_box;
   char *str;
 
   if (!gtk_css_gadget_get_visible (gadget))
     return NULL;
 
-  gtk_css_gadget_get_margin_box (gadget, &margin_box);
+  margin_box = priv->allocated_size;
+  clip_box = priv->clip;
 
-  x = margin_box.x;
-  y = margin_box.y;
-  width = margin_box.width;
-  height = margin_box.height;
+  width = clip_box.width;
+  height = clip_box.height;
+
+  clip.left = margin_box.x - clip_box.x;
+  clip.top = margin_box.y - clip_box.y;
+  clip.right = clip_box.width - margin_box.width - clip.left;
+  clip.bottom = clip_box.height - margin_box.height - clip.top;
 
   if (width < 0 || height < 0)
     {
@@ -842,21 +849,16 @@ gtk_css_gadget_get_render_node (GtkCssGadget  *gadget,
                  "Did you forget to allocate a size? (node %s owner %s)",
                  gtk_css_node_get_name (gtk_css_gadget_get_node (gadget)),
                  G_OBJECT_TYPE_NAME (gtk_css_gadget_get_owner (gadget)));
-      x = 0;
-      y = 0;
       width = gtk_widget_get_allocated_width (priv->owner);
       height = gtk_widget_get_allocated_height (priv->owner);
     }
 
   graphene_rect_init (&bounds, 0, 0, width, height);
-  graphene_point3d_init (&p, x, y, 0);
-  graphene_matrix_init_translate (&m, &p);
 
   str = g_strconcat ("Box<", G_OBJECT_TYPE_NAME (gtk_css_gadget_get_owner (gadget)), ">", NULL);
   box_node = gsk_renderer_create_render_node (renderer);
   gsk_render_node_set_name (box_node, str);
   gsk_render_node_set_bounds (box_node, &bounds);
-  gsk_render_node_set_transform (box_node, &m);
   g_free (str);
 
   style = gtk_css_gadget_get_style (gadget);
@@ -872,10 +874,10 @@ gtk_css_gadget_get_render_node (GtkCssGadget  *gadget,
 
   gtk_css_style_render_background (style,
                                    cr,
-                                   margin.left,
-                                   margin.top,
-                                   width - margin.left - margin.right,
-                                   height - margin.top - margin.bottom,
+                                   clip.left + margin.left,
+                                   clip.top + margin.top,
+                                   width - clip.left - clip.right - margin.left - margin.right,
+                                   height - clip.top - clip.bottom - margin.top - margin.bottom,
                                    gtk_css_node_get_junction_sides (priv->node));
 
   cairo_destroy (cr);
@@ -892,10 +894,10 @@ gtk_css_gadget_get_render_node (GtkCssGadget  *gadget,
 
   gtk_css_style_render_border (style,
                                cr,
-                               margin.left,
-                               margin.top,
-                               width - margin.left - margin.right,
-                               height - margin.top - margin.bottom,
+                               clip.left + margin.left,
+                               clip.top + margin.top,
+                               width - clip.left - clip.right - margin.left - margin.right,
+                               height - clip.top - clip.bottom - margin.top - margin.bottom,
                                0,
                                gtk_css_node_get_junction_sides (priv->node));
 
@@ -905,10 +907,10 @@ gtk_css_gadget_get_render_node (GtkCssGadget  *gadget,
   gsk_render_node_append_child (box_node, border_node);
   gsk_render_node_unref (border_node);
 
-  contents_x = margin.left + border.left + padding.left;
-  contents_y = margin.top + border.top + padding.top;
-  contents_width = width - margin.left - margin.right - border.left - border.right - padding.left - 
padding.right;
-  contents_height = height - margin.top - margin.bottom - border.top - border.bottom - padding.top - 
padding.bottom;
+  contents_x = clip.left + margin.left + border.left + padding.left;
+  contents_y = clip.top + margin.top + border.top + padding.top;
+  contents_width = width - clip.left - clip.right - margin.left - margin.right - border.left - border.right 
- padding.left - padding.right;
+  contents_height = height - clip.top - clip.bottom - margin.top - margin.bottom - border.top - 
border.bottom - padding.top - padding.bottom;
 
   if (contents_width > 0 && contents_height > 0)
     {
@@ -958,10 +960,10 @@ gtk_css_gadget_get_render_node (GtkCssGadget  *gadget,
       cr = gsk_render_node_get_draw_context (focus_node);
       gtk_css_style_render_outline (style,
                                     cr,
-                                    margin.left,
-                                    margin.top,
-                                    width - margin.left - margin.right,
-                                    height - margin.top - margin.bottom);
+                                    clip.left + margin.left,
+                                    clip.top + margin.top,
+                                    width - clip.left - clip.right - margin.left - margin.right,
+                                    height - clip.top - clip.bottom - margin.top - margin.bottom);
       g_free (str);
       cairo_destroy (cr);
 
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 2dad6a6..4cb3a01 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -17472,20 +17472,15 @@ gtk_widget_create_render_node (GtkWidget   *widget,
                                const char  *name)
 {
   GskRenderNode *res = gsk_renderer_create_render_node (renderer);
-  GtkAllocation allocation, clip;
-  graphene_point3d_t p;
+  GtkAllocation clip;
   graphene_rect_t bounds;
-  graphene_matrix_t m;
 
-  _gtk_widget_get_allocation (widget, &allocation);
   gtk_widget_get_clip (widget, &clip);
 
   graphene_rect_init (&bounds, 0, 0, clip.width, clip.height);
-  graphene_matrix_init_translate (&m, graphene_point3d_init (&p, allocation.x, allocation.y, 0));
 
   gsk_render_node_set_name (res, name);
   gsk_render_node_set_bounds (res, &bounds);
-  gsk_render_node_set_transform (res, &m);
 
   return res;
 }
@@ -17508,8 +17503,7 @@ gtk_widget_get_render_node (GtkWidget   *widget,
   gtk_widget_get_clip (widget, &clip);
   _gtk_widget_get_allocation (widget, &alloc);
   graphene_rect_init (&bounds, 0, 0, clip.width, clip.height);
-  graphene_matrix_init_translate (&m, graphene_point3d_init (&p, alloc.x, alloc.y, 0.f));
-  graphene_point3d_init (&p, clip.x - alloc.x, clip.y - alloc.y, 0.f);
+  graphene_matrix_init_translate (&m, graphene_point3d_init (&p, clip.x, clip.y, 0.f));
 
   /* Compatibility mode: if the widget does not have a render node, we draw
    * using gtk_widget_draw() on a temporary node
@@ -17526,7 +17520,6 @@ gtk_widget_get_render_node (GtkWidget   *widget,
       gsk_render_node_set_name (tmp, str);
       gsk_render_node_set_bounds (tmp, &bounds);
       gsk_render_node_set_transform (tmp, &m);
-      gsk_render_node_set_anchor_point (tmp, &p);
 
       cr = gsk_render_node_get_draw_context (tmp);
       cairo_translate (cr, alloc.x - clip.x, alloc.y - clip.y);
@@ -17556,10 +17549,9 @@ gtk_widget_get_render_node (GtkWidget   *widget,
           tmp = gsk_renderer_create_render_node (renderer);
           gsk_render_node_set_name (tmp, str);
           gsk_render_node_set_bounds (tmp, &bounds);
-          gsk_render_node_set_transform (tmp, &m);
-          gsk_render_node_set_anchor_point (tmp, &p);
 
           cr = gsk_render_node_get_draw_context (tmp);
+          cairo_translate (cr, alloc.x - clip.x, alloc.y - clip.y);
           g_signal_emit (widget, widget_signals[DRAW], 0, cr, &result);
           cairo_destroy (cr);
 


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