Пример #1
0
/*
** Make a context the current one for the GL (in this implementation, there
** is only one instance of the GL, and we use it to serve all GL clients by
** switching it between different contexts).  While we are at it, look up
** a context by its tag and return its (__GLXcontext *).
*/
__GLXcontext *
__glXForceCurrent(__GLXclientState * cl, GLXContextTag tag, int *error)
{
    __GLXcontext *cx;

    /*
     ** See if the context tag is legal; it is managed by the extension,
     ** so if it's invalid, we have an implementation error.
     */
    cx = __glXLookupContextByTag(cl, tag);
    if (!cx) {
        cl->client->errorValue = tag;
        *error = __glXError(GLXBadContextTag);
        return 0;
    }

    if (!cx->isDirect) {
        if (cx->drawPriv == NULL) {
            /*
             ** The drawable has vanished.  It must be a window, because only
             ** windows can be destroyed from under us; GLX pixmaps are
             ** refcounted and don't go away until no one is using them.
             */
            *error = __glXError(GLXBadCurrentWindow);
            return 0;
        }
    }

    if (cx->wait && (*cx->wait) (cx, cl, error))
        return NULL;

    if (cx == __glXLastContext && GET_DISPATCH()) {
        /* No need to re-bind */
        return cx;
    }

    /* Make this context the current one for the GL. */
    if (!cx->isDirect) {
        if (!(*cx->makeCurrent) (cx)) {
            /* Bind failed, and set the error code.  Bummer */
            cl->client->errorValue = cx->id;
            *error = __glXError(GLXBadContextState);
            return 0;
        }
    }
    __glXLastContext = cx;
    return cx;
}
Пример #2
0
int __glXDispSwap_VendorPrivate(__GLXclientState *cl, GLbyte *pc)
{
    xGLXVendorPrivateReq *req;
    GLint vendorcode;
    __GLXdispatchVendorPrivProcPtr proc;

    __GLX_DECLARE_SWAP_VARIABLES;

    req = (xGLXVendorPrivateReq *) pc;
    __GLX_SWAP_SHORT(&req->length);
    __GLX_SWAP_INT(&req->vendorCode);

    vendorcode = req->vendorCode;

    proc = (__GLXdispatchVendorPrivProcPtr)
      __glXGetProtocolDecodeFunction(& VendorPriv_dispatch_info,
				     vendorcode, 1);
    if (proc != NULL) {
	(*proc)(cl, (GLbyte*)req);
	return Success;
    }

    cl->client->errorValue = req->vendorCode;
    return __glXError(GLXUnsupportedPrivateRequest);
}
Пример #3
0
int
DoSwapInterval(__GLXclientState * cl, GLbyte * pc, int do_swap)
{
    xGLXVendorPrivateReq *const req = (xGLXVendorPrivateReq *) pc;
    ClientPtr client = cl->client;
    const GLXContextTag tag = req->contextTag;
    __GLXcontext *cx;
    GLint interval;

    REQUEST_FIXED_SIZE(xGLXVendorPrivateReq, 4);

    cx = __glXLookupContextByTag(cl, tag);

    if ((cx == NULL) || (cx->pGlxScreen == NULL)) {
        client->errorValue = tag;
        return __glXError(GLXBadContext);
    }

    if (cx->pGlxScreen->swapInterval == NULL) {
        LogMessage(X_ERROR, "AIGLX: cx->pGlxScreen->swapInterval == NULL\n");
        client->errorValue = tag;
        return __glXError(GLXUnsupportedPrivateRequest);
    }

    if (cx->drawPriv == NULL) {
        client->errorValue = tag;
        return BadValue;
    }

    pc += __GLX_VENDPRIV_HDR_SIZE;
    interval = (do_swap)
               ? bswap_32(*(int *) (pc + 0))
               : *(int *) (pc + 0);

    if (interval <= 0)
        return BadValue;

    (void) (*cx->pGlxScreen->swapInterval) (cx->drawPriv, interval);
    return Success;
}
Пример #4
0
/*
** Top level dispatcher; all commands are executed from here down.
*/
static int
__glXDispatch(ClientPtr client)
{
    REQUEST(xGLXSingleReq);
    CARD8 opcode;
    __GLXdispatchSingleProcPtr proc;
    __GLXclientState *cl;
    int retval;

    opcode = stuff->glxCode;
    cl = glxGetClient(client);
    /* Mark it in use so we suspend it on VT switch. */
    cl->inUse = TRUE;

    /*
     ** If we're expecting a glXRenderLarge request, this better be one.
     */
    if ((cl->largeCmdRequestsSoFar != 0) && (opcode != X_GLXRenderLarge)) {
        client->errorValue = stuff->glxCode;
        return __glXError(GLXBadLargeRequest);
    }

    /* If we're currently blocking GLX clients, just put this guy to
     * sleep, reset the request and return. */
    if (glxBlockClients) {
        ResetCurrentRequest(client);
        client->sequence--;
        IgnoreClient(client);
        return Success;
    }

    /*
     ** Use the opcode to index into the procedure table.
     */
    proc = __glXGetProtocolDecodeFunction(&Single_dispatch_info, opcode,
                                          client->swapped);
    if (proc != NULL) {
        GLboolean rendering = opcode <= X_GLXRenderLarge;

        __glXleaveServer(rendering);

        retval = (*proc) (cl, (GLbyte *) stuff);

        __glXenterServer(rendering);
    }
    else {
        retval = BadRequest;
    }

    return retval;
}
Пример #5
0
int __glXDisp_UseXFont(__GLXclientState *cl, GLbyte *pc)
{
    ClientPtr client = cl->client;
    xGLXUseXFontReq *req;
    FontPtr pFont;
    GC *pGC;
    GLuint currentListIndex;
    __GLXcontext *cx;
    int error;

    req = (xGLXUseXFontReq *) pc;
    cx = __glXForceCurrent(cl, req->contextTag, &error);
    if (!cx) {
	return error;
    }

    CALL_GetIntegerv( GET_DISPATCH(), (GL_LIST_INDEX, (GLint*) &currentListIndex) );
    if (currentListIndex != 0) {
	/*
	** A display list is currently being made.  It is an error
	** to try to make a font during another lists construction.
	*/
	client->errorValue = cx->id;
	return __glXError(GLXBadContextState);
    }

    /*
    ** Font can actually be either the ID of a font or the ID of a GC
    ** containing a font.
    */

    error = dixLookupResourceByType((pointer *)&pFont,
				    req->font, RT_FONT,
				    client, DixReadAccess);
    if (error != Success) {
	error = dixLookupResourceByType((pointer *)&pGC,
					req->font, RT_GC,
					client, DixReadAccess);
        if (error != Success) {
	    client->errorValue = req->font;
            return error == BadGC ? BadFont : error;
	}
	pFont = pGC->font;
    }

    return MakeBitmapsFromFont(pFont, req->first, req->count,
				    req->listBase);
}
Пример #6
0
int
__glXDisp_CreateContextAttribsARB(__GLXclientState * cl, GLbyte * pc)
{
    ClientPtr client = cl->client;
    xGLXCreateContextAttribsARBReq *req = (xGLXCreateContextAttribsARBReq *) pc;
    int32_t *attribs = (req->numAttribs != 0) ? (int32_t *) (req + 1) : NULL;
    unsigned i;
    int major_version = 1;
    int minor_version = 0;
    uint32_t flags = 0;
    uint32_t render_type = GLX_RGBA_TYPE;
    __GLXcontext *ctx = NULL;
    __GLXcontext *shareCtx = NULL;
    __GLXscreen *glxScreen;
    __GLXconfig *config;
    int err;

    /* The GLX_ARB_create_context_robustness spec says:
     *
     *     "The default value for GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB
     *     is GLX_NO_RESET_NOTIFICATION_ARB."
     */
    int reset = GLX_NO_RESET_NOTIFICATION_ARB;

    /* The GLX_ARB_create_context_profile spec says:
     *
     *     "The default value for GLX_CONTEXT_PROFILE_MASK_ARB is
     *     GLX_CONTEXT_CORE_PROFILE_BIT_ARB."
     *
     * The core profile only makes sense for OpenGL versions 3.2 and later.
     * If the version ultimately specified is less than 3.2, the core profile
     * bit is cleared (see below).
     */
    int profile = GLX_CONTEXT_CORE_PROFILE_BIT_ARB;

    /* Verify that the size of the packet matches the size inferred from the
     * sizes specified for the various fields.
     */
    const unsigned expected_size = (sz_xGLXCreateContextAttribsARBReq
                                    + (req->numAttribs * 8)) / 4;

    if (req->length != expected_size)
        return BadLength;

    LEGAL_NEW_RESOURCE(req->context, client);

    /* The GLX_ARB_create_context spec says:
     *
     *     "* If <config> is not a valid GLXFBConfig, GLXBadFBConfig is
     *        generated."
     *
     * On the client, the screen comes from the FBConfig, so GLXBadFBConfig
     * should be issued if the screen is nonsense.
     */
    if (!validGlxScreen(client, req->screen, &glxScreen, &err))
        return __glXError(GLXBadFBConfig);

    if (!validGlxFBConfig(client, glxScreen, req->fbconfig, &config, &err))
        return __glXError(GLXBadFBConfig);

    /* Validate the context with which the new context should share resources.
     */
    if (req->shareList != None) {
        if (!validGlxContext(client, req->shareList, DixReadAccess,
                             &shareCtx, &err))
            return err;

        /* The crazy condition is because C doesn't have a logical XOR
         * operator.  Comparing directly for equality may fail if one is 1 and
         * the other is 2 even though both are logically true.
         */
        if (!!req->isDirect != !!shareCtx->isDirect) {
            client->errorValue = req->shareList;
            return BadMatch;
        }

        /* The GLX_ARB_create_context spec says:
         *
         *     "* If the server context state for <share_context>...was
         *        created on a different screen than the one referenced by
         *        <config>...BadMatch is generated."
         */
        if (glxScreen != shareCtx->pGlxScreen) {
            client->errorValue = shareCtx->pGlxScreen->pScreen->myNum;
            return BadMatch;
        }
    }

    for (i = 0; i < req->numAttribs; i++) {
        switch (attribs[i * 2]) {
        case GLX_CONTEXT_MAJOR_VERSION_ARB:
            major_version = attribs[2 * i + 1];
            break;

        case GLX_CONTEXT_MINOR_VERSION_ARB:
            minor_version = attribs[2 * i + 1];
            break;

        case GLX_CONTEXT_FLAGS_ARB:
            flags = attribs[2 * i + 1];
            break;

        case GLX_RENDER_TYPE:
            render_type = attribs[2 * i + 1];
            break;

        case GLX_CONTEXT_PROFILE_MASK_ARB:
            profile = attribs[2 * i + 1];
            break;

        case GLX_CONTEXT_RESET_NOTIFICATION_STRATEGY_ARB:
            reset = attribs[2 * i + 1];
            if (reset != GLX_NO_RESET_NOTIFICATION_ARB
                && reset != GLX_LOSE_CONTEXT_ON_RESET_ARB)
                return BadValue;

            break;

        default:
            return BadValue;
        }
    }

    /* The GLX_ARB_create_context spec says:
     *
     *     "If attributes GLX_CONTEXT_MAJOR_VERSION_ARB and
     *     GLX_CONTEXT_MINOR_VERSION_ARB, when considered together
     *     with attributes GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB and
     *     GLX_RENDER_TYPE, specify an OpenGL version and feature set
     *     that are not defined, BadMatch is generated.
     *
     *     ...Feature deprecation was introduced with OpenGL 3.0, so
     *     forward-compatible contexts may only be requested for
     *     OpenGL 3.0 and above. Thus, examples of invalid
     *     combinations of attributes include:
     *
     *       - Major version < 1 or > 3
     *       - Major version == 1 and minor version < 0 or > 5
     *       - Major version == 2 and minor version < 0 or > 1
     *       - Major version == 3 and minor version > 2
     *       - Forward-compatible flag set and major version < 3
     *       - Color index rendering and major version >= 3"
     */
    if (!validate_GL_version(major_version, minor_version))
        return BadMatch;

    if (major_version < 3
        && ((flags & GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB) != 0))
        return BadMatch;

    if (major_version >= 3 && render_type == GLX_COLOR_INDEX_TYPE)
        return BadMatch;

    if (!validate_render_type(render_type))
        return BadValue;

    if ((flags & ~ALL_VALID_FLAGS) != 0)
        return BadValue;

    /* The GLX_ARB_create_context_profile spec says:
     *
     *     "* If attribute GLX_CONTEXT_PROFILE_MASK_ARB has no bits set; has
     *        any bits set other than GLX_CONTEXT_CORE_PROFILE_BIT_ARB and
     *        GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB; has more than one of
     *        these bits set; or if the implementation does not support the
     *        requested profile, then GLXBadProfileARB is generated."
     */
    switch (profile) {
    case GLX_CONTEXT_CORE_PROFILE_BIT_ARB:
    case GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB:
        break;
    case GLX_CONTEXT_ES2_PROFILE_BIT_EXT:
        /* The GLX_EXT_create_context_es2_profile spec says:
         *
         *     "... If the version requested is 2.0, and the
         *     GLX_CONTEXT_ES2_PROFILE_BIT_EXT bit is set in the
         *     GLX_CONTEXT_PROFILE_MASK_ARB attribute (see below), then the
         *     context returned will implement OpenGL ES 2.0."
         *
         * It also says:
         *
         *     "* If attribute GLX_CONTEXT_PROFILE_MASK_ARB has no bits set;
         *        has any bits set other than
         *        GLX_CONTEXT_CORE_PROFILE_BIT_ARB,
         *        GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, or
         *        GLX_CONTEXT_ES2_PROFILE_BIT_EXT; has more than one of these
         *        bits set; or if the implementation does not supported the
         *        requested profile, then GLXBadProfileARB is generated."
         *
         * It does not specifically say what is supposed to happen if
         * GLX_CONTEXT_ES2_PROFILE_BIT_EXT is set but the version requested is
         * not 2.0.  We choose to generate GLXBadProfileARB as this matches
         * NVIDIA's behavior.
         */
        if (major_version != 2 || minor_version != 0)
            return __glXError(GLXBadProfileARB);
        break;
    default:
        return __glXError(GLXBadProfileARB);
    }

    /* The GLX_ARB_create_context_robustness spec says:
     *
     *     "* If the reset notification behavior of <share_context> and the
     *        newly created context are different, BadMatch is generated."
     */
    if (shareCtx != NULL && shareCtx->resetNotificationStrategy != reset)
        return BadMatch;

    /* There is no GLX protocol for desktop OpenGL versions after 1.4.  There
     * is no GLX protocol for any version of OpenGL ES.  If the application is
     * requested an indirect rendering context for a version that cannot be
     * satisfied, reject it.
     *
     * The GLX_ARB_create_context spec says:
     *
     *     "* If <config> does not support compatible OpenGL contexts
     *        providing the requested API major and minor version,
     *        forward-compatible flag, and debug context flag, GLXBadFBConfig
     *        is generated."
     */
    if (!req->isDirect && (major_version > 1 || minor_version > 4
                           || profile == GLX_CONTEXT_ES2_PROFILE_BIT_EXT)) {
        return __glXError(GLXBadFBConfig);
    }

    /* Allocate memory for the new context
     */
    if (req->isDirect) {
        ctx = __glXdirectContextCreate(glxScreen, config, shareCtx);
        err = BadAlloc;
    }
    else {
        ctx = glxScreen->createContext(glxScreen, config, shareCtx,
                                       req->numAttribs, (uint32_t *) attribs,
                                       &err);
    }

    if (ctx == NULL)
        return err;

    ctx->pGlxScreen = glxScreen;
    ctx->config = config;
    ctx->id = req->context;
    ctx->share_id = req->shareList;
    ctx->idExists = True;
    ctx->isCurrent = False;
    ctx->isDirect = req->isDirect;
    ctx->hasUnflushedCommands = False;
    ctx->renderMode = GL_RENDER;
    ctx->feedbackBuf = NULL;
    ctx->feedbackBufSize = 0;
    ctx->selectBuf = NULL;
    ctx->selectBufSize = 0;
    ctx->drawPriv = NULL;
    ctx->readPriv = NULL;
    ctx->resetNotificationStrategy = reset;

    /* Add the new context to the various global tables of GLX contexts.
     */
    if (!__glXAddContext(ctx)) {
        (*ctx->destroy) (ctx);
        client->errorValue = req->context;
        return BadAlloc;
    }

    return Success;
}