kernel/qopenglcontext.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtGui module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
9** Commercial License Usage -
10** Licensees holding valid commercial Qt licenses may use this file in -
11** accordance with the commercial license agreement provided with the -
12** Software or, alternatively, in accordance with the terms contained in -
13** a written agreement between you and Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include <qpa/qplatformopenglcontext.h> -
43#include <qpa/qplatformintegration.h> -
44#include "qopenglcontext.h" -
45#include "qopenglcontext_p.h" -
46#include "qwindow.h" -
47 -
48#include <QtCore/QThreadStorage> -
49#include <QtCore/QThread> -
50 -
51#include <QtGui/private/qguiapplication_p.h> -
52#include <QtGui/private/qopengl_p.h> -
53#include <QtGui/private/qwindow_p.h> -
54#include <QtGui/QScreen> -
55 -
56#include <private/qopenglextensions_p.h> -
57 -
58#include <QDebug> -
59 -
60QT_BEGIN_NAMESPACE -
61 -
62class QGuiGLThreadContext -
63{ -
64public: -
65 QGuiGLThreadContext() -
66 : context(0) -
67 { -
68 }
never executed: }
0
69 ~QGuiGLThreadContext() { -
70 if (context)
never evaluated: context
0
71 context->doneCurrent();
never executed: context->doneCurrent();
0
72 }
never executed: }
0
73 QOpenGLContext *context; -
74}; -
75 -
76static QThreadStorage<QGuiGLThreadContext *> qwindow_context_storage; -
77 -
78#ifndef QT_NO_DEBUG -
79QHash<QOpenGLContext *, bool> QOpenGLContextPrivate::makeCurrentTracker; -
80QMutex QOpenGLContextPrivate::makeCurrentTrackerMutex; -
81#endif -
82 -
83/*! -
84 \class QOpenGLContext -
85 \inmodule QtGui -
86 \since 5.0 -
87 \brief The QOpenGLContext class represents a native OpenGL context, enabling -
88 OpenGL rendering on a QSurface. -
89 -
90 QOpenGLContext represents the OpenGL state of an underlying OpenGL context. -
91 To set up a context, set its screen and format such that they match those -
92 of the surface or surfaces with which the context is meant to be used, if -
93 necessary make it share resources with other contexts with -
94 setShareContext(), and finally call create(). Use isValid() to check if the -
95 context was successfully initialized. -
96 -
97 A context can be made current against a given surface by calling -
98 makeCurrent(). When OpenGL rendering is done, call swapBuffers() to swap -
99 the front and back buffers of the surface, so that the newly rendered -
100 content becomes visible. To be able to support certain platforms, -
101 QOpenGLContext requires that you call makeCurrent() again before starting -
102 rendering a new frame, after calling swapBuffers(). -
103 -
104 If the context is temporarily not needed, such as when the application is -
105 not rendering, it can be useful to call destroy() to free resources. -
106 However, if you do so you will need to call create() again before the -
107 context can be used, and you might need to recreate any OpenGL resources -
108 and reinitialize the OpenGL state. You can connect to the -
109 aboutToBeDestroyed() signal to clean up any resources that have been -
110 allocated with different ownership from the QOpenGLContext itself. -
111 -
112 Once a QOpenGLContext has been made current, you can render to it in a -
113 platform independent way by using Qt's OpenGL enablers such as -
114 QOpenGLFunctions, QOpenGLBuffer, QOpenGLShaderProgram, and -
115 QOpenGLFramebufferObject. It is also possible to use the platform's OpenGL -
116 API directly, without using the Qt enablers, although potentially at the -
117 cost of portability. The latter is necessary when wanting to use OpenGL 1.x -
118 or OpenGL ES 1.x. -
119 -
120 For more information about the OpenGL API, refer to the official -
121 \l{OpenGL documentation}. -
122 -
123 For an example of how to use QOpenGLContext see the -
124 \l{OpenGL Window Example}{OpenGL Window} example. -
125 -
126 \section1 Thread affinity -
127 -
128 QOpenGLContext can be moved to a different thread with moveToThread(). Do -
129 not call makeCurrent() from a different thread than the one to which the -
130 QOpenGLContext object belongs. A context can only be current in one thread -
131 and against one surface at a time, and a thread only has one context -
132 current at a time. -
133 -
134 \section1 Context resource sharing -
135 -
136 Resources, such as framebuffer objects, textures, and vertex buffer objects -
137 can be shared between contexts. Use setShareContext() before calling -
138 create() to specify that the contexts should share these resources. -
139 QOpenGLContext internally keeps track of a QOpenGLContextGroup object which -
140 can be accessed with shareGroup(), and which can be used to find all the -
141 contexts in a given share group. A share group consists of all contexts that -
142 have been successfully initialized and are sharing with an existing context in -
143 the share group. A non-sharing context has a share group consisting of a -
144 single context. -
145 -
146 \section1 Default framebuffer -
147 -
148 On certain platforms, a framebuffer other than 0 might be the default frame -
149 buffer depending on the current surface. Instead of calling -
150 glBindFramebuffer(0), it is recommended that you use -
151 glBindFramebuffer(ctx->defaultFramebufferObject()), to ensure that your -
152 application is portable between different platforms. However, if you use -
153 QOpenGLFunctions::glBindFramebuffer(), this is done automatically for you. -
154 -
155 \sa QOpenGLFunctions, QOpenGLBuffer, QOpenGLShaderProgram, QOpenGLFramebufferObject -
156*/ -
157 -
158/*! -
159 \internal -
160 -
161 Set the current context. Returns the previously current context. -
162*/ -
163QOpenGLContext *QOpenGLContextPrivate::setCurrentContext(QOpenGLContext *context) -
164{ -
165 QGuiGLThreadContext *threadContext = qwindow_context_storage.localData();
never executed (the execution status of this line is deduced): QGuiGLThreadContext *threadContext = qwindow_context_storage.localData();
-
166 if (!threadContext) {
never evaluated: !threadContext
0
167 if (!QThread::currentThread()) {
never evaluated: !QThread::currentThread()
0
168 qWarning("No QTLS available. currentContext won't work");
never executed (the execution status of this line is deduced): QMessageLogger("kernel/qopenglcontext.cpp", 168, __PRETTY_FUNCTION__).warning("No QTLS available. currentContext won't work");
-
169 return 0;
never executed: return 0;
0
170 } -
171 threadContext = new QGuiGLThreadContext;
never executed (the execution status of this line is deduced): threadContext = new QGuiGLThreadContext;
-
172 qwindow_context_storage.setLocalData(threadContext);
never executed (the execution status of this line is deduced): qwindow_context_storage.setLocalData(threadContext);
-
173 }
never executed: }
0
174 QOpenGLContext *previous = threadContext->context;
never executed (the execution status of this line is deduced): QOpenGLContext *previous = threadContext->context;
-
175 threadContext->context = context;
never executed (the execution status of this line is deduced): threadContext->context = context;
-
176 return previous;
never executed: return previous;
0
177} -
178 -
179int QOpenGLContextPrivate::maxTextureSize() -
180{ -
181 if (max_texture_size != -1)
never evaluated: max_texture_size != -1
0
182 return max_texture_size;
never executed: return max_texture_size;
0
183 -
184 glGetIntegerv(GL_MAX_TEXTURE_SIZE, &max_texture_size);
never executed (the execution status of this line is deduced): glGetIntegerv(0x0D33, &max_texture_size);
-
185 -
186#if defined(QT_OPENGL_ES) -
187 return max_texture_size; -
188#else -
189 GLenum proxy = GL_PROXY_TEXTURE_2D;
never executed (the execution status of this line is deduced): GLenum proxy = 0x8064;
-
190 -
191 GLint size;
never executed (the execution status of this line is deduced): GLint size;
-
192 GLint next = 64;
never executed (the execution status of this line is deduced): GLint next = 64;
-
193 glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
never executed (the execution status of this line is deduced): glTexImage2D(proxy, 0, 0x1908, next, next, 0, 0x1908, 0x1401, 0);
-
194 glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &size);
never executed (the execution status of this line is deduced): glGetTexLevelParameteriv(proxy, 0, 0x1000, &size);
-
195 if (size == 0) {
never evaluated: size == 0
0
196 return max_texture_size;
never executed: return max_texture_size;
0
197 } -
198 do { -
199 size = next;
never executed (the execution status of this line is deduced): size = next;
-
200 next = size * 2;
never executed (the execution status of this line is deduced): next = size * 2;
-
201 -
202 if (next > max_texture_size)
never evaluated: next > max_texture_size
0
203 break;
never executed: break;
0
204 glTexImage2D(proxy, 0, GL_RGBA, next, next, 0, GL_RGBA, GL_UNSIGNED_BYTE, 0);
never executed (the execution status of this line is deduced): glTexImage2D(proxy, 0, 0x1908, next, next, 0, 0x1908, 0x1401, 0);
-
205 glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &next);
never executed (the execution status of this line is deduced): glGetTexLevelParameteriv(proxy, 0, 0x1000, &next);
-
206 } while (next > size);
never executed: }
never evaluated: next > size
0
207 -
208 max_texture_size = size;
never executed (the execution status of this line is deduced): max_texture_size = size;
-
209 return max_texture_size;
never executed: return max_texture_size;
0
210#endif -
211} -
212 -
213/*! -
214 Returns the last context which called makeCurrent in the current thread, -
215 or 0, if no context is current. -
216*/ -
217QOpenGLContext* QOpenGLContext::currentContext() -
218{ -
219 QGuiGLThreadContext *threadContext = qwindow_context_storage.localData();
never executed (the execution status of this line is deduced): QGuiGLThreadContext *threadContext = qwindow_context_storage.localData();
-
220 if(threadContext) {
never evaluated: threadContext
0
221 return threadContext->context;
never executed: return threadContext->context;
0
222 } -
223 return 0;
never executed: return 0;
0
224} -
225 -
226/*! -
227 Returns true if the \a first and \a second contexts are sharing OpenGL resources. -
228*/ -
229bool QOpenGLContext::areSharing(QOpenGLContext *first, QOpenGLContext *second) -
230{ -
231 return first->shareGroup() == second->shareGroup();
never executed: return first->shareGroup() == second->shareGroup();
0
232} -
233 -
234/*! -
235 Returns the underlying platform context. -
236 -
237 \internal -
238*/ -
239QPlatformOpenGLContext *QOpenGLContext::handle() const -
240{ -
241 Q_D(const QOpenGLContext);
never executed (the execution status of this line is deduced): const QOpenGLContextPrivate * const d = d_func();
-
242 return d->platformGLContext;
never executed: return d->platformGLContext;
0
243} -
244 -
245/*! -
246 Returns the underlying platform context with which this context is sharing. -
247 -
248 \internal -
249*/ -
250 -
251QPlatformOpenGLContext *QOpenGLContext::shareHandle() const -
252{ -
253 Q_D(const QOpenGLContext);
never executed (the execution status of this line is deduced): const QOpenGLContextPrivate * const d = d_func();
-
254 if (d->shareContext)
never evaluated: d->shareContext
0
255 return d->shareContext->handle();
never executed: return d->shareContext->handle();
0
256 return 0;
never executed: return 0;
0
257} -
258 -
259/*! -
260 Creates a new OpenGL context instance with parent object \a parent. -
261 -
262 Before it can be used you need to set the proper format and call create(). -
263 -
264 \sa create(), makeCurrent() -
265*/ -
266QOpenGLContext::QOpenGLContext(QObject *parent) -
267 : QObject(*new QOpenGLContextPrivate(), parent) -
268{ -
269 Q_D(QOpenGLContext);
never executed (the execution status of this line is deduced): QOpenGLContextPrivate * const d = d_func();
-
270 d->screen = QGuiApplication::primaryScreen();
never executed (the execution status of this line is deduced): d->screen = QGuiApplication::primaryScreen();
-
271}
never executed: }
0
272 -
273/*! -
274 Sets the \a format the OpenGL context should be compatible with. You need -
275 to call create() before it takes effect. -
276*/ -
277void QOpenGLContext::setFormat(const QSurfaceFormat &format) -
278{ -
279 Q_D(QOpenGLContext);
never executed (the execution status of this line is deduced): QOpenGLContextPrivate * const d = d_func();
-
280 d->requestedFormat = format;
never executed (the execution status of this line is deduced): d->requestedFormat = format;
-
281}
never executed: }
0
282 -
283/*! -
284 Makes this context share textures, shaders, and other OpenGL resources -
285 with \a shareContext. You need to call create() before it takes effect. -
286*/ -
287void QOpenGLContext::setShareContext(QOpenGLContext *shareContext) -
288{ -
289 Q_D(QOpenGLContext);
never executed (the execution status of this line is deduced): QOpenGLContextPrivate * const d = d_func();
-
290 d->shareContext = shareContext;
never executed (the execution status of this line is deduced): d->shareContext = shareContext;
-
291}
never executed: }
0
292 -
293/*! -
294 Sets the \a screen the OpenGL context should be valid for. You need to call -
295 create() before it takes effect. -
296*/ -
297void QOpenGLContext::setScreen(QScreen *screen) -
298{ -
299 Q_D(QOpenGLContext);
never executed (the execution status of this line is deduced): QOpenGLContextPrivate * const d = d_func();
-
300 d->screen = screen;
never executed (the execution status of this line is deduced): d->screen = screen;
-
301 if (!d->screen)
never evaluated: !d->screen
0
302 d->screen = QGuiApplication::primaryScreen();
never executed: d->screen = QGuiApplication::primaryScreen();
0
303}
never executed: }
0
304 -
305/*! -
306 Attempts to create the OpenGL context with the current configuration. -
307 -
308 The current configuration includes the format, the share context, and the -
309 screen. -
310 -
311 If the OpenGL implementation on your system does not support the requested -
312 version of OpenGL context, then QOpenGLContext will try to create the closest -
313 matching version. The actual created context properties can be queried -
314 using the QSurfaceFormat returned by the format() function. For example, if -
315 you request a context that supports OpenGL 4.3 Core profile but the driver -
316 and/or hardware only supports version 3.2 Core profile contexts then you will -
317 get a 3.2 Core profile context. -
318 -
319 Returns true if the native context was successfully created and is ready to -
320 be used with makeCurrent(), swapBuffers(), etc. -
321 -
322 \sa makeCurrent(), destroy(), format() -
323*/ -
324bool QOpenGLContext::create() -
325{ -
326 destroy();
never executed (the execution status of this line is deduced): destroy();
-
327 -
328 Q_D(QOpenGLContext);
never executed (the execution status of this line is deduced): QOpenGLContextPrivate * const d = d_func();
-
329 d->platformGLContext = QGuiApplicationPrivate::platformIntegration()->createPlatformOpenGLContext(this);
never executed (the execution status of this line is deduced): d->platformGLContext = QGuiApplicationPrivate::platformIntegration()->createPlatformOpenGLContext(this);
-
330 if (!d->platformGLContext)
never evaluated: !d->platformGLContext
0
331 return false;
never executed: return false;
0
332 d->platformGLContext->setContext(this);
never executed (the execution status of this line is deduced): d->platformGLContext->setContext(this);
-
333 if (!d->platformGLContext->isSharing())
never evaluated: !d->platformGLContext->isSharing()
0
334 d->shareContext = 0;
never executed: d->shareContext = 0;
0
335 d->shareGroup = d->shareContext ? d->shareContext->shareGroup() : new QOpenGLContextGroup;
never evaluated: d->shareContext
0
336 d->shareGroup->d_func()->addContext(this);
never executed (the execution status of this line is deduced): d->shareGroup->d_func()->addContext(this);
-
337 return d->platformGLContext;
never executed: return d->platformGLContext;
0
338} -
339 -
340/*! -
341 Destroy the underlying platform context associated with this context. -
342 -
343 If any other context is directly or indirectly sharing resources with this -
344 context, the shared resources, which includes vertex buffer objects, shader -
345 objects, textures, and framebuffer objects, are not freed. However, -
346 destroying the underlying platform context frees any state associated with -
347 the context. -
348 -
349 After destroy() has been called, you must call create() if you wish to -
350 use the context again. -
351 -
352 \note This implicitly calls doneCurrent() if the context is current. -
353 -
354 \sa create() -
355*/ -
356void QOpenGLContext::destroy() -
357{ -
358 Q_D(QOpenGLContext);
never executed (the execution status of this line is deduced): QOpenGLContextPrivate * const d = d_func();
-
359 if (d->platformGLContext)
never evaluated: d->platformGLContext
0
360 emit aboutToBeDestroyed();
never executed: aboutToBeDestroyed();
0
361 if (QOpenGLContext::currentContext() == this)
never evaluated: QOpenGLContext::currentContext() == this
0
362 doneCurrent();
never executed: doneCurrent();
0
363 if (d->shareGroup)
never evaluated: d->shareGroup
0
364 d->shareGroup->d_func()->removeContext(this);
never executed: d->shareGroup->d_func()->removeContext(this);
0
365 d->shareGroup = 0;
never executed (the execution status of this line is deduced): d->shareGroup = 0;
-
366 delete d->platformGLContext;
never executed (the execution status of this line is deduced): delete d->platformGLContext;
-
367 d->platformGLContext = 0;
never executed (the execution status of this line is deduced): d->platformGLContext = 0;
-
368 delete d->functions;
never executed (the execution status of this line is deduced): delete d->functions;
-
369 d->functions = 0;
never executed (the execution status of this line is deduced): d->functions = 0;
-
370}
never executed: }
0
371 -
372/*! -
373 \fn void QOpenGLContext::aboutToBeDestroyed() -
374 -
375 This signal is emitted before the underlying native OpenGL context is -
376 destroyed, such that users may clean up OpenGL resources that might -
377 otherwise be left dangling in the case of shared OpenGL contexts. -
378 -
379 If you wish to make the context current in order to do clean-up, make sure -
380 to only connect to the signal using a direct connection. -
381*/ -
382 -
383/*! -
384 Destroys the QOpenGLContext object. -
385 -
386 This implicitly calls destroy(), so if this is the current context for the -
387 thread, doneCurrent() is also called. -
388 -
389 \sa destroy() -
390*/ -
391QOpenGLContext::~QOpenGLContext() -
392{ -
393 destroy();
never executed (the execution status of this line is deduced): destroy();
-
394 -
395#ifndef QT_NO_DEBUG -
396 QOpenGLContextPrivate::cleanMakeCurrentTracker(this); -
397#endif -
398}
never executed: }
0
399 -
400/*! -
401 Returns if this context is valid, i.e. has been successfully created. -
402 -
403 \sa create() -
404*/ -
405bool QOpenGLContext::isValid() const -
406{ -
407 Q_D(const QOpenGLContext);
never executed (the execution status of this line is deduced): const QOpenGLContextPrivate * const d = d_func();
-
408 return d->platformGLContext && d->platformGLContext->isValid();
never executed: return d->platformGLContext && d->platformGLContext->isValid();
0
409} -
410 -
411/*! -
412 Get the QOpenGLFunctions instance for this context. -
413 -
414 QOpenGLContext offers this as a convenient way to access QOpenGLFunctions -
415 without having to manage it manually. -
416 -
417 The context or a sharing context must be current. -
418*/ -
419QOpenGLFunctions *QOpenGLContext::functions() const -
420{ -
421 Q_D(const QOpenGLContext);
never executed (the execution status of this line is deduced): const QOpenGLContextPrivate * const d = d_func();
-
422 if (!d->functions)
never evaluated: !d->functions
0
423 const_cast<QOpenGLFunctions *&>(d->functions) = new QOpenGLExtensions(QOpenGLContext::currentContext());
never executed: const_cast<QOpenGLFunctions *&>(d->functions) = new QOpenGLExtensions(QOpenGLContext::currentContext());
0
424 return d->functions;
never executed: return d->functions;
0
425} -
426 -
427/*! -
428 Returns the set of OpenGL extensions supported by this context. -
429 -
430 The context or a sharing context must be current. -
431 -
432 \sa hasExtension() -
433*/ -
434QSet<QByteArray> QOpenGLContext::extensions() const -
435{ -
436 Q_D(const QOpenGLContext);
never executed (the execution status of this line is deduced): const QOpenGLContextPrivate * const d = d_func();
-
437 if (d->extensionNames.isEmpty()) {
never evaluated: d->extensionNames.isEmpty()
0
438 QOpenGLExtensionMatcher matcher;
never executed (the execution status of this line is deduced): QOpenGLExtensionMatcher matcher;
-
439 d->extensionNames = matcher.extensions();
never executed (the execution status of this line is deduced): d->extensionNames = matcher.extensions();
-
440 }
never executed: }
0
441 -
442 return d->extensionNames;
never executed: return d->extensionNames;
0
443} -
444 -
445/*! -
446 Returns true if this OpenGL context supports the specified OpenGL -
447 \a extension, false otherwise. -
448 -
449 The context or a sharing context must be current. -
450 -
451 \sa extensions() -
452*/ -
453bool QOpenGLContext::hasExtension(const QByteArray &extension) const -
454{ -
455 return extensions().contains(extension);
never executed: return extensions().contains(extension);
0
456} -
457 -
458/*! -
459 Call this to get the default framebuffer object for the current surface. -
460 -
461 On some platforms the default framebuffer object depends on the surface -
462 being rendered to, and might be different from 0. Thus, instead of calling -
463 glBindFramebuffer(0), you should call -
464 glBindFramebuffer(ctx->defaultFramebufferObject()) if you want your -
465 application to work across different Qt platforms. -
466 -
467 If you use the glBindFramebuffer() in QOpenGLFunctions you do not have to -
468 worry about this, as it automatically binds the current context's -
469 defaultFramebufferObject() when 0 is passed. -
470*/ -
471GLuint QOpenGLContext::defaultFramebufferObject() const -
472{ -
473 if (!isValid())
never evaluated: !isValid()
0
474 return 0;
never executed: return 0;
0
475 -
476 Q_D(const QOpenGLContext);
never executed (the execution status of this line is deduced): const QOpenGLContextPrivate * const d = d_func();
-
477 if (!d->surface || !d->surface->surfaceHandle())
never evaluated: !d->surface
never evaluated: !d->surface->surfaceHandle()
0
478 return 0;
never executed: return 0;
0
479 -
480 return d->platformGLContext->defaultFramebufferObject(d->surface->surfaceHandle());
never executed: return d->platformGLContext->defaultFramebufferObject(d->surface->surfaceHandle());
0
481} -
482 -
483/*! -
484 Makes the context current in the current thread, against the given -
485 \a surface. Returns true if successful. -
486 -
487 If \a surface is 0 this is equivalent to calling doneCurrent(). -
488 -
489 Do not call this function from a different thread than the one the -
490 QOpenGLContext instance lives in. If you wish to use QOpenGLContext from a -
491 different thread you should first call make sure it's not current in the -
492 current thread, by calling doneCurrent() if necessary. Then call -
493 moveToThread(otherThread) before using it in the other thread. -
494 -
495 \sa functions(), doneCurrent() -
496*/ -
497bool QOpenGLContext::makeCurrent(QSurface *surface) -
498{ -
499 Q_D(QOpenGLContext);
never executed (the execution status of this line is deduced): QOpenGLContextPrivate * const d = d_func();
-
500 if (!isValid())
never evaluated: !isValid()
0
501 return false;
never executed: return false;
0
502 -
503 if (thread() != QThread::currentThread())
never evaluated: thread() != QThread::currentThread()
0
504 qFatal("Cannot make QOpenGLContext current in a different thread");
never executed: QMessageLogger("kernel/qopenglcontext.cpp", 504, __PRETTY_FUNCTION__).fatal("Cannot make QOpenGLContext current in a different thread");
0
505 -
506 if (!surface) {
never evaluated: !surface
0
507 doneCurrent();
never executed (the execution status of this line is deduced): doneCurrent();
-
508 return true;
never executed: return true;
0
509 } -
510 -
511 if (!surface->surfaceHandle())
never evaluated: !surface->surfaceHandle()
0
512 return false;
never executed: return false;
0
513 -
514 if (surface->surfaceType() != QSurface::OpenGLSurface) {
never evaluated: surface->surfaceType() != QSurface::OpenGLSurface
0
515 qWarning() << "QOpenGLContext::makeCurrent() called with non-opengl surface";
never executed (the execution status of this line is deduced): QMessageLogger("kernel/qopenglcontext.cpp", 515, __PRETTY_FUNCTION__).warning() << "QOpenGLContext::makeCurrent() called with non-opengl surface";
-
516 return false;
never executed: return false;
0
517 } -
518 -
519 QOpenGLContext *previous = QOpenGLContextPrivate::setCurrentContext(this);
never executed (the execution status of this line is deduced): QOpenGLContext *previous = QOpenGLContextPrivate::setCurrentContext(this);
-
520 -
521 if (d->platformGLContext->makeCurrent(surface->surfaceHandle())) {
never evaluated: d->platformGLContext->makeCurrent(surface->surfaceHandle())
0
522 d->surface = surface;
never executed (the execution status of this line is deduced): d->surface = surface;
-
523 -
524 d->shareGroup->d_func()->deletePendingResources(this);
never executed (the execution status of this line is deduced): d->shareGroup->d_func()->deletePendingResources(this);
-
525 -
526#ifndef QT_NO_DEBUG -
527 QOpenGLContextPrivate::toggleMakeCurrentTracker(this, true); -
528#endif -
529 -
530 return true;
never executed: return true;
0
531 } -
532 -
533 QOpenGLContextPrivate::setCurrentContext(previous);
never executed (the execution status of this line is deduced): QOpenGLContextPrivate::setCurrentContext(previous);
-
534 -
535 return false;
never executed: return false;
0
536} -
537 -
538/*! -
539 Convenience function for calling makeCurrent with a 0 surface. -
540 -
541 This results in no context being current in the current thread. -
542 -
543 \sa makeCurrent(), currentContext() -
544*/ -
545void QOpenGLContext::doneCurrent() -
546{ -
547 Q_D(QOpenGLContext);
never executed (the execution status of this line is deduced): QOpenGLContextPrivate * const d = d_func();
-
548 if (!isValid())
never evaluated: !isValid()
0
549 return;
never executed: return;
0
550 -
551 if (QOpenGLContext::currentContext() == this)
never evaluated: QOpenGLContext::currentContext() == this
0
552 d->shareGroup->d_func()->deletePendingResources(this);
never executed: d->shareGroup->d_func()->deletePendingResources(this);
0
553 -
554 d->platformGLContext->doneCurrent();
never executed (the execution status of this line is deduced): d->platformGLContext->doneCurrent();
-
555 QOpenGLContextPrivate::setCurrentContext(0);
never executed (the execution status of this line is deduced): QOpenGLContextPrivate::setCurrentContext(0);
-
556 -
557 d->surface = 0;
never executed (the execution status of this line is deduced): d->surface = 0;
-
558}
never executed: }
0
559 -
560/*! -
561 Returns the surface the context has been made current with. -
562 -
563 This is the surface passed as an argument to makeCurrent(). -
564*/ -
565QSurface *QOpenGLContext::surface() const -
566{ -
567 Q_D(const QOpenGLContext);
never executed (the execution status of this line is deduced): const QOpenGLContextPrivate * const d = d_func();
-
568 return d->surface;
never executed: return d->surface;
0
569} -
570 -
571 -
572/*! -
573 Swap the back and front buffers of \a surface. -
574 -
575 Call this to finish a frame of OpenGL rendering, and make sure to -
576 call makeCurrent() again before you begin a new frame. -
577*/ -
578void QOpenGLContext::swapBuffers(QSurface *surface) -
579{ -
580 Q_D(QOpenGLContext);
never executed (the execution status of this line is deduced): QOpenGLContextPrivate * const d = d_func();
-
581 if (!isValid())
never evaluated: !isValid()
0
582 return;
never executed: return;
0
583 -
584 if (!surface) {
never evaluated: !surface
0
585 qWarning() << "QOpenGLContext::swapBuffers() called with null argument";
never executed (the execution status of this line is deduced): QMessageLogger("kernel/qopenglcontext.cpp", 585, __PRETTY_FUNCTION__).warning() << "QOpenGLContext::swapBuffers() called with null argument";
-
586 return;
never executed: return;
0
587 } -
588 -
589 if (surface->surfaceType() != QSurface::OpenGLSurface) {
never evaluated: surface->surfaceType() != QSurface::OpenGLSurface
0
590 qWarning() << "QOpenGLContext::swapBuffers() called with non-opengl surface";
never executed (the execution status of this line is deduced): QMessageLogger("kernel/qopenglcontext.cpp", 590, __PRETTY_FUNCTION__).warning() << "QOpenGLContext::swapBuffers() called with non-opengl surface";
-
591 return;
never executed: return;
0
592 } -
593 -
594 if (surface->surfaceClass() == QSurface::Window
never evaluated: surface->surfaceClass() == QSurface::Window
0
595 && !qt_window_private(static_cast<QWindow *>(surface))->receivedExpose)
never evaluated: !qt_window_private(static_cast<QWindow *>(surface))->receivedExpose
0
596 { -
597 qWarning() << "QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined";
never executed (the execution status of this line is deduced): QMessageLogger("kernel/qopenglcontext.cpp", 597, __PRETTY_FUNCTION__).warning() << "QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined";
-
598 }
never executed: }
0
599 -
600 QPlatformSurface *surfaceHandle = surface->surfaceHandle();
never executed (the execution status of this line is deduced): QPlatformSurface *surfaceHandle = surface->surfaceHandle();
-
601 if (!surfaceHandle)
never evaluated: !surfaceHandle
0
602 return;
never executed: return;
0
603 -
604#if !defined(QT_NO_DEBUG) -
605 if (!QOpenGLContextPrivate::toggleMakeCurrentTracker(this, false)) -
606 qWarning() << "QOpenGLContext::swapBuffers() called without corresponding makeCurrent()"; -
607#endif -
608 if (surface->format().swapBehavior() == QSurfaceFormat::SingleBuffer)
never evaluated: surface->format().swapBehavior() == QSurfaceFormat::SingleBuffer
0
609 glFlush();
never executed: glFlush();
0
610 d->platformGLContext->swapBuffers(surfaceHandle);
never executed (the execution status of this line is deduced): d->platformGLContext->swapBuffers(surfaceHandle);
-
611}
never executed: }
0
612 -
613/*! -
614 Resolves the function pointer to an OpenGL extension function, identified by \a procName -
615 -
616 Returns 0 if no such function can be found. -
617*/ -
618QFunctionPointer QOpenGLContext::getProcAddress(const QByteArray &procName) const -
619{ -
620 Q_D(const QOpenGLContext);
never executed (the execution status of this line is deduced): const QOpenGLContextPrivate * const d = d_func();
-
621 if (!d->platformGLContext)
never evaluated: !d->platformGLContext
0
622 return 0;
never executed: return 0;
0
623 return d->platformGLContext->getProcAddress(procName);
never executed: return d->platformGLContext->getProcAddress(procName);
0
624} -
625 -
626/*! -
627 Returns the format of the underlying platform context, if create() has been called. -
628 -
629 Otherwise, returns the requested format. -
630*/ -
631QSurfaceFormat QOpenGLContext::format() const -
632{ -
633 Q_D(const QOpenGLContext);
never executed (the execution status of this line is deduced): const QOpenGLContextPrivate * const d = d_func();
-
634 if (!d->platformGLContext)
never evaluated: !d->platformGLContext
0
635 return d->requestedFormat;
never executed: return d->requestedFormat;
0
636 return d->platformGLContext->format();
never executed: return d->platformGLContext->format();
0
637} -
638 -
639/*! -
640 Returns the share group this context belongs to. -
641*/ -
642QOpenGLContextGroup *QOpenGLContext::shareGroup() const -
643{ -
644 Q_D(const QOpenGLContext);
never executed (the execution status of this line is deduced): const QOpenGLContextPrivate * const d = d_func();
-
645 return d->shareGroup;
never executed: return d->shareGroup;
0
646} -
647 -
648/*! -
649 Returns the share context this context was created with. -
650 -
651 If the underlying platform was not able to support the requested -
652 sharing, this will return 0. -
653*/ -
654QOpenGLContext *QOpenGLContext::shareContext() const -
655{ -
656 Q_D(const QOpenGLContext);
never executed (the execution status of this line is deduced): const QOpenGLContextPrivate * const d = d_func();
-
657 return d->shareContext;
never executed: return d->shareContext;
0
658} -
659 -
660/*! -
661 Returns the screen the context was created for. -
662*/ -
663QScreen *QOpenGLContext::screen() const -
664{ -
665 Q_D(const QOpenGLContext);
never executed (the execution status of this line is deduced): const QOpenGLContextPrivate * const d = d_func();
-
666 return d->screen;
never executed: return d->screen;
0
667} -
668 -
669/*! -
670 internal: Needs to have a pointer to qGLContext. But since this is in Qt GUI we can't -
671 have any type information. -
672 -
673 \internal -
674*/ -
675void *QOpenGLContext::qGLContextHandle() const -
676{ -
677 Q_D(const QOpenGLContext);
never executed (the execution status of this line is deduced): const QOpenGLContextPrivate * const d = d_func();
-
678 return d->qGLContextHandle;
never executed: return d->qGLContextHandle;
0
679} -
680 -
681/*! -
682 \internal -
683*/ -
684void QOpenGLContext::setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *)) -
685{ -
686 Q_D(QOpenGLContext);
never executed (the execution status of this line is deduced): QOpenGLContextPrivate * const d = d_func();
-
687 d->qGLContextHandle = handle;
never executed (the execution status of this line is deduced): d->qGLContextHandle = handle;
-
688 d->qGLContextDeleteFunction = qGLContextDeleteFunction;
never executed (the execution status of this line is deduced): d->qGLContextDeleteFunction = qGLContextDeleteFunction;
-
689}
never executed: }
0
690 -
691/*! -
692 \internal -
693*/ -
694void QOpenGLContext::deleteQGLContext() -
695{ -
696 Q_D(QOpenGLContext);
never executed (the execution status of this line is deduced): QOpenGLContextPrivate * const d = d_func();
-
697 if (d->qGLContextDeleteFunction && d->qGLContextHandle) {
never evaluated: d->qGLContextDeleteFunction
never evaluated: d->qGLContextHandle
0
698 d->qGLContextDeleteFunction(d->qGLContextHandle);
never executed (the execution status of this line is deduced): d->qGLContextDeleteFunction(d->qGLContextHandle);
-
699 d->qGLContextDeleteFunction = 0;
never executed (the execution status of this line is deduced): d->qGLContextDeleteFunction = 0;
-
700 d->qGLContextHandle = 0;
never executed (the execution status of this line is deduced): d->qGLContextHandle = 0;
-
701 }
never executed: }
0
702}
never executed: }
0
703 -
704/*! -
705 \class QOpenGLContextGroup -
706 \since 5.0 -
707 \brief The QOpenGLContextGroup class represents a group of contexts sharing -
708 OpenGL resources. -
709 \inmodule QtGui -
710 -
711 QOpenGLContextGroup is automatically created and managed by QOpenGLContext -
712 instances. Its purpose is to identify all the contexts that are sharing -
713 resources. -
714 -
715 \sa QOpenGLContext::shareGroup() -
716*/ -
717QOpenGLContextGroup::QOpenGLContextGroup() -
718 : QObject(*new QOpenGLContextGroupPrivate()) -
719{ -
720}
never executed: }
0
721 -
722/*! -
723 \internal -
724*/ -
725QOpenGLContextGroup::~QOpenGLContextGroup() -
726{ -
727 Q_D(QOpenGLContextGroup);
never executed (the execution status of this line is deduced): QOpenGLContextGroupPrivate * const d = d_func();
-
728 d->cleanup();
never executed (the execution status of this line is deduced): d->cleanup();
-
729}
never executed: }
0
730 -
731/*! -
732 Returns all the QOpenGLContext objects in this share group. -
733*/ -
734QList<QOpenGLContext *> QOpenGLContextGroup::shares() const -
735{ -
736 Q_D(const QOpenGLContextGroup);
never executed (the execution status of this line is deduced): const QOpenGLContextGroupPrivate * const d = d_func();
-
737 return d->m_shares;
never executed: return d->m_shares;
0
738} -
739 -
740/*! -
741 Returns the QOpenGLContextGroup corresponding to the current context. -
742 -
743 \sa QOpenGLContext::currentContext() -
744*/ -
745QOpenGLContextGroup *QOpenGLContextGroup::currentContextGroup() -
746{ -
747 QOpenGLContext *current = QOpenGLContext::currentContext();
never executed (the execution status of this line is deduced): QOpenGLContext *current = QOpenGLContext::currentContext();
-
748 return current ? current->shareGroup() : 0;
never executed: return current ? current->shareGroup() : 0;
0
749} -
750 -
751void QOpenGLContextGroupPrivate::addContext(QOpenGLContext *ctx) -
752{ -
753 QMutexLocker locker(&m_mutex);
never executed (the execution status of this line is deduced): QMutexLocker locker(&m_mutex);
-
754 m_refs.ref();
never executed (the execution status of this line is deduced): m_refs.ref();
-
755 m_shares << ctx;
never executed (the execution status of this line is deduced): m_shares << ctx;
-
756}
never executed: }
0
757 -
758void QOpenGLContextGroupPrivate::removeContext(QOpenGLContext *ctx) -
759{ -
760 Q_Q(QOpenGLContextGroup);
never executed (the execution status of this line is deduced): QOpenGLContextGroup * const q = q_func();
-
761 -
762 bool deleteObject = false;
never executed (the execution status of this line is deduced): bool deleteObject = false;
-
763 -
764 { -
765 QMutexLocker locker(&m_mutex);
never executed (the execution status of this line is deduced): QMutexLocker locker(&m_mutex);
-
766 m_shares.removeOne(ctx);
never executed (the execution status of this line is deduced): m_shares.removeOne(ctx);
-
767 -
768 if (ctx == m_context && !m_shares.isEmpty())
never evaluated: ctx == m_context
never evaluated: !m_shares.isEmpty()
0
769 m_context = m_shares.first();
never executed: m_context = m_shares.first();
0
770 -
771 if (!m_refs.deref()) {
never evaluated: !m_refs.deref()
0
772 cleanup();
never executed (the execution status of this line is deduced): cleanup();
-
773 deleteObject = true;
never executed (the execution status of this line is deduced): deleteObject = true;
-
774 }
never executed: }
0
775 } -
776 -
777 if (deleteObject) {
never evaluated: deleteObject
0
778 if (q->thread() == QThread::currentThread())
never evaluated: q->thread() == QThread::currentThread()
0
779 delete q; // Delete directly to prevent leak, refer to QTBUG-29056
never executed: delete q;
0
780 else -
781 q->deleteLater();
never executed: q->deleteLater();
0
782 } -
783}
never executed: }
0
784 -
785void QOpenGLContextGroupPrivate::cleanup() -
786{ -
787 Q_Q(QOpenGLContextGroup);
never executed (the execution status of this line is deduced): QOpenGLContextGroup * const q = q_func();
-
788 { -
789 QHash<QOpenGLMultiGroupSharedResource *, QOpenGLSharedResource *>::const_iterator it, end;
never executed (the execution status of this line is deduced): QHash<QOpenGLMultiGroupSharedResource *, QOpenGLSharedResource *>::const_iterator it, end;
-
790 end = m_resources.constEnd();
never executed (the execution status of this line is deduced): end = m_resources.constEnd();
-
791 for (it = m_resources.constBegin(); it != end; ++it)
never evaluated: it != end
0
792 it.key()->cleanup(q, it.value());
never executed: it.key()->cleanup(q, it.value());
0
793 m_resources.clear();
never executed (the execution status of this line is deduced): m_resources.clear();
-
794 } -
795 -
796 QList<QOpenGLSharedResource *>::iterator it = m_sharedResources.begin();
never executed (the execution status of this line is deduced): QList<QOpenGLSharedResource *>::iterator it = m_sharedResources.begin();
-
797 QList<QOpenGLSharedResource *>::iterator end = m_sharedResources.end();
never executed (the execution status of this line is deduced): QList<QOpenGLSharedResource *>::iterator end = m_sharedResources.end();
-
798 -
799 while (it != end) {
never evaluated: it != end
0
800 (*it)->invalidateResource();
never executed (the execution status of this line is deduced): (*it)->invalidateResource();
-
801 (*it)->m_group = 0;
never executed (the execution status of this line is deduced): (*it)->m_group = 0;
-
802 ++it;
never executed (the execution status of this line is deduced): ++it;
-
803 }
never executed: }
0
804 -
805 m_sharedResources.clear();
never executed (the execution status of this line is deduced): m_sharedResources.clear();
-
806 -
807 qDeleteAll(m_pendingDeletion.begin(), m_pendingDeletion.end());
never executed (the execution status of this line is deduced): qDeleteAll(m_pendingDeletion.begin(), m_pendingDeletion.end());
-
808 m_pendingDeletion.clear();
never executed (the execution status of this line is deduced): m_pendingDeletion.clear();
-
809}
never executed: }
0
810 -
811void QOpenGLContextGroupPrivate::deletePendingResources(QOpenGLContext *ctx) -
812{ -
813 QMutexLocker locker(&m_mutex);
never executed (the execution status of this line is deduced): QMutexLocker locker(&m_mutex);
-
814 -
815 QList<QOpenGLSharedResource *> pending = m_pendingDeletion;
never executed (the execution status of this line is deduced): QList<QOpenGLSharedResource *> pending = m_pendingDeletion;
-
816 m_pendingDeletion.clear();
never executed (the execution status of this line is deduced): m_pendingDeletion.clear();
-
817 -
818 QList<QOpenGLSharedResource *>::iterator it = pending.begin();
never executed (the execution status of this line is deduced): QList<QOpenGLSharedResource *>::iterator it = pending.begin();
-
819 QList<QOpenGLSharedResource *>::iterator end = pending.end();
never executed (the execution status of this line is deduced): QList<QOpenGLSharedResource *>::iterator end = pending.end();
-
820 while (it != end) {
never evaluated: it != end
0
821 (*it)->freeResource(ctx);
never executed (the execution status of this line is deduced): (*it)->freeResource(ctx);
-
822 delete *it;
never executed (the execution status of this line is deduced): delete *it;
-
823 ++it;
never executed (the execution status of this line is deduced): ++it;
-
824 }
never executed: }
0
825}
never executed: }
0
826 -
827/*! -
828 \class QOpenGLSharedResource -
829 \internal -
830 \since 5.0 -
831 \brief The QOpenGLSharedResource class is used to keep track of resources -
832 that are shared between OpenGL contexts (like textures, framebuffer -
833 objects, shader programs, etc), and clean them up in a safe way when -
834 they're no longer needed. -
835 \inmodule QtGui -
836 -
837 The QOpenGLSharedResource instance should never be deleted, instead free() -
838 should be called when it's no longer needed. Thus it will be put on a queue -
839 and freed at an appropriate time (when a context in the share group becomes -
840 current). -
841 -
842 The sub-class needs to implement two pure virtual functions. The first, -
843 freeResource() must be implemented to actually do the freeing, for example -
844 call glDeleteTextures() on a texture id. Qt makes sure a valid context in -
845 the resource's share group is current at the time. The other, -
846 invalidateResource(), is called by Qt in the circumstance when the last -
847 context in the share group is destroyed before free() has been called. The -
848 implementation of invalidateResource() should set any identifiers to 0 or -
849 set a flag to prevent them from being used later on. -
850*/ -
851QOpenGLSharedResource::QOpenGLSharedResource(QOpenGLContextGroup *group) -
852 : m_group(group) -
853{ -
854 QMutexLocker locker(&m_group->d_func()->m_mutex);
never executed (the execution status of this line is deduced): QMutexLocker locker(&m_group->d_func()->m_mutex);
-
855 m_group->d_func()->m_sharedResources << this;
never executed (the execution status of this line is deduced): m_group->d_func()->m_sharedResources << this;
-
856}
never executed: }
0
857 -
858QOpenGLSharedResource::~QOpenGLSharedResource() -
859{ -
860} -
861 -
862// schedule the resource for deletion at an appropriate time -
863void QOpenGLSharedResource::free() -
864{ -
865 if (!m_group) {
never evaluated: !m_group
0
866 delete this;
never executed (the execution status of this line is deduced): delete this;
-
867 return;
never executed: return;
0
868 } -
869 -
870 QMutexLocker locker(&m_group->d_func()->m_mutex);
never executed (the execution status of this line is deduced): QMutexLocker locker(&m_group->d_func()->m_mutex);
-
871 m_group->d_func()->m_sharedResources.removeOne(this);
never executed (the execution status of this line is deduced): m_group->d_func()->m_sharedResources.removeOne(this);
-
872 m_group->d_func()->m_pendingDeletion << this;
never executed (the execution status of this line is deduced): m_group->d_func()->m_pendingDeletion << this;
-
873 -
874 // can we delete right away? -
875 QOpenGLContext *current = QOpenGLContext::currentContext();
never executed (the execution status of this line is deduced): QOpenGLContext *current = QOpenGLContext::currentContext();
-
876 if (current && current->shareGroup() == m_group) {
never evaluated: current
never evaluated: current->shareGroup() == m_group
0
877 m_group->d_func()->deletePendingResources(current);
never executed (the execution status of this line is deduced): m_group->d_func()->deletePendingResources(current);
-
878 }
never executed: }
0
879}
never executed: }
0
880 -
881/*! -
882 \class QOpenGLSharedResourceGuard -
883 \internal -
884 \since 5.0 -
885 \brief The QOpenGLSharedResourceGuard class is a convenience sub-class of -
886 QOpenGLSharedResource to be used to track a single OpenGL object with a -
887 GLuint identifier. The constructor takes a function pointer to a function -
888 that will be used to free the resource if and when necessary. -
889 \inmodule QtGui -
890 -
891*/ -
892void QOpenGLSharedResourceGuard::freeResource(QOpenGLContext *context) -
893{ -
894 if (m_id) {
never evaluated: m_id
0
895 QOpenGLFunctions functions(context);
never executed (the execution status of this line is deduced): QOpenGLFunctions functions(context);
-
896 m_func(&functions, m_id);
never executed (the execution status of this line is deduced): m_func(&functions, m_id);
-
897 m_id = 0;
never executed (the execution status of this line is deduced): m_id = 0;
-
898 }
never executed: }
0
899}
never executed: }
0
900 -
901/*! -
902 \class QOpenGLMultiGroupSharedResource -
903 \internal -
904 \since 5.0 -
905 \brief The QOpenGLMultiGroupSharedResource keeps track of a shared resource -
906 that might be needed from multiple contexts, like a glyph cache or gradient -
907 cache. One instance of the object is created for each group when necessary. -
908 The shared resource instance should have a constructor that takes a -
909 QOpenGLContext *. To get an instance for a given context one calls -
910 T *QOpenGLMultiGroupSharedResource::value<T>(context), where T is a sub-class -
911 of QOpenGLSharedResource. -
912 \inmodule QtGui -
913 -
914 You should not call free() on QOpenGLSharedResources owned by a -
915 QOpenGLMultiGroupSharedResource instance. -
916*/ -
917QOpenGLMultiGroupSharedResource::QOpenGLMultiGroupSharedResource() -
918 : active(0) -
919{ -
920#ifdef QT_GL_CONTEXT_RESOURCE_DEBUG -
921 qDebug("Creating context group resource object %p.", this); -
922#endif -
923}
never executed: }
0
924 -
925QOpenGLMultiGroupSharedResource::~QOpenGLMultiGroupSharedResource() -
926{ -
927#ifdef QT_GL_CONTEXT_RESOURCE_DEBUG -
928 qDebug("Deleting context group resource %p. Group size: %d.", this, m_groups.size()); -
929#endif -
930 for (int i = 0; i < m_groups.size(); ++i) {
never evaluated: i < m_groups.size()
0
931 if (!m_groups.at(i)->shares().isEmpty()) {
never evaluated: !m_groups.at(i)->shares().isEmpty()
0
932 QOpenGLContext *context = m_groups.at(i)->shares().first();
never executed (the execution status of this line is deduced): QOpenGLContext *context = m_groups.at(i)->shares().first();
-
933 QOpenGLSharedResource *resource = value(context);
never executed (the execution status of this line is deduced): QOpenGLSharedResource *resource = value(context);
-
934 if (resource)
never evaluated: resource
0
935 resource->free();
never executed: resource->free();
0
936 }
never executed: }
0
937 m_groups.at(i)->d_func()->m_resources.remove(this);
never executed (the execution status of this line is deduced): m_groups.at(i)->d_func()->m_resources.remove(this);
-
938 active.deref();
never executed (the execution status of this line is deduced): active.deref();
-
939 }
never executed: }
0
940#ifndef QT_NO_DEBUG -
941 if (active.load() != 0) { -
942 qWarning("QtGui: Resources are still available at program shutdown.\n" -
943 " This is possibly caused by a leaked QOpenGLWidget, \n" -
944 " QOpenGLFramebufferObject or QOpenGLPixelBuffer."); -
945 } -
946#endif -
947}
never executed: }
0
948 -
949void QOpenGLMultiGroupSharedResource::insert(QOpenGLContext *context, QOpenGLSharedResource *value) -
950{ -
951#ifdef QT_GL_CONTEXT_RESOURCE_DEBUG -
952 qDebug("Inserting context group resource %p for context %p, managed by %p.", value, context, this); -
953#endif -
954 QOpenGLContextGroup *group = context->shareGroup();
never executed (the execution status of this line is deduced): QOpenGLContextGroup *group = context->shareGroup();
-
955 Q_ASSERT(!group->d_func()->m_resources.contains(this));
never executed (the execution status of this line is deduced): qt_noop();
-
956 group->d_func()->m_resources.insert(this, value);
never executed (the execution status of this line is deduced): group->d_func()->m_resources.insert(this, value);
-
957 m_groups.append(group);
never executed (the execution status of this line is deduced): m_groups.append(group);
-
958 active.ref();
never executed (the execution status of this line is deduced): active.ref();
-
959}
never executed: }
0
960 -
961QOpenGLSharedResource *QOpenGLMultiGroupSharedResource::value(QOpenGLContext *context) -
962{ -
963 QOpenGLContextGroup *group = context->shareGroup();
never executed (the execution status of this line is deduced): QOpenGLContextGroup *group = context->shareGroup();
-
964 return group->d_func()->m_resources.value(this, 0);
never executed: return group->d_func()->m_resources.value(this, 0);
0
965} -
966 -
967QList<QOpenGLSharedResource *> QOpenGLMultiGroupSharedResource::resources() const -
968{ -
969 QList<QOpenGLSharedResource *> result;
never executed (the execution status of this line is deduced): QList<QOpenGLSharedResource *> result;
-
970 for (QList<QOpenGLContextGroup *>::const_iterator it = m_groups.constBegin(); it != m_groups.constEnd(); ++it) {
never evaluated: it != m_groups.constEnd()
0
971 QOpenGLSharedResource *resource = (*it)->d_func()->m_resources.value(const_cast<QOpenGLMultiGroupSharedResource *>(this), 0);
never executed (the execution status of this line is deduced): QOpenGLSharedResource *resource = (*it)->d_func()->m_resources.value(const_cast<QOpenGLMultiGroupSharedResource *>(this), 0);
-
972 if (resource)
never evaluated: resource
0
973 result << resource;
never executed: result << resource;
0
974 }
never executed: }
0
975 return result;
never executed: return result;
0
976} -
977 -
978void QOpenGLMultiGroupSharedResource::cleanup(QOpenGLContextGroup *group, QOpenGLSharedResource *value) -
979{ -
980#ifdef QT_GL_CONTEXT_RESOURCE_DEBUG -
981 qDebug("Cleaning up context group resource %p, for group %p in thread %p.", this, group, QThread::currentThread()); -
982#endif -
983 value->invalidateResource();
never executed (the execution status of this line is deduced): value->invalidateResource();
-
984 value->free();
never executed (the execution status of this line is deduced): value->free();
-
985 active.deref();
never executed (the execution status of this line is deduced): active.deref();
-
986 -
987 Q_ASSERT(m_groups.contains(group));
never executed (the execution status of this line is deduced): qt_noop();
-
988 m_groups.removeOne(group);
never executed (the execution status of this line is deduced): m_groups.removeOne(group);
-
989}
never executed: }
0
990 -
991QT_END_NAMESPACE -
992 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial