~ubuntu-branches/ubuntu/quantal/mesa/quantal

« back to all changes in this revision

Viewing changes to src/glx/x11/glxext.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-02-21 12:44:07 UTC
  • mfrom: (1.2.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20070221124407-rgcacs32mycrtadl
ImportĀ upstreamĀ versionĀ 6.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
64
64
#endif
65
65
 
66
66
#ifdef USE_XCB
67
 
#include <X11/xcl.h>
68
 
#include <X11/XCB/xcb.h>
69
 
#include <X11/XCB/glx.h>
 
67
#include <X11/Xlib-xcb.h>
 
68
#include <xcb/xcb.h>
 
69
#include <xcb/glx.h>
70
70
#endif
71
71
 
72
72
#include <assert.h>
719
719
    XF86DRIGetDrawableInfo,
720
720
 
721
721
    __glXGetUST,
722
 
    glXGetMscRateOML,
 
722
    __glXGetMscRateOML,
723
723
};
724
724
 
725
725
 
 
726
 
726
727
/**
727
728
 * Perform the required libGL-side initialization and call the client-side
728
729
 * driver's \c __driCreateNewScreen function.
773
774
    framebuffer.dev_priv = NULL;
774
775
 
775
776
    if (XF86DRIOpenConnection(dpy, scrn, &hSAREA, &BusID)) {
776
 
        fd = drmOpen(NULL,BusID);
 
777
        int newlyopened;
 
778
        fd = drmOpenOnce(NULL,BusID, &newlyopened);
777
779
        Xfree(BusID); /* No longer needed */
778
780
 
779
781
        err_msg = "open DRM";
800
802
                }
801
803
 
802
804
                err_msg = "XF86DRIAuthConnection";
803
 
                if (XF86DRIAuthConnection(dpy, scrn, magic)) {
 
805
                if (!newlyopened || XF86DRIAuthConnection(dpy, scrn, magic)) {
804
806
                    char *driverName;
805
807
 
806
808
                    /*
904
906
        }
905
907
 
906
908
        if ( fd >= 0 ) {
907
 
            (void)drmClose(fd);
 
909
            (void)drmCloseOnce(fd);
908
910
        }
909
911
 
910
912
        (void)XF86DRICloseConnection(dpy, scrn);
1016
1018
        if (!_XReply(dpy, (xReply*) &reply, 0, False)) {
1017
1019
            /* Something is busted. Punt. */
1018
1020
            UnlockDisplay(dpy);
 
1021
            SyncHandle();
1019
1022
            FreeScreenConfigs(priv);
1020
1023
            return GL_FALSE;
1021
1024
        }
1022
1025
 
1023
 
        UnlockDisplay(dpy);
1024
1026
        if (!reply.numVisuals) {
1025
1027
            /* This screen does not support GL rendering */
1026
1028
            UnlockDisplay(dpy);
1284
1286
{
1285
1287
    Display * const dpy = ctx->currentDpy;
1286
1288
#ifdef USE_XCB
1287
 
    XCBConnection *c = XCBConnectionOfDisplay(dpy);
 
1289
    xcb_connection_t *c = XGetXCBConnection(dpy);
1288
1290
#else
1289
1291
    xGLXRenderReq *req;
1290
1292
#endif /* USE_XCB */
1292
1294
 
1293
1295
    if ( (dpy != NULL) && (size > 0) ) {
1294
1296
#ifdef USE_XCB
1295
 
        XCBGlxRender(c, ctx->currentContextTag, size, (char *)ctx->buf);
 
1297
        xcb_glx_render(c, ctx->currentContextTag, size, (char *)ctx->buf);
1296
1298
#else
1297
1299
        /* Send the entire buffer as an X request */
1298
1300
        LockDisplay(dpy);
1335
1337
{
1336
1338
    Display *dpy = gc->currentDpy;
1337
1339
#ifdef USE_XCB
1338
 
    XCBConnection *c = XCBConnectionOfDisplay(dpy);
1339
 
    XCBGlxRenderLarge(c, gc->currentContextTag, requestNumber, totalRequests, dataLen, data);
 
1340
    xcb_connection_t *c = XGetXCBConnection(dpy);
 
1341
    xcb_glx_render_large(c, gc->currentContextTag, requestNumber, totalRequests, dataLen, data);
1340
1342
#else
1341
1343
    xGLXRenderLargeReq *req;
1342
1344
    
1480
1482
 * \warning
1481
1483
 * This function assumes that \c dpy is locked with \c LockDisplay on entry.
1482
1484
 */
1483
 
static Bool SendMakeCurrentRequest( Display *dpy, CARD8 opcode,
1484
 
                                    GLXContextID gc_id, GLXContextTag gc_tag,
1485
 
                                    GLXDrawable draw, GLXDrawable read,
1486
 
                                    xGLXMakeCurrentReply * reply )
 
1485
static Bool SendMakeCurrentRequest(Display *dpy, CARD8 opcode,
 
1486
                                   GLXContextID gc_id, GLXContextTag gc_tag,
 
1487
                                   GLXDrawable draw, GLXDrawable read,
 
1488
                                   xGLXMakeCurrentReply *reply)
1487
1489
{
1488
 
    if ( draw == read ) {
 
1490
    Bool ret;
 
1491
 
 
1492
 
 
1493
    LockDisplay(dpy);
 
1494
 
 
1495
    if (draw == read) {
1489
1496
        xGLXMakeCurrentReq *req;
1490
1497
 
1491
1498
        GetReq(GLXMakeCurrent,req);
1503
1510
         * not the SGI extension.
1504
1511
         */
1505
1512
 
1506
 
        if ( (priv->majorVersion > 1) || (priv->minorVersion >= 3) ) {
 
1513
        if ((priv->majorVersion > 1) || (priv->minorVersion >= 3)) {
1507
1514
            xGLXMakeContextCurrentReq *req;
1508
1515
 
1509
1516
            GetReq(GLXMakeContextCurrent,req);
1531
1538
        }
1532
1539
    }
1533
1540
 
1534
 
    return _XReply(dpy, (xReply*) reply, 0, False);
 
1541
    ret = _XReply(dpy, (xReply*) reply, 0, False);
 
1542
 
 
1543
    UnlockDisplay(dpy);
 
1544
    SyncHandle();
 
1545
 
 
1546
    return ret;
1535
1547
}
1536
1548
 
1537
1549
 
1554
1566
#endif /* GLX_DIRECT_RENDERING */
1555
1567
 
1556
1568
 
1557
 
/*
1558
 
** Make a particular context current.
1559
 
** NOTE: this is in this file so that it can access dummyContext.
1560
 
*/
 
1569
/**
 
1570
 * Make a particular context current.
 
1571
 * 
 
1572
 * \note This is in this file so that it can access dummyContext.
 
1573
 */
1561
1574
USED static Bool MakeContextCurrent(Display *dpy, GLXDrawable draw,
1562
1575
                                    GLXDrawable read, GLXContext gc)
1563
1576
{
1564
1577
    xGLXMakeCurrentReply reply;
1565
 
    GLXContext oldGC;
1566
 
    CARD8 opcode, oldOpcode;
1567
 
    Bool sentRequestToOldDpy = False;
1568
 
    Bool bindReturnValue = True;
1569
 
 
1570
 
    opcode = __glXSetupForCommand(dpy);
1571
 
    if (!opcode) {
 
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;
 
1583
 
 
1584
 
 
1585
    if (!opcode || !oldOpcode) {
1572
1586
        return GL_FALSE;
1573
1587
    }
1574
1588
 
1575
 
    /*
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
1578
 
    ** context.
1579
 
    */
 
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
 
1591
     * context.
 
1592
     */
1580
1593
    if ((gc != NULL) && (gc->xid == None)) {
1581
1594
        return GL_FALSE;
1582
1595
    }
1583
1596
 
1584
 
    oldGC = __glXGetCurrentContext();
1585
 
    oldOpcode = (gc == oldGC) ? opcode : __glXSetupForCommand(dpy);
1586
 
    if (!oldOpcode) {
 
1597
#ifndef GLX_DIRECT_RENDERING
 
1598
    if (gc && gc->isDirect) {
1587
1599
        return GL_FALSE;
1588
1600
    }
1589
 
 
1590
 
    if ((dpy != oldGC->currentDpy || (gc && gc->isDirect)) &&
1591
 
        !oldGC->isDirect && oldGC != &dummyContext) {
1592
 
        /*
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.
1598
 
        */
1599
 
        sentRequestToOldDpy = True;
1600
 
        LockDisplay(oldGC->currentDpy);
1601
 
        if ( ! SendMakeCurrentRequest( oldGC->currentDpy, oldOpcode, None,
1602
 
                                       oldGC->currentContextTag, None, None,
1603
 
                                       &reply ) ) {
1604
 
            /* The make current failed.  Just return GL_FALSE. */
1605
 
            UnlockDisplay(oldGC->currentDpy);
1606
 
            SyncHandle();
1607
 
            return GL_FALSE;
1608
 
        }
1609
 
 
1610
 
        oldGC->currentContextTag = 0;
1611
 
    }
 
1601
#endif
1612
1602
 
1613
1603
    _glapi_check_multithread();
1614
1604
 
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. */
1621
 
                return GL_FALSE;
1622
 
            }
1623
 
        }
1624
 
        oldGC->currentContextTag = 0;
1625
 
    }
1626
 
 
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 );
1631
 
        }
1632
 
    } else {
 
1608
        bindReturnValue = (gc->driContext.private) 
 
1609
          ? BindContextWrapper(dpy, gc, draw, read)
 
1610
          : False;
 
1611
    } else
1633
1612
#endif
 
1613
    {
1634
1614
        /* Send a glXMakeCurrent request to bind the new context. */
1635
 
        LockDisplay(dpy);
1636
 
 
1637
 
        bindReturnValue = SendMakeCurrentRequest( dpy, opcode, 
1638
 
                                                  gc ? gc->xid : None,
1639
 
                                                  oldGC->currentContextTag,
1640
 
                                                  draw, read, &reply );
1641
 
        UnlockDisplay(dpy);
1642
 
#ifdef GLX_DIRECT_RENDERING
 
1615
        bindReturnValue = 
 
1616
          SendMakeCurrentRequest(dpy, opcode, gc ? gc->xid : None,
 
1617
                                 ((dpy != oldGC->currentDpy) || oldGC->isDirect)
 
1618
                                 ? None : oldGC->currentContextTag,
 
1619
                                 draw, read, &reply);
1643
1620
    }
1644
 
#endif
1645
1621
 
1646
1622
 
1647
1623
    if (!bindReturnValue) {
1648
 
        /* The make current failed. */
1649
 
        if (gc && !gc->isDirect) {
1650
 
            SyncHandle();
1651
 
        }
1652
 
 
 
1624
        return False;
 
1625
    }
 
1626
 
 
1627
    if ((dpy != oldGC->currentDpy || (gc && gc->isDirect)) &&
 
1628
        !oldGC->isDirect && oldGC != &dummyContext) {
 
1629
        xGLXMakeCurrentReply dummy_reply;
 
1630
 
 
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.
 
1636
         */
 
1637
        (void) SendMakeCurrentRequest(oldGC->currentDpy, oldOpcode, None,
 
1638
                                      oldGC->currentContextTag, None, None,
 
1639
                                      & dummy_reply);
 
1640
    }
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 )) {
1660
 
                    /*
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.
1668
 
                    */
1669
 
                }
1670
 
            }
1671
 
        } else
 
1642
    else if (oldGC->isDirect && oldGC->driContext.private) {
 
1643
        (void) UnbindContextWrapper(oldGC);
 
1644
    }
1672
1645
#endif
1673
 
        /*
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
1677
 
        ** drawable.
1678
 
        */
1679
 
        if (sentRequestToOldDpy) {
1680
 
            if ( !SendMakeCurrentRequest( oldGC->currentDpy, oldOpcode,
1681
 
                                          oldGC->xid, 0, 
1682
 
                                          oldGC->currentDrawable,
1683
 
                                          oldGC->currentReadable, &reply ) ) {
1684
 
                UnlockDisplay(oldGC->currentDpy);
1685
 
                SyncHandle();
1686
 
                /*
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.
1693
 
                */
1694
 
            }
1695
 
            else {
1696
 
                UnlockDisplay(oldGC->currentDpy);
1697
 
            }
1698
 
            oldGC->currentContextTag = reply.contextTag;
1699
 
        }
1700
 
        return GL_FALSE;
1701
 
    }
 
1646
 
1702
1647
 
1703
1648
    /* Update our notion of what is current */
1704
1649
    __glXLock();
1705
1650
    if (gc == oldGC) {
1706
 
        /*
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.
1711
 
        */
 
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.
 
1655
         */
1712
1656
        gc->currentDrawable = draw;
1713
1657
        gc->currentReadable = read;
1714
1658
    } else {
1720
1664
            oldGC->currentContextTag = 0;
1721
1665
 
1722
1666
            if (oldGC->xid == None) {
1723
 
                /* 
1724
 
                ** We are switching away from a context that was
1725
 
                ** previously destroyed, so we need to free the memory
1726
 
                ** for the old handle.
1727
 
                */
 
1667
                /* We are switching away from a context that was
 
1668
                 * previously destroyed, so we need to free the memory
 
1669
                 * for the old handle.
 
1670
                 */
1728
1671
#ifdef GLX_DIRECT_RENDERING
1729
1672
                /* Destroy the old direct rendering context */
1730
1673
                if (oldGC->isDirect) {
1740
1683
        }
1741
1684
        if (gc) {
1742
1685
            __glXSetCurrentContext(gc);
1743
 
#ifdef GLX_DIRECT_RENDERING
 
1686
 
 
1687
            gc->currentDpy = dpy;
 
1688
            gc->currentDrawable = draw;
 
1689
            gc->currentReadable = read;
 
1690
 
1744
1691
            if (!gc->isDirect) {
1745
1692
               if (!IndirectAPI)
1746
1693
                  IndirectAPI = __glXNewIndirectAPI();
1747
1694
               _glapi_set_dispatch(IndirectAPI);
1748
 
# ifdef GLX_USE_APPLEGL
 
1695
 
 
1696
#ifdef GLX_USE_APPLEGL
1749
1697
               do {
1750
1698
                   extern void XAppleDRIUseIndirectDispatch(void);
1751
1699
                   XAppleDRIUseIndirectDispatch();
1752
1700
               } while (0);
1753
 
# endif
1754
 
            }
1755
 
#else
1756
 
            /* if not direct rendering, always need indirect dispatch */
1757
 
            if (!IndirectAPI)
1758
 
               IndirectAPI = __glXNewIndirectAPI();
1759
 
            _glapi_set_dispatch(IndirectAPI);
1760
1701
#endif
1761
 
            gc->currentDpy = dpy;
1762
 
            gc->currentDrawable = draw;
1763
 
            gc->currentReadable = read;
1764
1702
 
1765
 
            if ( ! gc->isDirect ) {
1766
 
                __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
 
1703
                __GLXattribute *state = 
 
1704
                  (__GLXattribute *)(gc->client_state_private);
1767
1705
 
1768
1706
                gc->currentContextTag = reply.contextTag;
1769
 
                if ( state->array_state == NULL ) {
1770
 
                    (void) glGetString( GL_EXTENSIONS );
1771
 
                    (void) glGetString( GL_VERSION );
 
1707
                if (state->array_state == NULL) {
 
1708
                    (void) glGetString(GL_EXTENSIONS);
 
1709
                    (void) glGetString(GL_VERSION);
1772
1710
                    __glXInitVertexArrayState(gc);
1773
1711
                }
1774
1712
            }