File indexing completed on 2024-05-12 15:58:43
0001 /* 0002 * SPDX-FileCopyrightText: 2010 Dmitry Kazakov <dimula73@gmail.com> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #ifndef __KIS_SIMPLE_UPDATE_QUEUE_H 0008 #define __KIS_SIMPLE_UPDATE_QUEUE_H 0009 0010 #include <QMutex> 0011 #include "kis_updater_context.h" 0012 0013 typedef QList<KisBaseRectsWalkerSP> KisWalkersList; 0014 typedef QListIterator<KisBaseRectsWalkerSP> KisWalkersListIterator; 0015 typedef QMutableListIterator<KisBaseRectsWalkerSP> KisMutableWalkersListIterator; 0016 0017 typedef QList<KisSpontaneousJob*> KisSpontaneousJobsList; 0018 typedef QListIterator<KisSpontaneousJob*> KisSpontaneousJobsListIterator; 0019 typedef QMutableListIterator<KisSpontaneousJob*> KisMutableSpontaneousJobsListIterator; 0020 0021 0022 class KRITAIMAGE_EXPORT KisSimpleUpdateQueue 0023 { 0024 public: 0025 KisSimpleUpdateQueue(); 0026 virtual ~KisSimpleUpdateQueue(); 0027 0028 void processQueue(KisUpdaterContext &updaterContext); 0029 0030 void addUpdateJob(KisNodeSP node, const QVector<QRect> &rects, const QRect& cropRect, int levelOfDetail); 0031 void addUpdateJob(KisNodeSP node, const QRect &rc, const QRect& cropRect, int levelOfDetail); 0032 void addUpdateNoFilthyJob(KisNodeSP node, const QVector<QRect>& rc, const QRect& cropRect, int levelOfDetail); 0033 void addUpdateNoFilthyJob(KisNodeSP node, const QRect& rc, const QRect& cropRect, int levelOfDetail); 0034 void addFullRefreshJob(KisNodeSP node, const QRect &rc, const QRect& cropRect, int levelOfDetail); 0035 void addFullRefreshJob(KisNodeSP node, const QVector<QRect> &rects, const QRect& cropRect, int levelOfDetail); 0036 void addFullRefreshNoFilthyJob(KisNodeSP node, const QVector<QRect> &rects, const QRect& cropRect, int levelOfDetail); 0037 void addSpontaneousJob(KisSpontaneousJob *spontaneousJob); 0038 0039 0040 void optimize(); 0041 0042 bool isEmpty() const; 0043 qint32 sizeMetric() const; 0044 0045 void updateSettings(); 0046 0047 int overrideLevelOfDetail() const; 0048 0049 protected: 0050 void addJob(KisNodeSP node, const QVector<QRect> &rects, const QRect& cropRect, int levelOfDetail, KisBaseRectsWalker::UpdateType type); 0051 0052 bool processOneJob(KisUpdaterContext &updaterContext); 0053 0054 bool trySplitJob(KisNodeSP node, const QRect& rc, const QRect& cropRect, int levelOfDetail, KisBaseRectsWalker::UpdateType type); 0055 bool tryMergeJob(KisNodeSP node, const QRect& rc, const QRect& cropRect, int levelOfDetail, KisBaseRectsWalker::UpdateType type); 0056 0057 void collectJobs(KisBaseRectsWalkerSP &baseWalker, QRect baseRect, 0058 const qreal maxAlpha); 0059 bool joinRects(QRect& baseRect, const QRect& newRect, qreal maxAlpha); 0060 0061 protected: 0062 0063 mutable QMutex m_lock; 0064 KisWalkersList m_updatesList; 0065 KisSpontaneousJobsList m_spontaneousJobsList; 0066 0067 /** 0068 * Parameters of optimization 0069 * (loaded from a configuration file) 0070 */ 0071 0072 /** 0073 * Big update areas are split into a set of smaller 0074 * ones, m_patchWidth and m_patchHeight represent the 0075 * size of these areas. 0076 */ 0077 qint32 m_patchWidth; 0078 qint32 m_patchHeight; 0079 0080 /** 0081 * Maximum coefficient of work while regular optimization() 0082 */ 0083 qreal m_maxCollectAlpha; 0084 0085 /** 0086 * Maximum coefficient of work when to rects are considered 0087 * similar and are merged in tryMergeJob() 0088 */ 0089 qreal m_maxMergeAlpha; 0090 0091 /** 0092 * The coefficient of work used while collecting phase of tryToMerge() 0093 */ 0094 qreal m_maxMergeCollectAlpha; 0095 0096 int m_overrideLevelOfDetail; 0097 }; 0098 0099 class KRITAIMAGE_EXPORT KisTestableSimpleUpdateQueue : public KisSimpleUpdateQueue 0100 { 0101 public: 0102 KisWalkersList& getWalkersList(); 0103 KisSpontaneousJobsList& getSpontaneousJobsList(); 0104 }; 0105 0106 #endif /* __KIS_SIMPLE_UPDATE_QUEUE_H */ 0107