Debian Codegraph @

testsuite/reftests/image-recording-surface.c

raw
1 /*
2 * Copyright (C) 2014 Red Hat Inc.
3 *
4 * Author:
5 * Matthias Clasen <[email protected]>
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 <gtk/gtk.h>
24
25 G_MODULE_EXPORT void
26 image_recording_surface_set (GtkWidget *widget,
27 gpointer unused)
28 {
29 GError *error = NULL;
30 GdkPixbuf *pixbuf;
31 cairo_surface_t *surface;
32 cairo_t *cr;
33 cairo_rectangle_t rect;
34
35 pixbuf = gdk_pixbuf_new_from_resource ("/org/gtk/libgtk/inspector/logo.png", &error);
36 g_assert_no_error (error);
37 rect.x = 0;
38 rect.y = 0;
39 rect.width = gdk_pixbuf_get_width (pixbuf);
40 rect.height = gdk_pixbuf_get_height (pixbuf);
41 surface = cairo_recording_surface_create (CAIRO_CONTENT_COLOR_ALPHA, &rect);
42
43 cr = cairo_create (surface);
44 gdk_cairo_set_source_pixbuf (cr, pixbuf, 0, 0);
45 cairo_paint (cr);
46 cairo_destroy (cr);
47
48 gtk_image_set_from_surface (GTK_IMAGE (widget), surface);
49
50 cairo_surface_destroy (surface);
51 g_object_unref (pixbuf);
52 }