<br>I am having trouble rendering an ImageSurface to an X11 display. My problem seems to be with only certain sizes and may possibly be related to my graphics card and driver.<br><br>In the code below, I took the "Image" snippet from the cairo-demo package and broke it out into a simple program.
<br><br>I then took the png file "romedalen.png" and sc.aled and saved it using Gimp such that I had a total of five files of pixel sizes 100x100, 256x192(original size), 300x300, 400x300, and 400x400.<br><br>(BTW, the cairo_snippets_gtk program is presently broken due to API changes. I have included patches at the bottom of this message.)
<br><br>I found that some files would display properly and some would not. I also found that it seemed to be related to the display and graphics card. Here are the results:<br><br>ATI Radeon 9000 with dual screen using ati driver:
<br>screen 0: 1400x1050<br>works: 256x192, 100x100,<br>doesn't work: 400x400, 300x300, 400x300<br><br>screen 1: 1600x1200<br>works: 256x192, 400x400, 100x100<br>doesn't work: 300x300, 400x300<br><br>NVIDIA on 1280x1024 using nvidia driver
<br>works: 100x100, 256x192, 300x300, 400x300, 400x400<br>doesn't work: <br><br>I get the same results with cairo-1.0.4 and cairo-1.2.0.<br>Can anyone tell me what is wrong? Is this a cairo bug?<br><br>Thanks<br>Bob Gibbs
<br><br><br>/*********************** START SIMPLE PROGRAM ***************************/
<br>#include <math.h><br>#include <cairo.h><br>#include <gtk/gtk.h><br><br>/*cc `pkg-config gtk+-2.0 --cflags --libs` test-png.c */<br><br>#define WINDOW_WIDTH 400<br>#define WINDOW_HEIGHT 400<br><br>static cairo_surface_t *surface;
<br><br>static void<br>create_surface()<br>{<br> surface = cairo_image_surface_create_from_png ("romedalen5.png");<br>}<br><br>static void<br>snippet_normalize (cairo_t *cr, double width, double height)<br>
{<br> cairo_scale (cr, width, height);<br> cairo_set_line_width (cr, 0.04);<br>}<br><br>static void<br>do_blit(cairo_t *cr)<br>{<br> int w, h;<br><br> snippet_normalize (cr, WINDOW_WIDTH, WINDOW_HEIGHT);
<br><br> w = cairo_image_surface_get_width (surface);<br> h = cairo_image_surface_get_height (surface);<br> printf("w=%d, h=%d\n", w, h);<br><br> cairo_translate (cr, 0.5, 0.5);<br> cairo_rotate (cr, 45* M_PI/180);
<br> cairo_scale (cr, 1.0/w, 1.0/h);<br> cairo_translate (cr, -0.5*w, -0.5*h);<br><br> cairo_set_source_surface (cr, surface, 0, 0);<br> //cairo_pattern_set_extend(cairo_get_source(cr), CAIRO_EXTEND_REPEAT);
<br> cairo_paint (cr);<br>}<br><br>static void<br>paint(GtkWidget *w, GdkEvent *event)<br>{<br> cairo_t *c;<br><br> c = gdk_cairo_create(w->window);<br> do_blit(c);<br> cairo_destroy(c);
<br>}<br><br>int<br>main(int argc, char **argv)<br>{<br> GtkWidget *w, *da;<br><br> create_surface();<br><br> gtk_init(&argc, &argv);<br> w = gtk_window_new(GTK_WINDOW_TOPLEVEL);<br> da = gtk_drawing_area_new();
<br> gtk_widget_set_size_request(w, WINDOW_WIDTH, WINDOW_HEIGHT);<br> g_signal_connect(da, "expose-event", G_CALLBACK(paint), NULL);<br> gtk_container_add(GTK_CONTAINER(w), da);<br> gtk_widget_show_all(w);
<br> gtk_main();<br> return 0;<br>}<br>/*********************** END SIMPLE PROGRAM ***************************/<br><br><br>PATCHES:<br><br>Index: cairo_snippets_gtk.c<br>===================================================================
<br>RCS file: /cvs/cairo/cairo-demo/cairo_snippets/cairo_snippets_gtk.c,v<br>retrieving revision 1.4<br>diff -a -u -r1.4 cairo_snippets_gtk.c<br>--- cairo_snippets_gtk.c 11 Jan 2005 22:38:03 -0000 1.4<br>+++ cairo_snippets_gtk.c 11 Aug 2006 01:06:37 -0000
<br>@@ -3,7 +3,6 @@<br> */<br><br> #include "snippets.h"<br>-#include <gtkcairo.h><br> #include <gtk/gtk.h><br> #include <stdio.h><br><br>@@ -13,15 +12,19 @@<br><br> static void<br> paint (GtkWidget *widget,
<br>- cairo_t *cr,<br>- void *data)<br>+ GdkEvent *event)<br> {<br>+ cairo_t *cr;<br>+<br>+ cr = gdk_cairo_create(widget->window);<br>+<br> gint width = widget->allocation.width
;<br> gint height = widget->allocation.height;<br><br> cairo_save (cr);<br> snippet_do (cr, current_snippet, width, height);<br> cairo_restore (cr);<br>+ cairo_destroy(cr);<br> }<br><br> static void
<br>@@ -123,10 +126,10 @@<br> hpaned = gtk_hpaned_new ();<br> vpaned = gtk_vpaned_new ();<br><br>- gtkcairo = gtk_cairo_new ();<br>+ gtkcairo = gtk_drawing_area_new ();<br> gtk_widget_set_usize (GTK_WIDGET (gtkcairo), 256, 256);
<br><br>- g_signal_connect (G_OBJECT (gtkcairo), "paint",<br>+ g_signal_connect (G_OBJECT (gtkcairo), "expose-event",<br> G_CALLBACK (paint), NULL);<br><br> source_view = create_source_view ();
<br>Index: <a href="http://configure.ac" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">configure.ac</a><br>===================================================================<br>RCS file: /cvs/cairo/cairo-demo/cairo_snippets/configure.ac,v
<br>retrieving revision 1.3<br>
diff -a -u -r1.3 <a href="http://configure.ac" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">configure.ac</a><br>--- <a href="http://configure.ac" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
configure.ac</a> 24 Feb 2005 16:21:01 -0000 1.3<br>+++ <a href="http://configure.ac" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">configure.ac</a> 11 Aug 2006 01:06:37 -0000
<br>@@ -9,7 +9,7 @@<br> AC_STDC_HEADERS<br><br> PKG_CHECK_MODULES(SNIPPETS, libpng libsvg-cairo >= 0.1.2 cairo >= 0.3.0)<br>-PKG_CHECK_MODULES(GTKCAIRO, gtkcairo, enable_gtkcairo=yes, enable_gtkcairo=no)<br>+PKG_CHECK_MODULES(GTKCAIRO, gtk+-
2.0 >= 2.8, enable_gtkcairo=yes, enable_gtkcairo=no)<br><br> AM_CONDITIONAL(BUILD_GTKCAIRO, test x$enable_gtkcairo = xyes)<br><br><br>