app: don't bother to emit an "update" region if no handler is connected

because constructing the region can be expensive. Also make sure not
to use g_object_set() if nothing would change to further reduce
"update" emissions.
This commit is contained in:
Michael Natterer
2010-10-01 17:43:41 +02:00
parent d9cd9f8a07
commit f0d01f611c

View File

@ -234,32 +234,42 @@ gimp_canvas_item_dispatch_properties_changed (GObject *object,
GParamSpec **pspecs) GParamSpec **pspecs)
{ {
GimpCanvasItem *item = GIMP_CANVAS_ITEM (object); GimpCanvasItem *item = GIMP_CANVAS_ITEM (object);
GdkRegion *before;
GdkRegion *region;
before = gimp_canvas_item_get_extents (item); if (g_signal_has_handler_pending (object, item_signals[UPDATE], 0, FALSE))
G_OBJECT_CLASS (parent_class)->dispatch_properties_changed (object,
n_pspecs,
pspecs);
region = gimp_canvas_item_get_extents (item);
if (! region)
{ {
region = before; GdkRegion *before;
GdkRegion *region;
before = gimp_canvas_item_get_extents (item);
G_OBJECT_CLASS (parent_class)->dispatch_properties_changed (object,
n_pspecs,
pspecs);
region = gimp_canvas_item_get_extents (item);
if (! region)
{
region = before;
}
else if (before)
{
gdk_region_union (region, before);
gdk_region_destroy (before);
}
if (region)
{
g_signal_emit (object, item_signals[UPDATE], 0,
region);
gdk_region_destroy (region);
}
} }
else if (before) else
{ {
gdk_region_union (region, before); G_OBJECT_CLASS (parent_class)->dispatch_properties_changed (object,
gdk_region_destroy (before); n_pspecs,
} pspecs);
if (region)
{
g_signal_emit (object, item_signals[UPDATE], 0,
region);
gdk_region_destroy (region);
} }
} }
@ -346,22 +356,40 @@ void
gimp_canvas_item_set_line_cap (GimpCanvasItem *item, gimp_canvas_item_set_line_cap (GimpCanvasItem *item,
cairo_line_cap_t line_cap) cairo_line_cap_t line_cap)
{ {
GimpCanvasItemPrivate *private;
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item)); g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
g_object_set (item, private = GET_PRIVATE (item);
"line-cap", line_cap,
NULL); line_cap = CLAMP (line_cap,
CAIRO_LINE_CAP_BUTT,
CAIRO_LINE_CAP_SQUARE);
if (private->line_cap != line_cap)
{
private->line_cap = line_cap;
g_object_notify (G_OBJECT (item), "line-cap");
}
} }
void void
gimp_canvas_item_set_highlight (GimpCanvasItem *item, gimp_canvas_item_set_highlight (GimpCanvasItem *item,
gboolean highlight) gboolean highlight)
{ {
GimpCanvasItemPrivate *private;
g_return_if_fail (GIMP_IS_CANVAS_ITEM (item)); g_return_if_fail (GIMP_IS_CANVAS_ITEM (item));
g_object_set (item, private = GET_PRIVATE (item);
"highlight", highlight,
NULL); highlight = highlight ? TRUE : FALSE;
if (private->highlight != highlight)
{
private->highlight = highlight;
g_object_notify (G_OBJECT (item), "highlight");
}
} }
gboolean gboolean