2
* Copyright (c) 2010 Dmitry Kazakov <dimula73@gmail.com>
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; either version 2 of the License, or
7
* (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
#include "kis_update_scheduler.h"
21
#include "kis_merge_walker.h"
22
#include "kis_full_refresh_walker.h"
23
#include "kis_simple_update_queue.h"
25
KisUpdateScheduler::KisUpdateScheduler(KisImageWSP image)
30
// The queue will update settings in a constructor itself
31
m_workQueue = new KisSimpleUpdateQueue();
33
connect(&m_updaterContext, SIGNAL(sigContinueUpdate(const QRect&)),
34
image, SLOT(slotProjectionUpdated(const QRect&)),
35
Qt::DirectConnection);
37
connect(&m_updaterContext, SIGNAL(sigDoSomeUsefulWork()),
38
SLOT(doSomeUsefulWork()), Qt::DirectConnection);
40
connect(&m_updaterContext, SIGNAL(sigSpareThreadAppeared()),
41
SLOT(spareThreadAppeared()), Qt::DirectConnection);
45
KisUpdateScheduler::~KisUpdateScheduler()
49
void KisUpdateScheduler::updateProjection(KisNodeSP node, const QRect& rc, const QRect &cropRect)
51
m_workQueue->addJob(node, rc, cropRect);
52
m_workQueue->processQueue(m_updaterContext);
55
void KisUpdateScheduler::fullRefresh(KisNodeSP root, const QRect& rc, const QRect &cropRect)
57
KisBaseRectsWalkerSP walker = new KisFullRefreshWalker(cropRect);
58
walker->collectRects(root, rc);
60
m_workQueue->executeJobSync(walker, m_updaterContext);
63
void KisUpdateScheduler::updateSettings()
66
m_workQueue->updateSettings();
70
void KisUpdateScheduler::lock()
72
m_workQueue->blockProcessing(m_updaterContext);
75
void KisUpdateScheduler::unlock()
77
m_workQueue->startProcessing(m_updaterContext);
80
void KisUpdateScheduler::waitForDone()
82
m_updaterContext.waitForDone();
83
Q_ASSERT(m_workQueue->isEmpty());
86
void KisUpdateScheduler::doSomeUsefulWork()
88
m_workQueue->optimize();
91
void KisUpdateScheduler::spareThreadAppeared()
93
m_workQueue->processQueue(m_updaterContext);