[Mesa-dev] [PATCH 2/2] egl: Check if API is supported when using eglBindAPI.

Emil Velikov emil.l.velikov at gmail.com
Wed May 18 11:11:52 UTC 2016


Hi Plamena,

On 17 May 2016 at 17:35, Plamena Manolova <plamena.manolova at intel.com> wrote:
> According to the EGL specifications before binding an API
> we must check whether it's supported first. If not eglBindAPI
> should return EGL_FALSE and generate a EGL_BAD_PARAMETER error.
>
> Signed-off-by: Plamena Manolova <plamena.manolova at intel.com>
> ---
>  src/egl/main/eglcurrent.h | 33 ++++++++++++++++++++++++++++++---
>  1 file changed, 30 insertions(+), 3 deletions(-)
>
> diff --git a/src/egl/main/eglcurrent.h b/src/egl/main/eglcurrent.h
> index 1e386ac..f2e19cc 100644
> --- a/src/egl/main/eglcurrent.h
> +++ b/src/egl/main/eglcurrent.h
> @@ -32,7 +32,8 @@
>  #include "c99_compat.h"
>
>  #include "egltypedefs.h"
> -
> +#include "eglglobals.h"
> +#include "egldisplay.h"
>
>  #ifdef __cplusplus
>  extern "C" {
> @@ -62,14 +63,40 @@ struct _egl_thread_info
>     EGLint CurrentAPIIndex;
>  };
>
> -
> +static inline EGLBoolean
> +_eglDisplaySupportsApi(_EGLDisplay *dpy, EGLenum api)
> +{
> +   if (!dpy->Initialized) {
> +      return EGL_FALSE;
> +   } else if (api == EGL_OPENGL_API && dpy->ClientAPIs & EGL_OPENGL_BIT) {
> +      return EGL_TRUE;
> +   } else if (api == EGL_OPENGL_ES_API &&
> +      (dpy->ClientAPIs & EGL_OPENGL_ES_BIT ||
> +       dpy->ClientAPIs & EGL_OPENGL_ES2_BIT ||
> +       dpy->ClientAPIs & EGL_OPENGL_ES3_BIT_KHR)) {
> +      return EGL_TRUE;
> +   } else if (api == EGL_OPENVG_API && dpy->ClientAPIs & EGL_OPENVG_BIT) {
> +      return EGL_TRUE;
> +   } else {
> +      return EGL_FALSE;
> +   }
Nit: please use a switch (api) statement ?

> +}
>  /**
>   * Return true if a client API enum is recognized.
>   */
>  static inline EGLBoolean
>  _eglIsApiValid(EGLenum api)
>  {
> -   return (api >= _EGL_API_FIRST_API && api <= _EGL_API_LAST_API);
> +   _EGLDisplay *dpy = _eglGlobal.DisplayList;
> +
> +   while (dpy) {
> +      if (_eglDisplaySupportsApi(dpy, api) == EGL_TRUE)
> +         return EGL_TRUE;
> +
> +      dpy = dpy->Next;
> +   }
> +
> +   return EGL_FALSE;
Afaict currently this returns true if any display supports the said
APIs, while the manpage says

"eglBindAPI defines the current rendering API for EGL in the thread it
is called from"

Haven't looked at the spec, but I'd assume it's a similar thing.

So here we'd want to get the current thread info via
_eglGetCurrentThread() and derive the display (displays?) based on it.
I think we don't have a way to the the latter yet, so one will need to
sort that one first.

I'm not an EGL expert but ^^ makes sense from where I look at it.

-Emil


More information about the mesa-dev mailing list