don't need the reqUpdate_() slot, update is already a slot. lock the image data with a mutex
This commit is contained in:
@@ -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<void (GLESWidget::*)()>(&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();
|
||||
}
|
||||
|
@@ -7,7 +7,8 @@
|
||||
#include <QKeyEvent>
|
||||
|
||||
#include <atomic>
|
||||
#include <qapplication.h>
|
||||
#include <mutex>
|
||||
#include <QApplication>
|
||||
|
||||
#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<bool> firstupdate{false};
|
||||
};
|
||||
|
Reference in New Issue
Block a user