[gtk+/rendering-cleanup: 20/65] API: Make gdk_cairo_create() take a GdkWindow
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/rendering-cleanup: 20/65] API: Make gdk_cairo_create() take a GdkWindow
- Date: Thu, 2 Dec 2010 11:53:08 +0000 (UTC)
commit f8ad5d86e11cc4d85aa586c3fcf9f9a582c19a0d
Author: Benjamin Otte <otte redhat com>
Date: Wed Oct 6 19:12:27 2010 +0200
API: Make gdk_cairo_create() take a GdkWindow
This is not strictly an API change as GdkDrawable is typedeffed to
GdkWindow, but it changes the header, so I'm marking it as such.
gdk_cairo_create() can only be used with windows these days, so it makes
sense to pass a window. With that, we can alseo remove the
set_cairo_clip() vfunc from GdkDrawable and implement it inside
gdkwindow.c.
gdk/gdkcairo.c | 36 -------------------------------
gdk/gdkcairo.h | 2 +-
gdk/gdkdrawable.h | 3 --
gdk/gdkwindow.c | 60 +++++++++++++++++++++++++++++++++++++++++++++--------
4 files changed, 52 insertions(+), 49 deletions(-)
---
diff --git a/gdk/gdkcairo.c b/gdk/gdkcairo.c
index a554241..7fe0ccc 100644
--- a/gdk/gdkcairo.c
+++ b/gdk/gdkcairo.c
@@ -43,42 +43,6 @@
/**
- * gdk_cairo_create:
- * @drawable: a #GdkDrawable
- *
- * Creates a Cairo context for drawing to @drawable.
- *
- * <note><para>
- * Note that due to double-buffering, Cairo contexts created
- * in a GTK+ expose event handler cannot be cached and reused
- * between different expose events.
- * </para></note>
- *
- * Return value: A newly created Cairo context. Free with
- * cairo_destroy() when you are done drawing.
- *
- * Since: 2.8
- **/
-cairo_t *
-gdk_cairo_create (GdkDrawable *drawable)
-{
- cairo_surface_t *surface;
- cairo_t *cr;
-
- g_return_val_if_fail (GDK_IS_DRAWABLE (drawable), NULL);
-
- surface = _gdk_drawable_ref_cairo_surface (drawable);
- cr = cairo_create (surface);
-
- if (GDK_DRAWABLE_GET_CLASS (drawable)->set_cairo_clip)
- GDK_DRAWABLE_GET_CLASS (drawable)->set_cairo_clip (drawable, cr);
-
- cairo_surface_destroy (surface);
-
- return cr;
-}
-
-/**
* gdk_cairo_get_clip_rectangle:
* @cr: a cairo context
* @rect: (out) (allow-none): return location for the clip, or %NULL
diff --git a/gdk/gdkcairo.h b/gdk/gdkcairo.h
index f594f8b..67e08aa 100644
--- a/gdk/gdkcairo.h
+++ b/gdk/gdkcairo.h
@@ -31,7 +31,7 @@
G_BEGIN_DECLS
-cairo_t *gdk_cairo_create (GdkDrawable *drawable);
+cairo_t *gdk_cairo_create (GdkWindow *window);
gboolean gdk_cairo_get_clip_rectangle(cairo_t *cr,
GdkRectangle *rect);
diff --git a/gdk/gdkdrawable.h b/gdk/gdkdrawable.h
index a32c185..24fa122 100644
--- a/gdk/gdkdrawable.h
+++ b/gdk/gdkdrawable.h
@@ -67,9 +67,6 @@ struct _GdkDrawableClass
cairo_surface_t *(*ref_cairo_surface) (GdkDrawable *drawable);
- void (*set_cairo_clip) (GdkDrawable *drawable,
- cairo_t *cr);
-
cairo_surface_t * (*create_cairo_surface) (GdkDrawable *drawable,
int width,
int height);
diff --git a/gdk/gdkwindow.c b/gdk/gdkwindow.c
index 01c5749..bb46643 100644
--- a/gdk/gdkwindow.c
+++ b/gdk/gdkwindow.c
@@ -224,8 +224,6 @@ static cairo_surface_t *gdk_window_create_cairo_surface (GdkDrawable *drawable,
int width,
int height);
static void gdk_window_drop_cairo_surface (GdkWindowObject *private);
-static void gdk_window_set_cairo_clip (GdkDrawable *drawable,
- cairo_t *cr);
static cairo_region_t* gdk_window_get_clip_region (GdkDrawable *drawable);
static cairo_region_t* gdk_window_get_visible_region (GdkDrawable *drawable);
@@ -385,7 +383,6 @@ gdk_window_class_init (GdkWindowObjectClass *klass)
drawable_class->ref_cairo_surface = gdk_window_ref_cairo_surface;
drawable_class->create_cairo_surface = gdk_window_create_cairo_surface;
- drawable_class->set_cairo_clip = gdk_window_set_cairo_clip;
drawable_class->get_clip_region = gdk_window_get_clip_region;
drawable_class->get_visible_region = gdk_window_get_visible_region;
@@ -2818,6 +2815,23 @@ gdk_window_begin_implicit_paint (GdkWindow *window, GdkRectangle *rect)
return TRUE;
}
+static cairo_t *
+gdk_cairo_create_for_impl (GdkWindow *window)
+{
+ GdkWindowObject *priv;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+
+ priv = (GdkWindowObject*) window;
+
+ surface = _gdk_drawable_ref_cairo_surface (priv->impl);
+ cr = cairo_create (surface);
+
+ cairo_surface_destroy (surface);
+
+ return cr;
+}
+
/* Ensure that all content related to this (sub)window is pushed to the
native region. If there is an active paint then that area is not
pushed, in order to not show partially finished double buffers. */
@@ -2858,7 +2872,7 @@ gdk_window_flush_implicit_paint (GdkWindow *window)
cairo_region_subtract (paint->region, region);
/* Some regions are valid, push these to window now */
- cr = gdk_cairo_create (private->impl);
+ cr = gdk_cairo_create_for_impl (window);
gdk_cairo_region (cr, region);
cairo_clip (cr);
cairo_set_source_surface (cr, paint->surface, 0, 0);
@@ -2890,7 +2904,7 @@ gdk_window_end_implicit_paint (GdkWindow *window)
cairo_t *cr;
/* Some regions are valid, push these to window now */
- cr = gdk_cairo_create (private->impl);
+ cr = gdk_cairo_create_for_impl (window);
gdk_cairo_region (cr, paint->region);
cairo_clip (cr);
cairo_set_source_surface (cr, paint->surface, 0, 0);
@@ -3727,11 +3741,35 @@ gdk_window_ref_cairo_surface (GdkDrawable *drawable)
return surface;
}
-static void
-gdk_window_set_cairo_clip (GdkDrawable *drawable,
- cairo_t *cr)
+/**
+ * gdk_cairo_create:
+ * @drawable: a #GdkWindow
+ *
+ * Creates a Cairo context for drawing to @window.
+ *
+ * <note><warning>
+ * Note that calling cairo_reset_clip() on the resulting #cairo_t will
+ * produce undefined results, so avoid it at all costs.
+ * </warning></note>
+ *
+ * Return value: A newly created Cairo context. Free with
+ * cairo_destroy() when you are done drawing.
+ *
+ * Since: 2.8
+ **/
+cairo_t *
+gdk_cairo_create (GdkWindow *window)
{
- GdkWindowObject *private = (GdkWindowObject*) drawable;
+ GdkWindowObject *private;
+ cairo_surface_t *surface;
+ cairo_t *cr;
+
+ g_return_val_if_fail (GDK_IS_WINDOW (window), NULL);
+
+ private = (GdkWindowObject*) window;
+
+ surface = _gdk_drawable_ref_cairo_surface (window);
+ cr = cairo_create (surface);
if (!private->paint_stack)
{
@@ -3765,6 +3803,10 @@ gdk_window_set_cairo_clip (GdkDrawable *drawable,
cairo_clip (cr);
}
}
+
+ cairo_surface_destroy (surface);
+
+ return cr;
}
/* Code for dirty-region queueing
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]