Process for implementing a double buffer on Wayland

Daniel Stone daniel at fooishbar.org
Wed Nov 25 08:18:52 PST 2015


Hi Mike,

On 25 November 2015 at 16:06, Mike Johnson <mikeyj001 at hotmail.com> wrote:
> I've created 2 buffers of the same size (800x600 pixels).  So I want the
> input buffer to get filled off-screen, while the output buffer will show the
> content on-screen.
>
> First of all what sort of content could be used to illustrate this
> technique, and secondly, what mechanisms are available to:
>
> a) Notify that the input buffer is full
> b) Copy the content to the output buffer so that it shows on-screen

It's quite simple. wl_surface_attach(surf, buf) +
wl_surface_commit(surf) will display 'buf' for that surface. At that
point, the compositor owns that buffer, so you should stop drawing on
it. When the compositor has finished with a buffer, it will send you a
wl_buffer.release event. You can sync your paint clock to the
compositor's repaint loop with wl_surface_frame.

So, the normal workflow is:
  - create surface S, buffer A, buffer B
  - draw first frame into buffer A
  - call wl_surface_frame(S) + wl_surface_attach(S, A) +
wl_surface_commit(S) + wl_display_flush()
  - go to sleep
  - receive completion for wl_surface_frame callback
  - draw second frame into buffer B
  - call wl_surface_frame(S) + wl_surface_attach(S, B) +
wl_surface_commit(S) + wl_display_flush()
  - compositor now owns both buffers, so don't touch any
  - receive wl_buffer.release event for buffer A - now unused
  - receive completion for wl_surface_frame callback
  - draw third frame into buffer A
  - ...

Hope that helps. You can see the weston-simple-shm client for a pretty
straightforward example.

Cheers,
Daniel


More information about the wayland-devel mailing list