From 08e62dfbc156ef79cd9fa98e54bfba043247af8f Mon Sep 17 00:00:00 2001 From: "Armin Le Grand (allotropia)" Date: Wed, 31 Aug 2022 12:49:50 +0200 Subject: Added BufferedDecompositionGroupPrimitive2D ...and adapted GlowPrimitive2D to it as a preparation to use similar to BufferedDecompositionPrimitive2D, but for primitives based on GroupPrimitive2D. Change-Id: Ia1f9a09d4db09238ebbf6ad1303a4cdbdb8baedf Reviewed-on: https://gerrit.libreoffice.org/c/core/+/139099 Tested-by: Jenkins Reviewed-by: Armin Le Grand --- drawinglayer/Library_drawinglayer.mk | 1 + .../BufferedDecompositionGroupPrimitive2D.cxx | 50 ++++++++++++++++++++++ .../source/primitive2d/glowprimitive2d.cxx | 29 ++++--------- 3 files changed, 59 insertions(+), 21 deletions(-) create mode 100644 drawinglayer/source/primitive2d/BufferedDecompositionGroupPrimitive2D.cxx (limited to 'drawinglayer') 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 + +#include +#include + +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(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(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(this)->mfLastDiscreteGlowRadius = fDiscreteGlowRadius; - const_cast(this)->maLastClippedRange = aClippedRange; - - // create decomposition - Primitive2DContainer aNewSequence; - - create2DDecomposition(aNewSequence, rViewInformation); - const_cast(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 -- cgit