diff --git a/src/mtsgui/mainwindow.cpp b/src/mtsgui/mainwindow.cpp index 05a1a669..bcaaa44d 100644 --- a/src/mtsgui/mainwindow.cpp +++ b/src/mtsgui/mainwindow.cpp @@ -163,8 +163,8 @@ MainWindow::MainWindow(QWidget *parent) : connect(m_renderListener, SIGNAL(jobFinished(const RenderJob *, bool)), this, SLOT(onJobFinished(const RenderJob *, bool)), Qt::QueuedConnection); - connect(m_renderListener, SIGNAL(refresh(const RenderJob *, const Bitmap *)), - this, SLOT(onRefresh(const RenderJob *, const Bitmap *)), Qt::BlockingQueuedConnection); + connect(m_renderListener, SIGNAL(refresh(const RenderJob *)), + this, SLOT(onRefresh(const RenderJob *)), Qt::QueuedConnection); connect(m_renderListener, SIGNAL(workEnd(const RenderJob *, const ImageBlock *)), this, SLOT(onWorkEnd(const RenderJob *, const ImageBlock *)), Qt::DirectConnection); connect(m_renderListener, SIGNAL(workBegin(const RenderJob *, const RectangularWorkUnit *, int)), @@ -1673,10 +1673,11 @@ void MainWindow::onWorkEnd(const RenderJob *job, const ImageBlock *block) { emit updateView(); } -void MainWindow::onRefresh(const RenderJob *job, const Bitmap *_bitmap) { +void MainWindow::onRefresh(const RenderJob *job) { SceneContext *context = getContext(job, false); if (context == NULL) return; + Film *film = context->scene->getFilm(); Point2i co = film->getCropOffset(); Bitmap *bitmap = context->framebuffer; diff --git a/src/mtsgui/mainwindow.h b/src/mtsgui/mainwindow.h index bfd1c7a0..1d5e8cd1 100644 --- a/src/mtsgui/mainwindow.h +++ b/src/mtsgui/mainwindow.h @@ -41,6 +41,11 @@ class PreviewSettingsDlg; class QRenderListener : public QObject, public RenderListener { Q_OBJECT public: + QRenderListener() { + m_mutex = new Mutex(); + m_cond = new ConditionVariable(m_mutex); + } + /// Called when work has begun in a rectangular image region inline void workBeginEvent(const RenderJob *job, const RectangularWorkUnit *wu, int worker) { emit workBegin(job, wu, worker); @@ -53,7 +58,12 @@ public: /// Called when the whole target image has been altered in some way inline void refreshEvent(const RenderJob *job, const Bitmap *bitmap) { - emit refresh(job, bitmap); + m_mutex->lock(); + m_bitmap = bitmap; + emit refresh(job); + m_cond->wait(500); + m_bitmap = NULL; + m_mutex->unlock(); } /// Called when a render job has completed successfully or unsuccessfully @@ -61,14 +71,29 @@ public: emit jobFinished(job, cancelled); } + /// Lock the mutex + inline void lock() { m_mutex->lock(); } + + /// Access the image associated with the last refresh event + inline const Bitmap *getBitmap() const { return m_bitmap.get(); } + + /// Unlock the mutex + inline void unlock() { m_mutex->unlock(); } + MTS_DECLARE_CLASS() signals: void workBegin(const RenderJob *job, const RectangularWorkUnit *wu, int worker); void workEnd(const RenderJob *job, const ImageBlock *wr); - void refresh(const RenderJob *job, const Bitmap *bitmap); + void refresh(const RenderJob *job); void jobFinished(const RenderJob *job, bool cancelled); + protected: virtual ~QRenderListener() { } + +private: + ref m_mutex; + ref m_cond; + ref m_bitmap; }; class PreviewSettingsDialog;