Fix QOpenGLWindow tests when devicePixelRatio != 1
Change-Id: I83d71de8b9d735cd649a6c514e41a9ff23625005 Reviewed-by: Laszlo Agocs <laszlo.agocs@digia.com>
This commit is contained in:
parent
bcda685be9
commit
c231694949
@ -211,8 +211,11 @@ public:
|
||||
context->makeCurrent(q);
|
||||
}
|
||||
|
||||
const int deviceWidth = q->width() * q->devicePixelRatio();
|
||||
const int deviceHeight = q->height() * q->devicePixelRatio();
|
||||
const QSize deviceSize(deviceWidth, deviceHeight);
|
||||
if (updateBehavior > QOpenGLWindow::NoPartialUpdate) {
|
||||
if (!fbo || fbo->size() != q->size() * q->devicePixelRatio()) {
|
||||
if (!fbo || fbo->size() != deviceSize) {
|
||||
QOpenGLFramebufferObjectFormat fboFormat;
|
||||
fboFormat.setAttachment(QOpenGLFramebufferObject::CombinedDepthStencil);
|
||||
if (q->requestedFormat().samples() > 0) {
|
||||
@ -221,15 +224,13 @@ public:
|
||||
else
|
||||
qWarning("QOpenGLWindow: PartialUpdateBlend does not support multisampling");
|
||||
}
|
||||
fbo.reset(new QOpenGLFramebufferObject(q->size() * q->devicePixelRatio(), fboFormat));
|
||||
fbo.reset(new QOpenGLFramebufferObject(deviceSize, fboFormat));
|
||||
markWindowAsDirty();
|
||||
}
|
||||
} else {
|
||||
markWindowAsDirty();
|
||||
}
|
||||
|
||||
const int deviceWidth = q->width() * q->devicePixelRatio();
|
||||
const int deviceHeight = q->height() * q->devicePixelRatio();
|
||||
paintDevice->setSize(QSize(deviceWidth, deviceHeight));
|
||||
paintDevice->setDevicePixelRatio(q->devicePixelRatio());
|
||||
context->functions()->glViewport(0, 0, deviceWidth, deviceHeight);
|
||||
@ -252,11 +253,13 @@ public:
|
||||
context->functions()->glBindFramebuffer(GL_FRAMEBUFFER, context->defaultFramebufferObject());
|
||||
|
||||
if (updateBehavior == QOpenGLWindow::PartialUpdateBlit && hasFboBlit) {
|
||||
const int deviceWidth = q->width() * q->devicePixelRatio();
|
||||
const int deviceHeight = q->height() * q->devicePixelRatio();
|
||||
QOpenGLExtensions extensions(context.data());
|
||||
extensions.glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo->handle());
|
||||
extensions.glBindFramebuffer(GL_DRAW_FRAMEBUFFER, context->defaultFramebufferObject());
|
||||
extensions.glBlitFramebuffer(0, 0, q->width(), q->height(),
|
||||
0, 0, q->width(), q->height(),
|
||||
extensions.glBlitFramebuffer(0, 0, deviceWidth, deviceHeight,
|
||||
0, 0, deviceWidth, deviceHeight,
|
||||
GL_COLOR_BUFFER_BIT, GL_NEAREST);
|
||||
} else if (updateBehavior > QOpenGLWindow::NoPartialUpdate) {
|
||||
if (updateBehavior == QOpenGLWindow::PartialUpdateBlend) {
|
||||
@ -591,7 +594,7 @@ int QOpenGLWindow::metric(PaintDeviceMetric metric) const
|
||||
break;
|
||||
case PdmDevicePixelRatio:
|
||||
if (d->paintDevice)
|
||||
return d->paintDevice->devicePixelRatio();
|
||||
return devicePixelRatio();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
|
@ -116,8 +116,8 @@ void tst_QOpenGLWindow::basic()
|
||||
QVERIFY(w.paintCount >= 1);
|
||||
|
||||
// Check that something has been drawn;
|
||||
QCOMPARE(w.img.size(), w.size());
|
||||
QVERIFY(w.img.pixel(5, 5) == qRgb(255, 0, 0));
|
||||
QCOMPARE(w.img.size(), w.size() * w.devicePixelRatio());
|
||||
QVERIFY(w.img.pixel(QPoint(5, 5) * w.devicePixelRatio()) == qRgb(255, 0, 0));
|
||||
|
||||
// Check that the viewport was properly set.
|
||||
w.makeCurrent();
|
||||
@ -168,9 +168,9 @@ void tst_QOpenGLWindow::painter()
|
||||
w.show();
|
||||
QTest::qWaitForWindowExposed(&w);
|
||||
|
||||
QCOMPARE(w.img.size(), w.size());
|
||||
QVERIFY(w.img.pixel(5, 5) == qRgb(0, 0, 255));
|
||||
QVERIFY(w.img.pixel(200, 5) == qRgb(255, 0, 0));
|
||||
QCOMPARE(w.img.size(), w.size() * w.devicePixelRatio());
|
||||
QVERIFY(w.img.pixel(QPoint(5, 5) * w.devicePixelRatio()) == qRgb(0, 0, 255));
|
||||
QVERIFY(w.img.pixel(QPoint(200, 5) * w.devicePixelRatio()) == qRgb(255, 0, 0));
|
||||
}
|
||||
|
||||
class PartialPainterWindow : public QOpenGLWindow
|
||||
@ -222,10 +222,10 @@ void tst_QOpenGLWindow::partial()
|
||||
// Now since the painting went to an extra framebuffer, all the rects should
|
||||
// be present since everything is preserved between the frames.
|
||||
QImage img = w.grabFramebuffer();
|
||||
QCOMPARE(img.size(), w.size());
|
||||
QCOMPARE(img.pixel(5, 5), qRgb(0, 0, 255));
|
||||
QCOMPARE(img.pixel(15, 5), qRgb(0, 255, 0));
|
||||
QCOMPARE(img.pixel(25, 5), qRgb(0, 0, 255));
|
||||
QCOMPARE(img.size(), w.size() * w.devicePixelRatio());
|
||||
QCOMPARE(img.pixel(QPoint(5, 5) * w.devicePixelRatio()), qRgb(0, 0, 255));
|
||||
QCOMPARE(img.pixel(QPoint(15, 5) * w.devicePixelRatio()), qRgb(0, 255, 0));
|
||||
QCOMPARE(img.pixel(QPoint(25, 5) * w.devicePixelRatio()), qRgb(0, 0, 255));
|
||||
}
|
||||
|
||||
class PaintUnderOverWindow : public QOpenGLWindow
|
||||
|
Loading…
Reference in New Issue
Block a user