[cairo] Cairo and FLTK?

Bill Spitzak spitzak at thefoundry.co.uk
Tue Oct 30 03:06:07 PDT 2007


Kai-Uwe Behrmann wrote:
> Date: Mon, 29 Oct 2007 12:00:58 +0000
> From: Bill Spitzak
>  
>> The following code should return a cairo surfact_t that can be used to 
>> draw into an fltk window. You would call this inside your 
>> window/widget's draw() function:
> 
> Neighter inside or outside FLTK(1)'s draw() gives more speed in the Fl_Box 
> my app uses. Drawing in a image surface is much quicker for me.
> 
>> /** Fltk cairo create surface function accepting a Window* as input */
>> cairo_surface_t* fltk::cairo_create_surface(Window* wi) {
>>    XWindow window = fltk::xid(wi);
>>    cairo_surface_t* surface =  cairo_xlib_surface_create(xdisplay, window,
>> 				   xvisual->visual, wi->w(), wi->h());
>>    cairo_xlib_surface_set_size(surface, wi->w(), wi->h());
>>    return surface;
>> }
> 
> My test app show much flickering even though it is a Fl_Double_Window.

Yes you actually have to pick up a different xid to get the back buffer 
window. This is in the x.h header file. What a pain.

> Alternatively using a Xrender surface brings me lots of errors for the 
> first of following variants:

That's not recommended and a waste of time. Either draw directly into 
the xid that fltk has, or use an image surface.

> One other thing, which made me wonder, is the need for a swap of the RGB 
> channels coming from a 
> cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w,h) created image 
> surface before using fl_draw_image() in myFl_Box::draw().
> Is this normal behaviour?

Yes back when the fl_draw_image was created I assummed rgba layout of 
the bytes would be the standard. It was Windows that made the argb32 (or 
bgra) layout common. Fltk2 has support for argb32 and other layouts of 
the pixels.

-- 
Bill Spitzak, Senior Software Engineer
The Foundry, 1 Wardour Street, London, W1D 6PA, UK
Tel: +44 (0)20 7434 0449 * Fax: +44 (0)20 7434 1550 * Web: 
www.thefoundry.co.uk
The Foundry Visionmongers Ltd * Registered in England and Wales No: 4642027



More information about the cairo mailing list