<p dir="ltr"><br>
Von: "Eugen Friedrich" <<a href="mailto:friedrix@gmail.com">friedrix@gmail.com</a>><br>
Datum: 24.06.2016 10:59 nachm.<br>
Betreff: Re: How to create client in child thread<br>
An: "Pekka Paalanen" <<a href="mailto:ppaalanen@gmail.com">ppaalanen@gmail.com</a>><br>
Cc: </p>
<p dir="ltr">Hello Pekka,<br>
you mentions some interesting points for me in this email not really<br>
related to the original topic,<br>
therefore I'm just jumping in  between.<br>
> > On Thu, 16 Jun 2016 09:54:54 +0800 (CST)<br>
> > 袁嘉伟 <<a href="mailto:yuanjw1025@163.com">yuanjw1025@163.com</a>> wrote:<br>
> ><br>
> >> Yes, I want to achieve that drawing the client from a thread but not<br>
> >> the main thread. Before I have tested that creating display and<br>
> >> drawing surface from main thread, and I try to call the<br>
> >> functions(xdg_surface_xxxx) of wayland to control the client from<br>
> >> child thread, but failed. The reason is function blocked. Through<br>
> >> referring some websites, I thought  the drawing and control might be<br>
> >> in the same thread. I continue to test that drawing the client in<br>
> >> child thread, but it still block in function eglGetDisplay(&display).<br>
> >> I don't know why. Because of HMI framework, I must call the function<br>
> >> to control the client in child thread. My test code is sample-egl.c.<br>
> >> Thanks.<br>
> >><br>
> >><br>
> >><br>
> >><br>
> >> 在 2016-06-16 04:24:19,"Benoit Gschwind" <<a href="mailto:gschwind@gnu-log.net">gschwind@gnu-log.net</a>><br>
> >> 写道:<br>
> >> >Hello,<br>
> >> ><br>
> >> >The reply from Pekka is about compositor using a client to make the<br>
> >> >rendering, but I not sure this is what you asking for.<br>
> >> ><br>
> >> >Are you talking about building a compositor ? It look like you are<br>
> >> >making a wayland client that try to delegate the drawing to a<br>
> >> >thread. Is it what you want to do ?<br>
> >> ><br>
> >> >Best regards<br>
> >> ><br>
> ><br>
> > Oh indeed, sorry for my confusion. First, some general background<br>
> > information:<br>
> ><br>
> > eglSwapBuffers() counts as a Wayland protocol call, because it is<br>
> > guaranteed to call wl_surface.commit before it returns and with the</p>
<p dir="ltr"> totally agree with that, but is there any official specification for this?<br>
 Argument: because it is implemented in Mesa is not always accepted by<br>
 suppliers. Also if compositor and clients use different hardware for<br>
 rendering synchronization might become difficult.<br>
I already know two different EGL providers where wl_surface.commit is<br>
not called during eglSwapBuffer execution, there is a thread inside<br>
 the EGL which is doing this.</p>
<p dir="ltr">> > newly rendered buffer attached, and it will also wait for<br>
> > wl_buffer.release events if necessary, and by default it also waits for<br>
> > wl_surface.frame callbacks to return.<br>
> ><br>
> > Here is what I wrote about EGL elsewhere:<br>
> ><br>
> >         eglSwapBuffers will be waiting for the previous eglSwapBuffers'<br>
> >         frame callback and only if it has not arrived already for the<br>
> >         particular surface. If you call eglSwapBuffers as a response to<br>
> >         receiving your own copy of the frame callback or later,<br>
> >         eglSwapBuffers will never block.<br>
> ><br>
> >         To be more precise, wait for the frame callback happens on the<br>
> >         eglSwapBuffers *after* the current one as I explained above,<br>
> >         and waits for wl_buffer.releases happen at the first draw call<br>
> >         that would need a buffer to draw into if necessary.<br>
> ><br>
> >         Those are the two orthogonal throttling mechanisms in Mesa.<br>
> >         Setting swap interval to 0 will prevent waits for the frame<br>
> >         callbacks, but not for buffer releases, because Mesa does not<br>
> >         want to potentially allocate an unlimited number of buffers in<br>
> >         case the server is slow to send out releases (which would imply<br>
> >         your whole system is already hosed anyway, so putting even more<br>
> >         pressure to it would only make things worse).<br>
> ><br>
> > The above describes the expected behaviour of EGL. Bugs, which we know<br>
> > to be around, are another matter.<br>
> ><br>
> > Do note, that I am only talking about Mesa and what a proper EGL<br>
> > implementation would do. If you are using any properietary EGL<br>
> > implementation, especially Vivante, you might be in trouble.<br>
> ><br>
> > Other things you must take care of are:<br>
> ><br>
> > - every thread where you want Wayland events dispatched must have its<br>
> >   own wl_event_queue (Mesa EGL creates one for itself)<br>
> ><br>
> > - you must use the wl_display_prepare_read() API of libwayland-client<br>
> >   in all callers of libwayland-client properly<br>
> ><br>
> > - Pay attention to all bugs linked from<br>
> >   <a href="https://bugs.freedesktop.org/show_bug.cgi?id=91769">https://bugs.freedesktop.org/show_bug.cgi?id=91769</a> ,<br>
> >   particularly <a href="https://bugs.freedesktop.org/show_bug.cgi?id=91273">https://bugs.freedesktop.org/show_bug.cgi?id=91273</a> which<br>
> >   also requires a fix in the EGL implementation (for Mesa, see<br>
> >   <a href="https://lists.freedesktop.org/archives/mesa-dev/2016-May/115617.html">https://lists.freedesktop.org/archives/mesa-dev/2016-May/115617.html</a><br>
> >   for a patch that does not seem to have been even merged yet).<br>
> ><br>
> > In general, Wayland functions are *not* meant for controlling things<br>
> > across thread boundaries. It is safe to send requests from multiple<br>
> > threads, but you are still responsible for ordering them correctly<br>
> > yourself in cases where the order matters.<br>
> ><br>
> > If this gives you the impression that using threads with EGL/Wayland in<br>
> > particular is rare and not really tested, you are right. I do not know<br>
> > of any good code examples, maybe others have some?</p>
<p dir="ltr">don't have an example by hand but I think with wayland 1.11 there is a<br>
 proper way to implement thread save handling, right?<br>
 important points are already mentioned above only one to add:<br>
       - use proxy wrappers for creation of wayland objects</p>
<p dir="ltr">> ><br>
> > You say you are blocked in eglGetDisplay(). I have not heard of that<br>
> > before. Which EGL implementation is that? If it is not Mesa, and you<br>
> > cannot reproduce the problem with Mesa, then I suspect you have to<br>
> > contact your EGL vendor about it.<br>
> ><br>
> ><br>
> > Thanks,<br>
> > pq<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="https://lists.freedesktop.org/mailman/listinfo/wayland-devel">https://lists.freedesktop.org/mailman/listinfo/wayland-devel</a><br>
> ><br>
</p>