[gtk+] Add internal gdk_cairo_region_from_clip helper



commit ceeed1c48db28bdf04e5d36dbb0fc24e3c702dd5
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Oct 9 09:58:36 2014 +0200

    Add internal gdk_cairo_region_from_clip helper
    
    This extract the current cairo clip region if possible and
    returns it as a cairo_region_T. It will be needed by later code.

 gdk/gdkcairo.c     |   35 +++++++++++++++++++++++++++++++++++
 gdk/gdkinternals.h |    6 ++++--
 2 files changed, 39 insertions(+), 2 deletions(-)
---
diff --git a/gdk/gdkcairo.c b/gdk/gdkcairo.c
index a363394..bb7f33e 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 bb6f831..07df2f1 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 *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]