<div dir="ltr"><div class="gmail_extra"><br><div class="gmail_quote">On Wed, May 18, 2016 at 8:44 PM, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 05/18/2016 11:45 AM, Manolova, Plamena wrote:<br>
> Hi Ian,<br>
> Thanks for reviewing!<br>
><br>
> On Wed, May 18, 2016 at 4:33 PM, Ian Romanick <<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a><br>
</span><span class="">> <mailto:<a href="mailto:idr@freedesktop.org">idr@freedesktop.org</a>>> wrote:<br>
><br>
> On 05/17/2016 09:35 AM, Plamena Manolova wrote:<br>
> > According to the EGL specifications before binding an API<br>
> > we must check whether it's supported first. If not eglBindAPI<br>
> > should return EGL_FALSE and generate a EGL_BAD_PARAMETER error.<br>
><br>
> Can you provide a spec quotation?<br>
><br>
><br>
> <a href="https://www.khronos.org/registry/egl/sdk/docs/man/html/eglBindAPI.xhtml" rel="noreferrer" target="_blank">https://www.khronos.org/registry/egl/sdk/docs/man/html/eglBindAPI.xhtml</a><br>
><br>
> "EGL_BAD_PARAMETER is generated if api is not one of the accepted<br>
> tokens, or if the<br>
> specified client API is not supported by the EGL implementation."<br>
<br>
</span>That's the man page, not the spec. We have found a few problems over<br>
the years in using man page quotations, so we generally prefer to use<br>
the spec. The biggest issue is that it's harder to track changes in the<br>
man pages, but we can pretty easily tell when something changed between,<br>
say, EGL 1.2 and EGL 1.5. If nothing else, it makes the quotation<br>
practice more consistent to always use the same kind of source.<br>
<br>
In Mesa, changes like this should be accompanied by a quotation, in a<br>
canonical format, from the specification. Ideally, the quotation should<br>
go in the code being changed. It may also be acceptable to include the<br>
quotation in the commit message. The next person to look at this code<br>
is either going to just look at the code or look at the commit that<br>
added it (after using git-blame).<br>
<br>
For this case, the proper spec quotation would be:<br>
<br>
Section 3.7 (Rendering Contexts) of the EGL 1.5 spec says:<br>
<br>
"api must specify one of the supported client APIs, either<br>
EGL_OPENGL_API, EGL_OPENGL_ES_API, or EGL_OPENVG_API... If api<br>
is not one of the values specified above, or if the client API<br>
specified by api is not supported by the implementation, an<br>
EGL_BAD_PARAMETER error is generated."<br>
<br></blockquote><div><br></div><div>Thanks for clearing this up for me Ian, I'm pretty new to Mesa so pointers like this</div><div>are really appreciated. I'll keep it mind for next time. I'll also include the quotation in</div><div>the code for my follow up patch.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
> > Signed-off-by: Plamena Manolova <<a href="mailto:plamena.manolova@intel.com">plamena.manolova@intel.com</a><br>
> <mailto:<a href="mailto:plamena.manolova@intel.com">plamena.manolova@intel.com</a>>><br>
<div class="HOEnZb"><div class="h5">> > ---<br>
> > src/egl/main/eglcurrent.h | 33 ++++++++++++++++++++++++++++++---<br>
> > 1 file changed, 30 insertions(+), 3 deletions(-)<br>
> ><br>
> > diff --git a/src/egl/main/eglcurrent.h b/src/egl/main/eglcurrent.h<br>
> > index 1e386ac..f2e19cc 100644<br>
> > --- a/src/egl/main/eglcurrent.h<br>
> > +++ b/src/egl/main/eglcurrent.h<br>
> > @@ -32,7 +32,8 @@<br>
> > #include "c99_compat.h"<br>
> ><br>
> > #include "egltypedefs.h"<br>
> > -<br>
> > +#include "eglglobals.h"<br>
> > +#include "egldisplay.h"<br>
> ><br>
> > #ifdef __cplusplus<br>
> > extern "C" {<br>
> > @@ -62,14 +63,40 @@ struct _egl_thread_info<br>
> > EGLint CurrentAPIIndex;<br>
> > };<br>
> ><br>
> > -<br>
> > +static inline EGLBoolean<br>
> > +_eglDisplaySupportsApi(_EGLDisplay *dpy, EGLenum api)<br>
><br>
> Since this is only used internally, please use bool/true/false. Based<br>
> on my comments at the bottom, I think this function should go directly<br>
> in eglapi.c.<br>
><br>
> > +{<br>
><br>
> This is a really complex way of doing something quite simple. How<br>
> about.<br>
><br>
> unsigned api_bit;<br>
><br>
> if (!dpy->Initialized)<br>
> return false:<br>
><br>
> switch (api) {<br>
> case EGL_OPENGL_API:<br>
> api_bit = EGL_OPENGL_BIT;<br>
> break;<br>
> case EGL_OPENGL_ES_API:<br>
> api_bit = EGL_OPENGL_ES_BIT |<br>
> EGL_OPENGL_ES2_BIT |<br>
> EGL_OPENGL_ES3_BIT_KHR;<br>
> break;<br>
> case EGL_OPENVG_API:<br>
> api_bit = EGL_OPENVG_BIT;<br>
> break;<br>
> default:<br>
> api_bit = 0;<br>
> break;<br>
> }<br>
><br>
> return (dpy->ClientAPIs & api_bit) != 0;<br>
><br>
><br>
> I'll make those changes.<br>
><br>
><br>
><br>
> > + if (!dpy->Initialized) {<br>
> > + return EGL_FALSE;<br>
> > + } else if (api == EGL_OPENGL_API && dpy->ClientAPIs & EGL_OPENGL_BIT) {<br>
> > + return EGL_TRUE;<br>
> > + } else if (api == EGL_OPENGL_ES_API &&<br>
> > + (dpy->ClientAPIs & EGL_OPENGL_ES_BIT ||<br>
> > + dpy->ClientAPIs & EGL_OPENGL_ES2_BIT ||<br>
> > + dpy->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR)) {<br>
> > + return EGL_TRUE;<br>
> > + } else if (api == EGL_OPENVG_API && dpy->ClientAPIs & EGL_OPENVG_BIT) {<br>
> > + return EGL_TRUE;<br>
> > + } else {<br>
> > + return EGL_FALSE;<br>
> > + }<br>
> > +}<br>
> > /**<br>
> > * Return true if a client API enum is recognized.<br>
> > */<br>
> > static inline EGLBoolean<br>
> > _eglIsApiValid(EGLenum api)<br>
><br>
> There's only one user of this function, and I suspect there will only<br>
> every be that one user. I would do a first patch that moves this<br>
> function into eglapi.c... maybe even just move this function into the<br>
> only caller. Then this patch would change the way it works.<br>
><br>
><br>
> Makes sense I'll go ahead and move it to the actual caller.<br>
><br>
><br>
</div></div><div class="HOEnZb"><div class="h5">> > {<br>
> > - return (api >= _EGL_API_FIRST_API && api <= _EGL_API_LAST_API);<br>
> > + _EGLDisplay *dpy = _eglGlobal.DisplayList;<br>
> > +<br>
> > + while (dpy) {<br>
> > + if (_eglDisplaySupportsApi(dpy, api) == EGL_TRUE)<br>
><br>
> Even without changing _eglDisplaySupportsApi to return bool, you can<br>
> drop the '== EGL_TRUE'.<br>
><br>
> > + return EGL_TRUE;<br>
> > +<br>
> > + dpy = dpy->Next;<br>
> > + }<br>
> > +<br>
> > + return EGL_FALSE;<br>
> > }<br>
> ><br>
> ><br>
><br>
<br>
</div></div></blockquote></div><br></div></div>