Pixbuf to Cairo and vice versa


I was benchmarking one of my applications today and one of the slowest operations I detected is related to 
the Cairo > Pixbuf conversion.

This is what the code is currently doing:
1) Get the current screen content as a pixbuf

my $clean_pixbuf = Gtk2::Gdk::Pixbuf->get_from_drawable(
        $self->{_root}, undef, 0, 0, 0, 0,

2) I want to draw something on the pixbuf with Cairo

my $surface = Cairo::ImageSurface->create( 'argb32', $self->{_root}->{w}, $self->{_root}->{h} );
my $cr = Cairo::Context->create($surface);

Gtk2::Gdk::Cairo::Context::set_source_pixbuf( $cr, $clean_pixbuf, 0, 0 );

<<< more painting goes here >>>

3) Show the final image in a widget, i.e. convert the cairo surface back to a pixbuf

#write surface to pixbuf
my $loader = Gtk2::Gdk::PixbufLoader->new;
        sub {
                my ( $closure, $data ) = @_;

<<< use $loader->get_pixbuf somewhere >>>

Especially the last operation is pretty slow (the root window is big, dual monitor). My question is: Is this 
the correct workflow to do such things? Is there any way to avoid the conversions between pixbufs and cairo?

Thanks in advance.


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