summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/opengl/pbuffers/cube.h2
-rw-r--r--examples/opengl/pbuffers/glwidget.h1
-rw-r--r--src/opengl/qgl_p.h2
-rw-r--r--tests/auto/qgl/tst_qgl.cpp122
4 files changed, 125 insertions, 2 deletions
diff --git a/examples/opengl/pbuffers/cube.h b/examples/opengl/pbuffers/cube.h
index 4f29b7d..1974f4f 100644
--- a/examples/opengl/pbuffers/cube.h
+++ b/examples/opengl/pbuffers/cube.h
@@ -42,7 +42,7 @@
#ifndef CUBE_H
#define CUBE_H
-#include <QtOpenGl/qgl.h>
+#include <QtOpenGL/qgl.h>
#include <QtCore/qvector.h>
#include <QtGui/qmatrix4x4.h>
#include <QtGui/qvector3d.h>
diff --git a/examples/opengl/pbuffers/glwidget.h b/examples/opengl/pbuffers/glwidget.h
index 991e8b9..c019abe 100644
--- a/examples/opengl/pbuffers/glwidget.h
+++ b/examples/opengl/pbuffers/glwidget.h
@@ -47,6 +47,7 @@
class Geometry;
class Cube;
class Tile;
+class QGLPixelBuffer;
class GLWidget : public QGLWidget
{
diff --git a/src/opengl/qgl_p.h b/src/opengl/qgl_p.h
index 2e8ac88..a113b0f 100644
--- a/src/opengl/qgl_p.h
+++ b/src/opengl/qgl_p.h
@@ -399,7 +399,7 @@ public:
Q_DECLARE_OPERATORS_FOR_FLAGS(QGLExtensions::Extensions)
-class QGLShareRegister
+class Q_AUTOTEST_EXPORT QGLShareRegister
{
public:
QGLShareRegister() {}
diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp
index 8027e9b..a49f543 100644
--- a/tests/auto/qgl/tst_qgl.cpp
+++ b/tests/auto/qgl/tst_qgl.cpp
@@ -54,6 +54,10 @@
#include <QGraphicsProxyWidget>
#include <QVBoxLayout>
+#ifdef QT_BUILD_INTERNAL
+#include <QtOpenGL/private/qgl_p.h>
+#endif
+
//TESTED_CLASS=
//TESTED_FILES=
@@ -85,6 +89,7 @@ private slots:
void replaceClipping();
void clipTest();
void destroyFBOAfterContext();
+ void shareRegister();
};
tst_QGL::tst_QGL()
@@ -1749,5 +1754,122 @@ void tst_QGL::destroyFBOAfterContext()
delete fbo;
}
+void tst_QGL::shareRegister()
+{
+#ifdef QT_BUILD_INTERNAL
+ QGLShareRegister *shareReg = qgl_share_reg();
+ QVERIFY(shareReg != 0);
+
+ // Create a context.
+ QGLWidget *glw1 = new QGLWidget();
+ glw1->makeCurrent();
+
+ // Nothing should be sharing with glw1's context yet.
+ QList<const QGLContext *> list;
+ list = shareReg->shares(glw1->context());
+ QCOMPARE(list.size(), 0);
+
+ // Create a guard for the first context.
+ QGLSharedResourceGuard guard(glw1->context());
+ QVERIFY(guard.id() == 0);
+ guard.setId(3);
+ QVERIFY(guard.id() == 3);
+
+ // Create another context that shares with the first.
+ QGLWidget *glw2 = new QGLWidget(0, glw1);
+ if (!glw2->isSharing()) {
+ delete glw2;
+ delete glw1;
+ QSKIP("Context sharing is not supported", SkipSingle);
+ }
+ QVERIFY(glw1->context() != glw2->context());
+
+ // Guard should still be the same.
+ QVERIFY(guard.context() == glw1->context());
+ QVERIFY(guard.id() == 3);
+
+ // Now there are two items in the share lists.
+ list = shareReg->shares(glw1->context());
+ QCOMPARE(list.size(), 2);
+ QVERIFY(list.contains(glw1->context()));
+ QVERIFY(list.contains(glw2->context()));
+ list = shareReg->shares(glw2->context());
+ QCOMPARE(list.size(), 2);
+ QVERIFY(list.contains(glw1->context()));
+ QVERIFY(list.contains(glw2->context()));
+
+ // Check the sharing relationships.
+ QVERIFY(shareReg->checkSharing(glw1->context(), glw1->context()));
+ QVERIFY(shareReg->checkSharing(glw2->context(), glw2->context()));
+ QVERIFY(shareReg->checkSharing(glw1->context(), glw2->context()));
+ QVERIFY(shareReg->checkSharing(glw2->context(), glw1->context()));
+ QVERIFY(!shareReg->checkSharing(0, glw2->context()));
+ QVERIFY(!shareReg->checkSharing(glw1->context(), 0));
+ QVERIFY(!shareReg->checkSharing(0, 0));
+
+ // Create a third context, not sharing with the others.
+ QGLWidget *glw3 = new QGLWidget();
+
+ // Create a guard on the standalone context.
+ QGLSharedResourceGuard guard3(glw3->context());
+ guard3.setId(5);
+
+ // First two should still be sharing, but third is in its own list.
+ list = shareReg->shares(glw1->context());
+ QCOMPARE(list.size(), 2);
+ QVERIFY(list.contains(glw1->context()));
+ QVERIFY(list.contains(glw2->context()));
+ list = shareReg->shares(glw2->context());
+ QCOMPARE(list.size(), 2);
+ QVERIFY(list.contains(glw1->context()));
+ QVERIFY(list.contains(glw2->context()));
+ list = shareReg->shares(glw3->context());
+ QCOMPARE(list.size(), 0);
+
+ // Check the sharing relationships again.
+ QVERIFY(shareReg->checkSharing(glw1->context(), glw1->context()));
+ QVERIFY(shareReg->checkSharing(glw2->context(), glw2->context()));
+ QVERIFY(shareReg->checkSharing(glw1->context(), glw2->context()));
+ QVERIFY(shareReg->checkSharing(glw2->context(), glw1->context()));
+ QVERIFY(!shareReg->checkSharing(glw1->context(), glw3->context()));
+ QVERIFY(!shareReg->checkSharing(glw2->context(), glw3->context()));
+ QVERIFY(!shareReg->checkSharing(glw3->context(), glw1->context()));
+ QVERIFY(!shareReg->checkSharing(glw3->context(), glw2->context()));
+ QVERIFY(shareReg->checkSharing(glw3->context(), glw3->context()));
+ QVERIFY(!shareReg->checkSharing(0, glw2->context()));
+ QVERIFY(!shareReg->checkSharing(glw1->context(), 0));
+ QVERIFY(!shareReg->checkSharing(0, glw3->context()));
+ QVERIFY(!shareReg->checkSharing(glw3->context(), 0));
+ QVERIFY(!shareReg->checkSharing(0, 0));
+
+ // Shared guard should still be the same.
+ QVERIFY(guard.context() == glw1->context());
+ QVERIFY(guard.id() == 3);
+
+ // Delete the first context.
+ delete glw1;
+
+ // Shared guard should now be the second context, with the id the same.
+ QVERIFY(guard.context() == glw2->context());
+ QVERIFY(guard.id() == 3);
+ QVERIFY(guard3.context() == glw3->context());
+ QVERIFY(guard3.id() == 5);
+
+ // Re-check the share list for the second context (should be empty now).
+ list = shareReg->shares(glw2->context());
+ QCOMPARE(list.size(), 0);
+
+ // Clean up.
+ delete glw2;
+ delete glw3;
+
+ // Guards should now be null and the id zero.
+ QVERIFY(guard.context() == 0);
+ QVERIFY(guard.id() == 0);
+ QVERIFY(guard3.context() == 0);
+ QVERIFY(guard3.id() == 0);
+#endif
+}
+
QTEST_MAIN(tst_QGL)
#include "tst_qgl.moc"