summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Larsson <alexl@redhat.com>2017-01-11 16:14:03 +0100
committerAlexander Larsson <alexl@redhat.com>2017-01-11 16:14:03 +0100
commitc00f8dce9f8076e3e914210dda62e7fd2207d1e4 (patch)
tree016ec44ab7b6eea3a595c8f2cdebe3ddb7d1196a
parent275185d4157f40def0ec34c98058a98c4b98382f (diff)
downloadgtk+-wip/alexl/snapshot-int-translate.tar.gz
GtkSnapshot: Always use int for the translationwip/alexl/snapshot-int-translate
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.
-rw-r--r--gtk/gtkcssgadget.c2
-rw-r--r--gtk/gtkcssimagelinear.c2
-rw-r--r--gtk/gtkcssshadowvalue.c4
-rw-r--r--gtk/gtkiconview.c14
-rw-r--r--gtk/gtkrenderborder.c2
-rw-r--r--gtk/gtksnapshot.c21
-rw-r--r--gtk/gtksnapshot.h6
-rw-r--r--gtk/gtksnapshotprivate.h4
-rw-r--r--gtk/gtkwidget.c16
9 files changed, 40 insertions, 31 deletions
diff --git a/gtk/gtkcssgadget.c b/gtk/gtkcssgadget.c
index 3fb2f0af37..f2ee45609f 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 592180a020..7200c48951 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 1be9708159..ed56504166 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 6f092fb539..2cbc6802aa 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 31f5725efb..a42f74e42b 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 72f1b1586f..08db8c5b63 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 f03cef7a31..0b691c3486 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 2384a8b55f..91d1b66ef6 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 fc5edbc889..2f93d63413 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;