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
105 void lock();
106
112 void unlock();
113
122 void setThreadsLimit(int value);
123
128 int threadsLimit() const;
129
130 void continueUpdate(const QRect& rc);
131 void doSomeUsefulWork();
132 void jobFinished();
133 void jobThreadExited();
134
135 void setTestingMode(bool value);
136
137protected:
138 static bool walkerIntersectsJob(KisBaseRectsWalkerSP walker,
139 const KisUpdateJobItem* job);
140 qint32 findSpareThread();
141
142protected:
149 QReadWriteLock m_exclusiveJobLock;
150
151 QMutex m_lock;
153 int m_numRunningThreads = 0;
156 QThreadPool m_threadPool;
159 bool m_testingMode = false;
160
161private:
162
163 friend class KisUpdaterContextTest;
164 friend class KisUpdateSchedulerTest;
165 friend class KisStrokesQueueTest;
166 friend class KisSimpleUpdateQueueTest;
167 friend class KisUpdateJobItem;
168
169 const QVector<KisUpdateJobItem*> getJobs();
170 void clear();
171
172 void startThread(int index);
173
174};
175
176class KRITAIMAGE_EXPORT KisTestableUpdaterContext : public KisUpdaterContext
177{
178public:
182 KisTestableUpdaterContext(qint32 threadCount);
183};
184
185
186#endif /* __KIS_UPDATER_CONTEXT_H */
187
188
189
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