citra-emu
/
citra
Archived
1
0
Fork 0

StillImageCamera: move GetFilePath to UI thread

This commit is contained in:
zhupengfei 2018-06-03 11:29:46 +08:00
parent 341c07156a
commit 7c48160beb
No known key found for this signature in database
GPG Key ID: 85B82A3E62174206
7 changed files with 26 additions and 16 deletions

View File

@ -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()) {

View File

@ -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

View File

@ -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);
}

View File

@ -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 {

View File

@ -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()) {

View File

@ -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

View File

@ -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);
}
};