mirror of
https://github.com/f4exb/sdrangel.git
synced 2025-09-04 14:17:50 -04:00
GUI: TVScreen: cleanup and revised mutex handling
This commit is contained in:
parent
d89ae03b2b
commit
461b31495a
@ -18,32 +18,36 @@
|
|||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
// along with this program. If not, see <http://www.gnu.org/licenses/>. //
|
||||||
///////////////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QMouseEvent>
|
#include <QMouseEvent>
|
||||||
#include <QOpenGLContext>
|
#include <QOpenGLContext>
|
||||||
#include <QOpenGLFunctions>
|
#include <QOpenGLFunctions>
|
||||||
#include <QSurface>
|
#include <QSurface>
|
||||||
|
#include <QDebug>
|
||||||
|
#include <QMutexLocker>
|
||||||
|
|
||||||
#include "tvscreen.h"
|
#include "tvscreen.h"
|
||||||
|
|
||||||
#include <algorithm>
|
|
||||||
#include <QDebug>
|
|
||||||
|
|
||||||
// Note: When this object is created, QWidget* is converted to bool
|
// Note: When this object is created, QWidget* is converted to bool
|
||||||
TVScreen::TVScreen(bool blnColor, QWidget* parent) :
|
TVScreen::TVScreen(bool color, QWidget* parent) :
|
||||||
QGLWidget(parent), m_objMutex(QMutex::NonRecursive), m_objGLShaderArray(blnColor)
|
QGLWidget(parent),
|
||||||
|
m_mutex(QMutex::Recursive),
|
||||||
|
m_glShaderArray(color)
|
||||||
{
|
{
|
||||||
setAttribute(Qt::WA_OpaquePaintEvent);
|
setAttribute(Qt::WA_OpaquePaintEvent);
|
||||||
connect(&m_objTimer, SIGNAL(timeout()), this, SLOT(tick()));
|
connect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
|
||||||
m_objTimer.start(40); // capped at 25 FPS
|
m_timer.start(40); // capped at 25 FPS
|
||||||
|
|
||||||
m_chrLastData = nullptr;
|
m_lastData = nullptr;
|
||||||
m_blnConfigChanged = false;
|
m_dataChanged = false;
|
||||||
m_blnDataChanged = false;
|
m_glContextInitialized = false;
|
||||||
m_blnGLContextInitialized = false;
|
|
||||||
|
|
||||||
//Par défaut
|
//Par défaut
|
||||||
m_intAskedCols = TV_COLS;
|
m_askedCols = TV_COLS;
|
||||||
m_intAskedRows = TV_ROWS;
|
m_askedRows = TV_ROWS;
|
||||||
m_cols = TV_COLS;
|
m_cols = TV_COLS;
|
||||||
m_rows = TV_ROWS;
|
m_rows = TV_ROWS;
|
||||||
}
|
}
|
||||||
@ -52,66 +56,66 @@ TVScreen::~TVScreen()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void TVScreen::setColor(bool blnColor)
|
void TVScreen::setColor(bool color)
|
||||||
{
|
{
|
||||||
m_objGLShaderArray.setColor(blnColor);
|
m_glShaderArray.setColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRgb* TVScreen::getRowBuffer(int intRow)
|
QRgb* TVScreen::getRowBuffer(int row)
|
||||||
{
|
{
|
||||||
if (!m_blnGLContextInitialized)
|
if (!m_glContextInitialized) {
|
||||||
{
|
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_objGLShaderArray.GetRowBuffer(intRow);
|
return m_glShaderArray.GetRowBuffer(row);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TVScreen::renderImage(unsigned char * objData)
|
void TVScreen::renderImage(unsigned char * data)
|
||||||
{
|
{
|
||||||
m_chrLastData = objData;
|
m_lastData = data;
|
||||||
m_blnDataChanged = true;
|
m_dataChanged = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TVScreen::resetImage()
|
void TVScreen::resetImage()
|
||||||
{
|
{
|
||||||
m_objGLShaderArray.ResetPixels();
|
m_glShaderArray.ResetPixels();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TVScreen::resetImage(int alpha)
|
void TVScreen::resetImage(int alpha)
|
||||||
{
|
{
|
||||||
m_objGLShaderArray.ResetPixels(alpha);
|
m_glShaderArray.ResetPixels(alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TVScreen::resizeTVScreen(int intCols, int intRows)
|
void TVScreen::resizeTVScreen(int cols, int intRows)
|
||||||
{
|
{
|
||||||
qDebug("TVScreen::resizeTVScreen: cols: %d, rows: %d", intCols, intRows);
|
qDebug("TVScreen::resizeTVScreen: cols: %d, rows: %d", cols, intRows);
|
||||||
m_intAskedCols = intCols;
|
QMutexLocker mlock(&m_mutex);
|
||||||
m_intAskedRows = intRows;
|
m_askedCols = cols;
|
||||||
m_cols = intCols;
|
m_askedRows = intRows;
|
||||||
|
m_cols = cols;
|
||||||
m_rows = intRows;
|
m_rows = intRows;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TVScreen::getSize(int& intCols, int& intRows) const
|
void TVScreen::getSize(int& cols, int& intRows) const
|
||||||
{
|
{
|
||||||
intCols = m_cols;
|
cols = m_cols;
|
||||||
intRows = m_rows;
|
intRows = m_rows;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TVScreen::initializeGL()
|
void TVScreen::initializeGL()
|
||||||
{
|
{
|
||||||
m_objMutex.lock();
|
QMutexLocker mlock(&m_mutex);
|
||||||
|
|
||||||
QOpenGLContext *objGlCurrentContext = QOpenGLContext::currentContext();
|
QOpenGLContext *glCurrentContext = QOpenGLContext::currentContext();
|
||||||
|
|
||||||
if (objGlCurrentContext)
|
if (glCurrentContext)
|
||||||
{
|
{
|
||||||
if (QOpenGLContext::currentContext()->isValid())
|
if (QOpenGLContext::currentContext()->isValid())
|
||||||
{
|
{
|
||||||
qDebug() << "TVScreen::initializeGL: context:"
|
qDebug() << "TVScreen::initializeGL: context:"
|
||||||
<< " major: " << (QOpenGLContext::currentContext()->format()).majorVersion()
|
<< " major: " << (QOpenGLContext::currentContext()->format()).majorVersion()
|
||||||
<< " minor: " << (QOpenGLContext::currentContext()->format()).minorVersion()
|
<< " minor: " << (QOpenGLContext::currentContext()->format()).minorVersion()
|
||||||
<< " ES: " << (QOpenGLContext::currentContext()->isOpenGLES() ? "yes" : "no");
|
<< " ES: " << (QOpenGLContext::currentContext()->isOpenGLES() ? "yes" : "no");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -124,61 +128,63 @@ void TVScreen::initializeGL()
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
QSurface *objSurface = objGlCurrentContext->surface();
|
QSurface *surface = glCurrentContext->surface();
|
||||||
|
|
||||||
if (objSurface == nullptr)
|
if (surface == nullptr)
|
||||||
{
|
{
|
||||||
qCritical() << "TVScreen::initializeGL: no surface attached";
|
qCritical() << "TVScreen::initializeGL: no surface attached";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (objSurface->surfaceType() != QSurface::OpenGLSurface)
|
if (surface->surfaceType() != QSurface::OpenGLSurface)
|
||||||
{
|
{
|
||||||
qCritical() << "TVScreen::initializeGL: surface is not an OpenGLSurface: "
|
qCritical() << "TVScreen::initializeGL: surface is not an OpenGLSurface: "
|
||||||
<< objSurface->surfaceType()
|
<< surface->surfaceType()
|
||||||
<< " cannot use an OpenGL context";
|
<< " cannot use an OpenGL context";
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
qDebug() << "TVScreen::initializeGL: OpenGL surface:"
|
qDebug() << "TVScreen::initializeGL: OpenGL surface:"
|
||||||
<< " class: " << (objSurface->surfaceClass() == QSurface::Window ? "Window" : "Offscreen");
|
<< " class: " << (surface->surfaceClass() == QSurface::Window ? "Window" : "Offscreen");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
connect(objGlCurrentContext, &QOpenGLContext::aboutToBeDestroyed, this,
|
connect(
|
||||||
&TVScreen::cleanup); // TODO: when migrating to QOpenGLWidget
|
glCurrentContext,
|
||||||
|
&QOpenGLContext::aboutToBeDestroyed,
|
||||||
|
this,
|
||||||
|
&TVScreen::cleanup
|
||||||
|
); // TODO: when migrating to QOpenGLWidget
|
||||||
|
|
||||||
m_blnGLContextInitialized = true;
|
m_glContextInitialized = true;
|
||||||
|
|
||||||
m_objMutex.unlock();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TVScreen::resizeGL(int intWidth, int intHeight)
|
void TVScreen::resizeGL(int width, int height)
|
||||||
{
|
{
|
||||||
QOpenGLFunctions *ptrF = QOpenGLContext::currentContext()->functions();
|
QMutexLocker mlock(&m_mutex);
|
||||||
ptrF->glViewport(0, 0, intWidth, intHeight);
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
||||||
m_blnConfigChanged = true;
|
f->glViewport(0, 0, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TVScreen::paintGL()
|
void TVScreen::paintGL()
|
||||||
{
|
{
|
||||||
if (!m_objMutex.tryLock(2))
|
if (!m_mutex.tryLock(2)) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_blnDataChanged = false;
|
|
||||||
|
|
||||||
if ((m_intAskedCols != 0) && (m_intAskedRows != 0))
|
|
||||||
{
|
|
||||||
m_objGLShaderArray.initializeGL(m_intAskedCols, m_intAskedRows);
|
|
||||||
m_intAskedCols = 0;
|
|
||||||
m_intAskedRows = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
m_objGLShaderArray.RenderPixels(m_chrLastData);
|
m_dataChanged = false;
|
||||||
|
|
||||||
m_objMutex.unlock();
|
if ((m_askedCols != 0) && (m_askedRows != 0))
|
||||||
|
{
|
||||||
|
m_glShaderArray.initializeGL(m_askedCols, m_askedRows);
|
||||||
|
m_askedCols = 0;
|
||||||
|
m_askedRows = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
m_glShaderArray.RenderPixels(m_lastData);
|
||||||
|
m_mutex.unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TVScreen::mousePressEvent(QMouseEvent* event)
|
void TVScreen::mousePressEvent(QMouseEvent* event)
|
||||||
@ -188,59 +194,51 @@ void TVScreen::mousePressEvent(QMouseEvent* event)
|
|||||||
|
|
||||||
void TVScreen::tick()
|
void TVScreen::tick()
|
||||||
{
|
{
|
||||||
if (m_blnDataChanged) {
|
if (m_dataChanged) {
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TVScreen::connectTimer(const QTimer& objTimer)
|
void TVScreen::connectTimer(const QTimer& timer)
|
||||||
{
|
{
|
||||||
qDebug() << "TVScreen::connectTimer";
|
qDebug() << "TVScreen::connectTimer";
|
||||||
disconnect(&m_objTimer, SIGNAL(timeout()), this, SLOT(tick()));
|
disconnect(&m_timer, SIGNAL(timeout()), this, SLOT(tick()));
|
||||||
connect(&objTimer, SIGNAL(timeout()), this, SLOT(tick()));
|
connect(&timer, SIGNAL(timeout()), this, SLOT(tick()));
|
||||||
m_objTimer.stop();
|
m_timer.stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TVScreen::cleanup()
|
void TVScreen::cleanup()
|
||||||
{
|
{
|
||||||
if (m_blnGLContextInitialized)
|
QMutexLocker mlock(&m_mutex);
|
||||||
{
|
|
||||||
m_objGLShaderArray.cleanup();
|
if (m_glContextInitialized) {
|
||||||
|
m_glShaderArray.cleanup();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TVScreen::selectRow(int intLine)
|
bool TVScreen::selectRow(int line)
|
||||||
{
|
{
|
||||||
if (m_blnGLContextInitialized)
|
if (m_glContextInitialized) {
|
||||||
{
|
return m_glShaderArray.SelectRow(line);
|
||||||
return m_objGLShaderArray.SelectRow(intLine);
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TVScreen::setDataColor(int intCol, int intRed, int intGreen, int intBlue)
|
bool TVScreen::setDataColor(int col, int red, int green, int blue)
|
||||||
{
|
{
|
||||||
if (m_blnGLContextInitialized)
|
if (m_glContextInitialized) {
|
||||||
{
|
return m_glShaderArray.SetDataColor(col, qRgb(blue, green, red)); // FIXME: blue <> red inversion in shader
|
||||||
return m_objGLShaderArray.SetDataColor(intCol, qRgb(intBlue, intGreen, intRed)); // FIXME: blue <> red inversion in shader
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TVScreen::setDataColor(int intCol, int intRed, int intGreen, int intBlue, int intAlpha)
|
bool TVScreen::setDataColor(int col, int red, int green, int blue, int alpha)
|
||||||
{
|
{
|
||||||
if (m_blnGLContextInitialized)
|
if (m_glContextInitialized) {
|
||||||
{
|
return m_glShaderArray.SetDataColor(col, qRgba(blue, green, red, alpha)); // FIXME: blue <> red inversion in shader
|
||||||
return m_objGLShaderArray.SetDataColor(intCol, qRgba(intBlue, intGreen, intRed, intAlpha)); // FIXME: blue <> red inversion in shader
|
} else {
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -42,46 +42,46 @@ class SDRGUI_API TVScreen: public QGLWidget
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
TVScreen(bool blnColor, QWidget* parent = 0);
|
TVScreen(bool color, QWidget* parent = nullptr);
|
||||||
virtual ~TVScreen();
|
virtual ~TVScreen();
|
||||||
|
|
||||||
void setColor(bool blnColor);
|
void setColor(bool color);
|
||||||
void resizeTVScreen(int intCols, int intRows);
|
void resizeTVScreen(int cols, int rows);
|
||||||
void getSize(int& intCols, int& intRows) const;
|
void getSize(int& cols, int& rows) const;
|
||||||
void renderImage(unsigned char * objData);
|
void renderImage(unsigned char * data);
|
||||||
QRgb* getRowBuffer(int intRow);
|
QRgb* getRowBuffer(int row);
|
||||||
void resetImage();
|
void resetImage();
|
||||||
void resetImage(int alpha);
|
void resetImage(int alpha);
|
||||||
|
|
||||||
bool selectRow(int intLine);
|
bool selectRow(int line);
|
||||||
bool setDataColor(int intCol, int intRed, int intGreen, int intBlue);
|
bool setDataColor(int col, int red, int green, int blue);
|
||||||
bool setDataColor(int intCol, int intRed, int intGreen, int intBlue, int intAlpha);
|
bool setDataColor(int col, int red, int green, int blue, int alpha);
|
||||||
void setAlphaBlend(bool blnAlphaBlend) { m_objGLShaderArray.setAlphaBlend(blnAlphaBlend); }
|
void setAlphaBlend(bool alphaBlend) { m_glShaderArray.setAlphaBlend(alphaBlend); }
|
||||||
void setAlphaReset() { m_objGLShaderArray.setAlphaReset(); }
|
void setAlphaReset() { m_glShaderArray.setAlphaReset(); }
|
||||||
|
|
||||||
void connectTimer(const QTimer& timer);
|
void connectTimer(const QTimer& timer);
|
||||||
|
|
||||||
//Valeurs par défaut
|
//Valeurs par défaut
|
||||||
static const int TV_COLS=256;
|
static const int TV_COLS = 256;
|
||||||
static const int TV_ROWS=256;
|
static const int TV_ROWS = 256;
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void traceSizeChanged(int);
|
void traceSizeChanged(int);
|
||||||
void sampleRateChanged(int);
|
void sampleRateChanged(int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool m_blnGLContextInitialized;
|
bool m_glContextInitialized;
|
||||||
int m_intAskedCols;
|
int m_askedCols;
|
||||||
int m_intAskedRows;
|
int m_askedRows;
|
||||||
|
|
||||||
|
|
||||||
// state
|
// state
|
||||||
QTimer m_objTimer;
|
QTimer m_timer;
|
||||||
QMutex m_objMutex;
|
QMutex m_mutex;
|
||||||
bool m_blnDataChanged;
|
bool m_dataChanged;
|
||||||
bool m_blnConfigChanged;
|
bool m_configChanged;
|
||||||
|
|
||||||
GLShaderTVArray m_objGLShaderArray;
|
GLShaderTVArray m_glShaderArray;
|
||||||
|
|
||||||
int m_cols;
|
int m_cols;
|
||||||
int m_rows;
|
int m_rows;
|
||||||
@ -92,7 +92,7 @@ private:
|
|||||||
|
|
||||||
void mousePressEvent(QMouseEvent*);
|
void mousePressEvent(QMouseEvent*);
|
||||||
|
|
||||||
unsigned char *m_chrLastData;
|
unsigned char *m_lastData;
|
||||||
|
|
||||||
protected slots:
|
protected slots:
|
||||||
void cleanup();
|
void cleanup();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user