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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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