From 4c98de9bcd9754965877e0c45714979f45aad4b7 Mon Sep 17 00:00:00 2001 From: "Joakim L. Gilje" Date: Fri, 3 Dec 2021 12:57:56 +0100 Subject: [PATCH] don't need the reqUpdate_() slot, update is already a slot. lock the image data with a mutex --- src/qt/qt_gleswidget.cpp | 50 ++++++++++++++++++---------------------- src/qt/qt_gleswidget.hpp | 6 ++--- 2 files changed, 26 insertions(+), 30 deletions(-) diff --git a/src/qt/qt_gleswidget.cpp b/src/qt/qt_gleswidget.cpp index 40daa2e0c..5bab0910d 100644 --- a/src/qt/qt_gleswidget.cpp +++ b/src/qt/qt_gleswidget.cpp @@ -60,20 +60,14 @@ void GLESWidget::resizeGL(int w, int h) void GLESWidget::initializeGL() { initializeOpenGLFunctions(); - connect(this, &GLESWidget::reqUpdate, this, &GLESWidget::reqUpdate_); + connect(this, &GLESWidget::reqUpdate, this, static_cast(&GLESWidget::update)); } void GLESWidget::paintGL() { + std::scoped_lock lock(image_mx); QPainter painter(this); 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) @@ -136,26 +130,28 @@ void GLESWidget::mouseMoveEvent(QMouseEvent *event) void GLESWidget::qt_real_blit(int x, int y, int w, int h) { - if ((w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL) || !firstupdate) { + std::scoped_lock lock(image_mx); + if ((w <= 0) || (h <= 0) || (w > 2048) || (h > 2048) || (buffer32 == NULL)) + { + video_blit_complete(); + return; + } + sx = x; + sy = y; + sw = this->w = w; + sh = this->h = h; + static auto imagebits = m_image.bits(); + for (int y1 = y; y1 < (y + h - 1); y1++) + { + auto scanline = imagebits + (y1 * (2048 + 64) * 4); + video_copy(scanline + (x * 4), &(buffer32->line[y1][x]), w * 4); + } + if (screenshots) + { + video_screenshot((uint32_t *)imagebits, 0, 0, 2048 + 64); + } video_blit_complete(); - return; } - sx = x; - sy = y; - sw = this->w = w; - sh = this->h = h; - static auto imagebits = m_image.bits(); - for (int y1 = y; y1 < (y + h - 1); y1++) - { - auto scanline = imagebits + (y1 * (2048 + 64) * 4); - video_copy(scanline + (x * 4), &(buffer32->line[y1][x]), w * 4); - } - if (screenshots) - { - video_screenshot((uint32_t *)imagebits, 0, 0, 2048 + 64); - } - video_blit_complete(); - firstupdate = false; - this->reqUpdate(); + reqUpdate(); } diff --git a/src/qt/qt_gleswidget.hpp b/src/qt/qt_gleswidget.hpp index 9c7e9a6cd..c5f4087b0 100644 --- a/src/qt/qt_gleswidget.hpp +++ b/src/qt/qt_gleswidget.hpp @@ -7,7 +7,8 @@ #include #include -#include +#include +#include #ifdef WAYLAND #include "wl_mouse.hpp" @@ -19,6 +20,7 @@ class GLESWidget : public QOpenGLWidget, protected QOpenGLFunctions private: QImage m_image{QSize(2048 + 64, 2048 + 64), QImage::Format_RGB32}; + std::mutex image_mx; int x, y, w, h, sx, sy, sw, sh; bool wayland = false; public: @@ -58,7 +60,6 @@ signals: public slots: void qt_real_blit(int x, int y, int w, int h); void qt_mouse_poll(); - void reqUpdate_(); private: struct mouseinputdata { @@ -66,5 +67,4 @@ private: int mousebuttons; }; mouseinputdata mousedata; - std::atomic firstupdate{false}; };