[Mesa-dev] [PATCH] swrast: Fix eglMakeCurrent(dpy, NULL, NULL, ctx)

Emil Velikov emil.l.velikov at gmail.com
Fri Jul 6 09:29:32 UTC 2018


On 5 July 2018 at 20:35, Adam Jackson <ajax at redhat.com> wrote:
> Fixes 14 piglits, mostly in egl_khr_create_context.
>
> Fixes: https://github.com/anholt/libepoxy/issues/177
> Signed-off-by: Adam Jackson <ajax at redhat.com>
> ---
>  src/mesa/drivers/dri/swrast/swrast.c | 34 +++++++++++++++-------------
>  1 file changed, 18 insertions(+), 16 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/swrast/swrast.c b/src/mesa/drivers/dri/swrast/swrast.c
> index ae5874f5927..7f08107c24f 100644
> --- a/src/mesa/drivers/dri/swrast/swrast.c
> +++ b/src/mesa/drivers/dri/swrast/swrast.c
> @@ -675,6 +675,9 @@ swrast_check_and_update_window_size( struct gl_context *ctx, struct gl_framebuff
>  {
>      GLsizei width, height;
>
> +    if (!fb)
> +        return;
> +
>      get_window_size(fb, &width, &height);
>      if (fb->Width != width || fb->Height != height) {
>         _mesa_resize_framebuffer(ctx, fb, width, height);
> @@ -857,30 +860,29 @@ dri_make_current(__DRIcontext * cPriv,
>                  __DRIdrawable * driReadPriv)
>  {
>      struct gl_context *mesaCtx;
> -    struct gl_framebuffer *mesaDraw;
> -    struct gl_framebuffer *mesaRead;
> +    struct gl_framebuffer *mesaDraw = NULL;
> +    struct gl_framebuffer *mesaRead = NULL;
>      TRACE;
>
>      if (cPriv) {
> -       struct dri_context *ctx = dri_context(cPriv);
>         struct dri_drawable *draw;
>         struct dri_drawable *read;
>
> -       if (!driDrawPriv || !driReadPriv)
> -           return GL_FALSE;
> +        mesaCtx = &dri_context(cPriv)->Base;
>
> -       draw = dri_drawable(driDrawPriv);
> -       read = dri_drawable(driReadPriv);
> -       mesaCtx = &ctx->Base;
> -       mesaDraw = &draw->Base;
> -       mesaRead = &read->Base;
> +       if (driDrawPriv && driReadPriv) {
> +           draw = dri_drawable(driDrawPriv);
> +           read = dri_drawable(driReadPriv);
> +           mesaDraw = &draw->Base;
> +           mesaRead = &read->Base;
>
> -       /* check for same context and buffer */
> -       if (mesaCtx == _mesa_get_current_context()
> -           && mesaCtx->DrawBuffer == mesaDraw
> -           && mesaCtx->ReadBuffer == mesaRead) {
> -           return GL_TRUE;
> -       }
> +           /* check for same context and buffer */
> +           if (mesaCtx == _mesa_get_current_context()
> +               && mesaCtx->DrawBuffer == mesaDraw
> +               && mesaCtx->ReadBuffer == mesaRead) {
> +               return GL_TRUE;
> +           }
> +        }
>
Skimming through the egl_khr_create_context text, this relaxes some
parts which are meant to be an error.
For example

      * If either of <draw> or <read> is a valid surface and the other
        is EGL_NO_SURFACE, an EGL_BAD_MATCH error is generated.

Something like the below should handle the case you're thinking of, right?

HTH
Emil

diff --git a/src/mesa/drivers/dri/swrast/swrast.c
b/src/mesa/drivers/dri/swrast/swrast.c
index ae5874f5927..3fa2dd83f27 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -866,6 +866,12 @@ dri_make_current(__DRIcontext * cPriv,
  struct dri_drawable *draw;
  struct dri_drawable *read;

+        /* GL 3.0 allows *MakeCurrent(dpy, NULL, NULL, ctx) */
+        if (!driDrawPriv && !driReadPriv) {
+            _mesa_make_current(ctx, NULL, NULL);
+            return GL_TRUE;
+        }
+
  if (!driDrawPriv || !driReadPriv)
      return GL_FALSE;


More information about the mesa-dev mailing list