summaryrefslogtreecommitdiffstats
path: root/tests/auto
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2017-06-07 14:35:41 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2017-06-08 13:34:54 +0000
commit2ea90c56f2924acc5c620ed7c29a48c72a42efd3 (patch)
treee2a31ace9625ba07903d93c06ef0d0e6fe8ed0dc /tests/auto
parent41ae544c40e0568bd627a992a23b8c8f8f5cc27d (diff)
Start supporting purely offscreen QOpenGLWidget
Due to popular demand. It does have it benefits (especially when it comes to convenience) to allow grabbing QOpenGLWidgets even when they are not part of an actual window and are not actually visible. Does not involve much more than dropping the warnings and bailouts when there is active native window (because the QOpenGLWidget/its parents are still hidden). In addition the device pixel ratio from metric() has to be fixed as well. [ChangeLog][Qt Widgets] QOpenGLWidget is now able to render and return its content via grabFramebuffer(), QWidget::grab() or QWidget::render() even when the widget has not been made visible. Task-number: QTBUG-47185 Task-number: QTBUG-61280 Change-Id: Icc2b0b3ce9778a3eb6409d54744238568abb0f0d Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r--tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp70
1 files changed, 70 insertions, 0 deletions
diff --git a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp
index c7fca550e5..510576f6df 100644
--- a/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp
+++ b/tests/auto/widgets/widgets/qopenglwidget/tst_qopenglwidget.cpp
@@ -61,6 +61,8 @@ private slots:
void showHide();
void nativeWindow();
void stackWidgetOpaqueChildIsVisible();
+ void offscreen();
+ void offscreenThenOnscreen();
};
void tst_QOpenGLWidget::initTestCase()
@@ -572,6 +574,74 @@ void tst_QOpenGLWidget::stackWidgetOpaqueChildIsVisible()
#undef VERIFY_COLOR
}
+void tst_QOpenGLWidget::offscreen()
+{
+ {
+ QScopedPointer<ClearWidget> w(new ClearWidget(0, 800, 600));
+ w->resize(800, 600);
+
+ w->setClearColor(0, 0, 1);
+ QImage image = w->grabFramebuffer();
+
+ QVERIFY(!image.isNull());
+ QCOMPARE(image.width(), w->width());
+ QCOMPARE(image.height(), w->height());
+ QVERIFY(image.pixel(30, 40) == qRgb(0, 0, 255));
+ }
+
+ // QWidget::grab() should eventually end up in grabFramebuffer() as well
+ {
+ QScopedPointer<ClearWidget> w(new ClearWidget(0, 800, 600));
+ w->resize(800, 600);
+
+ w->setClearColor(0, 0, 1);
+ QPixmap pm = w->grab();
+ QImage image = pm.toImage();
+
+ QVERIFY(!image.isNull());
+ QCOMPARE(image.width(), w->width());
+ QCOMPARE(image.height(), w->height());
+ QVERIFY(image.pixel(30, 40) == qRgb(0, 0, 255));
+ }
+
+ // ditto for QWidget::render()
+ {
+ QScopedPointer<ClearWidget> w(new ClearWidget(0, 800, 600));
+ w->resize(800, 600);
+
+ w->setClearColor(0, 0, 1);
+ QImage image(800, 600, QImage::Format_ARGB32);
+ w->render(&image);
+
+ QVERIFY(image.pixel(30, 40) == qRgb(0, 0, 255));
+ }
+}
+
+void tst_QOpenGLWidget::offscreenThenOnscreen()
+{
+ QScopedPointer<ClearWidget> w(new ClearWidget(0, 800, 600));
+ w->resize(800, 600);
+
+ w->setClearColor(0, 0, 1);
+ QImage image = w->grabFramebuffer();
+
+ QVERIFY(!image.isNull());
+ QCOMPARE(image.width(), w->width());
+ QCOMPARE(image.height(), w->height());
+ QVERIFY(image.pixel(30, 40) == qRgb(0, 0, 255));
+
+ // now let's make things more challenging: show. Internally this needs
+ // recreating the context.
+ w->show();
+ QTest::qWaitForWindowExposed(w.data());
+
+ image = w->grabFramebuffer();
+ QVERIFY(!image.isNull());
+ QCOMPARE(image.width(), w->width());
+ QCOMPARE(image.height(), w->height());
+ QVERIFY(image.pixel(30, 40) == qRgb(0, 0, 255));
+}
+
QTEST_MAIN(tst_QOpenGLWidget)
#include "tst_qopenglwidget.moc"