diff --git a/src/qt/qt_gleswidget.cpp b/src/qt/qt_gleswidget.cpp index 24c9e4a36..c30e5cefa 100644 --- a/src/qt/qt_gleswidget.cpp +++ b/src/qt/qt_gleswidget.cpp @@ -1,4 +1,5 @@ #include +#include #include "qt_gleswidget.hpp" #ifdef __APPLE__ #include @@ -53,13 +54,20 @@ void GLESWidget::resizeGL(int w, int h) void GLESWidget::initializeGL() { initializeOpenGLFunctions(); + connect(this, &GLESWidget::reqUpdate, this, &GLESWidget::reqUpdate_); } + void GLESWidget::paintGL() { QPainter painter(this); - //painter.fillRect(rect, QColor(0, 0, 0)); - painter.drawImage(QRect(0, 0, width(), height()), m_image.convertToFormat(QImage::Format_RGBA8888), QRect(sx, sy, sw, sh)); + painter.drawImage(QRect(0, 0, width(), height()), m_image.convertToFormat(QImage::Format_RGBX8888), QRect(sx, sy, sw, sh)); painter.end(); + firstupdate = true; +} + +void GLESWidget::reqUpdate_() +{ + update(); } void GLESWidget::mouseReleaseEvent(QMouseEvent *event) @@ -114,8 +122,7 @@ void GLESWidget::mouseMoveEvent(QMouseEvent *event) void GLESWidget::qt_real_blit(int x, int y, int w, int h) { - // printf("Offpainter thread ID: %X\n", SDL_ThreadID()); - if ((w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL)) + if ((w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || !firstupdate) { video_blit_complete(); return; @@ -124,7 +131,7 @@ void GLESWidget::qt_real_blit(int x, int y, int w, int h) sy = y; sw = this->w = w; sh = this->h = h; - auto imagebits = m_image.bits(); + static auto imagebits = m_image.bits(); for (int y1 = y; y1 < (y + h - 1); y1++) { auto scanline = imagebits + (y1 * (2048 + 64) * 4); @@ -135,5 +142,5 @@ void GLESWidget::qt_real_blit(int x, int y, int w, int h) video_screenshot((uint32_t *)imagebits, 0, 0, 2048 + 64); } video_blit_complete(); - update(); + this->reqUpdate(); } diff --git a/src/qt/qt_gleswidget.hpp b/src/qt/qt_gleswidget.hpp index 2ac888724..2fa8d8d67 100644 --- a/src/qt/qt_gleswidget.hpp +++ b/src/qt/qt_gleswidget.hpp @@ -6,6 +6,8 @@ #include #include +#include + class GLESWidget : public QOpenGLWidget, protected QOpenGLFunctions { Q_OBJECT @@ -38,9 +40,13 @@ public: { event->ignore(); } +signals: + void reqUpdate(); + public slots: void qt_real_blit(int x, int y, int w, int h); void qt_mouse_poll(); + void reqUpdate_(); private: struct mouseinputdata { @@ -48,5 +54,5 @@ private: int mousebuttons; }; mouseinputdata mousedata; - + std::atomic firstupdate{false}; }; diff --git a/src/qt/qt_mainwindow.cpp b/src/qt/qt_mainwindow.cpp index 9adad9656..ad3a4df14 100644 --- a/src/qt/qt_mainwindow.cpp +++ b/src/qt/qt_mainwindow.cpp @@ -44,8 +44,6 @@ MainWindow::MainWindow(QWidget *parent) : video_setblit(qt_blit); ui->glesWidget->setMouseTracking(true); - connect(this, &MainWindow::blitToWidget, ui->glesWidget, &GLESWidget::qt_real_blit); - connect(this, &MainWindow::showMessageForNonQtThread, this, &MainWindow::showMessage_, Qt::BlockingQueuedConnection); connect(this, &MainWindow::setTitleForNonQtThread, this, &MainWindow::setTitle_, Qt::BlockingQueuedConnection); @@ -702,6 +700,11 @@ void MainWindow::keyPressEvent(QKeyEvent* event) } } +void MainWindow::blitToWidget(int x, int y, int w, int h) +{ + ui->glesWidget->qt_real_blit(x, y, w, h); +} + void MainWindow::keyReleaseEvent(QKeyEvent* event) { #ifdef __APPLE__ diff --git a/src/qt/qt_mainwindow.hpp b/src/qt/qt_mainwindow.hpp index ba93df369..3c5055027 100644 --- a/src/qt/qt_mainwindow.hpp +++ b/src/qt/qt_mainwindow.hpp @@ -22,9 +22,9 @@ public: void showMessage(const QString& header, const QString& message); void setTitle(const wchar_t* title); void getTitle(wchar_t* title); + void blitToWidget(int x, int y, int w, int h); signals: void paint(const QImage& image); - void blitToWidget(int x, int y, int w, int h); void resizeContents(int w, int h); void pollMouse(); void updateStatusBarPanes();