[cairo] cairo / xlib not updating window content

Pavel Petrovic pavel.petrovic.level2 at gmail.com
Sun Jul 29 13:01:05 UTC 2018


Dear Cedric,

Many thanks for your new version with push/pop group
and the explanation.

I am trying to use Cairo in a little robot project for SICK
Robot day contest, and I made this little test of our
tiny gui framework for displaying information from sensors
in different windows, used for example here:

https://github.com/Robotics-DAI-FMFI-UK/mikes-common/blob/master/modules/passive/x_tim571.c

I do not need anything fancy, just see the sensor data
updated on the screen. The sensor has 15 Hz frequency,
and when drawing its 811 lines per scan to window, it usually
takes something under 200ms on RaspPI3.  Not too good,
but for a human monitoring, it should be sufficient.
With the push/pop group, the drawings are shown
immediately.

But I thought push/pop group is only useful/needed to avoid
flickering in animation, to allow drawing to memory and pasting
the whole new frame over the window, I did not read it
as this is always needed.

Otherwise, I would consider it a bug that the filled rectangles
never show up, if they are not stroked, and quite a surprise
that it takes more than 10 seconds for simple line drawing to
actually appear in the window, if it was generated after a keyboard
event, while other drawings that come after mouse events
appear immediately.

I think I am now ok with the Expose events - I thought it would
be enough to draw after the first one, but then the window
remains dark again sometimes, so one has to draw
after each Expose, even if they follow 3 one after another.
So the one in the version 3 already did that:
   https://kempelen.dai.fmph.uniba.sk/test_cairo/test_cairo3.c

and now I have combined it into version 4, with the push/pop group
of yours:
  https://kempelen.dai.fmph.uniba.sk/test_cairo/test_cairo4.c

which solved all the issues:
   - red line appearing immediately
   - rectangles do not need to be stroked, and yet appearing immediately
   - window background is always white

I am still not sure whether it is better to always create a new cairo_t
(as in version 4) or just keep it in the windows[] array as was in the first
version, but both seem to work.

Many thanks to all of you, Cairo has shown a very friendly community!

Pavel.


On Sun, Jul 29, 2018 at 12:29 PM, Cedric Roux <sed at free.fr> wrote:
> Hi,
>
> On 07/28/2018 09:50 AM, Pavel Petrovic wrote:
>> I am trying to learn how to use Cairo 2D drawing library with xlib surfaces.
>
> attached a version that "works" for me.
>
> At https://cairographics.org/Xlib/ it is said you
> need to call cairo_push_group and cairo_pop_group_to_source
> (and also cairo_surface_flush, which I didn't add; it
> works for me without it).
>
> That said, keep in mind that the content of an X window
> may vanish at any time. So all you did between XMapWindow
> and the current time may be displayed, or not.
>
> That's why your white background is there for one window
> and not for the others.
>
> There is the notion of "backing store" for X windows. The X
> server may store content, but it's not guarantied (by default,
> when calling XCreateSimpleWindow at least).
>
> You should thus change your inner thinking of what an X window
> is. This is not a buffer that keeps all what you plot into.
> You should (must?) react to the Expose event and redraw dirty
> the dirty area indicated by this event.
>
> I don't know what your ultimate goal is, but maybe you want
> to use X pixmaps (that keep their contents), draw cairo into
> them and copy the pixmaps to the X windows whenever the content
> is ready, instead of directly draw to X windows.
>
> If you minimize your windows or put another window in front
> of them, and then put the window back in front, depending on
> the X server you use (and maybe also the window manager),
> the hidden content will have been preserved or not.
>
> Anyway, in short: X windows are very "volatile" creatures.
> Do not assume the content you send there will survive long.
> React to Expose event, and redraw the area that is invalid.
> Use X pixmaps if you want some kind of permanent content.
>
> Something like that.
>
> HTH.
> Cedric.


More information about the cairo mailing list