diff --git a/gdk/gdkcairo.c b/gdk/gdkcairo.c index a363394458..bb7f33efd1 100644 --- a/gdk/gdkcairo.c +++ b/gdk/gdkcairo.c @@ -525,3 +525,38 @@ gdk_cairo_region_create_from_surface (cairo_surface_t *surface) return region; } + +cairo_region_t * +gdk_cairo_region_from_clip (cairo_t *cr) +{ + cairo_rectangle_list_t *rectangles; + cairo_region_t *region; + int i; + + rectangles = cairo_copy_clip_rectangle_list (cr); + + if (rectangles->status != CAIRO_STATUS_SUCCESS) + return NULL; + + region = cairo_region_create (); + for (i = 0; i < rectangles->num_rectangles; i++) + { + cairo_rectangle_int_t clip_rect; + cairo_rectangle_t *rect; + + rect = &rectangles->rectangles[i]; + + /* Here we assume clip rects are ints for direct targets, which + is true for cairo */ + clip_rect.x = (int)rect->x; + clip_rect.y = (int)rect->y; + clip_rect.width = (int)rect->width; + clip_rect.height = (int)rect->height; + + cairo_region_union_rectangle (region, &clip_rect); + } + + cairo_rectangle_list_destroy (rectangles); + + return region; +} diff --git a/gdk/gdkinternals.h b/gdk/gdkinternals.h index bb6f8312b7..07df2f15de 100644 --- a/gdk/gdkinternals.h +++ b/gdk/gdkinternals.h @@ -319,8 +319,10 @@ void _gdk_windowing_event_data_free (GdkEvent *event); void _gdk_set_window_state (GdkWindow *window, GdkWindowState new_state); -gboolean _gdk_cairo_surface_extents (cairo_surface_t *surface, - GdkRectangle *extents); +gboolean _gdk_cairo_surface_extents (cairo_surface_t *surface, + GdkRectangle *extents); +cairo_region_t *gdk_cairo_region_from_clip (cairo_t *cr); + /************************************* * Interfaces used by windowing code *