delay at pango startup



Hello,
please find appended a minimal program that exhibits on my machine
the following behaviour:

1. First startup/expose:                   850 ms
2. Second and all further expose events:     5 ms
3. Second and further startups:            300 ms
4. All expose events after those startups:   5 ms

The program does nothing more than create a window and layout
some text using pango/cairo on every expose event. The text is 
not rendered on screen (and this would be much faster than 300 ms).

Now, I'm assuming that pango has to initialize some things like
fonts etc before I can use it. This is fine. But in my application,
I would like to have command over when this time is spent. 

My question: which function to call to initialize pango such that
this delay will no longer show for the app's lifetime?

If this is news to you I can try to get a backtrace while the delay 
is happening.


Regards,
ralf


#include <iostream>
#include <sigc++/sigc++.h>
#include <gtkmm.h>

static void on_expose (GdkEventExpose *event, Gtk::Window *w);

int main(int argc, char *argv[])
{
    Gtk::Main kit(argc, argv);

    Gtk::Window window;
    window.signal_expose_event().connect_notify (sigc::bind (sigc::ptr_fun (on_expose), &window));

    Gtk::Main::run(window);
    
    return 0;
}

static void on_expose (GdkEventExpose *event, Gtk::Window *w)
{
    Glib::RefPtr<Gdk::Pixmap> pm = Gdk::Pixmap::create (w->get_window(), 200, 200);
    Cairo::RefPtr<Cairo::Context> cr = pm->create_cairo_context();
    Glib::Timer sw;
    sw.start();
	Glib::RefPtr<Pango::Layout> pl = Pango::Layout::create (cr);
		const char *fonts[] = {"Sans 10", "Sans 14"};
		for (unsigned i = 0; i < sizeof(fonts)/sizeof(const char*); ++i)
		{
			Pango::FontDescription fdesc (fonts[i]);
			pl->set_font_description (fdesc);
			pl->set_width (10 * Pango::SCALE); // force line break
			pl->set_markup ("<b>Show Us Your Freaky Geek Costumes</b>\nHitting the streets in a scary, tech-themed outfit this Halloween? We want to see it. Find out how your Sergey Brin costume (or is it David Duchovny?) could be featured on Wired News. test\n test");
			Pango::Rectangle irect, lrect;
			pl->get_extents (irect, lrect);
		}
sw.stop();
unsigned long l;
sw.elapsed(l);
std::cerr << "Time spent layouting: " << l << " us" << std::endl << std::flush;
	}



// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=4:softtabstop=4 :





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