qglgradientcache.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/opengl/gl2paintengineex/qglgradientcache.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4class QGL2GradientCacheWrapper-
5{-
6public:-
7 QGL2GradientCache *cacheForContext(const QGLContext *context) {-
8 QMutexLocker lock(&m_mutex);-
9 return
never executed: return m_resource.value<QGL2GradientCache>(context->contextHandle());
m_resource.value<QGL2GradientCache>(context->contextHandle());
never executed: return m_resource.value<QGL2GradientCache>(context->contextHandle());
0
10 }-
11-
12private:-
13 QOpenGLMultiGroupSharedResource m_resource;-
14 QMutex m_mutex;-
15};-
16-
17namespace { namespace Q_QGS_qt_gradient_caches { typedef QGL2GradientCacheWrapper Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized
guard.load() =...c::InitializedDescription
TRUEnever evaluated
FALSEnever evaluated
) guard.store(QtGlobalStatic::Destroyed);
never executed: guard.store(QtGlobalStatic::Destroyed);
}
never executed: end of block
}; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return
never executed: return &holder.value;
&holder.value;
never executed: return &holder.value;
} } } static QGlobalStatic<QGL2GradientCacheWrapper, Q_QGS_qt_gradient_caches::innerFunction, Q_QGS_qt_gradient_caches::guard> qt_gradient_caches;
0
18-
19QGL2GradientCache::QGL2GradientCache(QOpenGLContext *ctx)-
20 : QOpenGLSharedResource(ctx->shareGroup())-
21{-
22}
never executed: end of block
0
23-
24QGL2GradientCache::~QGL2GradientCache()-
25{-
26 cache.clear();-
27}
never executed: end of block
0
28-
29QGL2GradientCache *QGL2GradientCache::cacheForContext(const QGLContext *context)-
30{-
31 return
never executed: return qt_gradient_caches()->cacheForContext(context);
qt_gradient_caches()->cacheForContext(context);
never executed: return qt_gradient_caches()->cacheForContext(context);
0
32}-
33-
34void QGL2GradientCache::invalidateResource()-
35{-
36 QMutexLocker lock(&m_mutex);-
37 cache.clear();-
38}
never executed: end of block
0
39-
40void QGL2GradientCache::freeResource(QOpenGLContext *)-
41{-
42 cleanCache();-
43}
never executed: end of block
0
44-
45void QGL2GradientCache::cleanCache()-
46{-
47 QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();-
48 QMutexLocker lock(&m_mutex);-
49 QGLGradientColorTableHash::const_iterator it = cache.constBegin();-
50 for (; it != cache.constEnd()
it != cache.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
; ++it) {
0
51 const CacheInfo &cache_info = it.value();-
52 funcs->glDeleteTextures(1, &cache_info.texId);-
53 }
never executed: end of block
0
54 cache.clear();-
55}
never executed: end of block
0
56-
57GLuint QGL2GradientCache::getBuffer(const QGradient &gradient, qreal opacity)-
58{-
59 QMutexLocker lock(&m_mutex);-
60 quint64 hash_val = 0;-
61-
62 const QGradientStops stops = gradient.stops();-
63 for (int i = 0; i < stops.size()
i < stops.size()Description
TRUEnever evaluated
FALSEnever evaluated
&& i <= 2
i <= 2Description
TRUEnever evaluated
FALSEnever evaluated
; i++)
0
64 hash_val += stops[i].second.rgba();
never executed: hash_val += stops[i].second.rgba();
0
65-
66 QGLGradientColorTableHash::const_iterator it = cache.constFind(hash_val);-
67-
68 if (it == cache.constEnd()
it == cache.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
69 return
never executed: return addCacheElement(hash_val, gradient, opacity);
addCacheElement(hash_val, gradient, opacity);
never executed: return addCacheElement(hash_val, gradient, opacity);
0
70 else {-
71 do {-
72 const CacheInfo &cache_info = it.value();-
73 if (cache_info.stops == stops
cache_info.stops == stopsDescription
TRUEnever evaluated
FALSEnever evaluated
&& cache_info.opacity == opacity
cache_info.opacity == opacityDescription
TRUEnever evaluated
FALSEnever evaluated
0
74 && cache_info.interpolationMode == gradient.interpolationMode()
cache_info.int...polationMode()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
75 {-
76 return
never executed: return cache_info.texId;
cache_info.texId;
never executed: return cache_info.texId;
0
77 }-
78 ++it;-
79 }
never executed: end of block
while (it != cache.constEnd()
it != cache.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
&& it.key() == hash_val
it.key() == hash_valDescription
TRUEnever evaluated
FALSEnever evaluated
);
0
80-
81 return
never executed: return addCacheElement(hash_val, gradient, opacity);
addCacheElement(hash_val, gradient, opacity);
never executed: return addCacheElement(hash_val, gradient, opacity);
0
82 }-
83}-
84-
85-
86GLuint QGL2GradientCache::addCacheElement(quint64 hash_val, const QGradient &gradient, qreal opacity)-
87{-
88 QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();-
89 if (cache.size() == maxCacheSize()
cache.size() == maxCacheSize()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
90 int elem_to_remove = qrand() % maxCacheSize();-
91 quint64 key = cache.keys()[elem_to_remove];-
92-
93-
94 QGLGradientColorTableHash::const_iterator it = cache.constFind(key);-
95 do {-
96 funcs->glDeleteTextures(1, &it.value().texId);-
97 }
never executed: end of block
while (++
++it != cache.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
it != cache.constEnd()
++it != cache.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
&& it.key() == key
it.key() == keyDescription
TRUEnever evaluated
FALSEnever evaluated
);
0
98 cache.remove(key);-
99 }
never executed: end of block
0
100-
101 CacheInfo cache_entry(gradient.stops(), opacity, gradient.interpolationMode());-
102 uint buffer[1024];-
103 generateGradientColorTable(gradient, buffer, paletteSize(), opacity);-
104 funcs->glGenTextures(1, &cache_entry.texId);-
105 funcs->glBindTexture(0x0DE1, cache_entry.texId);-
106 funcs->glTexImage2D(0x0DE1, 0, 0x1908, paletteSize(), 1,-
107 0, 0x1908, 0x1401, buffer);-
108 return
never executed: return cache.insert(hash_val, cache_entry).value().texId;
cache.insert(hash_val, cache_entry).value().texId;
never executed: return cache.insert(hash_val, cache_entry).value().texId;
0
109}-
110-
111-
112-
113-
114static inline uint qtToGlColor(uint c)-
115{-
116 uint o;-
117-
118 o = (c & 0xff00ff00)-
119 | ((c >> 16) & 0x000000ff)-
120 | ((c << 16) & 0x00ff0000);-
121-
122-
123-
124-
125 return
never executed: return o;
o;
never executed: return o;
0
126}-
127-
128-
129void QGL2GradientCache::generateGradientColorTable(const QGradient& gradient, uint *colorTable, int size, qreal opacity) const-
130{-
131 int pos = 0;-
132 const QGradientStops s = gradient.stops();-
133 bool colorInterpolation = (gradient.interpolationMode() == QGradient::ColorInterpolation);-
134-
135 uint alpha = qRound(opacity * 256);-
136-
137 uint current_color = ((((s[0].second.rgba() >> 24) * alpha) >> 8) << 24) | (s[0].second.rgba() & 0x00ffffff);-
138 qreal incr = 1.0 / qreal(size);-
139 qreal fpos = 1.5 * incr;-
140 colorTable[pos++] = qtToGlColor(qPremultiply(current_color));-
141-
142 while (fpos <= s.first().first
fpos <= s.first().firstDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
143 colorTable[pos] = colorTable[pos - 1];-
144 pos++;-
145 fpos += incr;-
146 }
never executed: end of block
0
147-
148 if (colorInterpolation
colorInterpolationDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
149 current_color = qPremultiply(current_color);
never executed: current_color = qPremultiply(current_color);
0
150-
151 const int sLast = s.size() - 1;-
152 for (int i = 0; i < sLast
i < sLastDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
153 qreal delta = 1/(s[i+1].first - s[i].first);-
154 uint next_color = ((((s[i + 1].second.rgba() >> 24) * alpha) >> 8) << 24) | (s[i + 1].second.rgba() & 0x00ffffff);-
155 if (colorInterpolation
colorInterpolationDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
156 next_color = qPremultiply(next_color);
never executed: next_color = qPremultiply(next_color);
0
157-
158 while (fpos < s[i+1].first
fpos < s[i+1].firstDescription
TRUEnever evaluated
FALSEnever evaluated
&& pos < size
pos < sizeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
159 int dist = int(256 * ((fpos - s[i].first) * delta));-
160 int idist = 256 - dist;-
161 if (colorInterpolation
colorInterpolationDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
162 colorTable[pos] = qtToGlColor(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist));
never executed: colorTable[pos] = qtToGlColor(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist));
0
163 else-
164 colorTable[pos] = qtToGlColor(qPremultiply(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist)));
never executed: colorTable[pos] = qtToGlColor(qPremultiply(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist)));
0
165 ++pos;-
166 fpos += incr;-
167 }
never executed: end of block
0
168 current_color = next_color;-
169 }
never executed: end of block
0
170-
171 ((!(s.size() > 0)) ? qt_assert("s.size() > 0",__FILE__,214) : qt_noop());-
172-
173 uint last_color = qtToGlColor(qPremultiply(((((s[sLast].second.rgba() >> 24) * alpha) >> 8) << 24) | (s[sLast].second.rgba() & 0x00ffffff)));-
174 for (;pos < size
pos < sizeDescription
TRUEnever evaluated
FALSEnever evaluated
; ++pos)
0
175 colorTable[pos] = last_color;
never executed: colorTable[pos] = last_color;
0
176-
177-
178 colorTable[size-1] = last_color;-
179}
never executed: end of block
0
180-
181-
Switch to Source codePreprocessed file

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9