[gtk+/wip/alexl/snapshot-int-translate] GtkSnapshot: Always use int for the translation



commit c00f8dce9f8076e3e914210dda62e7fd2207d1e4
Author: Alexander Larsson <alexl redhat com>
Date:   Wed Jan 11 16:14:03 2017 +0100

    GtkSnapshot: Always use int for the translation
    
    We already take ints when setting the translation, so it can't
    currently take any other values. Additionally, I was seeing large
    costs in int -> double -> int for the rects in
    gtk_snapshot_clips_rect(), as all callers really are ints (widget
    allocations) and the clip region is int-based.
    
    This change completely cleared a 2% rectangle_init_from_graphene from
    the profile and is likely to have nice performance effects elsewhere
    too.

 gtk/gtkcssgadget.c       |    2 +-
 gtk/gtkcssimagelinear.c  |    2 +-
 gtk/gtkcssshadowvalue.c  |    4 ++--
 gtk/gtkiconview.c        |   14 +++++++-------
 gtk/gtkrenderborder.c    |    2 +-
 gtk/gtksnapshot.c        |   21 +++++++++++----------
 gtk/gtksnapshot.h        |    6 +++---
 gtk/gtksnapshotprivate.h |    4 ++--
 gtk/gtkwidget.c          |   16 ++++++++++++----
 9 files changed, 40 insertions(+), 31 deletions(-)
---
diff --git a/gtk/gtkcssgadget.c b/gtk/gtkcssgadget.c
index 3fb2f0a..f2ee456 100644
--- a/gtk/gtkcssgadget.c
+++ b/gtk/gtkcssgadget.c
@@ -834,7 +834,7 @@ gtk_css_gadget_snapshot (GtkCssGadget *gadget,
 
   clip = priv->clip;
   shift_allocation (gadget, &clip);
-  if (gtk_snapshot_clips_rect (snapshot, &GRAPHENE_RECT_INIT(clip.x, clip.y, clip.width, clip.height)))
+  if (gtk_snapshot_clips_rect (snapshot, &clip))
     return;
 
   gtk_css_gadget_get_margin_box (gadget, &margin_box);
diff --git a/gtk/gtkcssimagelinear.c b/gtk/gtkcssimagelinear.c
index 592180a..7200c48 100644
--- a/gtk/gtkcssimagelinear.c
+++ b/gtk/gtkcssimagelinear.c
@@ -136,7 +136,7 @@ gtk_css_image_linear_snapshot (GtkCssImage        *image,
   GtkCssImageLinear *linear = GTK_CSS_IMAGE_LINEAR (image);
   GskColorStop *stops;
   GskRenderNode *node;
-  double off_x, off_y; /* snapshot offset */
+  int off_x, off_y; /* snapshot offset */
   double angle; /* actual angle of the gradiant line in degrees */
   double x, y; /* coordinates of start point */
   double length; /* distance in pixels for 100% */
diff --git a/gtk/gtkcssshadowvalue.c b/gtk/gtkcssshadowvalue.c
index 1be9708..ed56504 100644
--- a/gtk/gtkcssshadowvalue.c
+++ b/gtk/gtkcssshadowvalue.c
@@ -1039,7 +1039,7 @@ gtk_css_shadow_value_snapshot_outset (const GtkCssValue    *shadow,
 {
   GskRoundedRect outline;
   GskRenderNode *node;
-  double off_x, off_y;
+  int off_x, off_y;
 
   g_return_if_fail (shadow->class == &GTK_CSS_VALUE_SHADOW);
 
@@ -1070,7 +1070,7 @@ gtk_css_shadow_value_snapshot_inset (const GtkCssValue   *shadow,
 {
   GskRoundedRect outline;
   GskRenderNode *node;
-  double off_x, off_y;
+  int off_x, off_y;
 
   g_return_if_fail (shadow->class == &GTK_CSS_VALUE_SHADOW);
 
diff --git a/gtk/gtkiconview.c b/gtk/gtkiconview.c
index 6f092fb..2cbc680 100644
--- a/gtk/gtkiconview.c
+++ b/gtk/gtkiconview.c
@@ -1783,14 +1783,14 @@ gtk_icon_view_snapshot (GtkWidget   *widget,
   for (icons = icon_view->priv->items; icons; icons = icons->next)
     {
       GtkIconViewItem *item = icons->data;
+      cairo_rectangle_int_t area;
 
-      if (!gtk_snapshot_clips_rect (snapshot,
-                                    &GRAPHENE_RECT_INIT (
-                                        item->cell_area.x      - icon_view->priv->item_padding,
-                                        item->cell_area.y      - icon_view->priv->item_padding,
-                                        item->cell_area.width  + icon_view->priv->item_padding * 2,
-                                        item->cell_area.height + icon_view->priv->item_padding * 2
-                                    )))
+      area.x = item->cell_area.x - icon_view->priv->item_padding;
+      area.y = item->cell_area.y      - icon_view->priv->item_padding;
+      area.width = item->cell_area.width  + icon_view->priv->item_padding * 2;
+      area.height = item->cell_area.height + icon_view->priv->item_padding * 2;
+
+      if (!gtk_snapshot_clips_rect (snapshot, &area))
         {
           gtk_icon_view_snapshot_item (icon_view, snapshot, item,
                                        item->cell_area.x, item->cell_area.y,
diff --git a/gtk/gtkrenderborder.c b/gtk/gtkrenderborder.c
index 31f5725..a42f74e 100644
--- a/gtk/gtkrenderborder.c
+++ b/gtk/gtkrenderborder.c
@@ -414,7 +414,7 @@ snapshot_frame_fill (GtkSnapshot          *snapshot,
 {
   GskRoundedRect offset_outline;
   GskRenderNode *node;
-  double off_x, off_y;
+  int off_x, off_y;
 
   if (hidden_side)
     {
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c
index 72f1b15..08db8c5 100644
--- a/gtk/gtksnapshot.c
+++ b/gtk/gtksnapshot.c
@@ -78,8 +78,8 @@ static GtkSnapshotState *
 gtk_snapshot_state_new (GtkSnapshotState       *parent,
                         char                   *name,
                         cairo_region_t         *clip,
-                        double                  translate_x,
-                        double                  translate_y,
+                        int                     translate_x,
+                        int                     translate_y,
                         GtkSnapshotCollectFunc  collect_func)
 {
   GtkSnapshotState *state;
@@ -797,8 +797,8 @@ gtk_snapshot_translate_2d (GtkSnapshot *snapshot,
  **/
 void
 gtk_snapshot_get_offset (GtkSnapshot *snapshot,
-                         double      *x,
-                         double      *y)
+                         int         *x,
+                         int         *y)
 {
   if (x)
     *x = snapshot->state->translate_x;
@@ -996,18 +996,19 @@ gtk_snapshot_append_color_node (GtkSnapshot           *snapshot,
  */
 gboolean
 gtk_snapshot_clips_rect (GtkSnapshot           *snapshot,
-                         const graphene_rect_t *bounds)
+                         const cairo_rectangle_int_t *rect)
 {
-  graphene_rect_t offset_bounds;
-  cairo_rectangle_int_t rect;
+  cairo_rectangle_int_t offset_rect;
 
   if (snapshot->state->clip_region == NULL)
     return FALSE;
 
-  graphene_rect_offset_r (bounds, snapshot->state->translate_x, snapshot->state->translate_y, 
&offset_bounds);
-  rectangle_init_from_graphene (&rect, &offset_bounds);
+  offset_rect.x = rect->x + snapshot->state->translate_x;
+  offset_rect.y = rect->y + snapshot->state->translate_y;
+  offset_rect.width = rect->width;
+  offset_rect.height = rect->height;
 
-  return cairo_region_contains_rectangle (snapshot->state->clip_region, &rect) == CAIRO_REGION_OVERLAP_OUT;
+  return cairo_region_contains_rectangle (snapshot->state->clip_region, &offset_rect) == 
CAIRO_REGION_OVERLAP_OUT;
 }
 
 /**
diff --git a/gtk/gtksnapshot.h b/gtk/gtksnapshot.h
index f03cef7..0b691c3 100644
--- a/gtk/gtksnapshot.h
+++ b/gtk/gtksnapshot.h
@@ -90,8 +90,8 @@ void            gtk_snapshot_translate_2d               (GtkSnapshot
                                                          int                     y);
 GDK_AVAILABLE_IN_3_90
 void            gtk_snapshot_get_offset                 (GtkSnapshot            *snapshot,
-                                                         double                 *x,
-                                                         double                 *y);
+                                                         int                    *x,
+                                                         int                    *y);
 
 GDK_AVAILABLE_IN_3_90
 void            gtk_snapshot_append_node                (GtkSnapshot            *snapshot,
@@ -116,7 +116,7 @@ void            gtk_snapshot_append_color_node          (GtkSnapshot
 
 GDK_AVAILABLE_IN_3_90
 gboolean        gtk_snapshot_clips_rect                 (GtkSnapshot            *snapshot,
-                                                         const graphene_rect_t  *bounds);
+                                                         const cairo_rectangle_int_t  *bounds);
 
 GDK_AVAILABLE_IN_3_90
 void            gtk_snapshot_render_background          (GtkSnapshot            *snapshot,
diff --git a/gtk/gtksnapshotprivate.h b/gtk/gtksnapshotprivate.h
index 2384a8b..91d1b66 100644
--- a/gtk/gtksnapshotprivate.h
+++ b/gtk/gtksnapshotprivate.h
@@ -37,8 +37,8 @@ struct _GtkSnapshotState {
   GPtrArray             *nodes;
 
   cairo_region_t        *clip_region;
-  double                 translate_x;
-  double                 translate_y;
+  int                    translate_x;
+  int                    translate_y;
 
   GtkSnapshotCollectFunc collect_func;
   union {
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index fc5edbc..2f93d63 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -15591,15 +15591,17 @@ gtk_widget_snapshot (GtkWidget   *widget,
   GtkCssValue *filter_value;
   RenderMode mode;
   double opacity;
+  cairo_rectangle_int_t offset_clip;
 
   if (_gtk_widget_get_alloc_needed (widget))
     return;
 
   priv = widget->priv;
-  graphene_rect_init (&bounds, priv->clip.x - priv->allocation.x,
-                      priv->clip.y - priv->allocation.y,
-                      priv->clip.width, priv->clip.height);
-  if (gtk_snapshot_clips_rect (snapshot, &bounds))
+  offset_clip = priv->clip;
+  offset_clip.x -= priv->allocation.x;
+  offset_clip.y -= priv->allocation.y;
+
+  if (gtk_snapshot_clips_rect (snapshot, &offset_clip))
     return;
 
   if (_gtk_widget_is_toplevel (widget))
@@ -15620,6 +15622,12 @@ gtk_widget_snapshot (GtkWidget   *widget,
   filter_value = _gtk_style_context_peek_property (_gtk_widget_get_style_context (widget), 
GTK_CSS_PROPERTY_FILTER);
   gtk_css_filter_value_push_snapshot (filter_value, snapshot);
 
+  graphene_rect_init (&bounds,
+                      offset_clip.x,
+                      offset_clip.y,
+                      offset_clip.width,
+                      offset_clip.height);
+
   if (mode == RENDER_DRAW)
     {
       cairo_t *cr;


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