src/GLdispatch/GLdispatch.c
static int PatchEntrypoints(
   const __GLdispatchPatchCallbacks *patchCb,
   int vendorID
)
{
    __GLdispatchStubCallback *stub;
    CheckDispatchLocked();

    if (!PatchingIsSafe()) {
        return 0;
    }

    if (patchCb == stubCurrentPatchCb) {
        // Entrypoints already using the requested patch; no need to do anything
        return 1;
    }

    if (stubCurrentPatchCb) {
        // Notify the previous vendor that it no longer owns these
        // entrypoints.
        if (stubCurrentPatchCb->releasePatch != NULL) {
            stubCurrentPatchCb->releasePatch();
        }
    }

    if (patchCb) {
        GLboolean anySuccess = GL_FALSE;

        glvnd_list_for_each_entry(stub, &dispatchStubList, entry) {
            if (patchCb->isPatchSupported(stub->callbacks.getStubType(),
                        stub->callbacks.getStubSize()))
            {
                if (stub->callbacks.startPatch()) {
                    if (patchCb->initiatePatch(stub->callbacks.getStubType(),
                                stub->callbacks.getStubSize(),
                                stub->callbacks.getPatchOffset)) {
                        stub->callbacks.finishPatch();
                        stub->isPatched = GL_TRUE;
                        anySuccess = GL_TRUE;
                    } else {
                        stub->callbacks.abortPatch();
                        stub->isPatched = GL_FALSE;
                    }
                }
            } else if (stub->isPatched) {
                // The vendor library can't patch these stubs, but they were
                // patched before. Restore them now.
                stub->callbacks.restoreFuncs();
                stub->isPatched = GL_FALSE;
            }
        }

        if (anySuccess) {
            stubCurrentPatchCb = patchCb;
            stubOwnerVendorID = vendorID;
        } else {
            stubCurrentPatchCb = NULL;
            stubOwnerVendorID = 0;
        }
    } else {
        // Restore the stubs to the default implementation
        glvnd_list_for_each_entry(stub, &dispatchStubList, entry) {
            if (stub->isPatched) {
                stub->callbacks.restoreFuncs();
                stub->isPatched = GL_FALSE;
            }
        }

        stubCurrentPatchCb = NULL;
        stubOwnerVendorID = 0;
    }

    return 1;
}
/*
 * Attempt to patch entrypoints with the given patch function and vendor ID.
 * If the function pointers are NULL, then this attempts to restore the default
 * libglvnd entrypoints.
 *
 * Returns 1 on success, 0 on failure.
 */
Attempt to patch entrypoints with the given patch function and vendor ID.
If the function pointers are NULL, then this attempts to restore the default
libglvnd entrypoints.

Returns 1 on success, 0 on failure.
Attempt to patch entrypoints with the given patch function and vendor ID . If the function pointers are NULL then this attempts to restore the default libglvnd entrypoints . Returns 1 on success 0 on failure .
static int PatchEntrypoints(
   const __GLdispatchPatchCallbacks *patchCb,
   int vendorID
)
{
    __GLdispatchStubCallback *stub;
    CheckDispatchLocked();
    if (!PatchingIsSafe()) {
        return 0;
    }
    if (patchCb == stubCurrentPatchCb) {
        return 1;
    }
    if (stubCurrentPatchCb) {
        if (stubCurrentPatchCb->releasePatch != NULL) {
            stubCurrentPatchCb->releasePatch();
        }
    }
    if (patchCb) {
        GLboolean anySuccess = GL_FALSE;
        glvnd_list_for_each_entry(stub, &dispatchStubList, entry) {
            if (patchCb->isPatchSupported(stub->callbacks.getStubType(),
                        stub->callbacks.getStubSize()))
            {
                if (stub->callbacks.startPatch()) {
                    if (patchCb->initiatePatch(stub->callbacks.getStubType(),
                                stub->callbacks.getStubSize(),
                                stub->callbacks.getPatchOffset)) {
                        stub->callbacks.finishPatch();
                        stub->isPatched = GL_TRUE;
                        anySuccess = GL_TRUE;
                    } else {
                        stub->callbacks.abortPatch();
                        stub->isPatched = GL_FALSE;
                    }
                }
            } else if (stub->isPatched) {
                stub->callbacks.restoreFuncs();
                stub->isPatched = GL_FALSE;
            }
        }
        if (anySuccess) {
            stubCurrentPatchCb = patchCb;
            stubOwnerVendorID = vendorID;
        } else {
            stubCurrentPatchCb = NULL;
            stubOwnerVendorID = 0;
        }
    } else {
        glvnd_list_for_each_entry(stub, &dispatchStubList, entry) {
            if (stub->isPatched) {
                stub->callbacks.restoreFuncs();
                stub->isPatched = GL_FALSE;
            }
        }
        stubCurrentPatchCb = NULL;
        stubOwnerVendorID = 0;
    }
    return 1;
}
static int PatchEntrypoints ( const __GLdispatchPatchCallbacks * patchCb , int vendorID ) { __GLdispatchStubCallback * stub ; CheckDispatchLocked ( ) ; if ( ! PatchingIsSafe ( ) ) { return 0 ; } if ( patchCb == stubCurrentPatchCb ) { return 1 ; } if ( stubCurrentPatchCb ) { if ( stubCurrentPatchCb -> releasePatch != NULL ) { stubCurrentPatchCb -> releasePatch ( ) ; } } if ( patchCb ) { GLboolean anySuccess = GL_FALSE ; glvnd_list_for_each_entry ( stub , & dispatchStubList , entry ) { if ( patchCb -> isPatchSupported ( stub -> callbacks . getStubType ( ) , stub -> callbacks . getStubSize ( ) ) ) { if ( stub -> callbacks . startPatch ( ) ) { if ( patchCb -> initiatePatch ( stub -> callbacks . getStubType ( ) , stub -> callbacks . getStubSize ( ) , stub -> callbacks . getPatchOffset ) ) { stub -> callbacks . finishPatch ( ) ; stub -> isPatched = GL_TRUE ; anySuccess = GL_TRUE ; } else { stub -> callbacks . abortPatch ( ) ; stub -> isPatched = GL_FALSE ; } } } else if ( stub -> isPatched ) { stub -> callbacks . restoreFuncs ( ) ; stub -> isPatched = GL_FALSE ; } } if ( anySuccess ) { stubCurrentPatchCb = patchCb ; stubOwnerVendorID = vendorID ; } else { stubCurrentPatchCb = NULL ; stubOwnerVendorID = 0 ; } } else { glvnd_list_for_each_entry ( stub , & dispatchStubList , entry ) { if ( stub -> isPatched ) { stub -> callbacks . restoreFuncs ( ) ; stub -> isPatched = GL_FALSE ; } } stubCurrentPatchCb = NULL ; stubOwnerVendorID = 0 ; } return 1 ; }
Attempt to patch entrypoints with the given patch function and vendor ID.
Attempt to patch entrypoints with the given patch function and vendor ID .
// Entrypoints already using the requested patch; no need to do anything // Notify the previous vendor that it no longer owns these // entrypoints. // The vendor library can't patch these stubs, but they were // patched before. Restore them now. // Restore the stubs to the default implementation