[PATCH 16/19] Xephyr: move glx code to xcb

Julien Cristau jcristau at debian.org
Wed Aug 28 07:27:56 PDT 2013


On Mon, Aug 26, 2013 at 13:21:00 -0700, Eric Anholt wrote:

> @@ -560,81 +366,70 @@ Bool
>  ephyrHostGLXMakeCurrent(int a_drawable, int a_readable,
>                          int a_glx_ctxt_id, int a_old_ctxt_tag, int *a_ctxt_tag)
>  {
> +    xcb_connection_t *conn = hostx_get_xcbconn();
>      Bool is_ok = FALSE;
> -    Display *dpy = hostx_get_display();
> -    int32_t major_opcode = 0;
>      int remote_glx_ctxt_id = 0;
> -    xGLXMakeCurrentReply reply;
>  
>      EPHYR_RETURN_VAL_IF_FAIL(a_ctxt_tag, FALSE);
>  
>      EPHYR_LOG("enter. drawable:%d, read:%d, context:%d, oldtag:%d\n",
>                a_drawable, a_readable, a_glx_ctxt_id, a_old_ctxt_tag);
>  
> -    if (!ephyrHostGLXGetMajorOpcode(&major_opcode)) {
> -        EPHYR_LOG_ERROR("failed to get major opcode\n");
> -        goto out;
> -    }
>      if (!hostx_get_resource_id_peer(a_glx_ctxt_id, &remote_glx_ctxt_id)) {
>          EPHYR_LOG_ERROR("failed to get remote glx ctxt id\n");
>          goto out;
>      }
>  
> -    LockDisplay(dpy);
> -
>      /* If both drawables are the same, use the old MakeCurrent request.
>       * Otherwise, if we have GLX 1.3 or higher, use the MakeContextCurrent
>       * request which supports separate read and draw targets.  Failing that,
>       * try the SGI MakeCurrentRead extension.  Logic cribbed from Mesa. */
>      if (a_drawable == a_readable) {
> -        xGLXMakeCurrentReq *req;
> -
> -        GetReq(GLXMakeCurrent, req);
> -        req->reqType = major_opcode;
> -        req->glxCode = X_GLXMakeCurrent;
> -        req->drawable = a_drawable;
> -        req->context = remote_glx_ctxt_id;
> -        req->oldContextTag = a_old_ctxt_tag;
> +        xcb_glx_make_current_cookie_t cookie;
> +        xcb_glx_make_current_reply_t *reply;
> +        cookie = xcb_glx_make_current(conn,
> +                                      a_drawable,
> +                                      remote_glx_ctxt_id,
> +                                      a_old_ctxt_tag);
> +        reply = xcb_glx_make_current_reply(conn, cookie, NULL);
> +        if (!reply)
> +            goto out;
> +        *a_ctxt_tag = reply->context_tag;
> +        free(reply);
>      }
>      else if (glx_major > 1 || glx_minor >= 3) {
> -        xGLXMakeContextCurrentReq *req;
> -
> -        GetReq(GLXMakeContextCurrent, req);
> -        req->reqType = major_opcode;
> -        req->glxCode = X_GLXMakeContextCurrent;
> -        req->drawable = a_drawable;
> -        req->readdrawable = a_readable;
> -        req->context = remote_glx_ctxt_id;
> -        req->oldContextTag = a_old_ctxt_tag;
> +        xcb_glx_make_context_current_cookie_t cookie;
> +        xcb_glx_make_context_current_reply_t *reply;
> +        cookie = xcb_glx_make_context_current(conn,
> +                                              a_old_ctxt_tag,
> +                                              a_drawable,
> +                                              a_readable,
> +                                              remote_glx_ctxt_id);
> +        reply = xcb_glx_make_context_current_reply(conn, cookie, NULL);
> +        if (!reply)
> +            goto out;
> +        *a_ctxt_tag = reply->context_tag;
> +        free(reply);
>      }
>      else {
> -        xGLXVendorPrivateWithReplyReq *vpreq;
> -        xGLXMakeCurrentReadSGIReq *req;
> -
> -        GetReqExtra(GLXVendorPrivateWithReply,
> -                    (sz_xGLXMakeCurrentReadSGIReq -
> -                     sz_xGLXVendorPrivateWithReplyReq),
> -                    vpreq);
> -        req = (xGLXMakeCurrentReadSGIReq *) vpreq;
> -        req->reqType = major_opcode;
> -        req->glxCode = X_GLXVendorPrivateWithReply;
> -        req->vendorCode = X_GLXvop_MakeCurrentReadSGI;
> -        req->drawable = a_drawable;
> -        req->readable = a_readable;
> -        req->context = remote_glx_ctxt_id;
> -        req->oldContextTag = a_old_ctxt_tag;
> -    }
> +        xcb_glx_vendor_private_with_reply_cookie_t cookie;
> +        xcb_glx_vendor_private_with_reply_reply_t *reply;
> +        uint32_t data[3] = {
> +            a_drawable, a_readable, remote_glx_ctxt_id,
> +        };
>  
> -    memset(&reply, 0, sizeof(reply));
> -    if (!_XReply(dpy, (xReply *) &reply, 0, False)) {
> -        EPHYR_LOG_ERROR("failed to get reply from host\n");
> -        UnlockDisplay(dpy);
> -        SyncHandle();
> -        goto out;
> +        EPHYR_LOG("enter\n");
> +        cookie = xcb_glx_vendor_private_with_reply(conn,
> +                                                   X_GLXvop_MakeCurrentReadSGI,
> +                                                   a_old_ctxt_tag,
> +                                                   sizeof(data),
> +                                                   (uint8_t *)data);
> +        reply = xcb_glx_vendor_private_with_reply_reply(conn, cookie, NULL);
> +        free(reply);
> +
> +        *a_ctxt_tag = reply->retval;

Use after free.

>      }
> -    UnlockDisplay(dpy);
> -    SyncHandle();
> -    *a_ctxt_tag = reply.contextTag;
> +
>      EPHYR_LOG("context tag:%d\n", *a_ctxt_tag);
>      is_ok = TRUE;
>  
Cheers,
Julien


More information about the xorg-devel mailing list