File indexing completed on 2024-05-19 04:26:36

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     void setPostSyncLod0GUIPlaneRequestForResumeCallback(const std::function<void()> &callback);
0063     KisPostExecutionUndoAdapter* lodNPostExecutionUndoAdapter() const;
0064 
0065     /**
0066      * Notifies the queue, that someone else (neither strokes nor the
0067      * queue itself have changed the image. It means that the caches
0068      * should be regenerated
0069      */
0070     void notifyUFOChangedImage();
0071 
0072     void debugDumpAllStrokes();
0073 
0074     // interface for KisStrokeStrategy only!
0075     void addMutatedJobs(KisStrokeId id, const QVector<KisStrokeJobData*> list) final override;
0076 
0077 private:
0078     bool processOneJob(KisUpdaterContext &updaterContext,
0079                        bool externalJobsPending);
0080     bool checkStrokeState(bool hasStrokeJobsRunning,
0081                           int runningLevelOfDetail);
0082     bool checkExclusiveProperty(bool hasMergeJobs, bool hasStrokeJobs);
0083     bool checkSequentialProperty(KisUpdaterContextSnapshotEx snapshot, bool externalJobsPending);
0084     bool checkBarrierProperty(bool hasMergeJobs, bool hasStrokeJobs,
0085                               bool externalJobsPending);
0086     bool checkLevelOfDetailProperty(int runningLevelOfDetail);
0087 
0088     class LodNUndoStrokesFacade;
0089     KisStrokeId startLodNUndoStroke(KisStrokeStrategy *strokeStrategy);
0090 
0091 private:
0092     struct Private;
0093     Private * const m_d;
0094 };
0095 
0096 #endif /* __KIS_STROKES_QUEUE_H */