Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/opengl/qgl_x11.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information ([email protected])
     4** All rights reserved.
     5** Contact: Nokia Corporation ([email protected])
    56**
    67** This file is part of the QtOpenGL module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     24** In addition, as a special exception, Nokia gives you certain additional
     25** rights.  These rights are described in the Nokia Qt LGPL Exception
     26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you
     37** @nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5353#include <private/qfontengine_ft_p.h>
    5454#include <private/qt_x11_p.h>
     55
     56
    5557#ifdef Q_OS_HPUX
    5658// for GLXPBuffer
    5759#include <private/qglpixelbuffer_p.h>
    5860#endif
     61
     62
     63
     64
    5965
    6066#define INT8  dummy_INT8
     
    6369#undef  INT8
    6470#undef  INT32
     71
    6572#include <X11/Xlib.h>
    6673#include <X11/Xutil.h>
    6774#include <X11/Xos.h>
     75
     76
     77
     78
     79
     80
     81
     82
    6883#include <X11/Xatom.h>
    6984
     
    8095#define GLX_SAMPLE_BUFFERS_ARB  100000
    8196#define GLX_SAMPLES_ARB         100001
     97
     98
     99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
    82116#endif
    83117
     
    130164    GLCMapHash *qglcmap_hash;
    131165};
    132 Q_GLOBAL_STATIC(QGLCMapCleanupHandler, cmap_handler);
     166Q_GLOBAL_STATIC(QGLCMapCleanupHandler, cmap_handler)
    133167
    134168static void cleanup_cmaps()
     
    298332  QGLFormat UNIX/GLX-specific code
    299333 *****************************************************************************/
     334
     335
     336
     337
     338
     339
     340
     341
     342
     343
     344
     345
     346
     347
     348
     349
     350
     351
     352
     353
     354
     355
     356
     357
     358
     359
     360
     361
     362
     363
     364
     365
     366
     367
     368
     369
     370
     371
     372
     373
     374
     375
     376
     377
     378
     379
     380
     381
     382
     383
     384
     385
     386
     387
     388
     389
    300390
    301391bool QGLFormat::hasOpenGL()
     
    434524            return false;
    435525    }
    436     QString glxExt = QString(QLatin1String(glXGetClientString(QX11Info::display(), GLX_EXTENSIONS)));
    437     if (glxExt.contains(QLatin1String("GLX_SGI_video_sync"))) {
     526    Q)));
     527    if ()) {
    438528        if (d->glFormat.swapInterval() == -1)
    439529            d->glFormat.setSwapInterval(0);
     
    444534}
    445535
    446 
    447 /*!
    448   \bold{X11 only:} This virtual function tries to find a
    449   visual that matches the format, reducing the demands if the original
    450   request cannot be met.
    451 
    452   The algorithm for reducing the demands of the format is quite
    453   simple-minded, so override this method in your subclass if your
    454   application has spcific requirements on visual selection.
    455 
    456   \sa chooseContext()
    457 */
    458 
     536/*
     537  See qgl.cpp for qdoc comment.
     538 */
    459539void *QGLContext::chooseVisual()
    460540{
     
    520600}
    521601
    522 
    523 /*!
    524   \internal
    525 
    526   \bold{X11 only:} This virtual function chooses a visual
    527   that matches the OpenGL \link format() format\endlink. Reimplement this
    528   function in a subclass if you need a custom visual.
    529 
    530   \sa chooseContext()
    531 */
    532 
     602/*
     603  See qgl.cpp for qdoc comment.
     604 */
    533605void *QGLContext::tryVisual(const QGLFormat& f, int bufDepth)
    534606{
    535607    Q_D(QGLContext);
    536     int spec[40];
     608    int spec[4];
    537609    int i = 0;
    538610    spec[i++] = GLX_LEVEL;
    539611    spec[i++] = f.plane();
    540612    const QX11Info *xinfo = qt_x11Info(d->paintDevice);
     613
     614
     615
     616
     617
     618
     619
     620
     621
     622
     623
     624
     625
     626
     627
    541628
    542629#if defined(GLX_VERSION_1_1) && defined(GLX_EXT_visual_info)
     
    544631    static bool useTranspExtChecked = false;
    545632    if (f.plane() && !useTranspExtChecked && d->paintDevice) {
    546         QByteArray estr(glXQueryExtensionsString(xinfo->display(), xinfo->screen()));
    547         useTranspExt = estr.contains("GLX_EXT_visual_info");
     633        Q(glXQueryExtensionsString(xinfo->display(), xinfo->screen()));
     634        useTranspExt = e("GLX_EXT_visual_info");
    548635        //# (A bit simplistic; that could theoretically be a substring)
    549636        if (useTranspExt) {
     
    566653        useTranspExtChecked = true;
    567654    }
    568     if (f.plane() && useTranspExt) {
     655    if (f.plane() && useTranspExt) {
    569656        // Required to avoid non-transparent overlay visual(!) on some systems
    570657        spec[i++] = GLX_TRANSPARENT_TYPE_EXT;
     
    573660#endif
    574661
     662
     663
     664
     665
     666
     667
     668
     669
    575670    if (f.doubleBuffer())
    576671        spec[i++] = GLX_DOUBLEBUFFER;
     672
     673
    577674    if (f.depth()) {
    578675        spec[i++] = GLX_DEPTH_SIZE;
     
    581678    if (f.stereo()) {
    582679        spec[i++] = GLX_STEREO;
     680
     681
    583682    }
    584683    if (f.stencil()) {
     
    587686    }
    588687    if (f.rgba()) {
    589         spec[i++] = GLX_RGBA;
     688        if (!useFBConfig)
     689            spec[i++] = GLX_RGBA;
    590690        spec[i++] = GLX_RED_SIZE;
    591691        spec[i++] = f.redBufferSize() == -1 ? 1 : f.redBufferSize();
     
    622722    }
    623723
     724
     725
     726
     727
     728
     729
     730
     731
     732
     733
     734
     735
     736
     737
     738
     739
     740
     741
     742
     743
    624744    spec[i] = XNone;
    625     return glXChooseVisual(xinfo->display(), xinfo->screen(), spec);
     745
     746
     747    XVisualInfo* chosenVisualInfo = 0;
     748
     749#if defined(GLX_VERSION_1_3) && !defined(Q_OS_HPUX)
     750    while (useFBConfig) {
     751        GLXFBConfig *configs;
     752        int configCount = 0;
     753        configs = glXChooseFBConfig(xinfo->display(), xinfo->screen(), spec, &configCount);
     754
     755        if (!configs)
     756            break; // fallback to trying glXChooseVisual
     757
     758        for (i = 0; i < configCount; ++i) {
     759            XVisualInfo* vi;
     760            vi = glXGetVisualFromFBConfig(xinfo->display(), configs[i]);
     761            if (!vi)
     762                continue;
     763
     764#if !defined(QT_NO_XRENDER)
     765            QWidget* w = 0;
     766            if (d->paintDevice->devType() == QInternal::Widget)
     767                w = static_cast<QWidget*>(d->paintDevice);
     768
     769            if (w && w->testAttribute(Qt::WA_TranslucentBackground) && f.alpha()) {
     770                // Attempt to find a config who's visual has a proper alpha channel
     771                XRenderPictFormat *pictFormat;
     772                pictFormat = XRenderFindVisualFormat(xinfo->display(), vi->visual);
     773
     774                if (pictFormat && (pictFormat->type == PictTypeDirect) && pictFormat->direct.alphaMask) {
     775                    // The pict format for the visual matching the FBConfig indicates ARGB
     776                    if (chosenVisualInfo)
     777                        XFree(chosenVisualInfo);
     778                    chosenVisualInfo = vi;
     779                    break;
     780                }
     781            } else
     782#endif //QT_NO_XRENDER
     783            if (chosenVisualInfo) {
     784                // If we've got a visual we can use and we're not trying to find one with a
     785                // real alpha channel, we might as well just use the one we've got
     786                break;
     787            }
     788
     789            if (!chosenVisualInfo)
     790                chosenVisualInfo = vi; // Have something to fall back to
     791            else
     792                XFree(vi);
     793        }
     794
     795        XFree(configs);
     796        break;
     797    }
     798#endif // defined(GLX_VERSION_1_3)
     799
     800    if (!chosenVisualInfo)
     801        chosenVisualInfo = glXChooseVisual(xinfo->display(), xinfo->screen(), spec);
     802
     803    return chosenVisualInfo;
    626804}
    627805
     
    671849        qWarning("QGLContext::makeCurrent(): Failed.");
    672850
    673     if (ok) {
    674         if (!qgl_context_storage.hasLocalData() && QThread::currentThread())
    675             qgl_context_storage.setLocalData(new QGLThreadContext);
    676         if (qgl_context_storage.hasLocalData())
    677             qgl_context_storage.localData()->context = this;
    678         currentCtx = this;
    679     }
     851    if (ok)
     852        QGLContextPrivate::setCurrentContext(this);
    680853}
    681854
     
    684857    Q_D(QGLContext);
    685858    glXMakeCurrent(qt_x11Info(d->paintDevice)->display(), 0, 0);
    686     if (qgl_context_storage.hasLocalData())
    687         qgl_context_storage.localData()->context = 0;
    688     currentCtx = 0;
     859    QGLContextPrivate::setCurrentContext(0);
    689860}
    690861
     
    704875            static bool resolved = false;
    705876            if (!resolved) {
    706                 QString glxExt = QString(QLatin1String(glXGetClientString(QX11Info::display(), GLX_EXTENSIONS)));
    707                 if (glxExt.contains(QLatin1String("GLX_SGI_video_sync"))) {
    708 #if defined(Q_OS_LINUX) || defined(Q_OS_BSD4)
    709                     void *handle = dlopen(NULL, RTLD_LAZY);
    710                     if (handle) {
    711                         glXGetVideoSyncSGI = (qt_glXGetVideoSyncSGI) dlsym(handle, "glXGetVideoSyncSGI");
    712                         glXWaitVideoSyncSGI = (qt_glXWaitVideoSyncSGI) dlsym(handle, "glXWaitVideoSyncSGI");
    713                         dlclose(handle);
    714                     }
    715                     if (!glXGetVideoSyncSGI)
    716 #endif
    717                     {
    718                         extern const QString qt_gl_library_name();
    719                         QLibrary lib(qt_gl_library_name());
    720                         glXGetVideoSyncSGI = (qt_glXGetVideoSyncSGI) lib.resolve("glXGetVideoSyncSGI");
    721                         glXWaitVideoSyncSGI = (qt_glXWaitVideoSyncSGI) lib.resolve("glXWaitVideoSyncSGI");
    722                     }
     877                const QX11Info *xinfo = qt_x11Info(d->paintDevice);
     878                QGLExtensionMatcher extensions(glXQueryExtensionsString(xinfo->display(), xinfo->screen()));
     879                if (extensions.match("GLX_SGI_video_sync")) {
     880                    glXGetVideoSyncSGI =  (qt_glXGetVideoSyncSGI)qglx_getProcAddress("glXGetVideoSyncSGI");
     881                    glXWaitVideoSyncSGI = (qt_glXWaitVideoSyncSGI)qglx_getProcAddress("glXWaitVideoSyncSGI");
    723882                }
    724883                resolved = true;
     
    9491108        return 0;
    9501109    if (!glXGetProcAddressARB) {
    951         QString glxExt = QString(QLatin1String(glXGetClientString(QX11Info::display(), GLX_EXTENSIONS)));
    952         if (glxExt.contains(QLatin1String("GLX_ARB_get_proc_address"))) {
     1110        Q));
     1111        if ()) {
    9531112#if defined(Q_OS_LINUX) || defined(Q_OS_BSD4)
    9541113            void *handle = dlopen(NULL, RTLD_LAZY);
     
    9601119#endif
    9611120            {
     1121
    9621122                extern const QString qt_gl_library_name();
    9631123                QLibrary lib(qt_gl_library_name());
    9641124                glXGetProcAddressARB = (qt_glXGetProcAddressARB) lib.resolve("glXGetProcAddressARB");
     1125
    9651126            }
    9661127        }
     
    11841345    d->glcx = context;
    11851346
    1186 
    11871347    if (parentWidget()) {
    11881348        // force creation of delay-created widgets
     
    11911351            d_func()->xinfo = parentWidget()->d_func()->xinfo;
    11921352    }
     1353
     1354
     1355
     1356
     1357
     1358
    11931359
    11941360    bool createFailed = false;
     
    14231589}
    14241590
     1591
     1592
     1593
     1594
     1595
     1596
     1597
     1598
     1599
     1600
     1601
     1602
     1603
     1604
     1605
     1606
     1607
     1608
     1609
     1610
     1611
     1612
     1613
     1614
     1615
     1616
     1617
     1618
     1619
     1620
     1621
     1622
     1623
     1624
     1625
     1626
     1627
     1628
     1629
     1630
     1631
     1632
     1633
     1634
     1635
     1636
     1637
     1638
     1639
     1640
     1641
     1642
     1643
     1644
     1645
     1646
     1647
     1648
     1649
     1650
     1651
     1652
     1653
     1654
     1655
     1656
     1657
     1658
     1659
     1660
     1661
     1662
     1663
     1664
     1665
     1666
     1667
     1668
     1669
     1670
     1671
     1672
     1673
     1674
     1675
     1676
     1677
     1678
     1679
     1680
     1681
     1682
     1683
     1684
     1685
     1686
     1687
     1688
     1689
     1690
     1691
     1692
     1693
     1694
     1695
     1696
     1697
     1698
     1699
     1700
     1701
     1702
     1703
     1704
     1705
     1706
     1707
     1708
     1709
     1710
     1711
     1712
     1713
     1714
     1715
     1716
     1717
     1718
     1719
     1720
     1721
     1722
     1723
     1724
     1725
     1726
     1727
     1728
     1729
     1730
     1731
     1732
     1733
     1734
     1735
     1736
     1737
     1738
     1739
     1740
     1741
     1742
     1743
     1744
     1745
     1746
     1747
     1748
     1749
     1750
     1751
     1752
     1753
     1754
     1755
     1756
    14251757QT_END_NAMESPACE
Note: See TracChangeset for help on using the changeset viewer.