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.
This commit is contained in:
Alexander Larsson 2017-01-11 16:14:03 +01:00
parent 275185d415
commit c00f8dce9f
9 changed files with 40 additions and 31 deletions

View File

@ -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);

View File

@ -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% */

View File

@ -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);

View File

@ -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,

View File

@ -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)
{

View File

@ -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;
}
/**

View File

@ -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,

View File

@ -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 {

View File

@ -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;