* Deprecated function; use g_object_ref() instead.
*
* Return value: the gc.
+ *
+ * Deprecated: 2.0: Use g_object_ref() instead.
**/
GdkGC *
gdk_gc_ref (GdkGC *gc)
*
* Decrement the reference count of @gc.
*
- * Deprecated: Use g_object_unref() instead.
+ * Deprecated: 2.0: Use g_object_unref() instead.
**/
void
gdk_gc_unref (GdkGC *gc)
}
-/* returns old clip region */
void
_gdk_gc_add_drawable_clip (GdkGC *gc,
guint32 region_tag,
GdkPixmap *new_mask;
GdkGC *tmp_gc;
GdkColor black = {0, 0, 0, 0};
-
- priv->old_clip_mask = g_object_ref (priv->clip_mask);
- gdk_drawable_get_size (priv->old_clip_mask, &w, &h);
-
- new_mask = gdk_pixmap_new (priv->old_clip_mask, w, h, -1);
- tmp_gc = _gdk_drawable_get_scratch_gc ((GdkDrawable *)new_mask, FALSE);
-
- gdk_gc_set_foreground (tmp_gc, &black);
- gdk_draw_rectangle (new_mask, tmp_gc, TRUE, 0, 0, -1, -1);
- _gdk_gc_set_clip_region_internal (tmp_gc, region, TRUE); /* Takes ownership of region */
- gdk_draw_drawable (new_mask,
- tmp_gc,
- priv->old_clip_mask,
- 0, 0,
- 0, 0,
- -1, -1);
- gdk_gc_set_clip_region (tmp_gc, NULL);
- gdk_gc_set_clip_mask (gc, new_mask);
+ GdkRectangle r;
+ GdkOverlapType overlap;
+
+ gdk_drawable_get_size (priv->clip_mask, &w, &h);
+
+ r.x = 0;
+ r.y = 0;
+ r.width = w;
+ r.height = h;
+
+ /* Its quite common to expose areas that are completely in or outside
+ * the region, so we try to avoid allocating bitmaps that are just fully
+ * set or completely unset.
+ */
+ overlap = gdk_region_rect_in (region, &r);
+ if (overlap == GDK_OVERLAP_RECTANGLE_PART)
+ {
+ /* The region and the mask intersect, create a new clip mask that
+ includes both areas */
+ priv->old_clip_mask = g_object_ref (priv->clip_mask);
+ new_mask = gdk_pixmap_new (priv->old_clip_mask, w, h, -1);
+ tmp_gc = _gdk_drawable_get_scratch_gc ((GdkDrawable *)new_mask, FALSE);
+
+ gdk_gc_set_foreground (tmp_gc, &black);
+ gdk_draw_rectangle (new_mask, tmp_gc, TRUE, 0, 0, -1, -1);
+ _gdk_gc_set_clip_region_internal (tmp_gc, region, TRUE); /* Takes ownership of region */
+ gdk_draw_drawable (new_mask,
+ tmp_gc,
+ priv->old_clip_mask,
+ 0, 0,
+ 0, 0,
+ -1, -1);
+ gdk_gc_set_clip_region (tmp_gc, NULL);
+ gdk_gc_set_clip_mask (gc, new_mask);
+ g_object_unref (new_mask);
+ }
+ else if (overlap == GDK_OVERLAP_RECTANGLE_OUT)
+ {
+ /* No intersection, set empty clip region */
+ GdkRegion *empty = gdk_region_new ();
+
+ gdk_region_destroy (region);
+ priv->old_clip_mask = g_object_ref (priv->clip_mask);
+ priv->clip_region = empty;
+ _gdk_windowing_gc_set_clip_region (gc, empty, FALSE);
+ }
+ else
+ {
+ /* Completely inside region, don't set unnecessary clip */
+ gdk_region_destroy (region);
+ return;
+ }
}
else
{
priv->clip_region = region;
if (priv->old_clip_region)
gdk_region_intersect (region, priv->old_clip_region);
-
+
_gdk_windowing_gc_set_clip_region (gc, priv->clip_region, FALSE);
}
gdk_gc_set_clip_mask (gc, priv->old_clip_mask);
g_object_unref (priv->old_clip_mask);
priv->old_clip_mask = NULL;
+
+ if (priv->clip_region)
+ {
+ g_object_unref (priv->clip_region);
+ priv->clip_region = NULL;
+ }
}
else
{
return GDK_GC_GET_PRIVATE (gc)->clip_region;
}
+/**
+ * _gdk_gc_get_clip_mask:
+ * @gc: a #GdkGC
+ *
+ * Gets the current clip mask for @gc, if any.
+ *
+ * Return value: the clip mask for the GC, or %NULL.
+ * (if a clip region is set, the return will be %NULL)
+ * This value is owned by the GC and must not be freed.
+ **/
+GdkBitmap *
+_gdk_gc_get_clip_mask (GdkGC *gc)
+{
+ g_return_val_if_fail (GDK_IS_GC (gc), NULL);
+
+ return GDK_GC_GET_PRIVATE (gc)->clip_mask;
+}
+
/**
* _gdk_gc_get_fill:
* @gc: a #GdkGC
priv = GDK_GC_GET_PRIVATE (gc);
+ _gdk_gc_remove_drawable_clip (gc);
+
fill = priv->fill;
if (override_stipple && fill != GDK_OPAQUE_STIPPLED)
fill = GDK_STIPPLED;
return;
cairo_reset_clip (cr);
+ /* The reset above resets the window clip rect, so we want to re-set that */
+ if (target_drawable && GDK_DRAWABLE_GET_CLASS (target_drawable)->set_cairo_clip)
+ GDK_DRAWABLE_GET_CLASS (target_drawable)->set_cairo_clip (target_drawable, cr);
+
if (priv->clip_region)
{
cairo_save (cr);
cairo_clip (cr);
}
- /* The reset above resets the window clip rect, so we want to re-set that */
- if (target_drawable && GDK_DRAWABLE_GET_CLASS (target_drawable)->set_cairo_clip)
- GDK_DRAWABLE_GET_CLASS (target_drawable)->set_cairo_clip (target_drawable, cr);
}