qopenglgradientcache.cpp

Absolute File Name:/home/qt/qt5_coco/qt5/qtbase/src/gui/opengl/qopenglgradientcache.cpp
Switch to Source codePreprocessed file
LineSourceCount
1-
2-
3-
4-
5-
6-
7-
8class QOpenGL2GradientCacheWrapper-
9{-
10public:-
11 QOpenGL2GradientCache *cacheForContext(QOpenGLContext *context) {-
12 QMutexLocker lock(&m_mutex);-
13 return
never executed: return m_resource.value<QOpenGL2GradientCache>(context);
m_resource.value<QOpenGL2GradientCache>(context);
never executed: return m_resource.value<QOpenGL2GradientCache>(context);
0
14 }-
15-
16private:-
17 QOpenGLMultiGroupSharedResource m_resource;-
18 QMutex m_mutex;-
19};-
20-
21namespace { namespace Q_QGS_qt_gradient_caches { typedef QOpenGL2GradientCacheWrapper 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<QOpenGL2GradientCacheWrapper, Q_QGS_qt_gradient_caches::innerFunction, Q_QGS_qt_gradient_caches::guard> qt_gradient_caches;
0
22-
23QOpenGL2GradientCache::QOpenGL2GradientCache(QOpenGLContext *ctx)-
24 : QOpenGLSharedResource(ctx->shareGroup())-
25{-
26}
never executed: end of block
0
27-
28QOpenGL2GradientCache::~QOpenGL2GradientCache()-
29{-
30 cache.clear();-
31}
never executed: end of block
0
32-
33QOpenGL2GradientCache *QOpenGL2GradientCache::cacheForContext(QOpenGLContext *context)-
34{-
35 return
never executed: return qt_gradient_caches()->cacheForContext(context);
qt_gradient_caches()->cacheForContext(context);
never executed: return qt_gradient_caches()->cacheForContext(context);
0
36}-
37-
38void QOpenGL2GradientCache::invalidateResource()-
39{-
40 QMutexLocker lock(&m_mutex);-
41 cache.clear();-
42}
never executed: end of block
0
43-
44void QOpenGL2GradientCache::freeResource(QOpenGLContext *)-
45{-
46 cleanCache();-
47}
never executed: end of block
0
48-
49void QOpenGL2GradientCache::cleanCache()-
50{-
51 QMutexLocker lock(&m_mutex);-
52 QOpenGLGradientColorTableHash::const_iterator it = cache.constBegin();-
53 QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();-
54 for (; it != cache.constEnd()
it != cache.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
; ++it) {
0
55 const CacheInfo &cache_info = it.value();-
56 funcs->glDeleteTextures(1, &cache_info.texId);-
57 }
never executed: end of block
0
58 cache.clear();-
59}
never executed: end of block
0
60-
61GLuint QOpenGL2GradientCache::getBuffer(const QGradient &gradient, qreal opacity)-
62{-
63 quint64 hash_val = 0;-
64-
65 const QGradientStops stops = gradient.stops();-
66 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
67 hash_val += stops[i].second.rgba();
never executed: hash_val += stops[i].second.rgba();
0
68-
69 const QMutexLocker lock(&m_mutex);-
70 QOpenGLGradientColorTableHash::const_iterator it = cache.constFind(hash_val);-
71-
72 if (it == cache.constEnd()
it == cache.constEnd()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
73 return
never executed: return addCacheElement(hash_val, gradient, opacity);
addCacheElement(hash_val, gradient, opacity);
never executed: return addCacheElement(hash_val, gradient, opacity);
0
74 else {-
75 do {-
76 const CacheInfo &cache_info = it.value();-
77 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
78 && cache_info.interpolationMode == gradient.interpolationMode()
cache_info.int...polationMode()Description
TRUEnever evaluated
FALSEnever evaluated
)
0
79 {-
80 return
never executed: return cache_info.texId;
cache_info.texId;
never executed: return cache_info.texId;
0
81 }-
82 ++it;-
83 }
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
84-
85 return
never executed: return addCacheElement(hash_val, gradient, opacity);
addCacheElement(hash_val, gradient, opacity);
never executed: return addCacheElement(hash_val, gradient, opacity);
0
86 }-
87}-
88-
89-
90GLuint QOpenGL2GradientCache::addCacheElement(quint64 hash_val, const QGradient &gradient, qreal opacity)-
91{-
92 QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions();-
93 if (cache.size() == maxCacheSize()
cache.size() == maxCacheSize()Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
94 int elem_to_remove = qrand() % maxCacheSize();-
95 quint64 key = cache.keys()[elem_to_remove];-
96-
97-
98 QOpenGLGradientColorTableHash::const_iterator it = cache.constFind(key);-
99 do {-
100 funcs->glDeleteTextures(1, &it.value().texId);-
101 }
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
102 cache.remove(key);-
103 }
never executed: end of block
0
104-
105 CacheInfo cache_entry(gradient.stops(), opacity, gradient.interpolationMode());-
106 funcs->glGenTextures(1, &cache_entry.texId);-
107 funcs->glBindTexture(0x0DE1, cache_entry.texId);-
108 if (static_cast<
static_cast<QO...ized16Formats)Description
TRUEnever evaluated
FALSEnever evaluated
QOpenGLExtensions *>(funcs)->hasOpenGLExtension(QOpenGLExtensions::Sized16Formats)
static_cast<QO...ized16Formats)Description
TRUEnever evaluated
FALSEnever evaluated
) {
0
109 QRgba64 buffer[1024];-
110 generateGradientColorTable(gradient, buffer, paletteSize(), opacity);-
111 funcs->glTexImage2D(0x0DE1, 0, 0x805B, paletteSize(), 1,-
112 0, 0x1908, 0x1403, buffer);-
113 }
never executed: end of block
else {
0
114 uint buffer[1024];-
115 generateGradientColorTable(gradient, buffer, paletteSize(), opacity);-
116 funcs->glTexImage2D(0x0DE1, 0, 0x1908, paletteSize(), 1,-
117 0, 0x1908, 0x1401, buffer);-
118 }
never executed: end of block
0
119 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
120}-
121-
122-
123-
124void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient, QRgba64 *colorTable, int size, qreal opacity) const-
125{-
126 int pos = 0;-
127 const QGradientStops s = gradient.stops();-
128-
129 bool colorInterpolation = (gradient.interpolationMode() == QGradient::ColorInterpolation);-
130-
131 uint alpha = qRound(opacity * 256);-
132 QRgba64 current_color = combineAlpha256(s[0].second.rgba64(), alpha);-
133 qreal incr = 1.0 / qreal(size);-
134 qreal fpos = 1.5 * incr;-
135 colorTable[pos++] = qPremultiply(current_color);-
136-
137 while (fpos <= s.first().first
fpos <= s.first().firstDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
138 colorTable[pos] = colorTable[pos - 1];-
139 pos++;-
140 fpos += incr;-
141 }
never executed: end of block
0
142-
143 if (colorInterpolation
colorInterpolationDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
144 current_color = qPremultiply(current_color);
never executed: current_color = qPremultiply(current_color);
0
145-
146 const int sLast = s.size() - 1;-
147 for (int i = 0; i < sLast
i < sLastDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
148 qreal delta = 1/(s[i+1].first - s[i].first);-
149 QRgba64 next_color = combineAlpha256(s[i + 1].second.rgba64(), alpha);-
150 if (colorInterpolation
colorInterpolationDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
151 next_color = qPremultiply(next_color);
never executed: next_color = qPremultiply(next_color);
0
152-
153 while (fpos < s[i+1].first
fpos < s[i+1].firstDescription
TRUEnever evaluated
FALSEnever evaluated
&& pos < size
pos < sizeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
154 int dist = int(256 * ((fpos - s[i].first) * delta));-
155 int idist = 256 - dist;-
156 if (colorInterpolation
colorInterpolationDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
157 colorTable[pos] = interpolate256(current_color, idist, next_color, dist);
never executed: colorTable[pos] = interpolate256(current_color, idist, next_color, dist);
0
158 else-
159 colorTable[pos] = qPremultiply(interpolate256(current_color, idist, next_color, dist));
never executed: colorTable[pos] = qPremultiply(interpolate256(current_color, idist, next_color, dist));
0
160 ++pos;-
161 fpos += incr;-
162 }
never executed: end of block
0
163 current_color = next_color;-
164 }
never executed: end of block
0
165-
166 ((!(s.size() > 0)) ? qt_assert("s.size() > 0",__FILE__,212) : qt_noop());-
167-
168 QRgba64 last_color = qPremultiply(combineAlpha256(s[sLast].second.rgba64(), alpha));-
169 for (;pos < size
pos < sizeDescription
TRUEnever evaluated
FALSEnever evaluated
; ++pos)
0
170 colorTable[pos] = last_color;
never executed: colorTable[pos] = last_color;
0
171-
172-
173 colorTable[size-1] = last_color;-
174}
never executed: end of block
0
175-
176void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient, uint *colorTable, int size, qreal opacity) const-
177{-
178 int pos = 0;-
179 const QGradientStops s = gradient.stops();-
180-
181 bool colorInterpolation = (gradient.interpolationMode() == QGradient::ColorInterpolation);-
182-
183 uint alpha = qRound(opacity * 256);-
184-
185 uint current_color = ((((s[0].second.rgba() >> 24) * alpha) >> 8) << 24) | (s[0].second.rgba() & 0x00ffffff);-
186 qreal incr = 1.0 / qreal(size);-
187 qreal fpos = 1.5 * incr;-
188 colorTable[pos++] = ARGB2RGBA(qPremultiply(current_color));-
189-
190 while (fpos <= s.first().first
fpos <= s.first().firstDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
191 colorTable[pos] = colorTable[pos - 1];-
192 pos++;-
193 fpos += incr;-
194 }
never executed: end of block
0
195-
196 if (colorInterpolation
colorInterpolationDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
197 current_color = qPremultiply(current_color);
never executed: current_color = qPremultiply(current_color);
0
198-
199 const int sLast = s.size() - 1;-
200 for (int i = 0; i < sLast
i < sLastDescription
TRUEnever evaluated
FALSEnever evaluated
; ++i) {
0
201 qreal delta = 1/(s[i+1].first - s[i].first);-
202 uint next_color = ((((s[i + 1].second.rgba() >> 24) * alpha) >> 8) << 24) | (s[i + 1].second.rgba() & 0x00ffffff);-
203 if (colorInterpolation
colorInterpolationDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
204 next_color = qPremultiply(next_color);
never executed: next_color = qPremultiply(next_color);
0
205-
206 while (fpos < s[i+1].first
fpos < s[i+1].firstDescription
TRUEnever evaluated
FALSEnever evaluated
&& pos < size
pos < sizeDescription
TRUEnever evaluated
FALSEnever evaluated
) {
0
207 int dist = int(256 * ((fpos - s[i].first) * delta));-
208 int idist = 256 - dist;-
209 if (colorInterpolation
colorInterpolationDescription
TRUEnever evaluated
FALSEnever evaluated
)
0
210 colorTable[pos] = ARGB2RGBA(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist));
never executed: colorTable[pos] = ARGB2RGBA(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist));
0
211 else-
212 colorTable[pos] = ARGB2RGBA(qPremultiply(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist)));
never executed: colorTable[pos] = ARGB2RGBA(qPremultiply(INTERPOLATE_PIXEL_256(current_color, idist, next_color, dist)));
0
213 ++pos;-
214 fpos += incr;-
215 }
never executed: end of block
0
216 current_color = next_color;-
217 }
never executed: end of block
0
218-
219 ((!(s.size() > 0)) ? qt_assert("s.size() > 0",__FILE__,265) : qt_noop());-
220-
221 uint last_color = ARGB2RGBA(qPremultiply(((((s[sLast].second.rgba() >> 24) * alpha) >> 8) << 24) | (s[sLast].second.rgba() & 0x00ffffff)));-
222 for (;pos < size
pos < sizeDescription
TRUEnever evaluated
FALSEnever evaluated
; ++pos)
0
223 colorTable[pos] = last_color;
never executed: colorTable[pos] = last_color;
0
224-
225-
226 colorTable[size-1] = last_color;-
227}
never executed: end of block
0
228-
229-
Switch to Source codePreprocessed file

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