File indexing completed on 2024-05-12 15:58:44

0001 /*
0002  *  SPDX-FileCopyrightText: 2011 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef __KIS_STROKES_QUEUE_H
0008 #define __KIS_STROKES_QUEUE_H
0009 
0010 #include "kritaimage_export.h"
0011 #include "kundo2magicstring.h"
0012 #include "kis_types.h"
0013 #include "kis_stroke_job_strategy.h"
0014 #include "kis_stroke_strategy.h"
0015 #include "kis_stroke_strategy_factory.h"
0016 #include "kis_strokes_queue_undo_result.h"
0017 #include "KisStrokesQueueMutatedJobInterface.h"
0018 #include "KisUpdaterContextSnapshotEx.h"
0019 #include "KisLodPreferences.h"
0020 
0021 class KisUpdaterContext;
0022 class KisStroke;
0023 class KisStrokeStrategy;
0024 class KisStrokeJobData;
0025 class KisPostExecutionUndoAdapter;
0026 
0027 
0028 class KRITAIMAGE_EXPORT KisStrokesQueue : public KisStrokesQueueMutatedJobInterface
0029 {
0030 public:
0031     KisStrokesQueue();
0032     ~KisStrokesQueue();
0033 
0034     KisStrokeId startStroke(KisStrokeStrategy *strokeStrategy);
0035     void addJob(KisStrokeId id, KisStrokeJobData *data);
0036 
0037     void endStroke(KisStrokeId id);
0038     bool cancelStroke(KisStrokeId id);
0039 
0040     bool tryCancelCurrentStrokeAsync();
0041 
0042     UndoResult tryUndoLastStrokeAsync();
0043 
0044     void processQueue(KisUpdaterContext &updaterContext,
0045                       bool externalJobsPending);
0046     bool needsExclusiveAccess() const;
0047     bool isEmpty() const;
0048 
0049     qint32 sizeMetric() const;
0050     KUndo2MagicString currentStrokeName() const;
0051     bool hasOpenedStrokes() const;
0052 
0053     bool wrapAroundModeSupported() const;
0054     qreal balancingRatioOverride() const;
0055 
0056     KisLodPreferences lodPreferences() const override;
0057     void setLodPreferences(const KisLodPreferences &value);
0058     void explicitRegenerateLevelOfDetail();
0059     void setLod0ToNStrokeStrategyFactory(const KisLodSyncStrokeStrategyFactory &factory);
0060     void setSuspendResumeUpdatesStrokeStrategyFactory(const KisSuspendResumeStrategyPairFactory &factory);
0061     void setPurgeRedoStateCallback(const std::function<void()> &callback);
0062     KisPostExecutionUndoAdapter* lodNPostExecutionUndoAdapter() const;
0063 
0064     /**
0065      * Notifies the queue, that someone else (neither strokes nor the
0066      * queue itself have changed the image. It means that the caches
0067      * should be regenerated
0068      */
0069     void notifyUFOChangedImage();
0070 
0071     void debugDumpAllStrokes();
0072 
0073     // interface for KisStrokeStrategy only!
0074     void addMutatedJobs(KisStrokeId id, const QVector<KisStrokeJobData*> list) final override;
0075 
0076 private:
0077     bool processOneJob(KisUpdaterContext &updaterContext,
0078                        bool externalJobsPending);
0079     bool checkStrokeState(bool hasStrokeJobsRunning,
0080                           int runningLevelOfDetail);
0081     bool checkExclusiveProperty(bool hasMergeJobs, bool hasStrokeJobs);
0082     bool checkSequentialProperty(KisUpdaterContextSnapshotEx snapshot, bool externalJobsPending);
0083     bool checkBarrierProperty(bool hasMergeJobs, bool hasStrokeJobs,
0084                               bool externalJobsPending);
0085     bool checkLevelOfDetailProperty(int runningLevelOfDetail);
0086 
0087     class LodNUndoStrokesFacade;
0088     KisStrokeId startLodNUndoStroke(KisStrokeStrategy *strokeStrategy);
0089 
0090 private:
0091     struct Private;
0092     Private * const m_d;
0093 };
0094 
0095 #endif /* __KIS_STROKES_QUEUE_H */