Qt: More camera threading fixes
Vicki Pfau vi@endrift.com
Thu, 27 Jul 2017 00:06:54 -0700
2 files changed,
16 insertions(+),
4 deletions(-)
M
src/platform/qt/InputController.cpp
→
src/platform/qt/InputController.cpp
@@ -111,12 +111,17 @@ };
m_image.requestImage = [](mImageSource* context, const uint32_t** buffer, size_t* stride) { InputControllerImage* image = static_cast<InputControllerImage*>(context); - if (image->resizedImage.isNull()) { - image->resizedImage = image->image.scaled(image->w, image->h, Qt::KeepAspectRatioByExpanding); + QSize size; + { + 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()); - QSize size = image->resizedImage.size(); if (size.width() > image->w) { bits += (size.width() - image->w) / 2; }@@ -671,13 +676,17 @@ }
} void InputController::loadCamImage(const QString& path) { + QMutexLocker locker(&m_image.mutex); m_image.image.load(path); m_image.resizedImage = QImage(); + m_image.outOfDate = true; } void InputController::setCamImage(const QImage& image) { + QMutexLocker locker(&m_image.mutex); m_image.image = image; m_image.resizedImage = QImage(); + m_image.outOfDate = true; } void InputController::increaseLuminanceLevel() {
M
src/platform/qt/InputController.h
→
src/platform/qt/InputController.h
@@ -10,6 +10,7 @@ #include "GamepadAxisEvent.h"
#include "GamepadHatEvent.h" #include <QImage> +#include <QMutex> #include <QObject> #include <QSet> #include <QTimer>@@ -144,6 +145,8 @@ struct InputControllerImage : mImageSource {
InputController* p; QImage image; QImage resizedImage; + bool outOfDate; + QMutex mutex; unsigned w, h; } m_image;