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 <Armin.Le.Grand@me.com>
This commit is contained in:
Armin Le Grand (allotropia)
2022-09-01 12:39:27 +02:00
committed by Armin Le Grand
parent 256086fc9b
commit 08e62dfbc1
5 changed files with 133 additions and 39 deletions
+1
View File
@@ -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 \
@@ -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: */
@@ -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
@@ -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: */
@@ -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