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/gl2paintengineex/qglgradientcache.cpp

    r2 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    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 have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    4545#include "qglgradientcache_p.h"
    4646
    47 void QGLGradientCache::cleanCache() {
     47QT_BEGIN_NAMESPACE
     48
     49static void QGL2GradientCache_free(void *ptr)
     50{
     51    delete reinterpret_cast<QGL2GradientCache *>(ptr);
     52}
     53
     54Q_GLOBAL_STATIC_WITH_ARGS(QGLContextResource, qt_gradient_caches, (QGL2GradientCache_free))
     55
     56QGL2GradientCache *QGL2GradientCache::cacheForContext(const QGLContext *context)
     57{
     58    QGL2GradientCache *p = reinterpret_cast<QGL2GradientCache *>(qt_gradient_caches()->value(context));
     59    if (!p) {
     60        QGLShareContextScope scope(context);
     61        p = new QGL2GradientCache;
     62        qt_gradient_caches()->insert(context, p);
     63    }
     64    return p;
     65}
     66
     67void QGL2GradientCache::cleanCache() {
    4868    QGLGradientColorTableHash::const_iterator it = cache.constBegin();
    4969    for (; it != cache.constEnd(); ++it) {
     
    5474}
    5575
    56 GLuint QGLGradientCache::getBuffer(const QGradient &gradient, qreal opacity, const QGLContext *ctx)
     76GLuint QGL2GradientCache::getBuffer(const QGradient &gradient, qreal opacity)
    5777{
    58     if (buffer_ctx && !qgl_share_reg()->checkSharing(buffer_ctx, ctx))
    59         cleanCache();
    60 
    61     buffer_ctx = ctx;
    62 
    6378    quint64 hash_val = 0;
    6479
     
    85100
    86101
    87 GLuint QGLGradientCache::addCacheElement(quint64 hash_val, const QGradient &gradient, qreal opacity)
     102GLuint QGL2GradientCache::addCacheElement(quint64 hash_val, const QGradient &gradient, qreal opacity)
    88103{
    89104    if (cache.size() == maxCacheSize()) {
     
    110125
    111126
    112 // GL's expects pixels in RGBA, bin-endian (ABGR on x86).
    113 // Qt stores in ARGB using whatever byte-order the mancine uses.
     127// GL's expects pixels in RGBA (when using GL_RGBA), bin-endian (ABGR on x86).
     128// Qt always stores in ARGB reguardless of the byte-order the mancine uses.
    114129static inline uint qtToGlColor(uint c)
    115130{
    116131    uint o;
    117132#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
    118     o = c & 0xFF00FF00; // alpha & green already in the right place
    119     o |= (c >> 16) & 0x000000FF; // red
    120     o |= (c << 16) & 0x00FF0000; // blue
    121 
     133    o = (c & 0xff00ff00)  // alpha & green already in the right place
     134        | ((c >> 16) & 0x000000ff) // red
     135        | ((c << 16) & 0x00ff0000); // blue
    122136#else //Q_BIG_ENDIAN
    123     o = c & 0x00FF00FF; // alpha & green already in the right place
    124     o |= (c << 16) & 0xFF000000; // red
    125     o |= (c >> 16) & 0x0000FF00; // blue
    126 #error big endian not tested with QGLGraphicsContext
     137    o = (c << 8)
     138        | ((c >> 24) & 0x000000ff);
    127139#endif // Q_BYTE_ORDER
    128140    return o;
     
    130142
    131143//TODO: Let GL generate the texture using an FBO
    132 void QGLGradientCache::generateGradientColorTable(const QGradient& gradient, uint *colorTable, int size, qreal opacity) const
     144void QGL2GradientCache::generateGradientColorTable(const QGradient& gradient, uint *colorTable, int size, qreal opacity) const
    133145{
    134146    int pos = 0;
     
    137149
    138150    for (int i = 0; i < s.size(); ++i)
    139         colors[i] = s[i].second.rgba(); // Qt LIES! It returns ARGB
     151        colors[i] = s[i].second.rgba(); // Qt LIES! It returns ARGB (on little-endian AND on big-endian)
    140152
    141153    bool colorInterpolation = (gradient.interpolationMode() == QGradient::ColorInterpolation);
     
    184196    colorTable[size-1] = last_color;
    185197}
     198
     199QT_END_NAMESPACE
Note: See TracChangeset for help on using the changeset viewer.