[cairo] cairo / xlib not updating window content

Pavel Petrovic pavel.petrovic.level2 at gmail.com
Sat Jul 28 10:34:59 UTC 2018


Hello,

I tried to investigate in more depth, here are some findings:

1. Filled rectangles not showing up:
  - changing them for circles solves it, so it really is about the rectangles
  - workaround: not only fill, but draw again and then stroke, this
solves the issue

  pending question: why drawing filled rectangles without borders is
not possible/flushed?

2. cairo_paint() effect lost due to window not shown yet:
  - adding ExposureMask to XSelectInput() and then painting only after
    the Expose event arrives, solves the problem

  pending question: why drawing to a window that has been properly
constructed is lost if it was not exposed yet?

3. the red line drawn from keyboard events not being updated:
   - adding extra cairo_surface_flush() after each piece of line helps somewhat,
     it seems that all parts of line are drawn eventually, but
sometimes it takes
     even several seconds, while the machine cpu/memory is pretty idle

  follow-up question:
    Does cairo keep all the shapes that have been drawn in some kind of list
    which slows it down so much when there are so many shapes?
    (sorry for such a beginner/disturbing question)

Thanks.
Pavel



On Sat, Jul 28, 2018 at 9:50 AM, Pavel Petrovic
<pavel.petrovic.level2 at gmail.com> wrote:
> I am trying to learn how to use Cairo 2D drawing library with xlib surfaces.
>
> I wrote a little test program that allows creating multiple windows.
> Each function may have a custom paint() function that is called
> regularly to add some graphics content to the window, or redraw it
> completely if desired. There is also an option to define mouse and key
> listener. The main routine checks for X events (to delegate them to
> mouse and key listener) and for timeout for periodic call of those
> paint() functions.
>
> I tried with the 1.14.6 version of Cairo (that is currently available
> as package in Ubuntu 16.04), and the latest 1.15.12, but the results
> are the same.
>
> The expected behavior of this demo is to open 3 windows. One will have
> random rectangles being added, another one random texts, and the third
> random circles.
>
> In addition, clicking into windows should produce lines (connecting to
> mouse click, or randomly), and using arrow keys should draw a red line
> in the window with circles.
>
> The circles and text seem to show up regularly as expected. All three
> windows should have white background, but two of them are black. And
> the worst, the window with rectangles does not get updated much (and
> it does not matter if it is the first window created or not, it is
> always the rectangles that do not show up properly).
>
> They are only shown when the focus changes to or from that window -
> then the remaining rectangles that should have been drawn meanwhile
> suddenly appear.
>
> I am calling cairo_surface_flush() on the surface of each window after
> adding any content, but that does not help. I also tried posting
> XEvents to that window of various kind (such as focus), they arrive,
> but rectangles do not show up.
>
> Furthermore, even though drawing lines with mouse works fine, drawing
> line with key arrows suffers from the same problem - it is drawn, but
> not shown properly.
>
> I am obviously wrong in some of my assumptions about what this library
> can do, but I am not sure where.
>
> It seems that there are some two competing versions of drawing being
> shown, since it happens sometimes that one or two rectangles, or
> pieces of the red line are flashing. Some kind of strange buffering,
> caching? It may just be some bug in my program, I do not know.
>
> Another observation - the black background is because drawing white
> background happens before the window is shown, and thus those
> cairo_paint calls are somehow discarded. I do not know how to make the
> window appear earlier, it seems it appears only after some later
> changes on the screen.
>
> I am stuck on this after a couple of desperate days, could you help me
> out at least in part, please?
>
> The program is here: https://kempelen.dai.fmph.uniba.sk/test_cairo/test_cairo.c
>
> An example screenshot (with a broken red line drawn by keys, and
> rectangles not showing up properly):
> https://kempelen.dai.fmph.uniba.sk/test_cairo/test_cairo.png
>
> To compile (on Ubuntu 16.04 or similar system):
>
> gcc -o test_cairo test_cairo.c -I/usr/include/cairo -lX11 -lcairo


More information about the cairo mailing list