1 /* GDK - The GIMP Drawing Kit
2 *
3 * gdkcairocontext.c: Cairo wrappers
4 *
5 * Copyright © 2018 Benjamin Otte
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Library General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Library General Public License for more details.
16 *
17 * You should have received a copy of the GNU Library General Public
18 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "config.h"
22
23 #include "gdkcairocontext.h"
24
25 #include "gdkcairocontextprivate.h"
26
27 #include "gdkcairo.h"
28 #include "gdkinternals.h"
29
30 /**
31 * GdkCairoContext:
32 *
33 * `GdkCairoContext` is an object representing the platform-specific
34 * draw context.
35 *
36 * `GdkCairoContext`s are created for a surface using
37 * [method@Gdk.Surface.create_cairo_context], and the context
38 * can then be used to draw on that surface.
39 */
40
41 typedef struct _GdkCairoContextPrivate GdkCairoContextPrivate;
42
43 struct _GdkCairoContextPrivate {
44 gpointer unused;
45 };
46
G_DEFINE_ABSTRACT_TYPE_WITH_CODE(GdkCairoContext,gdk_cairo_context,GDK_TYPE_DRAW_CONTEXT,G_ADD_PRIVATE (GdkCairoContext))47 G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GdkCairoContext, gdk_cairo_context, GDK_TYPE_DRAW_CONTEXT,
48 G_ADD_PRIVATE (GdkCairoContext))
49
50 static void
51 gdk_cairo_context_class_init (GdkCairoContextClass *klass)
52 {
53 }
54
55 static void
gdk_cairo_context_init(GdkCairoContext * self)56 gdk_cairo_context_init (GdkCairoContext *self)
57 {
58 }
59
60 /**
61 * gdk_cairo_context_cairo_create:
62 * @self: a `GdkCairoContext` that is currently drawing
63 *
64 * Retrieves a Cairo context to be used to draw on the `GdkSurface`
65 * of @context.
66 *
67 * A call to [method@Gdk.DrawContext.begin_frame] with this
68 * @context must have been done or this function will return %NULL.
69 *
70 * The returned context is guaranteed to be valid until
71 * [method@Gdk.DrawContext.end_frame] is called.
72 *
73 * Returns: (transfer full) (nullable): a Cairo context
74 * to draw on `GdkSurface
75 */
76 cairo_t *
gdk_cairo_context_cairo_create(GdkCairoContext * self)77 gdk_cairo_context_cairo_create (GdkCairoContext *self)
78 {
79 GdkDrawContext *draw_context;
80 cairo_t *cr;
81
82 g_return_val_if_fail (GDK_IS_CAIRO_CONTEXT (self), NULL);
83
84 draw_context = GDK_DRAW_CONTEXT (self);
85
86 if (!gdk_draw_context_is_in_frame (draw_context))
87 return NULL;
88
89 cr = GDK_CAIRO_CONTEXT_GET_CLASS (self)->cairo_create (self);
90
91 gdk_cairo_region (cr, gdk_draw_context_get_frame_region (draw_context));
92 cairo_clip (cr);
93
94 return cr;
95 }
96
97