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

0001 /*
0002  *  SPDX-FileCopyrightText: 2009 Dmitry Kazakov <dimula73@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #ifndef __KIS_MERGE_WALKER_H
0008 #define __KIS_MERGE_WALKER_H
0009 
0010 #include "kis_types.h"
0011 #include "kis_base_rects_walker.h"
0012 
0013 class KisMergeWalker;
0014 typedef KisSharedPtr<KisMergeWalker> KisMergeWalkerSP;
0015 
0016 class KRITAIMAGE_EXPORT KisMergeWalker : public virtual KisBaseRectsWalker
0017 {
0018 
0019 public:
0020     /**
0021      * NO_FILTHY flag notifies the walker that there should be no (!)
0022      * filthy node in the update. It means that the projection() of
0023      * the node is already guaranteed to be ready, we just need to
0024      * update all the higher-level nodes. Used by KisTransformMask
0025      * regeneration code.
0026      */
0027     enum Flags {
0028         DEFAULT = 0,
0029         NO_FILTHY
0030     };
0031 
0032     KisMergeWalker(QRect cropRect, Flags flags = DEFAULT);
0033 
0034     ~KisMergeWalker() override;
0035 
0036     UpdateType type() const override;
0037 
0038 protected:
0039     KisMergeWalker() : m_flags(DEFAULT) {}
0040     KisMergeWalker(Flags flags) : m_flags(flags) {}
0041 
0042     /**
0043      * Begins visiting nodes starting with @p startWith.
0044      * First it climbs to the top of the graph, collecting
0045      * changeRects (it calls @ref registerChangeRect for every node).
0046      * Then it goes down to the bottom collecting needRects
0047      * for every branch.
0048      */
0049     void startTrip(KisProjectionLeafSP startWith) override;
0050 
0051     using KisBaseRectsWalker::startTrip;
0052 
0053     void startTripWithMask(KisProjectionLeafSP filthyMask, KisMergeWalker::Flags flags);
0054 
0055 private:
0056     void startTripImpl(KisProjectionLeafSP startLeaf, Flags flags);
0057 
0058 private:
0059     /**
0060      * Visits a node @leaf and goes on crowling
0061      * towards the top of the graph, calling visitHigherNode() or
0062      * startTrip() one more time. After the top is reached
0063      * returns back to the @leaf.
0064      */
0065     void visitHigherNode(KisProjectionLeafSP leaf, NodePosition positionToFilthy);
0066 
0067     /**
0068      * Visits a node @leaf and goes on crowling
0069      * towards the bottom of the graph, calling visitLowerNode() or
0070      * startTrip() one more time.
0071      */
0072     void visitLowerNode(KisProjectionLeafSP leaf);
0073 
0074 private:
0075     const Flags m_flags;
0076 };
0077 
0078 
0079 #endif /* __KIS_MERGE_WALKER_H */
0080