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 | |
29 | /** |
30 | * GdkCairoContext: |
31 | * |
32 | * `GdkCairoContext` is an object representing the platform-specific |
33 | * draw context. |
34 | * |
35 | * `GdkCairoContext`s are created for a surface using |
36 | * [method@Gdk.Surface.create_cairo_context], and the context |
37 | * can then be used to draw on that surface. |
38 | */ |
39 | |
40 | typedef struct _GdkCairoContextPrivate GdkCairoContextPrivate; |
41 | |
42 | struct _GdkCairoContextPrivate { |
43 | gpointer unused; |
44 | }; |
45 | |
46 | G_DEFINE_ABSTRACT_TYPE_WITH_CODE (GdkCairoContext, gdk_cairo_context, GDK_TYPE_DRAW_CONTEXT, |
47 | G_ADD_PRIVATE (GdkCairoContext)) |
48 | |
49 | static void |
50 | gdk_cairo_context_class_init (GdkCairoContextClass *klass) |
51 | { |
52 | } |
53 | |
54 | static void |
55 | gdk_cairo_context_init (GdkCairoContext *self) |
56 | { |
57 | } |
58 | |
59 | /** |
60 | * gdk_cairo_context_cairo_create: |
61 | * @self: a `GdkCairoContext` that is currently drawing |
62 | * |
63 | * Retrieves a Cairo context to be used to draw on the `GdkSurface` |
64 | * of @context. |
65 | * |
66 | * A call to [method@Gdk.DrawContext.begin_frame] with this |
67 | * @context must have been done or this function will return %NULL. |
68 | * |
69 | * The returned context is guaranteed to be valid until |
70 | * [method@Gdk.DrawContext.end_frame] is called. |
71 | * |
72 | * Returns: (transfer full) (nullable): a Cairo context |
73 | * to draw on `GdkSurface |
74 | */ |
75 | cairo_t * |
76 | gdk_cairo_context_cairo_create (GdkCairoContext *self) |
77 | { |
78 | GdkDrawContext *draw_context; |
79 | cairo_t *cr; |
80 | |
81 | g_return_val_if_fail (GDK_IS_CAIRO_CONTEXT (self), NULL); |
82 | |
83 | draw_context = GDK_DRAW_CONTEXT (self); |
84 | |
85 | if (!gdk_draw_context_is_in_frame (context: draw_context)) |
86 | return NULL; |
87 | |
88 | cr = GDK_CAIRO_CONTEXT_GET_CLASS (self)->cairo_create (self); |
89 | |
90 | gdk_cairo_region (cr, region: gdk_draw_context_get_frame_region (context: draw_context)); |
91 | cairo_clip (cr); |
92 | |
93 | return cr; |
94 | } |
95 | |
96 | |