diff options
5 files changed, 133 insertions, 39 deletions
diff --git a/drawinglayer/Library_drawinglayer.mk b/drawinglayer/Library_drawinglayer.mk index 2b618f73136d..28e073f983c8 100644 --- a/drawinglayer/Library_drawinglayer.mk +++ b/drawinglayer/Library_drawinglayer.mk @@ -78,6 +78,7 @@ $(eval $(call gb_Library_add_exception_objects,drawinglayer,\ drawinglayer/source/primitive2d/backgroundcolorprimitive2d \ drawinglayer/source/primitive2d/bitmapprimitive2d \ drawinglayer/source/primitive2d/borderlineprimitive2d \ + drawinglayer/source/primitive2d/BufferedDecompositionGroupPrimitive2D \ drawinglayer/source/primitive2d/controlprimitive2d \ drawinglayer/source/primitive2d/cropprimitive2d \ drawinglayer/source/primitive2d/discretebitmapprimitive2d \ diff --git a/drawinglayer/source/primitive2d/BufferedDecompositionGroupPrimitive2D.cxx b/drawinglayer/source/primitive2d/BufferedDecompositionGroupPrimitive2D.cxx new file mode 100644 index 000000000000..67f41627718e --- /dev/null +++ b/drawinglayer/source/primitive2d/BufferedDecompositionGroupPrimitive2D.cxx @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include <sal/config.h> + +#include <drawinglayer/primitive2d/BufferedDecompositionGroupPrimitive2D.hxx> +#include <drawinglayer/geometry/viewinformation2d.hxx> + +namespace drawinglayer::primitive2d +{ +BufferedDecompositionGroupPrimitive2D::BufferedDecompositionGroupPrimitive2D( + Primitive2DContainer&& aChildren) + : GroupPrimitive2D(std::move(aChildren)) +{ +} + +void BufferedDecompositionGroupPrimitive2D::get2DDecomposition( + Primitive2DDecompositionVisitor& rVisitor, + const geometry::ViewInformation2D& rViewInformation) const +{ + if (getBuffered2DDecomposition().empty()) + { + Primitive2DContainer aNewSequence; + create2DDecomposition(aNewSequence, rViewInformation); + const_cast<BufferedDecompositionGroupPrimitive2D*>(this)->setBuffered2DDecomposition( + std::move(aNewSequence)); + } + + rVisitor.visit(getBuffered2DDecomposition()); +} + +} // end of namespace drawinglayer::primitive2d + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/drawinglayer/source/primitive2d/glowprimitive2d.cxx b/drawinglayer/source/primitive2d/glowprimitive2d.cxx index 0bce06d90a1d..d3c8539eddf8 100644 --- a/drawinglayer/source/primitive2d/glowprimitive2d.cxx +++ b/drawinglayer/source/primitive2d/glowprimitive2d.cxx @@ -37,8 +37,7 @@ namespace drawinglayer::primitive2d { GlowPrimitive2D::GlowPrimitive2D(const Color& rGlowColor, double fRadius, Primitive2DContainer&& rChildren) - : GroupPrimitive2D(std::move(rChildren)) - , maBuffered2DDecomposition() + : BufferedDecompositionGroupPrimitive2D(std::move(rChildren)) , maGlowColor(rGlowColor) , mfGlowRadius(fRadius) , mfLastDiscreteGlowRadius(0.0) @@ -48,7 +47,7 @@ GlowPrimitive2D::GlowPrimitive2D(const Color& rGlowColor, double fRadius, bool GlowPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const { - if (BasePrimitive2D::operator==(rPrimitive)) + if (BufferedDecompositionGroupPrimitive2D::operator==(rPrimitive)) { const GlowPrimitive2D& rCompare = static_cast<const GlowPrimitive2D&>(rPrimitive); @@ -239,10 +238,9 @@ void GlowPrimitive2D::create2DDecomposition( } } -// Same as in BufferedDecompositionPrimitive2D, maybe we need a tooling class -// like BufferedDecompositionGropupPrimitive2D if this is used more often -// (AFAIR it's similar for ScenePrimitive2D which also does quite some re-use/ -// buffering checks to avoid too much re-creation) +// Using tooling class BufferedDecompositionGroupPrimitive2D now, so +// no more need to locally do the buffered get2DDecomposition here, +// see BufferedDecompositionGroupPrimitive2D::get2DDecomposition void GlowPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, const geometry::ViewInformation2D& rViewInformation) const { @@ -319,20 +317,9 @@ void GlowPrimitive2D::get2DDecomposition(Primitive2DDecompositionVisitor& rVisit } } - if (getBuffered2DDecomposition().empty()) - { - // refresh last used DiscreteGlowRadius and ClippedRange to new remembered values - const_cast<GlowPrimitive2D*>(this)->mfLastDiscreteGlowRadius = fDiscreteGlowRadius; - const_cast<GlowPrimitive2D*>(this)->maLastClippedRange = aClippedRange; - - // create decomposition - Primitive2DContainer aNewSequence; - - create2DDecomposition(aNewSequence, rViewInformation); - const_cast<GlowPrimitive2D*>(this)->setBuffered2DDecomposition(std::move(aNewSequence)); - } - - rVisitor.visit(getBuffered2DDecomposition()); + // call parent, that will check for empty, call create2DDecomposition and + // set as decomposition + BufferedDecompositionGroupPrimitive2D::get2DDecomposition(rVisitor, rViewInformation); } basegfx::B2DRange diff --git a/include/drawinglayer/primitive2d/BufferedDecompositionGroupPrimitive2D.hxx b/include/drawinglayer/primitive2d/BufferedDecompositionGroupPrimitive2D.hxx new file mode 100644 index 000000000000..b5446c703d2e --- /dev/null +++ b/include/drawinglayer/primitive2d/BufferedDecompositionGroupPrimitive2D.hxx @@ -0,0 +1,69 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#pragma once + +#include <drawinglayer/drawinglayerdllapi.h> +#include <drawinglayer/primitive2d/groupprimitive2d.hxx> + +namespace drawinglayer::primitive2d +{ +/** BufferedDecompositionGroupPrimitive2D class + + Baseclass for all C++ implementations whiich are derived from GroupPrimitive2D + which want to buffer the decomposition result + + For discussion please refer to BufferedDecompositionPrimitive2D, this is the same + but for GroupPrimitive2D which want to buffer their decomposition + */ +class DRAWINGLAYER_DLLPUBLIC BufferedDecompositionGroupPrimitive2D : public GroupPrimitive2D +{ +private: + /// a sequence used for buffering the last create2DDecomposition() result + Primitive2DContainer maBuffered2DDecomposition; + +protected: + /// identical to BufferedDecompositionPrimitive2D, see there please + const Primitive2DContainer& getBuffered2DDecomposition() const + { + return maBuffered2DDecomposition; + } + void setBuffered2DDecomposition(Primitive2DContainer&& rNew) + { + maBuffered2DDecomposition = std::move(rNew); + } + + /// method which is to be used to implement the local decomposition of a 2D group primitive. + virtual void + create2DDecomposition(Primitive2DContainer& rContainer, + const geometry::ViewInformation2D& rViewInformation) const = 0; + +public: + /// constructor/destructor. For GroupPrimitive2D we need the child parameter, too. + BufferedDecompositionGroupPrimitive2D(Primitive2DContainer&& aChildren); + + /// identical to BufferedDecompositionPrimitive2D, see there please + virtual void + get2DDecomposition(Primitive2DDecompositionVisitor& rVisitor, + const geometry::ViewInformation2D& rViewInformation) const override; +}; + +} // end of namespace drawinglayer::primitive2d + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/drawinglayer/primitive2d/glowprimitive2d.hxx b/include/drawinglayer/primitive2d/glowprimitive2d.hxx index 1fbc5f73652c..6a60c85ad6ae 100644 --- a/include/drawinglayer/primitive2d/glowprimitive2d.hxx +++ b/include/drawinglayer/primitive2d/glowprimitive2d.hxx @@ -22,16 +22,14 @@ #include <drawinglayer/drawinglayerdllapi.h> #include <drawinglayer/primitive2d/groupprimitive2d.hxx> +#include <drawinglayer/primitive2d/BufferedDecompositionGroupPrimitive2D.hxx> #include <tools/color.hxx> namespace drawinglayer::primitive2d { -class DRAWINGLAYER_DLLPUBLIC GlowPrimitive2D final : public GroupPrimitive2D +class DRAWINGLAYER_DLLPUBLIC GlowPrimitive2D final : public BufferedDecompositionGroupPrimitive2D { private: - /// a sequence used for buffering the last create2DDecomposition() result - Primitive2DContainer maBuffered2DDecomposition; - /// the Glow color to which all geometry is to be forced; includes alpha Color maGlowColor; @@ -49,21 +47,10 @@ private: const geometry::ViewInformation2D& rViewInformation) const; protected: - /** access methods to maBuffered2DDecomposition, same as in - * BufferedDecompositionPrimitive2D - */ - const Primitive2DContainer& getBuffered2DDecomposition() const - { - return maBuffered2DDecomposition; - } - void setBuffered2DDecomposition(Primitive2DContainer&& rNew) - { - maBuffered2DDecomposition = std::move(rNew); - } - /** method which is to be used to implement the local decomposition of a 2D primitive. */ - virtual void create2DDecomposition(Primitive2DContainer& rContainer, - const geometry::ViewInformation2D& rViewInformation) const; + virtual void + create2DDecomposition(Primitive2DContainer& rContainer, + const geometry::ViewInformation2D& rViewInformation) const override; public: /// constructor |