diff options
Diffstat (limited to 'src/gui/kernel/qplatformglcontext_qpa.cpp')
-rw-r--r-- | src/gui/kernel/qplatformglcontext_qpa.cpp | 157 |
1 files changed, 28 insertions, 129 deletions
diff --git a/src/gui/kernel/qplatformglcontext_qpa.cpp b/src/gui/kernel/qplatformglcontext_qpa.cpp index b0c6aeb27a..81030b8cfe 100644 --- a/src/gui/kernel/qplatformglcontext_qpa.cpp +++ b/src/gui/kernel/qplatformglcontext_qpa.cpp @@ -41,135 +41,6 @@ #include "qplatformglcontext_qpa.h" -#include <QtCore/QThreadStorage> -#include <QtCore/QThread> - -#include <QDebug> - -class QPlatformGLThreadContext -{ -public: - ~QPlatformGLThreadContext() { - if (context) - context->doneCurrent(); - } - QPlatformGLContext *context; -}; - -static QThreadStorage<QPlatformGLThreadContext *> qplatformgl_context_storage; - -class QPlatformGLContextPrivate -{ -public: - QPlatformGLContextPrivate() - : qGLContextHandle(0) - , qGLContextDeleteFunction(0) - { - } - - virtual ~QPlatformGLContextPrivate() - { - //do not delete the QGLContext handle here as it is deleted in - //QWidgetPrivate::deleteTLSysExtra() - } - void *qGLContextHandle; - void (*qGLContextDeleteFunction)(void *handle); - static QPlatformGLContext *staticSharedContext; - - static void setCurrentContext(QPlatformGLContext *context); -}; - -QPlatformGLContext *QPlatformGLContextPrivate::staticSharedContext = 0; - -void QPlatformGLContextPrivate::setCurrentContext(QPlatformGLContext *context) -{ - QPlatformGLThreadContext *threadContext = qplatformgl_context_storage.localData(); - if (!threadContext) { - if (!QThread::currentThread()) { - qWarning("No QTLS available. currentContext wont work"); - return; - } - threadContext = new QPlatformGLThreadContext; - qplatformgl_context_storage.setLocalData(threadContext); - } - threadContext->context = context; -} - -/*! - Returns the last context which called makeCurrent. This function is thread aware. -*/ -const QPlatformGLContext* QPlatformGLContext::currentContext() -{ - QPlatformGLThreadContext *threadContext = qplatformgl_context_storage.localData(); - if(threadContext) { - return threadContext->context; - } - return 0; -} - -/*! - All subclasses needs to specify the platformWindow. It can be a null window. -*/ -QPlatformGLContext::QPlatformGLContext() - :d_ptr(new QPlatformGLContextPrivate()) -{ -} - -/*! - If this is the current context for the thread, doneCurrent is called -*/ -QPlatformGLContext::~QPlatformGLContext() -{ - if (QPlatformGLContext::currentContext() == this) { - doneCurrent(); - } - -} - -/*! - Reimplement in subclass to do makeCurrent on native GL context -*/ -void QPlatformGLContext::makeCurrent() -{ - QPlatformGLContextPrivate::setCurrentContext(this); -} - -/*! - Reimplement in subclass to release current context. - Typically this is calling makeCurrent with 0 "surface" -*/ -void QPlatformGLContext::doneCurrent() -{ - QPlatformGLContextPrivate::setCurrentContext(0); -} - -/* - internal: Needs to have a pointer to qGLContext. But since this is in QtGui we cant - have any type information. -*/ -void *QPlatformGLContext::qGLContextHandle() const -{ - Q_D(const QPlatformGLContext); - return d->qGLContextHandle; -} - -void QPlatformGLContext::setQGLContextHandle(void *handle,void (*qGLContextDeleteFunction)(void *)) -{ - Q_D(QPlatformGLContext); - d->qGLContextHandle = handle; - d->qGLContextDeleteFunction = qGLContextDeleteFunction; -} - -void QPlatformGLContext::deleteQGLContext() -{ - Q_D(QPlatformGLContext); - if (d->qGLContextDeleteFunction && d->qGLContextHandle) { - d->qGLContextDeleteFunction(d->qGLContextHandle); - d->qGLContextDeleteFunction = 0; - d->qGLContextHandle = 0; - } -} - /*! \class QPlatformGLContext \since 4.8 @@ -208,3 +79,31 @@ void QPlatformGLContext::deleteQGLContext() Reimplement this function in a subclass to indicate what format the glContext actually has. */ + +struct QPlatformGLContextPrivate +{ + QGuiGLContext *context; +}; + +QPlatformGLContext::QPlatformGLContext() + : d_ptr(new QPlatformGLContextPrivate) +{ + Q_D(QPlatformGLContext); + d->context = 0; +} + +QPlatformGLContext::~QPlatformGLContext() +{ +} + +QGuiGLContext *QPlatformGLContext::context() const +{ + Q_D(const QPlatformGLContext); + return d->context; +} + +void QPlatformGLContext::setContext(QGuiGLContext *context) +{ + Q_D(QPlatformGLContext); + d->context = context; +} |