1554
1566
#endif /* GLX_DIRECT_RENDERING */
1558
** Make a particular context current.
1559
** NOTE: this is in this file so that it can access dummyContext.
1570
* Make a particular context current.
1572
* \note This is in this file so that it can access dummyContext.
1561
1574
USED static Bool MakeContextCurrent(Display *dpy, GLXDrawable draw,
1562
1575
GLXDrawable read, GLXContext gc)
1564
1577
xGLXMakeCurrentReply reply;
1566
CARD8 opcode, oldOpcode;
1567
Bool sentRequestToOldDpy = False;
1568
Bool bindReturnValue = True;
1570
opcode = __glXSetupForCommand(dpy);
1578
const GLXContext oldGC = __glXGetCurrentContext();
1579
const CARD8 opcode = __glXSetupForCommand(dpy);
1580
const CARD8 oldOpcode = ((gc == oldGC) || (oldGC == &dummyContext))
1581
? opcode : __glXSetupForCommand(oldGC->currentDpy);
1582
Bool bindReturnValue;
1585
if (!opcode || !oldOpcode) {
1572
1586
return GL_FALSE;
1576
** Make sure that the new context has a nonzero ID. In the request,
1577
** a zero context ID is used only to mean that we bind to no current
1589
/* Make sure that the new context has a nonzero ID. In the request,
1590
* a zero context ID is used only to mean that we bind to no current
1580
1593
if ((gc != NULL) && (gc->xid == None)) {
1581
1594
return GL_FALSE;
1584
oldGC = __glXGetCurrentContext();
1585
oldOpcode = (gc == oldGC) ? opcode : __glXSetupForCommand(dpy);
1597
#ifndef GLX_DIRECT_RENDERING
1598
if (gc && gc->isDirect) {
1587
1599
return GL_FALSE;
1590
if ((dpy != oldGC->currentDpy || (gc && gc->isDirect)) &&
1591
!oldGC->isDirect && oldGC != &dummyContext) {
1593
** We are either switching from one dpy to another and have to
1594
** send a request to the previous dpy to unbind the previous
1595
** context, or we are switching away from a indirect context to
1596
** a direct context and have to send a request to the dpy to
1597
** unbind the previous context.
1599
sentRequestToOldDpy = True;
1600
LockDisplay(oldGC->currentDpy);
1601
if ( ! SendMakeCurrentRequest( oldGC->currentDpy, oldOpcode, None,
1602
oldGC->currentContextTag, None, None,
1604
/* The make current failed. Just return GL_FALSE. */
1605
UnlockDisplay(oldGC->currentDpy);
1610
oldGC->currentContextTag = 0;
1613
1603
_glapi_check_multithread();
1615
1605
#ifdef GLX_DIRECT_RENDERING
1616
/* Unbind the old direct rendering context */
1617
if (oldGC->isDirect) {
1618
if (oldGC->driContext.private) {
1619
if (! UnbindContextWrapper( oldGC )) {
1620
/* The make current failed. Just return GL_FALSE. */
1624
oldGC->currentContextTag = 0;
1627
1606
/* Bind the direct rendering context to the drawable */
1628
1607
if (gc && gc->isDirect) {
1629
if (gc->driContext.private) {
1630
bindReturnValue = BindContextWrapper( dpy, gc, draw, read );
1608
bindReturnValue = (gc->driContext.private)
1609
? BindContextWrapper(dpy, gc, draw, read)
1634
1614
/* Send a glXMakeCurrent request to bind the new context. */
1637
bindReturnValue = SendMakeCurrentRequest( dpy, opcode,
1638
gc ? gc->xid : None,
1639
oldGC->currentContextTag,
1640
draw, read, &reply );
1642
#ifdef GLX_DIRECT_RENDERING
1616
SendMakeCurrentRequest(dpy, opcode, gc ? gc->xid : None,
1617
((dpy != oldGC->currentDpy) || oldGC->isDirect)
1618
? None : oldGC->currentContextTag,
1619
draw, read, &reply);
1647
1623
if (!bindReturnValue) {
1648
/* The make current failed. */
1649
if (gc && !gc->isDirect) {
1627
if ((dpy != oldGC->currentDpy || (gc && gc->isDirect)) &&
1628
!oldGC->isDirect && oldGC != &dummyContext) {
1629
xGLXMakeCurrentReply dummy_reply;
1631
/* We are either switching from one dpy to another and have to
1632
* send a request to the previous dpy to unbind the previous
1633
* context, or we are switching away from a indirect context to
1634
* a direct context and have to send a request to the dpy to
1635
* unbind the previous context.
1637
(void) SendMakeCurrentRequest(oldGC->currentDpy, oldOpcode, None,
1638
oldGC->currentContextTag, None, None,
1653
1641
#ifdef GLX_DIRECT_RENDERING
1654
/* If the old context was direct rendering, then re-bind to it. */
1655
if (oldGC->isDirect) {
1656
if (oldGC->driContext.private) {
1657
if (! BindContextWrapper( oldGC->currentDpy, oldGC,
1658
oldGC->currentDrawable,
1659
oldGC->currentReadable )) {
1661
** The request failed; this cannot happen with the
1662
** current API. If in the future the API is
1663
** extended to allow context sharing between
1664
** clients, then this may fail (because another
1665
** client may have grabbed the context); in that
1666
** case, we cannot undo the previous request, and
1667
** cannot adhere to the "no-op" behavior.
1642
else if (oldGC->isDirect && oldGC->driContext.private) {
1643
(void) UnbindContextWrapper(oldGC);
1674
** If we had just sent a request to a previous dpy, we have to
1675
** undo that request (because if a command fails, it should act
1676
** like a no-op) by making current to the previous context and
1679
if (sentRequestToOldDpy) {
1680
if ( !SendMakeCurrentRequest( oldGC->currentDpy, oldOpcode,
1682
oldGC->currentDrawable,
1683
oldGC->currentReadable, &reply ) ) {
1684
UnlockDisplay(oldGC->currentDpy);
1687
** The request failed; this cannot happen with the
1688
** current API. If in the future the API is extended to
1689
** allow context sharing between clients, then this may
1690
** fail (because another client may have grabbed the
1691
** context); in that case, we cannot undo the previous
1692
** request, and cannot adhere to the "no-op" behavior.
1696
UnlockDisplay(oldGC->currentDpy);
1698
oldGC->currentContextTag = reply.contextTag;
1703
1648
/* Update our notion of what is current */
1705
1650
if (gc == oldGC) {
1707
** Even though the contexts are the same the drawable might have
1708
** changed. Note that gc cannot be the dummy, and that oldGC
1709
** cannot be NULL, therefore if they are the same, gc is not
1710
** NULL and not the dummy.
1651
/* Even though the contexts are the same the drawable might have
1652
* changed. Note that gc cannot be the dummy, and that oldGC
1653
* cannot be NULL, therefore if they are the same, gc is not
1654
* NULL and not the dummy.
1712
1656
gc->currentDrawable = draw;
1713
1657
gc->currentReadable = read;