Added private API for enabling sharing between the QQuickwindow instances.

This API is primarily a hook which is needed by the Qt WebEngine to
set up sharing with the scene graph's OpenGL contexts.

Change-Id: I5bb03abd9ab99f502db8e413fe838a8b30365b8d
Reviewed-by: Jocelyn Turcotte <jocelyn.turcotte@digia.com>
This commit is contained in:
Gunnar Sletta 2013-10-30 14:32:54 +01:00 committed by The Qt Project
parent 2192e5005b
commit 5b05a78d00
6 changed files with 66 additions and 12 deletions

View File

@ -117,8 +117,12 @@ public:
QSGContext::AntialiasingMethod antialiasingMethod;
bool distanceFieldDisabled;
QSGDistanceFieldGlyphNode::AntialiasingMode distanceFieldAntialiasing;
static QOpenGLContext *sharedOpenGLContext;
};
QOpenGLContext *QSGContextPrivate::sharedOpenGLContext = 0;
class QSGTextureCleanupEvent : public QEvent
{
public:
@ -170,6 +174,20 @@ QSGContext::~QSGContext()
{
}
/*!
* This function is used by the Qt WebEngine to set up context sharing
* across multiple windows. Do not use it for any other purpose.
*/
void QSGContext::setSharedOpenGLContext(QOpenGLContext *context)
{
QSGContextPrivate::sharedOpenGLContext = context;
}
QOpenGLContext *QSGContext::sharedOpenGLContext()
{
return QSGContextPrivate::sharedOpenGLContext;
}
void QSGContext::renderContextInitialized(QSGRenderContext *renderContext)
{
Q_D(QSGContext);

View File

@ -162,6 +162,9 @@ public:
virtual QSize minimumFBOSize() const;
virtual QSurfaceFormat defaultSurfaceFormat() const;
static void setSharedOpenGLContext(QOpenGLContext *context);
static QOpenGLContext *sharedOpenGLContext();
void setDistanceFieldEnabled(bool enabled);
bool isDistanceFieldEnabled() const;

View File

@ -264,6 +264,8 @@ void QSGGuiThreadRenderLoop::renderWindow(QQuickWindow *window)
if (!gl) {
gl = new QOpenGLContext();
gl->setFormat(window->requestedFormat());
if (QSGContext::sharedOpenGLContext())
gl->setShareContext(QSGContext::sharedOpenGLContext());
if (!gl->create()) {
delete gl;
gl = 0;

View File

@ -889,6 +889,8 @@ void QSGThreadedRenderLoop::handleExposure(Window *w)
if (!w->thread->gl) {
w->thread->gl = new QOpenGLContext();
if (QSGContext::sharedOpenGLContext())
w->thread->gl->setShareContext(QSGContext::sharedOpenGLContext());
w->thread->gl->setFormat(w->window->requestedFormat());
if (!w->thread->gl->create()) {
delete w->thread->gl;

View File

@ -178,6 +178,8 @@ void QSGWindowsRenderLoop::show(QQuickWindow *window)
RLDEBUG(" - creating GL context");
m_gl = new QOpenGLContext();
m_gl->setFormat(window->requestedFormat());
if (QSGContext::sharedOpenGLContext())
m_gl->setShareContext(QSGContext::sharedOpenGLContext());
m_gl->create();
QSG_RENDER_TIMING_SAMPLE(time_created);
RLDEBUG(" - making current");

View File

@ -42,8 +42,8 @@
#include <qtest.h>
#include <QtQuick>
#include <private/qquickanimator_p.h>
#include <private/qsgcontext_p.h>
#include <QtQml>
@ -99,9 +99,13 @@ bool containsSomethingOtherThanWhite(const QImage &image)
return false;
}
// To compare images, we need a special function with a bit of error
// as glyphs has an invisible, but measurable variance depending
// on where in the glyph cache they end up.
// When running on native Nvidia graphics cards on linux, the
// distance field glyph pixels have a measurable, but not visible
// pixel error. Use a custom compare function to avoid
//
// This was GT-216 with the ubuntu "nvidia-319" driver package.
// llvmpipe does not show the same issue.
//
bool compareImages(const QImage &ia, const QImage &ib)
{
if (ia.size() != ib.size())
@ -137,21 +141,44 @@ void tst_SceneGraph::manyWindows_data()
{
QTest::addColumn<QString>("file");
QTest::addColumn<bool>("toplevel");
QTest::addColumn<bool>("shared");
QTest::newRow("image,toplevel") << QStringLiteral("manyWindows_image.qml") << true;
QTest::newRow("image,subwindow") << QStringLiteral("manyWindows_image.qml") << false;
QTest::newRow("dftext,toplevel") << QStringLiteral("manyWindows_dftext.qml") << true;
QTest::newRow("dftext,subwindow") << QStringLiteral("manyWindows_dftext.qml") << false;
QTest::newRow("ntext,toplevel") << QStringLiteral("manyWindows_ntext.qml") << true;
QTest::newRow("ntext,subwindow") << QStringLiteral("manyWindows_ntext.qml") << false;
QTest::newRow("rects,toplevel") << QStringLiteral("manyWindows_rects.qml") << true;
QTest::newRow("rects,subwindow") << QStringLiteral("manyWindows_rects.qml") << false;
QTest::newRow("image,toplevel") << QStringLiteral("manyWindows_image.qml") << true << false;
QTest::newRow("image,subwindow") << QStringLiteral("manyWindows_image.qml") << false << false;
QTest::newRow("dftext,toplevel") << QStringLiteral("manyWindows_dftext.qml") << true << false;
QTest::newRow("dftext,subwindow") << QStringLiteral("manyWindows_dftext.qml") << false << false;
QTest::newRow("ntext,toplevel") << QStringLiteral("manyWindows_ntext.qml") << true << false;
QTest::newRow("ntext,subwindow") << QStringLiteral("manyWindows_ntext.qml") << false << false;
QTest::newRow("rects,toplevel") << QStringLiteral("manyWindows_rects.qml") << true << false;
QTest::newRow("rects,subwindow") << QStringLiteral("manyWindows_rects.qml") << false << false;
QTest::newRow("image,toplevel,sharing") << QStringLiteral("manyWindows_image.qml") << true << true;
QTest::newRow("image,subwindow,sharing") << QStringLiteral("manyWindows_image.qml") << false << true;
QTest::newRow("dftext,toplevel,sharing") << QStringLiteral("manyWindows_dftext.qml") << true << true;
QTest::newRow("dftext,subwindow,sharing") << QStringLiteral("manyWindows_dftext.qml") << false << true;
QTest::newRow("ntext,toplevel,sharing") << QStringLiteral("manyWindows_ntext.qml") << true << true;
QTest::newRow("ntext,subwindow,sharing") << QStringLiteral("manyWindows_ntext.qml") << false << true;
QTest::newRow("rects,toplevel,sharing") << QStringLiteral("manyWindows_rects.qml") << true << true;
QTest::newRow("rects,subwindow,sharing") << QStringLiteral("manyWindows_rects.qml") << false << true;
}
struct ShareContextResetter {
public:
~ShareContextResetter() { QSGContext::setSharedOpenGLContext(0); }
};
void tst_SceneGraph::manyWindows()
{
QFETCH(QString, file);
QFETCH(bool, toplevel);
QFETCH(bool, shared);
QOpenGLContext sharedGLContext;
ShareContextResetter cleanup; // To avoid dangling pointer in case of test-failure.
if (shared) {
sharedGLContext.create();
QSGContext::setSharedOpenGLContext(&sharedGLContext);
}
QScopedPointer<QWindow> parent;
if (!toplevel) {