diff options
author | Benjamin Otte <otte@redhat.com> | 2018-04-12 02:10:22 +0200 |
---|---|---|
committer | Benjamin Otte <otte@redhat.com> | 2018-04-24 23:16:12 +0200 |
commit | a83487a0c4e57063f02f7e3edecb2af9194d6c29 (patch) | |
tree | 100ea6a4339d07e0d3ce7894c9b9e68549eed236 /gdk/gdkcairocontext.c | |
parent | 52de880c1c1c64c7f2393ed2f42ca45ee3c7d7c8 (diff) | |
download | gtk+-a83487a0c4e57063f02f7e3edecb2af9194d6c29.tar.gz |
cairocontext: Move a function
A function of GdkDrawingContext is only used when drawing with Cairo, so
move it to GdkCairoContext.
Diffstat (limited to 'gdk/gdkcairocontext.c')
-rw-r--r-- | gdk/gdkcairocontext.c | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/gdk/gdkcairocontext.c b/gdk/gdkcairocontext.c index 1954b3a339..596eaabfa6 100644 --- a/gdk/gdkcairocontext.c +++ b/gdk/gdkcairocontext.c @@ -223,3 +223,46 @@ gdk_cairo_context_init (GdkCairoContext *self) { } +/** + * gdk_cairo_context_cairo_create: + * @context: a #GdkCairoContext that is currently drawing + * + * Retrieves a Cairo context to be used to draw on the #GdkSurface + * of @context. A call to gdk_surface_begin_draw_frame() with this + * @context must have been done or this function will return %NULL. + * + * The returned context is guaranteed to be valid until + * gdk_surface_end_draw_frame() is called. + * + * Returns: (transfer full) (nullable): a Cairo context to be used + * to draw the contents of the #GdkSurface. %NULL is returned + * when @contet is not drawing. + */ +cairo_t * +gdk_cairo_context_cairo_create (GdkCairoContext *self) +{ + GdkSurface *surface; + cairo_region_t *region; + cairo_surface_t *cairo_surface; + cairo_t *cr; + + g_return_val_if_fail (GDK_IS_CAIRO_CONTEXT (self), NULL); + + surface = gdk_draw_context_get_surface (GDK_DRAW_CONTEXT (self)); + if (surface->drawing_context == NULL || + gdk_drawing_context_get_paint_context (surface->drawing_context) != GDK_DRAW_CONTEXT (self)) + return NULL; + + cairo_surface = _gdk_surface_ref_cairo_surface (surface); + cr = cairo_create (cairo_surface); + + region = gdk_surface_get_current_paint_region (surface); + gdk_cairo_region (cr, region); + cairo_clip (cr); + + cairo_region_destroy (region); + cairo_surface_destroy (cairo_surface); + + return cr; +} + |