diff --git a/libs/image/kis_update_job_item.h b/libs/image/kis_update_job_item.h --- a/libs/image/kis_update_job_item.h +++ b/libs/image/kis_update_job_item.h @@ -28,6 +28,7 @@ #include "kis_spontaneous_job.h" #include "kis_base_rects_walker.h" #include "kis_async_merger.h" +#include "kis_updater_context.h" class KisUpdateJobItem : public QObject, public QRunnable @@ -43,8 +44,8 @@ }; public: - KisUpdateJobItem(QReadWriteLock *exclusiveJobLock) - : m_exclusiveJobLock(exclusiveJobLock), + KisUpdateJobItem(KisUpdaterContext *updaterContext) + : m_updaterContext(updaterContext), m_atomicType(Type::EMPTY), m_runnableJob(0) { @@ -76,9 +77,9 @@ KIS_SAFE_ASSERT_RECOVER_RETURN(isRunning()); if(m_exclusive) { - m_exclusiveJobLock->lockForWrite(); + m_updaterContext->m_exclusiveJobLock.lockForWrite(); } else { - m_exclusiveJobLock->lockForRead(); + m_updaterContext->m_exclusiveJobLock.lockForRead(); } if(m_atomicType == Type::MERGE) { @@ -93,12 +94,12 @@ setDone(); - emit sigDoSomeUsefulWork(); + m_updaterContext->doSomeUsefulWork(); // may flip the current state from Waiting -> Running again - emit sigJobFinished(); + m_updaterContext->jobFinished(); - m_exclusiveJobLock->unlock(); + m_updaterContext->m_exclusiveJobLock.unlock(); // try to exit the loop. Please note, that no one can flip the state from // WAITING to EMPTY except ourselves! @@ -117,7 +118,7 @@ m_merger.startMerge(*m_walker); QRect changeRect = m_walker->changeRect(); - emit sigContinueUpdate(changeRect); + m_updaterContext->continueUpdate(changeRect); } // return true if the thread should actually be started @@ -191,11 +192,6 @@ return m_strokeJobSequentiality; } -Q_SIGNALS: - void sigContinueUpdate(const QRect& rc); - void sigDoSomeUsefulWork(); - void sigJobFinished(); - private: /** * Open walker and stroke job for the testing suite. @@ -222,10 +218,7 @@ } private: - /** - * \see KisUpdaterContext::m_exclusiveJobLock - */ - QReadWriteLock *m_exclusiveJobLock; + KisUpdaterContext *m_updaterContext; bool m_exclusive; diff --git a/libs/image/kis_update_scheduler.h b/libs/image/kis_update_scheduler.h --- a/libs/image/kis_update_scheduler.h +++ b/libs/image/kis_update_scheduler.h @@ -204,6 +204,10 @@ bool wrapAroundModeSupported() const; int currentLevelOfDetail() const; + void continueUpdate(const QRect &rect); + void doSomeUsefulWork(); + void spareThreadAppeared(); + protected: // Trivial constructor for testing support KisUpdateScheduler(); @@ -216,11 +220,6 @@ */ void updateSettings(); -private Q_SLOTS: - void continueUpdate(const QRect &rect); - void doSomeUsefulWork(); - void spareThreadAppeared(); - private: friend class UpdatesBlockTester; bool haveUpdatesRunning(); diff --git a/libs/image/kis_update_scheduler.cpp b/libs/image/kis_update_scheduler.cpp --- a/libs/image/kis_update_scheduler.cpp +++ b/libs/image/kis_update_scheduler.cpp @@ -117,16 +117,6 @@ void KisUpdateScheduler::connectSignals() { - connect(&m_d->updaterContext, SIGNAL(sigContinueUpdate(const QRect&)), - SLOT(continueUpdate(const QRect&)), - Qt::DirectConnection); - - connect(&m_d->updaterContext, SIGNAL(sigDoSomeUsefulWork()), - SLOT(doSomeUsefulWork()), Qt::DirectConnection); - - connect(&m_d->updaterContext, SIGNAL(sigSpareThreadAppeared()), - SLOT(spareThreadAppeared()), Qt::DirectConnection); - connect(KisImageConfigNotifier::instance(), SIGNAL(configChanged()), SLOT(updateSettings())); } diff --git a/libs/image/kis_updater_context.h b/libs/image/kis_updater_context.h --- a/libs/image/kis_updater_context.h +++ b/libs/image/kis_updater_context.h @@ -29,6 +29,7 @@ #include "kis_lock_free_lod_counter.h" #include "KisUpdaterContextSnapshotEx.h" +#include "kis_update_scheduler.h" class KisUpdateJobItem; class KisSpontaneousJob; @@ -138,14 +139,11 @@ */ int threadsLimit() const; + void continueUpdate(const QRect& rc); + void doSomeUsefulWork(); + void jobFinished(); -Q_SIGNALS: - void sigContinueUpdate(const QRect& rc); - void sigDoSomeUsefulWork(); - void sigSpareThreadAppeared(); - -protected Q_SLOTS: - void slotJobFinished(); + friend class KisUpdateJobItem; protected: static bool walkerIntersectsJob(KisBaseRectsWalkerSP walker, @@ -165,6 +163,7 @@ QVector m_jobs; QThreadPool m_threadPool; KisLockFreeLodCounter m_lodCounter; + KisUpdateScheduler *m_scheduler; }; class KRITAIMAGE_EXPORT KisTestableUpdaterContext : public KisUpdaterContext @@ -186,6 +185,8 @@ const QVector getJobs(); void clear(); + + friend class KisUpdateJobItem; }; diff --git a/libs/image/kis_updater_context.cpp b/libs/image/kis_updater_context.cpp --- a/libs/image/kis_updater_context.cpp +++ b/libs/image/kis_updater_context.cpp @@ -27,7 +27,7 @@ const int KisUpdaterContext::useIdealThreadCountTag = -1; KisUpdaterContext::KisUpdaterContext(qint32 threadCount, QObject *parent) - : QObject(parent) + : QObject(parent), m_scheduler(qobject_cast(parent)) { if(threadCount <= 0) { threadCount = QThread::idealThreadCount(); @@ -244,14 +244,6 @@ return -1; } -void KisUpdaterContext::slotJobFinished() -{ - m_lodCounter.removeLod(); - - // Be careful. This slot can be called asynchronously without locks. - emit sigSpareThreadAppeared(); -} - void KisUpdaterContext::lock() { m_lock.lock(); @@ -278,16 +270,7 @@ m_jobs.resize(value); for(qint32 i = 0; i < m_jobs.size(); i++) { - m_jobs[i] = new KisUpdateJobItem(&m_exclusiveJobLock); - connect(m_jobs[i], SIGNAL(sigContinueUpdate(const QRect&)), - SIGNAL(sigContinueUpdate(const QRect&)), - Qt::DirectConnection); - - connect(m_jobs[i], SIGNAL(sigDoSomeUsefulWork()), - SIGNAL(sigDoSomeUsefulWork()), Qt::DirectConnection); - - connect(m_jobs[i], SIGNAL(sigJobFinished()), - SLOT(slotJobFinished()), Qt::DirectConnection); + m_jobs[i] = new KisUpdateJobItem(this); } } @@ -297,6 +280,22 @@ return m_jobs.size(); } +void KisUpdaterContext::continueUpdate(const QRect& rc) +{ + if (m_scheduler) m_scheduler->continueUpdate(rc); +} + +void KisUpdaterContext::doSomeUsefulWork() +{ + if (m_scheduler) m_scheduler->doSomeUsefulWork(); +} + +void KisUpdaterContext::jobFinished() +{ + m_lodCounter.removeLod(); + if (m_scheduler) m_scheduler->spareThreadAppeared(); +} + KisTestableUpdaterContext::KisTestableUpdaterContext(qint32 threadCount) : KisUpdaterContext(threadCount) {