<FILE>gdkdrawingcontext</FILE>
GdkDrawingContext
gdk_drawing_context_get_clip
-gdk_drawing_context_get_cairo_context
gdk_drawing_context_get_paint_context
<SUBSECTION Standard>
<SECTION>
<FILE>gdkcairocontext</FILE>
GdkCairoContext
+gdk_cairo_context_cairo_create
<SUBSECTION Standard>
gdk_cairo_context_get_type
{
}
+/**
+ * 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;
+}
+
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
#include "gdkinternals.h"
#include "gdkintl.h"
#include "gdksurfaceimpl.h"
-#include "gdkglcontextprivate.h"
#include "gdk-private.h"
typedef struct _GdkDrawingContextPrivate GdkDrawingContextPrivate;
{
}
-/**
- * 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
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__ */
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);
gsk_cairo_renderer_do_render (renderer, cr, root);
+ cairo_destroy (cr);
+
gdk_surface_end_draw_frame (surface, context);
}