Re: cairo surface from GdkPixmap



Dear Andrew, Dov,

Thank you for your replies. Maybe my original question was not so clear; I've tried to clear things up below.

[Andrew wrote]
> As is compulsory on this list :) I note in passing that it turns out
> that this [poorly-named] list is the one for discussion about _hacking_
> on GTK. Questions about _developing_ with the library are best directed
> to gtk-list.

Yeah I know, I wrote to this mailing list because as far as I can tell, the functionality I am looking for is available in GTK but only as a private function, and I was trying to show that software building on GTK (such as pygtk) may want access to this functionality. So the issue is more about the design of the GTK api.

[Michiel wrote]
> > I am looking for a way to obtain a Cairo surface from a GdkPixmap.

[Andrew wrote]
> You're probably looking for gdk_cairo_create() ...

Unfortunately this won't work for me. gdk_cairo_create() creates a Cairo surface, then it creates a Cairo context from this surface, and then it destroys the Cairo surface.  What I am looking for is a function that creates a Cairo surface and returns it directly. Then I can use pycairo to create a Cairo context from the Cairo surface, which allows me to subclass the Cairo context. The gtk function _gdk_drawable_ref_cairo_surface does exactly what I want, however this is a private function.

[Andrew wrote]
> or gdk_cairo_set_source_pixmap(), depending on what exactly you're up to.

Sorry for that, I should have been more clear in my original post. I am looking at a third-party piece of software that uses pygtk and pycairo. As drawing can be expensive in this application, to avoid unnecessary redrawing all drawing is done to a pixmap, and on an expose event the pixmap is drawn to the window. In my understanding, gdk_cairo_create is appropriate in this case (rather than gdk_cairo_set_source_pixmap), except that in the current design of gtk I won't be able to subclass the Cairo context.

[Dov wrote]
...
> Basically all you need to do is:
> 
>  cairo_surface_t *surface
>   = cairo_image_surface_create_for_data(gdk_pixbuf_get_pixels(pixbuf),
                                          CAIRO_FORMAT_RGB24,
                                          img_width,
                                          img_height,
                                       gdk_pixbuf_get_rowstride(pixbuf));

This is very close to what I need, except that this is for a pixbuf rather than for a pixmap. Can the same functionality be made available for pixmap? In other words, can _gdk_drawable_ref_cairo_surface become public?

Thanks again for your replies,

--Michiel




      


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]