Skip to content

Commit

Permalink
Avoid missing paints when resizing GV with QOpenGLWidget viewport
Browse files Browse the repository at this point in the history
There is nothing guaranteeing there will be a paint request after
resizeViewportFramebuffer() is called. However we must not be left
with a framebuffer with uninitialized content. So trigger an update.

Include also a half-hearted autotest. QOpenGLWidget (or QGLWidget)
viewports have not been autotested at all. Try to verify that it
is functional at least, even if we cannot check the actual output.

Change-Id: I34d78fe32e94c39dad919216b5a4f4bb2aea3cc2
Task-number: QTBUG-52419
Reviewed-by: Friedemann Kleint <[email protected]>
Reviewed-by: Paul Olav Tvete <[email protected]>
  • Loading branch information
alpqr committed May 24, 2016
1 parent c96ddd9 commit 61521b6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/widgets/kernel/qopenglwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,8 +904,10 @@ void QOpenGLWidgetPrivate::resizeViewportFramebuffer()
if (!initialized)
return;

if (!fbo || q->size() * q->devicePixelRatioF() != fbo->size())
if (!fbo || q->size() * q->devicePixelRatioF() != fbo->size()) {
recreateFbo();
q->update();
}
}

/*!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
#include <QtWidgets/QStyle>
#include <QtWidgets/QPushButton>
#include <QtWidgets/QDesktopWidget>
#ifndef QT_NO_OPENGL
#include <QtWidgets/QOpenGLWidget>
#endif
#include <private/qgraphicsscene_p.h>
#include <private/qgraphicsview_p.h>
#include "../../../shared/platforminputcontext.h"
Expand Down Expand Up @@ -161,6 +164,9 @@ private slots:
void sceneRect_growing();
void setSceneRect();
void viewport();
#ifndef QT_NO_OPENGL
void openGLViewport();
#endif
void dragMode_scrollHand();
void dragMode_rubberBand();
void rubberBandSelectionMode();
Expand Down Expand Up @@ -675,6 +681,45 @@ void tst_QGraphicsView::viewport()
QTest::qWait(25);
}

#ifndef QT_NO_OPENGL
void tst_QGraphicsView::openGLViewport()
{
QGraphicsScene scene;
scene.setBackgroundBrush(Qt::white);
scene.addText("GraphicsView");
scene.addEllipse(QRectF(400, 50, 50, 50));
scene.addEllipse(QRectF(-100, -400, 50, 50));
scene.addEllipse(QRectF(50, -100, 50, 50));
scene.addEllipse(QRectF(-100, 50, 50, 50));

QGraphicsView view(&scene);
view.setSceneRect(-400, -400, 800, 800);
view.resize(400, 400);

QOpenGLWidget *glw = new QOpenGLWidget;
QSignalSpy spy1(glw, SIGNAL(resized()));
QSignalSpy spy2(glw, SIGNAL(frameSwapped()));

view.setViewport(glw);

view.show();
QTest::qWaitForWindowExposed(&view);
QTRY_VERIFY(spy1.count() > 0);
QTRY_VERIFY(spy2.count() >= spy1.count());
spy1.clear();
spy2.clear();

// Now test for resize (QTBUG-52419). This is special when the viewport is
// a QOpenGLWidget since the underlying FBO must also be maintained.
view.resize(300, 300);
QTRY_VERIFY(spy1.count() > 0);
QTRY_VERIFY(spy2.count() >= spy1.count());
// There is no sane way to check if the framebuffer contents got updated
// (grabFramebuffer is no good for the viewport case as that does not go
// through paintGL). So skip the actual verification.
}
#endif

void tst_QGraphicsView::dragMode_scrollHand()
{
for (int j = 0; j < 2; ++j) {
Expand Down

0 comments on commit 61521b6

Please sign in to comment.