Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glwaveformrenderbackground #11523

Merged
merged 3 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -949,6 +949,7 @@ add_library(mixxx-lib STATIC EXCLUDE_FROM_ALL
src/waveform/guitick.cpp
src/waveform/renderers/glslwaveformrenderersignal.cpp
src/waveform/renderers/glvsynctestrenderer.cpp
src/waveform/renderers/glwaveformrenderbackground.cpp
src/waveform/renderers/glwaveformrendererfilteredsignal.cpp
src/waveform/renderers/glwaveformrendererrgb.cpp
src/waveform/renderers/glwaveformrenderersimplesignal.cpp
Expand Down
24 changes: 24 additions & 0 deletions src/waveform/renderers/glwaveformrenderbackground.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "waveform/renderers/glwaveformrenderbackground.h"

GLWaveformRenderBackground::GLWaveformRenderBackground(
WaveformWidgetRenderer* waveformWidgetRenderer)
: WaveformRenderBackground(waveformWidgetRenderer) {
}

#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_2)
void GLWaveformRenderBackground::draw(QPainter* painter, QPaintEvent* /*event*/) {
maybeInitializeGL();

painter->beginNativePainting();
glClearColor(static_cast<float>(m_backgroundColor.redF()),
static_cast<float>(m_backgroundColor.greenF()),
static_cast<float>(m_backgroundColor.blueF()),
1.f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
painter->endNativePainting();

if (hasImage()) {
drawImage(painter);
}
}
#endif
24 changes: 24 additions & 0 deletions src/waveform/renderers/glwaveformrenderbackground.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#pragma once

#include "waveform/renderers/waveformrenderbackground.h"
#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_2)
#include "waveform/renderers/glwaveformrenderer.h"
#endif

class GLWaveformRenderBackground : public WaveformRenderBackground
#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_2)
,
public GLWaveformRenderer
#endif
{
public:
explicit GLWaveformRenderBackground(
WaveformWidgetRenderer* waveformWidgetRenderer);

#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_2)
virtual void draw(QPainter* painter, QPaintEvent* event);
#endif

private:
DISALLOW_COPY_AND_ASSIGN(GLWaveformRenderBackground);
};
28 changes: 19 additions & 9 deletions src/waveform/renderers/waveformrenderbackground.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,15 @@ void WaveformRenderBackground::setup(const QDomNode& node,
setDirty(true);
}

void WaveformRenderBackground::draw(QPainter* painter,
QPaintEvent* /*event*/) {
bool WaveformRenderBackground::hasImage() {
if (isDirty()) {
generateImage();
}

// If there is no background image, just fill the painter with the
// background color.
if (m_backgroundImage.isNull()) {
painter->fillRect(0, 0, m_waveformRenderer->getWidth(),
m_waveformRenderer->getHeight(), m_backgroundColor);
return;
}
return !m_backgroundImage.isNull();
}

void WaveformRenderBackground::drawImage(QPainter* painter) {
// since we use opaque widget we need to draw the background !
painter->drawImage(QPoint(0, 0), m_backgroundImage);

Expand All @@ -46,6 +41,21 @@ void WaveformRenderBackground::draw(QPainter* painter,
//painter->drawPixmap(QPoint(0, 0), m_backgroundPixmap);
}

void WaveformRenderBackground::draw(QPainter* painter,
QPaintEvent* /*event*/) {
if (hasImage()) {
drawImage(painter);
return;
}
// If there is no background image, just fill the painter with the
// background color.
painter->fillRect(0,
0,
m_waveformRenderer->getWidth(),
m_waveformRenderer->getHeight(),
m_backgroundColor);
}

void WaveformRenderBackground::generateImage() {
m_backgroundImage = QImage();
if (!m_backgroundPixmapPath.isEmpty()) {
Expand Down
7 changes: 6 additions & 1 deletion src/waveform/renderers/waveformrenderbackground.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ class WaveformRenderBackground : public WaveformRendererAbstract {
virtual void setup(const QDomNode& node, const SkinContext& context);
virtual void draw(QPainter* painter, QPaintEvent* event);

protected:
bool hasImage();
void drawImage(QPainter* painter);

QColor m_backgroundColor;

private:
void generateImage();

QString m_backgroundPixmapPath;
QColor m_backgroundColor;
QImage m_backgroundImage;

DISALLOW_COPY_AND_ASSIGN(WaveformRenderBackground);
Expand Down
4 changes: 2 additions & 2 deletions src/waveform/widgets/glrgbwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

#include "moc_glrgbwaveformwidget.cpp"
#include "util/performancetimer.h"
#include "waveform/renderers/glwaveformrenderbackground.h"
#include "waveform/renderers/glwaveformrendererrgb.h"
#include "waveform/renderers/waveformrenderbackground.h"
#include "waveform/renderers/waveformrenderbeat.h"
#include "waveform/renderers/waveformrendererendoftrack.h"
#include "waveform/renderers/waveformrendererpreroll.h"
Expand All @@ -18,7 +18,7 @@ GLRGBWaveformWidget::GLRGBWaveformWidget(const QString& group, QWidget* parent)
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();

addRenderer<WaveformRenderBackground>();
addRenderer<GLWaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
addRenderer<WaveformRendererPreroll>();
addRenderer<WaveformRenderMarkRange>();
Expand Down
4 changes: 2 additions & 2 deletions src/waveform/widgets/glsimplewaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#include "moc_glsimplewaveformwidget.cpp"
#include "util/performancetimer.h"
#include "waveform/renderers/glwaveformrenderbackground.h"
#include "waveform/renderers/glwaveformrenderersimplesignal.h"
#include "waveform/renderers/waveformrenderbackground.h"
#include "waveform/renderers/waveformrenderbeat.h"
#include "waveform/renderers/waveformrendererendoftrack.h"
#include "waveform/renderers/waveformrendererpreroll.h"
Expand All @@ -21,7 +21,7 @@ GLSimpleWaveformWidget::GLSimpleWaveformWidget(const QString& group, QWidget* pa
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();

addRenderer<WaveformRenderBackground>();
addRenderer<GLWaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
addRenderer<WaveformRendererPreroll>();
addRenderer<WaveformRenderMarkRange>();
Expand Down
4 changes: 2 additions & 2 deletions src/waveform/widgets/glslwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#include "moc_glslwaveformwidget.cpp"
#include "util/performancetimer.h"
#include "waveform/renderers/glslwaveformrenderersignal.h"
#include "waveform/renderers/waveformrenderbackground.h"
#include "waveform/renderers/glwaveformrenderbackground.h"
#include "waveform/renderers/waveformrenderbeat.h"
#include "waveform/renderers/waveformrendererendoftrack.h"
#include "waveform/renderers/waveformrendererpreroll.h"
Expand Down Expand Up @@ -39,7 +39,7 @@ GLSLWaveformWidget::GLSLWaveformWidget(
makeCurrent();
}

addRenderer<WaveformRenderBackground>();
addRenderer<GLWaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
addRenderer<WaveformRendererPreroll>();
addRenderer<WaveformRenderMarkRange>();
Expand Down
10 changes: 5 additions & 5 deletions src/waveform/widgets/glvsynctestwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
#include "moc_glvsynctestwidget.cpp"
#include "util/performancetimer.h"
#include "waveform/renderers/glvsynctestrenderer.h"
#include "waveform/renderers/glwaveformrenderbackground.h"
#include "waveform/renderers/glwaveformrenderersimplesignal.h"
#include "waveform/renderers/waveformrenderbackground.h"
#include "waveform/renderers/waveformrenderbeat.h"
#include "waveform/renderers/waveformrendererendoftrack.h"
#include "waveform/renderers/waveformrendererpreroll.h"
Expand All @@ -21,10 +21,10 @@ GLVSyncTestWidget::GLVSyncTestWidget(const QString& group, QWidget* parent)
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();

addRenderer<WaveformRenderBackground>(); // 172 µs
// addRenderer<WaveformRendererEndOfTrack>(); // 677 µs 1145 µs (active)
// addRenderer<WaveformRendererPreroll>(); // 652 µs 2034 µs (active)
// addRenderer<WaveformRenderMarkRange>(); // 793 µs
addRenderer<GLWaveformRenderBackground>(); // 172 µs
// addRenderer<WaveformRendererEndOfTrack>(); // 677 µs 1145 µs (active)
// addRenderer<WaveformRendererPreroll>(); // 652 µs 2034 µs (active)
// addRenderer<WaveformRenderMarkRange>(); // 793 µs

#if !defined(QT_NO_OPENGL) && !defined(QT_OPENGL_ES_2)
addRenderer<GLVSyncTestRenderer>(); // 841 µs // 2271 µs
Expand Down
4 changes: 2 additions & 2 deletions src/waveform/widgets/glwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

#include "moc_glwaveformwidget.cpp"
#include "util/performancetimer.h"
#include "waveform/renderers/glwaveformrenderbackground.h"
#include "waveform/renderers/glwaveformrendererfilteredsignal.h"
#include "waveform/renderers/qtwaveformrendererfilteredsignal.h"
#include "waveform/renderers/waveformrenderbackground.h"
#include "waveform/renderers/waveformrenderbeat.h"
#include "waveform/renderers/waveformrendererendoftrack.h"
#include "waveform/renderers/waveformrendererpreroll.h"
Expand All @@ -23,7 +23,7 @@ GLWaveformWidget::GLWaveformWidget(const QString& group, QWidget* parent)
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();

addRenderer<WaveformRenderBackground>();
addRenderer<GLWaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
addRenderer<WaveformRendererPreroll>();
addRenderer<WaveformRenderMarkRange>();
Expand Down
4 changes: 2 additions & 2 deletions src/waveform/widgets/qthsvwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <QtDebug>

#include "moc_qthsvwaveformwidget.cpp"
#include "waveform/renderers/waveformrenderbackground.h"
#include "waveform/renderers/glwaveformrenderbackground.h"
#include "waveform/renderers/waveformrenderbeat.h"
#include "waveform/renderers/waveformrendererendoftrack.h"
#include "waveform/renderers/waveformrendererhsv.h"
Expand All @@ -20,7 +20,7 @@ QtHSVWaveformWidget::QtHSVWaveformWidget(const QString& group, QWidget* parent)
if (QGLContext::currentContext() != context()) {
makeCurrent();
}
addRenderer<WaveformRenderBackground>();
addRenderer<GLWaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
addRenderer<WaveformRendererPreroll>();
addRenderer<WaveformRenderMarkRange>();
Expand Down
4 changes: 2 additions & 2 deletions src/waveform/widgets/qtrgbwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include <QtDebug>

#include "moc_qtrgbwaveformwidget.cpp"
#include "waveform/renderers/waveformrenderbackground.h"
#include "waveform/renderers/glwaveformrenderbackground.h"
#include "waveform/renderers/waveformrenderbeat.h"
#include "waveform/renderers/waveformrendererendoftrack.h"
#include "waveform/renderers/waveformrendererpreroll.h"
Expand All @@ -22,7 +22,7 @@ QtRGBWaveformWidget::QtRGBWaveformWidget(const QString& group, QWidget* parent)
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();

addRenderer<WaveformRenderBackground>();
addRenderer<GLWaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
addRenderer<WaveformRendererPreroll>();
addRenderer<WaveformRenderMarkRange>();
Expand Down
4 changes: 2 additions & 2 deletions src/waveform/widgets/qtsimplewaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

#include "moc_qtsimplewaveformwidget.cpp"
#include "util/performancetimer.h"
#include "waveform/renderers/glwaveformrenderbackground.h"
#include "waveform/renderers/qtwaveformrenderersimplesignal.h"
#include "waveform/renderers/waveformrenderbackground.h"
#include "waveform/renderers/waveformrenderbeat.h"
#include "waveform/renderers/waveformrendererendoftrack.h"
#include "waveform/renderers/waveformrendererpreroll.h"
Expand All @@ -24,7 +24,7 @@ QtSimpleWaveformWidget::QtSimpleWaveformWidget(
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();

addRenderer<WaveformRenderBackground>();
addRenderer<GLWaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
addRenderer<WaveformRendererPreroll>();
addRenderer<WaveformRenderMarkRange>();
Expand Down
2 changes: 1 addition & 1 deletion src/waveform/widgets/qtvsynctestwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "moc_qtvsynctestwidget.cpp"
#include "util/performancetimer.h"
#include "waveform/renderers/glwaveformrenderbackground.h"
#include "waveform/renderers/qtvsynctestrenderer.h"
#include "waveform/renderers/waveformrenderbackground.h"
#include "waveform/renderers/waveformrenderbeat.h"
#include "waveform/renderers/waveformrendererendoftrack.h"
#include "waveform/renderers/waveformrendererpreroll.h"
Expand Down
4 changes: 2 additions & 2 deletions src/waveform/widgets/qtwaveformwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

#include "moc_qtwaveformwidget.cpp"
#include "util/performancetimer.h"
#include "waveform/renderers/glwaveformrenderbackground.h"
#include "waveform/renderers/qtwaveformrendererfilteredsignal.h"
#include "waveform/renderers/waveformrenderbackground.h"
#include "waveform/renderers/waveformrenderbeat.h"
#include "waveform/renderers/waveformrendererendoftrack.h"
#include "waveform/renderers/waveformrendererpreroll.h"
Expand All @@ -23,7 +23,7 @@ QtWaveformWidget::QtWaveformWidget(const QString& group, QWidget* parent)
<< "Valid:" << context()->isValid()
<< "Sharing:" << context()->isSharing();

addRenderer<WaveformRenderBackground>();
addRenderer<GLWaveformRenderBackground>();
addRenderer<WaveformRendererEndOfTrack>();
addRenderer<WaveformRendererPreroll>();
addRenderer<WaveformRenderMarkRange>();
Expand Down