Ignore:
Timestamp:
May 5, 2011, 5:36:53 AM (14 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/opengl/qgl_p.h

    r769 r846  
    11/****************************************************************************
    22**
    3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
     3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
    44** All rights reserved.
    55** Contact: Nokia Corporation (qt-info@nokia.com)
     
    6565#include "qglpaintdevice_p.h"
    6666
    67 #ifndef QT_OPENGL_ES_1_CL
    68 #define q_vertexType float
    69 #define q_vertexTypeEnum GL_FLOAT
    70 #define f2vt(f)     (f)
    71 #define vt2f(x)     (x)
    72 #define i2vt(i)     (float(i))
    73 #else
    74 #define FLOAT2X(f)      (int( (f) * (65536)))
    75 #define X2FLOAT(x)      (float(x) / 65536.0f)
    76 #define f2vt(f)     FLOAT2X(f)
    77 #define i2vt(i)     ((i)*65536)
    78 #define vt2f(x)     X2FLOAT(x)
    79 #define q_vertexType GLfixed
    80 #define q_vertexTypeEnum GL_FIXED
    81 #endif //QT_OPENGL_ES_1_CL
    82 
    83 #if defined(QT_OPENGL_ES) || defined(QT_OPENGL_ES_2)
    84 QT_BEGIN_INCLUDE_NAMESPACE
    85 
    86 #if defined(QT_OPENGL_ES_2)
    87 #   include <GLES2/gl2.h>
    88 #endif
    89 
    90 #if defined(QT_GLES_EGL)
    91 #   include <GLES/egl.h>
    92 #else
    93 #   include <EGL/egl.h>
    94 #endif
    95 
    96 QT_END_INCLUDE_NAMESPACE
     67#ifndef QT_NO_EGL
     68#include <QtGui/private/qegl_p.h>
    9769#endif
    9870
     
    11587# ifdef old_qDebug
    11688#   undef qDebug
    117 #   define qDebug QT_QDEBUG_MACRO
     89#   define qDebug QT_NO_QDEBUG_MACRO
    11890#   undef old_qDebug
    11991# endif
     
    12597#endif
    12698
    127 #if defined(QT_OPENGL_ES)
     99#ifndef QT_NO_EGL
    128100class QEglContext;
    129101#endif
     
    139111        : ref(1)
    140112    {
    141         opts = QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba | QGL::DirectRendering | QGL::StencilBuffer;
     113        opts = QGL::DoubleBuffer | QGL::DepthBuffer | QGL::Rgba | QGL::DirectRendering
     114             | QGL::StencilBuffer | QGL::DeprecatedFunctions;
    142115        pln = 0;
    143116        depthSize = accumSize = stencilSize = redSize = greenSize = blueSize = alphaSize = -1;
    144117        numSamples = -1;
    145118        swapInterval = -1;
     119        majorVersion = 1;
     120        minorVersion = 0;
     121        profile = QGLFormat::NoProfile;
    146122    }
    147123    QGLFormatPrivate(const QGLFormatPrivate *other)
     
    157133          alphaSize(other->alphaSize),
    158134          numSamples(other->numSamples),
    159           swapInterval(other->swapInterval)
     135          swapInterval(other->swapInterval),
     136          majorVersion(other->majorVersion),
     137          minorVersion(other->minorVersion),
     138          profile(other->profile)
    160139    {
    161140    }
     
    172151    int numSamples;
    173152    int swapInterval;
     153    int majorVersion;
     154    int minorVersion;
     155    QGLFormat::OpenGLContextProfile profile;
    174156};
    175157
     
    183165                       , wsurf(0)
    184166#endif
    185 #if defined(Q_WS_X11) && defined(QT_OPENGL_ES)
     167#if defined(Q_WS_X11) && !defined(QT_NO_EGL)
     168                       , eglSurfaceWindowId(0)
     169#endif
     170#if defined(Q_OS_SYMBIAN)
    186171                       , eglSurfaceWindowId(0)
    187172#endif
     
    196181    bool renderCxPm(QPixmap *pixmap);
    197182    void cleanupColormaps();
     183    void aboutToDestroy() {
     184        if (glcx)
     185            glcx->reset();
     186    }
    198187
    199188    QGLContext *glcx;
     
    213202#elif defined(Q_WS_X11)
    214203    QGLOverlayWidget *olw;
    215 #if defined(QT_OPENGL_ES)
    216     void recreateEglSurface(bool force);
     204#ifndef QT_NO_EGL
     205    void recreateEglSurface();
    217206    WId eglSurfaceWindowId;
    218207#endif
     
    223212    QWSGLWindowSurface *wsurf;
    224213#endif
     214#ifdef Q_OS_SYMBIAN
     215    void recreateEglSurface();
     216    WId eglSurfaceWindowId;
     217#endif
    225218};
    226219
     
    249242    static void removeShare(const QGLContext *context);
    250243private:
    251     QGLContextGroup(const QGLContext *context) : m_context(context), m_guards(0), m_refs(1) { }
     244    QGLContextGroup(const QGLContext *context);
    252245
    253246    QGLExtensionFuncs m_extensionFuncs;
     
    292285        ETC1TextureCompression  = 0x00010000,
    293286        PVRTCTextureCompression = 0x00020000,
    294         FragmentShader          = 0x00040000
     287        FragmentShader          = 0x00040000,
     288        ElementIndexUint        = 0x00080000,
     289        Depth24                 = 0x00100000
    295290    };
    296291    Q_DECLARE_FLAGS(Extensions, Extension)
    297292
    298293    static Extensions glExtensions();
    299 
    300 private:
    301294    static Extensions currentContextExtensions();
    302295};
     
    325318
    326319class QGLTexture;
     320class QGLTextureDestroyer;
    327321
    328322// This probably needs to grow to GL_MAX_VERTEX_ATTRIBS, but 3 is ok for now as that's
     
    334328    Q_DECLARE_PUBLIC(QGLContext)
    335329public:
    336     explicit QGLContextPrivate(QGLContext *context) : internal_context(false), q_ptr(context) {group = new QGLContextGroup(context);}
     330    explicit QGLContextPrivate(QGLContext *context);
    337331    ~QGLContextPrivate();
    338332    QGLTexture *bindTexture(const QImage &image, GLenum target, GLint format,
     
    351345    void setVertexAttribArrayEnabled(int arrayIndex, bool enabled = true);
    352346    void syncGlState(); // Makes sure the GL context's state is what we think it is
     347    void swapRegion(const QRegion &region);
     348
     349#if defined(Q_WS_WIN)
     350    void updateFormatVersion();
     351#endif
    353352
    354353#if defined(Q_WS_WIN)
     
    361360    HDC hbitmap_hdc;
    362361#endif
    363 #if defined(QT_OPENGL_ES)
     362#ifndef QT_NO_EGL
     363    uint ownsEglContext : 1;
    364364    QEglContext *eglContext;
    365365    EGLSurface eglSurface;
    366366    void destroyEglSurfaceForDevice();
     367    EGLSurface eglSurfaceForDevice() const;
    367368#elif defined(Q_WS_X11) || defined(Q_WS_MAC)
    368369    void* cx;
     
    376377    int screen;
    377378    QHash<QPixmapData*, QPixmap> boundPixmaps;
    378     QGLTexture *bindTextureFromNativePixmap(QPixmapData*, const qint64 key,
     379    QGLTexture *bindTextureFromNativePixmap(QPixmap*, const qint64 key,
    379380                                            QGLContext::BindOptions options);
    380381    static void destroyGlSurfaceForPixmap(QPixmapData*);
     
    397398    uint version_flags_cached : 1;
    398399    uint extension_flags_cached : 1;
     400
     401    // workarounds for driver/hw bugs on different platforms
     402    uint workaround_needsFullClearOnEveryFrame : 1;
     403    uint workaround_brokenFBOReadBack : 1;
     404    uint workaround_brokenTexSubImage : 1;
     405    uint workaroundsCached : 1;
     406
     407    uint workaround_brokenTextureFromPixmap : 1;
     408    uint workaround_brokenTextureFromPixmap_init : 1;
     409
    399410    QPaintDevice *paintDevice;
    400411    QColor transpColor;
     
    409420    GLuint default_fbo;
    410421    QPaintEngine *active_engine;
     422    QGLTextureDestroyer *texture_destroyer;
    411423
    412424    bool vertexAttributeArraysEnabledState[QT_GL_VERTEX_ARRAY_TRACKED_COUNT];
     
    418430#endif
    419431
    420 #if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS)
     432#if defined(Q_WS_X11) || defined(Q_WS_MAC) || defined(Q_WS_QWS) || defined(Q_OS_SYMBIAN)
    421433    static QGLExtensionFuncs qt_extensionFuncs;
    422     static inline QGLExtensionFuncs& extensionFuncs(const QGLContext *) { return qt_extensionFuncs; }
     434    static Q_OPENGL_EXPORT QGLExtensionFuncs& extensionFuncs(const QGLContext *);
    423435#endif
    424436
    425437    static void setCurrentContext(QGLContext *context);
    426 };
    427 
    428 // ### make QGLContext a QObject in 5.0 and remove the proxy stuff
    429 class Q_OPENGL_EXPORT QGLSignalProxy : public QObject
    430 {
    431     Q_OBJECT
    432 public:
    433     QGLSignalProxy() : QObject() {}
    434     void emitAboutToDestroyContext(const QGLContext *context) {
    435         emit aboutToDestroyContext(context);
    436     }
    437     static QGLSignalProxy *instance();
    438 Q_SIGNALS:
    439     void aboutToDestroyContext(const QGLContext *context);
    440438};
    441439
     
    482480};
    483481
     482class QGLTextureDestroyer : public QObject
     483{
     484    Q_OBJECT
     485public:
     486    QGLTextureDestroyer() : QObject() {
     487        qRegisterMetaType<GLuint>("GLuint");
     488        connect(this, SIGNAL(freeTexture(QGLContext *, QPixmapData *, GLuint)),
     489                this, SLOT(freeTexture_slot(QGLContext *, QPixmapData *, GLuint)));
     490    }
     491    void emitFreeTexture(QGLContext *context, QPixmapData *boundPixmap, GLuint id) {
     492        emit freeTexture(context, boundPixmap, id);
     493    }
     494
     495Q_SIGNALS:
     496    void freeTexture(QGLContext *context, QPixmapData *boundPixmap, GLuint id);
     497
     498private slots:
     499    void freeTexture_slot(QGLContext *context, QPixmapData *boundPixmap, GLuint id) {
     500#if defined(Q_WS_X11)
     501        if (boundPixmap) {
     502            QGLContext *oldContext = const_cast<QGLContext *>(QGLContext::currentContext());
     503            context->makeCurrent();
     504            // Although glXReleaseTexImage is a glX call, it must be called while there
     505            // is a current context - the context the pixmap was bound to a texture in.
     506            // Otherwise the release doesn't do anything and you get BadDrawable errors
     507            // when you come to delete the context.
     508            QGLContextPrivate::unbindPixmapFromTexture(boundPixmap);
     509            glDeleteTextures(1, &id);
     510            if (oldContext)
     511                oldContext->makeCurrent();
     512            return;
     513        }
     514#endif
     515        QGLShareContextScope scope(context);
     516        glDeleteTextures(1, &id);
     517    }
     518};
     519
     520// ### make QGLContext a QObject in 5.0 and remove the proxy stuff
     521class Q_OPENGL_EXPORT QGLSignalProxy : public QObject
     522{
     523    Q_OBJECT
     524public:
     525    void emitAboutToDestroyContext(const QGLContext *context) {
     526        emit aboutToDestroyContext(context);
     527    }
     528    static QGLSignalProxy *instance();
     529Q_SIGNALS:
     530    void aboutToDestroyContext(const QGLContext *context);
     531};
     532
    484533class QGLTexture {
    485534public:
     
    498547        if (options & QGLContext::MemoryManagedBindOption) {
    499548            Q_ASSERT(context);
    500             QGLShareContextScope scope(context);
    501 #if defined(Q_WS_X11)
    502             // Although glXReleaseTexImage is a glX call, it must be called while there
    503             // is a current context - the context the pixmap was bound to a texture in.
    504             // Otherwise the release doesn't do anything and you get BadDrawable errors
    505             // when you come to delete the context.
    506             if (boundPixmap)
    507                 QGLContextPrivate::unbindPixmapFromTexture(boundPixmap);
    508 #endif
    509             glDeleteTextures(1, &id);
     549#if !defined(Q_WS_X11)
     550            QPixmapData *boundPixmap = 0;
     551#endif
     552            context->d_ptr->texture_destroyer->emitFreeTexture(context, boundPixmap, id);
    510553        }
    511554     }
     
    531574};
    532575
     576struct QGLTextureCacheKey {
     577    qint64 key;
     578    QGLContextGroup *group;
     579};
     580
     581inline bool operator==(const QGLTextureCacheKey &a, const QGLTextureCacheKey &b)
     582{
     583    return a.key == b.key && a.group == b.group;
     584}
     585
     586inline uint qHash(const QGLTextureCacheKey &key)
     587{
     588    return qHash(key.key) ^ qHash(key.group);
     589}
     590
     591
    533592class Q_AUTOTEST_EXPORT QGLTextureCache {
    534593public:
     
    537596
    538597    void insert(QGLContext *ctx, qint64 key, QGLTexture *texture, int cost);
    539     void remove(quint64 key) { m_cache.remove(key); }
     598    void remove(qint64 key);
     599    inline int size();
     600    inline void setMaxCost(int newMax);
     601    inline int maxCost();
     602    inline QGLTexture* getTexture(QGLContext *ctx, qint64 key);
     603
    540604    bool remove(QGLContext *ctx, GLuint textureId);
    541605    void removeContextTextures(QGLContext *ctx);
    542     int size() { return m_cache.size(); }
    543     void setMaxCost(int newMax) { m_cache.setMaxCost(newMax); }
    544     int maxCost() {return m_cache.maxCost(); }
    545     QGLTexture* getTexture(quint64 key) { return m_cache.object(key); }
    546 
    547606    static QGLTextureCache *instance();
    548     static void deleteIfEmpty();
    549607    static void cleanupTexturesForCacheKey(qint64 cacheKey);
    550608    static void cleanupTexturesForPixampData(QPixmapData* pixmap);
     
    552610
    553611private:
    554     QCache<qint64, QGLTexture> m_cache;
    555 };
    556 
     612    QCache<QGLTextureCacheKey, QGLTexture> m_cache;
     613    QReadWriteLock m_lock;
     614};
     615
     616int QGLTextureCache::size() {
     617    QReadLocker locker(&m_lock);
     618    return m_cache.size();
     619}
     620
     621void QGLTextureCache::setMaxCost(int newMax)
     622{
     623    QWriteLocker locker(&m_lock);
     624    m_cache.setMaxCost(newMax);
     625}
     626
     627int QGLTextureCache::maxCost()
     628{
     629    QReadLocker locker(&m_lock);
     630    return m_cache.maxCost();
     631}
     632
     633QGLTexture* QGLTextureCache::getTexture(QGLContext *ctx, qint64 key)
     634{
     635    QReadLocker locker(&m_lock);
     636    const QGLTextureCacheKey cacheKey = {key, QGLContextPrivate::contextGroup(ctx)};
     637    return m_cache.object(cacheKey);
     638}
    557639
    558640extern Q_OPENGL_EXPORT QPaintEngine* qt_qgl_paint_engine();
Note: See TracChangeset for help on using the changeset viewer.