<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On 26 November 2014 at 09:04, Pekka Paalanen <span dir="ltr"><<a href="mailto:ppaalanen@gmail.com" target="_blank">ppaalanen@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">From: Pekka Paalanen <<a href="mailto:pekka.paalanen@collabora.co.uk">pekka.paalanen@collabora.co.uk</a>><br>
<br>
Explain carefully why we need two roundtrips, not just one, not just<br>
dispatch and roundtrip, but two roundtrips after creating the<br>
wl_registry object.<br>
<br>
</span>v2: Explain what initial events are, and that this is a general<br>
technique.<br>
<span class=""><br>
Signed-off-by: Pekka Paalanen <<a href="mailto:pekka.paalanen@collabora.co.uk">pekka.paalanen@collabora.co.uk</a>><br>
---<br>
</span> clients/simple-shm.c | 40 ++++++++++++++++++++++++++++++++++++++++<br>
<span class=""> 1 file changed, 40 insertions(+)<br>
<br>
diff --git a/clients/simple-shm.c b/clients/simple-shm.c<br>
</span>index c1cb386..0844565 100644<br>
--- a/clients/simple-shm.c<br>
+++ b/clients/simple-shm.c<br>
@@ -388,6 +388,46 @@ create_display(void)<br>
<span class=""><br>
        wl_display_roundtrip(display->display);<br>
<br>
+       /*<br>
+        * Why do we need two roundtrips here?<br>
+        *<br>
+        * wl_display_get_registry() sends a request to the server, to which<br>
+        * the server replies by emitting the wl_registry.global events.<br>
+        * The first wl_display_roundtrip() sends wl_display.sync. The server<br>
+        * first processes the wl_display.get_registry which includes sending<br>
+        * the global events, and then processes the sync. Therefore when the<br>
+        * sync (roundtrip) returns, we are guaranteed to have received and<br>
+        * processed all the global events.<br>
+        *<br>
+        * While we are inside the first wl_display_roundtrip(), incoming<br>
+        * events are dispatched, which causes registry_handle_global() to<br>
+        * be called for each global. One of these globals is wl_shm.<br>
+        * registry_handle_global() sends wl_registry.bind request for the<br>
+        * wl_shm global. However, wl_registry.bind request is sent only after<br></span></blockquote><div><br></div><div>Probably it's just due to my bad English, but the 'only' seems redundant to me here.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="">
+        * the first wl_display.sync, so the reply to the sync comes before<br>
+        * the initial events of the wl_shm object.<br>
+        *<br>
</span>+        * The initial events that get sent as a reply to binding to wl_shm<br>
+        * include wl_shm.format. These tell us which pixel formats are<br>
+        * supported, and we need them before we can create buffers. They<br>
+        * don't change at runtime, so we receive them as part of init.<br>
<span class="">+        *<br>
+        * When the reply to the first sync comes, the server may or may not<br>
</span>+        * have sent the initial wl_shm events. Therefore we need the second<br>
<span class="">+        * wl_display_roundtrip() call here.<br>
+        *<br>
+        * The server processes the wl_registry.bind for wl_shm first, and<br>
+        * the second wl_display.sync next. During our second call to<br>
+        * wl_display_roundtrip() the initial wl_shm events are received and<br>
+        * processed. Finally, when the reply to the second wl_display.sync<br>
+        * arrives, it guarantees we have processed all wl_shm initial events.<br>
+        *<br>
</span>+        * This sequence contains two examples on how wl_display_roundtrip()<br>
+        * can be used to guarantee, that all reply events to a request<br>
+        * have been received and processed. This is a general Wayland<br>
+        * technique.<br>
<div class=""><div class="h5">+        */<br>
+<br>
        if (!(display->formats & (1 << WL_SHM_FORMAT_XRGB8888))) {<br>
                fprintf(stderr, "WL_SHM_FORMAT_XRGB32 not available\n");<br>
                exit(1);<br>
--<br>
2.0.4<br>
<br>
_______________________________________________<br>
wayland-devel mailing list<br>
<a href="mailto:wayland-devel@lists.freedesktop.org">wayland-devel@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/wayland-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br></div></div></blockquote><div> </div><div><div><div><div>Looks fine to me.<br><br></div>Maybe it'd be worth to 
mention this 'general technique' on appropriate places in the source 
code, i. e. in wl_display_get_registry() documentation or so.<br></div>Everybody who first runs into Wayland will probably read documentation to wl_display_get_registry() :)<br><br></div>Reviewed-by: Marek Chalupa <<a href="mailto:mchqwerty@gmail.com">mchqwerty@gmail.com</a>> <br></div></div><br></div></div>