Help with proxy queues please
Hi I am clearly deeply confused by event queues and proxies - I have this snippet of code (from some VLC work I'm doing): sys->eventq = wl_display_create_queue(video_display(sys)); if (sys->eventq == NULL) { msg_Err(vd, "Failed to create event Q"); goto error; } if ((sys->wrapped_display = wl_proxy_create_wrapper(video_display(sys))) == NULL) { msg_Err(vd, "Failed to create wrapper"); goto error; } wl_proxy_set_queue((struct wl_proxy *)sys->wrapped_display, sys->eventq); struct wl_callback * cb; struct wl_registry *const registry = wl_display_get_registry(sys->wrapped_display); if (registry == NULL) { msg_Err(vd, "Cannot get registry for display"); goto error; } wl_registry_add_listener(registry, ®istry_cbs, vd); cb = wl_display_sync(sys->wrapped_display); wl_callback_add_listener(cb, ®_done_sync_listener, vd); msg_Info(vd, "Roundtrip start"); wl_display_roundtrip_queue(sys->wrapped_display, sys->eventq); msg_Info(vd, "Roundtrip done"); wl_registry_destroy(registry); video_display() returns the display we are rendering to. My expectation was that the registry & sync listeners would be called somewhere between the roundtrip start/end debug lines, but what seems to happen is that the roundtrip just returns immediately. I have clearly misunderstood something at a fundamental level. I thought that the wrapped display would set the Q that the listeners would send events on and th eroundtrip would wait for that. The wl_proxy_create_wrapper docn on https://wayland.freedesktop.org/docs/html/apb.html#Client-classwl__proxy also seems to imply this. Any hints would be gratefully received - thanks John Cox
Re: Help with proxy queues please
On Mon, 11 Sep 2023 12:53:15 +0100 John Cox wrote: > Hi > I am clearly deeply confused by event queues and proxies - I have this > snippet of code (from some VLC work I'm doing): > > sys->eventq = wl_display_create_queue(video_display(sys)); > if (sys->eventq == NULL) { > msg_Err(vd, "Failed to create event Q"); > goto error; > } > if ((sys->wrapped_display = > wl_proxy_create_wrapper(video_display(sys))) == NULL) > { > msg_Err(vd, "Failed to create wrapper"); > goto error; > } > wl_proxy_set_queue((struct wl_proxy *)sys->wrapped_display, sys->eventq); > > struct wl_callback * cb; > struct wl_registry *const registry = > wl_display_get_registry(sys->wrapped_display); > if (registry == NULL) { > msg_Err(vd, "Cannot get registry for display"); > goto error; > } > > wl_registry_add_listener(registry, ®istry_cbs, vd); > cb = wl_display_sync(sys->wrapped_display); > wl_callback_add_listener(cb, ®_done_sync_listener, vd); > > msg_Info(vd, "Roundtrip start"); > wl_display_roundtrip_queue(sys->wrapped_display, sys->eventq); The problem is probably here. wrapped_display is just a shell of a wl_proxy, but wl_display_roundtrip_queue() needs the original wl_display, just like wl_display_dispatch_queue() it calls. Thanks to elinor in IRC for pointing this out, when I first went on a complete wild goose chase wondering if a wl_display can even be wrapped, but of course it must be wrappable. > msg_Info(vd, "Roundtrip done"); > wl_registry_destroy(registry); > > video_display() returns the display we are rendering to. My > expectation was that the registry & sync listeners would be called > somewhere between the roundtrip start/end debug lines, but what seems > to happen is that the roundtrip just returns immediately. > > I have clearly misunderstood something at a fundamental level. I > thought that the wrapped display would set the Q that the listeners > would send events on and th eroundtrip would wait for that. The > wl_proxy_create_wrapper docn on > https://wayland.freedesktop.org/docs/html/apb.html#Client-classwl__proxy > also seems to imply this. > > Any hints would be gratefully received - thanks Yeah, it's a bit awkward to have wl_display both as a proxy and a Wayland connection. Some APIs need only a wl_proxy, others need the connection. That's something to add in the docs somehow. As a rule of thumb, I'd say that anything that explicitly takes a 'struct wl_display *' as an argument in wayland-client-core.h needs the original wl_display and does not work with a proxy-wrapper. Another exception is that you cannot change the queue of the original wl_display (or at least it's buggy), while a proxy-wrapped wl_display you can. Thanks, pq pgpOaVz6PO7ZA.pgp Description: OpenPGP digital signature
Re: Help with proxy queues please
On Mon, 11 Sept 2023 at 15:52, Pekka Paalanen wrote: > > On Mon, 11 Sep 2023 12:53:15 +0100 > John Cox wrote: > > > Hi > > I am clearly deeply confused by event queues and proxies - I have this > > snippet of code (from some VLC work I'm doing): > > > > sys->eventq = wl_display_create_queue(video_display(sys)); > > if (sys->eventq == NULL) { > > msg_Err(vd, "Failed to create event Q"); > > goto error; > > } > > if ((sys->wrapped_display = > > wl_proxy_create_wrapper(video_display(sys))) == NULL) > > { > > msg_Err(vd, "Failed to create wrapper"); > > goto error; > > } > > wl_proxy_set_queue((struct wl_proxy *)sys->wrapped_display, sys->eventq); > > > > struct wl_callback * cb; > > struct wl_registry *const registry = > > wl_display_get_registry(sys->wrapped_display); > > if (registry == NULL) { > > msg_Err(vd, "Cannot get registry for display"); > > goto error; > > } > > > > wl_registry_add_listener(registry, ®istry_cbs, vd); > > cb = wl_display_sync(sys->wrapped_display); > > wl_callback_add_listener(cb, ®_done_sync_listener, vd); > > > > msg_Info(vd, "Roundtrip start"); > > wl_display_roundtrip_queue(sys->wrapped_display, sys->eventq); > > The problem is probably here. > > wrapped_display is just a shell of a wl_proxy, but > wl_display_roundtrip_queue() needs the original wl_display, just like > wl_display_dispatch_queue() it calls. > > Thanks to elinor in IRC for pointing this out, when I first went on a > complete wild goose chase wondering if a wl_display can even be > wrapped, but of course it must be wrappable. > > > msg_Info(vd, "Roundtrip done"); > > wl_registry_destroy(registry); > > > > video_display() returns the display we are rendering to. My > > expectation was that the registry & sync listeners would be called > > somewhere between the roundtrip start/end debug lines, but what seems > > to happen is that the roundtrip just returns immediately. > > > > I have clearly misunderstood something at a fundamental level. I > > thought that the wrapped display would set the Q that the listeners > > would send events on and th eroundtrip would wait for that. The > > wl_proxy_create_wrapper docn on > > https://wayland.freedesktop.org/docs/html/apb.html#Client-classwl__proxy > > also seems to imply this. > > > > Any hints would be gratefully received - thanks > > Yeah, it's a bit awkward to have wl_display both as a proxy and a > Wayland connection. Some APIs need only a wl_proxy, others need the > connection. > > That's something to add in the docs somehow. > > As a rule of thumb, I'd say that anything that explicitly takes a > 'struct wl_display *' as an argument in wayland-client-core.h needs the > original wl_display and does not work with a proxy-wrapper. > > Another exception is that you cannot change the queue of the original > wl_display (or at least it's buggy), while a proxy-wrapped wl_display > you can. > > > Thanks, > pq Many thanks for that. That makes it all (a little) clearer. John Cox