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 | |
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.
-rw-r--r-- | docs/reference/gdk/gdk4-sections.txt | 2 | ||||
-rw-r--r-- | gdk/gdkcairocontext.c | 43 | ||||
-rw-r--r-- | gdk/gdkcairocontext.h | 2 | ||||
-rw-r--r-- | gdk/gdkdrawingcontext.c | 51 | ||||
-rw-r--r-- | gdk/gdkdrawingcontext.h | 3 | ||||
-rw-r--r-- | gsk/gskcairorenderer.c | 4 |
6 files changed, 49 insertions, 56 deletions
diff --git a/docs/reference/gdk/gdk4-sections.txt b/docs/reference/gdk/gdk4-sections.txt index 2cc4563ce8..c59224ac15 100644 --- a/docs/reference/gdk/gdk4-sections.txt +++ b/docs/reference/gdk/gdk4-sections.txt @@ -1187,7 +1187,6 @@ GDK_IS_MONITOR <FILE>gdkdrawingcontext</FILE> GdkDrawingContext gdk_drawing_context_get_clip -gdk_drawing_context_get_cairo_context gdk_drawing_context_get_paint_context <SUBSECTION Standard> @@ -1204,6 +1203,7 @@ GDK_IS_DRAWING_CONTEXT <SECTION> <FILE>gdkcairocontext</FILE> GdkCairoContext +gdk_cairo_context_cairo_create <SUBSECTION Standard> gdk_cairo_context_get_type 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; +} + diff --git a/gdk/gdkcairocontext.h b/gdk/gdkcairocontext.h index 0d2948a262..dc38701613 100644 --- a/gdk/gdkcairocontext.h +++ b/gdk/gdkcairocontext.h @@ -41,6 +41,8 @@ G_BEGIN_DECLS GDK_AVAILABLE_IN_ALL GType gdk_cairo_context_get_type (void) G_GNUC_CONST; +GDK_AVAILABLE_IN_ALL +cairo_t * gdk_cairo_context_cairo_create (GdkCairoContext *self); G_END_DECLS diff --git a/gdk/gdkdrawingcontext.c b/gdk/gdkdrawingcontext.c index 70569ba9cf..55da8b6d83 100644 --- a/gdk/gdkdrawingcontext.c +++ b/gdk/gdkdrawingcontext.c @@ -49,7 +49,6 @@ #include "gdkinternals.h" #include "gdkintl.h" #include "gdksurfaceimpl.h" -#include "gdkglcontextprivate.h" #include "gdk-private.h" typedef struct _GdkDrawingContextPrivate GdkDrawingContextPrivate; @@ -206,56 +205,6 @@ gdk_drawing_context_init (GdkDrawingContext *self) } /** - * gdk_drawing_context_get_cairo_context: - * @context: a #GdkDrawingContext created with a %NULL paint context - * - * Retrieves a Cairo context to be used to draw on the #GdkSurface - * that created the #GdkDrawingContext. The @context must have been - * created without a #GdkDrawContext for this function to work. If - * gdk_drawing_context_get_paint_context() does not return %NULL, - * then this function will. - * - * The returned context is guaranteed to be valid as long as the - * #GdkDrawingContext is valid, that is between a call to - * gdk_surface_begin_draw_frame() and gdk_surface_end_draw_frame(). - * - * Returns: (transfer none) (nullable): a Cairo context to be used to draw - * the contents of the #GdkSurface. The context is owned by the - * #GdkDrawingContext and should not be destroyed. %NULL is - * returned when a paint context is in used. - */ -cairo_t * -gdk_drawing_context_get_cairo_context (GdkDrawingContext *context) -{ - GdkDrawingContextPrivate *priv = gdk_drawing_context_get_instance_private (context); - - g_return_val_if_fail (GDK_IS_DRAWING_CONTEXT (context), NULL); - g_return_val_if_fail (GDK_IS_SURFACE (priv->surface), NULL); - - if (!GDK_IS_CAIRO_CONTEXT (priv->paint_context)) - return NULL; - - if (priv->cr == NULL) - { - cairo_region_t *region; - cairo_surface_t *surface; - - surface = _gdk_surface_ref_cairo_surface (priv->surface); - priv->cr = cairo_create (surface); - - region = gdk_surface_get_current_paint_region (priv->surface); - cairo_region_union (region, priv->clip); - gdk_cairo_region (priv->cr, region); - cairo_clip (priv->cr); - - cairo_region_destroy (region); - cairo_surface_destroy (surface); - } - - return priv->cr; -} - -/** * gdk_drawing_context_get_paint_context: * @context: a #GdkDrawingContext * diff --git a/gdk/gdkdrawingcontext.h b/gdk/gdkdrawingcontext.h index 44bb43b89c..21faf0542c 100644 --- a/gdk/gdkdrawingcontext.h +++ b/gdk/gdkdrawingcontext.h @@ -41,9 +41,6 @@ GdkDrawContext* gdk_drawing_context_get_paint_context (GdkDrawingContext *cont GDK_AVAILABLE_IN_ALL cairo_region_t *gdk_drawing_context_get_clip (GdkDrawingContext *context); -GDK_AVAILABLE_IN_ALL -cairo_t * gdk_drawing_context_get_cairo_context (GdkDrawingContext *context); - G_END_DECLS #endif /* __GDK_DRAWING_CONTEXT_H__ */ diff --git a/gsk/gskcairorenderer.c b/gsk/gskcairorenderer.c index f5871e49a8..43d47d1aac 100644 --- a/gsk/gskcairorenderer.c +++ b/gsk/gskcairorenderer.c @@ -115,7 +115,7 @@ gsk_cairo_renderer_render (GskRenderer *renderer, context = gdk_surface_begin_draw_frame (surface, GDK_DRAW_CONTEXT (self->cairo_context), region); - cr = gdk_drawing_context_get_cairo_context (context); + cr = gdk_cairo_context_cairo_create (self->cairo_context); g_return_if_fail (cr != NULL); @@ -135,6 +135,8 @@ gsk_cairo_renderer_render (GskRenderer *renderer, gsk_cairo_renderer_do_render (renderer, cr, root); + cairo_destroy (cr); + gdk_surface_end_draw_frame (surface, context); } |