Krita Source Code Documentation
Loading...
Searching...
No Matches
kis_refresh_subtree_walker.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_REFRESH_SUBTREE_WALKER_H
8#define __KIS_REFRESH_SUBTREE_WALKER_H
9
10#include "kis_types.h"
12
13
14class KRITAIMAGE_EXPORT KisRefreshSubtreeWalker : public virtual KisBaseRectsWalker
15{
16public:
17 enum Flag {
18 None = 0x0,
19 SkipNonRenderableNodes = 0x1,
20 NoFilthyMode = 0x2,
21 DontAdjustChangeRect = 0x4,
22 ClonesDontInvalidateFrames = 0x8
23 };
24
26
27public:
28 KisRefreshSubtreeWalker(QRect cropRect, Flags flags = None)
29 : m_flags(flags)
30 {
31 setCropRect(cropRect);
32 setClonesDontInvalidateFrames(flags.testFlag(ClonesDontInvalidateFrames));
33 }
34
35 UpdateType type() const override {
36 return UNSUPPORTED;
37 }
38
40 {
41 }
42
43 Flags flags() const {
44 return m_flags;
45 }
46
47protected:
49
50
51 static
52 std::pair<QRect, bool>
54 const QRect &requestedRect) {
55
56 if(!startWith->isLayer())
57 return std::make_pair(requestedRect, false);
58
59 QRect finalChangeRect = requestedRect;
60 bool changeRectVaries = false;
61
62 KisProjectionLeafSP currentLeaf = startWith->firstChild();
63
64 while (currentLeaf) {
65 if (currentLeaf->isLayer() && currentLeaf->shouldBeRendered()) {
66 QRect leafRect;
67
68 std::tie(leafRect, changeRectVaries) =
69 calculateChangeRect(currentLeaf, requestedRect);
70
71 finalChangeRect |= leafRect;
72 }
73
74 currentLeaf = currentLeaf->nextSibling();
75 }
76
77 finalChangeRect |= startWith->projectionPlane()->changeRect(finalChangeRect);
78
79 if (!changeRectVaries) {
80 changeRectVaries = finalChangeRect != requestedRect;
81 }
82
83 return std::make_pair(finalChangeRect, changeRectVaries);
84 }
85
86 void startTrip(KisProjectionLeafSP startWith) override {
87 if (!m_flags.testFlag(DontAdjustChangeRect)) {
89 }
90
91 if (isStartLeaf(startWith)) {
92 KisProjectionLeafSP extraUpdateLeaf = startWith;
93
94 if (startWith->isMask()) {
103 extraUpdateLeaf = startWith->parent();
104 }
105
111 if (extraUpdateLeaf) {
112 NodePosition pos = N_EXTRA | calculateNodePosition(extraUpdateLeaf);
113 registerNeedRect(extraUpdateLeaf, pos, KisRenderPassFlag::None);
114
123 registerCloneNotification(extraUpdateLeaf->node(), pos);
124 }
125 }
126
127 SubtreeVisitFlags subtreeFlags = SubtreeVisitFlag::None;
128 if (m_flags & SkipNonRenderableNodes) {
130 }
131 if (m_flags & NoFilthyMode) {
132 subtreeFlags |= SubtreeVisitFlag::NoFilthyMode;
133 }
134
135 visitSubtreeTopToBottom(startWith, subtreeFlags, KisRenderPassFlag::None, cropRect());
136 }
137
138private:
139 Flags m_flags = None;
140};
141
142Q_DECLARE_OPERATORS_FOR_FLAGS(KisRefreshSubtreeWalker::Flags);
143
144#endif /* __KIS_REFRESH_SUBTREE_WALKER_H */
145
static NodePosition calculateNodePosition(KisProjectionLeafSP leaf)
void registerCloneNotification(KisNodeSP node, NodePosition position)
bool isStartLeaf(KisProjectionLeafSP leaf) const
void visitSubtreeTopToBottom(KisProjectionLeafSP startWith, SubtreeVisitFlags flags, KisRenderPassFlags renderFlags, const QRect &cropRect)
void setExplicitChangeRect(const QRect &changeRect, bool changeRectVaries)
void setClonesDontInvalidateFrames(bool value)
void setCropRect(QRect cropRect)
void registerNeedRect(KisProjectionLeafSP leaf, NodePosition position, KisRenderPassFlags flags)
Q_DECLARE_FLAGS(Flags, Flag)
UpdateType type() const override
void startTrip(KisProjectionLeafSP startWith) override
static std::pair< QRect, bool > calculateChangeRect(KisProjectionLeafSP startWith, const QRect &requestedRect)
KisRefreshSubtreeWalker(QRect cropRect, Flags flags=None)
Q_DECLARE_OPERATORS_FOR_FLAGS(KisRefreshSubtreeWalker::Flags)