43 #include <private/qdrawhelper_p.h> 44 #include <private/qgl_p.h> 45 #include <QtCore/qmutex.h> 72 QGLGradientColorTableHash::const_iterator
it = cache.constBegin();
73 for (; it != cache.constEnd(); ++
it) {
75 glDeleteTextures(1, &cache_info.
texId);
86 for (
int i = 0; i < stops.
size() && i <= 2; i++)
87 hash_val += stops[i].second.rgba();
89 QGLGradientColorTableHash::const_iterator
it = cache.constFind(hash_val);
91 if (it == cache.constEnd())
92 return addCacheElement(hash_val, gradient, opacity);
96 if (cache_info.
stops == stops && cache_info.
opacity == opacity
99 return cache_info.
texId;
102 }
while (it != cache.constEnd() && it.key() == hash_val);
104 return addCacheElement(hash_val, gradient, opacity);
111 if (cache.size() == maxCacheSize()) {
112 int elem_to_remove =
qrand() % maxCacheSize();
116 QGLGradientColorTableHash::const_iterator
it = cache.constFind(key);
118 glDeleteTextures(1, &it.value().texId);
119 }
while (++it != cache.constEnd() && it.key() ==
key);
125 generateGradientColorTable(gradient, buffer, paletteSize(), opacity);
126 glGenTextures(1, &cache_entry.texId);
130 return cache.insert(hash_val, cache_entry).value().texId;
139 #if Q_BYTE_ORDER == Q_LITTLE_ENDIAN 141 | ((c >> 16) & 0x000000ff)
142 | ((c << 16) & 0x00ff0000);
145 | ((c >> 24) & 0x000000ff);
146 #endif // Q_BYTE_ORDER 157 for (
int i = 0; i < s.
size(); ++i)
158 colors[i] = s[i].second.rgba();
165 qreal fpos = 1.5 * incr;
169 colorTable[pos] = colorTable[pos - 1];
174 if (colorInterpolation)
175 current_color =
PREMUL(current_color);
177 for (
int i = 0; i < s.
size() - 1; ++i) {
180 if (colorInterpolation)
181 next_color =
PREMUL(next_color);
183 while (fpos < s[i+1].first && pos < size) {
184 int dist = int(256 * ((fpos - s[i].first) * delta));
185 int idist = 256 - dist;
186 if (colorInterpolation)
193 current_color = next_color;
199 for (;pos < size; ++pos)
200 colorTable[pos] = last_color;
203 colorTable[size-1] = last_color;
GLuint addCacheElement(quint64 hash_val, const QGradient &gradient, qreal opacity)
T * value(const QGLContext *context)
#define QT_END_NAMESPACE
This macro expands to.
The QMutex class provides access serialization between threads.
#define it(className, varName)
T & first()
Returns a reference to the first item in the vector.
QGL2GradientCache * cacheForContext(const QGLContext *context)
Q_CORE_EXPORT int qrand()
InterpolationMode interpolationMode() const
Returns the interpolation mode of this gradient.
static uint qtToGlColor(uint c)
QGradientStops stops() const
Returns the stop points for this gradient.
#define ARGB_COMBINE_ALPHA(argb, alpha)
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QGLContext class encapsulates an OpenGL rendering context.
QGradient::InterpolationMode interpolationMode
Q_STATIC_INLINE_FUNCTION uint PREMUL(uint x)
Q_STATIC_INLINE_FUNCTION uint INTERPOLATE_PIXEL_256(uint x, uint a, uint y, uint b)
#define Q_GLOBAL_STATIC(TYPE, NAME)
Declares a global static variable with the given type and name.
GLuint getBuffer(const QGradient &gradient, qreal opacity)
The QMutexLocker class is a convenience class that simplifies locking and unlocking mutexes...
static QGL2GradientCache * cacheForContext(const QGLContext *context)
The QGradient class is used in combination with QBrush to specify gradient fills. ...
void generateGradientColorTable(const QGradient &gradient, uint *colorTable, int size, qreal opacity) const
QGLContextGroupResource< QGL2GradientCache > m_resource
static QReadWriteLock lock
int size() const
Returns the number of items in the vector.
Q_DECL_CONSTEXPR int qRound(qreal d)