Process for implementing a double buffer on Wayland

Hardening rdp.effort at gmail.com
Wed Nov 25 12:43:49 PST 2015


Le 25/11/2015 17:18, Daniel Stone a écrit :
> 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
>   - ...
> 

I may be wrong, but there's no guaranty that the compositor sends
wl_buffer.release event on buffer A. I think I have experimented this
when the renderer in weston is the pixman renderer.
IIRC I have been told on IRC that the compositor decides when the buffer
is not used, so you may not receive the release message immediately. I
have hit that kind of bug when coding libUWAC.

Best regards.

-- 
David FORT
website: http://www.hardening-consulting.com/



More information about the wayland-devel mailing list