From 424055db8e286acc559bafe2bb14787c283ba45b Mon Sep 17 00:00:00 2001 From: Jabier Arraiza Date: Tue, 26 Mar 2024 00:11:11 +0100 Subject: [PATCH] Invalidte updates on tranform --- src/object/sp-ellipse.cpp | 4 ++-- src/object/sp-item.cpp | 6 ++++++ src/object/sp-line.cpp | 3 +-- src/object/sp-offset.cpp | 29 +++++++++++++++-------------- src/object/sp-path.cpp | 2 +- src/object/sp-rect.cpp | 3 +-- src/object/sp-shape.cpp | 17 ++++++++++++----- src/object/sp-shape.h | 2 +- src/object/sp-spiral.cpp | 2 +- src/object/sp-star.cpp | 2 +- 10 files changed, 41 insertions(+), 29 deletions(-) diff --git a/src/object/sp-ellipse.cpp b/src/object/sp-ellipse.cpp index 1db7c0ecd4..6293bc766c 100644 --- a/src/object/sp-ellipse.cpp +++ b/src/object/sp-ellipse.cpp @@ -212,7 +212,8 @@ void SPGenericEllipse::set(SPAttr key, gchar const *value) void SPGenericEllipse::update(SPCtx *ctx, guint flags) { // std::cout << "\nSPGenericEllipse::update: Entrance" << std::endl; - if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + + if (validate_update(flags) && flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { Geom::Rect const &viewbox = ((SPItemCtx const *) ctx)->viewport; double const dx = viewbox.width(); @@ -228,7 +229,6 @@ void SPGenericEllipse::update(SPCtx *ctx, guint flags) this->set_shape(); } - SPShape::update(ctx, flags); // std::cout << "SPGenericEllipse::update: Exit\n" << std::endl; } diff --git a/src/object/sp-item.cpp b/src/object/sp-item.cpp index ce237b38cd..9ec27e028b 100644 --- a/src/object/sp-item.cpp +++ b/src/object/sp-item.cpp @@ -1695,6 +1695,12 @@ void SPItem::doWriteTransform(Geom::Affine const &transform, Geom::Affine const void SPItem::set_item_transform(Geom::Affine const &transform_matrix) { if (!Geom::are_near(transform_matrix, transform, 1e-18)) { + if (Geom::are_near(transform_matrix, Geom::Affine())) { + if (auto shape = cast(this)) { + shape->bbox_geom_cache = Geom::OptRect(); + shape->bbox_vis_cache = Geom::OptRect(); + } + } transform = transform_matrix; /* The SP_OBJECT_USER_MODIFIED_FLAG_B is used to mark the fact that it's only a transformation. It's apparently not used anywhere else. */ diff --git a/src/object/sp-line.cpp b/src/object/sp-line.cpp index 1c89462b39..c3efacd05c 100644 --- a/src/object/sp-line.cpp +++ b/src/object/sp-line.cpp @@ -70,7 +70,7 @@ void SPLine::set(SPAttr key, const gchar* value) { } void SPLine::update(SPCtx *ctx, guint flags) { - if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + if (validate_update(flags) && flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { SPStyle const *style = this->style; SPItemCtx const *ictx = (SPItemCtx const *) ctx; double const w = ictx->viewport.width(); @@ -85,7 +85,6 @@ void SPLine::update(SPCtx *ctx, guint flags) { this->set_shape(); } - SPShape::update(ctx, flags); } diff --git a/src/object/sp-offset.cpp b/src/object/sp-offset.cpp index 9021332ff3..4b237a1302 100644 --- a/src/object/sp-offset.cpp +++ b/src/object/sp-offset.cpp @@ -298,21 +298,22 @@ void SPOffset::set(SPAttr key, const gchar* value) { } void SPOffset::update(SPCtx *ctx, guint flags) { - this->isUpdating=true; // prevent sp_offset_set from requesting updates - - if ( this->sourceDirty ) { - refresh_offset_source(this); - } - - if (flags & - (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | - SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { - - this->set_shape(); + if (validate_update(flags)) { + this->isUpdating=true; // prevent sp_offset_set from requesting updates + + if ( this->sourceDirty ) { + refresh_offset_source(this); + } + + if (flags & + (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | + SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + + this->set_shape(); + } + + this->isUpdating=false; } - - this->isUpdating=false; - SPShape::update(ctx, flags); } diff --git a/src/object/sp-path.cpp b/src/object/sp-path.cpp index 1fe8d241ec..c9604d6b5e 100644 --- a/src/object/sp-path.cpp +++ b/src/object/sp-path.cpp @@ -273,7 +273,7 @@ void SPPath::update_patheffect(bool write) { } void SPPath::update(SPCtx *ctx, guint flags) { - if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + if (validate_update(flags) && flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { flags &= ~SP_OBJECT_USER_MODIFIED_FLAG_B; // since we change the description, it's not a "just translation" anymore } diff --git a/src/object/sp-rect.cpp b/src/object/sp-rect.cpp index def363af99..011755272b 100644 --- a/src/object/sp-rect.cpp +++ b/src/object/sp-rect.cpp @@ -147,8 +147,7 @@ void SPRect::update(SPCtx* ctx, unsigned int flags) { #ifdef OBJECT_TRACE objectTrace( "SPRect::update", true, flags ); #endif - - if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + if (validate_update(flags) && flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { SPItemCtx const *ictx = reinterpret_cast(ctx); double const w = ictx->viewport.width(); diff --git a/src/object/sp-shape.cpp b/src/object/sp-shape.cpp index 0aa746f28d..e56176d6a4 100644 --- a/src/object/sp-shape.cpp +++ b/src/object/sp-shape.cpp @@ -122,13 +122,19 @@ Inkscape::XML::Node* SPShape::write(Inkscape::XML::Document *xml_doc, Inkscape:: return repr; } +bool SPShape::validate_update(unsigned int flags) { + if (!bbox_geom_cache || !bbox_vis_cache || !(flags & SP_OBJECT_USER_MODIFIED_FLAG_B)) { + bbox_vis_cache_is_valid = false; + bbox_geom_cache_is_valid = false; + return true; + } + return !(flags & SP_OBJECT_USER_MODIFIED_FLAG_B); +} + void SPShape::update(SPCtx* ctx, guint flags) { // Any update can change the bounding box, // so the cached version can no longer be used. // But the idle checker usually is just moving the objects around. - bbox_vis_cache_is_valid = false; - bbox_geom_cache_is_valid = false; - // std::cout << "SPShape::update(): " << (getId()?getId():"null") << std::endl; SPLPEItem::update(ctx, flags); @@ -541,7 +547,8 @@ Geom::OptRect SPShape::either_bbox(Geom::Affine const &transform, SPItem::BBoxTy // Return the cache if possible. auto delta = transform_cache.inverse() * transform; if (cache_is_valid && bbox_cache && delta.isTranslation()) { - + // uncomenting cout fail some output based tests + // std::cout << "using cache bbox" << std::endl; // Don't re-adjust the cache if we haven't moved if (!delta.isNonzeroTranslation()) { return bbox_cache; @@ -549,7 +556,7 @@ Geom::OptRect SPShape::either_bbox(Geom::Affine const &transform, SPItem::BBoxTy // delta is pure translation so it's safe to use it as is return *bbox_cache * delta; } - + // std::cout << "not using cache bbox" << std::endl; if (!this->_curve || this->_curve->get_pathvector().empty()) { return bbox; } diff --git a/src/object/sp-shape.h b/src/object/sp-shape.h index 9d257290a1..657e8608cb 100644 --- a/src/object/sp-shape.h +++ b/src/object/sp-shape.h @@ -78,7 +78,7 @@ public: void release() override; void update(SPCtx* ctx, unsigned int flags) override; void modified(unsigned int flags) override; - + bool validate_update(unsigned int flags); void set(SPAttr key, char const* value) override; Inkscape::XML::Node* write(Inkscape::XML::Document *xml_doc, Inkscape::XML::Node *repr, unsigned int flags) override; diff --git a/src/object/sp-spiral.cpp b/src/object/sp-spiral.cpp index f471873bbc..971b7c371b 100644 --- a/src/object/sp-spiral.cpp +++ b/src/object/sp-spiral.cpp @@ -193,7 +193,7 @@ void SPSpiral::set(SPAttr key, gchar const* value) { } void SPSpiral::update(SPCtx *ctx, guint flags) { - if (flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { + if (validate_update(flags) && flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { this->set_shape(); } diff --git a/src/object/sp-star.cpp b/src/object/sp-star.cpp index de4e195d97..4faf20f9d6 100644 --- a/src/object/sp-star.cpp +++ b/src/object/sp-star.cpp @@ -214,7 +214,7 @@ void SPStar::set(SPAttr key, const gchar* value) { } void SPStar::update(SPCtx *ctx, guint flags) { - if (flags & (SP_OBJECT_MODIFIED_FLAG | + if (validate_update(flags) && flags & (SP_OBJECT_MODIFIED_FLAG | SP_OBJECT_STYLE_MODIFIED_FLAG | SP_OBJECT_VIEWPORT_MODIFIED_FLAG)) { -- GitLab