StillImageCamera: move GetFilePath to UI thread
This commit is contained in:
parent
341c07156a
commit
7c48160beb
|
@ -40,8 +40,9 @@ std::vector<u16> QtCameraInterface::ReceiveFrame() {
|
||||||
flip_vertical);
|
flip_vertical);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<CameraInterface> QtCameraFactory::CreatePreview(
|
std::unique_ptr<CameraInterface> QtCameraFactory::CreatePreview(const std::string& config,
|
||||||
const std::string& config, int width, int height, const Service::CAM::Flip& flip) const {
|
int width, int height,
|
||||||
|
const Service::CAM::Flip& flip) {
|
||||||
std::unique_ptr<CameraInterface> camera = Create(config, flip);
|
std::unique_ptr<CameraInterface> camera = Create(config, flip);
|
||||||
|
|
||||||
if (camera->IsPreviewAvailable()) {
|
if (camera->IsPreviewAvailable()) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ private:
|
||||||
// Base class for camera factories of citra_qt
|
// Base class for camera factories of citra_qt
|
||||||
class QtCameraFactory : public CameraFactory {
|
class QtCameraFactory : public CameraFactory {
|
||||||
std::unique_ptr<CameraInterface> CreatePreview(const std::string& config, int width, int height,
|
std::unique_ptr<CameraInterface> CreatePreview(const std::string& config, int width, int height,
|
||||||
const Service::CAM::Flip& flip) const override;
|
const Service::CAM::Flip& flip) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Camera
|
} // namespace Camera
|
||||||
|
|
|
@ -106,8 +106,8 @@ bool QtMultimediaCamera::IsPreviewAvailable() {
|
||||||
return handler->CameraAvailable();
|
return handler->CameraAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<CameraInterface> QtMultimediaCameraFactory::Create(
|
std::unique_ptr<CameraInterface> QtMultimediaCameraFactory::Create(const std::string& config,
|
||||||
const std::string& config, const Service::CAM::Flip& flip) const {
|
const Service::CAM::Flip& flip) {
|
||||||
return std::make_unique<QtMultimediaCamera>(config, flip);
|
return std::make_unique<QtMultimediaCamera>(config, flip);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,7 @@ private:
|
||||||
class QtMultimediaCameraFactory final : public QtCameraFactory {
|
class QtMultimediaCameraFactory final : public QtCameraFactory {
|
||||||
public:
|
public:
|
||||||
std::unique_ptr<CameraInterface> Create(const std::string& config,
|
std::unique_ptr<CameraInterface> Create(const std::string& config,
|
||||||
const Service::CAM::Flip& flip) const override;
|
const Service::CAM::Flip& flip) override;
|
||||||
};
|
};
|
||||||
|
|
||||||
class QtMultimediaCameraHandler final : public QObject {
|
class QtMultimediaCameraHandler final : public QObject {
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <QFileDialog>
|
#include <QFileDialog>
|
||||||
#include <QImageReader>
|
#include <QImageReader>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
#include <QThread>
|
||||||
#include "citra_qt/camera/still_image_camera.h"
|
#include "citra_qt/camera/still_image_camera.h"
|
||||||
|
|
||||||
namespace Camera {
|
namespace Camera {
|
||||||
|
@ -24,7 +25,7 @@ bool StillImageCamera::IsPreviewAvailable() {
|
||||||
return !image.isNull();
|
return !image.isNull();
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string StillImageCameraFactory::GetFilePath() {
|
const std::string StillImageCameraFactory::GetFilePath() const {
|
||||||
QList<QByteArray> types = QImageReader::supportedImageFormats();
|
QList<QByteArray> types = QImageReader::supportedImageFormats();
|
||||||
QList<QString> temp_filters;
|
QList<QString> temp_filters;
|
||||||
for (QByteArray type : types) {
|
for (QByteArray type : types) {
|
||||||
|
@ -36,11 +37,18 @@ const std::string StillImageCameraFactory::GetFilePath() {
|
||||||
.toStdString();
|
.toStdString();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::unique_ptr<CameraInterface> StillImageCameraFactory::Create(
|
std::unique_ptr<CameraInterface> StillImageCameraFactory::Create(const std::string& config,
|
||||||
const std::string& config, const Service::CAM::Flip& flip) const {
|
const Service::CAM::Flip& flip) {
|
||||||
std::string real_config = config;
|
std::string real_config = config;
|
||||||
if (config.empty()) {
|
if (config.empty()) {
|
||||||
real_config = GetFilePath();
|
// call GetFilePath() in UI thread (note: StillImageCameraFactory itself is initialized in
|
||||||
|
// UI thread, so we can just pass in "this" here)
|
||||||
|
if (thread() == QThread::currentThread()) {
|
||||||
|
real_config = GetFilePath();
|
||||||
|
} else {
|
||||||
|
QMetaObject::invokeMethod(this, "GetFilePath", Qt::BlockingQueuedConnection,
|
||||||
|
Q_RETURN_ARG(std::string, real_config));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
QImage image(QString::fromStdString(real_config));
|
QImage image(QString::fromStdString(real_config));
|
||||||
if (image.isNull()) {
|
if (image.isNull()) {
|
||||||
|
|
|
@ -25,13 +25,14 @@ private:
|
||||||
QImage image;
|
QImage image;
|
||||||
};
|
};
|
||||||
|
|
||||||
class StillImageCameraFactory final : public QtCameraFactory {
|
class StillImageCameraFactory final : public QObject, public QtCameraFactory {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::unique_ptr<CameraInterface> Create(const std::string& config,
|
std::unique_ptr<CameraInterface> Create(const std::string& config,
|
||||||
const Service::CAM::Flip& flip) const override;
|
const Service::CAM::Flip& flip) override;
|
||||||
|
|
||||||
private:
|
Q_INVOKABLE const std::string GetFilePath() const;
|
||||||
static const std::string GetFilePath();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Camera
|
} // namespace Camera
|
||||||
|
|
|
@ -22,7 +22,7 @@ public:
|
||||||
* @returns a unique_ptr to the created camera object.
|
* @returns a unique_ptr to the created camera object.
|
||||||
*/
|
*/
|
||||||
virtual std::unique_ptr<CameraInterface> Create(const std::string& config,
|
virtual std::unique_ptr<CameraInterface> Create(const std::string& config,
|
||||||
const Service::CAM::Flip& flip) const = 0;
|
const Service::CAM::Flip& flip) = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a camera object for preview based on the configuration string.
|
* Creates a camera object for preview based on the configuration string.
|
||||||
|
@ -36,7 +36,7 @@ public:
|
||||||
*/
|
*/
|
||||||
virtual std::unique_ptr<CameraInterface> CreatePreview(const std::string& config, int width,
|
virtual std::unique_ptr<CameraInterface> CreatePreview(const std::string& config, int width,
|
||||||
int height,
|
int height,
|
||||||
const Service::CAM::Flip& flip) const {
|
const Service::CAM::Flip& flip) {
|
||||||
return Create(config, flip);
|
return Create(config, flip);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Reference in New Issue