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 ___ gtk-devel-list mailing list gtk-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-devel-list
Re: cairo surface from GdkPixmap
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. The surface isn't destroyed, it's un-reffed. You can still get the surface from the context using cairo's get_target() method, and then do with the surface as you please. ___ gtk-devel-list mailing list gtk-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-devel-list
cairo surface from GdkPixmap
Hi everybody, I am looking for a way to obtain a Cairo surface from a GdkPixmap. Just for reference, a few years ago one user was looking for the same functionality: http://mail.gnome.org/archives/gtk-devel-list/2005-September/msg00138.html The function _gdk_drawable_ref_cairo_surface does exactly what I want, however this is a private function. So right now I am using surface = GDK_DRAWABLE_GET_CLASS (pixmap)-ref_cairo_surface (pixmap); instead, but I doubt that this is recommended practice. Basically what I am trying to accomplish is to create a class derived from cairo.Context from a pixmap in pygtk. To do so, I need to go through the cairo.Context constructor directly rather than using pixmap.cairo_create. But the cairo.Context constructor takes a Cairo surface rather than a pixmap, so I need to obtain a Cairo surface from the pixmap first. While this can be done with _gdk_drawable_ref_cairo_surface, this function is not available through PyGTK since it's a private function in gtk. Or is there an alternative way to accomplish this? Many thanks in advance, --Michiel ___ gtk-devel-list mailing list gtk-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-devel-list
Re: cairo surface from GdkPixmap
On Sat, 2009-06-13 at 19:50 -0700, Michiel de Hoon wrote: I am looking for a way to obtain a Cairo surface from a GdkPixmap. You're probably looking for gdk_cairo_create() or gdk_cairo_set_source_pixmap(), depending on what exactly you're up to. http://library.gnome.org/devel/gdk/stable/gdk-Cairo-Interaction.html 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. AfC Sydney signature.asc Description: This is a digitally signed message part ___ gtk-devel-list mailing list gtk-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-devel-list
Re: cairo surface from GdkPixmap
On Fri, 2005-09-23 at 14:21 +0200, Alexander Larsson wrote: I'm trying to draw a GdkPixmap to a window with a transformation. I can do this using: surface = cairo_xlib_surface_create (gdk_x11_drawable_get_xdisplay (widget-window), gdk_x11_drawable_get_xid (pixmap), gdk_x11_visual_get_xvisual (gdk_drawable_get_visual (widget-window)), width, height); cairo_set_source_surface (cr, surface, 0, 0); I see that we have: void gdk_cairo_set_source_pixbuf (cairo_t *cr, GdkPixbuf*pixbuf, doublepixbuf_x, doublepixbuf_y); But no gdk_cairo_set_source_drawable(). In fact, _gdk_drawable_ref_cairo_surface() which does exactly what I want is a private function. What is the reason for this? The lack of gdk_cairo_set_source_drawable() is basically I didn't need it, so I didn't get around to adding it.. It makes sense and there aren't any issues with it. gdk_drawable_ref_cairo_surface() is a little more sticky. There are two things about it that are tricky: - It's ref_cairo_surface() not get_cairo_surface(). We don't have a lot of precedent for referencing accessors, but you really want to keep this one referencing. Surfaces are not necessarily lightweight ... they can cache pixel data, and we don't want to keep them around when not needed. From C, we have the established naming convention of ref() for this, but what we haven't established yet is that language bindings should rename such functions back to _get() [or should they?] - The behavior in begin_paint()/end_paint() is unexpected ... if you _ref_cairo_surface() with that pair, you get a surface pointing to the backing pixmap. If you draw to it after the end_paint(), then it will be safe (the cairo surface is finished) but nothing will appear. Now that there is cairo_xlib_surface_set_drawable() this could be fixed for X, but not for Win32. So it's probably better to just document the current behavior. Anyways, neither thing is a real stop-objection, but they made me want to leave things private rather than rushing ref_cairo_surface() out to the world when I was first adding the stuff. gdk_cairo_create() and the hypothetical gdk_drawable_set_source_cairo() have considerably less gotcha to them. Regards, Owen ___ gtk-devel-list mailing list gtk-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-devel-list