[cairo] Cairo and multiple X11 windows

W.Boeke w.boeke at chello.nl
Fri Aug 1 06:30:49 PDT 2008

Bill Spitzak wrote:
> No, FLTK uses single big X windows. The child widgets are just C++ 
> structures entirely kept in the programs local memory. IMHO creating 
> many child windows in X is very inefficient and requires far more 
> communication to the server, and produces very bad redrawing behavior 
> because the background rectangles are updated asynchronously with all 
> the other drawings. Also it would seem to be quite wasteful as there is 
> zero savings on the main process end and obviously a lot of data loaded 
> into the X server.

Are you shure that creating many windows in X is inefficient? My program
instantiates 100's of them, still the graphics are fast, even on an old
slow box and on the Asus eeePC. Running the 'top' command reveals that the
CPU is hardly occupied by the graphics, only when a window must be redrawn
because it is becoming less obscured by other windows. In this case
it probably makes no difference whether you have one big window or many
subwindows however.

I searched on the internet for "many child windows", and came across the
following text:
    Our FGL2C-compiled programs generate many childwindows. The worst case
    is 500 entrys,which is not possible under 16-bit(WIN32s),because the
    resources are down after about 300 entrys. This is the point, where all
    Tk-Window-Ports are slow. Under GNU/Linux with X11, 300 Childwindows don't
    consume any time for creation an displaying, even a 368-machine runs with
    satisfying results , but under Windows...

Anyhow, using many windows has its advantages. E.g. you can set event masks
for each window individually. If you use one big window and you need
at one place the ButtonMotionMask, then this must be set for the whole
window, which will generate an awful lot of unused events. And clearing
a window will have to be done by painting it, which is slower then XClearWindow().
And different cursor shapes for different window parts becomes (IMHO)
impossible. Probably the last word isn't yet said about the subject.

> FLTK's cairo support reuses exactly one cairo_t for drawing every 
> window, because I had the same concerns about efficiency. This is the 
> exact code it uses when it wants to change what window it draws into. 
> Carl may have some comments on this?

Thanks for this code! I am going to borrow it!


More information about the cairo mailing list