Pixbuf to Cairo and vice versa
- From: Mario Kemper <mario kemper googlemail com>
- To: gtk-perl-list gnome org
- Subject: Pixbuf to Cairo and vice versa
- Date: Wed, 13 Jul 2011 15:41:23 +0200 (MESZ)
Hi,
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,
$self->{_root}->{w},
$self->{_root}->{h}
);
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 );
$cr->paint;
<<< 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;
$surface->write_to_png_stream(
sub {
my ( $closure, $data ) = @_;
$loader->write($data);
}
);
$loader->close;
<<< 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.
Bye
Mario
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]