mirror of https://github.com/mgba-emu/mgba.git
Qt: More camera threading fixes
This commit is contained in:
parent
9b7521ccea
commit
c7e65ff621
|
@ -111,12 +111,17 @@ InputController::InputController(int playerId, QWidget* topLevel, QObject* paren
|
||||||
|
|
||||||
m_image.requestImage = [](mImageSource* context, const uint32_t** buffer, size_t* stride) {
|
m_image.requestImage = [](mImageSource* context, const uint32_t** buffer, size_t* stride) {
|
||||||
InputControllerImage* image = static_cast<InputControllerImage*>(context);
|
InputControllerImage* image = static_cast<InputControllerImage*>(context);
|
||||||
if (image->resizedImage.isNull()) {
|
QSize size;
|
||||||
image->resizedImage = image->image.scaled(image->w, image->h, Qt::KeepAspectRatioByExpanding);
|
{
|
||||||
|
QMutexLocker locker(&image->mutex);
|
||||||
|
if (image->outOfDate) {
|
||||||
|
image->resizedImage = image->image.scaled(image->w, image->h, Qt::KeepAspectRatioByExpanding);
|
||||||
|
image->resizedImage = image->resizedImage.convertToFormat(QImage::Format_RGB32);
|
||||||
|
image->outOfDate = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
image->resizedImage = image->resizedImage.convertToFormat(QImage::Format_RGB32);
|
size = image->resizedImage.size();
|
||||||
const uint32_t* bits = reinterpret_cast<const uint32_t*>(image->resizedImage.constBits());
|
const uint32_t* bits = reinterpret_cast<const uint32_t*>(image->resizedImage.constBits());
|
||||||
QSize size = image->resizedImage.size();
|
|
||||||
if (size.width() > image->w) {
|
if (size.width() > image->w) {
|
||||||
bits += (size.width() - image->w) / 2;
|
bits += (size.width() - image->w) / 2;
|
||||||
}
|
}
|
||||||
|
@ -671,13 +676,17 @@ void InputController::releaseFocus(QWidget* focus) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputController::loadCamImage(const QString& path) {
|
void InputController::loadCamImage(const QString& path) {
|
||||||
|
QMutexLocker locker(&m_image.mutex);
|
||||||
m_image.image.load(path);
|
m_image.image.load(path);
|
||||||
m_image.resizedImage = QImage();
|
m_image.resizedImage = QImage();
|
||||||
|
m_image.outOfDate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputController::setCamImage(const QImage& image) {
|
void InputController::setCamImage(const QImage& image) {
|
||||||
|
QMutexLocker locker(&m_image.mutex);
|
||||||
m_image.image = image;
|
m_image.image = image;
|
||||||
m_image.resizedImage = QImage();
|
m_image.resizedImage = QImage();
|
||||||
|
m_image.outOfDate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputController::increaseLuminanceLevel() {
|
void InputController::increaseLuminanceLevel() {
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include "GamepadHatEvent.h"
|
#include "GamepadHatEvent.h"
|
||||||
|
|
||||||
#include <QImage>
|
#include <QImage>
|
||||||
|
#include <QMutex>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
@ -144,6 +145,8 @@ private:
|
||||||
InputController* p;
|
InputController* p;
|
||||||
QImage image;
|
QImage image;
|
||||||
QImage resizedImage;
|
QImage resizedImage;
|
||||||
|
bool outOfDate;
|
||||||
|
QMutex mutex;
|
||||||
unsigned w, h;
|
unsigned w, h;
|
||||||
} m_image;
|
} m_image;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue