Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_updater_context.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2010 Dmitry Kazakov <dimula73@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
6
7#ifndef __KIS_UPDATER_CONTEXT_H
8#define __KIS_UPDATER_CONTEXT_H
9
10#include <QMutex>
11#include <QReadWriteLock>
12#include <QThreadPool>
13#include <QWaitCondition>
14
16#include "kis_async_merger.h"
18
21
24class KisStrokeJob;
26
27class KRITAIMAGE_EXPORT KisUpdaterContext
28{
29public:
30 static const int useIdealThreadCountTag;
31
32public:
33 KisUpdaterContext(qint32 threadCount = useIdealThreadCountTag, KisUpdateScheduler *parent = 0);
35
36
43 void getJobsSnapshot(qint32 &numMergeJobs, qint32 &numStrokeJobs);
44
45 KisUpdaterContextSnapshotEx getContextSnapshotEx() const;
46
51 int currentLevelOfDetail() const;
52
57 bool hasSpareThread();
58
67 bool isJobAllowed(KisBaseRectsWalkerSP walker);
68
79 void addMergeJob(KisBaseRectsWalkerSP walker);
80
86 void addStrokeJob(KisStrokeJob *strokeJob);
87
88
94 void addSpontaneousJob(KisSpontaneousJob *spontaneousJob);
95
99 void waitForDone();
100
108 bool isIdle() const;
109
114 void lock();
115
121 void unlock();
122
131 void setThreadsLimit(int value);
132
137 int threadsLimit() const;
138
139 void continueUpdate(const QRect& rc);
140 void doSomeUsefulWork();
141 void jobFinished();
142 void jobThreadExited();
143
144 void setTestingMode(bool value);
145
146protected:
147 static bool walkerIntersectsJob(KisBaseRectsWalkerSP walker,
148 const KisUpdateJobItem* job);
149 qint32 findSpareThread();
150
151protected:
158 QReadWriteLock m_exclusiveJobLock;
159
160 QMutex m_lock;
161 mutable QMutex m_runningThreadsMutex;
162 int m_numRunningThreads = 0;
165 QThreadPool m_threadPool;
168 bool m_testingMode = false;
169
170private:
171
172 friend class KisUpdaterContextTest;
173 friend class KisUpdateSchedulerTest;
174 friend class KisStrokesQueueTest;
175 friend class KisSimpleUpdateQueueTest;
176 friend class KisUpdateJobItem;
177
178 const QVector<KisUpdateJobItem*> getJobs();
179 void clear();
180
181 void startThread(int index);
182
183};
184
185class KRITAIMAGE_EXPORT KisTestableUpdaterContext : public KisUpdaterContext
186{
187public:
191 KisTestableUpdaterContext(qint32 threadCount);
192};
193
194
195#endif /* __KIS_UPDATER_CONTEXT_H */
196
197
198
float value(const T *src, size_t ch)
KisLockFreeLodCounter m_lodCounter
QReadWriteLock m_exclusiveJobLock
QVector< KisUpdateJobItem * > m_jobs
static const int useIdealThreadCountTag
KisUpdateScheduler * m_scheduler
QWaitCondition m_waitForDoneCondition