Skip to content

Commit

Permalink
correct painting on QtAV::QOpenGLWidget
Browse files Browse the repository at this point in the history
painter.beigin(pd->redirected(&offset))
  • Loading branch information
wang-bin committed Jan 12, 2015
1 parent 8f2514a commit 896475d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
31 changes: 28 additions & 3 deletions widgets/QOpenGLWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,23 @@

namespace QtAV {

// TODO: is QOpenGLWidgetPaintDevice required?
class QOpenGLWidgetPaintDevice : public QOpenGLPaintDevice
{
public:
QOpenGLWidgetPaintDevice(QOpenGLWidget *widget)
: QOpenGLPaintDevice()
, w(widget)
{ }
void ensureActiveTarget() Q_DECL_OVERRIDE {
if (QOpenGLContext::currentContext() != w->context()) {
w->makeCurrent();
}
}
private:
QOpenGLWidget *w;
};

QOpenGLWidget::QOpenGLWidget(QWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f)
, m_initialized(false)
Expand Down Expand Up @@ -85,6 +102,13 @@ QOpenGLContext *QOpenGLWidget::context() const
return m_context;
}

QPaintDevice* QOpenGLWidget::redirected(QPoint *offset) const
{
Q_UNUSED(offset);
// TODO: check backing store like Qt does
return m_paintDevice;
}

void QOpenGLWidget::initializeGL()
{
}
Expand Down Expand Up @@ -149,7 +173,7 @@ void QOpenGLWidget::initialize()
qWarning("QOpenGLWidget: Failed to make context current");
return;
}
m_paintDevice = new QOpenGLPaintDevice();
m_paintDevice = new QOpenGLWidgetPaintDevice(this);
m_paintDevice->setSize(size() * devicePixelRatio());
m_paintDevice->setDevicePixelRatio(devicePixelRatio());
m_initialized = true;
Expand All @@ -161,11 +185,12 @@ void QOpenGLWidget::render()
if (m_fakeHidden || !m_initialized)
return;
// QOpenGLContext::swapBuffers() called with non-exposed window, behavior is undefined
if (!windowHandle() || !windowHandle()->isExposed())
QWindow *win = windowHandle();
if (!win || !win->isExposed())
return;
makeCurrent();
invokeUserPaint();
m_context->swapBuffers(windowHandle());
m_context->swapBuffers(win);
}

void QOpenGLWidget::invokeUserPaint()
Expand Down
1 change: 1 addition & 0 deletions widgets/QtAVWidgets/QOpenGLWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class Q_AVWIDGETS_EXPORT QOpenGLWidget : public QWidget
void doneCurrent();
QOpenGLContext *context() const;
protected:
QPaintDevice* redirected(QPoint *offset) const Q_DECL_OVERRIDE;
virtual void initializeGL();
virtual void resizeGL(int w, int h);
virtual void paintGL();
Expand Down

0 comments on commit 896475d

Please sign in to comment.