mirror of
https://github.com/citra-emu/citra.git
synced 2024-12-29 23:10:05 +00:00
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);
|
||||
}
|
||||
|
||||
std::unique_ptr<CameraInterface> QtCameraFactory::CreatePreview(
|
||||
const std::string& config, int width, int height, const Service::CAM::Flip& flip) const {
|
||||
std::unique_ptr<CameraInterface> QtCameraFactory::CreatePreview(const std::string& config,
|
||||
int width, int height,
|
||||
const Service::CAM::Flip& flip) {
|
||||
std::unique_ptr<CameraInterface> camera = Create(config, flip);
|
||||
|
||||
if (camera->IsPreviewAvailable()) {
|
||||
|
@ -30,7 +30,7 @@ private:
|
||||
// Base class for camera factories of citra_qt
|
||||
class QtCameraFactory : public CameraFactory {
|
||||
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
|
||||
|
@ -106,8 +106,8 @@ bool QtMultimediaCamera::IsPreviewAvailable() {
|
||||
return handler->CameraAvailable();
|
||||
}
|
||||
|
||||
std::unique_ptr<CameraInterface> QtMultimediaCameraFactory::Create(
|
||||
const std::string& config, const Service::CAM::Flip& flip) const {
|
||||
std::unique_ptr<CameraInterface> QtMultimediaCameraFactory::Create(const std::string& config,
|
||||
const Service::CAM::Flip& flip) {
|
||||
return std::make_unique<QtMultimediaCamera>(config, flip);
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ private:
|
||||
class QtMultimediaCameraFactory final : public QtCameraFactory {
|
||||
public:
|
||||
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 {
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include <QFileDialog>
|
||||
#include <QImageReader>
|
||||
#include <QMessageBox>
|
||||
#include <QThread>
|
||||
#include "citra_qt/camera/still_image_camera.h"
|
||||
|
||||
namespace Camera {
|
||||
@ -24,7 +25,7 @@ bool StillImageCamera::IsPreviewAvailable() {
|
||||
return !image.isNull();
|
||||
}
|
||||
|
||||
const std::string StillImageCameraFactory::GetFilePath() {
|
||||
const std::string StillImageCameraFactory::GetFilePath() const {
|
||||
QList<QByteArray> types = QImageReader::supportedImageFormats();
|
||||
QList<QString> temp_filters;
|
||||
for (QByteArray type : types) {
|
||||
@ -36,11 +37,18 @@ const std::string StillImageCameraFactory::GetFilePath() {
|
||||
.toStdString();
|
||||
}
|
||||
|
||||
std::unique_ptr<CameraInterface> StillImageCameraFactory::Create(
|
||||
const std::string& config, const Service::CAM::Flip& flip) const {
|
||||
std::unique_ptr<CameraInterface> StillImageCameraFactory::Create(const std::string& config,
|
||||
const Service::CAM::Flip& flip) {
|
||||
std::string real_config = config;
|
||||
if (config.empty()) {
|
||||
// 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));
|
||||
if (image.isNull()) {
|
||||
|
@ -25,13 +25,14 @@ private:
|
||||
QImage image;
|
||||
};
|
||||
|
||||
class StillImageCameraFactory final : public QtCameraFactory {
|
||||
class StillImageCameraFactory final : public QObject, public QtCameraFactory {
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
std::unique_ptr<CameraInterface> Create(const std::string& config,
|
||||
const Service::CAM::Flip& flip) const override;
|
||||
const Service::CAM::Flip& flip) override;
|
||||
|
||||
private:
|
||||
static const std::string GetFilePath();
|
||||
Q_INVOKABLE const std::string GetFilePath() const;
|
||||
};
|
||||
|
||||
} // namespace Camera
|
||||
|
@ -22,7 +22,7 @@ public:
|
||||
* @returns a unique_ptr to the created camera object.
|
||||
*/
|
||||
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.
|
||||
@ -36,7 +36,7 @@ public:
|
||||
*/
|
||||
virtual std::unique_ptr<CameraInterface> CreatePreview(const std::string& config, int width,
|
||||
int height,
|
||||
const Service::CAM::Flip& flip) const {
|
||||
const Service::CAM::Flip& flip) {
|
||||
return Create(config, flip);
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user