summaryrefslogtreecommitdiffstats
path: root/tests/auto/qgl
diff options
context:
space:
mode:
authorOlivier Goffart <olivier.goffart@nokia.com>2010-11-12 14:33:33 (GMT)
committerOlivier Goffart <olivier.goffart@nokia.com>2010-11-12 14:33:33 (GMT)
commit437e83e7707516129f68ee26aca5349845b7cc7b (patch)
tree0d4c8721f21acc5398e4eabff88a902cb23d0521 /tests/auto/qgl
parent7b3880475d02bd3db630387bccccc7e1ef9d4e9a (diff)
parente61071a2a170eaeb524778e9e903100323b88bbe (diff)
downloadQt-437e83e7707516129f68ee26aca5349845b7cc7b.zip
Qt-437e83e7707516129f68ee26aca5349845b7cc7b.tar.gz
Qt-437e83e7707516129f68ee26aca5349845b7cc7b.tar.bz2
Merge remote branch 'origin/4.7' into qt-master-from-4.7
Conflicts: configure doc/src/snippets/code/doc_src_qmake-manual.qdoc mkspecs/features/symbian/application_icon.prf mkspecs/features/symbian/default_post.prf mkspecs/features/symbian/symbian_building.prf qmake/generators/symbian/initprojectdeploy_symbian.cpp src/multimedia/audio/audio.pri src/network/access/qnetworkaccessmanager.cpp src/opengl/gl2paintengineex/qpaintengineex_opengl2.cpp src/opengl/qgl_p.h src/plugins/bearer/corewlan/qcorewlanengine.mm src/plugins/phonon/mmf/mmf.pro tests/auto/qscriptvalue/tst_qscriptvalue.cpp tests/auto/qscriptvalue/tst_qscriptvalue.h tools/qdoc3/doc/qdoc-manual.qdocconf
Diffstat (limited to 'tests/auto/qgl')
-rw-r--r--tests/auto/qgl/tst_qgl.cpp122
1 files changed, 122 insertions, 0 deletions
diff --git a/tests/auto/qgl/tst_qgl.cpp b/tests/auto/qgl/tst_qgl.cpp
index dfcfb47..7f9ee04 100644
--- a/tests/auto/qgl/tst_qgl.cpp
+++ b/tests/auto/qgl/tst_qgl.cpp
@@ -96,6 +96,7 @@ private slots:
void shareRegister();
void qglContextDefaultBindTexture();
void textureCleanup();
+ void threadImages();
};
tst_QGL::tst_QGL()
@@ -2245,6 +2246,127 @@ void tst_QGL::textureCleanup()
#endif
}
+namespace ThreadImages {
+
+class Producer : public QObject
+{
+ Q_OBJECT
+public:
+ Producer()
+ {
+ startTimer(20);
+
+ QThread *thread = new QThread;
+ thread->start();
+
+ connect(this, SIGNAL(destroyed()), thread, SLOT(quit()));
+
+ moveToThread(thread);
+ connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
+ }
+
+signals:
+ void imageReady(const QImage &image);
+
+protected:
+ void timerEvent(QTimerEvent *)
+ {
+ QImage image(256, 256, QImage::Format_RGB32);
+ QLinearGradient g(0, 0, 0, 256);
+ g.setColorAt(0, QColor(255, 180, 180));
+ g.setColorAt(1, Qt::white);
+ g.setSpread(QGradient::ReflectSpread);
+
+ QBrush brush(g);
+ brush.setTransform(QTransform::fromTranslate(0, delta));
+ delta += 10;
+
+ QPainter p(&image);
+ p.fillRect(image.rect(), brush);
+
+ if (images.size() > 10)
+ images.removeFirst();
+
+ images.append(image);
+
+ emit imageReady(image);
+ }
+
+private:
+ QList<QImage> images;
+ int delta;
+};
+
+
+class DisplayWidget : public QGLWidget
+{
+ Q_OBJECT
+public:
+ DisplayWidget(QWidget *parent) : QGLWidget(parent) {}
+ void paintEvent(QPaintEvent *)
+ {
+ QPainter p(this);
+ p.drawImage(rect(), m_image);
+ }
+
+public slots:
+ void setImage(const QImage &image)
+ {
+ m_image = image;
+ update();
+ }
+
+private:
+ QImage m_image;
+};
+
+class Widget : public QWidget
+{
+ Q_OBJECT
+public:
+ Widget()
+ : iterations(0)
+ , display(0)
+ , producer(new Producer)
+ {
+ startTimer(400);
+ connect(this, SIGNAL(destroyed()), producer, SLOT(deleteLater()));
+ }
+
+ int iterations;
+
+protected:
+ void timerEvent(QTimerEvent *)
+ {
+ ++iterations;
+
+ delete display;
+ display = new DisplayWidget(this);
+ connect(producer, SIGNAL(imageReady(const QImage &)), display, SLOT(setImage(const QImage &)));
+
+ display->setGeometry(rect());
+ display->show();
+ }
+
+private:
+ DisplayWidget *display;
+ Producer *producer;
+};
+
+}
+
+void tst_QGL::threadImages()
+{
+ ThreadImages::Widget *widget = new ThreadImages::Widget;
+ widget->show();
+
+ while (widget->iterations <= 5) {
+ qApp->processEvents();
+ }
+
+ delete widget;
+}
+
class tst_QGLDummy : public QObject
{
Q_OBJECT