Skip to content

Commit

Permalink
moved duplicated qglwidget calls to wglwidget methods (this prepares …
Browse files Browse the repository at this point in the history
…for adding an alternative implementation using qopenglwindow) and use directconnection where appropriate
  • Loading branch information
m0dB committed Oct 15, 2022
1 parent 9177ed7 commit 31fa633
Show file tree
Hide file tree
Showing 16 changed files with 93 additions and 142 deletions.
9 changes: 7 additions & 2 deletions src/skin/legacy/legacyskinparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1314,8 +1314,13 @@ QWidget* LegacySkinParser::parseSpinny(const QDomElement& node) {
connect(waveformWidgetFactory,
&WaveformWidgetFactory::renderSpinnies,
pSpinny,
&WSpinny::render);
connect(waveformWidgetFactory, &WaveformWidgetFactory::swapSpinnies, pSpinny, &WSpinny::swap);
&WSpinny::render,
Qt::DirectConnection);
connect(waveformWidgetFactory,
&WaveformWidgetFactory::swapSpinnies,
pSpinny,
&WSpinny::swap,
Qt::DirectConnection);
connect(pSpinny,
&WSpinny::trackDropped,
m_pPlayerManager,
Expand Down
25 changes: 7 additions & 18 deletions src/waveform/waveformwidgetfactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,12 @@ bool shouldRenderWaveform(WaveformWidgetAbstract* pWaveformWidget) {

auto* glw = pWaveformWidget->getGLWidget();
if (glw == nullptr) {
// Not a QGLWidget. We can simply use QWidget::isVisible.
// Not a WGLWidget. We can simply use QWidget::isVisible.
auto* qwidget = qobject_cast<QWidget*>(pWaveformWidget->getWidget());
return qwidget != nullptr && qwidget->isVisible();
}

if (glw == nullptr || !glw->isValid() || !glw->isVisible()) {
return false;
}

// Strangely, a widget can have non-zero width/height, be valid and visible,
// yet still not show up on the screen. QWindow::isExposed tells us this.
const QWindow* window = glw->windowHandle();
if (window == nullptr || !window->isExposed()) {
return false;
}

return true;
return glw->shouldRender();
}
} // anonymous namespace

Expand Down Expand Up @@ -370,11 +359,13 @@ void WaveformWidgetFactory::addVuMeter(WVuMeterGL* pVuMeter) {
connect(this,
&WaveformWidgetFactory::renderVuMeters,
pVuMeter,
&WVuMeterGL::render);
&WVuMeterGL::render,
Qt::DirectConnection);
connect(this,
&WaveformWidgetFactory::swapVuMeters,
pVuMeter,
&WVuMeterGL::swap);
&WVuMeterGL::swap,
Qt::DirectConnection);
}

void WaveformWidgetFactory::slotSkinLoaded() {
Expand Down Expand Up @@ -734,9 +725,7 @@ void WaveformWidgetFactory::swap() {
}
WGLWidget* glw = pWaveformWidget->getGLWidget();
if (glw != nullptr) {
if (glw->context() != QGLContext::currentContext()) {
glw->makeCurrent();
}
glw->makeCurrentIfNeeded();
glw->swapBuffers();
}
//qDebug() << "swap x" << m_vsyncThread->elapsed();
Expand Down
9 changes: 2 additions & 7 deletions src/waveform/widgets/glrgbwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
GLRGBWaveformWidget::GLRGBWaveformWidget(const QString& group, QWidget* parent)
: GLWaveformWidgetAbstract(group, parent) {
qDebug() << "Created WGLWidget. Context"
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();
<< "Valid:" << isContextValid()
<< "Sharing:" << isContextSharing();

addRenderer<WaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
Expand All @@ -28,11 +28,6 @@ GLRGBWaveformWidget::GLRGBWaveformWidget(const QString& group, QWidget* parent)
addRenderer<WaveformRenderBeat>();
addRenderer<WaveformRenderMark>();

setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent);

setAutoBufferSwap(false);

m_initSuccess = init();
}

Expand Down
9 changes: 2 additions & 7 deletions src/waveform/widgets/glsimplewaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
GLSimpleWaveformWidget::GLSimpleWaveformWidget(const QString& group, QWidget* parent)
: GLWaveformWidgetAbstract(group, parent) {
qDebug() << "Created WGLWidget. Context"
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();
<< "Valid:" << isContextValid()
<< "Sharing:" << isContextSharing();

addRenderer<WaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
Expand All @@ -31,11 +31,6 @@ GLSimpleWaveformWidget::GLSimpleWaveformWidget(const QString& group, QWidget* pa
addRenderer<WaveformRenderBeat>();
addRenderer<WaveformRenderMark>();

setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent);

setAutoBufferSwap(false);

m_initSuccess = init();
}

Expand Down
18 changes: 6 additions & 12 deletions src/waveform/widgets/glslwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ GLSLWaveformWidget::GLSLWaveformWidget(
GlslType type)
: GLWaveformWidgetAbstract(group, parent) {
qDebug() << "Created WGLWidget. Context"
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();
if (QGLContext::currentContext() != context()) {
makeCurrent();
}
<< "Valid:" << isContextValid()
<< "Sharing:" << isContextSharing();

makeCurrentIfNeeded();

addRenderer<WaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
Expand All @@ -63,11 +62,6 @@ GLSLWaveformWidget::GLSLWaveformWidget(
addRenderer<WaveformRenderBeat>();
addRenderer<WaveformRenderMark>();

setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent);

setAutoBufferSwap(false);

m_initSuccess = init();
}

Expand Down Expand Up @@ -97,13 +91,13 @@ mixxx::Duration GLSLWaveformWidget::render() {
void GLSLWaveformWidget::resize(int width, int height) {
// NOTE: (vrince) this is needed since we allocation buffer on resize
// and the Gl Context should be properly set
makeCurrent();
makeCurrentIfNeeded();
WaveformWidgetAbstract::resize(width, height);
}

void GLSLWaveformWidget::mouseDoubleClickEvent(QMouseEvent *event) {
if (event->button() == Qt::RightButton) {
makeCurrent();
makeCurrentIfNeeded();
#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_2)
if (m_signalRenderer) {
m_signalRenderer->debugClick();
Expand Down
10 changes: 2 additions & 8 deletions src/waveform/widgets/glvsynctestwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
GLVSyncTestWidget::GLVSyncTestWidget(const QString& group, QWidget* parent)
: GLWaveformWidgetAbstract(group, parent) {
qDebug() << "Created WGLWidget. Context"
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();
<< "Valid:" << isContextValid()
<< "Sharing:" << isContextSharing();

addRenderer<WaveformRenderBackground>(); // 172 µs
// addRenderer<WaveformRendererEndOfTrack>(); // 677 µs 1145 µs (active)
Expand All @@ -33,13 +33,7 @@ GLVSyncTestWidget::GLVSyncTestWidget(const QString& group, QWidget* parent)
// addRenderer<WaveformRenderMark>(); // 711 µs
// addRenderer<WaveformRenderBeat>(); // 1183 µs

setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent);

setAutoBufferSwap(false);

m_initSuccess = init();
qDebug() << "GLVSyncTestWidget.isSharing() =" << isSharing();
}

GLVSyncTestWidget::~GLVSyncTestWidget() {
Expand Down
9 changes: 2 additions & 7 deletions src/waveform/widgets/glwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
GLWaveformWidget::GLWaveformWidget(const QString& group, QWidget* parent)
: GLWaveformWidgetAbstract(group, parent) {
qDebug() << "Created WGLWidget. Context"
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();
<< "Valid:" << isContextValid()
<< "Sharing:" << isContextSharing();

addRenderer<WaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
Expand All @@ -33,11 +33,6 @@ GLWaveformWidget::GLWaveformWidget(const QString& group, QWidget* parent)
addRenderer<WaveformRenderBeat>();
addRenderer<WaveformRenderMark>();

setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent);

setAutoBufferSwap(false);

m_initSuccess = init();
}

Expand Down
7 changes: 1 addition & 6 deletions src/waveform/widgets/qthsvwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@

QtHSVWaveformWidget::QtHSVWaveformWidget(const QString& group, QWidget* parent)
: GLWaveformWidgetAbstract(group, parent) {
if (QGLContext::currentContext() != context()) {
makeCurrent();
}
makeCurrentIfNeeded();
addRenderer<WaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
addRenderer<WaveformRendererPreroll>();
Expand All @@ -27,9 +25,6 @@ QtHSVWaveformWidget::QtHSVWaveformWidget(const QString& group, QWidget* parent)
addRenderer<WaveformRenderBeat>();
addRenderer<WaveformRenderMark>();

setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent);

m_initSuccess = init();
}

Expand Down
9 changes: 2 additions & 7 deletions src/waveform/widgets/qtrgbwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
QtRGBWaveformWidget::QtRGBWaveformWidget(const QString& group, QWidget* parent)
: GLWaveformWidgetAbstract(group, parent) {
qDebug() << "Created WGLWidget. Context"
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();
<< "Valid:" << isContextValid()
<< "Sharing:" << isContextSharing();

addRenderer<WaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
Expand All @@ -28,11 +28,6 @@ QtRGBWaveformWidget::QtRGBWaveformWidget(const QString& group, QWidget* parent)
addRenderer<WaveformRenderBeat>();
addRenderer<WaveformRenderMark>();

setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent);

setAutoBufferSwap(false);

m_initSuccess = init();
}

Expand Down
9 changes: 2 additions & 7 deletions src/waveform/widgets/qtsimplewaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ QtSimpleWaveformWidget::QtSimpleWaveformWidget(
QWidget* parent)
: GLWaveformWidgetAbstract(group, parent) {
qDebug() << "Created WGLWidget. Context"
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();
<< "Valid:" << isContextValid()
<< "Sharing:" << isContextSharing();

addRenderer<WaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
Expand All @@ -30,11 +30,6 @@ QtSimpleWaveformWidget::QtSimpleWaveformWidget(
addRenderer<WaveformRenderBeat>();
addRenderer<WaveformRenderMark>();

setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent);

setAutoBufferSwap(false);

m_initSuccess = init();
}

Expand Down
9 changes: 2 additions & 7 deletions src/waveform/widgets/qtvsynctestwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@
QtVSyncTestWidget::QtVSyncTestWidget(const QString& group, QWidget* parent)
: GLWaveformWidgetAbstract(group, parent) {
qDebug() << "Created WGLWidget. Context"
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();
<< "Valid:" << isContextValid()
<< "Sharing:" << isContextSharing();

addRenderer<QtVSyncTestRenderer>();

setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent);

setAutoBufferSwap(false);

m_initSuccess = init();
}

Expand Down
9 changes: 2 additions & 7 deletions src/waveform/widgets/qtwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
QtWaveformWidget::QtWaveformWidget(const QString& group, QWidget* parent)
: GLWaveformWidgetAbstract(group, parent) {
qDebug() << "Created WGLWidget. Context"
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();
<< "Valid:" << isContextValid()
<< "Sharing:" << isContextSharing();

addRenderer<WaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
Expand All @@ -29,11 +29,6 @@ QtWaveformWidget::QtWaveformWidget(const QString& group, QWidget* parent)
addRenderer<WaveformRenderBeat>();
addRenderer<WaveformRenderMark>();

setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent);

setAutoBufferSwap(false);

m_initSuccess = init();
}

Expand Down
15 changes: 15 additions & 0 deletions src/widget/wglwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,19 @@
class WGLWidget : public QGLWidget {
public:
WGLWidget(QWidget* parent);

bool isContextValid() const;
bool isContextSharing() const;

bool shouldRender() const;

void makeCurrentIfNeeded();
};

// Other QGLWidget / QWidget methods called:
// - void swapBuffers() {
// - To avoid xcb crash, in legacyskinparser.cpp
// - void setParent(QWidget* parent) {
// - Used by WSpinny:
// - void installEventFilter(QObject *);
// - connect
28 changes: 28 additions & 0 deletions src/widget/wglwidgetqglwidget.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,34 @@
#include <QWindow>

#include "waveform/sharedglcontext.h"
#include "widget/wglwidget.h"

WGLWidget::WGLWidget(QWidget* parent)
: QGLWidget(parent, SharedGLContext::getWidget()) {
setAttribute(Qt::WA_NoSystemBackground);
setAttribute(Qt::WA_OpaquePaintEvent);
setAutoFillBackground(false);
setAutoBufferSwap(false);
// Not interested in repaint or update calls, as we draw from the vsync thread
setUpdatesEnabled(false);
}

bool WGLWidget::isContextValid() const {
return context()->isValid();
}

bool WGLWidget::isContextSharing() const {
return context()->isSharing();
}

bool WGLWidget::shouldRender() const {
return true;
return isValid() && isVisible() && windowHandle() && windowHandle()->isExposed();
}

void WGLWidget::makeCurrentIfNeeded() {
// TODO m0dB is this really needed? is calling makeCurrent without this 'if' really a problem?
//if (context() != QGLContext::currentContext()) {
makeCurrent();
//}
}
Loading

0 comments on commit 31fa633

Please sign in to comment.