Skip to content

Commit

Permalink
Add context, dispatch parameters to __glDispatchMakeCurrent()
Browse files Browse the repository at this point in the history
When making current, assign the API state's new context and dispatch table
in GLdispatch rather than GLX.  This avoids consistency issues if the API state
is unchanged but the current dispatch or context may have changed.

Update the __glDispatchMakeCurrent() call in
__glXMakeGLDispatchCurrent() to get libglvnd building for now; a later change
will remove libglxgldispatch.c altogether.

Signed-off-by: Brian Nguyen <[email protected]>
  • Loading branch information
brnguyen2 committed Nov 25, 2013
1 parent e480788 commit 4628149
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 31 deletions.
21 changes: 9 additions & 12 deletions src/GLX/libglx.c
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ static Bool MakeContextCurrentInternal(Display *dpy,
return False;
}

/*
* Call into GLdispatch to lose current and update the context and GL
* dispatch table
*/
__glDispatchLoseCurrent();

/* Update the current display and drawable(s) in this apiState */
Expand All @@ -266,11 +270,6 @@ static Bool MakeContextCurrentInternal(Display *dpy,
apiState->currentStaticDispatch = NULL;
apiState->currentDynDispatch = NULL;

/* Update the GL dispatch table */
apiState->glas.dispatch = NULL;

/* Update the current context */
apiState->glas.context = NULL;
return True;
} else {
/* Update the current display and drawable(s) in this apiState */
Expand All @@ -283,13 +282,8 @@ static Bool MakeContextCurrentInternal(Display *dpy,
apiState->currentStaticDispatch = *ppDispatch;
apiState->currentDynDispatch = newVendor->dynDispatch;

/* Update the GL dispatch table */
apiState->glas.dispatch = newVendor->glDispatch;

DBG_PRINTF(0, "GL dispatch = %p\n", apiState->glas.dispatch);

/* Update the current context */
apiState->glas.context = context;

/*
* XXX It is possible that these drawables were never seen by
Expand All @@ -302,9 +296,12 @@ static Bool MakeContextCurrentInternal(Display *dpy,
__glXAddScreenDrawableMapping(read, screen);

/*
* Call into GLdispatch to set up the current state.
* Call into GLdispatch to set up the current context and
* GL dispatch table.
*/
__glDispatchMakeCurrent(&apiState->glas);
__glDispatchMakeCurrent(&apiState->glas,
newVendor->glDispatch,
(void *)context);
}

return True;
Expand Down
4 changes: 3 additions & 1 deletion src/GLX/libglxgldispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ void __glXMakeGLDispatchCurrent(__GLXcoreDispatchTable *table)

if (apiState) {
apiState->glas.dispatch = (__GLdispatchTable *)table;
__glDispatchMakeCurrent(&apiState->glas);
__glDispatchMakeCurrent(&apiState->glas,
apiState->glas.dispatch,
apiState->glas.context);
}
}

Expand Down
31 changes: 16 additions & 15 deletions src/GLdispatch/GLdispatch.c
Original file line number Diff line number Diff line change
Expand Up @@ -362,18 +362,18 @@ static struct _glapi_table
return table;
}

PUBLIC void __glDispatchMakeCurrent(__GLdispatchAPIState *apiState)
PUBLIC void __glDispatchMakeCurrent(__GLdispatchAPIState *apiState,
__GLdispatchTable *dispatch,
void *context)
{
__GLdispatchAPIState *curApiState = (__GLdispatchAPIState *)
_glapi_get_current(CURRENT_API_STATE);
__GLdispatchTable *dispatch = apiState->dispatch;
__GLdispatchTable *curDispatch = curApiState ? curApiState->dispatch : NULL;

// We need to fix up the dispatch table if it hasn't been
// initialized, or there are new dynamic entries which were
// added since the last time make current was called.
LockDispatch();
DBG_PRINTF(20, "dispatch=%p\n", dispatch);

if (!dispatch->table ||
(dispatch->generation < latestGeneration)) {
Expand All @@ -394,33 +394,34 @@ PUBLIC void __glDispatchMakeCurrent(__GLdispatchAPIState *apiState)
DispatchCurrentRef(dispatch);
}

UnlockDispatch();

/*
* Set the current __GLdispatchTable and _glapi_table in TLS
* we have to keep the dispatch lock until the _glapi_table
* is set.
* XXX: this would be cleaner if this used
* _glapi_set_current(dispatch->table, CURRENT_DISPATCH)
* Update the API state with the new values.
*/
_glapi_set_dispatch(dispatch->table);

DBG_PRINTF(20, "done\n");
UnlockDispatch();
apiState->context = context;
apiState->dispatch = dispatch;

_glapi_set_current(apiState->context, CURRENT_CONTEXT);
/*
* Set the current state in TLS.
*/
_glapi_set_current(context, CURRENT_CONTEXT);
_glapi_set_current(apiState, CURRENT_API_STATE);
_glapi_set_dispatch(dispatch->table);
}

PUBLIC void __glDispatchLoseCurrent(void)
{
__GLdispatchAPIState *curApiState =
(__GLdispatchAPIState *)_glapi_get_current(CURRENT_API_STATE);

DBG_PRINTF(20, "\n");

if (curApiState) {
LockDispatch();
DispatchCurrentUnref(curApiState->dispatch);
UnlockDispatch();

curApiState->dispatch = NULL;
curApiState->context = NULL;
}

_glapi_set_current(NULL, CURRENT_API_STATE);
Expand Down
8 changes: 5 additions & 3 deletions src/GLdispatch/GLdispatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,12 @@ PUBLIC __GLdispatchTable *__glDispatchCreateTable(
PUBLIC void __glDispatchDestroyTable(__GLdispatchTable *dispatch);

/*!
* This makes the given API state current, and sets the current dispatch
* table and context based on the settings in the API state.
* This makes the given API state current, and assigns this API state
* the passed-in current dispatch table and context.
*/
PUBLIC void __glDispatchMakeCurrent(__GLdispatchAPIState *apiState);
PUBLIC void __glDispatchMakeCurrent(__GLdispatchAPIState *apiState,
__GLdispatchTable *dispatch,
void *context);

/*!
* This makes the NOP dispatch table current and sets the current context and
Expand Down

0 comments on commit 4628149

Please sign in to comment.