Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
Fix more cycling updates in clone/transform-masks combinations
Dmitry Kazakovbc0757f08dc4
diff --git a/libs/image/KisRenderPassFlags.h b/libs/image/KisRenderPassFlags.hnew file mode 100644index 0000000000..d24dfee926--- /dev/null+++ b/libs/image/KisRenderPassFlags.h@@ -0,0 +1,17 @@+/*+ * SPDX-FileCopyrightText: 2024 Dmitry Kazakov <[email protected]>+ *+ * SPDX-License-Identifier: GPL-2.0-or-later+ */+#ifndef KISRENDERPASSFLAGS_H+#define KISRENDERPASSFLAGS_H++enum class KisRenderPassFlag+{+ None = 0x0,+ NoTransformMaskUpdates = 0x1+};+Q_DECLARE_FLAGS(KisRenderPassFlags, KisRenderPassFlag)+Q_DECLARE_OPERATORS_FOR_FLAGS(KisRenderPassFlags)++#endif // KISRENDERPASSFLAGS_Hdiff --git a/libs/image/kis_abstract_projection_plane.cpp b/libs/image/kis_abstract_projection_plane.cppindex 6552fa837d..6432014f0a 100644--- a/libs/image/kis_abstract_projection_plane.cpp+++ b/libs/image/kis_abstract_projection_plane.cpp@@ -15,9 +15,10 @@ KisAbstractProjectionPlane::~KisAbstractProjectionPlane(){}-QRect KisDumbProjectionPlane::recalculate(const QRect& rect, KisNodeSP filthyNode)+QRect KisDumbProjectionPlane::recalculate(const QRect& rect, KisNodeSP filthyNode, KisRenderPassFlags flags){Q_UNUSED(filthyNode);+ Q_UNUSED(flags);return rect;}diff --git a/libs/image/kis_abstract_projection_plane.h b/libs/image/kis_abstract_projection_plane.hindex 7684190cdd..87d8eb50c8 100644--- a/libs/image/kis_abstract_projection_plane.h+++ b/libs/image/kis_abstract_projection_plane.h@@ -41,7 +41,7 @@ public:* should recalculate its internal representation. For usual* layers it means just calling updateProjection().*/- virtual QRect recalculate(const QRect& rect, KisNodeSP filthyNode) = 0;+ virtual QRect recalculate(const QRect& rect, KisNodeSP filthyNode, KisRenderPassFlags flags) = 0;/*** Writes the data of the projection plane onto a global@@ -93,7 +93,7 @@ public:class KisDumbProjectionPlane : public KisAbstractProjectionPlane{public:- QRect recalculate(const QRect& rect, KisNodeSP filthyNode) override;+ QRect recalculate(const QRect& rect, KisNodeSP filthyNode, KisRenderPassFlags flags) override;void apply(KisPainter *painter, const QRect &rect) override;QRect needRect(const QRect &rect, KisLayer::PositionToFilthy pos) const override;diff --git a/libs/image/kis_async_merger.cpp b/libs/image/kis_async_merger.cppindex 840fa8cee8..7f7c48b020 100644--- a/libs/image/kis_async_merger.cpp+++ b/libs/image/kis_async_merger.cpp@@ -48,10 +48,11 @@class KisUpdateOriginalVisitor : public KisNodeVisitor{public:- KisUpdateOriginalVisitor(const QRect &updateRect, KisPaintDeviceSP projection, const QRect &cropRect)+ KisUpdateOriginalVisitor(const QRect &updateRect, KisPaintDeviceSP projection, const QRect &cropRect, KisRenderPassFlags flags): m_updateRect(updateRect),m_cropRect(cropRect),- m_projection(projection)+ m_projection(projection),+ m_parentFlags(flags){}@@ -140,8 +141,9 @@ public:bool visit(KisCloneLayer *layer) override {QRect emptyRect;- KisRefreshSubtreeWalker walker(emptyRect);+ KisRefreshSubtreeWalker walker(emptyRect, KisRefreshSubtreeWalker::NoFilthyMode);KisAsyncMerger merger;+ merger.setRenderFlags(m_parentFlags | KisRenderPassFlag::NoTransformMaskUpdates);KisLayerSP srcLayer = layer->copyFrom();QRect srcRect = m_updateRect.translated(-layer->x(), -layer->y());@@ -195,6 +197,7 @@ private:QRect m_updateRect;QRect m_cropRect;KisPaintDeviceSP m_projection;+ KisRenderPassFlags m_parentFlags;};@@ -225,7 +228,7 @@ void KisAsyncMerger::startMerge(KisBaseRectsWalker &walker, bool notifyClones) {QRect applyRect = item.m_applyRect;if (currentLeaf->isRoot()) {- currentLeaf->projectionPlane()->recalculate(applyRect, walker.startNode());+ currentLeaf->projectionPlane()->recalculate(applyRect, walker.startNode(), m_renderFlags);continue;}@@ -235,9 +238,10 @@ void KisAsyncMerger::startMerge(KisBaseRectsWalker &walker, bool notifyClones) {DEBUG_NODE_ACTION("Updating", "N_EXTRA", currentLeaf, applyRect);KisUpdateOriginalVisitor originalVisitor(applyRect,m_currentProjection,- walker.cropRect());+ walker.cropRect(),+ m_renderFlags);currentLeaf->accept(originalVisitor);- currentLeaf->projectionPlane()->recalculate(applyRect, currentLeaf->node());+ currentLeaf->projectionPlane()->recalculate(applyRect, currentLeaf->node(), m_renderFlags);continue;}@@ -249,13 +253,14 @@ void KisAsyncMerger::startMerge(KisBaseRectsWalker &walker, bool notifyClones) {KisUpdateOriginalVisitor originalVisitor(applyRect,m_currentProjection,- walker.cropRect());+ walker.cropRect(),+ m_renderFlags);if(item.m_position & KisMergeWalker::N_FILTHY) {DEBUG_NODE_ACTION("Updating", "N_FILTHY", currentLeaf, applyRect);if (currentLeaf->shouldBeRendered()) {currentLeaf->accept(originalVisitor);- currentLeaf->projectionPlane()->recalculate(applyRect, walker.startNode());+ currentLeaf->projectionPlane()->recalculate(applyRect, walker.startNode(), m_renderFlags);}}else if(item.m_position & KisMergeWalker::N_ABOVE_FILTHY) {@@ -263,14 +268,14 @@ void KisAsyncMerger::startMerge(KisBaseRectsWalker &walker, bool notifyClones) {if(currentLeaf->dependsOnLowerNodes()) {if (currentLeaf->shouldBeRendered()) {currentLeaf->accept(originalVisitor);- currentLeaf->projectionPlane()->recalculate(applyRect, currentLeaf->node());+ currentLeaf->projectionPlane()->recalculate(applyRect, currentLeaf->node(), m_renderFlags);}}}else if(item.m_position & KisMergeWalker::N_FILTHY_PROJECTION) {DEBUG_NODE_ACTION("Updating", "N_FILTHY_PROJECTION", currentLeaf, applyRect);if (currentLeaf->shouldBeRendered()) {- currentLeaf->projectionPlane()->recalculate(applyRect, walker.startNode());+ currentLeaf->projectionPlane()->recalculate(applyRect, walker.startNode(), m_renderFlags);}}else /*if(item.m_position & KisMergeWalker::N_BELOW_FILTHY)*/ {@@ -370,3 +375,13 @@ void KisAsyncMerger::doNotifyClones(KisBaseRectsWalker &walker) {(*it).notify();}}++KisRenderPassFlags KisAsyncMerger::renderFlags() const+{+ return m_renderFlags;+}++void KisAsyncMerger::setRenderFlags(const KisRenderPassFlags &newRenderFlags)+{+ m_renderFlags = newRenderFlags;+}diff --git a/libs/image/kis_async_merger.h b/libs/image/kis_async_merger.hindex f3ee86b4a0..d325923481 100644--- a/libs/image/kis_async_merger.h+++ b/libs/image/kis_async_merger.h@@ -8,6 +8,7 @@#include "kritaimage_export.h"#include "kis_types.h"+#include "KisRenderPassFlags.h"class QRect;class KisBaseRectsWalker;@@ -17,6 +18,9 @@ class KRITAIMAGE_EXPORT KisAsyncMergerpublic:void startMerge(KisBaseRectsWalker &walker, bool notifyClones = true);+ KisRenderPassFlags renderFlags() const;+ void setRenderFlags(const KisRenderPassFlags &newRenderFlags);+private:inline void resetProjection();inline void setupProjection(KisProjectionLeafSP currentLeaf, const QRect& rect, bool useTempProjection);@@ -49,6 +53,11 @@ private:* setupProjection()*/KisPaintDeviceSP m_cachedPaintDevice;++ /**+ * The flags that should be used while rendering process+ */+ KisRenderPassFlags m_renderFlags = KisRenderPassFlag::None;};diff --git a/libs/image/kis_filter_mask.cpp b/libs/image/kis_filter_mask.cppindex 12cae73a17..b39ada3ad3 100644--- a/libs/image/kis_filter_mask.cpp+++ b/libs/image/kis_filter_mask.cpp@@ -52,9 +52,11 @@ void KisFilterMask::setFilter(KisFilterConfigurationSP filterConfig, bool checkQRect KisFilterMask::decorateRect(KisPaintDeviceSP &src,KisPaintDeviceSP &dst,const QRect & rc,- PositionToFilthy maskPos) const+ PositionToFilthy maskPos,+ KisRenderPassFlags flags) const{Q_UNUSED(maskPos);+ Q_UNUSED(flags);KisFilterConfigurationSP filterConfig = filter();diff --git a/libs/image/kis_filter_mask.h b/libs/image/kis_filter_mask.hindex 0162a0602a..64d1c3fa63 100644--- a/libs/image/kis_filter_mask.h+++ b/libs/image/kis_filter_mask.h@@ -49,7 +49,8 @@ public:QRect decorateRect(KisPaintDeviceSP &src,KisPaintDeviceSP &dst,const QRect & rc,- PositionToFilthy maskPos) const override;+ PositionToFilthy maskPos,+ KisRenderPassFlags flags) const override;QRect changeRect(const QRect &rect, PositionToFilthy pos = N_FILTHY) const override;QRect needRect(const QRect &rect, PositionToFilthy pos = N_FILTHY) const override;diff --git a/libs/image/kis_layer.cc b/libs/image/kis_layer.ccindex f5f26f17d1..a9b88fc4af 100644--- a/libs/image/kis_layer.cc+++ b/libs/image/kis_layer.cc@@ -637,7 +637,8 @@ QRect KisLayer::applyMasks(const KisPaintDeviceSP source,KisPaintDeviceSP destination,const QRect &requestedRect,KisNodeSP filthyNode,- KisNodeSP lastNode) const+ KisNodeSP lastNode,+ KisRenderPassFlags flags) const{Q_ASSERT(source);Q_ASSERT(destination);@@ -687,7 +688,7 @@ QRect KisLayer::applyMasks(const KisPaintDeviceSP source,applyRects.isEmpty() ? needRect : applyRects.top();PositionToFilthy maskPosition = calculatePositionToFilthy(mask, filthyNode, const_cast<KisLayer*>(this));- mask->apply(destination, maskApplyRect, maskNeedRect, maskPosition);+ mask->apply(destination, maskApplyRect, maskNeedRect, maskPosition, flags);}Q_ASSERT(applyRects.isEmpty());} else {@@ -706,7 +707,7 @@ QRect KisLayer::applyMasks(const KisPaintDeviceSP source,Q_FOREACH (const KisEffectMaskSP& mask, masks) {PositionToFilthy maskPosition = calculatePositionToFilthy(mask, filthyNode, const_cast<KisLayer*>(this));- mask->apply(tempDevice, maskApplyRect, maskNeedRect, maskPosition);+ mask->apply(tempDevice, maskApplyRect, maskNeedRect, maskPosition, flags);if (!applyRects.isEmpty()) {maskNeedRect = maskApplyRect;@@ -722,7 +723,7 @@ QRect KisLayer::applyMasks(const KisPaintDeviceSP source,return changeRect;}-QRect KisLayer::updateProjection(const QRect& rect, KisNodeSP filthyNode)+QRect KisLayer::updateProjection(const QRect& rect, KisNodeSP filthyNode, KisRenderPassFlags flags){QRect updatedRect = rect;KisPaintDeviceSP originalDevice = original();@@ -737,7 +738,7 @@ QRect KisLayer::updateProjection(const QRect& rect, KisNodeSP filthyNode)if (!updatedRect.isEmpty()) {KisPaintDeviceSP projection = m_d->safeProjection->getDeviceLazy(originalDevice);updatedRect = applyMasks(originalDevice, projection,- updatedRect, filthyNode, 0);+ updatedRect, filthyNode, 0, flags);}}@@ -767,7 +768,7 @@ void KisLayer::buildProjectionUpToNode(KisPaintDeviceSP projection, KisNodeSP laif (!changeRect.isEmpty()) {applyMasks(originalDevice, projection,- changeRect, this, lastNode);+ changeRect, this, lastNode, KisRenderPassFlag::NoTransformMaskUpdates);}}diff --git a/libs/image/kis_layer.h b/libs/image/kis_layer.hindex 918d99581a..5a38b22c54 100644--- a/libs/image/kis_layer.h+++ b/libs/image/kis_layer.h@@ -21,6 +21,8 @@#include "kis_node.h"#include "kis_psd_layer_style.h"+#include "KisRenderPassFlags.h"+template <class T>class QStack;@@ -293,7 +295,7 @@ protected:* Ask the layer to assemble its data & apply all the effect masks* to it.*/- QRect updateProjection(const QRect& rect, KisNodeSP filthyNode);+ QRect updateProjection(const QRect& rect, KisNodeSP filthyNode, KisRenderPassFlags flags);/*** Layers can override this method to get some special behavior@@ -398,7 +400,9 @@ protected:QRect applyMasks(const KisPaintDeviceSP source,KisPaintDeviceSP destination,const QRect &requestedRect,- KisNodeSP filthyNode, KisNodeSP lastNode) const;+ KisNodeSP filthyNode,+ KisNodeSP lastNode,+ KisRenderPassFlags flags) const;bool canMergeAndKeepBlendOptions(KisLayerSP otherLayer);diff --git a/libs/image/kis_layer_projection_plane.cpp b/libs/image/kis_layer_projection_plane.cppindex 6ca7d7cc69..b465a8b864 100644--- a/libs/image/kis_layer_projection_plane.cpp+++ b/libs/image/kis_layer_projection_plane.cpp@@ -33,9 +33,9 @@ KisLayerProjectionPlane::~KisLayerProjectionPlane(){}-QRect KisLayerProjectionPlane::recalculate(const QRect& rect, KisNodeSP filthyNode)+QRect KisLayerProjectionPlane::recalculate(const QRect& rect, KisNodeSP filthyNode, KisRenderPassFlags flags){- return m_d->layer->updateProjection(rect, filthyNode);+ return m_d->layer->updateProjection(rect, filthyNode, flags);}void KisLayerProjectionPlane::applyImpl(KisPainter *painter, const QRect &rect, KritaUtils::ThresholdMode thresholdMode)diff --git a/libs/image/kis_layer_projection_plane.h b/libs/image/kis_layer_projection_plane.hindex 49bc8f97e0..ddfa3b955d 100644--- a/libs/image/kis_layer_projection_plane.h+++ b/libs/image/kis_layer_projection_plane.h@@ -22,7 +22,7 @@ public:KisLayerProjectionPlane(KisLayer *layer);~KisLayerProjectionPlane() override;- QRect recalculate(const QRect& rect, KisNodeSP filthyNode) override;+ QRect recalculate(const QRect& rect, KisNodeSP filthyNode, KisRenderPassFlags flags) override;void apply(KisPainter *painter, const QRect &rect) override;void applyMaxOutAlpha(KisPainter *painter, const QRect &rect, KritaUtils::ThresholdMode thresholdMode);diff --git a/libs/image/kis_mask.cc b/libs/image/kis_mask.ccindex 9d9c6195c1..478b381bfe 100644--- a/libs/image/kis_mask.cc+++ b/libs/image/kis_mask.cc@@ -270,11 +270,13 @@ void KisMask::select(const QRect & rc, quint8 selectedness)QRect KisMask::decorateRect(KisPaintDeviceSP &src,KisPaintDeviceSP &dst,const QRect & rc,- PositionToFilthy maskPos) const+ PositionToFilthy maskPos,+ KisRenderPassFlags flags) const{Q_UNUSED(src);Q_UNUSED(dst);Q_UNUSED(maskPos);+ Q_UNUSED(flags);Q_ASSERT_X(0, "KisMask::decorateRect", "Should be overridden by successors");return rc;}@@ -284,7 +286,7 @@ bool KisMask::paintsOutsideSelection() constreturn false;}-void KisMask::apply(KisPaintDeviceSP projection, const QRect &applyRect, const QRect &needRect, PositionToFilthy maskPos) const+void KisMask::apply(KisPaintDeviceSP projection, const QRect &applyRect, const QRect &needRect, PositionToFilthy maskPos, KisRenderPassFlags flags) const{if (selection()) {@@ -324,11 +326,11 @@ void KisMask::apply(KisPaintDeviceSP projection, const QRect &applyRect, const Qm_d->safeProjection->releaseDevice();}- mergeInMaskInternal(projection, effectiveSelection, applyRect, needRect, maskPos);+ mergeInMaskInternal(projection, effectiveSelection, applyRect, needRect, maskPos, flags);}} else {- mergeInMaskInternal(projection, 0, applyRect, needRect, maskPos);+ mergeInMaskInternal(projection, 0, applyRect, needRect, maskPos, flags);}}@@ -336,13 +338,14 @@ void KisMask::mergeInMaskInternal(KisPaintDeviceSP projection,KisSelectionSP effectiveSelection,const QRect &applyRect,const QRect &preparedNeedRect,- KisNode::PositionToFilthy maskPos) const+ KisNode::PositionToFilthy maskPos,+ KisRenderPassFlags flags) const{KisCachedPaintDevice::Guard d1(projection, m_d->paintDeviceCache);KisPaintDeviceSP cacheDevice = d1.device();if (effectiveSelection) {- QRect updatedRect = decorateRect(projection, cacheDevice, applyRect, maskPos);+ QRect updatedRect = decorateRect(projection, cacheDevice, applyRect, maskPos, flags);// masks don't have any compositingKisPainter::copyAreaOptimized(updatedRect.topLeft(), cacheDevice, projection, updatedRect, effectiveSelection);@@ -351,7 +354,7 @@ void KisMask::mergeInMaskInternal(KisPaintDeviceSP projection,cacheDevice->makeCloneFromRough(projection, preparedNeedRect);projection->clear(preparedNeedRect);- decorateRect(cacheDevice, projection, applyRect, maskPos);+ decorateRect(cacheDevice, projection, applyRect, maskPos, flags);}}diff --git a/libs/image/kis_mask.h b/libs/image/kis_mask.hindex f9aaa1749c..c94730be23 100644--- a/libs/image/kis_mask.h+++ b/libs/image/kis_mask.h@@ -14,6 +14,7 @@#include "kis_global.h"#include "kis_node.h"#include "kis_indirect_painting_support.h"+#include "KisRenderPassFlags.h"#include <kritaimage_export.h>@@ -187,12 +188,13 @@ protected:* Apply the effect the projection using the mask as a selection.* Made public in KisEffectMask*/- void apply(KisPaintDeviceSP projection, const QRect & applyRect, const QRect & needRect, PositionToFilthy maskPos) const;+ void apply(KisPaintDeviceSP projection, const QRect & applyRect, const QRect & needRect, PositionToFilthy maskPos, KisRenderPassFlags flags) const;virtual void mergeInMaskInternal(KisPaintDeviceSP projection,KisSelectionSP effectiveSelection,const QRect &applyRect, const QRect &preparedNeedRect,- PositionToFilthy maskPos) const;+ PositionToFilthy maskPos,+ KisRenderPassFlags flags) const;/*** A special callback for calling selection->updateProjection() during@@ -204,7 +206,8 @@ protected:virtual QRect decorateRect(KisPaintDeviceSP &src,KisPaintDeviceSP &dst,const QRect & rc,- PositionToFilthy maskPos) const;+ PositionToFilthy maskPos,+ KisRenderPassFlags flags) const;virtual bool paintsOutsideSelection() const;diff --git a/libs/image/kis_mask_projection_plane.cpp b/libs/image/kis_mask_projection_plane.cppindex 13b42c33f7..2652346cb3 100644--- a/libs/image/kis_mask_projection_plane.cpp+++ b/libs/image/kis_mask_projection_plane.cpp@@ -29,9 +29,10 @@ KisMaskProjectionPlane::~KisMaskProjectionPlane(){}-QRect KisMaskProjectionPlane::recalculate(const QRect& rect, KisNodeSP filthyNode)+QRect KisMaskProjectionPlane::recalculate(const QRect& rect, KisNodeSP filthyNode, KisRenderPassFlags flags){Q_UNUSED(filthyNode);+ Q_UNUSED(flags);KIS_ASSERT_RECOVER_NOOP(0 && "KisMaskProjectionPlane::recalculate() is not defined!");diff --git a/libs/image/kis_mask_projection_plane.h b/libs/image/kis_mask_projection_plane.hindex 102a134591..3e066ea9e8 100644--- a/libs/image/kis_mask_projection_plane.h+++ b/libs/image/kis_mask_projection_plane.h@@ -25,7 +25,7 @@ public:KisMaskProjectionPlane(KisMask *mask);~KisMaskProjectionPlane() override;- QRect recalculate(const QRect& rect, KisNodeSP filthyNode) override;+ QRect recalculate(const QRect& rect, KisNodeSP filthyNode, KisRenderPassFlags flags) override;void apply(KisPainter *painter, const QRect &rect) override;QRect needRect(const QRect &rect, KisNode::PositionToFilthy pos) const override;diff --git a/libs/image/kis_selection_mask.cpp b/libs/image/kis_selection_mask.cppindex b0e3c83a12..b524470e4d 100644--- a/libs/image/kis_selection_mask.cpp+++ b/libs/image/kis_selection_mask.cpp@@ -91,10 +91,13 @@ void KisSelectionMask::mergeInMaskInternal(KisPaintDeviceSP projection,KisSelectionSP effectiveSelection,const QRect &applyRect,const QRect &preparedNeedRect,- KisNode::PositionToFilthy maskPos) const+ KisNode::PositionToFilthy maskPos,+ KisRenderPassFlags flags) const{Q_UNUSED(maskPos);Q_UNUSED(preparedNeedRect);+ Q_UNUSED(flags);+if (!effectiveSelection) return;{diff --git a/libs/image/kis_selection_mask.h b/libs/image/kis_selection_mask.hindex d3ef1bbe13..8a8005a04f 100644--- a/libs/image/kis_selection_mask.h+++ b/libs/image/kis_selection_mask.h@@ -78,7 +78,7 @@ protected:void mergeInMaskInternal(KisPaintDeviceSP projection,KisSelectionSP effectiveSelection,const QRect &applyRect, const QRect &preparedNeedRect,- KisNode::PositionToFilthy maskPos) const override;+ KisNode::PositionToFilthy maskPos, KisRenderPassFlags flags) const override;bool paintsOutsideSelection() const override;diff --git a/libs/image/kis_transform_mask.cpp b/libs/image/kis_transform_mask.cppindex 7e8d1f7421..583a7eab44 100644--- a/libs/image/kis_transform_mask.cpp+++ b/libs/image/kis_transform_mask.cpp@@ -434,14 +434,15 @@ void KisTransformMask::recalculateStaticImage()* the layer and after that a special update call (no-filthy) will* be issued to pass the changed further through the stack.*/- parentLayer->updateProjection(requestedRect, this);+ parentLayer->updateProjection(requestedRect, this, KisRenderPassFlag::NoTransformMaskUpdates);m_d->recalculatingStaticImage = false;}QRect KisTransformMask::decorateRect(KisPaintDeviceSP &src,KisPaintDeviceSP &dst,const QRect & rc,- PositionToFilthy maskPos) const+ PositionToFilthy maskPos,+ KisRenderPassFlags flags) const{Q_ASSERT_X(src != dst, "KisTransformMask::decorateRect","src must be != dst, because we can't create transactions "@@ -486,7 +487,7 @@ QRect KisTransformMask::decorateRect(KisPaintDeviceSP &src,/// clone layers may fetch data outside image bounds,/// that should never cause async refresh, since it will/// cause an infinite loop- m_d->paramsHolder->defaultBounds()->imageBorderRect().intersects(rc)) {+ !flags.testFlag(KisRenderPassFlag::NoTransformMaskUpdates)) {if (m_d->testingInterface) {m_d->testingInterface->notifyDecorateRectTriggeredStaticImageUpdate();diff --git a/libs/image/kis_transform_mask.h b/libs/image/kis_transform_mask.hindex 2f80d7fa04..e6d76f3496 100644--- a/libs/image/kis_transform_mask.h+++ b/libs/image/kis_transform_mask.h@@ -47,7 +47,8 @@ public:QRect decorateRect(KisPaintDeviceSP &src,KisPaintDeviceSP &dst,const QRect & rc,- PositionToFilthy maskPos) const override;+ PositionToFilthy maskPos,+ KisRenderPassFlags flags) const override;QRect changeRect(const QRect &rect, PositionToFilthy pos = N_FILTHY) const override;QRect needRect(const QRect &rect, PositionToFilthy pos = N_FILTHY) const override;diff --git a/libs/image/kis_transparency_mask.cc b/libs/image/kis_transparency_mask.ccindex beb1840025..54aa24e443 100644--- a/libs/image/kis_transparency_mask.cc+++ b/libs/image/kis_transparency_mask.cc@@ -36,9 +36,11 @@ KisTransparencyMask::~KisTransparencyMask()QRect KisTransparencyMask::decorateRect(KisPaintDeviceSP &src,KisPaintDeviceSP &dst,const QRect & rc,- PositionToFilthy maskPos) const+ PositionToFilthy maskPos,+ KisRenderPassFlags flags) const{Q_UNUSED(maskPos);+ Q_UNUSED(flags);if (src != dst) {KisPainter::copyAreaOptimized(rc.topLeft(), src, dst, rc);diff --git a/libs/image/kis_transparency_mask.h b/libs/image/kis_transparency_mask.hindex 12ea3afa1e..792af8b57d 100644--- a/libs/image/kis_transparency_mask.h+++ b/libs/image/kis_transparency_mask.h@@ -37,7 +37,8 @@ public:QRect decorateRect(KisPaintDeviceSP &src, KisPaintDeviceSP &dst,const QRect & rc,- PositionToFilthy maskPos) const override;+ PositionToFilthy maskPos,+ KisRenderPassFlags flags) const override;QIcon icon() const override;bool accept(KisNodeVisitor &v) override;void accept(KisProcessingVisitor &visitor, KisUndoAdapter *undoAdapter) override;diff --git a/libs/image/layerstyles/kis_layer_style_filter_projection_plane.cpp b/libs/image/layerstyles/kis_layer_style_filter_projection_plane.cppindex be56a15547..133ee9666f 100644--- a/libs/image/layerstyles/kis_layer_style_filter_projection_plane.cpp+++ b/libs/image/layerstyles/kis_layer_style_filter_projection_plane.cpp@@ -71,9 +71,10 @@ void KisLayerStyleFilterProjectionPlane::setStyle(KisLayerStyleFilter *filter, Km_d->style = style;}-QRect KisLayerStyleFilterProjectionPlane::recalculate(const QRect& rect, KisNodeSP filthyNode)+QRect KisLayerStyleFilterProjectionPlane::recalculate(const QRect& rect, KisNodeSP filthyNode, KisRenderPassFlags flags){Q_UNUSED(filthyNode);+ Q_UNUSED(flags);if (!m_d->sourceLayer || !m_d->filter) {warnKrita << "KisLayerStyleFilterProjectionPlane::recalculate(): [BUG] is not initialized";diff --git a/libs/image/layerstyles/kis_layer_style_filter_projection_plane.h b/libs/image/layerstyles/kis_layer_style_filter_projection_plane.hindex 6c76a6c0d9..0a38054877 100644--- a/libs/image/layerstyles/kis_layer_style_filter_projection_plane.h+++ b/libs/image/layerstyles/kis_layer_style_filter_projection_plane.h@@ -25,7 +25,7 @@ public:void setStyle(KisLayerStyleFilter *filter, KisPSDLayerStyleSP style);- QRect recalculate(const QRect& rect, KisNodeSP filthyNode) override;+ QRect recalculate(const QRect& rect, KisNodeSP filthyNode, KisRenderPassFlags flags) override;void apply(KisPainter *painter, const QRect &rect) override;QRect needRect(const QRect &rect, KisLayer::PositionToFilthy pos) const override;diff --git a/libs/image/layerstyles/kis_layer_style_projection_plane.cpp b/libs/image/layerstyles/kis_layer_style_projection_plane.cppindex c3d7c18460..0a02a4ff36 100644--- a/libs/image/layerstyles/kis_layer_style_projection_plane.cpp+++ b/libs/image/layerstyles/kis_layer_style_projection_plane.cpp@@ -218,19 +218,19 @@ KisAbstractProjectionPlaneSP KisLayerStyleProjectionPlane::factoryObject(KisLayereturn toQShared(new KisLayerStyleProjectionPlane(sourceLayer));}-QRect KisLayerStyleProjectionPlane::recalculate(const QRect& rect, KisNodeSP filthyNode)+QRect KisLayerStyleProjectionPlane::recalculate(const QRect& rect, KisNodeSP filthyNode, KisRenderPassFlags flags){KisAbstractProjectionPlaneSP sourcePlane = m_d->sourceProjectionPlane.toStrongRef();QRect result = rect;if (m_d->style->isEnabled()) {- result = sourcePlane->recalculate(stylesNeedRect(rect), filthyNode);+ result = sourcePlane->recalculate(stylesNeedRect(rect), filthyNode, flags);Q_FOREACH (const KisAbstractProjectionPlaneSP plane, m_d->allStyles()) {- plane->recalculate(rect, filthyNode);+ plane->recalculate(rect, filthyNode, flags);}} else {- result = sourcePlane->recalculate(rect, filthyNode);+ result = sourcePlane->recalculate(rect, filthyNode, flags);}return result;diff --git a/libs/image/layerstyles/kis_layer_style_projection_plane.h b/libs/image/layerstyles/kis_layer_style_projection_plane.hindex 35cc8cd001..58b2c6b488 100644--- a/libs/image/layerstyles/kis_layer_style_projection_plane.h+++ b/libs/image/layerstyles/kis_layer_style_projection_plane.h@@ -24,7 +24,7 @@ public:~KisLayerStyleProjectionPlane() override;- QRect recalculate(const QRect& rect, KisNodeSP filthyNode) override;+ QRect recalculate(const QRect& rect, KisNodeSP filthyNode, KisRenderPassFlags flags) override;void apply(KisPainter *painter, const QRect &rect) override;QRect needRect(const QRect &rect, KisLayer::PositionToFilthy pos) const override;diff --git a/libs/image/lazybrush/kis_colorize_mask.cpp b/libs/image/lazybrush/kis_colorize_mask.cppindex 1cbd3ce0cd..93203b6f34 100644--- a/libs/image/lazybrush/kis_colorize_mask.cpp+++ b/libs/image/lazybrush/kis_colorize_mask.cpp@@ -513,9 +513,11 @@ bool KisColorizeMask::Private::shouldShowColoring() constQRect KisColorizeMask::decorateRect(KisPaintDeviceSP &src,KisPaintDeviceSP &dst,const QRect &rect,- PositionToFilthy maskPos) const+ PositionToFilthy maskPos,+ KisRenderPassFlags flags) const{Q_UNUSED(maskPos);+ Q_UNUSED(flags);if (maskPos == N_ABOVE_FILTHY) {// the source layer has changed, we should update the filtered cache!diff --git a/libs/image/lazybrush/kis_colorize_mask.h b/libs/image/lazybrush/kis_colorize_mask.hindex 196d563650..c72c58003f 100644--- a/libs/image/lazybrush/kis_colorize_mask.h+++ b/libs/image/lazybrush/kis_colorize_mask.h@@ -67,7 +67,8 @@ public:QRect decorateRect(KisPaintDeviceSP &src,KisPaintDeviceSP &dst,const QRect & rc,- PositionToFilthy maskPos) const override;+ PositionToFilthy maskPos,+ KisRenderPassFlags flags) const override;void setCurrentColor(const KoColor &color) override;void mergeToLayerThreaded(KisNodeSP layer, KUndo2Command *parentCommand, const KUndo2MagicString &transactionText, int timedID, QVector<KisRunnableStrokeJobData *> *jobs) override;diff --git a/libs/image/tests/data/clone_layer_test/tmask_x2_source_00_initial.png b/libs/image/tests/data/clone_layer_test/tmask_x2_source_00_initial.pngnew file mode 100644index 0000000000..19c27cdf38Binary files /dev/null and b/libs/image/tests/data/clone_layer_test/tmask_x2_source_00_initial.png differdiff --git a/libs/image/tests/data/clone_layer_test/tmask_x2_source_10_transform_mask_initial_static.png b/libs/image/tests/data/clone_layer_test/tmask_x2_source_10_transform_mask_initial_static.pngnew file mode 100644index 0000000000..19c27cdf38Binary files /dev/null and b/libs/image/tests/data/clone_layer_test/tmask_x2_source_10_transform_mask_initial_static.png differdiff --git a/libs/image/tests/data/clone_layer_test/tmask_x2_source_20_final.png b/libs/image/tests/data/clone_layer_test/tmask_x2_source_20_final.pngnew file mode 100644index 0000000000..19c27cdf38Binary files /dev/null and b/libs/image/tests/data/clone_layer_test/tmask_x2_source_20_final.png differdiff --git a/libs/image/tests/kis_clone_layer_test.cpp b/libs/image/tests/kis_clone_layer_test.cppindex 66c324ca91..39378e417a 100644--- a/libs/image/tests/kis_clone_layer_test.cpp+++ b/libs/image/tests/kis_clone_layer_test.cpp@@ -487,8 +487,122 @@ void KisCloneLayerTest::testWithSourceUnderTransformMask()"clone_layer_test","tmask_source","20_final"));+}++void KisCloneLayerTest::testWithSourceUnderTwoTransformMasks()+{+ /*+ +--------------------++ |root |+ | clone_of_p1 -+ |+ | paint 2 | |+ | paint 1 <-+ |+ | transf2 (offset)|+ | transf1 (scale) |+ +--------------------++ */++ const KoColorSpace *colorSpace = KoColorSpaceRegistry::instance()->rgb8();+ KisImageSP image = new KisImage(0, 128, 128, colorSpace, "clones test");++ KisPaintDeviceSP device1 = new KisPaintDevice(colorSpace);+ device1->fill(QRect(10,10,100,100), KoColor( Qt::white, colorSpace));+ KisLayerSP paintLayer1 = new KisPaintLayer(image, "paint1", OPACITY_OPAQUE_U8, device1);+ image->addNode(paintLayer1, image->root());++ KisTransformMaskTestingListener *listener1 = new KisTransformMaskTestingListener();+ QTransform transform1 = QTransform::fromScale(0.1, 0.2);+ KisTransformMaskSP transf1 = new KisTransformMask(image, "transf1");+ image->addNode(transf1, paintLayer1);+ transf1->setTransformParams(KisTransformMaskParamsInterfaceSP(+ new KisDumbTransformMaskParams(transform1)));+ transf1->setTestingInterface(listener1);++ /**+ * An additional offset in `transf2` makes the "hidden area+ * generation" on the clone to cause a dirty request inside+ * the image bounds on the transform mask `transf1`, which+ * causes an async update, and, hence infinite cycle.+ */++ KisTransformMaskTestingListener *listener2 = new KisTransformMaskTestingListener();+ QTransform transform2 = QTransform::fromTranslate(-3, -3);+ KisTransformMaskSP transf2 = new KisTransformMask(image, "transf2");+ image->addNode(transf2, paintLayer1);+ transf2->setTransformParams(KisTransformMaskParamsInterfaceSP(+ new KisDumbTransformMaskParams(transform2)));+ transf2->setTestingInterface(listener2);++ KisPaintDeviceSP device2 = new KisPaintDevice(colorSpace);+ device2->fill(QRect(20, 20, 10, 10), KoColor( Qt::red, colorSpace));+ KisLayerSP paintLayer2 = new KisPaintLayer(image, "paint2", OPACITY_OPAQUE_U8, device2);+ image->addNode(paintLayer2, image->root());++ KisLayerSP cloneLayer1 = new KisCloneLayer(paintLayer1, image, "clone_of_p1", OPACITY_OPAQUE_U8);+ cloneLayer1->setX(10);+ cloneLayer1->setY(10);+ image->addNode(cloneLayer1, image->root());++ image->initialRefreshGraph();+ QTest::qWait(50);+ image->waitForDone();++ QVERIFY(TestUtil::checkQImage(+ image->projection()->convertToQImage(nullptr, image->bounds()),+ "clone_layer_test",+ "tmask_x2_source",+ "00_initial"));+ transf1->forceUpdateTimedNode();+ transf2->forceUpdateTimedNode();+ QTest::qWait(50);+ image->waitForDone();+ QTest::qWait(50);+ image->waitForDone();++ QVERIFY(!transf1->hasPendingTimedUpdates());+ QVERIFY(!transf2->hasPendingTimedUpdates());++ {+ auto stat = listener1->stats();+ listener1->clear();++ QVERIFY(stat.decorateRectTriggeredStaticImageUpdate > 0);+ QCOMPARE(stat.forceUpdateTimedNode, 1);+ QCOMPARE(stat.slotDelayedStaticImageUpdate, 0);+ QCOMPARE(stat.recalculateStaticImage, 1);+ }++ QVERIFY(TestUtil::checkQImage(+ image->projection()->convertToQImage(nullptr, image->bounds()),+ "clone_layer_test",+ "tmask_x2_source",+ "10_transform_mask_initial_static"));+ cloneLayer1->setDirty();+ QTest::qWait(50);+ image->waitForDone();+ QTest::qWait(50);+ image->waitForDone();++ QVERIFY(!transf1->hasPendingTimedUpdates());+ QVERIFY(!transf2->hasPendingTimedUpdates());++ {+ auto stat = listener1->stats();+ listener1->clear();++ QCOMPARE(stat.decorateRectTriggeredStaticImageUpdate, 0);+ QCOMPARE(stat.forceUpdateTimedNode, 0);+ QCOMPARE(stat.slotDelayedStaticImageUpdate, 0);+ QCOMPARE(stat.recalculateStaticImage, 0);+ }++ QVERIFY(TestUtil::checkQImage(+ image->projection()->convertToQImage(nullptr, image->bounds()),+ "clone_layer_test",+ "tmask_x2_source",+ "20_final"));}KISTEST_MAIN(KisCloneLayerTest)diff --git a/libs/image/tests/kis_clone_layer_test.h b/libs/image/tests/kis_clone_layer_test.hindex af2f30eeac..54c9643270 100644--- a/libs/image/tests/kis_clone_layer_test.h+++ b/libs/image/tests/kis_clone_layer_test.h@@ -30,6 +30,7 @@ private Q_SLOTS:void testCyclingGroupLayer();void testWithSourceUnderTransformMask();+ void testWithSourceUnderTwoTransformMasks();};#endifdiff --git a/libs/image/tests/kis_filter_mask_test.cpp b/libs/image/tests/kis_filter_mask_test.cppindex 36618938cf..7f916017f6 100644--- a/libs/image/tests/kis_filter_mask_test.cpp+++ b/libs/image/tests/kis_filter_mask_test.cpp@@ -54,7 +54,7 @@ void KisFilterMaskTest::testProjectionNotSelected()mask->createNodeProgressProxy();mask->select(qimage.rect(), MIN_SELECTED);- mask->apply(projection, qimage.rect(), qimage.rect(), KisNode::N_FILTHY);+ mask->apply(projection, qimage.rect(), qimage.rect(), KisNode::N_FILTHY, KisRenderPassFlag::None);QPoint errpoint;if (!TestUtil::compareQImages(errpoint, qimage, projection->convertToQImage(0, 0, 0, qimage.width(), qimage.height()))) {@@ -87,7 +87,7 @@ void KisFilterMaskTest::testProjectionSelected()mask->initSelection(layer);mask->select(qimage.rect(), MAX_SELECTED);- mask->apply(projection, qimage.rect(), qimage.rect(), KisNode::N_FILTHY);+ mask->apply(projection, qimage.rect(), qimage.rect(), KisNode::N_FILTHY, KisRenderPassFlag::None);QCOMPARE(mask->exactBounds(), QRect(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT));QPoint errpoint;diff --git a/libs/image/tests/kis_layer_style_projection_plane_test.cpp b/libs/image/tests/kis_layer_style_projection_plane_test.cppindex 0a08536984..fe155e84f3 100644--- a/libs/image/tests/kis_layer_style_projection_plane_test.cpp+++ b/libs/image/tests/kis_layer_style_projection_plane_test.cpp@@ -68,7 +68,7 @@ void KisLayerStyleProjectionPlaneTest::test(KisPSDLayerStyleSP style, const QStrconst QRect changeRect = plane.changeRect(rFillRect, KisLayer::N_FILTHY);dbgKrita << ppVar(rFillRect) << ppVar(changeRect);- plane.recalculate(changeRect, layer);+ plane.recalculate(changeRect, layer, KisRenderPassFlag::None);KIS_DUMP_DEVICE_2(layer->projection(), imageRect, "02L_recalculate_fill", testName);@@ -100,7 +100,7 @@ void KisLayerStyleProjectionPlaneTest::test(KisPSDLayerStyleSP style, const QStrKIS_DUMP_DEVICE_2(projection, imageRect, "05P_apply_clone_after_copy", testName);}- clonedPlane->recalculate(changeRect, clonedLayer);+ clonedPlane->recalculate(changeRect, clonedLayer, KisRenderPassFlag::None);KIS_DUMP_DEVICE_2(clonedLayer->projection(), imageRect, "06L_recalculate_clone", testName);@@ -124,7 +124,7 @@ void KisLayerStyleProjectionPlaneTest::test(KisPSDLayerStyleSP style, const QStrKIS_DUMP_DEVICE_2(layer->projection(), imageRect, "08L_mask_added", testName);- plane.recalculate(imageRect, layer);+ plane.recalculate(imageRect, layer, KisRenderPassFlag::None);KIS_DUMP_DEVICE_2(layer->projection(), imageRect, "09_mask_added_recalculated", testName);@@ -145,7 +145,7 @@ void KisLayerStyleProjectionPlaneTest::test(KisPSDLayerStyleSP style, const QStrdbgKrita << ppVar(partialSelectionRect) << ppVar(changeRect);- plane.recalculate(changeRect, layer);+ plane.recalculate(changeRect, layer, KisRenderPassFlag::None);KIS_DUMP_DEVICE_2(layer->projection(), imageRect, "11L_recalculate_partial", testName);@@ -164,7 +164,7 @@ void KisLayerStyleProjectionPlaneTest::test(KisPSDLayerStyleSP style, const QStrdbgKrita << ppVar(updateRect1) << ppVar(changeRect);- plane.recalculate(changeRect, layer);+ plane.recalculate(changeRect, layer, KisRenderPassFlag::None);KIS_DUMP_DEVICE_2(layer->projection(), imageRect, "13recalculate_half1", testName);@@ -180,7 +180,7 @@ void KisLayerStyleProjectionPlaneTest::test(KisPSDLayerStyleSP style, const QStrdbgKrita << ppVar(updateRect2) << ppVar(changeRect);- plane.recalculate(changeRect, layer);+ plane.recalculate(changeRect, layer, KisRenderPassFlag::None);KIS_DUMP_DEVICE_2(layer->projection(), imageRect, "15L_recalculate_half1", testName);diff --git a/libs/image/tests/kis_mask_test.cpp b/libs/image/tests/kis_mask_test.cppindex d41a1953bf..34bd8f0f50 100644--- a/libs/image/tests/kis_mask_test.cpp+++ b/libs/image/tests/kis_mask_test.cpp@@ -86,7 +86,7 @@ void KisMaskTest::testCropUpdateBySelection()mask->initSelection(sel, p.layer);- mask->apply(p.layer->projection(), updateRect, updateRect, KisNode::N_FILTHY);+ mask->apply(p.layer->projection(), updateRect, updateRect, KisNode::N_FILTHY, KisRenderPassFlag::None);// Here we crash! :)/**diff --git a/libs/image/tests/kis_paint_layer_test.cpp b/libs/image/tests/kis_paint_layer_test.cppindex 3191ebce43..91601116db 100644--- a/libs/image/tests/kis_paint_layer_test.cpp+++ b/libs/image/tests/kis_paint_layer_test.cpp@@ -54,7 +54,7 @@ void KisPaintLayerTest::testProjection()Q_ASSERT(layer->hasEffectMasks());// And now we're going to update the projection, but nothing is dirty yet- layer->projectionPlane()->recalculate(qimage.rect(), layer);+ layer->projectionPlane()->recalculate(qimage.rect(), layer, KisRenderPassFlag::None);// Which also means that the projection is no longer the paint deviceQVERIFY(layer->paintDevice().data() != layer->projection().data());@@ -63,7 +63,7 @@ void KisPaintLayerTest::testProjection()layer->setDirty(qimage.rect());// And now we're going to update the projection, but nothing is dirty yet- layer->projectionPlane()->recalculate(qimage.rect(), layer);+ layer->projectionPlane()->recalculate(qimage.rect(), layer, KisRenderPassFlag::None);// Which also means that the projection is no longer the paint deviceQVERIFY(layer->paintDevice().data() != layer->projection().data());@@ -73,7 +73,7 @@ void KisPaintLayerTest::testProjection()QVERIFY(layer->projection().data() != 0);// The selection is initially empty, so after an update, all pixels are still visible- layer->projectionPlane()->recalculate(qimage.rect(), layer);+ layer->projectionPlane()->recalculate(qimage.rect(), layer, KisRenderPassFlag::None);// We've inverted the mask, so now nothing is seenKisSequentialConstIterator it(layer->projection(), qimage.rect());diff --git a/libs/image/tests/kis_transparency_mask_test.cpp b/libs/image/tests/kis_transparency_mask_test.cppindex 84df1e1a04..1fb8b67cb0 100644--- a/libs/image/tests/kis_transparency_mask_test.cpp+++ b/libs/image/tests/kis_transparency_mask_test.cpp@@ -55,7 +55,7 @@ void KisTransparencyMaskTest::testApply()// Everything is selectedinitImage(image, layer, dev, mask);mask->initSelection(layer);- mask->apply(dev, applyRect, applyRect, KisNode::N_FILTHY);+ mask->apply(dev, applyRect, applyRect, KisNode::N_FILTHY, KisRenderPassFlag::None);QImage qimage = dev->convertToQImage(0, 0, 0, 200, 100);if (!TestUtil::compareQImages(errpoint,@@ -68,7 +68,7 @@ void KisTransparencyMaskTest::testApply()initImage(image, layer, dev, mask);mask->initSelection(layer);mask->selection()->pixelSelection()->invert();- mask->apply(dev, applyRect, applyRect, KisNode::N_FILTHY);+ mask->apply(dev, applyRect, applyRect, KisNode::N_FILTHY, KisRenderPassFlag::None);qimage = dev->convertToQImage(0, 0, 0, 200, 100);if (!TestUtil::compareQImages(errpoint,@@ -81,7 +81,7 @@ void KisTransparencyMaskTest::testApply()mask->initSelection(layer);mask->selection()->pixelSelection()->invert();mask->select(QRect(50, 0, 100, 100));- mask->apply(dev, applyRect, applyRect, KisNode::N_FILTHY);+ mask->apply(dev, applyRect, applyRect, KisNode::N_FILTHY, KisRenderPassFlag::None);qimage = dev->convertToQImage(0, 0, 0, 200, 100);if (!TestUtil::compareQImages(errpoint,diff --git a/libs/ui/widgets/kis_scratch_pad.cpp b/libs/ui/widgets/kis_scratch_pad.cppindex e9eb4714f9..4a5b110d9f 100644--- a/libs/ui/widgets/kis_scratch_pad.cpp+++ b/libs/ui/widgets/kis_scratch_pad.cpp@@ -640,7 +640,7 @@ void KisScratchPad::paintEvent ( QPaintEvent * event ) {QPointF offset = alignedImageRect.topLeft();- m_paintLayer->projectionPlane()->recalculate(alignedImageRect, m_paintLayer);+ m_paintLayer->projectionPlane()->recalculate(alignedImageRect, m_paintLayer, KisRenderPassFlag::None);KisPaintDeviceSP projection = m_paintLayer->projection();QImage image = projection->convertToQImage(m_displayProfile,