[Mesa-dev] [PATCH 1/3] egl_dri2: Move filling context_attrib array in a separate function

Marek Olšák maraeo at gmail.com
Sun Jun 21 09:37:32 PDT 2015


"bool" as the return type of the new function would be more
appropriate. Other than that:

Reviewed-by: Marek Olšák <marek.olsak at amd.com>

Marek



On Sun, Jun 21, 2015 at 5:06 PM, Boyan Ding <boyan.j.ding at gmail.com> wrote:
> Signed-off-by: Boyan Ding <boyan.j.ding at gmail.com>
> ---
>  src/egl/drivers/dri2/egl_dri2.c | 89 ++++++++++++++++++++++++-----------------
>  1 file changed, 53 insertions(+), 36 deletions(-)
>
> diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
> index e590db6..c2a857f 100644
> --- a/src/egl/drivers/dri2/egl_dri2.c
> +++ b/src/egl/drivers/dri2/egl_dri2.c
> @@ -831,6 +831,55 @@ dri2_create_context_attribs_error(int dri_error)
>     _eglError(egl_error, "dri2_create_context");
>  }
>
> +static int
> +dri2_fill_context_attribs(struct dri2_egl_context *dri2_ctx,
> +                          struct dri2_egl_display *dri2_dpy,
> +                          uint32_t *ctx_attribs,
> +                          unsigned *num_attribs)
> +{
> +   int pos = 0;
> +
> +   assert(*num_attribs >= 8);
> +
> +   ctx_attribs[pos++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
> +   ctx_attribs[pos++] = dri2_ctx->base.ClientMajorVersion;
> +   ctx_attribs[pos++] = __DRI_CTX_ATTRIB_MINOR_VERSION;
> +   ctx_attribs[pos++] = dri2_ctx->base.ClientMinorVersion;
> +
> +   if (dri2_ctx->base.Flags != 0) {
> +      /* If the implementation doesn't support the __DRI2_ROBUSTNESS
> +       * extension, don't even try to send it the robust-access flag.
> +       * It may explode.  Instead, generate the required EGL error here.
> +       */
> +      if ((dri2_ctx->base.Flags & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) != 0
> +            && !dri2_dpy->robustness) {
> +         _eglError(EGL_BAD_MATCH, "eglCreateContext");
> +         return -1;
> +      }
> +
> +      ctx_attribs[pos++] = __DRI_CTX_ATTRIB_FLAGS;
> +      ctx_attribs[pos++] = dri2_ctx->base.Flags;
> +   }
> +
> +   if (dri2_ctx->base.ResetNotificationStrategy != EGL_NO_RESET_NOTIFICATION_KHR) {
> +      /* If the implementation doesn't support the __DRI2_ROBUSTNESS
> +       * extension, don't even try to send it a reset strategy.  It may
> +       * explode.  Instead, generate the required EGL error here.
> +       */
> +      if (!dri2_dpy->robustness) {
> +         _eglError(EGL_BAD_CONFIG, "eglCreateContext");
> +         return -1;
> +      }
> +
> +      ctx_attribs[pos++] = __DRI_CTX_ATTRIB_RESET_STRATEGY;
> +      ctx_attribs[pos++] = __DRI_CTX_RESET_LOSE_CONTEXT;
> +   }
> +
> +   *num_attribs = pos;
> +
> +   return 0;
> +}
> +
>  /**
>   * Called via eglCreateContext(), drv->API.CreateContext().
>   */
> @@ -916,44 +965,12 @@ dri2_create_context(_EGLDriver *drv, _EGLDisplay *disp, _EGLConfig *conf,
>     if (dri2_dpy->dri2) {
>        if (dri2_dpy->dri2->base.version >= 3) {
>           unsigned error;
> -         unsigned num_attribs = 0;
> +         unsigned num_attribs = 8;
>           uint32_t ctx_attribs[8];
>
> -         ctx_attribs[num_attribs++] = __DRI_CTX_ATTRIB_MAJOR_VERSION;
> -         ctx_attribs[num_attribs++] = dri2_ctx->base.ClientMajorVersion;
> -         ctx_attribs[num_attribs++] = __DRI_CTX_ATTRIB_MINOR_VERSION;
> -         ctx_attribs[num_attribs++] = dri2_ctx->base.ClientMinorVersion;
> -
> -         if (dri2_ctx->base.Flags != 0) {
> -            /* If the implementation doesn't support the __DRI2_ROBUSTNESS
> -             * extension, don't even try to send it the robust-access flag.
> -             * It may explode.  Instead, generate the required EGL error here.
> -             */
> -            if ((dri2_ctx->base.Flags & EGL_CONTEXT_OPENGL_ROBUST_ACCESS_BIT_KHR) != 0
> -                && !dri2_dpy->robustness) {
> -               _eglError(EGL_BAD_MATCH, "eglCreateContext");
> -               goto cleanup;
> -            }
> -
> -            ctx_attribs[num_attribs++] = __DRI_CTX_ATTRIB_FLAGS;
> -            ctx_attribs[num_attribs++] = dri2_ctx->base.Flags;
> -         }
> -
> -         if (dri2_ctx->base.ResetNotificationStrategy != EGL_NO_RESET_NOTIFICATION_KHR) {
> -            /* If the implementation doesn't support the __DRI2_ROBUSTNESS
> -             * extension, don't even try to send it a reset strategy.  It may
> -             * explode.  Instead, generate the required EGL error here.
> -             */
> -            if (!dri2_dpy->robustness) {
> -               _eglError(EGL_BAD_CONFIG, "eglCreateContext");
> -               goto cleanup;
> -            }
> -
> -            ctx_attribs[num_attribs++] = __DRI_CTX_ATTRIB_RESET_STRATEGY;
> -            ctx_attribs[num_attribs++] = __DRI_CTX_RESET_LOSE_CONTEXT;
> -         }
> -
> -         assert(num_attribs <= ARRAY_SIZE(ctx_attribs));
> +         if (dri2_fill_context_attribs(dri2_ctx, dri2_dpy, ctx_attribs,
> +                                       &num_attribs))
> +            goto cleanup;
>
>          dri2_ctx->dri_context =
>             dri2_dpy->dri2->createContextAttribs(dri2_dpy->dri_screen,
> --
> 2.4.1
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list