Commit 97e6e9d2 authored by Benjamin Otte's avatar Benjamin Otte
Browse files

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.
parent 65dde2f9
......@@ -42,42 +42,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
......
......@@ -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);
......
......@@ -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);
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment