1 /* This file is part of GTK+
6 * Copyright (C) 2008 Sven Herzberg
8 * This work is provided "as is"; redistribution and modification
9 * in whole or in part, in any medium, physical or electronic is
10 * permitted without restriction.
12 * This work 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.
16 * In no event shall the authors or contributors be liable for any
17 * direct, indirect, incidental, special, exemplary, or consequential
18 * damages (including, but not limited to, procurement of substitute
19 * goods or services; loss of use, data, or profits; or business
20 * interruption) however caused and on any theory of liability, whether
21 * in contract, strict liability, or tort (including negligence or
22 * otherwise) arising in any way out of the use of this software, even
23 * if advised of the possibility of such damage.
26 #include <glib/gstdio.h>
28 #ifdef CAIRO_HAS_QUARTZ_SURFACE
29 #include <cairo-quartz.h>
36 cairo_set_source_rgb (cr, 1.0, 1.0, 1.0);
40 cairo_move_to (cr, 10.0, 20.0);
41 cairo_line_to (cr, 10.0, 30.0);
44 cairo_set_source_rgba (cr, 0.0, 0.0, 0.0, 0.5);
45 cairo_arc (cr, 0.0, 0.0, 10.0, 0.0, G_PI/2);
50 test_surface_orientation (void)
52 cairo_surface_t *surface;
54 GdkPixbuf* pbuf_platform;
55 GdkPixbuf* pbuf_imagesrf;
56 GError * error = NULL;
57 cairo_surface_t* surface;
59 guchar* data_platform;
60 guchar* data_imagesrf;
63 /* create "platform.png" via native cairo surface */
64 surface = gdk_window_create_similar_surface (gdk_get_default_root_window (),
68 cr = cairo_create (surface);
72 pixbuf = gdk_pixbuf_get_from_surface (NULL,
77 if (!gdk_pixbuf_save (pixbuf, "gdksurface.png", "png", NULL, NULL)) {
78 g_error ("Eeek! Couldn't save the file \"gdksurface.png\"");
80 g_object_unref (pixbuf);
82 cairo_surface_destroy (surface);
84 /* create "cairosurface.png" via pure cairo */
85 #ifndef CAIRO_HAS_QUARTZ_SURFACE
86 surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, 100, 80);
88 surface = cairo_quartz_surface_create (CAIRO_FORMAT_RGB24, 100, 80);
90 cr = cairo_create (surface);
93 if (CAIRO_STATUS_SUCCESS != cairo_surface_write_to_png (surface, "cairosurface.png")) {
94 g_error ("Eeek! Couldn't save the file \"cairosurface.png\"");
96 cairo_surface_destroy (surface);
98 /* compare the images */
99 pbuf_platform = gdk_pixbuf_new_from_file ("gdksurface.png", &error);
100 if (!pbuf_platform || error) {
101 g_error ("Eeek! Error loading \"gdksurface.png\"");
103 pbuf_imagesrf = gdk_pixbuf_new_from_file ("cairosurface.png", &error);
104 if (!pbuf_imagesrf || error) {
105 g_object_unref (pbuf_platform);
106 g_error ("Eeek! Error loading \"cairosurface.png\"");
109 g_assert (gdk_pixbuf_get_width (pbuf_platform) ==
110 gdk_pixbuf_get_width (pbuf_imagesrf));
111 g_assert (gdk_pixbuf_get_height (pbuf_platform) ==
112 gdk_pixbuf_get_height (pbuf_imagesrf));
113 g_assert (gdk_pixbuf_get_rowstride (pbuf_platform) ==
114 gdk_pixbuf_get_rowstride (pbuf_imagesrf));
115 g_assert (gdk_pixbuf_get_n_channels (pbuf_platform) ==
116 gdk_pixbuf_get_n_channels (pbuf_imagesrf));
118 data_platform = gdk_pixbuf_get_pixels (pbuf_platform);
119 data_imagesrf = gdk_pixbuf_get_pixels (pbuf_imagesrf);
121 for (i = 0; i < gdk_pixbuf_get_height (pbuf_platform) * gdk_pixbuf_get_rowstride (pbuf_platform); i++) {
122 if (data_platform[i] != data_imagesrf[i]) {
123 g_warning ("Eeek! Images are differing at byte %d", i);
124 g_object_unref (pbuf_platform);
125 g_object_unref (pbuf_imagesrf);
126 g_assert_not_reached ();
130 g_object_unref (pbuf_platform);
131 g_object_unref (pbuf_imagesrf);
133 g_unlink ("gdksurface.png");
134 g_unlink ("cairosurface.png");
141 g_test_init (&argc, &argv, NULL);
142 gdk_init (&argc, &argv);
144 g_test_add_func ("/gdk/surface/orientation",
145 test_surface_orientation);
147 return g_test_run ();