Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/opengl/qopenglgradientcache.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | class QOpenGL2GradientCacheWrapper | - | ||||||||||||||||||
9 | { | - | ||||||||||||||||||
10 | public: | - | ||||||||||||||||||
11 | QOpenGL2GradientCache *cacheForContext(QOpenGLContext *context) { | - | ||||||||||||||||||
12 | QMutexLocker lock(&m_mutex); | - | ||||||||||||||||||
13 | return never executed: m_resource.value<QOpenGL2GradientCache>(context);return m_resource.value<QOpenGL2GradientCache>(context); never executed: return m_resource.value<QOpenGL2GradientCache>(context); | 0 | ||||||||||||||||||
14 | } | - | ||||||||||||||||||
15 | - | |||||||||||||||||||
16 | private: | - | ||||||||||||||||||
17 | QOpenGLMultiGroupSharedResource m_resource; | - | ||||||||||||||||||
18 | QMutex m_mutex; | - | ||||||||||||||||||
19 | }; | - | ||||||||||||||||||
20 | - | |||||||||||||||||||
21 | namespace { 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
never executed: }guard.store(QtGlobalStatic::Destroyed); never executed: }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; returnend of block never executed: &holder.value;return &holder.value; never executed: } } } static QGlobalStatic<QOpenGL2GradientCacheWrapper, Q_QGS_qt_gradient_caches::innerFunction, Q_QGS_qt_gradient_caches::guard> qt_gradient_caches;return &holder.value; | 0 | ||||||||||||||||||
22 | - | |||||||||||||||||||
23 | QOpenGL2GradientCache::QOpenGL2GradientCache(QOpenGLContext *ctx) | - | ||||||||||||||||||
24 | : QOpenGLSharedResource(ctx->shareGroup()) | - | ||||||||||||||||||
25 | { | - | ||||||||||||||||||
26 | } never executed: end of block | 0 | ||||||||||||||||||
27 | - | |||||||||||||||||||
28 | QOpenGL2GradientCache::~QOpenGL2GradientCache() | - | ||||||||||||||||||
29 | { | - | ||||||||||||||||||
30 | cache.clear(); | - | ||||||||||||||||||
31 | } never executed: end of block | 0 | ||||||||||||||||||
32 | - | |||||||||||||||||||
33 | QOpenGL2GradientCache *QOpenGL2GradientCache::cacheForContext(QOpenGLContext *context) | - | ||||||||||||||||||
34 | { | - | ||||||||||||||||||
35 | return never executed: qt_gradient_caches()->cacheForContext(context);return qt_gradient_caches()->cacheForContext(context); never executed: return qt_gradient_caches()->cacheForContext(context); | 0 | ||||||||||||||||||
36 | } | - | ||||||||||||||||||
37 | - | |||||||||||||||||||
38 | void QOpenGL2GradientCache::invalidateResource() | - | ||||||||||||||||||
39 | { | - | ||||||||||||||||||
40 | QMutexLocker lock(&m_mutex); | - | ||||||||||||||||||
41 | cache.clear(); | - | ||||||||||||||||||
42 | } never executed: end of block | 0 | ||||||||||||||||||
43 | - | |||||||||||||||||||
44 | void QOpenGL2GradientCache::freeResource(QOpenGLContext *) | - | ||||||||||||||||||
45 | { | - | ||||||||||||||||||
46 | cleanCache(); | - | ||||||||||||||||||
47 | } never executed: end of block | 0 | ||||||||||||||||||
48 | - | |||||||||||||||||||
49 | void 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()
| 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 | - | |||||||||||||||||||
61 | GLuint QOpenGL2GradientCache::getBuffer(const QGradient &gradient, qreal opacity) | - | ||||||||||||||||||
62 | { | - | ||||||||||||||||||
63 | quint64 hash_val = 0; | - | ||||||||||||||||||
64 | - | |||||||||||||||||||
65 | QGradientStops stops = gradient.stops(); | - | ||||||||||||||||||
66 | for (int i = 0; i < stops.size()
| 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()
| 0 | ||||||||||||||||||
73 | return never executed: addCacheElement(hash_val, gradient, opacity);return 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
| 0 | ||||||||||||||||||
78 | && cache_info.interpolationMode == gradient.interpolationMode()
| 0 | ||||||||||||||||||
79 | { | - | ||||||||||||||||||
80 | return never executed: cache_info.texId;return cache_info.texId; never executed: return cache_info.texId; | 0 | ||||||||||||||||||
81 | } | - | ||||||||||||||||||
82 | ++it; | - | ||||||||||||||||||
83 | } never executed: while (it != cache.constEnd()end of block
| 0 | ||||||||||||||||||
84 | - | |||||||||||||||||||
85 | return never executed: addCacheElement(hash_val, gradient, opacity);return addCacheElement(hash_val, gradient, opacity); never executed: return addCacheElement(hash_val, gradient, opacity); | 0 | ||||||||||||||||||
86 | } | - | ||||||||||||||||||
87 | } | - | ||||||||||||||||||
88 | - | |||||||||||||||||||
89 | - | |||||||||||||||||||
90 | GLuint QOpenGL2GradientCache::addCacheElement(quint64 hash_val, const QGradient &gradient, qreal opacity) | - | ||||||||||||||||||
91 | { | - | ||||||||||||||||||
92 | QOpenGLFunctions *funcs = QOpenGLContext::currentContext()->functions(); | - | ||||||||||||||||||
93 | if (cache.size() == maxCacheSize()
| 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: while (++end of block
| 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<
| 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: else {end of block | 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: cache.insert(hash_val, cache_entry).value().texId;return cache.insert(hash_val, cache_entry).value().texId; never executed: return cache.insert(hash_val, cache_entry).value().texId; | 0 | ||||||||||||||||||
120 | } | - | ||||||||||||||||||
121 | - | |||||||||||||||||||
122 | - | |||||||||||||||||||
123 | - | |||||||||||||||||||
124 | void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient, QRgba64 *colorTable, int size, qreal opacity) const | - | ||||||||||||||||||
125 | { | - | ||||||||||||||||||
126 | int pos = 0; | - | ||||||||||||||||||
127 | QGradientStops s = gradient.stops(); | - | ||||||||||||||||||
128 | QVector<QRgba64> colors(s.size()); | - | ||||||||||||||||||
129 | - | |||||||||||||||||||
130 | for (int i = 0; i < s.size()
| 0 | ||||||||||||||||||
131 | colors[i] = s[i].second.rgba64(); never executed: colors[i] = s[i].second.rgba64(); | 0 | ||||||||||||||||||
132 | - | |||||||||||||||||||
133 | bool colorInterpolation = (gradient.interpolationMode() == QGradient::ColorInterpolation); | - | ||||||||||||||||||
134 | - | |||||||||||||||||||
135 | uint alpha = qRound(opacity * 256); | - | ||||||||||||||||||
136 | QRgba64 current_color = combineAlpha256(colors[0], alpha); | - | ||||||||||||||||||
137 | qreal incr = 1.0 / qreal(size); | - | ||||||||||||||||||
138 | qreal fpos = 1.5 * incr; | - | ||||||||||||||||||
139 | colorTable[pos++] = qPremultiply(current_color); | - | ||||||||||||||||||
140 | - | |||||||||||||||||||
141 | while (fpos <= s.first().first
| 0 | ||||||||||||||||||
142 | colorTable[pos] = colorTable[pos - 1]; | - | ||||||||||||||||||
143 | pos++; | - | ||||||||||||||||||
144 | fpos += incr; | - | ||||||||||||||||||
145 | } never executed: end of block | 0 | ||||||||||||||||||
146 | - | |||||||||||||||||||
147 | if (colorInterpolation
| 0 | ||||||||||||||||||
148 | current_color = qPremultiply(current_color); never executed: current_color = qPremultiply(current_color); | 0 | ||||||||||||||||||
149 | - | |||||||||||||||||||
150 | for (int i = 0; i < s.size() - 1
| 0 | ||||||||||||||||||
151 | qreal delta = 1/(s[i+1].first - s[i].first); | - | ||||||||||||||||||
152 | QRgba64 next_color = combineAlpha256(colors[i+1], alpha); | - | ||||||||||||||||||
153 | if (colorInterpolation
| 0 | ||||||||||||||||||
154 | next_color = qPremultiply(next_color); never executed: next_color = qPremultiply(next_color); | 0 | ||||||||||||||||||
155 | - | |||||||||||||||||||
156 | while (fpos < s[i+1].first
| 0 | ||||||||||||||||||
157 | int dist = int(256 * ((fpos - s[i].first) * delta)); | - | ||||||||||||||||||
158 | int idist = 256 - dist; | - | ||||||||||||||||||
159 | if (colorInterpolation
| 0 | ||||||||||||||||||
160 | colorTable[pos] = interpolate256(current_color, idist, next_color, dist); never executed: colorTable[pos] = interpolate256(current_color, idist, next_color, dist); | 0 | ||||||||||||||||||
161 | else | - | ||||||||||||||||||
162 | colorTable[pos] = qPremultiply(interpolate256(current_color, idist, next_color, dist)); never executed: colorTable[pos] = qPremultiply(interpolate256(current_color, idist, next_color, dist)); | 0 | ||||||||||||||||||
163 | ++pos; | - | ||||||||||||||||||
164 | fpos += incr; | - | ||||||||||||||||||
165 | } never executed: end of block | 0 | ||||||||||||||||||
166 | current_color = next_color; | - | ||||||||||||||||||
167 | } never executed: end of block | 0 | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | ((!(s.size() > 0)) ? qt_assert("s.size() > 0",__FILE__,209) : qt_noop()); | - | ||||||||||||||||||
170 | - | |||||||||||||||||||
171 | QRgba64 last_color = qPremultiply(combineAlpha256(colors[s.size() - 1], alpha)); | - | ||||||||||||||||||
172 | for (;pos < size
| 0 | ||||||||||||||||||
173 | colorTable[pos] = last_color; never executed: colorTable[pos] = last_color; | 0 | ||||||||||||||||||
174 | - | |||||||||||||||||||
175 | - | |||||||||||||||||||
176 | colorTable[size-1] = last_color; | - | ||||||||||||||||||
177 | } never executed: end of block | 0 | ||||||||||||||||||
178 | - | |||||||||||||||||||
179 | void QOpenGL2GradientCache::generateGradientColorTable(const QGradient& gradient, uint *colorTable, int size, qreal opacity) const | - | ||||||||||||||||||
180 | { | - | ||||||||||||||||||
181 | int pos = 0; | - | ||||||||||||||||||
182 | QGradientStops s = gradient.stops(); | - | ||||||||||||||||||
183 | QVector<uint> colors(s.size()); | - | ||||||||||||||||||
184 | - | |||||||||||||||||||
185 | for (int i = 0; i < s.size()
| 0 | ||||||||||||||||||
186 | colors[i] = s[i].second.rgba(); never executed: colors[i] = s[i].second.rgba(); | 0 | ||||||||||||||||||
187 | - | |||||||||||||||||||
188 | bool colorInterpolation = (gradient.interpolationMode() == QGradient::ColorInterpolation); | - | ||||||||||||||||||
189 | - | |||||||||||||||||||
190 | uint alpha = qRound(opacity * 256); | - | ||||||||||||||||||
191 | uint current_color = ((((colors[0] >> 24) * alpha) >> 8) << 24) | (colors[0] & 0x00ffffff); | - | ||||||||||||||||||
192 | qreal incr = 1.0 / qreal(size); | - | ||||||||||||||||||
193 | qreal fpos = 1.5 * incr; | - | ||||||||||||||||||
194 | colorTable[pos++] = ARGB2RGBA(qPremultiply(current_color)); | - | ||||||||||||||||||
195 | - | |||||||||||||||||||
196 | while (fpos <= s.first().first
| 0 | ||||||||||||||||||
197 | colorTable[pos] = colorTable[pos - 1]; | - | ||||||||||||||||||
198 | pos++; | - | ||||||||||||||||||
199 | fpos += incr; | - | ||||||||||||||||||
200 | } never executed: end of block | 0 | ||||||||||||||||||
201 | - | |||||||||||||||||||
202 | if (colorInterpolation
| 0 | ||||||||||||||||||
203 | current_color = qPremultiply(current_color); never executed: current_color = qPremultiply(current_color); | 0 | ||||||||||||||||||
204 | - | |||||||||||||||||||
205 | for (int i = 0; i < s.size() - 1
| 0 | ||||||||||||||||||
206 | qreal delta = 1/(s[i+1].first - s[i].first); | - | ||||||||||||||||||
207 | uint next_color = ((((colors[i+1] >> 24) * alpha) >> 8) << 24) | (colors[i+1] & 0x00ffffff); | - | ||||||||||||||||||
208 | if (colorInterpolation
| 0 | ||||||||||||||||||
209 | next_color = qPremultiply(next_color); never executed: next_color = qPremultiply(next_color); | 0 | ||||||||||||||||||
210 | - | |||||||||||||||||||
211 | while (fpos < s[i+1].first
| 0 | ||||||||||||||||||
212 | int dist = int(256 * ((fpos - s[i].first) * delta)); | - | ||||||||||||||||||
213 | int idist = 256 - dist; | - | ||||||||||||||||||
214 | if (colorInterpolation
| 0 | ||||||||||||||||||
215 | 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 | ||||||||||||||||||
216 | else | - | ||||||||||||||||||
217 | 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 | ||||||||||||||||||
218 | ++pos; | - | ||||||||||||||||||
219 | fpos += incr; | - | ||||||||||||||||||
220 | } never executed: end of block | 0 | ||||||||||||||||||
221 | current_color = next_color; | - | ||||||||||||||||||
222 | } never executed: end of block | 0 | ||||||||||||||||||
223 | - | |||||||||||||||||||
224 | ((!(s.size() > 0)) ? qt_assert("s.size() > 0",__FILE__,264) : qt_noop()); | - | ||||||||||||||||||
225 | - | |||||||||||||||||||
226 | uint last_color = ARGB2RGBA(qPremultiply(((((colors[s.size() - 1] >> 24) * alpha) >> 8) << 24) | (colors[s.size() - 1] & 0x00ffffff))); | - | ||||||||||||||||||
227 | for (;pos < size
| 0 | ||||||||||||||||||
228 | colorTable[pos] = last_color; never executed: colorTable[pos] = last_color; | 0 | ||||||||||||||||||
229 | - | |||||||||||||||||||
230 | - | |||||||||||||||||||
231 | colorTable[size-1] = last_color; | - | ||||||||||||||||||
232 | } never executed: end of block | 0 | ||||||||||||||||||
233 | - | |||||||||||||||||||
234 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |