diff options
author | Jørgen Lind <jorgen.lind@nokia.com> | 2010-11-26 14:59:30 (GMT) |
---|---|---|
committer | Jørgen Lind <jorgen.lind@nokia.com> | 2010-11-26 15:06:05 (GMT) |
commit | 71abe300263d9f6bcd6e061e889a58111c48f92a (patch) | |
tree | 1d56f5244b8336de0b64e6e3131b8cedb514be6a /src/opengl | |
parent | 896c51e4d41a7fee06a1601f1b25746f9f98be88 (diff) | |
download | Qt-71abe300263d9f6bcd6e061e889a58111c48f92a.zip Qt-71abe300263d9f6bcd6e061e889a58111c48f92a.tar.gz Qt-71abe300263d9f6bcd6e061e889a58111c48f92a.tar.bz2 |
Make QtOpenGL use shared contextexts on Lighthouse
Diffstat (limited to 'src/opengl')
-rw-r--r-- | src/opengl/qgl.cpp | 24 | ||||
-rw-r--r-- | src/opengl/qgl_qpa.cpp | 33 | ||||
-rw-r--r-- | src/opengl/qglpixmapfilter.cpp | 2 | ||||
-rw-r--r-- | src/opengl/qpixmapdata_gl.cpp | 30 | ||||
-rw-r--r-- | src/opengl/qwindowsurface_gl.cpp | 32 | ||||
-rw-r--r-- | src/opengl/qwindowsurface_gl_p.h | 4 |
6 files changed, 89 insertions, 36 deletions
diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 111a3e4..dc7a333 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -2095,14 +2095,6 @@ QGLContext::QGLContext(const QGLFormat &format) d->init(0, format); } -QGLContext::QGLContext(QPlatformGLContext *platformContext) - : d_ptr(new QGLContextPrivate(this)) -{ - Q_D(QGLContext); - d->init(0,QGLFormat::fromPlatformWindowFormat(platformContext->platformWindowFormat())); - d->platformContext = platformContext; -} - /*! Destroys the OpenGL context and frees its resources. */ @@ -3788,7 +3780,13 @@ QGLWidget::QGLWidget(QWidget *parent, const QGLWidget* shareWidget, Qt::WindowFl setAttribute(Qt::WA_NoSystemBackground); setAutoFillBackground(true); // for compatibility #ifdef Q_WS_QPA - setPlatformWindowFormat(QGLFormat::toPlatformWindowFormat(QGLFormat::defaultFormat())); + QPlatformWindowFormat platformFormat = QGLFormat::toPlatformWindowFormat(QGLFormat::defaultFormat()); + platformFormat.setUseDefaultSharedContext(false); + if (shareWidget && shareWidget->d_func()->glcx) { + QPlatformGLContext *sharedPlatformContext = shareWidget->d_func()->glcx->d_func()->platformContext; + platformFormat.setSharedContext(sharedPlatformContext); + } + setPlatformWindowFormat(platformFormat); winId(); // create window; QGLContext *glContext = 0; if (platformWindow()) @@ -3839,7 +3837,13 @@ QGLWidget::QGLWidget(const QGLFormat &format, QWidget *parent, const QGLWidget* setAttribute(Qt::WA_NoSystemBackground); setAutoFillBackground(true); // for compatibility #ifdef Q_WS_QPA - setPlatformWindowFormat(QGLFormat::toPlatformWindowFormat(QGLFormat::defaultFormat())); + QPlatformWindowFormat platformFormat = QGLFormat::toPlatformWindowFormat(format); + platformFormat.setUseDefaultSharedContext(false); + if (shareWidget && shareWidget->d_func()->glcx) { + QPlatformGLContext *sharedPlatformContext = shareWidget->d_func()->glcx->d_func()->platformContext; + platformFormat.setSharedContext(sharedPlatformContext); + } + setPlatformWindowFormat(platformFormat); winId(); // create window; QGLContext *glContext = 0; if (platformWindow()) diff --git a/src/opengl/qgl_qpa.cpp b/src/opengl/qgl_qpa.cpp index d45f246..415e915 100644 --- a/src/opengl/qgl_qpa.cpp +++ b/src/opengl/qgl_qpa.cpp @@ -129,11 +129,7 @@ void qDeleteQGLContext(void *handle) bool QGLContext::chooseContext(const QGLContext* shareContext) { Q_D(QGLContext); - if (d->platformContext && !d->platformContext->qGLContextHandle()) { - d->platformContext->setQGLContextHandle(this,qDeleteQGLContext); - d->glFormat = QGLFormat::fromPlatformWindowFormat(d->platformContext->platformWindowFormat()); - d->valid = true; - }else if(!d->paintDevice || d->paintDevice->devType() != QInternal::Widget) { + if(!d->paintDevice || d->paintDevice->devType() != QInternal::Widget) { d->valid = false; }else { QWidget *widget = static_cast<QWidget *>(d->paintDevice); @@ -157,6 +153,18 @@ bool QGLContext::chooseContext(const QGLContext* shareContext) } } + if (d->valid) { + QPlatformGLContext *sharedPlatformGLContext = d->platformContext->platformWindowFormat().sharedGLContext(); + if (sharedPlatformGLContext) { + QGLContext *actualSharedContext = QGLContext::fromPlatformGLContext(sharedPlatformGLContext); + if (actualSharedContext == shareContext) { + d->sharing = true;//Will add combination in QGLContext::create + }else { + QGLContextGroup::addShare(this,actualSharedContext); + } + } + } + return d->valid; } @@ -173,13 +181,15 @@ void QGLContext::reset() d->transpColor = QColor(); d->initDone = false; QGLContextGroup::removeShare(this); + if (d->platformContext) { + d->platformContext->setQGLContextHandle(0,0); + } } void QGLContext::makeCurrent() { Q_D(QGLContext); d->platformContext->makeCurrent(); - QGLContextPrivate::setCurrentContext(this); if (!d->workaroundsCached) { d->workaroundsCached = true; @@ -195,7 +205,6 @@ void QGLContext::doneCurrent() { Q_D(QGLContext); d->platformContext->doneCurrent(); - QGLContextPrivate::setCurrentContext(0); } void QGLContext::swapBuffers() const @@ -279,6 +288,8 @@ QGLTemporaryContext::QGLTemporaryContext(bool, QWidget *) d->widget->setGeometry(0,0,3,3); QPlatformWindowFormat format = d->widget->platformWindowFormat(); format.setWindowApi(QPlatformWindowFormat::OpenGL); + format.setWindowSurface(false); + d->widget->setPlatformWindowFormat(format); d->widget->winId(); d->widget->platformWindow()->glContext()->makeCurrent(); @@ -360,6 +371,13 @@ void QGLWidget::setColormap(const QGLColormap & c) Q_UNUSED(c); } +QGLContext::QGLContext(QPlatformGLContext *platformContext) + : d_ptr(new QGLContextPrivate(this)) +{ + Q_D(QGLContext); + d->init(0,QGLFormat::fromPlatformWindowFormat(platformContext->platformWindowFormat())); + d->platformContext = platformContext; +} QGLContext *QGLContext::fromPlatformGLContext(QPlatformGLContext *platformContext) { @@ -379,5 +397,4 @@ QGLContext *QGLContext::fromPlatformGLContext(QPlatformGLContext *platformContex return glContext; } - QT_END_NAMESPACE diff --git a/src/opengl/qglpixmapfilter.cpp b/src/opengl/qglpixmapfilter.cpp index 73d698c..6c20aae 100644 --- a/src/opengl/qglpixmapfilter.cpp +++ b/src/opengl/qglpixmapfilter.cpp @@ -125,7 +125,7 @@ protected: bool processGL(QPainter *painter, const QPointF &pos, const QPixmap &src, const QRectF &srcRect) const; }; -extern QGLWidget *qt_gl_share_widget(); +extern const QGLContext *qt_gl_share_context(); QPixmapFilter *QGL2PaintEngineEx::pixmapFilter(int type, const QPixmapFilter *prototype) { diff --git a/src/opengl/qpixmapdata_gl.cpp b/src/opengl/qpixmapdata_gl.cpp index cd7f0c2..1cf5bd7 100644 --- a/src/opengl/qpixmapdata_gl.cpp +++ b/src/opengl/qpixmapdata_gl.cpp @@ -58,7 +58,7 @@ QT_BEGIN_NAMESPACE -extern QGLWidget* qt_gl_share_widget(); +extern const QGLContext* qt_gl_share_context(); /*! \class QGLFramebufferObjectPool @@ -261,14 +261,14 @@ QGLPixmapData::QGLPixmapData(PixelType type) QGLPixmapData::~QGLPixmapData() { - QGLWidget *shareWidget = qt_gl_share_widget(); - if (!shareWidget) + const QGLContext *shareContext = qt_gl_share_context(); + if (!shareContext) return; delete m_engine; if (m_texture.id) { - QGLShareContextScope ctx(shareWidget->context()); + QGLShareContextScope ctx(shareContext); glDeleteTextures(1, &m_texture.id); } } @@ -288,7 +288,7 @@ bool QGLPixmapData::isValidContext(const QGLContext *ctx) const if (ctx == m_ctx) return true; - const QGLContext *share_ctx = qt_gl_share_widget()->context(); + const QGLContext *share_ctx = qt_gl_share_context(); return ctx == share_ctx || QGLContext::areSharing(ctx, share_ctx); } @@ -308,7 +308,7 @@ void QGLPixmapData::resize(int width, int height) d = pixelType() == QPixmapData::PixmapType ? 32 : 1; if (m_texture.id) { - QGLShareContextScope ctx(qt_gl_share_widget()->context()); + QGLShareContextScope ctx(qt_gl_share_context()); glDeleteTextures(1, &m_texture.id); m_texture.id = 0; } @@ -325,7 +325,7 @@ void QGLPixmapData::ensureCreated() const m_dirty = false; - QGLShareContextScope ctx(qt_gl_share_widget()->context()); + QGLShareContextScope ctx(qt_gl_share_context()); m_ctx = ctx; const GLenum internal_format = m_hasAlpha ? GL_RGBA : GL_RGB; @@ -399,7 +399,7 @@ void QGLPixmapData::fromImage(const QImage &image, d = m_source.depth(); if (m_texture.id) { - QGLShareContextScope ctx(qt_gl_share_widget()->context()); + QGLShareContextScope ctx(qt_gl_share_context()); glDeleteTextures(1, &m_texture.id); m_texture.id = 0; } @@ -420,7 +420,7 @@ bool QGLPixmapData::fromFile(const QString &filename, const char *format, resize(0, 0); data = file.readAll(); file.close(); - QGLShareContextScope ctx(qt_gl_share_widget()->context()); + QGLShareContextScope ctx(qt_gl_share_context()); QSize size = m_texture.bindCompressedTexture (data.constData(), data.size(), format); if (!size.isEmpty()) { @@ -446,7 +446,7 @@ bool QGLPixmapData::fromData(const uchar *buffer, uint len, const char *format, const char *buf = reinterpret_cast<const char *>(buffer); if (m_texture.canBindCompressedTexture(buf, int(len), format, &alpha)) { resize(0, 0); - QGLShareContextScope ctx(qt_gl_share_widget()->context()); + QGLShareContextScope ctx(qt_gl_share_context()); QSize size = m_texture.bindCompressedTexture(buf, int(len), format); if (!size.isEmpty()) { w = size.width(); @@ -479,7 +479,7 @@ void QGLPixmapData::copy(const QPixmapData *data, const QRect &rect) const QGLPixmapData *other = static_cast<const QGLPixmapData *>(data); if (other->m_renderFbo) { - QGLShareContextScope ctx(qt_gl_share_widget()->context()); + QGLShareContextScope ctx(qt_gl_share_context()); resize(rect.width(), rect.height()); m_hasAlpha = other->m_hasAlpha; @@ -593,7 +593,7 @@ QImage QGLPixmapData::toImage() const ensureCreated(); } - QGLShareContextScope ctx(qt_gl_share_widget()->context()); + QGLShareContextScope ctx(qt_gl_share_context()); glBindTexture(GL_TEXTURE_2D, m_texture.id); return qt_gl_read_texture(QSize(w, h), true, true); } @@ -617,7 +617,7 @@ void QGLPixmapData::copyBackFromRenderFbo(bool keepCurrentFboBound) const m_hasFillColor = false; - const QGLContext *share_ctx = qt_gl_share_widget()->context(); + const QGLContext *share_ctx = qt_gl_share_context(); QGLShareContextScope ctx(share_ctx); ensureCreated(); @@ -672,8 +672,8 @@ QPaintEngine* QGLPixmapData::paintEngine() const extern QGLWidget* qt_gl_share_widget(); if (!QGLContext::currentContext()) - qt_gl_share_widget()->makeCurrent(); - QGLShareContextScope ctx(qt_gl_share_widget()->context()); + const_cast<QGLContext *>(qt_gl_share_context())->makeCurrent(); + QGLShareContextScope ctx(qt_gl_share_context()); QGLFramebufferObjectFormat format; format.setAttachment(QGLFramebufferObject::CombinedDepthStencil); diff --git a/src/opengl/qwindowsurface_gl.cpp b/src/opengl/qwindowsurface_gl.cpp index 47f36dd..cd7558c 100644 --- a/src/opengl/qwindowsurface_gl.cpp +++ b/src/opengl/qwindowsurface_gl.cpp @@ -182,6 +182,7 @@ QGLGraphicsSystem::QGLGraphicsSystem(bool useX11GL) // QGLWindowSurface // +#ifndef Q_WS_QPA class QGLGlobalShareWidget { public: @@ -255,6 +256,23 @@ void qt_destroy_gl_share_widget() { _qt_gl_share_widget()->destroy(); } +#endif//Q_WS_QPA + +const QGLContext *qt_gl_share_context() +{ +#ifdef Q_WS_QPA + //make it possible to have an assesor to defaultSharedGLContext. + const QPlatformGLContext *platformContext = QPlatformGLContext::defaultSharedContext(); + if (!platformContext) + qDebug() << "Please implement a defaultSharedContext for your platformplugin"; + return QGLContext::fromPlatformGLContext(const_cast<QPlatformGLContext *>(platformContext)); +#else + QGLWidget *widget = qt_gl_share_widget(); + if (widget) + return widget->context(); + return 0; +#endif +} struct QGLWindowSurfacePrivate { @@ -336,10 +354,12 @@ QGLWindowSurface::~QGLWindowSurface() { if (d_ptr->ctx) glDeleteTextures(1, &d_ptr->tex_id); +#ifndef Q_WS_QPA // Dont delete the contexts. Destroying the window does that for us foreach(QGLContext **ctx, d_ptr->contexts) { delete *ctx; *ctx = 0; } +#endif delete d_ptr->pb; delete d_ptr->fbo; @@ -356,6 +376,7 @@ void QGLWindowSurface::deleted(QObject *object) d_ptr->fbo = 0; } +#ifndef Q_WS_QPA //no need to specifically delete the QGLContext as it will be deleted by QWidget QWidgetPrivate *widgetPrivate = widget->d_func(); if (widgetPrivate->extraData()) { union { QGLContext **ctxPtrPtr; void **voidPtrPtr; }; @@ -367,6 +388,7 @@ void QGLWindowSurface::deleted(QObject *object) d_ptr->contexts.removeAt(index); } } +#endif } } @@ -377,8 +399,14 @@ void QGLWindowSurface::hijackWindow(QWidget *widget) if (widgetPrivate->extraData()->glContext) return; +#ifdef Q_WS_QPA + QGLContext *ctx = QGLContext::fromPlatformGLContext(widget->platformWindow()->glContext()); + if (!d_ptr->fbo && d_ptr->tried_fbo) + d_ptr->ctx = ctx; +#else QGLContext *ctx = new QGLContext(surfaceFormat, widget); ctx->create(qt_gl_share_widget()->context()); +#endif #ifndef QT_NO_EGL static bool checkedForNOKSwapRegion = false; @@ -816,7 +844,7 @@ void QGLWindowSurface::updateGeometry() { } } -#if !defined(QT_OPENGL_ES_2) +#if !defined(QT_OPENGL_ES_2) && !defined(Q_WS_QPA) //QPA doesn't support pixelbuffers if (d_ptr->destructive_swap_buffers && (d_ptr->pb || !d_ptr->tried_pb)) { d_ptr->tried_pb = true; @@ -855,7 +883,7 @@ void QGLWindowSurface::updateGeometry() { d_ptr->pb = 0; } } -#endif // !defined(QT_OPENGL_ES_2) +#endif // !defined(QT_OPENGL_ES_2) !defined(Q_WS_QPA) ctx->makeCurrent(); diff --git a/src/opengl/qwindowsurface_gl_p.h b/src/opengl/qwindowsurface_gl_p.h index 4f4ec92..22bd5f0 100644 --- a/src/opengl/qwindowsurface_gl_p.h +++ b/src/opengl/qwindowsurface_gl_p.h @@ -66,8 +66,12 @@ class QRegion; class QWidget; struct QGLWindowSurfacePrivate; +#ifdef Q_WS_QPA +Q_OPENGL_EXPORT const QGLContext* qt_gl_share_context(); +#else Q_OPENGL_EXPORT QGLWidget* qt_gl_share_widget(); Q_OPENGL_EXPORT void qt_destroy_gl_share_widget(); +#endif class QGLWindowSurfaceGLPaintDevice : public QGLPaintDevice { |