Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/gui/kernel/qopenglcontext.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||
2 | - | |||||||||||||
3 | - | |||||||||||||
4 | - | |||||||||||||
5 | - | |||||||||||||
6 | - | |||||||||||||
7 | - | |||||||||||||
8 | - | |||||||||||||
9 | - | |||||||||||||
10 | - | |||||||||||||
11 | - | |||||||||||||
12 | class QOpenGLVersionProfilePrivate | - | ||||||||||||
13 | { | - | ||||||||||||
14 | public: | - | ||||||||||||
15 | QOpenGLVersionProfilePrivate() | - | ||||||||||||
16 | : majorVersion(0), | - | ||||||||||||
17 | minorVersion(0), | - | ||||||||||||
18 | profile(QSurfaceFormat::NoProfile) | - | ||||||||||||
19 | {} | - | ||||||||||||
20 | - | |||||||||||||
21 | int majorVersion; | - | ||||||||||||
22 | int minorVersion; | - | ||||||||||||
23 | QSurfaceFormat::OpenGLContextProfile profile; | - | ||||||||||||
24 | }; | - | ||||||||||||
25 | QOpenGLVersionProfile::QOpenGLVersionProfile() | - | ||||||||||||
26 | : d(new QOpenGLVersionProfilePrivate) | - | ||||||||||||
27 | { | - | ||||||||||||
28 | } | - | ||||||||||||
29 | - | |||||||||||||
30 | - | |||||||||||||
31 | - | |||||||||||||
32 | - | |||||||||||||
33 | - | |||||||||||||
34 | QOpenGLVersionProfile::QOpenGLVersionProfile(const QSurfaceFormat &format) | - | ||||||||||||
35 | : d(new QOpenGLVersionProfilePrivate) | - | ||||||||||||
36 | { | - | ||||||||||||
37 | d->majorVersion = format.majorVersion(); | - | ||||||||||||
38 | d->minorVersion = format.minorVersion(); | - | ||||||||||||
39 | d->profile = format.profile(); | - | ||||||||||||
40 | } | - | ||||||||||||
41 | - | |||||||||||||
42 | - | |||||||||||||
43 | - | |||||||||||||
44 | - | |||||||||||||
45 | QOpenGLVersionProfile::QOpenGLVersionProfile(const QOpenGLVersionProfile &other) | - | ||||||||||||
46 | : d(new QOpenGLVersionProfilePrivate) | - | ||||||||||||
47 | { | - | ||||||||||||
48 | *d = *(other.d); | - | ||||||||||||
49 | } | - | ||||||||||||
50 | - | |||||||||||||
51 | - | |||||||||||||
52 | - | |||||||||||||
53 | - | |||||||||||||
54 | QOpenGLVersionProfile::~QOpenGLVersionProfile() | - | ||||||||||||
55 | { | - | ||||||||||||
56 | delete d; | - | ||||||||||||
57 | } | - | ||||||||||||
58 | - | |||||||||||||
59 | - | |||||||||||||
60 | - | |||||||||||||
61 | - | |||||||||||||
62 | QOpenGLVersionProfile &QOpenGLVersionProfile::operator=(const QOpenGLVersionProfile &rhs) | - | ||||||||||||
63 | { | - | ||||||||||||
64 | if (this == &rhs) | - | ||||||||||||
65 | return *this; | - | ||||||||||||
66 | *d = *(rhs.d); | - | ||||||||||||
67 | return *this; | - | ||||||||||||
68 | } | - | ||||||||||||
69 | - | |||||||||||||
70 | - | |||||||||||||
71 | - | |||||||||||||
72 | - | |||||||||||||
73 | - | |||||||||||||
74 | - | |||||||||||||
75 | - | |||||||||||||
76 | QPair<int, int> QOpenGLVersionProfile::version() const | - | ||||||||||||
77 | { | - | ||||||||||||
78 | return qMakePair( d->majorVersion, d->minorVersion); | - | ||||||||||||
79 | } | - | ||||||||||||
80 | - | |||||||||||||
81 | - | |||||||||||||
82 | - | |||||||||||||
83 | - | |||||||||||||
84 | - | |||||||||||||
85 | - | |||||||||||||
86 | void QOpenGLVersionProfile::setVersion(int majorVersion, int minorVersion) | - | ||||||||||||
87 | { | - | ||||||||||||
88 | d->majorVersion = majorVersion; | - | ||||||||||||
89 | d->minorVersion = minorVersion; | - | ||||||||||||
90 | } | - | ||||||||||||
91 | - | |||||||||||||
92 | - | |||||||||||||
93 | - | |||||||||||||
94 | - | |||||||||||||
95 | - | |||||||||||||
96 | - | |||||||||||||
97 | QSurfaceFormat::OpenGLContextProfile QOpenGLVersionProfile::profile() const | - | ||||||||||||
98 | { | - | ||||||||||||
99 | return d->profile; | - | ||||||||||||
100 | } | - | ||||||||||||
101 | - | |||||||||||||
102 | - | |||||||||||||
103 | - | |||||||||||||
104 | - | |||||||||||||
105 | - | |||||||||||||
106 | - | |||||||||||||
107 | - | |||||||||||||
108 | void QOpenGLVersionProfile::setProfile(QSurfaceFormat::OpenGLContextProfile profile) | - | ||||||||||||
109 | { | - | ||||||||||||
110 | d->profile = profile; | - | ||||||||||||
111 | } | - | ||||||||||||
112 | - | |||||||||||||
113 | - | |||||||||||||
114 | - | |||||||||||||
115 | - | |||||||||||||
116 | - | |||||||||||||
117 | - | |||||||||||||
118 | - | |||||||||||||
119 | bool QOpenGLVersionProfile::hasProfiles() const | - | ||||||||||||
120 | { | - | ||||||||||||
121 | return ( d->majorVersion > 3 | - | ||||||||||||
122 | || (d->majorVersion == 3 && d->minorVersion > 1)); | - | ||||||||||||
123 | } | - | ||||||||||||
124 | - | |||||||||||||
125 | - | |||||||||||||
126 | - | |||||||||||||
127 | - | |||||||||||||
128 | - | |||||||||||||
129 | bool QOpenGLVersionProfile::isLegacyVersion() const | - | ||||||||||||
130 | { | - | ||||||||||||
131 | return (d->majorVersion < 3 || (d->majorVersion == 3 && d->minorVersion == 0)); | - | ||||||||||||
132 | } | - | ||||||||||||
133 | - | |||||||||||||
134 | - | |||||||||||||
135 | - | |||||||||||||
136 | - | |||||||||||||
137 | - | |||||||||||||
138 | - | |||||||||||||
139 | - | |||||||||||||
140 | bool QOpenGLVersionProfile::isValid() const | - | ||||||||||||
141 | { | - | ||||||||||||
142 | return d->majorVersion > 0 && d->minorVersion >= 0; | - | ||||||||||||
143 | } | - | ||||||||||||
144 | - | |||||||||||||
145 | class QGuiGLThreadContext | - | ||||||||||||
146 | { | - | ||||||||||||
147 | public: | - | ||||||||||||
148 | QGuiGLThreadContext() | - | ||||||||||||
149 | : context(0) | - | ||||||||||||
150 | { | - | ||||||||||||
151 | } | - | ||||||||||||
152 | ~QGuiGLThreadContext() { | - | ||||||||||||
153 | if (context) | - | ||||||||||||
154 | context->doneCurrent(); | - | ||||||||||||
155 | } | - | ||||||||||||
156 | QOpenGLContext *context; | - | ||||||||||||
157 | }; | - | ||||||||||||
158 | - | |||||||||||||
159 | namespace { namespace Q_QGS_qwindow_context_storage { typedef QThreadStorage<QGuiGLThreadContext *> Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<QThreadStorage<QGuiGLThreadContext *>, Q_QGS_qwindow_context_storage::innerFunction, Q_QGS_qwindow_context_storage::guard> qwindow_context_storage;; | - | ||||||||||||
160 | static QOpenGLContext *global_share_context = 0; | - | ||||||||||||
161 | - | |||||||||||||
162 | - | |||||||||||||
163 | QHash<QOpenGLContext *, bool> QOpenGLContextPrivate::makeCurrentTracker; | - | ||||||||||||
164 | QMutex QOpenGLContextPrivate::makeCurrentTrackerMutex; | - | ||||||||||||
165 | void qt_gl_set_global_share_context(QOpenGLContext *context) | - | ||||||||||||
166 | { | - | ||||||||||||
167 | global_share_context = context; | - | ||||||||||||
168 | } | - | ||||||||||||
169 | - | |||||||||||||
170 | - | |||||||||||||
171 | - | |||||||||||||
172 | - | |||||||||||||
173 | QOpenGLContext *qt_gl_global_share_context() | - | ||||||||||||
174 | { | - | ||||||||||||
175 | return global_share_context; | - | ||||||||||||
176 | } | - | ||||||||||||
177 | QOpenGLContext *QOpenGLContextPrivate::setCurrentContext(QOpenGLContext *context) | - | ||||||||||||
178 | { | - | ||||||||||||
179 | QGuiGLThreadContext *threadContext = qwindow_context_storage()->localData(); | - | ||||||||||||
180 | if (!threadContext) { | - | ||||||||||||
181 | if (!QThread::currentThread()) { | - | ||||||||||||
182 | QMessageLogger(__FILE__, 342348, __PRETTY_FUNCTION__).warning("No QTLS available. currentContext won't work"); | - | ||||||||||||
183 | return 0; | - | ||||||||||||
184 | } | - | ||||||||||||
185 | threadContext = new QGuiGLThreadContext; | - | ||||||||||||
186 | qwindow_context_storage()->setLocalData(threadContext); | - | ||||||||||||
187 | } | - | ||||||||||||
188 | QOpenGLContext *previous = threadContext->context; | - | ||||||||||||
189 | threadContext->context = context; | - | ||||||||||||
190 | return previous; | - | ||||||||||||
191 | } | - | ||||||||||||
192 | - | |||||||||||||
193 | int QOpenGLContextPrivate::maxTextureSize() | - | ||||||||||||
194 | { | - | ||||||||||||
195 | if (max_texture_size != -1) | - | ||||||||||||
196 | return max_texture_size; | - | ||||||||||||
197 | - | |||||||||||||
198 | QOpenGLContext * const q = q_func(); | - | ||||||||||||
199 | QOpenGLFunctions *funcs = q->functions(); | - | ||||||||||||
200 | funcs->glGetIntegerv(0x0D33, &max_texture_size); | - | ||||||||||||
201 | - | |||||||||||||
202 | - | |||||||||||||
203 | if (!q->isOpenGLES()) { | - | ||||||||||||
204 | GLenum proxy = 0x8064; | - | ||||||||||||
205 | - | |||||||||||||
206 | GLint size; | - | ||||||||||||
207 | GLint next = 64; | - | ||||||||||||
208 | funcs->glTexImage2D(proxy, 0, 0x1908, next, next, 0, 0x1908, 0x1401, 0); | - | ||||||||||||
209 | - | |||||||||||||
210 | QOpenGLFunctions_1_0 *gl1funcs = 0; | - | ||||||||||||
211 | QOpenGLFunctions_3_2_Core *gl3funcs = 0; | - | ||||||||||||
212 | - | |||||||||||||
213 | if (q->format().profile() == QSurfaceFormat::CoreProfile) | - | ||||||||||||
214 | gl3funcs = q->versionFunctions<QOpenGLFunctions_3_2_Core>(); | - | ||||||||||||
215 | else | - | ||||||||||||
216 | gl1funcs = q->versionFunctions<QOpenGLFunctions_1_0>(); | - | ||||||||||||
217 | - | |||||||||||||
218 | ((!(gl1funcs || gl3funcs)) ? qt_assert("gl1funcs || gl3funcs",__FILE__,378384) : qt_noop()); | - | ||||||||||||
219 | - | |||||||||||||
220 | if (gl1funcs) | - | ||||||||||||
221 | gl1funcs->glGetTexLevelParameteriv(proxy, 0, 0x1000, &size); | - | ||||||||||||
222 | else | - | ||||||||||||
223 | gl3funcs->glGetTexLevelParameteriv(proxy, 0, 0x1000, &size); | - | ||||||||||||
224 | - | |||||||||||||
225 | if (size == 0) { | - | ||||||||||||
226 | return max_texture_size; | - | ||||||||||||
227 | } | - | ||||||||||||
228 | do { | - | ||||||||||||
229 | size = next; | - | ||||||||||||
230 | next = size * 2; | - | ||||||||||||
231 | - | |||||||||||||
232 | if (next > max_texture_size) | - | ||||||||||||
233 | break; | - | ||||||||||||
234 | funcs->glTexImage2D(proxy, 0, 0x1908, next, next, 0, 0x1908, 0x1401, 0); | - | ||||||||||||
235 | if (gl1funcs) | - | ||||||||||||
236 | gl1funcs->glGetTexLevelParameteriv(proxy, 0, 0x1000, &next); | - | ||||||||||||
237 | else | - | ||||||||||||
238 | gl3funcs->glGetTexLevelParameteriv(proxy, 0, 0x1000, &next); | - | ||||||||||||
239 | - | |||||||||||||
240 | } while (next > size); | - | ||||||||||||
241 | - | |||||||||||||
242 | max_texture_size = size; | - | ||||||||||||
243 | } | - | ||||||||||||
244 | - | |||||||||||||
245 | - | |||||||||||||
246 | return max_texture_size; | - | ||||||||||||
247 | } | - | ||||||||||||
248 | - | |||||||||||||
249 | - | |||||||||||||
250 | - | |||||||||||||
251 | - | |||||||||||||
252 | - | |||||||||||||
253 | QOpenGLContext* QOpenGLContext::currentContext() | - | ||||||||||||
254 | { | - | ||||||||||||
255 | QGuiGLThreadContext *threadContext = qwindow_context_storage()->localData(); | - | ||||||||||||
256 | if (threadContext) { | - | ||||||||||||
257 | return threadContext->context; | - | ||||||||||||
258 | } | - | ||||||||||||
259 | return 0; | - | ||||||||||||
260 | } | - | ||||||||||||
261 | - | |||||||||||||
262 | - | |||||||||||||
263 | - | |||||||||||||
264 | - | |||||||||||||
265 | bool QOpenGLContext::areSharing(QOpenGLContext *first, QOpenGLContext *second) | - | ||||||||||||
266 | { | - | ||||||||||||
267 | return first->shareGroup() == second->shareGroup(); | - | ||||||||||||
268 | } | - | ||||||||||||
269 | - | |||||||||||||
270 | - | |||||||||||||
271 | - | |||||||||||||
272 | - | |||||||||||||
273 | - | |||||||||||||
274 | - | |||||||||||||
275 | QPlatformOpenGLContext *QOpenGLContext::handle() const | - | ||||||||||||
276 | { | - | ||||||||||||
277 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
278 | return d->platformGLContext; | - | ||||||||||||
279 | } | - | ||||||||||||
280 | - | |||||||||||||
281 | - | |||||||||||||
282 | - | |||||||||||||
283 | - | |||||||||||||
284 | - | |||||||||||||
285 | - | |||||||||||||
286 | - | |||||||||||||
287 | QPlatformOpenGLContext *QOpenGLContext::shareHandle() const | - | ||||||||||||
288 | { | - | ||||||||||||
289 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
290 | if (d->shareContext) | - | ||||||||||||
291 | return d->shareContext->handle(); | - | ||||||||||||
292 | return 0; | - | ||||||||||||
293 | } | - | ||||||||||||
294 | QOpenGLContext::QOpenGLContext(QObject *parent) | - | ||||||||||||
295 | : QObject(*new QOpenGLContextPrivate(), parent) | - | ||||||||||||
296 | { | - | ||||||||||||
297 | setScreen(QGuiApplication::primaryScreen()); | - | ||||||||||||
298 | } | - | ||||||||||||
299 | void QOpenGLContext::setFormat(const QSurfaceFormat &format) | - | ||||||||||||
300 | { | - | ||||||||||||
301 | QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
302 | d->requestedFormat = format; | - | ||||||||||||
303 | } | - | ||||||||||||
304 | - | |||||||||||||
305 | - | |||||||||||||
306 | - | |||||||||||||
307 | - | |||||||||||||
308 | - | |||||||||||||
309 | void QOpenGLContext::setShareContext(QOpenGLContext *shareContext) | - | ||||||||||||
310 | { | - | ||||||||||||
311 | QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
312 | d->shareContext = shareContext; | - | ||||||||||||
313 | } | - | ||||||||||||
314 | - | |||||||||||||
315 | - | |||||||||||||
316 | - | |||||||||||||
317 | - | |||||||||||||
318 | - | |||||||||||||
319 | void QOpenGLContext::setScreen(QScreen *screen) | - | ||||||||||||
320 | { | - | ||||||||||||
321 | QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
322 | if (d->screen) | - | ||||||||||||
323 | disconnect(d->screen, qFlagLocation("2""destroyed(QObject*)" "\0" __FILE__ ":" "502""508"), this, qFlagLocation("1""_q_screenDestroyed(QObject*)" "\0" __FILE__ ":" "502""508")); | - | ||||||||||||
324 | d->screen = screen; | - | ||||||||||||
325 | if (!d->screen) | - | ||||||||||||
326 | d->screen = QGuiApplication::primaryScreen(); | - | ||||||||||||
327 | if (d->screen) | - | ||||||||||||
328 | connect(d->screen, qFlagLocation("2""destroyed(QObject*)" "\0" __FILE__ ":" "507""513"), this, qFlagLocation("1""_q_screenDestroyed(QObject*)" "\0" __FILE__ ":" "507""513")); | - | ||||||||||||
329 | } | - | ||||||||||||
330 | - | |||||||||||||
331 | void QOpenGLContextPrivate::_q_screenDestroyed(QObject *object) | - | ||||||||||||
332 | { | - | ||||||||||||
333 | QOpenGLContext * const q = q_func(); | - | ||||||||||||
334 | if (object == static_cast<QObject *>(screen)) { | - | ||||||||||||
335 | screen = 0; | - | ||||||||||||
336 | q->setScreen(0); | - | ||||||||||||
337 | } | - | ||||||||||||
338 | } | - | ||||||||||||
339 | void QOpenGLContext::setNativeHandle(const QVariant &handle) | - | ||||||||||||
340 | { | - | ||||||||||||
341 | QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
342 | d->nativeHandle = handle; | - | ||||||||||||
343 | } | - | ||||||||||||
344 | QVariant QOpenGLContext::nativeHandle() const | - | ||||||||||||
345 | { | - | ||||||||||||
346 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
347 | return d->nativeHandle; | - | ||||||||||||
348 | } | - | ||||||||||||
349 | bool QOpenGLContext::create() | - | ||||||||||||
350 | { | - | ||||||||||||
351 | QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
352 | if (d->platformGLContext) | - | ||||||||||||
353 | destroy(); | - | ||||||||||||
354 | - | |||||||||||||
355 | d->platformGLContext = QGuiApplicationPrivate::platformIntegration()->createPlatformOpenGLContext(this); | - | ||||||||||||
356 | if (!d->platformGLContext) | - | ||||||||||||
357 | return false; | - | ||||||||||||
358 | d->platformGLContext->initialize(); | - | ||||||||||||
359 | d->platformGLContext->setContext(this); | - | ||||||||||||
360 | if (!d->platformGLContext->isSharing()) | - | ||||||||||||
361 | d->shareContext = 0; | - | ||||||||||||
362 | d->shareGroup = d->shareContext ? d->shareContext->shareGroup() : new QOpenGLContextGroup; | - | ||||||||||||
363 | d->shareGroup->d_func()->addContext(this); | - | ||||||||||||
364 | return isValid(); | - | ||||||||||||
365 | } | - | ||||||||||||
366 | void QOpenGLContext::destroy() | - | ||||||||||||
367 | { | - | ||||||||||||
368 | deleteQGLContext(); | - | ||||||||||||
369 | QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
370 | if (d->platformGLContext
| 0 | ||||||||||||
371 | aboutToBeDestroyed(); never executed: aboutToBeDestroyed(); | 0 | ||||||||||||
372 | if (QOpenGLContext::currentContext() == this
| 0 | ||||||||||||
373 | doneCurrent(); never executed: doneCurrent(); | 0 | ||||||||||||
374 | if (d->shareGroup
| 0 | ||||||||||||
375 | d->shareGroup->d_func()->removeContext(this); never executed: d->shareGroup->d_func()->removeContext(this); | 0 | ||||||||||||
376 | d->shareGroup = 0; | - | ||||||||||||
377 | delete d->platformGLContext; | - | ||||||||||||
378 | d->platformGLContext = 0; | - | ||||||||||||
379 | delete d->functions; | - | ||||||||||||
380 | d->functions = 0; | - | ||||||||||||
381 | - | |||||||||||||
382 | for (QForeachContainer<typename QtPrivate::remove_reference<decltypeQAbstractOpenGLFunctions *func : qAsConst(d->externalVersionFunctions)>::type> _container_((d->externalVersionFunctions)); _container_.control && _container_.i != _container_.e; ++_container_.i, _container_.control ^= 1) for (QAbstractOpenGLFunctions *func = *_container_.i; _container_.control; _container_.control = 0))) { | - | ||||||||||||
383 | QAbstractOpenGLFunctionsPrivate *func_d = QAbstractOpenGLFunctionsPrivate::get(func); | - | ||||||||||||
384 | func_d->owningContext = 0; | - | ||||||||||||
385 | func_d->initialized = false; | - | ||||||||||||
386 | } never executed: end of block | 0 | ||||||||||||
387 | d->externalVersionFunctions.clear(); | - | ||||||||||||
388 | qDeleteAll(d->versionFunctions); | - | ||||||||||||
389 | d->versionFunctions.clear(); | - | ||||||||||||
qDeleteAll(d->versionFunctionsBackend); | ||||||||||||||
d->versionFunctionsBackend.clear(); | ||||||||||||||
390 | - | |||||||||||||
391 | delete d->textureFunctions; | - | ||||||||||||
392 | d->textureFunctions = 0; | - | ||||||||||||
393 | - | |||||||||||||
394 | d->nativeHandle = QVariant(); | - | ||||||||||||
395 | } never executed: end of block | 0 | ||||||||||||
396 | QOpenGLContext::~QOpenGLContext() | - | ||||||||||||
397 | { | - | ||||||||||||
398 | destroy(); | - | ||||||||||||
399 | - | |||||||||||||
400 | - | |||||||||||||
401 | QOpenGLContextPrivate::cleanMakeCurrentTracker(this); | - | ||||||||||||
402 | - | |||||||||||||
403 | } | - | ||||||||||||
404 | bool QOpenGLContext::isValid() const | - | ||||||||||||
405 | { | - | ||||||||||||
406 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
407 | return d->platformGLContext && d->platformGLContext->isValid(); | - | ||||||||||||
408 | } | - | ||||||||||||
409 | QOpenGLFunctions *QOpenGLContext::functions() const | - | ||||||||||||
410 | { | - | ||||||||||||
411 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
412 | if (!d->functions) | - | ||||||||||||
413 | const_cast<QOpenGLFunctions *&>(d->functions) = new QOpenGLExtensions(QOpenGLContext::currentContext()); | - | ||||||||||||
414 | return d->functions; | - | ||||||||||||
415 | } | - | ||||||||||||
416 | QOpenGLExtraFunctions *QOpenGLContext::extraFunctions() const | - | ||||||||||||
417 | { | - | ||||||||||||
418 | return static_cast<QOpenGLExtraFunctions *>(functions()); | - | ||||||||||||
419 | } | - | ||||||||||||
420 | QAbstractOpenGLFunctions *QOpenGLContext::versionFunctions(const QOpenGLVersionProfile &versionProfile) const | - | ||||||||||||
421 | { | - | ||||||||||||
422 | - | |||||||||||||
423 | if (isOpenGLES()) { | - | ||||||||||||
424 | QMessageLogger(__FILE__, 821825, __PRETTY_FUNCTION__).warning("versionFunctions: Not supported on OpenGL ES"); | - | ||||||||||||
425 | return 0; | - | ||||||||||||
426 | } | - | ||||||||||||
427 | - | |||||||||||||
428 | - | |||||||||||||
429 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
430 | const QSurfaceFormat f = format(); | - | ||||||||||||
431 | - | |||||||||||||
432 | - | |||||||||||||
433 | QOpenGLVersionProfile vp = versionProfile; | - | ||||||||||||
434 | if (!vp.isValid()) | - | ||||||||||||
435 | vp = QOpenGLVersionProfile(f); | - | ||||||||||||
436 | - | |||||||||||||
437 | - | |||||||||||||
438 | const QPair<int, int> v = qMakePair(f.majorVersion(), f.minorVersion()); | - | ||||||||||||
439 | if (v < vp.version()) | - | ||||||||||||
440 | return 0; | - | ||||||||||||
441 | - | |||||||||||||
442 | - | |||||||||||||
443 | - | |||||||||||||
444 | if (((vp.hasProfiles() && vp.profile() != QSurfaceFormat::CoreProfile) || vp.isLegacyVersion()) | - | ||||||||||||
445 | && f.profile() == QSurfaceFormat::CoreProfile) | - | ||||||||||||
446 | return 0; | - | ||||||||||||
447 | - | |||||||||||||
448 | - | |||||||||||||
449 | QAbstractOpenGLFunctions* funcs = 0; | - | ||||||||||||
450 | if (!d->versionFunctions.contains(vp)) { | - | ||||||||||||
451 | funcs = QOpenGLVersionFunctionsFactory::create(vp); | - | ||||||||||||
452 | if (funcs) { | - | ||||||||||||
453 | funcs->setOwningContext(this); | - | ||||||||||||
454 | d->versionFunctions.insert(vp, funcs); | - | ||||||||||||
455 | } | - | ||||||||||||
456 | } else { | - | ||||||||||||
457 | funcs = d->versionFunctions.value(vp); | - | ||||||||||||
458 | } | - | ||||||||||||
459 | - | |||||||||||||
460 | if (funcs && QOpenGLContext::currentContext() == this) | - | ||||||||||||
461 | funcs->initializeOpenGLFunctions(); | - | ||||||||||||
462 | - | |||||||||||||
463 | return funcs; | - | ||||||||||||
464 | } | - | ||||||||||||
465 | QSet<QByteArray> QOpenGLContext::extensions() const | - | ||||||||||||
466 | { | - | ||||||||||||
467 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
468 | if (d->extensionNames.isEmpty()) { | - | ||||||||||||
469 | QOpenGLExtensionMatcher matcher; | - | ||||||||||||
470 | d->extensionNames = matcher.extensions(); | - | ||||||||||||
471 | } | - | ||||||||||||
472 | - | |||||||||||||
473 | return d->extensionNames; | - | ||||||||||||
474 | } | - | ||||||||||||
475 | bool QOpenGLContext::hasExtension(const QByteArray &extension) const | - | ||||||||||||
476 | { | - | ||||||||||||
477 | return extensions().contains(extension); | - | ||||||||||||
478 | } | - | ||||||||||||
479 | GLuint QOpenGLContext::defaultFramebufferObject() const | - | ||||||||||||
480 | { | - | ||||||||||||
481 | if (!isValid()) | - | ||||||||||||
482 | return 0; | - | ||||||||||||
483 | - | |||||||||||||
484 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
485 | if (!d->surface || !d->surface->surfaceHandle()) | - | ||||||||||||
486 | return 0; | - | ||||||||||||
487 | - | |||||||||||||
488 | if (d->defaultFboRedirect) | - | ||||||||||||
489 | return d->defaultFboRedirect; | - | ||||||||||||
490 | - | |||||||||||||
491 | return d->platformGLContext->defaultFramebufferObject(d->surface->surfaceHandle()); | - | ||||||||||||
492 | } | - | ||||||||||||
493 | bool QOpenGLContext::makeCurrent(QSurface *surface) | - | ||||||||||||
494 | { | - | ||||||||||||
495 | QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
496 | if (!isValid()
| 0 | ||||||||||||
497 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
498 | - | |||||||||||||
499 | if (__builtin_expect(!!(
| 0 | ||||||||||||
500 | QMessageLogger(__FILE__, 954958, __PRETTY_FUNCTION__).fatal("Cannot make QOpenGLContext current in a different thread"); never executed: QMessageLogger(__FILE__, 958, __PRETTY_FUNCTION__).fatal("Cannot make QOpenGLContext current in a different thread"); | 0 | ||||||||||||
501 | - | |||||||||||||
502 | if (!surface
| 0 | ||||||||||||
503 | doneCurrent(); | - | ||||||||||||
504 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||
505 | } | - | ||||||||||||
506 | - | |||||||||||||
507 | if (!surface->surfaceHandle()
| 0 | ||||||||||||
508 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
509 | if (!surface->supportsOpenGL()
| 0 | ||||||||||||
510 | QMessageLogger(__FILE__, 964968, __PRETTY_FUNCTION__).warning() << "QOpenGLContext::makeCurrent() called with non-opengl surface" << surface; | - | ||||||||||||
511 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
512 | } | - | ||||||||||||
513 | - | |||||||||||||
514 | QOpenGLContext *previous = QOpenGLContextPrivate::setCurrentContext(this); | - | ||||||||||||
515 | - | |||||||||||||
516 | if (d->platformGLContext->makeCurrent(surface->surfaceHandle())
| 0 | ||||||||||||
517 | d->surface = surface; | - | ||||||||||||
518 | - | |||||||||||||
519 | d->shareGroup->d_func()->deletePendingResources(this); | - | ||||||||||||
520 | - | |||||||||||||
521 | - | |||||||||||||
522 | QOpenGLContextPrivate::toggleMakeCurrentTracker(this, true); | - | ||||||||||||
523 | - | |||||||||||||
524 | - | |||||||||||||
525 | return never executed: true;return true; never executed: return true; | 0 | ||||||||||||
526 | } | - | ||||||||||||
527 | - | |||||||||||||
528 | QOpenGLContextPrivate::setCurrentContext(previous); | - | ||||||||||||
529 | - | |||||||||||||
530 | return never executed: false;return false; never executed: return false; | 0 | ||||||||||||
531 | } | - | ||||||||||||
532 | void QOpenGLContext::doneCurrent() | - | ||||||||||||
533 | { | - | ||||||||||||
534 | QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
535 | if (!isValid()) | - | ||||||||||||
536 | return; | - | ||||||||||||
537 | - | |||||||||||||
538 | if (QOpenGLContext::currentContext() == this) | - | ||||||||||||
539 | d->shareGroup->d_func()->deletePendingResources(this); | - | ||||||||||||
540 | - | |||||||||||||
541 | d->platformGLContext->doneCurrent(); | - | ||||||||||||
542 | QOpenGLContextPrivate::setCurrentContext(0); | - | ||||||||||||
543 | - | |||||||||||||
544 | d->surface = 0; | - | ||||||||||||
545 | } | - | ||||||||||||
546 | - | |||||||||||||
547 | - | |||||||||||||
548 | - | |||||||||||||
549 | - | |||||||||||||
550 | - | |||||||||||||
551 | - | |||||||||||||
552 | QSurface *QOpenGLContext::surface() const | - | ||||||||||||
553 | { | - | ||||||||||||
554 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
555 | return d->surface; | - | ||||||||||||
556 | } | - | ||||||||||||
557 | void QOpenGLContext::swapBuffers(QSurface *surface) | - | ||||||||||||
558 | { | - | ||||||||||||
559 | QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
560 | if (!isValid()
| 0 | ||||||||||||
561 | return; never executed: return; | 0 | ||||||||||||
562 | - | |||||||||||||
563 | if (!surface
| 0 | ||||||||||||
564 | QMessageLogger(__FILE__, 10341038, __PRETTY_FUNCTION__).warning() << ("QOpenGLContext::swapBuffers() called with null argument";); | - | ||||||||||||
565 | return; never executed: return; | 0 | ||||||||||||
566 | } | - | ||||||||||||
567 | - | |||||||||||||
568 | if (!surface->supportsOpenGL()
| 0 | ||||||||||||
569 | QMessageLogger(__FILE__, 10391043, __PRETTY_FUNCTION__).warning() << ("QOpenGLContext::swapBuffers() called with non-opengl surface";); | - | ||||||||||||
570 | return; never executed: return; | 0 | ||||||||||||
571 | } | - | ||||||||||||
572 | - | |||||||||||||
573 | if (surface->surfaceClass() == QSurface::Window
| 0 | ||||||||||||
574 | && !qt_window_private(static_cast<QWindow *>(surface))->receivedExpose
| 0 | ||||||||||||
575 | { | - | ||||||||||||
576 | QMessageLogger(__FILE__, 10461050, __PRETTY_FUNCTION__).warning() << ("QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined";); | - | ||||||||||||
577 | } never executed: end of block | 0 | ||||||||||||
578 | - | |||||||||||||
579 | QPlatformSurface *surfaceHandle = surface->surfaceHandle(); | - | ||||||||||||
580 | if (!surfaceHandle
| 0 | ||||||||||||
581 | return; never executed: return; | 0 | ||||||||||||
582 | - | |||||||||||||
583 | - | |||||||||||||
584 | if (!QOpenGLContextPrivate::toggleMakeCurrentTracker(this, false)
| 0 | ||||||||||||
585 | QMessageLogger(__FILE__, 10551059, __PRETTY_FUNCTION__).warning() << ("QOpenGLContext::swapBuffers() called without corresponding makeCurrent()";); never executed: QMessageLogger(__FILE__, 1059, __PRETTY_FUNCTION__).warning("QOpenGLContext::swapBuffers() called without corresponding makeCurrent()"); | 0 | ||||||||||||
586 | - | |||||||||||||
587 | if (surface->format().swapBehavior() == QSurfaceFormat::SingleBuffer
| 0 | ||||||||||||
588 | functions()->glFlush(); never executed: functions()->glFlush(); | 0 | ||||||||||||
589 | d->platformGLContext->swapBuffers(surfaceHandle); | - | ||||||||||||
590 | } never executed: end of block | 0 | ||||||||||||
591 | - | |||||||||||||
592 | - | |||||||||||||
593 | - | |||||||||||||
594 | - | |||||||||||||
595 | - | |||||||||||||
596 | - | |||||||||||||
597 | QFunctionPointer QOpenGLContext::getProcAddress(const QByteArray &procName) const | - | ||||||||||||
598 | { | - | ||||||||||||
599 | return never executed: getProcAddress(procName.constData());return getProcAddress(procName.constData()); never executed: return getProcAddress(procName.constData()); | 0 | ||||||||||||
600 | } | - | ||||||||||||
601 | - | |||||||||||||
602 | - | |||||||||||||
603 | - | |||||||||||||
604 | - | |||||||||||||
605 | - | |||||||||||||
606 | QFunctionPointer QOpenGLContext::getProcAddress(const char *procName) const | - | ||||||||||||
607 | { | - | ||||||||||||
608 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
609 | if (!d->platformGLContext
| 0 | ||||||||||||
610 | return never executed: 0nullptr;return nullptr; never executed: return nullptr; | 0 | ||||||||||||
611 | return never executed: d->platformGLContext->getProcAddress(procName);return d->platformGLContext->getProcAddress(procName); never executed: return d->platformGLContext->getProcAddress(procName); | 0 | ||||||||||||
612 | } | - | ||||||||||||
613 | QSurfaceFormat QOpenGLContext::format() const | - | ||||||||||||
614 | { | - | ||||||||||||
615 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
616 | if (!d->platformGLContext) | - | ||||||||||||
617 | return d->requestedFormat; | - | ||||||||||||
618 | return d->platformGLContext->format(); | - | ||||||||||||
619 | } | - | ||||||||||||
620 | - | |||||||||||||
621 | - | |||||||||||||
622 | - | |||||||||||||
623 | - | |||||||||||||
624 | QOpenGLContextGroup *QOpenGLContext::shareGroup() const | - | ||||||||||||
625 | { | - | ||||||||||||
626 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
627 | return d->shareGroup; | - | ||||||||||||
628 | } | - | ||||||||||||
629 | - | |||||||||||||
630 | - | |||||||||||||
631 | - | |||||||||||||
632 | - | |||||||||||||
633 | - | |||||||||||||
634 | - | |||||||||||||
635 | - | |||||||||||||
636 | QOpenGLContext *QOpenGLContext::shareContext() const | - | ||||||||||||
637 | { | - | ||||||||||||
638 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
639 | return d->shareContext; | - | ||||||||||||
640 | } | - | ||||||||||||
641 | - | |||||||||||||
642 | - | |||||||||||||
643 | - | |||||||||||||
644 | - | |||||||||||||
645 | QScreen *QOpenGLContext::screen() const | - | ||||||||||||
646 | { | - | ||||||||||||
647 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
648 | return d->screen; | - | ||||||||||||
649 | } | - | ||||||||||||
650 | - | |||||||||||||
651 | - | |||||||||||||
652 | - | |||||||||||||
653 | - | |||||||||||||
654 | - | |||||||||||||
655 | - | |||||||||||||
656 | - | |||||||||||||
657 | void *QOpenGLContext::qGLContextHandle() const | - | ||||||||||||
658 | { | - | ||||||||||||
659 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
660 | return d->qGLContextHandle; | - | ||||||||||||
661 | } | - | ||||||||||||
662 | - | |||||||||||||
663 | - | |||||||||||||
664 | - | |||||||||||||
665 | - | |||||||||||||
666 | - | |||||||||||||
667 | - | |||||||||||||
668 | - | |||||||||||||
669 | void QOpenGLContext::setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *)) | - | ||||||||||||
670 | { | - | ||||||||||||
671 | QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
672 | d->qGLContextHandle = handle; | - | ||||||||||||
673 | d->qGLContextDeleteFunction = qGLContextDeleteFunction; | - | ||||||||||||
674 | } | - | ||||||||||||
675 | - | |||||||||||||
676 | - | |||||||||||||
677 | - | |||||||||||||
678 | - | |||||||||||||
679 | void QOpenGLContext::deleteQGLContext() | - | ||||||||||||
680 | { | - | ||||||||||||
681 | QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
682 | if (d->qGLContextDeleteFunction && d->qGLContextHandle) { | - | ||||||||||||
683 | d->qGLContextDeleteFunction(d->qGLContextHandle); | - | ||||||||||||
684 | d->qGLContextDeleteFunction = 0; | - | ||||||||||||
685 | d->qGLContextHandle = 0; | - | ||||||||||||
686 | } | - | ||||||||||||
687 | } | - | ||||||||||||
688 | void *QOpenGLContext::openGLModuleHandle() | - | ||||||||||||
689 | { | - | ||||||||||||
690 | - | |||||||||||||
691 | - | |||||||||||||
692 | - | |||||||||||||
693 | - | |||||||||||||
694 | - | |||||||||||||
695 | return 0; | - | ||||||||||||
696 | - | |||||||||||||
697 | } | - | ||||||||||||
698 | QOpenGLContext::OpenGLModuleType QOpenGLContext::openGLModuleType() | - | ||||||||||||
699 | { | - | ||||||||||||
700 | - | |||||||||||||
701 | - | |||||||||||||
702 | - | |||||||||||||
703 | - | |||||||||||||
704 | - | |||||||||||||
705 | - | |||||||||||||
706 | return LibGL; | - | ||||||||||||
707 | - | |||||||||||||
708 | } | - | ||||||||||||
709 | bool QOpenGLContext::isOpenGLES() const | - | ||||||||||||
710 | { | - | ||||||||||||
711 | return format().renderableType() == QSurfaceFormat::OpenGLES; | - | ||||||||||||
712 | } | - | ||||||||||||
713 | bool QOpenGLContext::supportsThreadedOpenGL() | - | ||||||||||||
714 | { | - | ||||||||||||
715 | ((!((static_cast<QGuiApplication *>(QCoreApplication::instance())))) ? qt_assert("qGuiApp",__FILE__,12601273) : qt_noop()); | - | ||||||||||||
716 | return QGuiApplicationPrivate::instance()->platformIntegration()->hasCapability(QPlatformIntegration::ThreadedOpenGL); | - | ||||||||||||
717 | } | - | ||||||||||||
718 | QOpenGLContext *QOpenGLContext::globalShareContext() | - | ||||||||||||
719 | { | - | ||||||||||||
720 | ((!((static_cast<QGuiApplication *>(QCoreApplication::instance())))) ? qt_assert("qGuiApp",__FILE__,12851298) : qt_noop()); | - | ||||||||||||
721 | return qt_gl_global_share_context(); | - | ||||||||||||
722 | } | - | ||||||||||||
723 | - | |||||||||||||
724 | - | |||||||||||||
725 | - | |||||||||||||
726 | - | |||||||||||||
QOpenGLVersionFunctionsBackendQOpenGLVersionFunctionsStorage *QOpenGLContext::functionsBackend(const QOpenGLVersionStatus &v)functionsBackendStorage() const | ||||||||||||||
728 | { | - | ||||||||||||
729 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
730 | return never executed: d->versionFunctionsBackend.value(v, 0);return &d->versionFunctionsStorage; never executed: return &d->versionFunctionsStorage; | 0 | ||||||||||||
} never executed: return &d->versionFunctionsStorage; | ||||||||||||||
void QOpenGLContext::insertFunctionsBackend(const QOpenGLVersionStatus &v, never executed: return &d->versionFunctionsStorage; | ||||||||||||||
QOpenGLVersionFunctionsBackend *backend) never executed: return &d->versionFunctionsStorage; | ||||||||||||||
{ never executed: return &d->versionFunctionsStorage; | ||||||||||||||
QOpenGLContextPrivate * const d = d_func(); never executed: return &d->versionFunctionsStorage; | ||||||||||||||
d->versionFunctionsBackend.insert(v, backend); never executed: return &d->versionFunctionsStorage; | ||||||||||||||
} never executed: return &d->versionFunctionsStorage; | ||||||||||||||
void QOpenGLContext::removeFunctionsBackend(const QOpenGLVersionStatus &v) never executed: return &d->versionFunctionsStorage; | ||||||||||||||
{ never executed: return &d->versionFunctionsStorage; | ||||||||||||||
QOpenGLContextPrivate * const d = d_func(); never executed: return &d->versionFunctionsStorage; | ||||||||||||||
d never executed: return &d->versionFunctionsStorage; never executed: &d->versionFunctionsBackend.remove(v);versionFunctionsStorage;return &d->versionFunctionsStorage; never executed: return &d->versionFunctionsStorage; | ||||||||||||||
731 | } | - | ||||||||||||
732 | - | |||||||||||||
733 | - | |||||||||||||
734 | - | |||||||||||||
735 | - | |||||||||||||
736 | void QOpenGLContext::insertExternalFunctions(QAbstractOpenGLFunctions *f) | - | ||||||||||||
737 | { | - | ||||||||||||
738 | QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
739 | d->externalVersionFunctions.insert(f); | - | ||||||||||||
740 | } | - | ||||||||||||
741 | - | |||||||||||||
742 | - | |||||||||||||
743 | - | |||||||||||||
744 | - | |||||||||||||
745 | void QOpenGLContext::removeExternalFunctions(QAbstractOpenGLFunctions *f) | - | ||||||||||||
746 | { | - | ||||||||||||
747 | QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
748 | d->externalVersionFunctions.remove(f); | - | ||||||||||||
749 | } | - | ||||||||||||
750 | - | |||||||||||||
751 | - | |||||||||||||
752 | - | |||||||||||||
753 | - | |||||||||||||
754 | QOpenGLTextureHelper* QOpenGLContext::textureFunctions() const | - | ||||||||||||
755 | { | - | ||||||||||||
756 | const QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
757 | return d->textureFunctions; | - | ||||||||||||
758 | } | - | ||||||||||||
759 | - | |||||||||||||
760 | - | |||||||||||||
761 | - | |||||||||||||
762 | - | |||||||||||||
763 | void QOpenGLContext::setTextureFunctions(QOpenGLTextureHelper* textureFuncs) | - | ||||||||||||
764 | { | - | ||||||||||||
765 | QOpenGLContextPrivate * const d = d_func(); | - | ||||||||||||
766 | d->textureFunctions = textureFuncs; | - | ||||||||||||
767 | } | - | ||||||||||||
768 | QOpenGLContextGroup::QOpenGLContextGroup() | - | ||||||||||||
769 | : QObject(*new QOpenGLContextGroupPrivate()) | - | ||||||||||||
770 | { | - | ||||||||||||
771 | } | - | ||||||||||||
772 | - | |||||||||||||
773 | - | |||||||||||||
774 | - | |||||||||||||
775 | - | |||||||||||||
776 | QOpenGLContextGroup::~QOpenGLContextGroup() | - | ||||||||||||
777 | { | - | ||||||||||||
778 | QOpenGLContextGroupPrivate * const d = d_func(); | - | ||||||||||||
779 | d->cleanup(); | - | ||||||||||||
780 | } | - | ||||||||||||
781 | - | |||||||||||||
782 | - | |||||||||||||
783 | - | |||||||||||||
784 | - | |||||||||||||
785 | QList<QOpenGLContext *> QOpenGLContextGroup::shares() const | - | ||||||||||||
786 | { | - | ||||||||||||
787 | const QOpenGLContextGroupPrivate * const d = d_func(); | - | ||||||||||||
788 | return d->m_shares; | - | ||||||||||||
789 | } | - | ||||||||||||
790 | - | |||||||||||||
791 | - | |||||||||||||
792 | - | |||||||||||||
793 | - | |||||||||||||
794 | - | |||||||||||||
795 | - | |||||||||||||
796 | QOpenGLContextGroup *QOpenGLContextGroup::currentContextGroup() | - | ||||||||||||
797 | { | - | ||||||||||||
798 | QOpenGLContext *current = QOpenGLContext::currentContext(); | - | ||||||||||||
799 | return current ? current->shareGroup() : 0; | - | ||||||||||||
800 | } | - | ||||||||||||
801 | - | |||||||||||||
802 | void QOpenGLContextGroupPrivate::addContext(QOpenGLContext *ctx) | - | ||||||||||||
803 | { | - | ||||||||||||
804 | QMutexLocker locker(&m_mutex); | - | ||||||||||||
805 | m_refs.ref(); | - | ||||||||||||
806 | m_shares << ctx; | - | ||||||||||||
807 | } | - | ||||||||||||
808 | - | |||||||||||||
809 | void QOpenGLContextGroupPrivate::removeContext(QOpenGLContext *ctx) | - | ||||||||||||
810 | { | - | ||||||||||||
811 | QOpenGLContextGroup * const q = q_func(); | - | ||||||||||||
812 | - | |||||||||||||
813 | bool deleteObject = false; | - | ||||||||||||
814 | - | |||||||||||||
815 | { | - | ||||||||||||
816 | QMutexLocker locker(&m_mutex); | - | ||||||||||||
817 | m_shares.removeOne(ctx); | - | ||||||||||||
818 | - | |||||||||||||
819 | if (ctx == m_context
| 0 | ||||||||||||
820 | m_context = m_shares.firstconstFirst(); never executed: m_context = m_shares.constFirst(); | 0 | ||||||||||||
821 | - | |||||||||||||
822 | if (!m_refs.deref()
| 0 | ||||||||||||
823 | cleanup(); | - | ||||||||||||
824 | deleteObject = true; | - | ||||||||||||
825 | } never executed: end of block | 0 | ||||||||||||
826 | } | - | ||||||||||||
827 | - | |||||||||||||
828 | if (deleteObject
| 0 | ||||||||||||
829 | if (q->thread() == QThread::currentThread()
| 0 | ||||||||||||
830 | delete q; never executed: delete q; | 0 | ||||||||||||
831 | else | - | ||||||||||||
832 | q->deleteLater(); never executed: q->deleteLater(); | 0 | ||||||||||||
833 | } | - | ||||||||||||
834 | } never executed: end of block | 0 | ||||||||||||
835 | - | |||||||||||||
836 | void QOpenGLContextGroupPrivate::cleanup() | - | ||||||||||||
837 | { | - | ||||||||||||
838 | QOpenGLContextGroup * const q = q_func(); | - | ||||||||||||
839 | { | - | ||||||||||||
840 | QHash<QOpenGLMultiGroupSharedResource *, QOpenGLSharedResource *>::const_iterator it, end; | - | ||||||||||||
841 | end = m_resources.constEnd(); | - | ||||||||||||
842 | for (it = m_resources.constBegin(); it != end; ++it) | - | ||||||||||||
843 | it.key()->cleanup(q, it.value()); | - | ||||||||||||
844 | m_resources.clear(); | - | ||||||||||||
845 | } | - | ||||||||||||
846 | - | |||||||||||||
847 | QList<QOpenGLSharedResource *>::iterator it = m_sharedResources.begin(); | - | ||||||||||||
848 | QList<QOpenGLSharedResource *>::iterator end = m_sharedResources.end(); | - | ||||||||||||
849 | - | |||||||||||||
850 | while (it != end) { | - | ||||||||||||
851 | (*it)->invalidateResource(); | - | ||||||||||||
852 | (*it)->m_group = 0; | - | ||||||||||||
853 | ++it; | - | ||||||||||||
854 | } | - | ||||||||||||
855 | - | |||||||||||||
856 | m_sharedResources.clear(); | - | ||||||||||||
857 | - | |||||||||||||
858 | qDeleteAll(m_pendingDeletion.begin(), m_pendingDeletion.end()); | - | ||||||||||||
859 | m_pendingDeletion.clear(); | - | ||||||||||||
860 | } | - | ||||||||||||
861 | - | |||||||||||||
862 | void QOpenGLContextGroupPrivate::deletePendingResources(QOpenGLContext *ctx) | - | ||||||||||||
863 | { | - | ||||||||||||
864 | QMutexLocker locker(&m_mutex); | - | ||||||||||||
865 | - | |||||||||||||
866 | const QList<QOpenGLSharedResource *> pending = m_pendingDeletion; | - | ||||||||||||
867 | m_pendingDeletion.clear(); | - | ||||||||||||
868 | - | |||||||||||||
869 | QList<QOpenGLSharedResource *>::const_iterator it = pending.begin(); | - | ||||||||||||
870 | QList<QOpenGLSharedResource *>::const_iterator end = pending.end(); | - | ||||||||||||
871 | while (it != end) { | - | ||||||||||||
872 | (*it)->freeResource(ctx); | - | ||||||||||||
873 | delete *it; | - | ||||||||||||
874 | ++it; | - | ||||||||||||
875 | } | - | ||||||||||||
876 | } | - | ||||||||||||
877 | QOpenGLSharedResource::QOpenGLSharedResource(QOpenGLContextGroup *group) | - | ||||||||||||
878 | : m_group(group) | - | ||||||||||||
879 | { | - | ||||||||||||
880 | QMutexLocker locker(&m_group->d_func()->m_mutex); | - | ||||||||||||
881 | m_group->d_func()->m_sharedResources << this; | - | ||||||||||||
882 | } | - | ||||||||||||
883 | - | |||||||||||||
884 | QOpenGLSharedResource::~QOpenGLSharedResource() | - | ||||||||||||
885 | { | - | ||||||||||||
886 | } | - | ||||||||||||
887 | - | |||||||||||||
888 | - | |||||||||||||
889 | void QOpenGLSharedResource::free() | - | ||||||||||||
890 | { | - | ||||||||||||
891 | if (!m_group) { | - | ||||||||||||
892 | delete this; | - | ||||||||||||
893 | return; | - | ||||||||||||
894 | } | - | ||||||||||||
895 | - | |||||||||||||
896 | QMutexLocker locker(&m_group->d_func()->m_mutex); | - | ||||||||||||
897 | m_group->d_func()->m_sharedResources.removeOne(this); | - | ||||||||||||
898 | m_group->d_func()->m_pendingDeletion << this; | - | ||||||||||||
899 | - | |||||||||||||
900 | - | |||||||||||||
901 | QOpenGLContext *current = QOpenGLContext::currentContext(); | - | ||||||||||||
902 | if (current && current->shareGroup() == m_group) { | - | ||||||||||||
903 | m_group->d_func()->deletePendingResources(current); | - | ||||||||||||
904 | } | - | ||||||||||||
905 | } | - | ||||||||||||
906 | void QOpenGLSharedResourceGuard::freeResource(QOpenGLContext *context) | - | ||||||||||||
907 | { | - | ||||||||||||
908 | if (m_id) { | - | ||||||||||||
909 | QOpenGLFunctions functions(context); | - | ||||||||||||
910 | m_func(&functions, m_id); | - | ||||||||||||
911 | m_id = 0; | - | ||||||||||||
912 | } | - | ||||||||||||
913 | } | - | ||||||||||||
914 | QOpenGLMultiGroupSharedResource::QOpenGLMultiGroupSharedResource() | - | ||||||||||||
915 | : active(0), | - | ||||||||||||
916 | m_mutex(QMutex::Recursive) | - | ||||||||||||
917 | { | - | ||||||||||||
918 | - | |||||||||||||
919 | - | |||||||||||||
920 | - | |||||||||||||
921 | } | - | ||||||||||||
922 | - | |||||||||||||
923 | QOpenGLMultiGroupSharedResource::~QOpenGLMultiGroupSharedResource() | - | ||||||||||||
924 | { | - | ||||||||||||
925 | - | |||||||||||||
926 | - | |||||||||||||
927 | - | |||||||||||||
928 | for (int i = 0; i < m_groups.size()
| 0 | ||||||||||||
929 | if (!m_groups.at(i)->shares().isEmpty()
| 0 | ||||||||||||
930 | QOpenGLContext *context = m_groups.at(i)->shares().firstconstFirst(); | - | ||||||||||||
931 | QOpenGLSharedResource *resource = value(context); | - | ||||||||||||
932 | if (resource
| 0 | ||||||||||||
933 | resource->free(); never executed: resource->free(); | 0 | ||||||||||||
934 | } never executed: end of block | 0 | ||||||||||||
935 | m_groups.at(i)->d_func()->m_resources.remove(this); | - | ||||||||||||
936 | active.deref(); | - | ||||||||||||
937 | } never executed: end of block | 0 | ||||||||||||
938 | - | |||||||||||||
939 | if (active.load() != 0
| 0 | ||||||||||||
940 | QMessageLogger(__FILE__, 15921586, __PRETTY_FUNCTION__).warning("QtGui: Resources are still available at program shutdown.\n" | - | ||||||||||||
941 | " This is possibly caused by a leaked QOpenGLWidget, \n" | - | ||||||||||||
942 | " QOpenGLFramebufferObject or QOpenGLPixelBuffer."); | - | ||||||||||||
943 | } never executed: end of block | 0 | ||||||||||||
944 | - | |||||||||||||
945 | } never executed: end of block | 0 | ||||||||||||
946 | - | |||||||||||||
947 | void QOpenGLMultiGroupSharedResource::insert(QOpenGLContext *context, QOpenGLSharedResource *value) | - | ||||||||||||
948 | { | - | ||||||||||||
949 | - | |||||||||||||
950 | - | |||||||||||||
951 | - | |||||||||||||
952 | QOpenGLContextGroup *group = context->shareGroup(); | - | ||||||||||||
953 | ((!(!group->d_func()->m_resources.contains(this))) ? qt_assert("!group->d_func()->m_resources.contains(this)",__FILE__,16051599) : qt_noop()); | - | ||||||||||||
954 | group->d_func()->m_resources.insert(this, value); | - | ||||||||||||
955 | m_groups.append(group); | - | ||||||||||||
956 | active.ref(); | - | ||||||||||||
957 | } | - | ||||||||||||
958 | - | |||||||||||||
959 | QOpenGLSharedResource *QOpenGLMultiGroupSharedResource::value(QOpenGLContext *context) | - | ||||||||||||
960 | { | - | ||||||||||||
961 | QOpenGLContextGroup *group = context->shareGroup(); | - | ||||||||||||
962 | return group->d_func()->m_resources.value(this, 0); | - | ||||||||||||
963 | } | - | ||||||||||||
964 | - | |||||||||||||
965 | QList<QOpenGLSharedResource *> QOpenGLMultiGroupSharedResource::resources() const | - | ||||||||||||
966 | { | - | ||||||||||||
967 | QList<QOpenGLSharedResource *> result; | - | ||||||||||||
968 | for (QList<QOpenGLContextGroup *>::const_iterator it = m_groups.constBegin(); it != m_groups.constEnd(); ++it) { | - | ||||||||||||
969 | QOpenGLSharedResource *resource = (*it)->d_func()->m_resources.value(const_cast<QOpenGLMultiGroupSharedResource *>(this), 0); | - | ||||||||||||
970 | if (resource) | - | ||||||||||||
971 | result << resource; | - | ||||||||||||
972 | } | - | ||||||||||||
973 | return result; | - | ||||||||||||
974 | } | - | ||||||||||||
975 | - | |||||||||||||
976 | void QOpenGLMultiGroupSharedResource::cleanup(QOpenGLContextGroup *group, QOpenGLSharedResource *value) | - | ||||||||||||
977 | { | - | ||||||||||||
978 | - | |||||||||||||
979 | - | |||||||||||||
980 | - | |||||||||||||
981 | value->invalidateResource(); | - | ||||||||||||
982 | value->free(); | - | ||||||||||||
983 | active.deref(); | - | ||||||||||||
984 | - | |||||||||||||
985 | ((!(m_groups.contains(group))) ? qt_assert("m_groups.contains(group)",__FILE__,16371631) : qt_noop()); | - | ||||||||||||
986 | m_groups.removeOne(group); | - | ||||||||||||
987 | } | - | ||||||||||||
988 | - | |||||||||||||
989 | - | |||||||||||||
990 | - | |||||||||||||
Switch to Source code | Preprocessed file |